前端联调接口

This commit is contained in:
陈淳
2022-10-11 16:48:25 +08:00
parent 58f85992b0
commit a0c869d0a1
54 changed files with 899 additions and 137 deletions

View File

@@ -0,0 +1,93 @@
import axios from 'axios'
// import store from '../store/index'
// import vm from '../main'
import JsonBig from 'json-bigint'
// import VuetifyDialogPlugin from 'vuetify-dialog/nuxt/index';
const myaxios = axios.create({
// baseURL:'/'//
baseURL: import.meta.env.VITE_APP_BASE_API, // /dev-apis
timeout: 50000,
headers: {
'Authorization': 'Bearer ' + ""
},
//雪花id精度问题
transformResponse: [ data => {
const json = JsonBig({
storeAsString: true
})
return json.parse(data)
}],
})
// 请求拦截器
myaxios.interceptors.request.use(function(config) {
// config.headers.Authorization = 'Bearer ' + store.state.user.token;
// store.dispatch("openLoad");
return config;
}, function(error) {
return Promise.reject(error);
});
// 响应拦截器
myaxios.interceptors.response.use(async function(response) {
const resp = response.data
if (resp.code == undefined && resp.message == undefined) {
// vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
// position: "top-right",
// timeout: 5000,
// });
} else if (resp.code == 401) {
// const res = await vm.$dialog.error({
// text: `错误代码:${resp.code},原因:${resp.message}<br>是否重新进行登录?`,
// title: '错误',
// actions: {
// 'false': '取消',
// 'true': '跳转'
// }
// });
// if (res) {
// vm.$router.push({ path: "/login" });
// }
} else if (resp.code !== 200) {
// vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, {
// position: "top-right",
// timeout: 5000,
// });
}
// store.dispatch("closeLoad");
return resp;
}, async function(error) {
// const resp = error.response.data
// if (resp.code == undefined && resp.message == undefined) {
// vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
// position: "top-right",
// timeout: 5000,
// });
// } else if (resp.code == 401) {
// const res = await vm.$dialog.error({
// text: `错误代码:${resp.code},原因:${resp.message}<br>是否重新进行登录?`,
// title: '错误',
// actions: {
// 'false': '取消',
// 'true': '跳转'
// }
// });
// if (res) {
// vm.$store.dispatch("Logout").then((resp) => {
// vm.$router.push({ path: "/login" });
// });
// }
// } else if (resp.code !== 200) {
// vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, {
// position: "top-right",
// timeout: 5000,
// });
// }
// store.dispatch("closeLoad");
return Promise.reject(error);
});
export default myaxios