Преглед изворни кода

优化参照组件,选择数据之后增加会清空id与code

002390 пре 1 година
родитељ
комит
852b88afed
2 измењених фајлова са 27 додато и 33 уклоњено
  1. 11 15
      src/components/popover-select-v2/index.vue
  2. 16 18
      src/components/popover-select/index.vue

+ 11 - 15
src/components/popover-select-v2/index.vue

@@ -84,6 +84,17 @@ export default {
         return this.value;
       },
       set(value) {
+        const {
+          $props: { source, dataMapping },
+        } = this;
+
+        for (let key in dataMapping) {
+          if (dataMapping[key] === "id" || dataMapping[key] === "code") {
+            if (source[key] && source[key] !== "") {
+              source[key] = undefined;
+            }
+          }
+        }
         this.$emit("input", value);
       },
     },
@@ -237,20 +248,6 @@ export default {
         }
       }
     },
-    handleKeyupDel() {
-      console.log("focus");
-      const {
-        $props: { source, dataMapping },
-      } = this;
-
-      for (let key in dataMapping) {
-        if (dataMapping[key] === "id" || dataMapping[key] === "code") {
-          if (source[key] && source[key] !== "") {
-            source[key] = undefined;
-          }
-        }
-      }
-    },
     handleClear() {
       this.innerValue = "";
     },
@@ -284,7 +281,6 @@ export default {
       :fetch-suggestions="useAutocomplete"
       @blur="useBlur"
       @select="useConfirm([$event])"
-      @keyup.delete.native="handleKeyupDel"
       style="width: 100%"
     >
       <i class="el-icon-search" slot="suffix" @click="open"> </i>

+ 16 - 18
src/components/popover-select/index.vue

@@ -109,6 +109,19 @@ export default {
         return multiple ? "" : value;
       },
       set(val) {
+        const {
+          $props: { source, dataMapping, multiple },
+        } = this;
+        if (!multiple) {
+          for (let key in dataMapping) {
+            if (dataMapping[key] === "id" || dataMapping[key] === "code") {
+              if (source[key] && source[key] !== "") {
+                source[key] = undefined;
+              }
+            }
+          }
+        }
+
         this.$emit("input", val);
       },
     },
@@ -127,10 +140,10 @@ export default {
     },
     innerValue: {
       handler: function (newValue) {
+        const {
+          $props: { source, dataMapping, multiple },
+        } = this;
         if (!newValue) {
-          const {
-            $props: { source, dataMapping },
-          } = this;
           for (let key in dataMapping) {
             source[key] = undefined;
           }
@@ -312,20 +325,6 @@ export default {
         }
       }
     },
-    handleKeyupDel() {
-      console.log("focus");
-      const {
-        $props: { source, dataMapping },
-      } = this;
-
-      for (let key in dataMapping) {
-        if (dataMapping[key] === "id" || dataMapping[key] === "code") {
-          if (source[key] && source[key] !== "") {
-            source[key] = undefined;
-          }
-        }
-      }
-    },
   },
   created() {},
   mounted() {},
@@ -359,7 +358,6 @@ export default {
       :fetch-suggestions="useAutocomplete"
       @blur="useBlur"
       @select="useConfirm([$event])"
-      @keyup.delete.native="handleKeyupDel"
       style="width: 100%"
     >
       <i :size="size" class="el-icon-search" slot="suffix" @click="open"> </i>