Commit 0c3578b0 by 张杰

修复导入文件bug

1 parent 89ebfc33
......@@ -7,7 +7,7 @@
<el-button slot="append">选择文件</el-button>
</el-input>
<!-- 隐藏上传文件按钮 开始 -->
<el-upload ref="uploadBox" class="upload_box" :auto-upload="false" :headers="uploadHead" :accept="acceptFile" :data="uploadParams" :action="uploadPath" multiple :limit="1" :show-file-list="false" :on-change="onChange" :on-success="onSuccess" :before-upload="beforeUpload">
<el-upload ref="uploadBox" class="upload_box" :auto-upload="false" :headers="uploadHead" :accept="acceptFile" :data="uploadParams" :action="uploadPath" multiple :show-file-list="false" :on-change="onChange" :on-success="onSuccess" :before-upload="beforeUpload" :on-error="onError" :file-list="fileList">
<el-button type="primary">点击上传</el-button>
</el-upload>
<!-- 隐藏上传文件按钮 end -->
......@@ -66,6 +66,7 @@ export default {
uploadParams: {},
uploadResult: {},
acceptFile: ".xlsx,.xls",
fileList: [],
};
},
mounted() {
......@@ -78,9 +79,13 @@ export default {
},
methods: {
// 监听文件选择
onChange(file) {
console.log("文件:", file);
this.uploadFile = file;
onChange(file, fileList) {
console.log(file);
console.log(fileList);
if (!file.response) {
this.uploadFile = file;
this.fileList = [file];
}
},
// 下载失败文件
......@@ -94,6 +99,11 @@ export default {
this.uploadResult = {};
},
// 文件上传失败
onError(err, file, fileList) {
console.log(err);
},
// 监听文件上传成功
onSuccess(response, file, fileList) {
console.log(response);
......@@ -104,6 +114,8 @@ export default {
showToast({
message: response.message,
});
_this.uploadFile = {};
_this.fileList = [];
return false;
}
this.uploadResult = response.data;
......@@ -113,6 +125,8 @@ export default {
// 上传文档
saveInfo() {
let o = this.uploadFile;
console.log(this.fileList);
console.log(o);
if (!o || !o.name) {
showToast({
message: "请选择文件",
......@@ -121,6 +135,18 @@ export default {
broadcast("cancel-loading");
return false;
}
let list = o.name.split('.')
let acceptFile = this.acceptFile;
let _type = list[list.length-1];
let idx = acceptFile.includes(_type)
if(!idx){
showToast({
message: `导入文件只支持${acceptFile}`,
});
broadcast("cancel-loading");
return false;
}
this.$refs.uploadBox.submit();
},
......
......@@ -329,7 +329,6 @@ export default {
let _this = this;
received("assign-success", this.closeDialog);
received("cancel-loading", function () {
console.log('进入此处')
_this.loading = false;
});
this.init();
......
......@@ -209,7 +209,7 @@ export default {
// 如果是用户
if (data.origin.type == "u") {
GET_USER_VEHICLE_LIST({ uIds: data.id }).then((res) => {
GET_USER_VEHICLE_LIST({ uIds: data.id,receiverId:_this.id }).then((res) => {
_this.ajaxloding = false;
let list = res.data || [];
_this.setList(data, list, checked);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!