authUtils.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* JVxeTable 行编辑 权限 */
  2. import { usePermissionStoreWithOut } from '/@/store/modules/permission';
  3. const permissionStore = usePermissionStoreWithOut();
  4. /**
  5. * JVxe 专用,获取权限
  6. * @param prefix
  7. */
  8. export function getJVxeAuths(prefix) {
  9. prefix = getPrefix(prefix);
  10. let { authList, allAuthList } = permissionStore;
  11. let authsMap = new Map<string, typeof allAuthList[0]>();
  12. if (!prefix || prefix.length == 0) {
  13. return authsMap;
  14. }
  15. // 将所有vxe用到的权限取出来
  16. for (let auth of allAuthList) {
  17. if (auth.status == '1' && (auth.action || '').startsWith(prefix)) {
  18. authsMap.set(auth.action, { ...auth, isAuth: false });
  19. }
  20. }
  21. // 设置是否已授权
  22. for (let auth of authList) {
  23. let getAuth = authsMap.get(auth.action);
  24. if (getAuth != null) {
  25. getAuth.isAuth = true;
  26. }
  27. }
  28. //update-begin-author:taoyan date:2022-6-1 for: VUEN-1162 子表按钮没控制
  29. let onlineButtonAuths = permissionStore.getOnlineSubTableAuth(prefix);
  30. if (onlineButtonAuths && onlineButtonAuths.length > 0) {
  31. for (let auth of onlineButtonAuths) {
  32. authsMap.set(prefix + 'btn:' + auth, { action: auth, type: 1, status: 1, isAuth: false });
  33. }
  34. }
  35. //update-end-author:taoyan date:2022-6-1 for: VUEN-1162 子表按钮没控制
  36. return authsMap;
  37. }
  38. /**
  39. * 获取前缀
  40. * @param prefix
  41. */
  42. export function getPrefix(prefix: string) {
  43. if (prefix && !prefix.endsWith(':')) {
  44. return prefix + ':';
  45. }
  46. return prefix;
  47. }