Commit 3788401c authored by yf's avatar yf

修改通用下载方法,新增导出

parent 1a476940
......@@ -61,46 +61,46 @@ service.interceptors.request.use(config => {
}
return config
}, error => {
console.log(error)
Promise.reject(error)
console.log(error)
Promise.reject(error)
})
// 响应拦截器
service.interceptors.response.use(res => {
// 未设置状态码则默认成功状态
const code = res.data.code || 200;
// 获取错误信息
const msg = errorCode[code] || res.data.msg || errorCode['default']
// 二进制数据则直接返回
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
return res.data
}
if (code === 401) {
if (!isRelogin.show) {
isRelogin.show = true;
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
isRelogin.show = false;
store.dispatch('LogOut').then(() => {
location.href = '/index';
})
// 未设置状态码则默认成功状态
const code = res.data.code || 200;
// 获取错误信息
const msg = errorCode[code] || res.data.msg || errorCode['default']
// 二进制数据则直接返回
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
return res
}
if (code === 401) {
if (!isRelogin.show) {
isRelogin.show = true;
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
isRelogin.show = false;
store.dispatch('LogOut').then(() => {
location.href = '/index';
})
}).catch(() => {
isRelogin.show = false;
});
}
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
} else if (code === 500) {
Message({ message: msg, type: 'error' })
return Promise.reject(new Error(msg))
} else if (code === 601) {
Message({ message: msg, type: 'warning' })
return Promise.reject('error')
} else if (code !== 200) {
Notification.error({ title: msg })
return Promise.reject('error')
} else {
return res.data
}
},
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
} else if (code === 500) {
Message({ message: msg, type: 'error' })
return Promise.reject(new Error(msg))
} else if (code === 601) {
Message({ message: msg, type: 'warning' })
return Promise.reject('error')
} else if (code !== 200) {
Notification.error({ title: msg })
return Promise.reject('error')
} else {
return res.data
}
},
error => {
console.log('err' + error)
let { message } = error;
......@@ -124,7 +124,12 @@ export function download(url, params, filename, config) {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
responseType: 'blob',
...config
}).then(async (data) => {
}).then(async (response) => {
var data = response.data;
if (!filename) {
filename = decodeURIComponent(response.headers["content-disposition"].split(';')[1].split('filename=')[1]);
console.log(filename);
}
const isBlob = blobValidate(data);
if (isBlob) {
const blob = new Blob([data])
......
......@@ -85,7 +85,11 @@
>
</el-form-item>
</el-form> -->
<el-button
style="margin-bottom: 10px"
@click="downList(InfoList.detailsDto.id)"
>导 出</el-button
>
<el-table v-loading="loading" :data="listList">
<!-- <el-table-column type="selection" width="55" align="center" /> -->
<el-table-column type="index" width="50" />
......@@ -173,7 +177,7 @@
<el-table-column label="所属建筑" align="center" prop="name" />
<el-table-column label="所属承租户" align="center" prop="type" />
<el-table-column label="操作" align="center" prop="describe">
<template slot-scope="scope">
<template>
<div>
<el-button size="mini" type="text" icon="el-icon-download"
>下载</el-button
......@@ -252,6 +256,9 @@ export default {
this.getRiskList(this.$route.params.id);
},
methods: {
downList(planId) {
this.download("/system/risk/plan/exportExcel/InherentList/" + planId, {});
},
showDrawCanvas(floorId) {
this.$router.push({
name: "drawCanvas",
......@@ -273,11 +280,7 @@ export default {
},
exportList(id) {
console.log(id, "kkkk");
this.download(
"system/risk/plan/exportWord/riskNotification/" + id,
{},
`风险告知卡.docx`
);
this.download("system/risk/plan/exportWord/riskNotification/" + id, {});
},
},
handleClick() {},
......
......@@ -35,7 +35,7 @@ module.exports = {
proxy: {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `http://192.168.4.232:8080`, //服务器地址
target: `http://localhost:8080`, //服务器地址
// target: `http://192.168.15.230:8081`, //晓晋本地地址
changeOrigin: true,
pathRewrite: {
......@@ -125,10 +125,10 @@ module.exports = {
});
config.optimization.runtimeChunk("single"),
{
from: path.resolve(__dirname, "./public/robots.txt"), //防爬虫文件
to: "./", //到根目录下
};
{
from: path.resolve(__dirname, "./public/robots.txt"), //防爬虫文件
to: "./", //到根目录下
};
});
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment