Skip to content

Commit

Permalink
fix: vue2角色模块优化 (#172)
Browse files Browse the repository at this point in the history
* fix: vue2角色模块优化

* fix: 删除console

* fix: 检视意见修改
  • Loading branch information
Muyu-art authored Aug 21, 2024
1 parent bcdc535 commit 32d2843
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 88 deletions.
6 changes: 6 additions & 0 deletions packages/toolkits/pro/template/tinyvue2/src/api/permission.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import axios from 'axios';

export type Permission = {
desc: string;
id: number;
name: string;
};

export function getAllPermission() {
return axios.get(`/api/permission`);
}
Expand Down
14 changes: 12 additions & 2 deletions packages/toolkits/pro/template/tinyvue2/src/api/role.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import axios from 'axios';

export type CreateRole = {
name: string;
menuIds: number[];
permissionIds: number[];
};

export type UpdateRole = Partial<CreateRole> & {
id: number;
};

export function getAllRole() {
return axios.get('/api/role');
}
Expand All @@ -8,15 +18,15 @@ export function getAllRoleDetail() {
return axios.get('/api/role/detail');
}

export function updateRole(data: any) {
export function updateRole(data: UpdateRole) {
return axios.patch(`/api/role`, data);
}

export function deleteRole(id: number) {
return axios.delete(`/api/role/${id}`);
}

export function createRole(data: any) {
export function createRole(data: CreateRole) {
return axios.post(`/api/role`, data);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/toolkits/pro/template/tinyvue2/src/hooks/useDisclosure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ref } from 'vue';

export const useDisclosure = () => {
const open = ref(false);
const onClose = () => (open.value = false);
const onOpen = () => (open.value = true);
return {
open,
onClose,
onOpen,
};
};
16 changes: 16 additions & 0 deletions packages/toolkits/pro/template/tinyvue2/src/hooks/useI18nMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { ITreeNodeData } from '@/router/guard/menu';
import type { Composer } from 'vue-i18n-composable';

export const useI18nMenu = (data: ITreeNodeData[], t: Composer['t']) => {
const menus: ITreeNodeData[] = [...data];
const dfs = (menu: ITreeNodeData) => {
menu.label = t(menu.locale).toString();
for (const item of menu.children ?? []) {
dfs(item);
}
};
for (const menu of data) {
dfs(menu);
}
return menus;
};
15 changes: 15 additions & 0 deletions packages/toolkits/pro/template/tinyvue2/src/hooks/useMenuId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ITreeNodeData } from '@/router/guard/menu';

export const useMenuId = (datas: ITreeNodeData[]) => {
const ids: any[] = [];
const dfs = (menu: ITreeNodeData) => {
ids.push(menu.id);
for (const child of menu.children ?? []) {
dfs(child);
}
};
for (const data of datas) {
dfs(data);
}
return ids;
};
30 changes: 15 additions & 15 deletions packages/toolkits/pro/template/tinyvue2/src/mock/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { successResponseWrap } from '../utils/setup-mock';
const taskList = Mock.mock({
'list|60': [
{
'id': '@id',
'name': 'xiaoming',
'rank': '初级',
'description': '一段描述文字',
'createTime': '@datetime',
id: '@id',
name: 'xiaoming',
rank: '初级',
description: '一段描述文字',
createTime: '@datetime',
'status|1': ['0', '1', '2'],
'type': 'Tiny Design',
'roles': '前端',
'employeeNo': '00022456',
'department': '公共服务',
'departmentLevel': '中级',
'workbenchName': 'work',
'project': 'TinyDesign',
'address': '西安研究所',
'lastUpdateUser': '张三',
type: 'Tiny Design',
roles: '前端',
employeeNo: '00022456',
department: '公共服务',
departmentLevel: '中级',
workbenchName: 'work',
project: 'TinyDesign',
address: '西安研究所',
lastUpdateUser: '张三',
},
],
});
Expand All @@ -30,7 +30,7 @@ export default [
{
url: '/api/employee/getEmployee',
method: 'post',
response: (params: { body: any; }) => {
response: (params: { body: any }) => {
const { pageIndex = 1, pageSize = 10 } = JSON.parse(
JSON.stringify(params.body)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// import type { Router, LocationQueryRaw } from 'vue-router';
// import NProgress from 'nprogress'; // progress bar
import { getUserInfo } from '@/api/user';
import { useUserStore } from '@/stores';
import { clearToken, isLogin } from '@/utils/auth';
import { nextTick } from 'vue';

export default function setupPermissionGuard(router: any) {
router.beforeEach(async (to, from, next) => {
// NProgress.start();
if (!isLogin()) {
if (to.name === 'login') {
next();
// NProgress.done();
return;
}
next({
Expand All @@ -21,7 +17,6 @@ export default function setupPermissionGuard(router: any) {
...to.query,
} as any,
});
// NProgress.done();
} else {
await nextTick();
const userStore = useUserStore();
Expand All @@ -37,7 +32,6 @@ export default function setupPermissionGuard(router: any) {
return;
}
next();
// NProgress.done();
}
});
}
Loading

0 comments on commit 32d2843

Please sign in to comment.