diff --git a/src/api/api.js b/src/api/api.js index 562af95..dc22c34 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -1,17 +1,9 @@ import request from "@/api/request"; -import { Loading } from 'element-ui'; const sysConfig = JSON.parse(window.sessionStorage.getItem('sysConfig')) export async function getapi(url, params = {}, config) { return new Promise((resolve, reject) => { - let loading = Loading.service({ - lock: true, - text: "正在加载中,请稍后", - spinner: "el-icon-loading", - background: "rgba(0, 0, 0, 0)", - customClass: "boxStyle" - }); request .get(`${sysConfig.apiurl}${url}`, { params: params, @@ -23,22 +15,13 @@ export async function getapi(url, params = {}, config) { .catch((err) => { reject(err.data); }) - .finally(() => { - loading.close(); - }); + .finally(() => {}); }); } //axios封装post export async function postapi(url, paramsdata = {}, config) { return new Promise((resolve, reject) => { - let loading = Loading.service({ - lock: true, - text: "正在加载中,请稍后", - spinner: "el-icon-loading", - background: "rgba(0, 0, 0, 0)", - customClass: "boxStyle" - }); request .post(`${sysConfig.apiurl}${url}`, paramsdata, config) .then((res) => { @@ -47,21 +30,12 @@ export async function postapi(url, paramsdata = {}, config) { .catch((err) => { reject(err.data); }) - .finally(() => { - loading.close(); - }); + .finally(() => {}); }); } //axios封装deleteapi export async function deletapi(url, params = {}, config) { return new Promise((resolve, reject) => { - let loading = Loading.service({ - lock: true, - text: "正在加载中,请稍后", - spinner: "el-icon-loading", - background: "rgba(0, 0, 0, 0)", - customClass: "boxStyle" - }); request .delete(`${sysConfig.apiurl}${url}`, { params: params, @@ -73,21 +47,12 @@ export async function deletapi(url, params = {}, config) { .catch((err) => { reject(err.data); }) - .finally(() => { - loading.close(); - }); + .finally(() => {}); }); } //axios封装Put方法 export async function putapi(url, params = {}, config) { return new Promise((resolve, reject) => { - let loading = Loading.service({ - lock: true, - text: "正在加载中,请稍后", - spinner: "el-icon-loading", - background: "rgba(0, 0, 0, 0)", - customClass: "boxStyle" - }); request .put(`${sysConfig.apiurl}${url}`, params, config) .then((res) => { @@ -96,8 +61,6 @@ export async function putapi(url, params = {}, config) { .catch((err) => { reject(err.data); }) - .finally(() => { - loading.close(); - }); + .finally(() => {}); }); } \ No newline at end of file diff --git a/src/api/request.js b/src/api/request.js index 15a1bfa..9232717 100644 --- a/src/api/request.js +++ b/src/api/request.js @@ -3,75 +3,84 @@ import router from "@/router"; import axios from "axios"; // import Promise from 'promise' import { yztoken } from "@/utlis/istoken"; -import { Message } from "element-ui"; +import { Message, Loading } from "element-ui"; const sysConfig = JSON.parse(window.sessionStorage.getItem('sysConfig')) const instance = axios.create({ - baseURL: sysConfig.apiurl, - //timeout: 500000, - withCredentials: true, // 允许跨域 + baseURL: sysConfig.apiurl, + //timeout: 500000, + withCredentials: true, // 允许跨域 }); - -//请求拦截 +let loading = null + //请求拦截 instance.interceptors.request.use( - async function (config) { - //console.log('old token:',window.sessionStorage.getItem("token")) - //console.log('old expires_in',window.sessionStorage.getItem("expires_in")) - await yztoken(); + async function(config) { + loading = Loading.service({ + lock: true, + text: "正在加载中,请稍后", + spinner: "el-icon-loading", + background: "rgba(0, 0, 0, 0)", + customClass: "boxStyle" + }); + //console.log('old token:',window.sessionStorage.getItem("token")) + //console.log('old expires_in',window.sessionStorage.getItem("expires_in")) + await yztoken(); - let token = window.sessionStorage.getItem("token"); + let token = window.sessionStorage.getItem("token"); - let tokentype = window.sessionStorage.getItem("tokentype"); - config.headers["Access-Control-Allow-Origin"] = "*"; - // config.headers.ContentType = 'application/x-www-form-urlencoded' - config.headers.Authorization = `${tokentype} ${token}`; - return config; - }, - function (err) { - return Promise.reject(err); - } + let tokentype = window.sessionStorage.getItem("tokentype"); + config.headers["Access-Control-Allow-Origin"] = "*"; + // config.headers.ContentType = 'application/x-www-form-urlencoded' + config.headers.Authorization = `${tokentype} ${token}`; + return config; + }, + function(err) { + return Promise.reject(err); + } ); //响应拦截 instance.interceptors.response.use( - (res) => { - // console.log(res); - if (res.data.code < 0) { - Message.error({ showClose: true, message: res.data.message }); + (res) => { + loading.close(); + // console.log(res); + if (res.data.code < 0) { + Message.error({ showClose: true, message: res.data.message }); + } + return res.data; + }, + (err) => { + // console.log(err); + // if (response.data.code == -1) { + // router.push({ path: '/login' }) + // // this.$router.push({path:'/login'}) + // // console.log('状态失效') + // Message.error('状态失效请重新登录') + // console.log('token失效返回登录'); + // } + // console.log(err); + loading.close(); + return Promise.reject(err); } - return res.data; - }, - (err) => { - // console.log(err); - // if (response.data.code == -1) { - // router.push({ path: '/login' }) - // // this.$router.push({path:'/login'}) - // // console.log('状态失效') - // Message.error('状态失效请重新登录') - // console.log('token失效返回登录'); - // } - // console.log(err); - return Promise.reject(err); - } - // function (response) { - // console.log(response,10010) - // const {data} = response - // if (data.status == 401) { + // function (response) { + // console.log(response,10010) + // const {data} = response + // if (data.status == 401) { - // window.location.href = '#/login' - // this.$message.error('状态失效'); - // } - // return data - // }, - // function (err) { - // if (err.response.status === 401) { - // window.location.href = '#/login' - // this.$router.push({ path: '/login' }) - // this.$message.error('登录失效请重新登录'); - // } - // return err - // } + // window.location.href = '#/login' + // this.$message.error('状态失效'); + // } + // return data + // }, + // function (err) { + // if (err.response.status === 401) { + // window.location.href = '#/login' + // this.$router.push({ path: '/login' }) + // this.$message.error('登录失效请重新登录'); + // } + // return err + // } ); -export default instance; +export default instance; \ No newline at end of file diff --git a/src/views/basic-dictionary/GuideType.vue b/src/views/basic-dictionary/GuideType.vue index e4226b3..440fc57 100644 --- a/src/views/basic-dictionary/GuideType.vue +++ b/src/views/basic-dictionary/GuideType.vue @@ -34,7 +34,6 @@