Pārlūkot izejas kodu

fix(table): fix table setting error #162

vben 4 gadi atpakaļ
vecāks
revīzija
a2c89d2e84

+ 9 - 1
src/components/Table/src/BasicTable.vue

@@ -102,7 +102,13 @@
       });
 
       const { getLoading, setLoading } = useLoading(getProps);
-      const { getPaginationInfo, getPagination, setPagination } = usePagination(getProps);
+      const {
+        getPaginationInfo,
+        getPagination,
+        setPagination,
+        setShowPagination,
+        getShowPagination,
+      } = usePagination(getProps);
 
       const {
         getRowSelection,
@@ -229,6 +235,8 @@
         getCacheColumns,
         emit,
         updateTableData,
+        setShowPagination,
+        getShowPagination,
         getSize: () => {
           return unref(getBindValues).size as SizeType;
         },

+ 4 - 5
src/components/Table/src/components/settings/ColumnSetting.vue

@@ -211,18 +211,17 @@
           cachePlainOptions.value = columns;
           state.defaultCheckList = checkList;
         } else {
-          const fixedColumns = columns.filter((item) =>
-            Reflect.has(item, 'fixed')
-          ) as BasicColumn[];
+          // const fixedColumns = columns.filter((item) =>
+          //   Reflect.has(item, 'fixed')
+          // ) as BasicColumn[];
 
           unref(plainOptions).forEach((item: BasicColumn) => {
-            const findItem = fixedColumns.find((fCol) => fCol.dataIndex === item.dataIndex);
+            const findItem = columns.find((col: BasicColumn) => col.dataIndex === item.dataIndex);
             if (findItem) {
               item.fixed = findItem.fixed;
             }
           });
         }
-
         state.checkedList = checkList;
       }
 

+ 14 - 2
src/components/Table/src/hooks/usePagination.tsx

@@ -27,13 +27,16 @@ function itemRender({ page, type, originalElement }: ItemRender) {
 export function usePagination(refProps: ComputedRef<BasicTableProps>) {
   const configRef = ref<PaginationProps>({});
 
+  const show = ref(true);
+
   const { t } = useI18n();
   const getPaginationInfo = computed((): PaginationProps | boolean => {
     const { pagination } = unref(refProps);
 
-    if (isBoolean(pagination) && !pagination) {
+    if (!unref(show) || (isBoolean(pagination) && !pagination)) {
       return false;
     }
+
     return {
       current: 1,
       pageSize: PAGE_SIZE,
@@ -60,5 +63,14 @@ export function usePagination(refProps: ComputedRef<BasicTableProps>) {
   function getPagination() {
     return unref(getPaginationInfo);
   }
-  return { getPagination, getPaginationInfo, setPagination };
+
+  function getShowPagination() {
+    return unref(show);
+  }
+
+  async function setShowPagination(flag: boolean) {
+    show.value = flag;
+  }
+
+  return { getPagination, getPaginationInfo, setShowPagination, getShowPagination, setPagination };
 }

+ 6 - 0
src/components/Table/src/hooks/useTable.ts

@@ -121,6 +121,12 @@ export function useTable(
     getForm: () => {
       return unref(formRef) as FormActionType;
     },
+    setShowPagination: async (show: boolean) => {
+      getTableInstance().setShowPagination(show);
+    },
+    getShowPagination: () => {
+      return getTableInstance().getShowPagination();
+    },
   };
 
   return [register, methods];

+ 2 - 0
src/components/Table/src/types/table.ts

@@ -102,6 +102,8 @@ export interface TableActionType {
   getCacheColumns: () => BasicColumn[];
   emit?: EmitType;
   updateTableData: (index: number, key: string, value: any) => Recordable;
+  setShowPagination: (show: boolean) => Promise<void>;
+  getShowPagination: () => boolean;
 }
 
 export interface FetchSetting {