| | |
| | | * @param restoreOrigin |
| | | * @param isTree 是否是 ParentID 构建树的数组 |
| | | * @param isChildTree 是否是 Children 构建的树的数组 |
| | | * @param filterFunc 额外过滤条件 |
| | | * @returns |
| | | */ |
| | | export const useQueryTable = ( |
| | |
| | | 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[]); |
| | | |
| | |
| | | }; |
| | | |
| | | const handleQueryTable = () => { |
| | | if (checkQueryParamsIsEmpty()) { |
| | | const isEmpty = checkQueryParamsIsEmpty(); |
| | | if (isEmpty) { |
| | | return restoreOrigin(); |
| | | } |
| | | const convertData = isChildTree ? flatten(tableData.value) : tableData.value; |
| | |
| | | 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; |
| | |
| | | }; |
| | | |
| | | 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( |