li.shaoyi 5 mesi fa
parent
commit
e4222e56a1
1 ha cambiato i file con 10 aggiunte e 8 eliminazioni
  1. 10 8
      src/packages/mobile/App.vue

+ 10 - 8
src/packages/mobile/App.vue

@@ -58,16 +58,17 @@ const message = reactive({
   index: 0
 })
 
-// 获取用户阅读状态的唯一键
-const getUserReadKey = () => {
-  const today = formatDate(new Date().toISOString(), 'YYYY-MM-DD')
-  return `${loginStore.loginId}@${today}`
-}
+// 获取用户阅读状态
+const getUserReadStatus = () => ({
+  key: 'user_' + loginStore.loginId,
+  value: formatDate(new Date().toISOString(), 'YYYY-MM-DD')
+})
 
 // 消息列表
 const messageList = computed(() => {
-  const readKey = localStorage.getItem('userReadKey')
-  const showUnread = props.showUnread && getUserReadKey() !== readKey // 未读消息一天内只会弹框一次
+  const { key, value } = getUserReadStatus()
+  const localValue = localStorage.getItem(key)
+  const showUnread = props.showUnread && localValue !== value // 未读消息一天内只会弹框一次
 
   return noticeStore.noticeList.filter((e) => (showUnread && !e.readed) || e.isforcedisplay)
 })
@@ -145,7 +146,8 @@ watch(() => noticeStore.isInitialized, () => {
   const [firstMessage] = messageList.value
 
   if (firstMessage) {
-    localStorage.setItem('userReadKey', getUserReadKey()) // 记录用户已读状态
+    const { key, value } = getUserReadStatus()
+    localStorage.setItem(key, value) // 记录用户已读状态
     message.index = 0
     message.show = true
     noticeStore.updateNoticeReaded(firstMessage.autoid)