fix: 补全 ComponentPropsMap 与 Vxe 表格表单链路的类型

This commit is contained in:
dullathanol
2026-04-05 19:03:03 +08:00
committed by allen
parent e417a2c209
commit 2013ba4de4
13 changed files with 72 additions and 31 deletions

View File

@@ -1,6 +1,9 @@
import type { VxeGridInstance } from 'vxe-table';
import type { ExtendedFormApi } from '@vben-core/form-ui';
import type {
BaseFormComponentType,
ExtendedFormApi,
} from '@vben-core/form-ui';
import type { VxeGridProps } from './types';
@@ -26,25 +29,29 @@ function getDefaultState(): VxeGridProps {
};
}
export class VxeGridApi<T extends Record<string, any> = any> {
export class VxeGridApi<
T extends Record<string, any> = any,
D extends BaseFormComponentType = BaseFormComponentType,
P extends Record<string, any> = Record<never, never>,
> {
public formApi = {} as ExtendedFormApi;
// private prevState: null | VxeGridProps = null;
public grid = {} as VxeGridInstance<T>;
public state: null | VxeGridProps<T> = null;
public state: null | VxeGridProps<T, D, P> = null;
public store: Store<VxeGridProps<T>>;
public store: Store<VxeGridProps<T, D, P>>;
private isMounted = false;
private stateHandler: StateHandler;
constructor(options: VxeGridProps = {}) {
constructor(options: VxeGridProps<T, D, P> = {} as VxeGridProps<T, D, P>) {
const storeState = { ...options };
const defaultState = getDefaultState();
this.store = new Store<VxeGridProps>(
mergeWithArrayOverride(storeState, defaultState),
this.store = new Store<VxeGridProps<T, D, P>>(
mergeWithArrayOverride(storeState, defaultState) as VxeGridProps<T, D, P>,
);
this.store.subscribe((state) => {
@@ -82,7 +89,7 @@ export class VxeGridApi<T extends Record<string, any> = any> {
}
}
setGridOptions(options: Partial<VxeGridProps['gridOptions']>) {
setGridOptions(options: Partial<VxeGridProps<T, D, P>['gridOptions']>) {
this.setState({
gridOptions: options,
});
@@ -98,8 +105,8 @@ export class VxeGridApi<T extends Record<string, any> = any> {
setState(
stateOrFn:
| ((prev: VxeGridProps<T>) => Partial<VxeGridProps<T>>)
| Partial<VxeGridProps<T>>,
| ((prev: VxeGridProps<T, D, P>) => Partial<VxeGridProps<T, D, P>>)
| Partial<VxeGridProps<T, D, P>>,
) {
if (isFunction(stateOrFn)) {
this.store.setState((prev) => {

View File

@@ -89,9 +89,9 @@ export type ExtendedVxeGridApi<
D extends Record<string, any> = any,
F extends BaseFormComponentType = BaseFormComponentType,
P extends Record<string, any> = Record<never, never>,
> = VxeGridApi<D> & {
> = VxeGridApi<D, F, P> & {
useStore: <S = NoInfer<VxeGridProps<D, F, P>>>(
selector?: (state: NoInfer<VxeGridProps<any, any, any>>) => S,
selector?: (state: NoInfer<VxeGridProps<D, F, P>>) => S,
) => Readonly<Ref<S>>;
};

View File

@@ -25,7 +25,7 @@ export function useVbenVxeGrid<
P extends Record<string, any> = Record<never, never>,
>(options: VxeGridProps<T, D, P>) {
// const IS_REACTIVE = isReactive(options);
const api = new VxeGridApi(options as VxeGridProps);
const api = new VxeGridApi<T, D, P>(options);
const extendedApi: ExtendedVxeGridApi<T, D, P> = api as ExtendedVxeGridApi<
T,
D,
@@ -36,12 +36,21 @@ export function useVbenVxeGrid<
};
const Grid = defineComponent(
(props: VxeGridProps<T>, { attrs, slots }) => {
(props: VxeGridProps<T, D, P>, { attrs, slots }) => {
onBeforeUnmount(() => {
api.unmount();
});
api.setState({ ...props, ...attrs });
return () => h(VxeGrid, { ...props, ...attrs, api: extendedApi }, slots);
api.setState({ ...props, ...attrs } as Partial<VxeGridProps<T, D, P>>);
return () =>
h(
VxeGrid,
{
...props,
...attrs,
api: extendedApi as ExtendedVxeGridApi,
},
slots,
);
},
{
name: 'VbenVxeGrid',