Просмотр исходного кода

refactor(规则模型): 优化编辑条件的逻辑并修复范围验证

- 将 `editCondition` 方法修改为接收 `index` 参数,以便在编辑时直接定位条件
- 修复 `speedRange` 和 `volumeRange` 的验证逻辑,确保范围值为非负数
- 移除冗余代码,简化条件保存逻辑
闪电 месяцев назад: 8
Родитель
Сommit
f231d6f623
1 измененных файлов с 19 добавлено и 20 удалено
  1. 19 20
      src/views/rules/models.vue

+ 19 - 20
src/views/rules/models.vue

@@ -187,7 +187,7 @@
187 187
               <el-table-column prop="score" label="分值" width="100" />
188 188
               <el-table-column label="操作" fixed="right" width="120">
189 189
                 <template #default="{ row, $index }">
190
-                  <el-button type="primary" :icon="Edit" circle class="mr-2" @click="editCondition(row)" />
190
+                  <el-button type="primary" :icon="Edit" circle class="mr-2" @click="editCondition($index, row)" />
191 191
                   <el-button type="danger" :icon="Delete" circle @click="deleteCondition($index, row)" />
192 192
                 </template>
193 193
               </el-table-column>
@@ -267,8 +267,8 @@ const getCases = async () => {
267 267
         operation: item.scoreType + '',
268 268
         warning: item.isAlert === 1,
269 269
         fatal: item.isCritical === 1,
270
-        speedRange: [item.minValue, item.maxValue],
271
-        volumeRange: [item.minValue, item.maxValue],
270
+        speedRange: (item.minValue >=0 && item.maxValue>=0) ? [item.minValue, item.maxValue] : [],
271
+        volumeRange: (item.minValue >=0 && item.maxValue>=0) ? [item.minValue, item.maxValue] : [],
272 272
       }
273 273
     });
274 274
   }
@@ -324,6 +324,7 @@ const conditionForm: any = ref({
324 324
 });
325 325
 
326 326
 const addCondition = async () => {
327
+  editIndex.value = -1;
327 328
   getModelCases();
328 329
   getWords();
329 330
   showConditionDrawer.value = true;
@@ -342,13 +343,16 @@ const addCondition = async () => {
342 343
     keywords: [],
343 344
   };
344 345
 };
345
-const editCondition = async (row: any) => {
346
+
347
+const editIndex = ref(-1);
348
+const editCondition = async (index: number, row: any) => {
346 349
   console.log('editCondition', row)
347 350
   await getWords();
348 351
   
349 352
   await getModelCases(row.type);
350 353
   nextTick(() => {
351 354
     showConditionDrawer.value = true;
355
+    editIndex.value = index;
352 356
     conditionForm.value = row;
353 357
     console.log('conditionForm.value', row)
354 358
     conditionForm.value.keywords = row.keywords?.length ? row.keywords.split(',').map(o => Number(o)) : [];
@@ -428,14 +432,6 @@ const conditionTypes = ref([
428 432
   //   Condition: ["开场白", "结束语"],
429 433
   //   name: "基础检测"
430 434
   // },
431
-  // {
432
-  //   Condition: ["清晰度", "打断客户", "答复不清", "脏话辱骂"],
433
-  //   name: "服务态度检测"
434
-  // },
435
-  // {
436
-  //   Condition: ["音量", "语速"],
437
-  //   name: "通话质量检测"
438
-  // }
439 435
 ]);
440 436
 
441 437
 const conditionOptions = ref<string[]>([]);
@@ -466,22 +462,25 @@ const saveCondition = async () => {
466 462
       fatal: conditionForm.value.fatal,
467 463
       frequency: conditionForm.value.frequency,
468 464
       score: conditionForm.value.score,
465
+      volumeRange: conditionForm.value.volumeRange,
466
+      speedRange: conditionForm.value.speedRange,
469 467
     };
470 468
 
471 469
     // 如果是编辑模式,找到原条件并更新
472
-    const existingIndex = currentModel.value.conditions.findIndex(
473
-      (item: any) =>
474
-        item.type === conditionForm.value.type &&
475
-        item.name === conditionForm.value.name
476
-    );
477
-
478
-    if (existingIndex !== -1) {
479
-      currentModel.value.conditions[existingIndex] = condition;
470
+    // const existingIndex = currentModel.value.conditions.findIndex(
471
+    //   (item: any) =>
472
+    //     item.type === conditionForm.value.type &&
473
+    //     item.name === conditionForm.value.name
474
+    // );
475
+
476
+    if (editIndex.value >= 0) {
477
+      currentModel.value.conditions[editIndex.value] = condition;
480 478
     } else {
481 479
       currentModel.value.conditions.push(condition);
482 480
     }
483 481
 
484 482
     showConditionDrawer.value = false;
483
+    editIndex.value = -1;
485 484
   } catch (error) {
486 485
     console.log('表单验证失败:', error);
487 486
     return;