|
|
@@ -0,0 +1,137 @@
|
|
|
+// import Axios from "axios";
|
|
|
+
|
|
|
+// const instanceNormal = () => {
|
|
|
+// let token = localStorage.getItem("token");
|
|
|
+// let headers = token ? {
|
|
|
+// "Authorization": 'Bearer ' + localStorage.getItem("token"),
|
|
|
+// } : {};
|
|
|
+// console.log(headers)
|
|
|
+// return Axios.create({
|
|
|
+// baseURL: 'http://localhost:8080',
|
|
|
+// });
|
|
|
+// }
|
|
|
+// let token = localStorage.getItem("token");
|
|
|
+// let headers = token ? {
|
|
|
+// "Authorization": 'Bearer ' + localStorage.getItem("token"),
|
|
|
+// 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
|
|
|
+// } : {};
|
|
|
+// const _get = (url, config) => {
|
|
|
+// return new Promise((resolve, reject) => {
|
|
|
+// instanceNormal()
|
|
|
+// .get(url, {
|
|
|
+// params: config,
|
|
|
+// headers: headers
|
|
|
+// })
|
|
|
+// .then(data => {
|
|
|
+// resolve(data.data);
|
|
|
+// })
|
|
|
+// .catch(err => {
|
|
|
+// reject(err);
|
|
|
+// });
|
|
|
+// });
|
|
|
+// };
|
|
|
+// const _post = (url, config) => {
|
|
|
+// return new Promise((resolve, reject) => {
|
|
|
+// instanceNormal()
|
|
|
+// .post(url, config)
|
|
|
+// .then(data => {
|
|
|
+// resolve(data.data);
|
|
|
+// })
|
|
|
+// .catch(err => {
|
|
|
+// reject(err);
|
|
|
+// });
|
|
|
+// });
|
|
|
+// };
|
|
|
+// const _delete = (url, config) => {
|
|
|
+// return new Promise((resolve, reject) => {
|
|
|
+// instanceNormal()
|
|
|
+// .delete(url, config)
|
|
|
+// .then(data => {
|
|
|
+// resolve(data.data);
|
|
|
+// })
|
|
|
+// .catch(err => {
|
|
|
+// reject(err);
|
|
|
+// });
|
|
|
+// });
|
|
|
+// };
|
|
|
+// const _put = (url, config) => {
|
|
|
+// return new Promise((resolve, reject) => {
|
|
|
+// instanceNormal()
|
|
|
+// .put(url, config)
|
|
|
+// .then(data => {
|
|
|
+// resolve(data.data);
|
|
|
+// })
|
|
|
+// .catch(err => {
|
|
|
+// reject(err);
|
|
|
+// });
|
|
|
+// });
|
|
|
+// };
|
|
|
+
|
|
|
+// export default {
|
|
|
+// _get,
|
|
|
+// _post,
|
|
|
+// _delete,
|
|
|
+// _put
|
|
|
+// };
|
|
|
+/* eslint-disable */
|
|
|
+import axios from 'axios';
|
|
|
+
|
|
|
+// Full config: https://github.com/axios/axios#request-config
|
|
|
+// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
|
+// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
|
+// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
+
|
|
|
+const config = {
|
|
|
+ baseURL: 'http://localhost:8080',
|
|
|
+ // timeout: 60 * 1000, // Timeout
|
|
|
+ // withCredentials: true, // Check cross-site Access-Control
|
|
|
+};
|
|
|
+
|
|
|
+const _axios = axios.create(config);
|
|
|
+
|
|
|
+_axios.interceptors.request.use(
|
|
|
+ (config) => {
|
|
|
+ const token = localStorage.getItem('token');
|
|
|
+ if (!token) {
|
|
|
+ return Promise.reject({message:'未登录', hidden: true});
|
|
|
+ }
|
|
|
+ // config.headers.Authorization = localStorage.getItem('token');
|
|
|
+ return config;
|
|
|
+ },
|
|
|
+ (error) =>
|
|
|
+ // Do something with request error
|
|
|
+ Promise.reject(error),
|
|
|
+);
|
|
|
+
|
|
|
+// Add a response interceptor
|
|
|
+// _axios.interceptors.response.use(
|
|
|
+// (response) => {
|
|
|
+// if (response.status === 403) {
|
|
|
+// destroyToken();
|
|
|
+// window.location.href = '/';
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// if (response.data.code >= 500) {
|
|
|
+// ElMessage({
|
|
|
+// type: 'error',
|
|
|
+// showClose: true,
|
|
|
+// message: '接口出错,错误信息:' + response.data.msg,
|
|
|
+// })
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// return response.data.data;
|
|
|
+// },
|
|
|
+// (error) => {
|
|
|
+// // Do something with response error
|
|
|
+// if (!error.hidden) {
|
|
|
+// ElMessage({
|
|
|
+// type: 'error',
|
|
|
+// showClose: true,
|
|
|
+// message: '接口出错,错误信息:' + error.message
|
|
|
+// })
|
|
|
+// }
|
|
|
+// Promise.reject(error)
|
|
|
+// }
|
|
|
+// );
|
|
|
+
|
|
|
+export default _axios;
|