Ver Fonte

feat: 调整小数返回按钮的实现逻辑

zhupei há 1 ano atrás
pai
commit
dc0aa78ce1

+ 2 - 2
src/modules/permission/account/index.vue

@@ -95,7 +95,7 @@ import AccountForm from './AccountForm.vue';
 import ViewPermission from './ViewPermission.vue';
 import DeptConfigModal from './DeptConfigModal.vue';
 import DeleteModal from '../../../components/DeleteModal.vue';
-import { hasPermission, filterNotEnabledTree } from '../../../utils/permission';
+import { hasBtnPermission, filterNotEnabledTree } from '../../../utils/permission';
 import {
   QueryUserList,
   QueryUserDeptDetail,
@@ -466,7 +466,7 @@ watch(
 );
 
 onMounted(() => {
-  if (hasPermission('system:user:list')) {
+  if (hasBtnPermission('system:user:list')) {
     getUserList();
     getDeptTree();
   } else {

+ 2 - 2
src/modules/permission/group/index.vue

@@ -97,7 +97,7 @@ import { useI18n } from 'vue-i18n';
 import MembertConfigModal from './MembertConfigModal.vue';
 import PermissionConfigModal from './PermissionConfigModal.vue';
 import DeleteModal from '../../../components/DeleteModal.vue';
-import { hasPermission } from '../../../utils/permission';
+import { hasBtnPermission } from '../../../utils/permission';
 import {
   QueryGroupList,
   QueryGroupUsers,
@@ -383,7 +383,7 @@ watch(
 );
 
 onMounted(() => {
-  if (hasPermission('system:group:list')) {
+  if (hasBtnPermission('system:group:list')) {
     getGroupList();
   } else {
     router.push('/denied');

+ 2 - 2
src/modules/permission/org/index.vue

@@ -53,7 +53,7 @@ import { Message } from '@arco-design/web-vue';
 import TreeParts from '../../../views/permission/TreeParts.vue';
 import OrgForm from './OrgForm.vue';
 import Modal from '../../../views/permission/Modal.vue';
-import { hasPermission } from '../../../utils/permission';
+import { hasBtnPermission } from '../../../utils/permission';
 import {
   QueryDeptDetail,
   UpdateDept,
@@ -232,7 +232,7 @@ const onNodeDrop = async ({ dropNode, dragNode, dropPosition }) => {
   }
 };
 onMounted(() => {
-  if (hasPermission('system:dept:list')) {
+  if (hasBtnPermission('system:dept:list')) {
     getDeptTree();
   } else {
     router.push('/denied');

+ 2 - 2
src/modules/permission/resource/index.vue

@@ -52,7 +52,7 @@ import { Message } from '@arco-design/web-vue';
 import TreeParts from '../../../views/permission/TreeParts.vue';
 import ResourceForm from './ResourceForm.vue';
 import Modal from '../../../views/permission/Modal.vue';
-import { hasPermission } from '../../../utils/permission';
+import { hasBtnPermission } from '../../../utils/permission';
 import {
   QueryResourceTree,
   QueryResourceDetail,
@@ -202,7 +202,7 @@ const resourceFromCancel = () => {
   resource_visible.value = false;
 };
 onMounted(() => {
-  if (hasPermission('system:menu:list')) {
+  if (hasBtnPermission('system:menu:list')) {
     getResourceTree();
   } else {
     router.push('/denied');

+ 2 - 2
src/modules/permission/role/index.vue

@@ -92,7 +92,7 @@ import RoleForm from './RoleForm.vue';
 import PermissionConfigModal from './PermissionConfigModal.vue';
 import DeptConfigModal from './DeptConfigModal.vue';
 import DeleteModal from '../../../components/DeleteModal.vue';
-import { hasPermission, filterNotEnabledTree } from '../../../utils/permission';
+import { hasBtnPermission, filterNotEnabledTree } from '../../../utils/permission';
 import { QueryRoleList, RoleStatusSwitch, DeleteRole, CreateRole, UpdateRole } from '../../../apis/permission/role';
 import { QueryResourceTree } from '../../../apis/permission/resource';
 import { QueryDeptTree } from '../../../apis/permission/common';
@@ -351,7 +351,7 @@ watch(
 );
 
 onMounted(() => {
-  if (hasPermission('system:role:list')) {
+  if (hasBtnPermission('system:role:list')) {
     gerRoleList();
     getMenuTree();
     getDeptTree();

+ 54 - 2
src/utils/permission.js

@@ -1,14 +1,15 @@
 import { localST_UserInfo, localST_RoutesList } from '../base/storage';
+import { jsonParse } from './utils';
 
 /**
- * 根据 系统资源标识符 判断当前用户对某个资源是否拥有权限
+ * 根据 系统资源标识符 判断当前用户对某个资源(按钮)是否拥有权限
  * 所有可用的资源标识符,请查看下方链接中的定义
  * 大模型2.0 -> 权限管理 -> 资源管理
  * @see http://smartai.com:8293/#/permission/resource
  * @param {String} str - 资源标识符,例如:system:menu:list
  * @returns {Boolean}
  */
-export const hasPermission = (str) => {
+export const hasBtnPermission = (str) => {
   try {
     const user_nfo = localST_UserInfo.getItem();
     if (!user_nfo) return false;
@@ -26,6 +27,57 @@ export const hasPermission = (str) => {
   }
 };
 
+/**
+ * 判断用户对某个路由是否有权限
+ * @param {string} str - 资源标识符或者路由路径,例如:system:menu:conversation 或者 /chat/qa
+ */
+export const hasRoutePermission = (str) => {
+  // 所有的路由信息
+  const routeString = localST_RoutesList.getItem();
+  const route_list = jsonParse(routeString);
+  if (!route_list) {
+    return false;
+  }
+
+  let type = 0;
+  if (str.indexOf('/') === 0) {
+    type = 1; // 使用 path进行判断
+  }
+  // if (str.split(':').length === 3) {
+  //   type = 2; // 使用资源标识符进行判断
+  // }
+  if (str.indexOf(':') > 0) {
+    type = 2; // 使用资源标识符进行判断
+  }
+
+  if (type === 0) {
+    return false;
+  }
+
+  const len = route_list.length;
+  for (let i = 0; i < len; i++) {
+    const item = route_list[i];
+
+    if (type === 1) {
+      const path = item.path;
+
+      if (path === str) {
+        return true;
+      }
+    }
+
+    if (type === 2) {
+      const perms = item.perms;
+
+      if (str === perms) {
+        return true;
+      }
+    }
+  }
+
+  return false;
+};
+
 /**
  * 格式化路由数据,将原始路由数据转换为组件路由对象。
  *

+ 20 - 8
src/views/Xiaoshu.vue

@@ -29,7 +29,7 @@ import { useCurrentUserStore } from '../base/store/use-current-user';
 
 import { getConfigField } from '../config/index';
 
-import { hasPermission } from '../utils/permission';
+import { hasBtnPermission, hasRoutePermission } from '../utils/permission';
 
 const router = useRouter();
 
@@ -64,18 +64,30 @@ function getXiaoshuBackUrl() {
    * 系统资源
    */
   const sys_resource_list = {
-    'system:menu:conversation': '/chat/qa', // 会话
-    'system:conversation:qa': '/chat/qa', // 会话进行中
-    'system:conversation:hisroty': '/chat/history', // 会话,历史记录
-    'system:conversation:board': '/chat/board', // 会话,智能体大全
-    'system:menu:intelligent': '/intelligent', // 智能体
-    'system:menu:knowledge': '/knowledge' // 知识库管理
+    // 菜单权限
+    // 'system:menu:xiaoshu': '/xiaoshu',
+    'system:conversation:board': '/chat/board', // 页面:会话,智能体大全
+    'system:conversation:hisroty': '/chat/history', // 页面:会话,历史记录
+
+    'system:menu:intelligent': '/intelligent', // 菜单:智能体
+    'system:menu:knowledge': '/knowledge', // 菜单:知识库管理
+    'system:menu:model': '/model', // 菜单:模型管理
+    'system:menu:permission': '/permission', // 菜单:权限管理
+
+    'system:menu:conversation': '/chat/qa', // 菜单:会话
+    'system:conversation:qa': '/chat/qa', // 页面:会话进行中
+
+    'system:group': '/permission/group', // 菜单:用户组管理
+    'system:dept': '/permission/org', // 菜单:机构管理
+    'system:role': '/permission/role', // 菜单:角色管理
+    'system:user': '/permission/account', // 菜单:用户管理
+    'system:menu': '/permission/resource' // 菜单:资源管理
   };
 
   let back_route = ''; // 返回的地址
 
   for (let key in sys_resource_list) {
-    const has_permission = hasPermission(key);
+    const has_permission = hasRoutePermission(key);
 
     if (has_permission) {
       // 有权限