罗斌杰 2 years ago
parent
commit
d9e68e8257
  1. 45
      src/api/api.js
  2. 13
      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(() => {});
});
}

13
src/api/request.js

@ -3,7 +3,7 @@ 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'))
@ -12,10 +12,17 @@ const instance = axios.create({
//timeout: 500000,
withCredentials: true, // 允许跨域
});
let loading = null
//请求拦截
instance.interceptors.request.use(
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();
@ -36,6 +43,7 @@ instance.interceptors.request.use(
//响应拦截
instance.interceptors.response.use(
(res) => {
loading.close();
// console.log(res);
if (res.data.code < 0) {
Message.error({ showClose: true, message: res.data.message });
@ -52,6 +60,7 @@ instance.interceptors.response.use(
// console.log('token失效返回登录');
// }
// console.log(err);
loading.close();
return Promise.reject(err);
}
// function (response) {

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