This commit is contained in:
parent
9fab544136
commit
724653b5fa
|
@ -2,7 +2,7 @@ import axios from "axios";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import tools from "@/utils/tools";
|
import tools from "@/utils/tools";
|
||||||
import router from "../router";
|
import router from "../router";
|
||||||
axios.defaults.baseURL = 'https://jzzf.longyou.gov.cn:998/'
|
// axios.defaults.baseURL = 'https://jzzf.longyou.gov.cn:998/'
|
||||||
axios.defaults.timeout = 120000;
|
axios.defaults.timeout = 120000;
|
||||||
|
|
||||||
// HTTP request 拦截器
|
// HTTP request 拦截器
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useLoadingStore } from "@/stores/loading.js";
|
import { useLoadingStore } from "@/stores/loading.js";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
|
||||||
var tool = {}
|
var tool = {};
|
||||||
|
|
||||||
/* localStorage */
|
/* localStorage */
|
||||||
tool.data = {
|
tool.data = {
|
||||||
set(table, settings) {
|
set(table, settings) {
|
||||||
var _set = JSON.stringify(settings)
|
var _set = JSON.stringify(settings);
|
||||||
return localStorage.setItem(table, _set);
|
return localStorage.setItem(table, _set);
|
||||||
},
|
},
|
||||||
get(table) {
|
get(table) {
|
||||||
var data = localStorage.getItem(table);
|
var data = localStorage.getItem(table);
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null
|
return null;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
@ -23,17 +24,17 @@ tool.data = {
|
||||||
},
|
},
|
||||||
clear() {
|
clear() {
|
||||||
return localStorage.clear();
|
return localStorage.clear();
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
tool.url = function (url, params) {
|
tool.url = function (url, params) {
|
||||||
var hasParams = url.indexOf("?") > 0;
|
var hasParams = url.indexOf("?") > 0;
|
||||||
for (var key in params) {
|
for (var key in params) {
|
||||||
url = url + (hasParams ? '&' : '?') + key + '=' + params[key];
|
url = url + (hasParams ? "&" : "?") + key + "=" + params[key];
|
||||||
hasParams = true;
|
hasParams = true;
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
};
|
||||||
|
|
||||||
// 文件下载(token放请求头中)
|
// 文件下载(token放请求头中)
|
||||||
tool.downloadFile = (url, params) => {
|
tool.downloadFile = (url, params) => {
|
||||||
|
@ -43,10 +44,11 @@ tool.downloadFile = (url,params) => {
|
||||||
axios
|
axios
|
||||||
.get(url, {
|
.get(url, {
|
||||||
headers: { token: JSON.parse(localStorage.getItem("token")) },
|
headers: { token: JSON.parse(localStorage.getItem("token")) },
|
||||||
responseType: "blob",
|
// responseType: "blob",
|
||||||
params
|
params,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
if (!response.data.code) {
|
||||||
let blob = new Blob([response.data], {
|
let blob = new Blob([response.data], {
|
||||||
//这里的type要和后端一致
|
//这里的type要和后端一致
|
||||||
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
|
@ -63,6 +65,13 @@ tool.downloadFile = (url,params) => {
|
||||||
a.click();
|
a.click();
|
||||||
window.URL.revokeObjectURL(Url);
|
window.URL.revokeObjectURL(Url);
|
||||||
store.isLoading = false;
|
store.isLoading = false;
|
||||||
|
} else {
|
||||||
|
console.log(response.data);
|
||||||
|
store.isLoading = false;
|
||||||
|
ElMessage.warning({
|
||||||
|
message: response.data.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err, "err");
|
console.log(err, "err");
|
||||||
|
@ -70,6 +79,4 @@ tool.downloadFile = (url,params) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default tool;
|
||||||
export default tool
|
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
@current-change="handlePagination"
|
@current-change="handlePagination"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<el-popconfirm title="是否确定导出Excel?" @confirm="toExcel(1)">
|
<el-popconfirm title="是否确定导出Excel?" @confirm="toExcel()">
|
||||||
<template #reference>
|
<template #reference>
|
||||||
<el-button type="info" plain style="margin-left: 24px"
|
<el-button type="info" plain style="margin-left: 24px"
|
||||||
>导出Excel</el-button
|
>导出Excel</el-button
|
||||||
|
|
Loading…
Reference in New Issue