From 760f21a5e7cb989e456c294d80b80b4a27bec758 Mon Sep 17 00:00:00 2001 From: bqy_fe <1743369777@qq.com> Date: Sat, 11 Dec 2021 22:31:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=E8=A7=92=E8=89=B2=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=9D=83=E9=99=90=E5=8B=BE=E9=80=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/dept/model.d.ts | 1 + src/api/system/menu/model.d.ts | 1 + .../JSON-schema-form/hooks/useSchemaForm.ts | 93 ----------------- src/components/JSON-schema-form/index.ts | 4 +- .../JSON-schema-form/schema-form-item.vue | 8 +- .../JSON-schema-form/schema-form.vue | 13 +++ .../dynamic-table/dynamic-table.vue | 3 +- src/components/split-panel/index.vue | 2 +- src/core/permission/utils.ts | 37 ++++--- src/hooks/useModal/useFormModal.tsx | 7 +- src/views/system/permission/role/index.vue | 42 ++++++-- types/global.d.ts | 99 ++++++++++--------- 12 files changed, 138 insertions(+), 172 deletions(-) delete mode 100644 src/components/JSON-schema-form/hooks/useSchemaForm.ts diff --git a/src/api/system/dept/model.d.ts b/src/api/system/dept/model.d.ts index 89440c595..33a369cc8 100644 --- a/src/api/system/dept/model.d.ts +++ b/src/api/system/dept/model.d.ts @@ -7,6 +7,7 @@ declare namespace API { parentId: number; name: string; orderNum: number; + pIds?: number[]; }; /** 部门 */ type MovedDeptItem = { diff --git a/src/api/system/menu/model.d.ts b/src/api/system/menu/model.d.ts index 41e022ac8..9a021ad52 100644 --- a/src/api/system/menu/model.d.ts +++ b/src/api/system/menu/model.d.ts @@ -13,6 +13,7 @@ declare namespace API { viewPath: string; keepalive: boolean; isShow: boolean; + pIds?: number[]; }; /** 获取菜单列表参数 */ diff --git a/src/components/JSON-schema-form/hooks/useSchemaForm.ts b/src/components/JSON-schema-form/hooks/useSchemaForm.ts deleted file mode 100644 index 2b71eed12..000000000 --- a/src/components/JSON-schema-form/hooks/useSchemaForm.ts +++ /dev/null @@ -1,93 +0,0 @@ -import type { FormSchema, FormItemSchema, FormActionType } from '../types/form'; -import type { NamePath } from 'ant-design-vue/lib/form/interface'; -import { ref, unref, nextTick } from 'vue'; - -export declare type ValidateFields = (nameList?: NamePath[]) => Promise; - -// eslint-disable-next-line -export const useSchemaForm = (props?: Partial) => { - const formRef = ref>(null); - // eslint-disable-next-line - const loadedRef = ref>(false); - - async function getForm() { - const form = unref(formRef); - if (!form) { - console.error('未获取到表单实例,请确保表单实例是否注册。'); - } - await nextTick(); - return form as FormActionType; - } - - const methods: FormActionType = { - scrollToField: async (name: NamePath, options?: ScrollOptions | undefined) => { - const form = await getForm(); - form.scrollToField(name, options); - }, - setProps: async (formProps: Partial) => { - const form = await getForm(); - form.setProps(formProps); - }, - - updateSchema: async (data: Partial | Partial[]) => { - const form = await getForm(); - form.updateSchema(data); - }, - - resetSchema: async (data: Partial | Partial[]) => { - const form = await getForm(); - form.resetSchema(data); - }, - - clearValidate: async (name?: string | string[]) => { - const form = await getForm(); - form.clearValidate(name); - }, - - resetFields: async () => { - getForm().then(async (form) => { - await form.resetFields(); - }); - }, - - removeSchemaByFiled: async (field: string | string[]) => { - unref(formRef)?.removeSchemaByFiled(field); - }, - - // TODO promisify - getFieldsValue: () => { - return unref(formRef)?.getFieldsValue() as T; - }, - - setFieldsValue: async (values: T) => { - const form = await getForm(); - form.setFieldsValue(values); - }, - - appendSchemaByField: async ( - schema: FormItemSchema, - prefixField: string | undefined, - first: boolean, - ) => { - const form = await getForm(); - form.appendSchemaByField(schema, prefixField, first); - }, - - submit: async (): Promise => { - const form = await getForm(); - return form.submit(); - }, - - validate: async (nameList?: NamePath[]): Promise => { - const form = await getForm(); - return form.validate(nameList); - }, - - validateFields: async (nameList?: NamePath[]): Promise => { - const form = await getForm(); - return form.validateFields(nameList); - }, - }; - - return [formRef, methods] as const; -}; diff --git a/src/components/JSON-schema-form/index.ts b/src/components/JSON-schema-form/index.ts index 112f60db6..bf5d29399 100644 --- a/src/components/JSON-schema-form/index.ts +++ b/src/components/JSON-schema-form/index.ts @@ -4,6 +4,6 @@ export * from './types/formItem'; // export { default as SchemaForm } from './schema-form.vue' import SchemaForm from './schema-form.vue'; -export { useSchemaForm } from './hooks/useSchemaForm'; - export { SchemaForm }; + +export type SchemaFormRef = InstanceType; diff --git a/src/components/JSON-schema-form/schema-form-item.vue b/src/components/JSON-schema-form/schema-form-item.vue index 61fa9f85e..ff9edebd1 100644 --- a/src/components/JSON-schema-form/schema-form-item.vue +++ b/src/components/JSON-schema-form/schema-form-item.vue @@ -12,6 +12,7 @@