Bladeren bron

Merge branch 'dev' of http://110.41.163.243:9980/kd-aiot/kd-aiot-frontend into dev

yijing 1 jaar geleden
bovenliggende
commit
5808da0e01
1 gewijzigde bestanden met toevoegingen van 41 en 20 verwijderingen
  1. 41 20
      src/views/technology/route/components/user-edit.vue

+ 41 - 20
src/views/technology/route/components/user-edit.vue

@@ -124,9 +124,7 @@
     />
 
     <template v-slot:footer>
-      <el-button type="primary" v-click-once  @click="save">
-        确定
-      </el-button>
+      <el-button type="primary" v-click-once @click="save"> 确定 </el-button>
     </template>
   </ele-modal>
 </template>
@@ -228,25 +226,32 @@
             delete this.form.id;
           }
 
-       
-
           if (this.taskInstanceList.length == 0) {
             this.$message.warning('至少配置一条工序才能保存');
             return;
           }
-          let isFalse = this.hasPropertyEqualToSeven(this.taskInstanceList, 'type');
-          if (isFalse) {
-               let _arr = JSON.parse(JSON.stringify(this.taskInstanceList));
-               _arr.sort((a, b) => a.orderNum - b.orderNum);
-               
-              if(_arr[0].type != 7) {
-                this.$message.warning('有生产准备工序,请将生产准备放在首位');
-                return;
-              }
-
 
+          const isValid = this.validateFieldUniqueness(
+            this.taskInstanceList,
+            'orderNum'
+          );
+          if (!isValid) {
+            return;
           }
 
+          let isFalse = this.hasPropertyEqualToSeven(
+            this.taskInstanceList,
+            'type'
+          );
+          if (isFalse) {
+            let _arr = JSON.parse(JSON.stringify(this.taskInstanceList));
+            _arr.sort((a, b) => a.orderNum - b.orderNum);
+
+            if (_arr[0].type != 7) {
+              this.$message.warning('有生产准备工序,请将生产准备放在首位');
+              return;
+            }
+          }
 
           let param = {
             taskInstanceList: this.taskInstanceList,
@@ -261,24 +266,40 @@
                 this.$message.success(msg);
                 this.updateVisible(false);
                 this.$emit('done');
-              
               }
             })
-            .finally(() => {
-             
-            });
+            .finally(() => {});
         });
       },
 
       hasPropertyEqualToSeven(arr, property) {
         for (let i = 0; i < arr.length; i++) {
-          if (Object.prototype.hasOwnProperty.call(arr[i], property)  && arr[i][property] === 7) {
+          if (
+            Object.prototype.hasOwnProperty.call(arr[i], property) &&
+            arr[i][property] === 7
+          ) {
             return true; // 找到属性等于7的对象
           }
         }
         return false; // 没有找到属性等于7的对象
       },
 
+      validateFieldUniqueness(array, fieldName) {
+        const seenValues = new Set();
+        for (const item of array) {
+          if (!item[fieldName]) {
+            this.$message.warning(` 排序不能为空,`);
+            return false;
+          }
+          if (seenValues.has(item[fieldName])) {
+            this.$message.warning(`排序不能重复,`);
+            return false;
+          }
+          seenValues.add(item[fieldName]);
+        }
+        return true;
+      },
+
       async getVersionList() {
         const res = await pageList({
           pageNum: 1,