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 { 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 拦截器

View File

@ -1,52 +1,54 @@
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;
},
remove(table) {
return localStorage.removeItem(table);
},
clear() {
return localStorage.clear();
} }
} return data;
},
remove(table) {
return localStorage.removeItem(table);
},
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) => {
console.log(url,params); console.log(url, params);
let store = useLoadingStore(); let store = useLoadingStore();
store.isLoading = true; store.isLoading = true;
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,13 +65,18 @@ tool.downloadFile = (url,params) => {
a.click(); a.click();
window.URL.revokeObjectURL(Url); window.URL.revokeObjectURL(Url);
store.isLoading = false; store.isLoading = false;
}) } else {
.catch((err) => { console.log(response.data);
console.log(err, "err");
store.isLoading = false; store.isLoading = false;
}); ElMessage.warning({
}; message: response.data.message,
});
}
export default tool })
.catch((err) => {
console.log(err, "err");
store.isLoading = false;
});
};
export default tool;

View File

@ -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