Răsfoiți Sursa

实现轮播组选择

Shinohara Haruna 5 luni în urmă
părinte
comite
16aa5a223a
1 a modificat fișierele cu 20 adăugiri și 15 ștergeri
  1. 20 15
      smsb-plus-ui/src/components/CarouselGroupSelector.vue

+ 20 - 15
smsb-plus-ui/src/components/CarouselGroupSelector.vue

@@ -31,7 +31,7 @@
         v-model:limit="queryParams.pageSize" @pagination="getCarouselList" />
       <template #footer>
         <el-button @click="dialogVisible = false">取消</el-button>
-        <el-button type="primary" @click="confirmSelect" :disabled="!currentRow">确定</el-button>
+        <el-button type="primary" @click="confirmSelect">确定</el-button>
       </template>
     </el-dialog>
   </div>
@@ -155,13 +155,16 @@ const handleRowClick = (row: CarouselGroup) => {
 
 // 处理选择变化
 const handleSelectChange = (row: CarouselGroup) => {
-  // 确保只有一个被选中
-  carouselList.value.forEach((item) => {
-    if (item.id !== row.id) {
-      item.selected = false;
-    }
-  });
-  currentRow.value = row.selected ? row : null;
+  if (row.selected) {
+    // 只允许单选,取消其他项
+    carouselList.value.forEach((item) => {
+      if (item !== row) item.selected = false;
+    });
+    currentRow.value = row;
+  } else {
+    // 当前项取消选中
+    currentRow.value = null;
+  }
 };
 
 // 选择轮播组
@@ -179,7 +182,13 @@ const removeGroup = () => {
 
 // 确认选择
 const confirmSelect = () => {
-  if (!currentRow.value) return;
+  if (!currentRow.value) {
+    // 无选中项,清除选中
+    selectedGroup.value = null;
+    emit('update:modelValue', '');
+    dialogVisible.value = false;
+    return;
+  }
 
   // 确保ID是数字类型
   const id = typeof currentRow.value.id === 'string' ? parseInt(currentRow.value.id, 10) : currentRow.value.id;
@@ -189,14 +198,10 @@ const confirmSelect = () => {
     return;
   }
 
-  // 只存储必要的信息
+  // 只存储 id 和 name 字段
   selectedGroup.value = {
     id,
-    name: currentRow.value.name,
-    itemCount: 0,
-    duration: 0,
-    createTime: '',
-    items: []
+    name: currentRow.value.name
   };
 
   // 更新所有行的选中状态