权限调整

This commit is contained in:
joylink_fanyuhong 2024-10-09 16:18:48 +08:00
parent 42ff85422e
commit 0704c6da0c
3 changed files with 45 additions and 29 deletions

View File

@ -67,6 +67,7 @@ export class ApiError {
// for each client)
const api = axios.create({ baseURL: getHttpBase() });
let isOpenDialog = false; // 认证弹窗是否打开
let quanXianDialog = false; // 权限提示弹窗是否打开
const CancelToken = axios.CancelToken;
const source = CancelToken.source();
@ -107,6 +108,24 @@ export default boot(({ app, router }) => {
.onCancel(() => {
isOpenDialog = false;
});
} else if (
err.response &&
err.response.status === 403 &&
!quanXianDialog
) {
quanXianDialog = true;
Dialog.create({
title: '无权限',
message: '你没有改页面访问权限',
persistent: true,
})
.onOk(() => {
router.push({ name: 'login' });
quanXianDialog = false;
})
.onCancel(() => {
quanXianDialog = false;
});
}
return Promise.reject(ApiError.from(err));
}

View File

@ -1,7 +1,7 @@
import { RouteRecordRaw } from 'vue-router';
export const admin = '1'; // 超级管理员
export const user = '2'; // 普通用户
// export const admin = '1'; // 超级管理员
// export const user = '2'; // 普通用户
export const routes: RouteRecordRaw[] = [
{
@ -35,7 +35,6 @@ export const asyncRoutes: RouteRecordRaw[] = [
name: 'sysManage',
component: () => import('layouts/MainLayout.vue'),
meta: {
roles: [admin],
label: '系统管理',
icon: 'dataset',
},
@ -74,7 +73,6 @@ export const asyncRoutes: RouteRecordRaw[] = [
name: 'dataManage',
component: () => import('layouts/MainLayout.vue'),
meta: {
roles: [admin],
label: '数据管理',
icon: 'list_alt',
},
@ -140,7 +138,6 @@ export const asyncRoutes: RouteRecordRaw[] = [
name: 'testManage',
component: () => import('layouts/MainLayout.vue'),
meta: {
roles: [admin, user],
label: '测试管理',
icon: 'format_list_bulleted',
},

View File

@ -1,8 +1,8 @@
import { defineStore } from 'pinia';
import { PathItem } from 'src/api/AuthApi';
import { AuthInfo, getCurrentUserInfo } from 'src/api/UserApi';
import { MethodType } from 'src/components/AuthData';
import { asyncRoutes, admin } from 'src/router/routes';
// import { MethodType } from 'src/components/AuthData';
import { asyncRoutes } from 'src/router/routes';
import { RouteRecordRaw } from 'vue-router';
export const useAuthStore = defineStore('auth', {
@ -43,28 +43,28 @@ export const useAuthStore = defineStore('auth', {
});
});
},
getHasAuth(path: string, method: MethodType): boolean {
if (this.currentRolesList.includes(admin)) {
return true;
}
let s = false;
const someP = this.currentPathsList.some((item) => {
const p = '^' + item.path;
const regP = new RegExp(p);
const hasP = regP.test(path);
let hasM = false;
if (item.method == '*') {
hasM = true;
} else {
hasM = item.method.includes(method);
}
return hasP && hasM;
});
if (someP) {
s = true;
}
return s;
},
// getHasAuth(path: string, method: MethodType): boolean {
// // if (this.currentRolesList.includes(admin)) {
// // return true;
// // }
// let s = false;
// const someP = this.currentPathsList.some((item) => {
// const p = '^' + item.path;
// const regP = new RegExp(p);
// const hasP = regP.test(path);
// let hasM = false;
// if (item.method == '*') {
// hasM = true;
// } else {
// hasM = item.method.includes(method);
// }
// return hasP && hasM;
// });
// if (someP) {
// s = true;
// }
// return s;
// },
GenerateRoutes() {
// 生成动态路由
function hasPermission(metaRoles: string[], roles: string[]): boolean {