Browse Source

fix: change multiple select

DESKTOP-USV654P\pc 4 months ago
parent
commit
f9b4f7da04

+ 2 - 2
Makefile

@@ -2,7 +2,7 @@
 
 # 记录开始时间
 START_TIME := $(shell powershell -NoProfile -Command "Get-Date -UFormat %%s")
-V_TAG:=v2.1.5
+V_TAG:=v2.1.6
 
 checkDev:
 	git checkout dev
@@ -12,7 +12,7 @@ build:
 
 commit:
 	git add . && \
-	git commit --no-verify -m "fix: change class examine"
+	git commit --no-verify -m "fix: change multiple select"
 
 checkPre:
 	git checkout pre

+ 41 - 8
src/components/MultiplePopup/src/components/MultipleSelect.vue

@@ -43,6 +43,7 @@
           }"
           :pagination="paginationProps"
           :scroll="{ y: '340px' }"
+          :rowKey="props.valueField || props.uniqueKey"
         />
       </a-tab-pane>
       <a-tab-pane key="2" :tab="t('已选记录')" force-render>
@@ -50,6 +51,7 @@
           :dataSource="selectedList"
           :columns="state.selectedColumns"
           :scroll="{ y: '340px' }"
+          :rowKey="props.valueField || props.uniqueKey"
         >
           <template #bodyCell="{ column, record, index }">
             <template v-if="column.key === 'delete'">
@@ -75,6 +77,7 @@
         type: 'radio',
       }"
       :scroll="{ y: '200px' }"
+      :rowKey="props.valueField || props.uniqueKey"
     />
   </a-modal>
 </template>
@@ -251,14 +254,17 @@
     },
   );
   const initData = () => {
+    console.log('props.valueField', props.valueField, props.uniqueKey);
     if (!props.isSubFormUse) {
       state.dataSourceList.map((data: any, index: number) => {
-        data.key = index + 1;
+        const id = data[props.valueField!] || data[props.uniqueKey!];
+        // data.key = index + 1;
         if (props.value) {
           props.selectedDataSource.map((select: any) => {
-            if (data.key === select.key) {
+            const sId = select[props.valueField!] || select[props.uniqueKey!];
+            if (id === sId) {
               selectedList.value.push(data);
-              state.selectedRowKeys.push(data.key);
+              state.selectedRowKeys.push(id);
             }
           });
         }
@@ -266,11 +272,13 @@
     }
     if (props.isSubFormUse) {
       state.dataSourceList.map((data: any, index: number) => {
-        data.key = index + 1;
+        // data.key = index + 1;
+        const id = data[props.valueField!] || data[props.uniqueKey!];
         props.selectedDataSource.map((select: any) => {
-          if (select[props.uniqueKey!] === data[props.valueField!]) {
+          const sId = select[props.valueField!] || select[props.uniqueKey!];
+          if (id === sId) {
             selectedList.value.push(data);
-            state.selectedRowKeys.push(data.key);
+            state.selectedRowKeys.push(id);
           }
         });
       });
@@ -432,6 +440,31 @@
     }
   };
 
+  const removeDuplicate = (tagerData, sourceData, key) => {
+    if (tagerData.length === 0) {
+      tagerData = [...sourceData];
+    } else {
+      sourceData.forEach((item) => {
+        if (key) {
+          const findIndex = tagerData.findIndex(
+            (row) =>
+              (row[props.valueField!] || row[props.uniqueKey!]) ===
+              (item[props.valueField!] || item[props.uniqueKey!]),
+          );
+          if (findIndex < 0) {
+            tagerData.push(item);
+          }
+        } else {
+          const findIndex = tagerData.findIndex((row) => row === item);
+          if (findIndex < 0) {
+            tagerData.push(item);
+          }
+        }
+      });
+    }
+    return tagerData;
+  };
+
   const onSelectChange = (rowKeys, selectedRows) => {
     if (!props.multiple) {
       selectedRows = selectedRows.slice(selectedRows.length - 1);
@@ -439,8 +472,8 @@
       state.selectedRowKeys = rowKeys;
       selectedList.value = selectedRows;
     } else {
-      state.selectedRowKeys = rowKeys;
-      selectedList.value = selectedRows;
+      state.selectedRowKeys = removeDuplicate([...state.selectedRowKeys], [...rowKeys], false);
+      selectedList.value = removeDuplicate([...selectedList.value], [...selectedRows], true);
     }
   };
 

+ 1 - 1
src/views/educational/stdudentBaseManager/components/data.config.ts

@@ -841,7 +841,7 @@ export const schoolRoll: FormSchema[] = [
   {
     field: 'rollNumber',
     label: '学籍号',
-    component: 'InputNumber',
+    component: 'Input',
     // required: true,
     colProps: { span: 7 },
   },