2 Commits 72673a8503 ... bbd1802c36

Author SHA1 Message Date
  zcuishan bbd1802c36 Merge remote-tracking branch 'origin/dev' into dev 4 months ago
  zcuishan 3700d6fda9 fix:修改多选弹层,修改单表组件 4 months ago

+ 55 - 29
src/components/MultiplePopup/src/components/MultipleSelect.vue

@@ -79,15 +79,16 @@
 </template>
 </template>
 
 
 <script lang="ts" setup>
 <script lang="ts" setup>
-  import { onMounted, watch, reactive, computed, inject, ref } from 'vue';
+  import { computed, inject, nextTick, onMounted, reactive, ref, watch } from 'vue';
   import { cloneDeep } from 'lodash-es';
   import { cloneDeep } from 'lodash-es';
   import { Icon } from '/@/components/Icon';
   import { Icon } from '/@/components/Icon';
   import { getDatasourceById } from '/@/api/system/datasource';
   import { getDatasourceById } from '/@/api/system/datasource';
   import { getDicDetailPageList } from '/@/api/system/dic';
   import { getDicDetailPageList } from '/@/api/system/dic';
   import { isFunction } from '/@/utils/is';
   import { isFunction } from '/@/utils/is';
   import type { ColumnProps } from 'ant-design-vue/lib/table';
   import type { ColumnProps } from 'ant-design-vue/lib/table';
-  import { camelCaseString, apiConfigFunc } from '/@/utils/event/design';
+  import { apiConfigFunc, camelCaseString } from '/@/utils/event/design';
   import { useI18n } from '/@/hooks/web/useI18n';
   import { useI18n } from '/@/hooks/web/useI18n';
+
   const { t } = useI18n();
   const { t } = useI18n();
   const props = defineProps({
   const props = defineProps({
     multipleDialog: { type: Boolean },
     multipleDialog: { type: Boolean },
@@ -136,6 +137,9 @@
     if (props.isSubFormUse) {
     if (props.isSubFormUse) {
       await getDatasourceList(1);
       await getDatasourceList(1);
     }
     }
+    await nextTick(() => {
+      console.log(props.selectedDataSource);
+    });
   });
   });
 
 
   const state = reactive({
   const state = reactive({
@@ -209,44 +213,66 @@
       immediate: true,
       immediate: true,
     },
     },
   );
   );
-
+  watch(
+    () => props.multipleDialog,
+    () => {
+      if (props.multipleDialog) {
+        selectedList.value = [];
+        state.selectedRowKeys = [];
+        initData();
+      } else {
+        selectedList.value = [];
+        state.selectedRowKeys = [];
+      }
+    },
+  );
   watch(
   watch(
     () => [state.dataSourceList, props.selectedDataSource, props.value],
     () => [state.dataSourceList, props.selectedDataSource, props.value],
     () => {
     () => {
       emit('getList', state.dataSourceList);
       emit('getList', state.dataSourceList);
       if (!state.dataSourceList.length) return;
       if (!state.dataSourceList.length) return;
-      selectedList.value = [];
-      state.selectedRowKeys = [];
-      if (!props.isSubFormUse) {
-        state.dataSourceList.map((data: any, index: number) => {
-          data.key = index + 1;
-          if (props.value) {
-            props.selectedDataSource.map((select: any) => {
-              if (data.key === select.key) {
-                selectedList.value.push(data);
-                state.selectedRowKeys.push(data.key);
-              }
-            });
-          }
-        });
-      }
-      if (props.isSubFormUse) {
-        state.dataSourceList.map((data: any, index: number) => {
-          data.key = index + 1;
+      initData();
+      const seenIds = new Map();
+      selectedList.value = selectedList.value.filter((item) => {
+        const id = item[props.valueField!] || item[props.uniqueKey!];
+        if (!seenIds.has(id)) {
+          seenIds.set(id, true);
+          return true;
+        }
+        return false;
+      });
+      state.selectedRowKeys = [...new Set(state.selectedRowKeys)];
+    },
+    {
+      deep: true,
+    },
+  );
+  const initData = () => {
+    if (!props.isSubFormUse) {
+      state.dataSourceList.map((data: any, index: number) => {
+        data.key = index + 1;
+        if (props.value) {
           props.selectedDataSource.map((select: any) => {
           props.selectedDataSource.map((select: any) => {
-            if (select[props.uniqueKey!] === data[props.valueField!]) {
+            if (data.key === select.key) {
               selectedList.value.push(data);
               selectedList.value.push(data);
               state.selectedRowKeys.push(data.key);
               state.selectedRowKeys.push(data.key);
             }
             }
           });
           });
+        }
+      });
+    }
+    if (props.isSubFormUse) {
+      state.dataSourceList.map((data: any, index: number) => {
+        data.key = index + 1;
+        props.selectedDataSource.map((select: any) => {
+          if (select[props.uniqueKey!] === data[props.valueField!]) {
+            selectedList.value.push(data);
+            state.selectedRowKeys.push(data.key);
+          }
         });
         });
-      }
-    },
-    {
-      deep: true,
-    },
-  );
-
+      });
+    }
+  };
   const resetSearch = () => {
   const resetSearch = () => {
     state.searchText = '';
     state.searchText = '';
     getDatasourceList(1);
     getDatasourceList(1);

+ 1 - 2
src/views/form/template/index.vue

@@ -333,6 +333,7 @@
         },
         },
         schemas: searchFormSchema,
         schemas: searchFormSchema,
       },
       },
+      bordered: true,
       beforeFetch: (pageParams) => {
       beforeFetch: (pageParams) => {
         //发送请求默认新增  左边树结构所选机构id
         //发送请求默认新增  左边树结构所选机构id
         const newParams = {
         const newParams = {
@@ -927,8 +928,6 @@
 
 
       return handleSearchForm(option, schema, config, isNeedTrans, false) as FormSchema;
       return handleSearchForm(option, schema, config, isNeedTrans, false) as FormSchema;
     });
     });
-    console.log(searchFormSchema);
-
     return [searchFormSchema, searchDate];
     return [searchFormSchema, searchDate];
   }
   }