Review.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { computed, type ComputedRef } from "vue";
  2. import { GROUP_LABELS, GROUP_PROTECT_UNIT, GROUP_TO_REVIEW_PROGRESS, SUBMITED_PROGRESS, GROUP_PROVINCE, GROUP_DISTRICT_CENTER, GROUP_DISTRICT, GROUP_DISTRICT_ST, GROUP_DISTRICT_ND, GROUP_DISTRICT_RD, GROUP_DISTRICT_TH, GROUP_DISTRICT_FI } from "./GroupData";
  3. import { useAuthStore } from "@/stores/auth";
  4. export function useReview(sourceProgress?: ComputedRef<number>) {
  5. const authStore = useAuthStore();
  6. const currentUserGroup = computed(() =>
  7. (authStore.userInfo?.adminGroup || []).find((group) => GROUP_TO_REVIEW_PROGRESS[group.id])
  8. );
  9. const reviewProgressInfo = computed(() => {
  10. return GROUP_TO_REVIEW_PROGRESS[currentUserGroup.value?.id ?? 0];
  11. });
  12. /**
  13. * 是否是最终级别
  14. */
  15. const isEndLevel = computed(() => {
  16. return currentUserGroup.value?.id === GROUP_PROVINCE;
  17. });
  18. /**
  19. * 是否是区级审核级别
  20. */
  21. const isDistrict = computed(() => {
  22. return (
  23. currentUserGroup.value?.id === GROUP_DISTRICT_FI
  24. || currentUserGroup.value?.id === GROUP_DISTRICT_FI
  25. || currentUserGroup.value?.id === GROUP_DISTRICT_ND
  26. || currentUserGroup.value?.id === GROUP_DISTRICT_RD
  27. || currentUserGroup.value?.id === GROUP_DISTRICT_TH
  28. || currentUserGroup.value?.id === GROUP_DISTRICT_FI
  29. );
  30. });
  31. /**
  32. * 是否是项目保护单位
  33. */
  34. const isProtectUnit = computed(() => {
  35. return currentUserGroup.value?.id === GROUP_PROTECT_UNIT;
  36. });
  37. /**
  38. * 是否可以提交审核
  39. */
  40. const canSubmitReview = computed(() => {
  41. const info = reviewProgressInfo.value;
  42. if (!info || !sourceProgress)
  43. return false;
  44. if (info.noProgressChange) {
  45. return sourceProgress.value >= info.minSource;
  46. }
  47. return sourceProgress.value >= info.minSource //上一阶段已完成
  48. && sourceProgress.value < info.target;// 当前审核阶段未完成
  49. });
  50. /**
  51. * 是否可以审核
  52. * @param sourceProgress
  53. * @returns
  54. */
  55. const canReview = (sourceProgress: number) => {
  56. const info = reviewProgressInfo.value;
  57. if (!info)
  58. return false;
  59. if (info.noProgressChange) {
  60. return sourceProgress >= info.minSource;
  61. }
  62. return sourceProgress >= info.minSource //上一阶段已完成
  63. && sourceProgress < info.target;// 当前审核阶段未完成
  64. };
  65. /**
  66. * 是否当前级别已经审核完成
  67. * @param sourceProgress
  68. * @returns
  69. */
  70. const isCurrentLevelReviewed = (sourceProgress: number) => {
  71. const info = reviewProgressInfo.value;
  72. if (!info)
  73. return false;
  74. return sourceProgress >= info.target;
  75. };
  76. /**
  77. * 是否可以审核,但上一阶段未完成
  78. * @param sourceProgress
  79. * @returns
  80. */
  81. const canReviewButPrevNotCompleted = (sourceProgress: number) => {
  82. const info = reviewProgressInfo.value;
  83. if (!info)
  84. return false;
  85. return sourceProgress >= SUBMITED_PROGRESS //已提交
  86. && sourceProgress < info.minSource //上一阶段未完成
  87. };
  88. const reviewLevelLabel = computed(() => {
  89. return GROUP_LABELS[currentUserGroup.value?.id ?? 0];
  90. });
  91. const progressHint = computed(() => {
  92. const roleText = reviewLevelLabel.value ? `当前账号审核环节:${reviewLevelLabel.value}` : `当前用户组无权限审核`;
  93. return `${roleText}。`;
  94. });
  95. /**
  96. * 当前角色是否不修改进度(子角色审核)
  97. */
  98. const isNoProgressChange = computed(() => {
  99. return !!reviewProgressInfo.value?.noProgressChange;
  100. });
  101. /**
  102. * 当前角色是否仅可退回(不可通过审核)
  103. */
  104. const canRejectOnly = computed(() => {
  105. const info = reviewProgressInfo.value;
  106. return !!info?.noProgressChange && !info?.canReject;
  107. });
  108. return {
  109. reviewProgressInfo,
  110. currentUserGroup,
  111. canReview,
  112. canReviewButPrevNotCompleted,
  113. isCurrentLevelReviewed,
  114. canSubmitReview,
  115. reviewLevelLabel,
  116. progressHint,
  117. isDistrict,
  118. isEndLevel,
  119. isProtectUnit,
  120. isNoProgressChange,
  121. canRejectOnly,
  122. };
  123. }