update import

This commit is contained in:
lb
2023-04-17 11:34:12 +08:00
parent 86b99fba43
commit 37371fc023
8 changed files with 76 additions and 96 deletions

View File

@@ -10,7 +10,7 @@
<el-upload
style="margin-top: 24px; text-align: center"
drag
:action="urls.importOrderUrl"
:action="actionUrl"
:headers="uploadHeaders"
:show-file-list="false"
:on-error="handleError"
@@ -24,7 +24,17 @@
</el-upload>
<div slot="footer">
<el-button type="success" @click="handleBtnClick({ name: 'download-template', filename, url })">下载模板</el-button>
<el-button
type="success"
@click="
handleBtnClick({
name: 'download-template',
filename: savedFilename,
url: templateUrl,
})
">
下载模板
</el-button>
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
</div>
</el-dialog>
@@ -40,19 +50,20 @@ export default {
props: {
title: {
type: String,
default: '导入'
default: "导入",
},
hint: {
hint: String,
default: '只能上传 Excel 文件'
default: "只能上传 Excel 文件",
},
filename: {
hint: String,
default: 'default_file.xlsx'
default: "default_file.xlsx",
},
url: { // 下载地址
url: {
// 下载地址
hint: String,
default: '/importTemplates/orderImport.xlsx'
default: "/importTemplates/orderImport.xlsx",
},
configs: {
type: Object,
@@ -75,6 +86,15 @@ export default {
token: Cookies.get("token") || "",
};
},
actionUrl() {
return window.SITE_CONFIG["apiURL"] + this.urls.importUrl;
},
savedFilename() {
return "templateUrl" in this.urls ? this.urls.templateUrl.split("/").pop() : this.filename;
},
templateUrl() {
return "templateUrl" in this.urls ? this.urls.templateUrl : this.url ?? "#";
},
},
methods: {
init(data) {
@@ -91,6 +111,16 @@ export default {
handleSuccess(response, file, fileList) {
// console.log("success response", response);
if ("code" in response && response.code === 500) {
this.$message({
message: response.msg,
type: "error",
duration: 1500,
});
return;
}
let message = "";
let isError = false;
@@ -100,7 +130,7 @@ export default {
message = response;
isError = true;
}
this.handleClose();
this.$message({
@@ -130,7 +160,7 @@ export default {
handleDownloadTemplate(filename, href) {
this.$notify({
title: "提示",
message: "开始下载",
message: "开始下载,请稍后检查浏览器的下载选项或者下载目录",
type: "success",
});