From 47016a535f2b7a22ab498bee197bc30a983f507d Mon Sep 17 00:00:00 2001 From: kailong321200875 <321200875@qq.com> Date: Sat, 5 Aug 2023 20:34:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/menu/index.ts | 5 + mock/role/index.ts | 36 +++ src/api/role/index.ts | 5 + src/components/Form/src/helper/index.ts | 2 +- src/locales/en.ts | 6 + src/locales/zh-CN.ts | 5 + .../Department/components/Write.vue | 2 +- .../Authorization/Menu/components/Write.vue | 44 ++-- src/views/Authorization/Role/Role.vue | 233 ++++++++++++------ .../Authorization/Role/components/Write.vue | 160 ++++++++++++ .../Authorization/User/components/Write.vue | 2 +- src/views/Example/Dialog/components/Write.vue | 2 +- src/views/Example/Page/components/Write.vue | 2 +- 13 files changed, 398 insertions(+), 106 deletions(-) create mode 100644 src/api/role/index.ts create mode 100644 src/views/Authorization/Role/components/Write.vue diff --git a/mock/menu/index.ts b/mock/menu/index.ts index d5958e9..1e4a62a 100644 --- a/mock/menu/index.ts +++ b/mock/menu/index.ts @@ -173,6 +173,7 @@ export default [ id: toAnyString(), meta: { title: '综合示例-弹窗', + currentPermission: ['edit', 'add'], permission: ['edit', 'add', 'delete'] } }, @@ -184,6 +185,7 @@ export default [ id: toAnyString(), meta: { title: '综合示例-页面', + currentPermission: ['edit', 'add'], permission: ['edit', 'add', 'delete'] } }, @@ -200,6 +202,7 @@ export default [ hidden: true, showMainRoute: true, activeMenu: '/example/example-page', + currentPermission: ['delete', 'add'], permission: ['edit', 'add', 'delete'] } }, @@ -216,6 +219,7 @@ export default [ hidden: true, showMainRoute: true, activeMenu: '/example/example-page', + currentPermission: ['delete', 'add'], permission: ['edit', 'add', 'delete'] } }, @@ -232,6 +236,7 @@ export default [ hidden: true, showMainRoute: true, activeMenu: '/example/example-page', + currentPermission: ['delete', 'edit'], permission: ['edit', 'add', 'delete'] } } diff --git a/mock/role/index.ts b/mock/role/index.ts index 47d14ac..52c8dfd 100644 --- a/mock/role/index.ts +++ b/mock/role/index.ts @@ -1,5 +1,7 @@ import config from '@/config/axios/config' import { MockMethod } from 'vite-plugin-mock' +import Mock from 'mockjs' +import { toAnyString } from '@/utils' const { code } = config @@ -527,6 +529,24 @@ const testList: string[] = [ '/error/500-demo' ] +const List: any[] = [] + +const roleNames = ['超级管理员', '管理员', '普通用户', '游客', '测试用户'] + +for (let i = 0; i < 5; i++) { + List.push( + Mock.mock({ + id: toAnyString(), + // timestamp: +Mock.Random.date('T'), + roleName: roleNames[i], + role: '@first', + status: Mock.Random.integer(0, 1), + createTime: '@datetime', + remark: '@cword(10, 15)' + }) + ) +} + export default [ // 列表接口 { @@ -542,5 +562,21 @@ export default [ } } } + }, + { + url: '/role/table', + method: 'get', + timeout, + response: () => { + return { + data: { + code: code, + data: { + list: List, + total: 5 + } + } + } + } } ] as MockMethod[] diff --git a/src/api/role/index.ts b/src/api/role/index.ts new file mode 100644 index 0000000..3e6d3f8 --- /dev/null +++ b/src/api/role/index.ts @@ -0,0 +1,5 @@ +import request from '@/config/axios' + +export const getRoleListApi = () => { + return request.get({ url: '/role/table' }) +} diff --git a/src/components/Form/src/helper/index.ts b/src/components/Form/src/helper/index.ts index 423993c..d537ad4 100644 --- a/src/components/Form/src/helper/index.ts +++ b/src/components/Form/src/helper/index.ts @@ -146,7 +146,7 @@ export const initModel = (schema: FormSchema[], formModel: Recordable) => { schema.map((v) => { if (v.remove) { delete model[v.field] - } else if (v.component && v.component !== 'Divider') { + } else if (v.component !== 'Divider') { // const hasField = Reflect.has(model, v.field) const hasField = get(model, v.field) // 如果先前已经有值存在,则不进行重新赋值,而是采用现有的值 diff --git a/src/locales/en.ts b/src/locales/en.ts index 3344dc8..8ec268b 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -523,6 +523,12 @@ export default { canTo: 'Can to', name: 'Name' }, + role: { + roleName: 'Role name', + role: 'Role', + // 菜单分配 + menu: 'Menu allocation' + }, inputPasswordDemo: { title: 'InputPassword', inputPasswordDes: 'Secondary packaging of Input components based on ElementPlus' diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 80510ce..b44a594 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -517,6 +517,11 @@ export default { canTo: '是否可跳转', name: '组件名称' }, + role: { + roleName: '角色名称', + role: '角色', + menu: '菜单分配' + }, inputPasswordDemo: { title: '密码输入框', inputPasswordDes: '基于 ElementPlus 的 Input 组件二次封装' diff --git a/src/views/Authorization/Department/components/Write.vue b/src/views/Authorization/Department/components/Write.vue index 2cde58f..512e651 100644 --- a/src/views/Authorization/Department/components/Write.vue +++ b/src/views/Authorization/Department/components/Write.vue @@ -34,7 +34,7 @@ const submit = async () => { console.log(err) }) if (valid) { - const formData = getFormData() + const formData = await getFormData() return formData } } diff --git a/src/views/Authorization/Menu/components/Write.vue b/src/views/Authorization/Menu/components/Write.vue index a622a95..2ba8b5b 100644 --- a/src/views/Authorization/Menu/components/Write.vue +++ b/src/views/Authorization/Menu/components/Write.vue @@ -64,27 +64,27 @@ const formSchema = reactive([ label: t('menu.activeMenu'), component: 'Input' }, - { - field: 'meta.permission', - label: t('menu.permission'), - component: 'CheckboxGroup', - componentProps: { - options: [ - { - label: 'add', - value: 'add' - }, - { - label: 'edit', - value: 'edit' - }, - { - label: 'delete', - value: 'delete' - } - ] - } - }, + // { + // field: 'meta.permission', + // label: t('menu.permission'), + // component: 'CheckboxGroup', + // componentProps: { + // options: [ + // { + // label: 'add', + // value: 'add' + // }, + // { + // label: 'edit', + // value: 'edit' + // }, + // { + // label: 'delete', + // value: 'delete' + // } + // ] + // } + // }, { field: 'meta.hidden', label: t('menu.hidden'), @@ -137,7 +137,7 @@ const submit = async () => { console.log(err) }) if (valid) { - const formData = getFormData() + const formData = await getFormData() return formData } } diff --git a/src/views/Authorization/Role/Role.vue b/src/views/Authorization/Role/Role.vue index bf4c08d..68096af 100644 --- a/src/views/Authorization/Role/Role.vue +++ b/src/views/Authorization/Role/Role.vue @@ -1,91 +1,166 @@ - diff --git a/src/views/Authorization/Role/components/Write.vue b/src/views/Authorization/Role/components/Write.vue new file mode 100644 index 0000000..ffff3e1 --- /dev/null +++ b/src/views/Authorization/Role/components/Write.vue @@ -0,0 +1,160 @@ + + + diff --git a/src/views/Authorization/User/components/Write.vue b/src/views/Authorization/User/components/Write.vue index 16100cc..030599e 100644 --- a/src/views/Authorization/User/components/Write.vue +++ b/src/views/Authorization/User/components/Write.vue @@ -36,7 +36,7 @@ const submit = async () => { console.log(err) }) if (valid) { - const formData = getFormData() + const formData = await getFormData() return formData } } diff --git a/src/views/Example/Dialog/components/Write.vue b/src/views/Example/Dialog/components/Write.vue index 5dc8ac1..2ea183a 100644 --- a/src/views/Example/Dialog/components/Write.vue +++ b/src/views/Example/Dialog/components/Write.vue @@ -36,7 +36,7 @@ const submit = async () => { console.log(err) }) if (valid) { - const formData = getFormData() + const formData = await getFormData() return formData } } diff --git a/src/views/Example/Page/components/Write.vue b/src/views/Example/Page/components/Write.vue index 22eaac5..c4f50ad 100644 --- a/src/views/Example/Page/components/Write.vue +++ b/src/views/Example/Page/components/Write.vue @@ -120,7 +120,7 @@ const submit = async () => { console.log(err) }) if (valid) { - const formData = getFormData() + const formData = await getFormData() return formData } }