index.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // 按钮权限
  2. import { MenuItem } from '@/common/components/contextMenu/interface';
  3. import { openModal } from '@/common/setup/modal/index';
  4. import { ModalName } from '@/common/setup/modal/interface';
  5. import { OperationTabMenu } from '@/services/go/commonService/interface';
  6. import { inject, Ref } from 'vue';
  7. import { BtnType, MenuType } from './interface';
  8. /**
  9. * 详情 按钮
  10. * @param modalName 相对应的弹窗组件名
  11. * @param contextMenuList 右键列表
  12. */
  13. export function detailButton(modalName: keyof ModalName, contextMenuList: Ref<MenuItem[]>) {
  14. const { openAction } = openModal(modalName);
  15. contextMenuList.value.push({ lable: '详情', callback: openAction });
  16. }
  17. /**
  18. * 权限 按钮
  19. * @param modalName 相对应的弹窗组件名
  20. * @param lable 按钮名
  21. * @param contextMenuList 右键列表
  22. */
  23. export function permissionButton(modalName: keyof ModalName, lable: string, contextMenuList: Ref<MenuItem[]>) {
  24. const { openAction } = openModal(modalName);
  25. function action() {
  26. contextMenuList.value.push({ lable, callback: openAction });
  27. }
  28. return { action };
  29. }
  30. /**
  31. * 判断某个按钮是否有权限
  32. * @param menuType
  33. * @returns
  34. */
  35. export function handlePermission(menuType: keyof MenuType) {
  36. const permissionData = inject('thirdMenuList') as Ref<OperationTabMenu[]>;
  37. // 判断按钮是否有权限
  38. function hasPermission(type: keyof BtnType): boolean {
  39. let result = false;
  40. if (permissionData) {
  41. const btnList = permissionData.value.find((e) => e.code === menuType);
  42. if (btnList && btnList.children) {
  43. result = btnList.children.find((e) => e.code === type && e.type === 2) ? true : false;
  44. }
  45. }
  46. return result;
  47. }
  48. return { hasPermission };
  49. }