fix: crud组件代码优化自动触发搜索逻辑,只有非input输入框值变化时触发

This commit is contained in:
YeMingfei666 2025-04-01 17:29:44 +08:00
parent 28fbbdff13
commit c779daebbc
1 changed files with 23 additions and 4 deletions

View File

@ -153,6 +153,7 @@ import dayjs from "dayjs";
const props = defineProps<{
searchConfig: ISearchConfig;
isOpenAutoSearch: Boolean;
watchKey: Array<string>;
}>();
//
const emit = defineEmits<{
@ -322,11 +323,29 @@ function timeChange(e: any, key: string) {
break;
}
}
watch(queryParams, () => {
if (props.isOpenAutoSearch) {
emit("queryClick", queryParams);
// input
function isChange(newval: any, oldval: any) {
const watchKeys = props.searchConfig.formItems
.filter((v) => v.type != "input" && v.type !== undefined)
.map((v) => v.prop);
return watchKeys.some((key) => newval[key] != oldval[key]);
}
//
watch(
() => {
return {
...queryParams,
};
},
(newval, oldval) => {
if (props.isOpenAutoSearch && isChange(newval, oldval)) {
handleQuery();
}
}
});
);
//
defineExpose({ getQueryParams, toggleVisible, setQueryValue });
</script>