Commit b4a23b35 authored by 张伯涛's avatar 张伯涛

axios请求头修改,响应拦截器封装,用户管理模块修改

parent b89678a4
...@@ -24,7 +24,7 @@ export const addUserApi = (params: any) => ...@@ -24,7 +24,7 @@ export const addUserApi = (params: any) =>
defHttp.post({ defHttp.post({
url: Api.addUser, url: Api.addUser,
params: params, params: params,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, // headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}); });
/** 获取用户详情信息*/ /** 获取用户详情信息*/
...@@ -36,7 +36,6 @@ export const UserUpdataApi = (params: any) => ...@@ -36,7 +36,6 @@ export const UserUpdataApi = (params: any) =>
defHttp.put<any>({ defHttp.put<any>({
url: Api.updataApi, url: Api.updataApi,
params: params, params: params,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}); });
...@@ -45,5 +44,5 @@ export const changeFlagApi = (params: any) => ...@@ -45,5 +44,5 @@ export const changeFlagApi = (params: any) =>
defHttp.put<any>({ defHttp.put<any>({
url: Api.changeFlag, url: Api.changeFlag,
params: params, params: params,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, // headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}); });
export default {
'401': '认证失败,无法访问系统资源',
'403': '当前操作没有权限',
'404': '访问资源不存在',
'default': '系统未知错误,请反馈给管理员'
}
...@@ -19,7 +19,7 @@ import { joinTimestamp, formatRequestDate } from './helper'; ...@@ -19,7 +19,7 @@ import { joinTimestamp, formatRequestDate } from './helper';
import { useUserStoreWithOut } from '@/store/modules/user'; import { useUserStoreWithOut } from '@/store/modules/user';
import { AxiosRetry } from '@/utils/http/axios/axiosRetry'; import { AxiosRetry } from '@/utils/http/axios/axiosRetry';
import axios from 'axios'; import axios from 'axios';
import errorCode from '@/utils/errorCode'
const globSetting = useGlobSetting(); const globSetting = useGlobSetting();
const urlPrefix = globSetting.urlPrefix; const urlPrefix = globSetting.urlPrefix;
const { createMessage, createErrorModal, createSuccessModal } = useMessage(); const { createMessage, createErrorModal, createSuccessModal } = useMessage();
...@@ -166,9 +166,33 @@ const transform: AxiosTransform = { ...@@ -166,9 +166,33 @@ const transform: AxiosTransform = {
/** /**
* @description: 响应拦截器处理 * @description: 响应拦截器处理
*/ */
responseInterceptors: (res: AxiosResponse<any>) => { responseInterceptors: (res: any) => {
// console.log('ree',res) // 未设置状态码则默认成功状态
return res; const code = res.data.code || 200
// 获取错误信息
const message = errorCode[code] || res.data.msg || res.data.message || errorCode['default']
if (code === 401) {
createMessage.error('用户不存在或密码错误');
}else if (code === 410) {
createMessage.error('当前登录无权限,请重新登录');
userStore.logout(true);
} else if (code === 500 || code === 400) {
const errMsg = res.data.message || res.data.msg
console.log('errMsg',errMsg)
createMessage.error(errMsg);
return Promise.reject(new Error(message))
}else if (code !== 200 && code !== 'E004') {
createMessage.error(message);
return Promise.reject('error')
} else if (code !== 'E004') {
return res;
// if (res.config.url.indexOf('downLoadSignaturesSample') > -1 || res.config.url.indexOf('downLoadSignatures') > -1) {
// return res
// } else {
// return res.data
// }
}
}, },
/** /**
...@@ -234,7 +258,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) { ...@@ -234,7 +258,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
// 基础接口地址 // 基础接口地址
// baseURL: globSetting.apiUrl, // baseURL: globSetting.apiUrl,
headers: { 'Content-Type': ContentTypeEnum.JSON }, // headers: { 'Content-Type': ContentTypeEnum.JSON },
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
// 如果是form-data格式 // 如果是form-data格式
// headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED }, // headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
// 数据处理方式 // 数据处理方式
......
...@@ -73,7 +73,7 @@ export const columns: BasicColumn[] = [ ...@@ -73,7 +73,7 @@ export const columns: BasicColumn[] = [
createMessage.success( text + `成功`); createMessage.success( text + `成功`);
}) })
.catch(() => { .catch(() => {
createMessage.error('操作失败'); // createMessage.error('操作失败');
}) })
.finally(() => { .finally(() => {
record.pendingStatus = false; record.pendingStatus = false;
......
...@@ -109,7 +109,6 @@ ...@@ -109,7 +109,6 @@
console.log(result); console.log(result);
reload(); reload();
} else { } else {
createMessage.success('新增成功');
reload(); reload();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment