From 8a5227c2e5a898004eda1f61180e076ec089fe85 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期二, 29 十一月 2022 10:34:42 +0800
Subject: [PATCH] 图片显示优化

---
 src/views/operate/images/updateUser/index.vue |  168 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 114 insertions(+), 54 deletions(-)

diff --git a/src/views/operate/images/updateUser/index.vue b/src/views/operate/images/updateUser/index.vue
index 309a684..38cc177 100644
--- a/src/views/operate/images/updateUser/index.vue
+++ b/src/views/operate/images/updateUser/index.vue
@@ -2,19 +2,36 @@
   <div class="updateUser">
     <main>
       <div class="mainContent">
-        <el-form label-position="right" label-width="150px"  :model="imagedata" :rules="rules" :disabled="isDisabled" ref="user" style="width: 100%;">
+        <el-form
+          label-position="right"
+          label-width="150px"
+          :model="imagedata"
+          :rules="rules"
+          :disabled="isDisabled"
+          ref="user"
+          style="width: 100%"
+        >
           <el-form-item prop="belongToId" label="鎵�灞炰簨浠剁紪鍙�">
-            <el-input v-model="imagedata.belongToId"></el-input>
+            <el-input v-model="imagedata.code"></el-input>
           </el-form-item>
           <el-form-item prop="eventSource" label="浜嬩欢鏉ユ簮">
-            <el-input v-model="imagedata.eventSource"></el-input>
+            <el-input
+              v-model="getEventSource(imagedata.eventSource).label"
+            ></el-input>
           </el-form-item>
           <el-form-item prop="category" label="闂绫诲埆">
-            <el-input v-model="imagedata.category"></el-input>
+            <el-input
+              v-model="getCategory(imagedata.category).label"
+            ></el-input>
           </el-form-item>
           <el-form-item prop="type" label="绫诲瀷">
             <el-select v-model="imagedata.type">
-              <el-option v-for="item in getResourceType()" :key="item.value" :label="item.label" :value="item.value" />
+              <el-option
+                v-for="item in getResourceType()"
+                :key="item.value"
+                :label="item.label"
+                :value="item.value"
+              />
             </el-select>
           </el-form-item>
           <el-form-item prop="regionName" label="绀惧尯鍚嶇О">
@@ -24,10 +41,20 @@
             <el-input v-model="imagedata.id"></el-input>
           </el-form-item>
           <el-form-item prop="url" label="鍥剧墖:" min-width="8">
-            <my-upload :picture-list="imageList" :is-show-upload="dialogType !== 'view'" @setPictureUrl="setPictureUrl" @delPictureUrl="delPictureUrl"></my-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>
+            <el-button
+              type="primary"
+              class="btn submit"
+              @click.native.prevent="onSubmit"
+              >鎻愪氦</el-button
+            >
           </div>
         </el-form>
       </div>
@@ -35,7 +62,12 @@
   </div>
 </template>
 <script>
-import { deepClone, RESOURCE_TYPE } from "@/utils/helper";
+import {
+  deepClone,
+  RESOURCE_TYPE,
+  CATEGOTY,
+  EVENT_SOURCE,
+} from "@/utils/helper";
 import imageManagement from "@/api/operate/imageManagement";
 import { FILE_ORIGINAL_URL } from "@/utils";
 import MyUpload from "@/components/myUpload";
