Skip to content

Commit

Permalink
feat(projects): add page manage and remove page user
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Nov 5, 2023
1 parent cb6c7d1 commit 73b023c
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 58 deletions.
8 changes: 5 additions & 3 deletions src/locales/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ const local: App.I18n.Schema = {
500: 'Server Error',
home: 'Home',
'user-center': 'User Center',
user: 'User Management',
user_list: 'User List',
user_detail: 'User List Detail',
manage: 'System Manage',
manage_user: 'User Manage',
'manage_user-detail': 'User Detail',
manage_role: 'Role Manage',
manage_route: 'Route Manage',
'multi-menu': 'Multi Menu',
'multi-menu_first': 'Menu One',
'multi-menu_first_child': 'Menu One Child',
Expand Down
8 changes: 5 additions & 3 deletions src/locales/lang/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ const local: App.I18n.Schema = {
500: '服务器错误',
home: '首页',
'user-center': '个人中心',
user: '用户管理',
user_list: '用户列表',
user_detail: '用户列表详情',
manage: '系统管理',
manage_user: '用户管理',
'manage_user-detail': '用户详情',
manage_role: '角色管理',
manage_route: '路由管理',
'multi-menu': '多级菜单',
'multi-menu_first': '菜单一',
'multi-menu_first_child': '菜单一子菜单',
Expand Down
6 changes: 4 additions & 2 deletions src/router/elegant/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export const views: Record<LastLevelRouteKey, RouteComponent | (() => Promise<Ro
500: () => import("@/views/_builtin/500/index.vue"),
login: () => import("@/views/_builtin/login/index.vue"),
home: () => import("@/views/home/index.vue"),
manage_role: () => import("@/views/manage/role/index.vue"),
manage_route: () => import("@/views/manage/route/index.vue"),
"manage_user-detail": () => import("@/views/manage/user-detail/[id].vue"),
manage_user: () => import("@/views/manage/user/index.vue"),
"multi-menu_first_child": () => import("@/views/multi-menu/first_child/index.vue"),
"multi-menu_second_child_home": () => import("@/views/multi-menu/second_child_home/index.vue"),
"user-center": () => import("@/views/user-center/index.vue"),
user_detail: () => import("@/views/user/detail/[id].vue"),
user_list: () => import("@/views/user/list/index.vue"),
};
108 changes: 69 additions & 39 deletions src/router/elegant/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const generatedRoutes: GeneratedRoute[] = [
meta: {
title: 'home',
i18nKey: 'route.home',
icon: 'mdi:monitor-dashboard'
icon: 'mdi:monitor-dashboard',
order: 1
}
},
{
Expand All @@ -57,21 +58,84 @@ export const generatedRoutes: GeneratedRoute[] = [
constant: true
}
},
{
name: 'manage',
path: '/manage',
component: 'layout.base',
meta: {
title: 'manage',
i18nKey: 'route.manage',
icon: 'carbon:cloud-service-management',
order: 9,
roles: ['R_ADMIN']
},
children: [
{
name: 'manage_role',
path: '/manage/role',
component: 'view.manage_role',
meta: {
title: 'manage_role',
i18nKey: 'route.manage_role',
icon: 'carbon:user-role',
order: 2,
roles: ['R_ADMIN']
}
},
{
name: 'manage_route',
path: '/manage/route',
component: 'view.manage_route',
meta: {
title: 'manage_route',
i18nKey: 'route.manage_route',
icon: 'material-symbols:route',
order: 3,
roles: ['R_ADMIN']
}
},
{
name: 'manage_user',
path: '/manage/user',
component: 'view.manage_user',
meta: {
title: 'manage_user',
i18nKey: 'route.manage_user',
icon: 'ic:round-manage-accounts',
order: 1,
roles: ['R_ADMIN']
}
},
{
name: 'manage_user-detail',
path: '/manage/user-detail/:id',
component: 'view.manage_user-detail',
meta: {
title: 'manage_user-detail',
i18nKey: 'route.manage_user-detail',
hideInMenu: true,
roles: ['R_ADMIN']
}
}
]
},
{
name: 'multi-menu',
path: '/multi-menu',
component: 'layout.base',
meta: {
title: 'multi-menu',
i18nKey: 'route.multi-menu'
i18nKey: 'route.multi-menu',
order: 8
},
children: [
{
name: 'multi-menu_first',
path: '/multi-menu/first',
meta: {
title: 'multi-menu_first',
i18nKey: 'route.multi-menu_first'
i18nKey: 'route.multi-menu_first',
order: 1
},
children: [
{
Expand All @@ -90,7 +154,8 @@ export const generatedRoutes: GeneratedRoute[] = [
path: '/multi-menu/second',
meta: {
title: 'multi-menu_second',
i18nKey: 'route.multi-menu_second'
i18nKey: 'route.multi-menu_second',
order: 2
},
children: [
{
Expand All @@ -116,41 +181,6 @@ export const generatedRoutes: GeneratedRoute[] = [
}
]
},
{
name: 'user',
path: '/user',
component: 'layout.base',
redirect: '/user/list',
meta: {
title: 'user',
i18nKey: 'route.user',
icon: 'ic:round-manage-accounts',
roles: ['R_SUPER']
},
children: [
{
name: 'user_detail',
path: '/user/detail/:id',
component: 'view.user_detail',
meta: {
title: 'user_detail',
i18nKey: 'route.user_detail',
icon: 'ic:round-account-box',
hideInMenu: true
}
},
{
name: 'user_list',
path: '/user/list',
component: 'view.user_list',
meta: {
title: 'user_list',
i18nKey: 'route.user_list',
icon: 'mdi:table-large'
}
}
]
},
{
name: 'user-center',
path: '/user-center',
Expand Down
8 changes: 5 additions & 3 deletions src/router/elegant/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ const routeMap: RouteMap = {
"500": "/500",
"home": "/home",
"login": "/login/:module(pwd-login|code-login|register|reset-pwd|bind-wechat)?",
"manage": "/manage",
"manage_role": "/manage/role",
"manage_route": "/manage/route",
"manage_user": "/manage/user",
"manage_user-detail": "/manage/user-detail/:id",
"multi-menu": "/multi-menu",
"multi-menu_first": "/multi-menu/first",
"multi-menu_first_child": "/multi-menu/first/child",
"multi-menu_second": "/multi-menu/second",
"multi-menu_second_child": "/multi-menu/second/child",
"multi-menu_second_child_home": "/multi-menu/second/child/home",
"user": "/user",
"user_detail": "/user/detail/:id",
"user_list": "/user/list",
"user-center": "/user-center"
};

Expand Down
7 changes: 6 additions & 1 deletion src/router/guard/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ export function createPermissionGuard(router: Router) {
const isLogin = Boolean(localStg.get('token'));
const needLogin = !to.meta.constant;
const routeRoles = to.meta.roles || [];
const hasPermission = !routeRoles.length || auth.userInfo.roles.some(role => routeRoles.includes(role));
const rootRoute: RouteKey = 'root';
const loginRoute: RouteKey = 'login';
const noPermissionRoute: RouteKey = '403';

const SUPER_ADMIN = 'R_SUPER';
const hasPermission =
!routeRoles.length ||
auth.userInfo.roles.includes(SUPER_ADMIN) ||
auth.userInfo.roles.some(role => routeRoles.includes(role));

const strategicPatterns: Common.StrategicPattern[] = [
// 1. if it is login route when logged in, change to the root page
{
Expand Down
2 changes: 1 addition & 1 deletion src/service/api/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { request } from '../request';
* @param example whether to use example data, default: 0
*/
export function fetchGetUserRoutes(example: '0' | '1' = '0') {
return request<App.Service.Response<Api.Route.UserRoute>>('/route/getUserRoute', { params: { example } });
return request<App.Service.Response<Api.Route.UserRoute>>('/route/getUserRoutes', { params: { example } });
}

/**
Expand Down
16 changes: 10 additions & 6 deletions src/typings/elegant-router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ declare module "@elegant-router/types" {
"500": "/500";
"home": "/home";
"login": "/login/:module(pwd-login|code-login|register|reset-pwd|bind-wechat)?";
"manage": "/manage";
"manage_role": "/manage/role";
"manage_route": "/manage/route";
"manage_user": "/manage/user";
"manage_user-detail": "/manage/user-detail/:id";
"multi-menu": "/multi-menu";
"multi-menu_first": "/multi-menu/first";
"multi-menu_first_child": "/multi-menu/first/child";
"multi-menu_second": "/multi-menu/second";
"multi-menu_second_child": "/multi-menu/second/child";
"multi-menu_second_child_home": "/multi-menu/second/child/home";
"user": "/user";
"user_detail": "/user/detail/:id";
"user_list": "/user/list";
"user-center": "/user-center";
};

Expand Down Expand Up @@ -68,8 +70,8 @@ declare module "@elegant-router/types" {
| "500"
| "home"
| "login"
| "manage"
| "multi-menu"
| "user"
| "user-center"
>;

Expand All @@ -92,11 +94,13 @@ declare module "@elegant-router/types" {
| "500"
| "login"
| "home"
| "manage_role"
| "manage_route"
| "manage_user-detail"
| "manage_user"
| "multi-menu_first_child"
| "multi-menu_second_child_home"
| "user-center"
| "user_detail"
| "user_list"
>;

/**
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions src/views/manage/user-detail/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script setup lang="ts">
interface Props {
id: string;
}
defineProps<Props>();
</script>

<template>
<LookForward />
</template>

<style scoped></style>
7 changes: 7 additions & 0 deletions src/views/manage/user/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts"></script>

<template>
<LookForward />
</template>

<style scoped></style>

0 comments on commit 73b023c

Please sign in to comment.