wujingjing
2025-01-02 3b6326a5f7be428657e2252560d10eb09e34eab9
src/hooks/useQueryTable.ts
@@ -10,6 +10,7 @@
 * @param restoreOrigin
 * @param isTree 是否是 ParentID 构建树的数组
 * @param isChildTree 是否是 Children 构建的树的数组
 * @param filterFunc 额外过滤条件
 * @returns
 */
export const useQueryTable = (
@@ -17,7 +18,8 @@
   queryParams: Ref<Object>,
   restoreOrigin: () => void | Promise<void>,
   isTree?: Boolean,
   isChildTree = false
   isChildTree = false,
   filterFunc?:(key:string,item,queryStr:string)=>boolean
) => {
   const displayTableData = ref(null as any[]);
@@ -33,7 +35,8 @@
   };
   const handleQueryTable = () => {
      if (checkQueryParamsIsEmpty()) {
      const isEmpty = checkQueryParamsIsEmpty();
      if (isEmpty) {
         return restoreOrigin();
      }
      const convertData = isChildTree ? flatten(tableData.value) : tableData.value;
@@ -49,7 +52,7 @@
            const toSearchStr = String(item[key]).toLowerCase();
            const searchStr = queryStr.trim().toLowerCase();
            const isMatch = toSearchStr.includes(searchStr);
            return isMatch;
            return isMatch || filterFunc?.(key,item,queryStr);
         });
      });
      displayTableData.value = filterTableData;
@@ -64,7 +67,7 @@
        };
   const checkQueryParamsIsEmpty = () => {
      return Object.values(queryParams.value).every((objectValue) => objectValue === '' || objectValue === null);
      return Object.values(queryParams.value).every((objectValue) => objectValue === '' || objectValue === null || objectValue===undefined);
   };
   watch(