feat: table搜索表单值发生改变可以触发reload (#3378)
This commit is contained in:
parent
e656b5d8dc
commit
1ca3f7c2c0
|
|
@ -24,6 +24,7 @@
|
||||||
import { cloneDeep, upperFirst } from 'lodash-es';
|
import { cloneDeep, upperFirst } from 'lodash-es';
|
||||||
import { useItemLabelWidth } from '../hooks/useLabelWidth';
|
import { useItemLabelWidth } from '../hooks/useLabelWidth';
|
||||||
import { useI18n } from '@/hooks/web/useI18n';
|
import { useI18n } from '@/hooks/web/useI18n';
|
||||||
|
import { useDebounceFn } from '@vueuse/core';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'BasicFormItem',
|
name: 'BasicFormItem',
|
||||||
|
|
@ -270,6 +271,8 @@
|
||||||
component,
|
component,
|
||||||
field,
|
field,
|
||||||
changeEvent = 'change',
|
changeEvent = 'change',
|
||||||
|
watchEventNames = ['search', 'change'],
|
||||||
|
enableWatchEvent = true,
|
||||||
valueField,
|
valueField,
|
||||||
} = props.schema;
|
} = props.schema;
|
||||||
|
|
||||||
|
|
@ -277,6 +280,27 @@
|
||||||
|
|
||||||
const eventKey = `on${upperFirst(changeEvent)}`;
|
const eventKey = `on${upperFirst(changeEvent)}`;
|
||||||
|
|
||||||
|
const { autoSetPlaceHolder, size, watchEvent } = props.formProps;
|
||||||
|
let eventNames = {};
|
||||||
|
if (watchEvent && enableWatchEvent) {
|
||||||
|
// table search 开启才触发事件
|
||||||
|
let immediateEvents = ['search']; // 立即执行的事件
|
||||||
|
watchEventNames.forEach((item) => {
|
||||||
|
let timer: number = 500;
|
||||||
|
if (immediateEvents.includes(item)) {
|
||||||
|
timer = 0;
|
||||||
|
}
|
||||||
|
eventNames[`on${upperFirst(item)}`] = useDebounceFn(
|
||||||
|
(...args: Nullable<Recordable<any>>[]) => {
|
||||||
|
// todo 后续需要优化input中文输入的问题
|
||||||
|
console.log(args);
|
||||||
|
const { reload = () => {} } = props.tableAction || {};
|
||||||
|
reload();
|
||||||
|
},
|
||||||
|
timer,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
const on = {
|
const on = {
|
||||||
[eventKey]: (...args: Nullable<Recordable<any>>[]) => {
|
[eventKey]: (...args: Nullable<Recordable<any>>[]) => {
|
||||||
const [e] = args;
|
const [e] = args;
|
||||||
|
|
@ -290,7 +314,6 @@
|
||||||
};
|
};
|
||||||
const Comp = componentMap.get(component) as ReturnType<typeof defineComponent>;
|
const Comp = componentMap.get(component) as ReturnType<typeof defineComponent>;
|
||||||
|
|
||||||
const { autoSetPlaceHolder, size } = props.formProps;
|
|
||||||
const propsData: Recordable<any> = {
|
const propsData: Recordable<any> = {
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
size,
|
size,
|
||||||
|
|
@ -315,6 +338,7 @@
|
||||||
const compAttr: Recordable<any> = {
|
const compAttr: Recordable<any> = {
|
||||||
...propsData,
|
...propsData,
|
||||||
...on,
|
...on,
|
||||||
|
...eventNames,
|
||||||
...bindValue,
|
...bindValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,4 +100,7 @@ export const basicProps = {
|
||||||
labelAlign: propTypes.string,
|
labelAlign: propTypes.string,
|
||||||
|
|
||||||
rowProps: Object as PropType<RowProps>,
|
rowProps: Object as PropType<RowProps>,
|
||||||
|
|
||||||
|
// table 开启监听表单监听事件,触发table reload
|
||||||
|
watchEvent: propTypes.bool.def(false),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,7 @@ export interface FormProps {
|
||||||
submitFunc?: () => Promise<void>;
|
submitFunc?: () => Promise<void>;
|
||||||
transformDateFunc?: (date: any) => string;
|
transformDateFunc?: (date: any) => string;
|
||||||
colon?: boolean;
|
colon?: boolean;
|
||||||
|
watchEvent?: boolean;
|
||||||
}
|
}
|
||||||
export type RenderOpts = {
|
export type RenderOpts = {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
|
|
@ -223,6 +224,11 @@ interface BaseFormSchema {
|
||||||
dynamicReadonly?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
|
dynamicReadonly?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
|
||||||
|
|
||||||
dynamicRules?: (renderCallbackParams: RenderCallbackParams) => Rule[];
|
dynamicRules?: (renderCallbackParams: RenderCallbackParams) => Rule[];
|
||||||
|
|
||||||
|
watchEventNames?: string[];
|
||||||
|
|
||||||
|
// 禁用事件监听触发reload
|
||||||
|
enableWatchEvent?: boolean;
|
||||||
}
|
}
|
||||||
export interface ComponentFormSchema extends BaseFormSchema {
|
export interface ComponentFormSchema extends BaseFormSchema {
|
||||||
// render component
|
// render component
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,45 @@ export function getFormConfig(): Partial<FormProps> {
|
||||||
xxl: 8,
|
xxl: 8,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
field: `field12`,
|
||||||
|
label: `input值改变`,
|
||||||
|
component: 'InputSearch',
|
||||||
|
enableWatchEvent: true,
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '需要开启watchEvent',
|
||||||
|
},
|
||||||
|
colProps: {
|
||||||
|
xl: 12,
|
||||||
|
xxl: 8,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field13',
|
||||||
|
component: 'Select',
|
||||||
|
label: 'select值改变',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '需要开启watchEvent',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '公开',
|
||||||
|
value: '1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '部分公开',
|
||||||
|
value: '2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '不公开',
|
||||||
|
value: '3',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: {
|
||||||
|
xl: 12,
|
||||||
|
xxl: 8,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue