罗斌杰 2 years ago
parent
commit
d9e68e8257
  1. 45
      src/api/api.js
  2. 119
      src/api/request.js
  3. 12
      src/views/basic-dictionary/GuideType.vue

45
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(() => {});
});
}

119
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;

12
src/views/basic-dictionary/GuideType.vue

@ -34,7 +34,6 @@
<div id="printTest" ref="imageDom">
<el-table
:data="tableData"
v-loading="loading"
row-key="id"
:height="window.pageHeight < 600 ? 480 : window.pageHeight - 130"
class="el-table__body-wrapper tbody"
@ -688,6 +687,7 @@ export default {
},
//
addoredit() {
console.log('eee')
if (this.title == 1) {
// this.form={}
if (this.form.displayName == undefined) {
@ -773,11 +773,11 @@ export default {
this.dialogVisible = true;
this.form = { ...this.curRow };
this.title = 2;
guideid(this.form.id).then((res) => {
if(res.code!=-1){
this.form = res.data;
}
});
// guideid(this.form.id).then((res) => {
// if(res.code!=-1){
// this.form = res.data;
// }
// });
}
// this.form=row

Loading…
Cancel
Save