lrf402788946 4 lat temu
rodzic
commit
6260d9887a
1 zmienionych plików z 14 dodań i 1 usunięć
  1. 14 1
      src/components/frame/e-upload.vue

+ 14 - 1
src/components/frame/e-upload.vue

@@ -10,6 +10,7 @@
       :on-preview="onPreview"
       :limit="limit"
       :on-exceed="onExceed"
+      :before-remove="beforeRemove"
     >
       <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
     </el-upload>
@@ -27,6 +28,8 @@ export default {
     type: { type: String, default: 'picture-card' },
     fileList: { type: Array },
     limit: { type: Number },
+    remove: { type: Function },
+    extra: { type: Object, default: () => {} },
   },
   model: {
     prop: 'fileList',
@@ -44,10 +47,20 @@ export default {
       const res = await axios.post(this.url, formdata, { headers: { 'Content-Type': 'multipart/form-data' } });
       if (res.status === 200 && res.data.errcode == 0) {
         const { id, name, uri } = res.data;
-        const obj = { url: uri, name };
+        const obj = { url: uri, name: file.name, ...this.extra, uid: id };
         this.fileList.push(obj);
       }
     },
+    beforeRemove(file) {
+      if (this.remove && _.isFunction(this.remove)) {
+        const { result, msg } = this.remove(file);
+        if (!result) {
+          this.$message.error(msg);
+          return false;
+        }
+      }
+      return true;
+    },
     onRemove(file) {
       const index = this.fileList.findIndex(f => f.url === file.url);
       this.fileList.splice(index, 1);