From bb66fcc56438b9f123ee4029f807f672b8baede5 Mon Sep 17 00:00:00 2001
From: luobisheng <727299681@qq.com>
Date: 星期一, 28 十一月 2022 17:40:28 +0800
Subject: [PATCH] 上传图片等修改

---
 src/views/operate/images/updateUser/index.vue |   38 +++++++++++++-------------------------
 1 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/views/operate/images/updateUser/index.vue b/src/views/operate/images/updateUser/index.vue
index f326791..309a684 100644
--- a/src/views/operate/images/updateUser/index.vue
+++ b/src/views/operate/images/updateUser/index.vue
@@ -24,16 +24,7 @@
             <el-input v-model="imagedata.id"></el-input>
           </el-form-item>
           <el-form-item prop="url" label="鍥剧墖:" min-width="8">
-            <el-upload
-                class="avatar-uploader"
-                action=""
-                ref="image"
-                :show-file-list="false"
-                :auto-upload="true"
-                :http-request="imageUpload">
-              <img v-if="imagedata.url" :src="imagedata.url" class="avatar" width="100px" height="100px">
-              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
-            </el-upload>
+            <my-upload :picture-list="imageList" :is-show-upload="dialogType !== 'view'" @setPictureUrl="setPictureUrl" @delPictureUrl="delPictureUrl"></my-upload>
           </el-form-item>
           <div v-if="!isDisabled" class="optionBtn">
             <el-button type="primary" class="btn submit" @click.native.prevent="onSubmit">鎻愪氦</el-button>
@@ -47,8 +38,10 @@
 import { deepClone, RESOURCE_TYPE } from "@/utils/helper";
 import imageManagement from "@/api/operate/imageManagement";
 import { FILE_ORIGINAL_URL } from "@/utils";
+import MyUpload from "@/components/myUpload";
 
 export default {
+  components: { MyUpload },
   data() {
     const validateImageUrl = (rule, value, callback) => {
       if (this.imagedata.url) {
@@ -76,14 +69,15 @@
         url: [{ required: true, validator: validateImageUrl }],
         type: [{ required: true, trigger: ['blur', 'change'], message: '璇烽�夋嫨绫诲瀷' }]
       },
-      isDisabled: false
+      isDisabled: false,
+      imageList: []
     }
   },
 
   created() {
     this.imagedata = deepClone(this.originalData);
     if (this.dialogType !== 'create') {
-      this.imagedata.url = this.imagedata.url.split(',')[0];
+      this.imageList = this.imagedata.url.split(',');
     }
     this.isDisabled = this.dialogType === 'view';
   },
@@ -117,19 +111,13 @@
         }
       })
     },
-    imageUpload(file) {
-      const formData = new FormData();
-      formData.append('file', file.file);
-      imageManagement.importImage(formData)
-          .then(res => {
-            this.$refs.image.clearFiles();
-            this.$set(this.imagedata, 'url', FILE_ORIGINAL_URL + res.url1);
-            this.$message.success('涓婁紶鎴愬姛');
-          })
-          .catch(err => {
-            this.$message.error(`${err}`);
-            this.$refs.image.clearFiles();
-          })
+    setPictureUrl({ url }) {
+      this.imageList.push(`${FILE_ORIGINAL_URL}${url}`);
+      this.imagedata.url = this.imageList.join(',');
+    },
+    delPictureUrl({ url }) {
+      this.imageList = this.imageList.filter(item => item !== url);
+      this.imagedata.url = this.imageList.join(',');
     },
     getResourceType(value) {
       return value ? RESOURCE_TYPE.find(item => item.value === value) : RESOURCE_TYPE;

--
Gitblit v1.8.0