This commit is contained in:
duanxiaohai 2024-11-01 10:41:33 +08:00
parent 9fab544136
commit 724653b5fa
3 changed files with 56 additions and 49 deletions

View File

@ -2,7 +2,7 @@ import axios from "axios";
import { ElMessage } from "element-plus";
import tools from "@/utils/tools";
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;
// HTTP request 拦截器
@ -81,7 +81,7 @@ var http = {
.get(url, {
params: params,
})
.then((response) => {
.then((response) => {
if (response.data.code == 400 && response.data.msg) {
ElMessage.error(response.data.msg);
}

View File

@ -1,52 +1,54 @@
import axios from "axios";
import { useLoadingStore } from "@/stores/loading.js";
import { ElMessage } from "element-plus";
var tool = {}
var tool = {};
/* localStorage */
tool.data = {
set(table, settings) {
var _set = JSON.stringify(settings)
return localStorage.setItem(table, _set);
},
get(table) {
var data = localStorage.getItem(table);
try {
data = JSON.parse(data)
} catch (err) {
return null
}
return data;
},
remove(table) {
return localStorage.removeItem(table);
},
clear() {
return localStorage.clear();
set(table, settings) {
var _set = JSON.stringify(settings);
return localStorage.setItem(table, _set);
},
get(table) {
var data = localStorage.getItem(table);
try {
data = JSON.parse(data);
} catch (err) {
return null;
}
}
return data;
},
remove(table) {
return localStorage.removeItem(table);
},
clear() {
return localStorage.clear();
},
};
tool.url = function (url, params) {
var hasParams = url.indexOf("?") > 0;
for (var key in params) {
url = url + (hasParams ? '&' : '?') + key + '=' + params[key];
hasParams = true;
}
return url;
}
var hasParams = url.indexOf("?") > 0;
for (var key in params) {
url = url + (hasParams ? "&" : "?") + key + "=" + params[key];
hasParams = true;
}
return url;
};
// 文件下载token放请求头中
tool.downloadFile = (url,params) => {
console.log(url,params);
let store = useLoadingStore();
store.isLoading = true;
axios
.get(url, {
headers: { token: JSON.parse(localStorage.getItem("token")) },
responseType: "blob",
params
})
.then((response) => {
tool.downloadFile = (url, params) => {
console.log(url, params);
let store = useLoadingStore();
store.isLoading = true;
axios
.get(url, {
headers: { token: JSON.parse(localStorage.getItem("token")) },
// responseType: "blob",
params,
})
.then((response) => {
if (!response.data.code) {
let blob = new Blob([response.data], {
//这里的type要和后端一致
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
@ -63,13 +65,18 @@ tool.downloadFile = (url,params) => {
a.click();
window.URL.revokeObjectURL(Url);
store.isLoading = false;
})
.catch((err) => {
console.log(err, "err");
} else {
console.log(response.data);
store.isLoading = false;
});
};
export default tool
ElMessage.warning({
message: response.data.message,
});
}
})
.catch((err) => {
console.log(err, "err");
store.isLoading = false;
});
};
export default tool;

View File

@ -206,7 +206,7 @@
@current-change="handlePagination"
/>
</div>
<el-popconfirm title="是否确定导出Excel?" @confirm="toExcel(1)">
<el-popconfirm title="是否确定导出Excel?" @confirm="toExcel()">
<template #reference>
<el-button type="info" plain style="margin-left: 24px"
>导出Excel</el-button