|
|
@ -1,6 +1,9 @@ |
|
|
import type { VxeGridInstance } from 'vxe-table'; |
|
|
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'; |
|
|
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; |
|
|
public formApi = {} as ExtendedFormApi; |
|
|
|
|
|
|
|
|
// private prevState: null | VxeGridProps = null;
|
|
|
// private prevState: null | VxeGridProps = null;
|
|
|
public grid = {} as VxeGridInstance<T>; |
|
|
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 isMounted = false; |
|
|
|
|
|
|
|
|
private stateHandler: StateHandler; |
|
|
private stateHandler: StateHandler; |
|
|
|
|
|
|
|
|
constructor(options: VxeGridProps = {}) { |
|
|
constructor(options: VxeGridProps<T, D, P> = {} as VxeGridProps<T, D, P>) { |
|
|
const storeState = { ...options }; |
|
|
const storeState = { ...options }; |
|
|
|
|
|
|
|
|
const defaultState = getDefaultState(); |
|
|
const defaultState = getDefaultState(); |
|
|
this.store = new Store<VxeGridProps>( |
|
|
this.store = new Store<VxeGridProps<T, D, P>>( |
|
|
mergeWithArrayOverride(storeState, defaultState), |
|
|
mergeWithArrayOverride(storeState, defaultState) as VxeGridProps<T, D, P>, |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
this.store.subscribe((state) => { |
|
|
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({ |
|
|
this.setState({ |
|
|
gridOptions: options, |
|
|
gridOptions: options, |
|
|
}); |
|
|
}); |
|
|
@ -98,8 +105,8 @@ export class VxeGridApi<T extends Record<string, any> = any> { |
|
|
|
|
|
|
|
|
setState( |
|
|
setState( |
|
|
stateOrFn: |
|
|
stateOrFn: |
|
|
| ((prev: VxeGridProps<T>) => Partial<VxeGridProps<T>>) |
|
|
| ((prev: VxeGridProps<T, D, P>) => Partial<VxeGridProps<T, D, P>>) |
|
|
| Partial<VxeGridProps<T>>, |
|
|
| Partial<VxeGridProps<T, D, P>>, |
|
|
) { |
|
|
) { |
|
|
if (isFunction(stateOrFn)) { |
|
|
if (isFunction(stateOrFn)) { |
|
|
this.store.setState((prev) => { |
|
|
this.store.setState((prev) => { |
|
|
|