Commit 1ba029818bbba5e2ecb2704acdb82c7ae8f62c52

Authored by ww
1 parent 3d184c4e

fix: 修复告警轮询请求导致频繁登出

... ... @@ -38,8 +38,30 @@ export function useAlarmNotify(params: UseAlarmNotifyParams = {}) {
38 38
39 39 let timeout: Nullable<NodeJS.Timer> = null;
40 40
  41 + const { hasPermission } = usePermission();
  42 + const getRoleHasNotifyFlag = () => {
  43 + const hasPermissionRole = [RoleEnum.CUSTOMER_USER, RoleEnum.TENANT_ADMIN];
  44 + const userInfo = useUserStore().getUserInfo;
  45 + const userRoles = userInfo.roles || [];
  46 +
  47 + let roleHasPermission = false;
  48 + for (const item of userRoles) {
  49 + const flag = hasPermissionRole.find((each) => item === each);
  50 + if (flag) {
  51 + roleHasPermission = true;
  52 + break;
  53 + }
  54 + }
  55 +
  56 + return hasPermission(AlarmPermissionKey.GLOBAL_NOTIFY) && roleHasPermission;
  57 + };
  58 +
41 59 const getAlarmLog = async () => {
42 60 try {
  61 + if (!getRoleHasNotifyFlag()) {
  62 + clearTimeout();
  63 + return;
  64 + }
43 65 const { items = [] } =
44 66 (await getDeviceAlarm({ status: alarmNotifyStatus, page: 1, pageSize: 10 })) || {};
45 67
... ... @@ -97,26 +119,15 @@ export function useAlarmNotify(params: UseAlarmNotifyParams = {}) {
97 119 }, interval);
98 120 };
99 121
100   - const { hasPermission } = usePermission();
101   -
  122 + const clearTimeout = () => {
  123 + clearInterval(timeout as NodeJS.Timer);
  124 + timeout = null;
  125 + };
102 126 onMounted(() => {
103   - const hasPermissionRole = [RoleEnum.CUSTOMER_USER, RoleEnum.TENANT_ADMIN];
104   - const userInfo = useUserStore().getUserInfo;
105   - const userRoles = userInfo.roles || [];
106   -
107   - const getRoleHasNotifyFlag = () => {
108   - for (const item of userRoles) {
109   - const flag = hasPermissionRole.find((each) => item === each);
110   - if (flag) return true;
111   - }
112   - return false;
113   - };
114   -
115   - if (hasPermission(AlarmPermissionKey.GLOBAL_NOTIFY) && getRoleHasNotifyFlag()) polling();
  127 + if (getRoleHasNotifyFlag()) polling();
116 128 });
117 129
118 130 onUnmounted(() => {
119   - clearInterval(timeout as NodeJS.Timer);
120   - timeout = null;
  131 + clearTimeout();
121 132 });
122 133 }
... ...