From 2c4ff7d190c816a92d92f9c2dbe048436b2bf964 Mon Sep 17 00:00:00 2001 From: kailong321200875 <321200875@qq.com> Date: Sat, 14 Oct 2023 10:43:04 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=AE=8C=E5=96=84demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/menu/index.ts | 17 ++ mock/role/index.ts | 19 +- .../Descriptions/src/Descriptions.vue | 8 +- src/hooks/web/useForm.ts | 23 ++- src/router/index.ts | 18 +- src/views/Authorization/Menu/Menu.vue | 27 +-- .../Authorization/Menu/components/Detail.vue | 155 +++++++++++++++++ .../Authorization/Menu/components/Write.vue | 162 +++++++++++++++--- .../Authorization/Role/components/Write.vue | 6 +- src/views/Authorization/User/User.vue | 16 +- .../{Authorization/Test => Function}/Test.vue | 0 11 files changed, 383 insertions(+), 68 deletions(-) create mode 100644 src/views/Authorization/Menu/components/Detail.vue rename src/views/{Authorization/Test => Function}/Test.vue (100%) diff --git a/mock/menu/index.ts b/mock/menu/index.ts index 70782f9..488b82c 100644 --- a/mock/menu/index.ts +++ b/mock/menu/index.ts @@ -24,6 +24,7 @@ export default [ name: 'Dashboard', status: Mock.Random.integer(0, 1), id: 1, + title: '首页', meta: { title: '首页', icon: 'ant-design:dashboard-filled', @@ -36,6 +37,7 @@ export default [ name: 'Analysis', status: Mock.Random.integer(0, 1), id: 2, + title: '分析页', meta: { title: '分析页', noCache: true @@ -47,6 +49,7 @@ export default [ name: 'Workplace', status: Mock.Random.integer(0, 1), id: 3, + title: '工作台', meta: { title: '工作台', noCache: true @@ -57,6 +60,7 @@ export default [ { path: '/external-link', component: '#', + title: '文档', meta: { title: '文档', icon: 'clarity:document-solid' @@ -70,6 +74,7 @@ export default [ name: 'DocumentLink', status: Mock.Random.integer(0, 1), id: 5, + title: '文档', meta: { title: '文档' } @@ -83,6 +88,7 @@ export default [ name: 'Level', status: Mock.Random.integer(0, 1), id: 6, + title: '菜单', meta: { title: '菜单', icon: 'carbon:skill-level-advanced' @@ -95,6 +101,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 7, redirect: '/level/menu1/menu1-1/menu1-1-1', + title: '菜单1', meta: { title: '菜单1' }, @@ -106,6 +113,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 8, redirect: '/level/menu1/menu1-1/menu1-1-1', + title: '菜单1-1', meta: { title: '菜单1-1', alwaysShow: true @@ -118,6 +126,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 9, permission: ['edit', 'add', 'delete'], + title: '菜单1-1-1', meta: { title: '菜单1-1-1' } @@ -131,6 +140,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 10, permission: ['edit', 'add', 'delete'], + title: '菜单1-2', meta: { title: '菜单1-2' } @@ -144,6 +154,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 11, permission: ['edit', 'add', 'delete'], + title: '菜单2', meta: { title: '菜单2' } @@ -157,6 +168,7 @@ export default [ name: 'Example', status: Mock.Random.integer(0, 1), id: 12, + title: '综合示例', meta: { title: '综合示例', icon: 'ep:management', @@ -169,6 +181,7 @@ export default [ name: 'ExampleDialog', status: Mock.Random.integer(0, 1), id: 13, + title: '综合示例-弹窗', permission: ['edit', 'add', 'delete'], meta: { title: '综合示例-弹窗', @@ -182,6 +195,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 14, permission: ['edit', 'add', 'delete'], + title: '综合示例-页面', meta: { title: '综合示例-页面', permission: ['edit', 'add'] @@ -194,6 +208,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 15, permission: ['edit', 'add', 'delete'], + title: '综合示例-新增', meta: { title: '综合示例-新增', noTagsView: true, @@ -211,6 +226,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 16, permission: ['edit', 'add', 'delete'], + title: '综合示例-编辑', meta: { title: '综合示例-编辑', noTagsView: true, @@ -228,6 +244,7 @@ export default [ status: Mock.Random.integer(0, 1), id: 17, permission: ['edit', 'add', 'delete'], + title: '综合示例-详情', meta: { title: '综合示例-详情', noTagsView: true, diff --git a/mock/role/index.ts b/mock/role/index.ts index 07c274d..ec5d2aa 100644 --- a/mock/role/index.ts +++ b/mock/role/index.ts @@ -332,6 +332,15 @@ const adminList = [ meta: { title: 'router.request' } + }, + { + path: 'test', + component: () => 'views/Function/Test', + name: 'Test', + meta: { + title: 'router.permission', + permission: ['add', 'edit', 'delete'] + } } ] }, @@ -602,14 +611,6 @@ const adminList = [ meta: { title: 'router.role' } - }, - { - path: 'test', - component: 'views/Authorization/Test/Test', - name: 'Test', - meta: { - title: 'router.permission' - } } ] } @@ -654,6 +655,7 @@ const testList: string[] = [ '/function/multiple-tabs', '/function/multiple-tabs-demo/:id', '/function/request', + '/function/test', '/hooks', '/hooks/useWatermark', '/hooks/useTagsView', @@ -678,7 +680,6 @@ const testList: string[] = [ '/authorization/user', '/authorization/role', '/authorization/menu', - '/authorization/test', '/error', '/error/404-demo', '/error/403-demo', diff --git a/src/components/Descriptions/src/Descriptions.vue b/src/components/Descriptions/src/Descriptions.vue index f031e5c..413ca75 100644 --- a/src/components/Descriptions/src/Descriptions.vue +++ b/src/components/Descriptions/src/Descriptions.vue @@ -159,6 +159,12 @@ export default defineComponent({ } :deep(.@{prefix-cls}-label) { - width: 150px; + width: 150px !important; } + +// .@{prefix-cls}-content { +// :deep(.@{elNamespace}-descriptions__cell) { +// width: 0; +// } +// } diff --git a/src/hooks/web/useForm.ts b/src/hooks/web/useForm.ts index 3846210..cdf5eac 100644 --- a/src/hooks/web/useForm.ts +++ b/src/hooks/web/useForm.ts @@ -2,6 +2,7 @@ import type { Form, FormExpose } from '@/components/Form' import type { ElForm, ElFormItem } from 'element-plus' import { ref, unref, nextTick } from 'vue' import { FormSchema, FormSetProps, FormProps } from '@/components/Form' +import { isEmptyVal, isObject } from '@/utils/is' export const useForm = () => { // From实例 @@ -83,9 +84,27 @@ export const useForm = () => { * @description 获取表单数据 * @returns form data */ - getFormData: async (): Promise => { + getFormData: async (filterEmptyVal = true): Promise => { const form = await getForm() - return form?.formModel as T + const model = form?.formModel as any + if (filterEmptyVal) { + // 使用reduce过滤空值,并返回一个新对象 + return Object.keys(model).reduce((prev, next) => { + const value = model[next] + if (!isEmptyVal(value)) { + if (isObject(value)) { + if (Object.keys(value).length > 0) { + prev[next] = value + } + } else { + prev[next] = value + } + } + return prev + }, {}) as T + } else { + return model as T + } }, /** diff --git a/src/router/index.ts b/src/router/index.ts index a7f12d2..2e20007 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -374,6 +374,15 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [ meta: { title: t('router.request') } + }, + { + path: 'test', + component: () => import('@/views/Function/Test.vue'), + name: 'Test', + meta: { + title: t('router.permission'), + permission: ['add', 'edit', 'delete'] + } } ] }, @@ -644,15 +653,6 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [ meta: { title: t('router.role') } - }, - { - path: 'test', - component: () => import('@/views/Authorization/Test/Test.vue'), - name: 'Test', - meta: { - title: t('router.permission'), - permission: ['add', 'edit', 'delete'] - } } ] } diff --git a/src/views/Authorization/Menu/Menu.vue b/src/views/Authorization/Menu/Menu.vue index cf43ef4..ee5bd22 100644 --- a/src/views/Authorization/Menu/Menu.vue +++ b/src/views/Authorization/Menu/Menu.vue @@ -10,6 +10,7 @@ import { Search } from '@/components/Search' import { FormSchema } from '@/components/Form' import { ContentWrap } from '@/components/ContentWrap' import Write from './components/Write.vue' +import Detail from './components/Detail.vue' import { Dialog } from '@/components/Dialog' const { t } = useI18n() @@ -54,16 +55,16 @@ const tableColumns = reactive([ } } }, - { - field: 'meta.permission', - label: t('menu.permission'), - slots: { - default: (data: any) => { - const permission = data.row.meta.permission - return permission ? <>{permission.join(', ')} : null - } - } - }, + // { + // field: 'meta.permission', + // label: t('menu.permission'), + // slots: { + // default: (data: any) => { + // const permission = data.row.meta.permission + // return permission ? <>{permission.join(', ')} : null + // } + // } + // }, { field: 'component', label: t('menu.component'), @@ -105,6 +106,9 @@ const tableColumns = reactive([ action(row, 'edit')}> {t('exampleDemo.edit')} + action(row, 'detail')}> + {t('exampleDemo.detail')} + {t('exampleDemo.del')} ) @@ -154,6 +158,7 @@ const AddAction = () => { const save = async () => { const write = unref(writeRef) const formData = await write?.submit() + console.log(formData) if (formData) { saveLoading.value = true setTimeout(() => { @@ -183,6 +188,8 @@ const save = async () => { + +