Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vue2角色模块优化 #172

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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