feat: useVxeTable returns formApi instance (#4582)

pull/48/MERGE
Vben 2024-10-07 13:32:37 +08:00 committed by GitHub
parent 60c615ce8a
commit f8ce3fdf1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 67 additions and 62 deletions

View File

@ -1,11 +1,12 @@
export { setupVbenForm } from './config'; export { setupVbenForm } from './config';
export type { export type {
BaseFormComponentType, BaseFormComponentType,
ExtendedFormApi,
FormSchema as VbenFormSchema, FormSchema as VbenFormSchema,
VbenFormProps, VbenFormProps,
} from './types'; } from './types';
export * from './use-vben-form'; export * from './use-vben-form';
// export { default as VbenForm } from './vben-form.vue'; // export { default as VbenForm } from './vben-form.vue';
export * as z from 'zod'; export * as z from 'zod';

View File

@ -1,3 +1,4 @@
import type { ExtendedFormApi } from '@vben-core/form-ui';
import type { VxeGridInstance } from 'vxe-table'; import type { VxeGridInstance } from 'vxe-table';
import type { VxeGridProps } from './types'; import type { VxeGridProps } from './types';
@ -23,14 +24,16 @@ function getDefaultState(): VxeGridProps {
} }
export class VxeGridApi { export class VxeGridApi {
private isMounted = false;
private stateHandler: StateHandler;
public formApi = {} as ExtendedFormApi;
// private prevState: null | VxeGridProps = null; // private prevState: null | VxeGridProps = null;
public grid = {} as VxeGridInstance; public grid = {} as VxeGridInstance;
isMounted = false;
public state: null | VxeGridProps = null; public state: null | VxeGridProps = null;
stateHandler: StateHandler;
public store: Store<VxeGridProps>; public store: Store<VxeGridProps>;
constructor(options: VxeGridProps = {}) { constructor(options: VxeGridProps = {}) {
@ -52,9 +55,10 @@ export class VxeGridApi {
bindMethods(this); bindMethods(this);
} }
mount(instance: null | VxeGridInstance) { mount(instance: null | VxeGridInstance, formApi: ExtendedFormApi) {
if (!this.isMounted && instance) { if (!this.isMounted && instance) {
this.grid = instance; this.grid = instance;
this.formApi = formApi;
this.stateHandler.setConditionTrue(); this.stateHandler.setConditionTrue();
this.isMounted = true; this.isMounted = true;
} }

View File

@ -217,7 +217,7 @@ async function init() {
} }
onMounted(() => { onMounted(() => {
props.api?.mount?.(gridRef.value); props.api?.mount?.(gridRef.value, formApi);
init(); init();
}); });
</script> </script>

View File

@ -40,8 +40,8 @@ catalogs:
specifier: ^4.1.2 specifier: ^4.1.2
version: 4.1.2 version: 4.1.2
'@intlify/core-base': '@intlify/core-base':
specifier: ^10.0.3 specifier: ^10.0.4
version: 10.0.3 version: 10.0.4
'@intlify/unplugin-vue-i18n': '@intlify/unplugin-vue-i18n':
specifier: ^5.2.0 specifier: ^5.2.0
version: 5.2.0 version: 5.2.0
@ -184,11 +184,11 @@ catalogs:
specifier: ^7.0.6 specifier: ^7.0.6
version: 7.0.6 version: 7.0.6
cz-git: cz-git:
specifier: ^1.10.0 specifier: ^1.10.1
version: 1.10.0 version: 1.10.1
czg: czg:
specifier: ^1.10.0 specifier: ^1.10.1
version: 1.10.0 version: 1.10.1
dayjs: dayjs:
specifier: ^1.11.13 specifier: ^1.11.13
version: 1.11.13 version: 1.11.13
@ -466,8 +466,8 @@ catalogs:
specifier: ^9.4.3 specifier: ^9.4.3
version: 9.4.3 version: 9.4.3
vue-i18n: vue-i18n:
specifier: ^10.0.3 specifier: ^10.0.4
version: 10.0.3 version: 10.0.4
vue-router: vue-router:
specifier: ^4.4.5 specifier: ^4.4.5
version: 4.4.5 version: 4.4.5
@ -475,8 +475,8 @@ catalogs:
specifier: ^2.1.6 specifier: ^2.1.6
version: 2.1.6 version: 2.1.6
vxe-pc-ui: vxe-pc-ui:
specifier: ^4.2.14 specifier: ^4.2.15
version: 4.2.14 version: 4.2.15
vxe-table: vxe-table:
specifier: ^4.7.84 specifier: ^4.7.84
version: 4.7.85 version: 4.7.85
@ -871,10 +871,10 @@ importers:
version: 4.0.0(@commitlint/lint@19.5.0) version: 4.0.0(@commitlint/lint@19.5.0)
cz-git: cz-git:
specifier: 'catalog:' specifier: 'catalog:'
version: 1.10.0 version: 1.10.1
czg: czg:
specifier: 'catalog:' specifier: 'catalog:'
version: 1.10.0 version: 1.10.1
internal/lint-configs/eslint-config: internal/lint-configs/eslint-config:
dependencies: dependencies:
@ -1106,7 +1106,7 @@ importers:
dependencies: dependencies:
'@intlify/unplugin-vue-i18n': '@intlify/unplugin-vue-i18n':
specifier: 'catalog:' specifier: 'catalog:'
version: 5.2.0(@vue/compiler-dom@3.5.11)(eslint@9.12.0(jiti@2.2.1))(rollup@4.24.0)(typescript@5.6.2)(vue-i18n@10.0.3(vue@3.5.11(typescript@5.6.2)))(vue@3.5.11(typescript@5.6.2)) version: 5.2.0(@vue/compiler-dom@3.5.11)(eslint@9.12.0(jiti@2.2.1))(rollup@4.24.0)(typescript@5.6.2)(vue-i18n@10.0.4(vue@3.5.11(typescript@5.6.2)))(vue@3.5.11(typescript@5.6.2))
'@jspm/generator': '@jspm/generator':
specifier: 'catalog:' specifier: 'catalog:'
version: 2.3.1 version: 2.3.1
@ -1634,7 +1634,7 @@ importers:
version: 3.5.11(typescript@5.6.2) version: 3.5.11(typescript@5.6.2)
vxe-pc-ui: vxe-pc-ui:
specifier: 'catalog:' specifier: 'catalog:'
version: 4.2.14 version: 4.2.15
vxe-table: vxe-table:
specifier: 'catalog:' specifier: 'catalog:'
version: 4.7.85 version: 4.7.85
@ -1665,7 +1665,7 @@ importers:
dependencies: dependencies:
'@intlify/core-base': '@intlify/core-base':
specifier: 'catalog:' specifier: 'catalog:'
version: 10.0.3 version: 10.0.4
'@vben-core/composables': '@vben-core/composables':
specifier: workspace:* specifier: workspace:*
version: link:../@core/composables version: link:../@core/composables
@ -1674,7 +1674,7 @@ importers:
version: 3.5.11(typescript@5.6.2) version: 3.5.11(typescript@5.6.2)
vue-i18n: vue-i18n:
specifier: 'catalog:' specifier: 'catalog:'
version: 10.0.3(vue@3.5.11(typescript@5.6.2)) version: 10.0.4(vue@3.5.11(typescript@5.6.2))
packages/preferences: packages/preferences:
dependencies: dependencies:
@ -3973,24 +3973,24 @@ packages:
vue-i18n: vue-i18n:
optional: true optional: true
'@intlify/core-base@10.0.3': '@intlify/core-base@10.0.4':
resolution: {integrity: sha512-ysJnTGDtuXPa6R2Ii4JIvfMVvDahUUny3aY8+P4r6/0TYHkblgzIMjV6cAn60em67AB0M7OWNAdcAVfWWeN8Qg==} resolution: {integrity: sha512-GG428DkrrWCMhxRMRQZjuS7zmSUzarYcaHJqG9VB8dXAxw4iQDoKVQ7ChJRB6ZtsCsX3Jse1PEUlHrJiyQrOTg==}
engines: {node: '>= 16'} engines: {node: '>= 16'}
'@intlify/message-compiler@10.0.0': '@intlify/message-compiler@10.0.0':
resolution: {integrity: sha512-OcaWc63NC/9p1cMdgoNKBj4d61BH8sUW1Hfs6YijTd9656ZR4rNqXAlRnBrfS5ABq0vjQjpa8VnyvH9hK49yBw==} resolution: {integrity: sha512-OcaWc63NC/9p1cMdgoNKBj4d61BH8sUW1Hfs6YijTd9656ZR4rNqXAlRnBrfS5ABq0vjQjpa8VnyvH9hK49yBw==}
engines: {node: '>= 16'} engines: {node: '>= 16'}
'@intlify/message-compiler@10.0.3': '@intlify/message-compiler@10.0.4':
resolution: {integrity: sha512-KC2fG8nCzSYmXjHptEt6i/xM3k6S2szsPaHDCRgWKEYAbeHe6JFm6X4KRw3Csy112A8CxpavMi1dh3h7khwV5w==} resolution: {integrity: sha512-AFbhEo10DP095/45EauinQJ5hJ3rJUmuuqltGguvc3WsvezZN+g8qNHLGWKu60FHQVizMrQY7VJ+zVlBXlQQkQ==}
engines: {node: '>= 16'} engines: {node: '>= 16'}
'@intlify/shared@10.0.0': '@intlify/shared@10.0.0':
resolution: {integrity: sha512-6ngLfI7DOTew2dcF9WMJx+NnMWghMBhIiHbGg+wRvngpzD5KZJZiJVuzMsUQE1a5YebEmtpTEfUrDp/NqVGdiw==} resolution: {integrity: sha512-6ngLfI7DOTew2dcF9WMJx+NnMWghMBhIiHbGg+wRvngpzD5KZJZiJVuzMsUQE1a5YebEmtpTEfUrDp/NqVGdiw==}
engines: {node: '>= 16'} engines: {node: '>= 16'}
'@intlify/shared@10.0.3': '@intlify/shared@10.0.4':
resolution: {integrity: sha512-PWxrCb6fDlnoGLnXLlWu6d7o/HdWACB9TjRnpLro+9uyfqgWA9hvqg5vekcPRyraTieV5srCbTk/ldYw9V3LHw==} resolution: {integrity: sha512-ukFn0I01HsSgr3VYhYcvkTCLS7rGa0gw4A4AMpcy/A9xx/zRJy7PS2BElMXLwUazVFMAr5zuiTk3MQeoeGXaJg==}
engines: {node: '>= 16'} engines: {node: '>= 16'}
'@intlify/unplugin-vue-i18n@5.2.0': '@intlify/unplugin-vue-i18n@5.2.0':
@ -5823,12 +5823,12 @@ packages:
csstype@3.1.3: csstype@3.1.3:
resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==}
cz-git@1.10.0: cz-git@1.10.1:
resolution: {integrity: sha512-WJidM6BwqJXPi2KUBzkUgZwZYh9U5VP5tJSIZ5G4+CDDv0lzLo8vrOrsWItE12f3xpAvlZTeQipreSczuaxFRA==} resolution: {integrity: sha512-pBudDYUEqSOgt5cAlAk6BDs/h99lxfiii+1KCxfuVNOgcpn+yz7AejDjdBEJ+XDt7MOeAvcpYW3gi7C7il+IFA==}
engines: {node: '>=v12.20.0'} engines: {node: '>=v12.20.0'}
czg@1.10.0: czg@1.10.1:
resolution: {integrity: sha512-RJqFwHtEoDe6eivsLXI1hrUTNRd7Fy16+wivm+q9C9VT6/uC+g77piaz27rcMVeqa5zmtTlWuSGr3svzqWe2WA==} resolution: {integrity: sha512-melR80u+GA4EWNexwiWkbAPkFkxBqtLMQU4ePmnkF4N9F//8lB9mo1i0PmxphTamhn0N6kRAmnrkFrkRteNW8g==}
engines: {node: '>=v12.20.0'} engines: {node: '>=v12.20.0'}
hasBin: true hasBin: true
@ -10188,8 +10188,8 @@ packages:
peerDependencies: peerDependencies:
eslint: '>=6.0.0' eslint: '>=6.0.0'
vue-i18n@10.0.3: vue-i18n@10.0.4:
resolution: {integrity: sha512-8ul2S4Hy9orKs7eOlkw/zqnVu98GttUdyIMRyjoMpv6hFPxnybgBLdep/UCmdan5kUHyxqMnr2cGHTBuPBYJaw==} resolution: {integrity: sha512-1xkzVxqBLk2ZFOmeI+B5r1J7aD/WtNJ4j9k2mcFcQo5BnOmHBmD7z4/oZohh96AAaRZ4Q7mNQvxc9h+aT+Md3w==}
engines: {node: '>= 16'} engines: {node: '>= 16'}
peerDependencies: peerDependencies:
vue: ^3.5.11 vue: ^3.5.11
@ -10224,8 +10224,8 @@ packages:
peerDependencies: peerDependencies:
vue: ^3.5.11 vue: ^3.5.11
vxe-pc-ui@4.2.14: vxe-pc-ui@4.2.15:
resolution: {integrity: sha512-yXZo7axUmn62bksPKFwOHafGJTDH7QXsvhWVwr/xb+vM4wLA14WUijyEnAJJvY78lM5FB8cIFZqwahOhj1Pu8w==} resolution: {integrity: sha512-Vdmd2YpUsH0jKVREurolAet2SMViwkkgNbCI8V0CQRqAA1JWNSw3RfeXywN+IQwBaghzihZFnKSfRSAVaALX3A==}
vxe-table@4.7.85: vxe-table@4.7.85:
resolution: {integrity: sha512-sNQ4jKnU6vZkStTK2JDDKgIz5kKCCWtTtOVl7dpNsLJ16NYWMCDlNby5m/DJC+xa0dPvSdr7+AH4TXfD1vpRFg==} resolution: {integrity: sha512-sNQ4jKnU6vZkStTK2JDDKgIz5kKCCWtTtOVl7dpNsLJ16NYWMCDlNby5m/DJC+xa0dPvSdr7+AH4TXfD1vpRFg==}
@ -12662,7 +12662,7 @@ snapshots:
dependencies: dependencies:
'@swc/helpers': 0.5.13 '@swc/helpers': 0.5.13
'@intlify/bundle-utils@9.0.0-beta.0(vue-i18n@10.0.3(vue@3.5.11(typescript@5.6.2)))': '@intlify/bundle-utils@9.0.0-beta.0(vue-i18n@10.0.4(vue@3.5.11(typescript@5.6.2)))':
dependencies: dependencies:
'@intlify/message-compiler': 10.0.0 '@intlify/message-compiler': 10.0.0
'@intlify/shared': 10.0.0 '@intlify/shared': 10.0.0
@ -12674,33 +12674,33 @@ snapshots:
source-map-js: 1.2.1 source-map-js: 1.2.1
yaml-eslint-parser: 1.2.3 yaml-eslint-parser: 1.2.3
optionalDependencies: optionalDependencies:
vue-i18n: 10.0.3(vue@3.5.11(typescript@5.6.2)) vue-i18n: 10.0.4(vue@3.5.11(typescript@5.6.2))
'@intlify/core-base@10.0.3': '@intlify/core-base@10.0.4':
dependencies: dependencies:
'@intlify/message-compiler': 10.0.3 '@intlify/message-compiler': 10.0.4
'@intlify/shared': 10.0.3 '@intlify/shared': 10.0.4
'@intlify/message-compiler@10.0.0': '@intlify/message-compiler@10.0.0':
dependencies: dependencies:
'@intlify/shared': 10.0.0 '@intlify/shared': 10.0.0
source-map-js: 1.2.1 source-map-js: 1.2.1
'@intlify/message-compiler@10.0.3': '@intlify/message-compiler@10.0.4':
dependencies: dependencies:
'@intlify/shared': 10.0.3 '@intlify/shared': 10.0.4
source-map-js: 1.2.1 source-map-js: 1.2.1
'@intlify/shared@10.0.0': {} '@intlify/shared@10.0.0': {}
'@intlify/shared@10.0.3': {} '@intlify/shared@10.0.4': {}
'@intlify/unplugin-vue-i18n@5.2.0(@vue/compiler-dom@3.5.11)(eslint@9.12.0(jiti@2.2.1))(rollup@4.24.0)(typescript@5.6.2)(vue-i18n@10.0.3(vue@3.5.11(typescript@5.6.2)))(vue@3.5.11(typescript@5.6.2))': '@intlify/unplugin-vue-i18n@5.2.0(@vue/compiler-dom@3.5.11)(eslint@9.12.0(jiti@2.2.1))(rollup@4.24.0)(typescript@5.6.2)(vue-i18n@10.0.4(vue@3.5.11(typescript@5.6.2)))(vue@3.5.11(typescript@5.6.2))':
dependencies: dependencies:
'@eslint-community/eslint-utils': 4.4.0(eslint@9.12.0(jiti@2.2.1)) '@eslint-community/eslint-utils': 4.4.0(eslint@9.12.0(jiti@2.2.1))
'@intlify/bundle-utils': 9.0.0-beta.0(vue-i18n@10.0.3(vue@3.5.11(typescript@5.6.2))) '@intlify/bundle-utils': 9.0.0-beta.0(vue-i18n@10.0.4(vue@3.5.11(typescript@5.6.2)))
'@intlify/shared': 10.0.0 '@intlify/shared': 10.0.0
'@intlify/vue-i18n-extensions': 7.0.0(@intlify/shared@10.0.0)(@vue/compiler-dom@3.5.11)(vue-i18n@10.0.3(vue@3.5.11(typescript@5.6.2)))(vue@3.5.11(typescript@5.6.2)) '@intlify/vue-i18n-extensions': 7.0.0(@intlify/shared@10.0.0)(@vue/compiler-dom@3.5.11)(vue-i18n@10.0.4(vue@3.5.11(typescript@5.6.2)))(vue@3.5.11(typescript@5.6.2))
'@rollup/pluginutils': 5.1.2(rollup@4.24.0) '@rollup/pluginutils': 5.1.2(rollup@4.24.0)
'@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/scope-manager': 7.18.0
'@typescript-eslint/typescript-estree': 7.18.0(typescript@5.6.2) '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.6.2)
@ -12714,7 +12714,7 @@ snapshots:
unplugin: 1.14.1 unplugin: 1.14.1
vue: 3.5.11(typescript@5.6.2) vue: 3.5.11(typescript@5.6.2)
optionalDependencies: optionalDependencies:
vue-i18n: 10.0.3(vue@3.5.11(typescript@5.6.2)) vue-i18n: 10.0.4(vue@3.5.11(typescript@5.6.2))
transitivePeerDependencies: transitivePeerDependencies:
- '@vue/compiler-dom' - '@vue/compiler-dom'
- eslint - eslint
@ -12723,14 +12723,14 @@ snapshots:
- typescript - typescript
- webpack-sources - webpack-sources
'@intlify/vue-i18n-extensions@7.0.0(@intlify/shared@10.0.0)(@vue/compiler-dom@3.5.11)(vue-i18n@10.0.3(vue@3.5.11(typescript@5.6.2)))(vue@3.5.11(typescript@5.6.2))': '@intlify/vue-i18n-extensions@7.0.0(@intlify/shared@10.0.0)(@vue/compiler-dom@3.5.11)(vue-i18n@10.0.4(vue@3.5.11(typescript@5.6.2)))(vue@3.5.11(typescript@5.6.2))':
dependencies: dependencies:
'@babel/parser': 7.25.7 '@babel/parser': 7.25.7
optionalDependencies: optionalDependencies:
'@intlify/shared': 10.0.0 '@intlify/shared': 10.0.0
'@vue/compiler-dom': 3.5.11 '@vue/compiler-dom': 3.5.11
vue: 3.5.11(typescript@5.6.2) vue: 3.5.11(typescript@5.6.2)
vue-i18n: 10.0.3(vue@3.5.11(typescript@5.6.2)) vue-i18n: 10.0.4(vue@3.5.11(typescript@5.6.2))
'@ioredis/commands@1.2.0': {} '@ioredis/commands@1.2.0': {}
@ -15000,9 +15000,9 @@ snapshots:
csstype@3.1.3: {} csstype@3.1.3: {}
cz-git@1.10.0: {} cz-git@1.10.1: {}
czg@1.10.0: {} czg@1.10.1: {}
dargs@8.1.0: {} dargs@8.1.0: {}
@ -19821,10 +19821,10 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
vue-i18n@10.0.3(vue@3.5.11(typescript@5.6.2)): vue-i18n@10.0.4(vue@3.5.11(typescript@5.6.2)):
dependencies: dependencies:
'@intlify/core-base': 10.0.3 '@intlify/core-base': 10.0.4
'@intlify/shared': 10.0.3 '@intlify/shared': 10.0.4
'@vue/devtools-api': 6.6.4 '@vue/devtools-api': 6.6.4
vue: 3.5.11(typescript@5.6.2) vue: 3.5.11(typescript@5.6.2)
@ -19866,13 +19866,13 @@ snapshots:
vooks: 0.2.12(vue@3.5.11(typescript@5.6.2)) vooks: 0.2.12(vue@3.5.11(typescript@5.6.2))
vue: 3.5.11(typescript@5.6.2) vue: 3.5.11(typescript@5.6.2)
vxe-pc-ui@4.2.14: vxe-pc-ui@4.2.15:
dependencies: dependencies:
'@vxe-ui/core': 4.0.12 '@vxe-ui/core': 4.0.12
vxe-table@4.7.85: vxe-table@4.7.85:
dependencies: dependencies:
vxe-pc-ui: 4.2.14 vxe-pc-ui: 4.2.15
warning@4.0.3: warning@4.0.3:
dependencies: dependencies:

View File

@ -25,7 +25,7 @@ catalog:
'@iconify/json': ^2.2.256 '@iconify/json': ^2.2.256
'@iconify/tailwind': ^1.1.3 '@iconify/tailwind': ^1.1.3
'@iconify/vue': ^4.1.2 '@iconify/vue': ^4.1.2
'@intlify/core-base': ^10.0.3 '@intlify/core-base': ^10.0.4
'@intlify/unplugin-vue-i18n': ^5.2.0 '@intlify/unplugin-vue-i18n': ^5.2.0
'@jspm/generator': ^2.3.1 '@jspm/generator': ^2.3.1
'@manypkg/get-packages': ^2.2.2 '@manypkg/get-packages': ^2.2.2
@ -74,8 +74,8 @@ catalog:
cross-env: ^7.0.3 cross-env: ^7.0.3
cspell: ^8.14.4 cspell: ^8.14.4
cssnano: ^7.0.6 cssnano: ^7.0.6
cz-git: ^1.10.0 cz-git: ^1.10.1
czg: ^1.10.0 czg: ^1.10.1
dayjs: ^1.11.13 dayjs: ^1.11.13
defu: ^6.1.4 defu: ^6.1.4
depcheck: ^1.4.7 depcheck: ^1.4.7
@ -170,10 +170,10 @@ catalog:
vitest: ^2.1.2 vitest: ^2.1.2
vue: ^3.5.11 vue: ^3.5.11
vue-eslint-parser: ^9.4.3 vue-eslint-parser: ^9.4.3
vue-i18n: ^10.0.3 vue-i18n: ^10.0.4
vue-router: ^4.4.5 vue-router: ^4.4.5
vue-tsc: ^2.1.6 vue-tsc: ^2.1.6
vxe-pc-ui: ^4.2.14 vxe-pc-ui: ^4.2.15
vxe-table: ^4.7.84 vxe-table: ^4.7.84
watermark-js-plus: ^1.5.7 watermark-js-plus: ^1.5.7
zod: ^3.23.8 zod: ^3.23.8