|
@@ -4,13 +4,20 @@ import { PageContentInstance } from "/@/components/PageContent";
|
|
|
import { FormConfig } from "/@/components/PageSearch";
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
|
-type Fn = (params?: any) => any
|
|
|
+type Fn = (params?: any) => any;
|
|
|
|
|
|
-export function usePageSearch(searchCallback?: Fn, resetCallback?: Fn, searchFormConfig?: FormConfig) {
|
|
|
+export function usePageSearch(
|
|
|
+ searchCallback?: Fn,
|
|
|
+ resetCallback?: Fn,
|
|
|
+ searchFormConfig?: FormConfig
|
|
|
+) {
|
|
|
const pageContentRef = ref<PageContentInstance>(null);
|
|
|
+ let searchParam = {};
|
|
|
|
|
|
function handleSearchClick(params: any) {
|
|
|
- const { result, deleteProps } = searchCallback ? searchCallback(params) : { result: {}, deleteProps: [] }
|
|
|
+ const { result, deleteProps } = searchCallback
|
|
|
+ ? searchCallback(params)
|
|
|
+ : { result: {}, deleteProps: [] };
|
|
|
|
|
|
const mergeParams = {
|
|
|
...params,
|
|
@@ -27,34 +34,43 @@ export function usePageSearch(searchCallback?: Fn, resetCallback?: Fn, searchFor
|
|
|
const { startProp, endProp } = otherOptions;
|
|
|
|
|
|
if (startProp || endProp) {
|
|
|
- mergeParams[startProp] = mergeParams[field][0] ? dayjs(mergeParams[field][0]).format('YYYY-MM-DD hh:mm:ss') : "";
|
|
|
- mergeParams[endProp] = mergeParams[field][1] ? dayjs(mergeParams[field][1]).format('YYYY-MM-DD hh:mm:ss') : "";
|
|
|
- delete mergeParams[field]
|
|
|
+ mergeParams[startProp] = mergeParams[field][0]
|
|
|
+ ? dayjs(mergeParams[field][0]).format("YYYY-MM-DD hh:mm:ss")
|
|
|
+ : "";
|
|
|
+ mergeParams[endProp] = mergeParams[field][1]
|
|
|
+ ? dayjs(mergeParams[field][1]).format("YYYY-MM-DD hh:mm:ss")
|
|
|
+ : "";
|
|
|
+ delete mergeParams[field];
|
|
|
}
|
|
|
|
|
|
if (type_field) {
|
|
|
mergeParams[mergeParams[type_field]] = mergeParams[field];
|
|
|
delete mergeParams[field];
|
|
|
- delete mergeParams[type_field]
|
|
|
+ delete mergeParams[type_field];
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- deleteProps.forEach(key => delete mergeParams[key])
|
|
|
-
|
|
|
+ deleteProps.forEach(key => delete mergeParams[key]);
|
|
|
+ searchParam = mergeParams;
|
|
|
pageContentRef.value?.getPageData(mergeParams);
|
|
|
}
|
|
|
|
|
|
function handleResetClick(params: any) {
|
|
|
- const { result } = searchCallback ? searchCallback(params) : { result: {} }
|
|
|
+ const { result } = searchCallback ? searchCallback(params) : { result: {} };
|
|
|
|
|
|
pageContentRef.value?.getPageData(result);
|
|
|
- resetCallback && resetCallback()
|
|
|
+ resetCallback && resetCallback();
|
|
|
+ searchParam = {};
|
|
|
+ }
|
|
|
+ function getMergeParams() {
|
|
|
+ return searchParam;
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
pageContentRef,
|
|
|
handleSearchClick,
|
|
|
- handleResetClick
|
|
|
+ handleResetClick,
|
|
|
+ getMergeParams
|
|
|
};
|
|
|
}
|