admin-vben5/packages/effects/plugins/src/vxe-table/extends.ts
Vben 304b1b2efc
fix: when a table switches paging, no form parameters will be carried (#4607)
* fix: when a table switches paging, no form parameters will be carried

* chore: typo
2024-10-10 22:48:25 +08:00

51 lines
1.1 KiB
TypeScript

import type { VxeGridProps } from 'vxe-table';
import type { VxeGridApi } from './api';
import { isFunction } from '@vben/utils';
export function extendProxyOptions(
api: VxeGridApi,
options: VxeGridProps,
getFormValues: () => Record<string, any>,
) {
[
'query',
'querySuccess',
'queryError',
'queryAll',
'queryAllSuccess',
'queryAllError',
].forEach((key) => {
extendProxyOption(key, api, options, getFormValues);
});
}
function extendProxyOption(
key: string,
api: VxeGridApi,
options: VxeGridProps,
getFormValues: () => Record<string, any>,
) {
const { proxyConfig } = options;
const configFn = (proxyConfig?.ajax as any)?.[key];
if (!isFunction(configFn)) {
return options;
}
const wrapperFn = async (params: any, _formValues: any, ...args: any[]) => {
const formValues = getFormValues();
const data = await configFn(params, formValues, ...args);
return data;
};
api.setState({
gridOptions: {
proxyConfig: {
ajax: {
[key]: wrapperFn,
},
},
},
});
}