|
|
@@ -2,14 +2,30 @@
|
|
|
import NotificationMessageCard from '@/components/NotificationMessageCard/src/NotificationMessageCard.vue'
|
|
|
import { useNotificationMessage } from '@/stores/modules/notificationMessage'
|
|
|
|
|
|
+const activeCardTypeName = ref(sessionStorage.getItem('activeCardTypeName') || 'Milestone Update')
|
|
|
+
|
|
|
const notificationMsgStore = useNotificationMessage()
|
|
|
const collapseVModel = ref<string[]>(['1'])
|
|
|
|
|
|
const tabCountList = ref([0, 0, 0, 0, 0])
|
|
|
+const curTabCount = ref([])
|
|
|
+
|
|
|
const handleCount = (count: number) => {
|
|
|
- if (!count) return 0
|
|
|
+ if (!count) return ''
|
|
|
return count > 99 ? '99+' : count
|
|
|
}
|
|
|
+const handleShowCount = (typeName: string, index: number) => {
|
|
|
+ // 在切换type类型时,防止点击的类型值为点击之前类型的值
|
|
|
+ if (curTabCount.value?.[index] > -1) {
|
|
|
+ return curTabCount.value[index]
|
|
|
+ }
|
|
|
+ const count = tabCountList.value[index]
|
|
|
+ if (typeName === activeCardTypeName.value) {
|
|
|
+ return handleCount(unreadNotificationList.value.length)
|
|
|
+ }
|
|
|
+ return handleCount(count)
|
|
|
+}
|
|
|
+
|
|
|
const navList = [
|
|
|
'Milestone Update',
|
|
|
'Container Status Update',
|
|
|
@@ -17,7 +33,6 @@ const navList = [
|
|
|
'ETD/ETA Change'
|
|
|
]
|
|
|
|
|
|
-const activeItem = ref('Milestone Update')
|
|
|
const notificationTypeList = ref({
|
|
|
Milestone_Update: 'Milestone Update',
|
|
|
Container_Status_Update: 'Container Status Update',
|
|
|
@@ -28,17 +43,23 @@ const notificationTypeList = ref({
|
|
|
})
|
|
|
|
|
|
const setActiveItem = (item: string) => {
|
|
|
- activeItem.value = item
|
|
|
- activeName.value = 'All Notifications'
|
|
|
-
|
|
|
- const idsToRemove = notificationList.value.map((item) => item.info.id)
|
|
|
- notificationMsgStore.removeNotificationMsgList(idsToRemove)
|
|
|
+ navList.forEach((navItem, index) => {
|
|
|
+ curTabCount.value[index] = handleShowCount(navItem, index)
|
|
|
+ })
|
|
|
+ curTabCount.value[tabCountList.value.length - 1] = handleShowCount(
|
|
|
+ 'Feature Update',
|
|
|
+ tabCountList.value.length - 1
|
|
|
+ )
|
|
|
|
|
|
+ activeCardTypeName.value = item
|
|
|
+ sessionStorage.setItem('activeCardTypeName', item)
|
|
|
+ activeTabName.value = 'All Notifications'
|
|
|
getNotificationList()
|
|
|
}
|
|
|
|
|
|
const loading = ref(false)
|
|
|
const notificationList = ref<any[]>([])
|
|
|
+
|
|
|
const unreadNotificationList = computed(() => {
|
|
|
return notificationList.value.filter((item) => !item.info.isRead)
|
|
|
})
|
|
|
@@ -48,7 +69,7 @@ const readNotificationList = computed(() => {
|
|
|
const getNotificationList = async () => {
|
|
|
loading.value = true
|
|
|
const rulesType = Object.entries(notificationTypeList.value).find(
|
|
|
- (item) => item[1] === activeItem.value
|
|
|
+ (item) => item[1] === activeCardTypeName.value
|
|
|
)?.[0]
|
|
|
try {
|
|
|
await notificationMsgStore.markMessageAsRead()
|
|
|
@@ -65,25 +86,38 @@ const getNotificationList = async () => {
|
|
|
})
|
|
|
.finally(() => {
|
|
|
loading.value = false
|
|
|
+ curTabCount.value = []
|
|
|
})
|
|
|
} catch (error) {
|
|
|
console.error(error)
|
|
|
loading.value = false
|
|
|
+ curTabCount.value = []
|
|
|
}
|
|
|
}
|
|
|
-// 获取未读消息数量
|
|
|
-const getUnReadCount = () => {
|
|
|
- return notificationList.value.filter((item) => !item.info.isRead).length
|
|
|
+
|
|
|
+const changeCardRead = () => {
|
|
|
+ const readCardMap = notificationMsgStore.readCardMap
|
|
|
+ notificationList.value.forEach((item) => {
|
|
|
+ if (readCardMap.includes(item.info.id)) {
|
|
|
+ item.info.isRead = true
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-const activeName = ref('All Notifications')
|
|
|
+const activeTabName = ref('All Notifications')
|
|
|
+const handleTabChange = () => {
|
|
|
+ // 当前tab页切换时,更新数据
|
|
|
+ const readCardMap = notificationMsgStore.readCardMap
|
|
|
+ notificationList.value.forEach((item) => {
|
|
|
+ if (readCardMap.includes(item.info.id)) {
|
|
|
+ item.info.isRead = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
onMounted(() => {
|
|
|
getNotificationList()
|
|
|
})
|
|
|
-onUnmounted(() => {
|
|
|
- notificationMsgStore.markMessageAsRead()
|
|
|
-})
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -96,18 +130,14 @@ onUnmounted(() => {
|
|
|
<div
|
|
|
@click="setActiveItem(item)"
|
|
|
class="collapse-item"
|
|
|
- :class="{ 'is-active': item === activeItem }"
|
|
|
+ :class="{ 'is-active': item === activeCardTypeName }"
|
|
|
v-for="(item, index) in navList"
|
|
|
:key="item"
|
|
|
>
|
|
|
- <div v-if="item === activeItem" class="active-sign"></div>
|
|
|
+ <div v-if="item === activeCardTypeName" class="active-sign"></div>
|
|
|
<span>{{ item }}</span>
|
|
|
- <div class="count" v-if="tabCountList?.[index]">
|
|
|
- <span>{{
|
|
|
- item === activeItem
|
|
|
- ? handleCount(getUnReadCount())
|
|
|
- : handleCount(tabCountList?.[index])
|
|
|
- }}</span>
|
|
|
+ <div class="count" v-if="handleShowCount(item, index)">
|
|
|
+ <span>{{ handleShowCount(item, index) }}</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</el-collapse-item>
|
|
|
@@ -116,25 +146,27 @@ onUnmounted(() => {
|
|
|
@click="setActiveItem('Feature Update')"
|
|
|
class="collapse-item"
|
|
|
style="margin-top: 4px; font-weight: 700"
|
|
|
- :class="{ 'is-active': activeItem === 'Feature Update' }"
|
|
|
+ :class="{ 'is-active': activeCardTypeName === 'Feature Update' }"
|
|
|
>
|
|
|
- <div v-if="activeItem === 'Feature Update'" class="active-sign"></div>
|
|
|
+ <div v-if="activeCardTypeName === 'Feature Update'" class="active-sign"></div>
|
|
|
<span>Feature Update</span>
|
|
|
- <div class="count" v-if="tabCountList?.[tabCountList.length - 1]">
|
|
|
- <span>{{ handleCount(tabCountList?.[tabCountList.length - 1]) }}</span>
|
|
|
+ <div class="count" v-if="handleShowCount('Feature Update', tabCountList.length - 1)">
|
|
|
+ <span>{{ handleShowCount('Feature Update', tabCountList.length - 1) }}</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="right-content">
|
|
|
- <el-tabs v-model="activeName" class="demo-tabs">
|
|
|
+ <el-tabs v-model="activeTabName" @tab-change="handleTabChange" class="demo-tabs">
|
|
|
<el-tab-pane label="All Notifications" name="All Notifications">
|
|
|
<template #label>
|
|
|
<span style="margin-right: 4px">All Notifications</span>
|
|
|
</template>
|
|
|
- <div style="padding: 10px 140px 0px 16px" v-if="activeName === 'All Notifications'">
|
|
|
+ <div style="padding: 10px 140px 0px 16px" v-if="activeTabName === 'All Notifications'">
|
|
|
<NotificationMessageCard
|
|
|
- v-if="activeName === 'All Notifications'"
|
|
|
+ v-if="activeTabName === 'All Notifications'"
|
|
|
:data="notificationList"
|
|
|
+ @hasCardRead="changeCardRead"
|
|
|
+ :updateReadCardsOnChange="false"
|
|
|
></NotificationMessageCard>
|
|
|
</div>
|
|
|
</el-tab-pane>
|
|
|
@@ -145,17 +177,22 @@ onUnmounted(() => {
|
|
|
<span>{{ handleCount(unreadNotificationList.length) }}</span>
|
|
|
</div>
|
|
|
</template>
|
|
|
- <div style="padding: 10px 140px 0px 16px" v-if="activeName === 'Unread'">
|
|
|
+ <div style="padding: 10px 140px 0px 16px" v-if="activeTabName === 'Unread'">
|
|
|
<NotificationMessageCard
|
|
|
- v-if="activeName === 'Unread'"
|
|
|
+ v-if="activeTabName === 'Unread'"
|
|
|
:data="unreadNotificationList"
|
|
|
+ :updateReadCardsOnChange="false"
|
|
|
></NotificationMessageCard>
|
|
|
</div>
|
|
|
</el-tab-pane>
|
|
|
<el-tab-pane label="Read" name="Read">
|
|
|
<template #label><span style="margin-right: 4px">Read</span> </template>
|
|
|
- <div style="padding: 10px 140px 0px 16px" v-if="activeName === 'Read'">
|
|
|
- <NotificationMessageCard v-if="activeName === 'Read'" :data="readNotificationList">
|
|
|
+ <div style="padding: 10px 140px 0px 16px" v-if="activeTabName === 'Read'">
|
|
|
+ <NotificationMessageCard
|
|
|
+ v-if="activeTabName === 'Read'"
|
|
|
+ :updateReadCardsOnChange="false"
|
|
|
+ :data="readNotificationList"
|
|
|
+ >
|
|
|
</NotificationMessageCard>
|
|
|
</div>
|
|
|
</el-tab-pane>
|