Showing
1 changed file
with
28 additions
and
17 deletions
@@ -38,8 +38,30 @@ export function useAlarmNotify(params: UseAlarmNotifyParams = {}) { | @@ -38,8 +38,30 @@ export function useAlarmNotify(params: UseAlarmNotifyParams = {}) { | ||
38 | 38 | ||
39 | let timeout: Nullable<NodeJS.Timer> = null; | 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 | const getAlarmLog = async () => { | 59 | const getAlarmLog = async () => { |
42 | try { | 60 | try { |
61 | + if (!getRoleHasNotifyFlag()) { | ||
62 | + clearTimeout(); | ||
63 | + return; | ||
64 | + } | ||
43 | const { items = [] } = | 65 | const { items = [] } = |
44 | (await getDeviceAlarm({ status: alarmNotifyStatus, page: 1, pageSize: 10 })) || {}; | 66 | (await getDeviceAlarm({ status: alarmNotifyStatus, page: 1, pageSize: 10 })) || {}; |
45 | 67 | ||
@@ -97,26 +119,15 @@ export function useAlarmNotify(params: UseAlarmNotifyParams = {}) { | @@ -97,26 +119,15 @@ export function useAlarmNotify(params: UseAlarmNotifyParams = {}) { | ||
97 | }, interval); | 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 | onMounted(() => { | 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 | onUnmounted(() => { | 130 | onUnmounted(() => { |
119 | - clearInterval(timeout as NodeJS.Timer); | ||
120 | - timeout = null; | 131 | + clearTimeout(); |
121 | }); | 132 | }); |
122 | } | 133 | } |