@@ -47,43 +79,59 @@
       if (this.imagedata.url) {
         callback();
       } else {
-        callback(new Error('璇蜂笂浼犲浘鐗�'));
+        callback(new Error("璇蜂笂浼犲浘鐗�"));
       }
     };
     return {
       imagedata: {
-        belongToId: '',
-        eventSource: '',
-        regionName: '',
-        category: '',
-        id: '',
-        url: '',
-        type: ''
+        belongToId: "",
+        eventSource: 1,
+        regionName: "",
+        category: 1,
+        id: "",
+        url: "",
+        type: "",
       },
       rules: {
-        belongToId: [{ required: true, trigger: 'blur', message: '璇疯緭鍏ユ墍灞炰簨浠剁紪鍙�' }],
-        eventSource: [{ required: true, trigger: 'blur', message: '璇疯緭鍏ヤ簨浠舵潵婧�' }],
-        regionName: [{ required: true, trigger: 'blur', message: '璇疯緭鍏ョぞ鍖哄悕绉�' }],
-        id: [{ required: true, trigger: 'blur', message: '璇疯緭鍏ュ浘鐗嘔d' }],
-        category: [{ required: true, trigger: 'blue', message: '璇疯緭鍏ラ棶棰樼被鍨�' }],
+        belongToId: [
+          { required: true, trigger: "blur", message: "璇疯緭鍏ユ墍灞炰簨浠剁紪鍙�" },
+        ],
+        eventSource: [
+          { required: true, trigger: "blur", message: "璇疯緭鍏ヤ簨浠舵潵婧�" },
+        ],
+        regionName: [
+          { required: true, trigger: "blur", message: "璇疯緭鍏ョぞ鍖哄悕绉�" },
+        ],
+        id: [{ required: true, trigger: "blur", message: "璇疯緭鍏ュ浘鐗嘔d" }],
+        category: [
+          { required: true, trigger: "blue", message: "璇疯緭鍏ラ棶棰樼被鍨�" },
+        ],
         url: [{ required: true, validator: validateImageUrl }],
-        type: [{ required: true, trigger: ['blur', 'change'], message: '璇烽�夋嫨绫诲瀷' }]
+        type: [
+          {
+            required: true,
+            trigger: ["blur", "change"],
+            message: "璇烽�夋嫨绫诲瀷",
+          },
+        ],
       },
       isDisabled: false,
-      imageList: []
-    }
+      imageList: [],
+    };
   },
 
   created() {
-    this.imagedata = deepClone(this.originalData);
-    if (this.dialogType !== 'create') {
-      this.imageList = this.imagedata.url.split(',');
+    if (this.originalData) {
+      this.imagedata = deepClone(this.originalData);
     }
-    this.isDisabled = this.dialogType === 'view';
+    if (this.dialogType !== "create") {
+      this.imageList = this.imagedata.url.split(",");
+    }
+    this.isDisabled = this.dialogType === "view";
   },
   methods: {
     onSubmit() {
-      this.$refs.user.validate(valid => {
+      this.$refs.user.validate((valid) => {
         if (valid) {
           const params = Object.assign({}, this.imagedata);
           delete params.regionName;
@@ -91,48 +139,59 @@
           delete params.eventSource;
           delete params.id;
           params.belongToId = +params.belongToId;
-          if (this.dialogType === 'create') {
-            imageManagement.addImageResource(params)
-                .then(() => {
-                  this.$message.success('鎿嶄綔鎴愬姛');
-                  this.$emit('closeDialog');
-                })
-                .catch(err => this.$message.error(`${err}`))
+          if (this.dialogType === "create") {
+            imageManagement
+              .addImageResource(params)
+              .then(() => {
+                this.$message.success("鎿嶄綔鎴愬姛");
+                this.$emit("closeDialog");
+              })
+              .catch((err) => this.$message.error(`${err}`));
           } else {
-            imageManagement.updateImageResource(params)
-                .then(() => {
-                  this.$message.success('鎿嶄綔鎴愬姛');
-                  this.$emit('closeDialog');
-                })
-                .catch(err => this.$message.error(`${err}`))
+            imageManagement
+              .updateImageResource(params)
+              .then(() => {
+                this.$message.success("鎿嶄綔鎴愬姛");
+                this.$emit("closeDialog");
+              })
+              .catch((err) => this.$message.error(`${err}`));
           }
         } else {
-          this.$message.warning('璇锋鏌ュ繀濉」');
+          this.$message.warning("璇锋鏌ュ繀濉」");
         }
-      })
+      });
     },
     setPictureUrl({ url }) {
       this.imageList.push(`${FILE_ORIGINAL_URL}${url}`);
-      this.imagedata.url = this.imageList.join(',');
+      this.imagedata.url = this.imageList.join(",");
     },
     delPictureUrl({ url }) {
-      this.imageList = this.imageList.filter(item => item !== url);
-      this.imagedata.url = this.imageList.join(',');
+      this.imageList = this.imageList.filter((item) => item !== url);
+      this.imagedata.url = this.imageList.join(",");
+    },
+    getCategory(value) {
+      return CATEGOTY.find((item) => item.value === value);
+    },
+
+    getEventSource(value) {
+      return EVENT_SOURCE.find((item) => item.value === value);
     },
     getResourceType(value) {
-      return value ? RESOURCE_TYPE.find(item => item.value === value) : RESOURCE_TYPE;
-    }
+      return value
+        ? RESOURCE_TYPE.find((item) => item.value === value)
+        : RESOURCE_TYPE;
+    },
   },
   props: {
     originalData: {
       type: Object,
-      default: () => null
+      default: () => null,
     },
     dialogType: {
       type: String,
-      default: () => 'create'
-    }
-  }
+      default: () => "create",
+    },
+  },
 };
 </script>
 <style lang="scss" scoped>
@@ -281,7 +340,8 @@
   color: red;
 }
 
-.el-input, .el-select {
+.el-input,
+.el-select {
   width: 280px !important;
 }
 </style>
\ No newline at end of file

--
Gitblit v1.8.0