Procházet zdrojové kódy

fix: BsUi自定义搜索方法

hanxiaohui před 5 měsíci
rodič
revize
de3356e9b9
1 změnil soubory, kde provedl 15 přidání a 3 odebrání
  1. 15 3
      src/components/BsUi/Table/index.js

+ 15 - 3
src/components/BsUi/Table/index.js

@@ -102,7 +102,7 @@ export const useBsTable = (options, tableRef) => {
     tableOptions = options;
   }
 
-  const getTableData = () => {
+  const getTableData = (customParams) => {
     tableOptions.tableSearchBeforeBiz && tableOptions.tableSearchBeforeBiz();
     setLoading(true);
     return new Promise(async (resolve, reject) => {
@@ -119,8 +119,9 @@ export const useBsTable = (options, tableRef) => {
         }, 500);
       } else {
 
-        console.log("入参为 =====>", { pageNum, pageSize, ...searchParams })
-        const resData = await getTableDataApi(tableOptions?.url,{ pageNum, pageSize, ...searchParams });
+        const otherParams = !isEmpty(customParams) ? { ...customParams } : {};
+        console.log("入参为 =====>", { pageNum, pageSize, ...searchParams, ...otherParams })
+        const resData = await getTableDataApi(tableOptions?.url,{ pageNum, pageSize, ...searchParams, ...otherParams });
         const { data } = resData;
         setLoading(false);
         setTableData(data.list);
@@ -220,6 +221,15 @@ export const useBsTable = (options, tableRef) => {
     set(tableOptions, 'pagerConfig.enable', visible);
   };
 
+  const refreshTable = async () => {
+    setPageNum(1);
+    await getTableData();
+  }
+
+  const fetchTableData = async (searchParams) => {
+    await getTableData(searchParams);
+  }
+
   return {
     tableOptions,
     onTableMounted,
@@ -228,6 +238,8 @@ export const useBsTable = (options, tableRef) => {
     getTablePropsValue,
     setTableOptions,
     getGridRef,
+    refreshTable,
+    fetchTableData
   };
 };
 export default BsTable;