fix: crud组件代码优化自动触发搜索逻辑,只有非input输入框值变化时触发
This commit is contained in:
parent
28fbbdff13
commit
c779daebbc
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue