From bc98ab3805ca89fa1bcdc3c3e4ecc3b265e1df5f Mon Sep 17 00:00:00 2001 From: fmm <1442620801@qq.com> Date: Sat, 3 Aug 2024 18:33:38 +0800 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20vue=E6=96=B0=E5=A2=9E=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nestJs/src/role/dto/delete-role.dto.ts | 6 - .../pro/template/tinyvue/src/api/menu.ts | 19 + .../pro/template/tinyvue/src/api/role.ts | 18 +- .../tinyvue/src/components/menu/index.vue | 17 +- .../pro/template/tinyvue/src/locale/en-US.ts | 5 + .../pro/template/tinyvue/src/locale/zh-CN.ts | 5 + .../tinyvue/src/router/routes/modules/role.ts | 29 + .../permission/info/components/info-tab.vue | 3 +- .../template/tinyvue/src/views/role/index.vue | 5 + .../views/role/info/components/info-tab.vue | 497 ++++++++++++++++++ .../tinyvue/src/views/role/info/index.vue | 61 +++ .../src/views/role/info/locale/en-US.ts | 18 + .../src/views/role/info/locale/zh-CN.ts | 18 + .../src/views/userManager/setting/index.vue | 4 +- .../src/views/userManager/useradd/index.vue | 4 +- 15 files changed, 690 insertions(+), 19 deletions(-) delete mode 100644 packages/toolkits/pro/template/server/nestJs/src/role/dto/delete-role.dto.ts create mode 100644 packages/toolkits/pro/template/tinyvue/src/api/menu.ts create mode 100644 packages/toolkits/pro/template/tinyvue/src/router/routes/modules/role.ts create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/role/index.vue create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/role/info/components/info-tab.vue create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/role/info/index.vue create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/role/info/locale/en-US.ts create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/role/info/locale/zh-CN.ts diff --git a/packages/toolkits/pro/template/server/nestJs/src/role/dto/delete-role.dto.ts b/packages/toolkits/pro/template/server/nestJs/src/role/dto/delete-role.dto.ts deleted file mode 100644 index a53480b0..00000000 --- a/packages/toolkits/pro/template/server/nestJs/src/role/dto/delete-role.dto.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IsNotEmpty } from 'class-validator'; - -export class DeleteRoleDto { - @IsNotEmpty() - name: string; -} diff --git a/packages/toolkits/pro/template/tinyvue/src/api/menu.ts b/packages/toolkits/pro/template/tinyvue/src/api/menu.ts new file mode 100644 index 00000000..cc79c924 --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/api/menu.ts @@ -0,0 +1,19 @@ +import axios from "axios"; + + + +export function getAllMenu() { + return axios.get('/api/menu'); +} + +export function updateMenu(data: any) { + return axios.patch(`/api/menu`, data); +} + +export function deleteMenu(id: number) { + return axios.delete(`/api/menu/${id}`); +} + +export function createMenu(data: any) { + return axios.post(`/api/menu`, data); +} diff --git a/packages/toolkits/pro/template/tinyvue/src/api/role.ts b/packages/toolkits/pro/template/tinyvue/src/api/role.ts index 089039c5..6e57f754 100644 --- a/packages/toolkits/pro/template/tinyvue/src/api/role.ts +++ b/packages/toolkits/pro/template/tinyvue/src/api/role.ts @@ -2,6 +2,22 @@ import axios from "axios"; -export function getRoles() { +export function getAllRole() { return axios.get('/api/role'); } + +export function getAllRoleDetail() { + return axios.get('/api/role/detail'); +} + +export function updateRole(data: any) { + return axios.patch(`/api/role`, data); +} + +export function deleteRole(id: number) { + return axios.delete(`/api/role/${id}`); +} + +export function createRole(data: any) { + return axios.post(`/api/role`, data); +} diff --git a/packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue b/packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue index b53081d4..a1597c6b 100644 --- a/packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue +++ b/packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue @@ -35,6 +35,7 @@ IconApplication, IconGroup, IconFolderOpened, + IconActivation, } from '@opentiny/vue-icon'; import { TreeMenu as tinyTreeMenu } from '@opentiny/vue'; import router from '@/router'; @@ -52,6 +53,7 @@ const iconApplication = IconApplication(); const iconFolderOpened = IconFolderOpened(); const iconGroup = IconGroup(); + const iconActivation = IconActivation(); const tree = ref(); const expandeArr = ref(); const routerTitle = [ @@ -230,17 +232,18 @@ bold: 'title', }, { - value: 'PermissionSetting', - name: 'menu.permission.setting', - icon: null, - bold: 'title', + value: 'Role', + name: 'menu.role', + icon: iconActivation, + bold: 'main-title', }, { - value: 'PermissionAdd', - name: 'menu.permission.permissionAdd', + value: 'AllRole', + name: 'menu.role.info', icon: null, bold: 'title', }, + ]; // 获取路由数据 @@ -311,6 +314,8 @@ 'User', 'Cloud', 'UserManager', + 'Permission', + 'Role' ]; if (filter.indexOf(data.id) === -1) { router.push({ name: data.id }); diff --git a/packages/toolkits/pro/template/tinyvue/src/locale/en-US.ts b/packages/toolkits/pro/template/tinyvue/src/locale/en-US.ts index 750d6e04..addd305d 100644 --- a/packages/toolkits/pro/template/tinyvue/src/locale/en-US.ts +++ b/packages/toolkits/pro/template/tinyvue/src/locale/en-US.ts @@ -32,6 +32,8 @@ import localeUserManagerUserAdd from '@/views/userManager/useradd/locale/en-US'; import localePermission from '@/views/permission/info/locale/en-US'; +import localeRole from '@/views/role/info/locale/en-US'; + import localeSettings from './en-US/settings'; import localeHttpError from './en-US/httpError'; @@ -56,6 +58,8 @@ export default { 'menu.permission.info':'All Permission Info', 'menu.permission.setting':'Permission Setting', 'menu.permission.permissionAdd':'Add Permission', + 'menu.role': 'Role Manager', + 'menu.role.info':'All Role Info', 'navbar.docs': 'Docs', 'navbar.action.locale': 'Switch to English', 'messageBox.switchRoles': 'Switch Roles', @@ -86,4 +90,5 @@ export default { ...localeUserManagerSetting, ...localeUserManagerUserAdd, ...localePermission, + ...localeRole, }; diff --git a/packages/toolkits/pro/template/tinyvue/src/locale/zh-CN.ts b/packages/toolkits/pro/template/tinyvue/src/locale/zh-CN.ts index 09ae2408..c00ab8cc 100644 --- a/packages/toolkits/pro/template/tinyvue/src/locale/zh-CN.ts +++ b/packages/toolkits/pro/template/tinyvue/src/locale/zh-CN.ts @@ -32,6 +32,8 @@ import localeUserManagerUserAdd from '@/views/userManager/useradd/locale/zh-CN'; import localePermission from '@/views/permission/info/locale/zh-CN'; +import localeRole from '@/views/role/info/locale/zh-CN'; + import localeSettings from './zh-CN/settings'; import localeHttpError from './zh-CN/httpError'; @@ -57,6 +59,8 @@ export default { 'menu.permission.info':'查看权限', 'menu.permission.setting':'修改权限', 'menu.permission.permissionAdd':'添加权限', + 'menu.role': '角色管理', + 'menu.role.info':'查看角色', 'navbar.docs': '文档中心', 'navbar.action.locale': '切换为中文', 'messageBox.switchRoles': '切换角色', @@ -87,4 +91,5 @@ export default { ...localeUserManagerSetting, ...localeUserManagerUserAdd, ...localePermission, + ...localeRole, }; diff --git a/packages/toolkits/pro/template/tinyvue/src/router/routes/modules/role.ts b/packages/toolkits/pro/template/tinyvue/src/router/routes/modules/role.ts new file mode 100644 index 00000000..d6e1f749 --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/router/routes/modules/role.ts @@ -0,0 +1,29 @@ +import { RoleType } from '@/types/roleType'; + +export default { + path: 'role', + name: 'Role', + id: 'Role', + label: 'Role', + component: () => import('@/views/role/index.vue'), + meta: { + locale: 'menu.role', + requiresAuth: true, + order: 9, + roles: [RoleType.admin], + }, + children: [ + { + path: 'allRole', + name: 'AllRole', + id: 'AllRole', + label: 'AllRole', + component: () => import('@/views/role/info/index.vue'), + meta: { + locale: 'menu.role.info', + requiresAuth: true, + roles: [RoleType.admin], + }, + }, + ], +}; diff --git a/packages/toolkits/pro/template/tinyvue/src/views/permission/info/components/info-tab.vue b/packages/toolkits/pro/template/tinyvue/src/views/permission/info/components/info-tab.vue index 88f53dfb..0f4ee9df 100644 --- a/packages/toolkits/pro/template/tinyvue/src/views/permission/info/components/info-tab.vue +++ b/packages/toolkits/pro/template/tinyvue/src/views/permission/info/components/info-tab.vue @@ -2,7 +2,7 @@
- 添加权限 + {{ $t('permissionInfo.modal.title.add') }}
+ + + + diff --git a/packages/toolkits/pro/template/tinyvue/src/views/role/info/components/info-tab.vue b/packages/toolkits/pro/template/tinyvue/src/views/role/info/components/info-tab.vue new file mode 100644 index 00000000..600c885f --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/role/info/components/info-tab.vue @@ -0,0 +1,497 @@ + + + + + diff --git a/packages/toolkits/pro/template/tinyvue/src/views/role/info/index.vue b/packages/toolkits/pro/template/tinyvue/src/views/role/info/index.vue new file mode 100644 index 00000000..5ceec97d --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/role/info/index.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/packages/toolkits/pro/template/tinyvue/src/views/role/info/locale/en-US.ts b/packages/toolkits/pro/template/tinyvue/src/views/role/info/locale/en-US.ts new file mode 100644 index 00000000..c5e62c6d --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/role/info/locale/en-US.ts @@ -0,0 +1,18 @@ +export default { + 'menu.allRole.info': 'All Role Info', + 'roleInfo.table.id': 'ID', + 'roleInfo.table.name': 'Name', + 'roleInfo.table.desc': 'Desc', + 'roleInfo.table.menu': 'Menu', + 'roleInfo.table.operations': 'Operation', + 'roleInfo.table.operations.update': 'Update', + 'roleInfo.table.operations.delete': 'Delete', + 'roleInfo.modal.title.update': 'Update Role', + 'roleInfo.modal.title.add': 'Add Role', + 'roleInfo.modal.input.id': 'ID', + 'roleInfo.modal.input.name': 'Name', + 'roleInfo.modal.input.desc': 'Desc', + 'roleInfo.modal.input.menu': 'Menu', + 'roleInfo.modal.message.error': 'Error', + 'roleInfo.modal.message.notNull': 'Not Null', +}; diff --git a/packages/toolkits/pro/template/tinyvue/src/views/role/info/locale/zh-CN.ts b/packages/toolkits/pro/template/tinyvue/src/views/role/info/locale/zh-CN.ts new file mode 100644 index 00000000..9c48c5e1 --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/role/info/locale/zh-CN.ts @@ -0,0 +1,18 @@ +export default { + 'menu.allRole.info': '查看权限', + 'roleInfo.table.id': 'ID', + 'roleInfo.table.name': '名称', + 'roleInfo.table.desc': '权限', + 'roleInfo.table.menu': '菜单', + 'roleInfo.table.operations': '操作', + 'roleInfo.table.operations.update': '修改', + 'roleInfo.table.operations.delete': '删除', + 'roleInfo.modal.title.update': '修改角色', + 'roleInfo.modal.title.add': '添加角色', + 'roleInfo.modal.input.id': 'ID', + 'roleInfo.modal.input.name': '名称', + 'roleInfo.modal.input.desc': '权限', + 'roleInfo.modal.input.menu': '菜单', + 'roleInfo.modal.message.error': '错误', + 'roleInfo.modal.message.notNull': '不能为空', +}; diff --git a/packages/toolkits/pro/template/tinyvue/src/views/userManager/setting/index.vue b/packages/toolkits/pro/template/tinyvue/src/views/userManager/setting/index.vue index 4286f560..fff3f3f2 100644 --- a/packages/toolkits/pro/template/tinyvue/src/views/userManager/setting/index.vue +++ b/packages/toolkits/pro/template/tinyvue/src/views/userManager/setting/index.vue @@ -169,7 +169,7 @@ import { import {getSimpleDate} from '@/utils/time'; import {useRoute, useRouter} from 'vue-router'; import {getAllUser, getUserInfo, updateUserInfo} from '@/api/user' -import {getRoles} from '@/api/role' +import {getAllRole} from '@/api/role' import headtop from './components/head.vue'; import setFrom from './components/set-from.vue'; @@ -307,7 +307,7 @@ async function fetchData() { } async function fetchRole(){ - const {data} = await getRoles(); + const {data} = await getAllRole(); state.roleData = data; } diff --git a/packages/toolkits/pro/template/tinyvue/src/views/userManager/useradd/index.vue b/packages/toolkits/pro/template/tinyvue/src/views/userManager/useradd/index.vue index 98b0c394..4561fc74 100644 --- a/packages/toolkits/pro/template/tinyvue/src/views/userManager/useradd/index.vue +++ b/packages/toolkits/pro/template/tinyvue/src/views/userManager/useradd/index.vue @@ -180,7 +180,7 @@ import { import {getSimpleDate} from '@/utils/time'; import {useRoute, useRouter} from 'vue-router'; import {getUserInfo, registerUser, updateUserInfo} from '@/api/user' -import {getRoles} from '@/api/role' +import {getAllRole} from '@/api/role' const route = useRoute(); @@ -295,7 +295,7 @@ async function handleSubmit() { } async function fetchRole(){ - const {data} = await getRoles(); + const {data} = await getAllRole(); state.roleData = data; } From e072394981878d5233f6e2e04be74a9cb479fd08 Mon Sep 17 00:00:00 2001 From: fmm <1442620801@qq.com> Date: Sat, 3 Aug 2024 18:34:57 +0800 Subject: [PATCH 02/10] =?UTF-8?q?fix:=20nest=E8=A7=92=E8=89=B2=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/nestJs/src/role/role.controller.ts | 13 +++++++++---- .../server/nestJs/src/role/role.service.ts | 15 +++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/toolkits/pro/template/server/nestJs/src/role/role.controller.ts b/packages/toolkits/pro/template/server/nestJs/src/role/role.controller.ts index b65bd3e4..0b1dd3db 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/role/role.controller.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/role/role.controller.ts @@ -10,7 +10,6 @@ import { import { RoleService } from './role.service'; import { CreateRoleDto } from './dto/create-role.dto'; import { UpdateRoleDto } from './dto/update-role.dto'; -import { DeleteRoleDto } from './dto/delete-role.dto'; import { Permission } from '../public/permission.decorator'; @Controller('role') @@ -29,16 +28,22 @@ export class RoleController { return this.roleService.findAll(); } + @Permission('role::get') + @Get('/detail') + getAllRoleDetail() { + return this.roleService.findAllDetail(); + } + @Patch() @Permission('role::update') updateRole(@Body() dto: UpdateRoleDto) { return this.roleService.update(dto); } - @Delete() + @Delete('/:id') @Permission('role::remove') - deleteRole(@Body() dto: DeleteRoleDto) { - return this.roleService.delete(dto); + deleteRole(@Param('id') id: number) { + return this.roleService.delete(id); } @Permission('role::get') diff --git a/packages/toolkits/pro/template/server/nestJs/src/role/role.service.ts b/packages/toolkits/pro/template/server/nestJs/src/role/role.service.ts index 564c17b9..3adb5baf 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/role/role.service.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/role/role.service.ts @@ -1,7 +1,6 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { CreateRoleDto } from './dto/create-role.dto'; import { UpdateRoleDto } from './dto/update-role.dto'; -import { DeleteRoleDto } from './dto/delete-role.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { Menu, Permission, Role } from '@app/models'; import { DataSource, In, Repository } from 'typeorm'; @@ -42,7 +41,15 @@ export class RoleService { return this.role.save({ name, permission: permissions, menus }); } findAll() { - return this.role.find(); + return this.role.find() + } + + findAllDetail(){ + return this.role + .createQueryBuilder('role') + .leftJoinAndSelect('role.menus','menus') + .leftJoinAndSelect('role.permission','permission') + .getMany(); } async findOne(id: string) { @@ -83,10 +90,10 @@ export class RoleService { role.menus = menus.length ? menus : undefined; return this.role.save(role); } - async delete(data: DeleteRoleDto) { + async delete(id: number) { const role = await this.role.find({ where: { - name: data.name, + id: id, }, }); return this.role.remove(role); From 26bb32919b139b2b9ccb7020d1425396622532c8 Mon Sep 17 00:00:00 2001 From: fmm <1442620801@qq.com> Date: Sun, 4 Aug 2024 21:51:42 +0800 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20vue=E6=96=B0=E5=A2=9Emenu?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tinyvue/src/components/menu/index.vue | 18 +- .../pro/template/tinyvue/src/locale/en-US.ts | 5 + .../pro/template/tinyvue/src/locale/zh-CN.ts | 5 + .../tinyvue/src/router/routes/modules/menu.ts | 29 + .../template/tinyvue/src/views/menu/index.vue | 5 + .../views/menu/info/components/info-tab.vue | 558 ++++++++++++++++++ .../tinyvue/src/views/menu/info/index.vue | 61 ++ .../src/views/menu/info/locale/en-US.ts | 18 + .../src/views/menu/info/locale/zh-CN.ts | 18 + 9 files changed, 715 insertions(+), 2 deletions(-) create mode 100644 packages/toolkits/pro/template/tinyvue/src/router/routes/modules/menu.ts create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/menu/index.vue create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/menu/info/index.vue create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/menu/info/locale/en-US.ts create mode 100644 packages/toolkits/pro/template/tinyvue/src/views/menu/info/locale/zh-CN.ts diff --git a/packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue b/packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue index a1597c6b..70fd6f21 100644 --- a/packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue +++ b/packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue @@ -36,6 +36,7 @@ IconGroup, IconFolderOpened, IconActivation, + IconGrade, } from '@opentiny/vue-icon'; import { TreeMenu as tinyTreeMenu } from '@opentiny/vue'; import router from '@/router'; @@ -54,6 +55,7 @@ const iconFolderOpened = IconFolderOpened(); const iconGroup = IconGroup(); const iconActivation = IconActivation(); + const iconGrade = IconGrade(); const tree = ref(); const expandeArr = ref(); const routerTitle = [ @@ -243,7 +245,18 @@ icon: null, bold: 'title', }, - + { + value: 'Menu', + name: 'menu.menu', + icon: iconGrade, + bold: 'main-title', + }, + { + value: 'AllMenu', + name: 'menu.menu.info', + icon: null, + bold: 'title', + }, ]; // 获取路由数据 @@ -315,7 +328,8 @@ 'Cloud', 'UserManager', 'Permission', - 'Role' + 'Role', + 'Menu', ]; if (filter.indexOf(data.id) === -1) { router.push({ name: data.id }); diff --git a/packages/toolkits/pro/template/tinyvue/src/locale/en-US.ts b/packages/toolkits/pro/template/tinyvue/src/locale/en-US.ts index addd305d..bd60f659 100644 --- a/packages/toolkits/pro/template/tinyvue/src/locale/en-US.ts +++ b/packages/toolkits/pro/template/tinyvue/src/locale/en-US.ts @@ -34,6 +34,8 @@ import localePermission from '@/views/permission/info/locale/en-US'; import localeRole from '@/views/role/info/locale/en-US'; +import localeMenu from '@/views/menu/info/locale/en-US'; + import localeSettings from './en-US/settings'; import localeHttpError from './en-US/httpError'; @@ -60,6 +62,8 @@ export default { 'menu.permission.permissionAdd':'Add Permission', 'menu.role': 'Role Manager', 'menu.role.info':'All Role Info', + 'menu.menu': 'Menu Manager', + 'menu.menu.info': 'All Menu Info', 'navbar.docs': 'Docs', 'navbar.action.locale': 'Switch to English', 'messageBox.switchRoles': 'Switch Roles', @@ -91,4 +95,5 @@ export default { ...localeUserManagerUserAdd, ...localePermission, ...localeRole, + ...localeMenu, }; diff --git a/packages/toolkits/pro/template/tinyvue/src/locale/zh-CN.ts b/packages/toolkits/pro/template/tinyvue/src/locale/zh-CN.ts index c00ab8cc..c2c49b48 100644 --- a/packages/toolkits/pro/template/tinyvue/src/locale/zh-CN.ts +++ b/packages/toolkits/pro/template/tinyvue/src/locale/zh-CN.ts @@ -34,6 +34,8 @@ import localePermission from '@/views/permission/info/locale/zh-CN'; import localeRole from '@/views/role/info/locale/zh-CN'; +import localeMenu from '@/views/menu/info/locale/zh-CN'; + import localeSettings from './zh-CN/settings'; import localeHttpError from './zh-CN/httpError'; @@ -61,6 +63,8 @@ export default { 'menu.permission.permissionAdd':'添加权限', 'menu.role': '角色管理', 'menu.role.info':'查看角色', + 'menu.menu': '菜单管理', + 'menu.menu.info': '查看菜单', 'navbar.docs': '文档中心', 'navbar.action.locale': '切换为中文', 'messageBox.switchRoles': '切换角色', @@ -92,4 +96,5 @@ export default { ...localeUserManagerUserAdd, ...localePermission, ...localeRole, + ...localeMenu, }; diff --git a/packages/toolkits/pro/template/tinyvue/src/router/routes/modules/menu.ts b/packages/toolkits/pro/template/tinyvue/src/router/routes/modules/menu.ts new file mode 100644 index 00000000..8f645538 --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/router/routes/modules/menu.ts @@ -0,0 +1,29 @@ +import { RoleType } from '@/types/roleType'; + +export default { + path: 'menu', + name: 'Menu', + id: 'Menu', + label: 'Menu', + component: () => import('@/views/menu/index.vue'), + meta: { + locale: 'menu.menu', + requiresAuth: true, + order: 9, + roles: [RoleType.admin], + }, + children: [ + { + path: 'allMenu', + name: 'AllMenu', + id: 'AllMenu', + label: 'AllMenu', + component: () => import('@/views/menu/info/index.vue'), + meta: { + locale: 'menu.menu.info', + requiresAuth: true, + roles: [RoleType.admin], + }, + }, + ], +}; diff --git a/packages/toolkits/pro/template/tinyvue/src/views/menu/index.vue b/packages/toolkits/pro/template/tinyvue/src/views/menu/index.vue new file mode 100644 index 00000000..6c71efda --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/menu/index.vue @@ -0,0 +1,5 @@ + + + diff --git a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue new file mode 100644 index 00000000..ccd5e376 --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue @@ -0,0 +1,558 @@ + + + + + diff --git a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/index.vue b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/index.vue new file mode 100644 index 00000000..5ceec97d --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/index.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/locale/en-US.ts b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/locale/en-US.ts new file mode 100644 index 00000000..1bcc2676 --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/locale/en-US.ts @@ -0,0 +1,18 @@ +export default { + 'menu.allMenu.info': 'All Menu Info', + 'menuInfo.table.id': 'ID', + 'menuInfo.table.name': 'Name', + 'menuInfo.table.order': 'Order', + 'menuInfo.table.parentId': 'ParentID', + 'menuInfo.table.menuType': 'MenuType', + 'menuInfo.table.icon': 'Icon', + 'menuInfo.table.component': 'Component', + 'menuInfo.table.path': 'Path', + 'menuInfo.table.operations': 'Operation', + 'menuInfo.table.operations.update': 'Update', + 'menuInfo.table.operations.delete': 'Delete', + 'menuInfo.modal.title.update': 'Update Menu', + 'menuInfo.modal.title.add': 'Add Menu', + 'menuInfo.modal.message.error': 'Error', + 'menuInfo.modal.message.notNull': 'Not Null', +}; diff --git a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/locale/zh-CN.ts b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/locale/zh-CN.ts new file mode 100644 index 00000000..4407baad --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/locale/zh-CN.ts @@ -0,0 +1,18 @@ +export default { + 'menu.allMenu.info': '查看菜单', + 'menuInfo.table.id': 'ID', + 'menuInfo.table.name': '名称', + 'menuInfo.table.order': '优先级', + 'menuInfo.table.parentId': '父菜单ID', + 'menuInfo.table.menuType': '菜单类型', + 'menuInfo.table.icon': '图标', + 'menuInfo.table.component': '组件', + 'menuInfo.table.path': '路径', + 'menuInfo.table.operations': '操作', + 'menuInfo.table.operations.update': '修改', + 'menuInfo.table.operations.delete': '删除', + 'menuInfo.modal.title.update': '修改菜单', + 'menuInfo.modal.title.add': '添加菜单', + 'menuInfo.modal.message.error': '错误', + 'menuInfo.modal.message.notNull': '不能为空', +}; From d1854d8597c17d59291681955f2be74ec9bc1761 Mon Sep 17 00:00:00 2001 From: fmm <1442620801@qq.com> Date: Mon, 5 Aug 2024 21:26:14 +0800 Subject: [PATCH 04/10] =?UTF-8?q?fix:=20vue=E5=AE=8C=E5=96=84=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/template/tinyvue/src/api/menu.ts | 8 +- .../views/menu/info/components/info-tab.vue | 380 ++++++++++-------- .../tinyvue/src/views/menu/info/index.vue | 2 +- .../src/views/menu/info/locale/en-US.ts | 4 +- .../src/views/menu/info/locale/zh-CN.ts | 5 +- .../permission/info/components/info-tab.vue | 3 + 6 files changed, 230 insertions(+), 172 deletions(-) diff --git a/packages/toolkits/pro/template/tinyvue/src/api/menu.ts b/packages/toolkits/pro/template/tinyvue/src/api/menu.ts index cc79c924..03e2cf3a 100644 --- a/packages/toolkits/pro/template/tinyvue/src/api/menu.ts +++ b/packages/toolkits/pro/template/tinyvue/src/api/menu.ts @@ -6,12 +6,16 @@ export function getAllMenu() { return axios.get('/api/menu'); } +export function getRoleMenu(data: any) { + return axios.get('/api/menu/role',data); +} + export function updateMenu(data: any) { return axios.patch(`/api/menu`, data); } -export function deleteMenu(id: number) { - return axios.delete(`/api/menu/${id}`); +export function deleteMenu(data: any) { + return axios.delete(`/api/menu`, data); } export function createMenu(data: any) { diff --git a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue index ccd5e376..a23a5b19 100644 --- a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue +++ b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue @@ -5,130 +5,123 @@ {{ $t('menuInfo.modal.title.add') }}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
+
+ + + + +
@@ -163,9 +156,9 @@ - + @@ -185,7 +178,15 @@ :label="$t('menuInfo.table.parentId')" prop="parentId" > - + + @@ -223,9 +224,9 @@ - + @@ -263,9 +264,9 @@ - + @@ -285,7 +286,15 @@ :label="$t('menuInfo.table.parentId')" prop="parentId" > - + + @@ -323,9 +332,9 @@ - + @@ -344,11 +353,7 @@ import {ref, reactive, onMounted, watch, computed} from 'vue'; import {useI18n} from 'vue-i18n'; import { - Tabs as TinyTabs, - TabItem as TinyTabItem, - Loading, - GridColumn as TinyGridColumn, - Grid as TinyGrid, Pager as TinyPager, Modal as TinyModal, + Modal as TinyModal, Button as TinyButton, Form as TinyForm, FormItem as TinyFormItem, @@ -358,6 +363,7 @@ import { BaseSelect as TinyBaseSelect, Select as TinySelect, Option as TinyOption, + Tree as TinyTree, } from '@opentiny/vue'; import {IconChevronDown} from '@opentiny/vue-icon'; import {useUserStore} from '@/store'; @@ -371,23 +377,27 @@ const router = useRouter(); const {t} = useI18n(); +const treeRef = ref(); + // 加载效果 const state = reactive<{ tableData: any; - permissionData: any; menuData: any; menuUpdData: any; menuAddData: any; + menuInfoData: any; isMenuUpdate: boolean; isMenuAdd: boolean; + isMenuInfo: boolean; }>({ tableData: [] as any, - permissionData: [] as any, menuData: {} as any, menuUpdData: {} as any, menuAddData: {} as any, + menuInfoData: {} as any, isMenuAdd: false, isMenuUpdate: false, + isMenuInfo: false, }); // 变量设置 @@ -405,19 +415,18 @@ const rulesSelect = { }; const rules = computed(() => { return { - name: [rulesType], + label: [rulesType], order: [rulesType], - parentId: [rulesType], menuType: [rulesType], icon: [rulesType], component: [rulesType], - path: [rulesType], + url: [rulesType], }; }); // 初始化请求数据 onMounted(() => { - // fetchMenuData(); + fetchMenuData(); }); // 请求数据接口方法 @@ -427,15 +436,18 @@ async function fetchMenuData() { }; -async function handleDelete (id: string){ +async function handleDelete (node: any){ + let newTemp = { + id: node.data.id, + parentId: node.data.parentId, + }; try { - await deleteMenu(id); + await deleteMenu(newTemp); TinyModal.message({ message: '已删除', status: 'success', }); - state.isMenuUpdate = false; - state.menuUpdData = {} as any; + await fetchMenuData(); } catch (error) { if (error.response && error.response.data) { const errorMessage = error.response.data.message || '未知错误'; @@ -447,9 +459,12 @@ async function handleDelete (id: string){ } } -const handleUpdate = (id: string) => { +const handleUpdate = (node: any) => { state.isMenuUpdate = true; - state.menuUpdData = state.tableData[id - 1]; + state.menuUpdData = node.data; + state.menuData = ref({ + data: state.tableData, + }) } const handleMenuUpdateCancel =()=>{ @@ -457,43 +472,72 @@ const handleMenuUpdateCancel =()=>{ state.menuUpdData = {} as any; } +const handleCheck = (node: any) => { + state.isMenuInfo = true; + state.menuInfoData = node.data; +} + +const handleMenuInfoCancel = () => { + state.isMenuInfo = false; + state.menuInfoData = {} as any; +} + async function handleMenuUpdateSubmit(){ let data = state.menuUpdData; let newTemp = { id: data.id, - name: data.name, - permissionIds: data.desc, - menuIds:data.menu, + name: data.label, + order: data.order, + parentId: data.parentId, + menuType: data.menuType, + icon: data.icon, + component: data.component, + path: data.url, }; - try { - await updateMenu(newTemp); + if(newTemp.id === newTemp.parentId){ Modal.message({ - message: t('baseForm.form.submit.success'), - status: 'success', + message: t('menuInfo.modal.message.error'), + status: 'error', }); - state.isMenuUpdate = false; - state.menuUpdData = {} as any; - } catch (error) { - if (error.response && error.response.data) { - const errorMessage = error.response.data.message || '未知错误'; + }else{ + try { + await updateMenu(newTemp); Modal.message({ - message: errorMessage, - status: 'error', + message: t('baseForm.form.submit.success'), + status: 'success', }); + state.isMenuUpdate = false; + state.menuUpdData = {} as any; + await fetchMenuData(); + } catch (error) { + if (error.response && error.response.data) { + const errorMessage = error.response.data.message || '未知错误'; + Modal.message({ + message: errorMessage, + status: 'error', + }); + } } } } function handleAddMenu() { state.isMenuAdd = true; + state.menuData = ref({ + data: state.tableData, + }) } async function handleMenuAddSubmit() { let data = state.menuAddData; let newTemp = { - name: data.name, - permissionIds: data.desc, - menuIds:data.menu, + name: data.label, + order: data.order, + parentId: data.parentId, + menuType: data.menuType, + icon: data.icon, + component: data.component, + path: data.url, }; try { await createMenu(newTemp); @@ -503,6 +547,7 @@ async function handleMenuAddSubmit() { }); state.isMenuAdd = false; state.menuAddData = {} as any; + await fetchMenuData(); } catch (error) { if (error.response && error.response.data) { const errorMessage = error.response.data.message || '未知错误'; @@ -540,8 +585,8 @@ async function handleMenuAddCancel() { .operation { &-delete { - padding-right: 5px; color: red; + padding-right: 10px; } &-update { @@ -549,8 +594,9 @@ async function handleMenuAddCancel() { color: #1890ff; } - &-pwd-update { + &-info { color: orange; + padding-right: 10px; } } diff --git a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/index.vue b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/index.vue index 5ceec97d..4164be0e 100644 --- a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/index.vue +++ b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/index.vue @@ -1,6 +1,6 @@ @@ -57,22 +58,20 @@ + + + - - - - - - - - - @@ -159,18 +158,16 @@ :label="$t('roleInfo.modal.input.menu')" prop="menu" > - - - + @@ -190,7 +187,7 @@ show-header show-footer mask-closable="true" - height="350" + height="auto" width="600" :title="$t('roleInfo.modal.title.add')" > @@ -243,18 +240,16 @@ :label="$t('roleInfo.modal.input.menu')" prop="menu" > - - - + @@ -287,6 +282,7 @@ import { BaseSelect as TinyBaseSelect, Select as TinySelect, Option as TinyOption, + Tree as TinyTree, } from '@opentiny/vue'; import {IconChevronDown} from '@opentiny/vue-icon'; import {useUserStore} from '@/store'; @@ -306,6 +302,7 @@ const state = reactive<{ tableData: any; permissionData: any; menuData: any; + menuOptionData: any; roleUpdData: any; roleAddData: any; isRoleUpdate: boolean; @@ -314,6 +311,7 @@ const state = reactive<{ tableData: [] as any, permissionData: [] as any, menuData: {} as any, + menuOptionData: {} as any, roleUpdData: {} as any, roleAddData: {} as any, isRoleAdd: false, @@ -351,19 +349,20 @@ onMounted(() => { // 请求数据接口方法 async function fetchRoleData() { const {data} = await getAllRoleDetail(); - state.tableData = data; + for(let i = 0; i < data.roleInfo.length; i+=1){ + data.roleInfo[i].menuTree = data.menuTree[i] + } + state.tableData = data.roleInfo }; async function fetchPermissionData() { const {data} = await getAllPermission(); state.permissionData = data; - console.log(state.permissionData) }; async function fetchMenuData() { const {data} = await getAllMenu(); state.menuData = data; - }; async function handleDelete (id: string){ @@ -386,9 +385,37 @@ async function handleDelete (id: string){ } } +async function convertMenu(data: any){ + let menu = [] as any; + for (let j = 0; j < data.menus.length; j+=1){ + menu.push(data.menus[j].id) + if(data.menus[j].children !== null){ + convertMenu(data.menus[j].children) + } + } + return menu; +} + const handleUpdate = (id: string) => { state.isRoleUpdate = true; - state.roleUpdData = state.tableData[id - 1]; + let data = state.tableData[id - 1]; + let permission = [] as any; + for (let i = 0; i < data.permission.length; i+=1){ + permission.push(data.permission[i].id) + } + let menu = [] as any; + for (let j = 0; j < data.menus.length; j+=1){ + menu.push(data.menus[j].id) + } + state.roleUpdData = { + id: data.id, + name: data.name, + menus: menu, + desc: permission, + } + state.menuOptionData = ref({ + data: state.menuData + }) } const handleRoleUpdateCancel =()=>{ @@ -402,7 +429,7 @@ async function handleRoleUpdateSubmit(){ id: data.id, name: data.name, permissionIds: data.desc, - menuIds:data.menu, + menuIds:data.menus, }; try { await updateRole(newTemp); @@ -412,6 +439,7 @@ async function handleRoleUpdateSubmit(){ }); state.isRoleUpdate = false; state.roleUpdData = {} as any; + await fetchRoleData(); } catch (error) { if (error.response && error.response.data) { const errorMessage = error.response.data.message || '未知错误'; @@ -425,6 +453,9 @@ async function handleRoleUpdateSubmit(){ function handleAddRole() { state.isRoleAdd = true; + state.menuOptionData = ref({ + data: state.menuData + }) } async function handleRoleAddSubmit() { @@ -432,7 +463,7 @@ async function handleRoleAddSubmit() { let newTemp = { name: data.name, permissionIds: data.desc, - menuIds:data.menu, + menuIds:data.menus, }; try { await createRole(newTemp); @@ -442,6 +473,7 @@ async function handleRoleAddSubmit() { }); state.isRoleAdd = false; state.roleAddData = {} as any; + await fetchRoleData(); } catch (error) { if (error.response && error.response.data) { const errorMessage = error.response.data.message || '未知错误'; diff --git a/packages/toolkits/pro/template/tinyvue/src/views/userManager/info/components/info-tab.vue b/packages/toolkits/pro/template/tinyvue/src/views/userManager/info/components/info-tab.vue index 4ed20dd4..b669f356 100644 --- a/packages/toolkits/pro/template/tinyvue/src/views/userManager/info/components/info-tab.vue +++ b/packages/toolkits/pro/template/tinyvue/src/views/userManager/info/components/info-tab.vue @@ -167,7 +167,7 @@ show-header show-footer mask-closable="true" - height="350" + height="auto" width="600" :title="$t('userInfo.modal.title.pwdUpdate')" > From 157c1c97458f7f1c5013e735383616d4faf99c00 Mon Sep 17 00:00:00 2001 From: fmm <1442620801@qq.com> Date: Mon, 5 Aug 2024 23:37:05 +0800 Subject: [PATCH 07/10] =?UTF-8?q?fix:=20nest=E5=AE=8C=E5=96=84role?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/nestJs/src/menu/menu.controller.ts | 8 ++++---- .../server/nestJs/src/menu/menu.service.ts | 4 ++-- .../server/nestJs/src/role/role.service.ts | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/toolkits/pro/template/server/nestJs/src/menu/menu.controller.ts b/packages/toolkits/pro/template/server/nestJs/src/menu/menu.controller.ts index dcb4fb5b..4b0fca6e 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/menu/menu.controller.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/menu/menu.controller.ts @@ -5,7 +5,7 @@ import { Body, Patch, Req, - Delete, + Delete, Param, } from '@nestjs/common'; import { MenuService } from './menu.service'; import { CreateMenuDto } from './dto/create-menu.dto'; @@ -17,9 +17,9 @@ import { DeleteMenuDto } from './dto/delete-menu.dto'; export class MenuController { constructor(private readonly menuService: MenuService) {} - @Get('/role') - async getMenus(@Req() req) { - return this.menuService.findRoleMenu(req.user); + @Get('/role/:email') + async getMenus(@Param('email') email: string) { + return this.menuService.findRoleMenu(email); } @Get() diff --git a/packages/toolkits/pro/template/server/nestJs/src/menu/menu.service.ts b/packages/toolkits/pro/template/server/nestJs/src/menu/menu.service.ts index bcbf6f18..07bc4748 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/menu/menu.service.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/menu/menu.service.ts @@ -70,13 +70,13 @@ export class MenuService { @InjectRepository(Menu) private menu: Repository ) {} - async findRoleMenu(user: User) { + async findRoleMenu(email: string) { const userInfo = await this.user .createQueryBuilder('user') .leftJoinAndSelect('user.role', 'role') .leftJoinAndSelect('role.menus', 'menus') .where({ - email: user.email, + email: email, }) .orderBy('menus.order', 'ASC') .getOne(); diff --git a/packages/toolkits/pro/template/server/nestJs/src/role/role.service.ts b/packages/toolkits/pro/template/server/nestJs/src/role/role.service.ts index 3adb5baf..0fdacd93 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/role/role.service.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/role/role.service.ts @@ -4,6 +4,7 @@ import { UpdateRoleDto } from './dto/update-role.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { Menu, Permission, Role } from '@app/models'; import { DataSource, In, Repository } from 'typeorm'; +import { convertToTree } from "../menu/menu.service"; @Injectable() export class RoleService { @@ -44,12 +45,22 @@ export class RoleService { return this.role.find() } - findAllDetail(){ - return this.role + async findAllDetail() { + const roleInfo = await this.role .createQueryBuilder('role') - .leftJoinAndSelect('role.menus','menus') - .leftJoinAndSelect('role.permission','permission') + .leftJoinAndSelect('role.menus', 'menus') + .leftJoinAndSelect('role.permission', 'permission') .getMany(); + const menuTree = [] as any; + for(const item of roleInfo){ + const temp = convertToTree(item.menus); + menuTree.push(temp) + } + + return { + roleInfo: roleInfo, + menuTree: menuTree, + } } async findOne(id: string) { From c12c5d9194282cb0abbaa8e1d6cab5732f03973d Mon Sep 17 00:00:00 2001 From: fmm <1442620801@qq.com> Date: Tue, 6 Aug 2024 16:39:38 +0800 Subject: [PATCH 08/10] =?UTF-8?q?fix:=20=E6=A3=80=E8=A7=86=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/server/nestJs/src/menu/dto/delete-menu.dto.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/toolkits/pro/template/server/nestJs/src/menu/dto/delete-menu.dto.ts b/packages/toolkits/pro/template/server/nestJs/src/menu/dto/delete-menu.dto.ts index 8190314a..0d06ac3b 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/menu/dto/delete-menu.dto.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/menu/dto/delete-menu.dto.ts @@ -1,7 +1,6 @@ import { IsNotEmpty } from 'class-validator'; -import { PartialType } from '@nestjs/mapped-types'; -import { CreateMenuDto } from './create-menu.dto'; -export class DeleteMenuDto extends PartialType(CreateMenuDto) { +export class DeleteMenuDto { @IsNotEmpty() id: number; + parentId: number | null; } From c6b4b4f506f1fff6e794ea4f78c49e85ea27ffe0 Mon Sep 17 00:00:00 2001 From: fmm <1442620801@qq.com> Date: Tue, 6 Aug 2024 17:23:59 +0800 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20vue=E4=BF=AE=E5=A4=8D=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=88=A0=E9=99=A4=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/toolkits/pro/template/tinyvue/src/api/menu.ts | 4 ++-- .../tinyvue/src/views/menu/info/components/info-tab.vue | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/toolkits/pro/template/tinyvue/src/api/menu.ts b/packages/toolkits/pro/template/tinyvue/src/api/menu.ts index d84519ad..1cb247cb 100644 --- a/packages/toolkits/pro/template/tinyvue/src/api/menu.ts +++ b/packages/toolkits/pro/template/tinyvue/src/api/menu.ts @@ -14,8 +14,8 @@ export function updateMenu(data: any) { return axios.patch(`/api/menu`, data); } -export function deleteMenu(data: any) { - return axios.delete(`/api/menu`, data); +export function deleteMenu(id: number, parentId: number) { + return axios.delete(`/api/menu?id=${id}&parentId=${parentId}`); } export function createMenu(data: any) { diff --git a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue index a23a5b19..e625bc9a 100644 --- a/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue +++ b/packages/toolkits/pro/template/tinyvue/src/views/menu/info/components/info-tab.vue @@ -437,12 +437,11 @@ async function fetchMenuData() { async function handleDelete (node: any){ - let newTemp = { - id: node.data.id, - parentId: node.data.parentId, - }; + if(node.data.parentId === null){ + node.data.parentId = -1 + } try { - await deleteMenu(newTemp); + await deleteMenu(node.data.id, node.data.parentId); TinyModal.message({ message: '已删除', status: 'success', From 640b9f67c5b8d95f14b31cb0034302998423de7b Mon Sep 17 00:00:00 2001 From: fmm <1442620801@qq.com> Date: Tue, 6 Aug 2024 17:25:46 +0800 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20nest=E4=BF=AE=E5=A4=8D=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=88=A0=E9=99=A4=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/nestJs/src/menu/dto/delete-menu.dto.ts | 6 ------ .../server/nestJs/src/menu/menu.controller.ts | 7 +++---- .../template/server/nestJs/src/menu/menu.service.ts | 13 ++++++++----- 3 files changed, 11 insertions(+), 15 deletions(-) delete mode 100644 packages/toolkits/pro/template/server/nestJs/src/menu/dto/delete-menu.dto.ts diff --git a/packages/toolkits/pro/template/server/nestJs/src/menu/dto/delete-menu.dto.ts b/packages/toolkits/pro/template/server/nestJs/src/menu/dto/delete-menu.dto.ts deleted file mode 100644 index 0d06ac3b..00000000 --- a/packages/toolkits/pro/template/server/nestJs/src/menu/dto/delete-menu.dto.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IsNotEmpty } from 'class-validator'; -export class DeleteMenuDto { - @IsNotEmpty() - id: number; - parentId: number | null; -} diff --git a/packages/toolkits/pro/template/server/nestJs/src/menu/menu.controller.ts b/packages/toolkits/pro/template/server/nestJs/src/menu/menu.controller.ts index 4b0fca6e..acbc9b7a 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/menu/menu.controller.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/menu/menu.controller.ts @@ -4,14 +4,13 @@ import { Post, Body, Patch, - Req, + Query, Delete, Param, } from '@nestjs/common'; import { MenuService } from './menu.service'; import { CreateMenuDto } from './dto/create-menu.dto'; import { Permission } from '../public/permission.decorator'; import { UpdateMenuDto } from './dto/update-menu.dto'; -import { DeleteMenuDto } from './dto/delete-menu.dto'; @Controller('menu') export class MenuController { @@ -42,7 +41,7 @@ export class MenuController { @Delete() @Permission('menu::remove') - async deleteMenu(@Body() dto: DeleteMenuDto) { - return this.menuService.deleteMenu(dto); + async deleteMenu(@Query('id') id: number, @Query('parentId') parentId: number) { + return this.menuService.deleteMenu(id, parentId); } } diff --git a/packages/toolkits/pro/template/server/nestJs/src/menu/menu.service.ts b/packages/toolkits/pro/template/server/nestJs/src/menu/menu.service.ts index 07bc4748..67b474bc 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/menu/menu.service.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/menu/menu.service.ts @@ -4,7 +4,6 @@ import { Menu, User } from '@app/models'; import { Repository } from 'typeorm'; import { CreateMenuDto } from './dto/create-menu.dto'; import { UpdateMenuDto } from './dto/update-menu.dto'; -import { DeleteMenuDto } from './dto/delete-menu.dto'; export interface ITreeNodeData { // node-key='id' 设置节点的唯一标识 @@ -125,16 +124,20 @@ export class MenuService { }); return true; } - async deleteMenu(dto: DeleteMenuDto) { + async deleteMenu(id: number, parentId: number) { const menu = this.menu.findOne({ where: { - id: dto.id, + id: id, }, }); const allMenu = await this.menu.find(); for (const tmp of allMenu){ - if(tmp.parentId === dto.id){ - tmp.parentId = dto.parentId + if(Number(tmp.parentId) === Number(id)){ + if(Number(parentId) === -1){ + tmp.parentId = null; + }else { + tmp.parentId = parentId; + } await this.updateMenu(tmp) } }