|
@@ -13,19 +13,25 @@ const tabCountList = ref([0, 0, 0, 0, 0])
|
|
|
const curTabCount = ref([])
|
|
const curTabCount = ref([])
|
|
|
|
|
|
|
|
const handleCount = (count: number) => {
|
|
const handleCount = (count: number) => {
|
|
|
- if (!count) return ''
|
|
|
|
|
|
|
+ if (!count || count < 0) return ''
|
|
|
return count > 99 ? '99+' : count
|
|
return count > 99 ? '99+' : count
|
|
|
}
|
|
}
|
|
|
|
|
+// 计算未读卡片数量
|
|
|
|
|
+const unreadCardCount = computed(() => {
|
|
|
|
|
+ const curEventNotificationIndex = navList.findIndex((navItem) => {
|
|
|
|
|
+ return navItem === activeCardTypeName.value
|
|
|
|
|
+ })
|
|
|
|
|
+ return tabCountList.value[curEventNotificationIndex] - notificationMsgStore.readCardMap.length
|
|
|
|
|
+})
|
|
|
const handleShowCount = (typeName: string, index: number) => {
|
|
const handleShowCount = (typeName: string, index: number) => {
|
|
|
// 在切换type类型时,防止点击的类型值为点击之前类型的值
|
|
// 在切换type类型时,防止点击的类型值为点击之前类型的值
|
|
|
if (curTabCount.value?.[index] > -1) {
|
|
if (curTabCount.value?.[index] > -1) {
|
|
|
return curTabCount.value[index]
|
|
return curTabCount.value[index]
|
|
|
}
|
|
}
|
|
|
- const count = tabCountList.value[index]
|
|
|
|
|
if (typeName === activeCardTypeName.value) {
|
|
if (typeName === activeCardTypeName.value) {
|
|
|
- return handleCount(unreadNotificationList.value.length)
|
|
|
|
|
|
|
+ return handleCount(unreadCardCount.value)
|
|
|
}
|
|
}
|
|
|
- return handleCount(count)
|
|
|
|
|
|
|
+ return handleCount(tabCountList.value[index])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const navList = [
|
|
const navList = [
|
|
@@ -52,49 +58,106 @@ const setActiveItem = (item: string) => {
|
|
|
tabCountList.value.length - 1
|
|
tabCountList.value.length - 1
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ // 滚动到顶部
|
|
|
|
|
+ if (notificationMessageCardRef.value) {
|
|
|
|
|
+ notificationMessageCardRef.value.scrollContainerRef.scrollTo(0, 0)
|
|
|
|
|
+ }
|
|
|
activeCardTypeName.value = item
|
|
activeCardTypeName.value = item
|
|
|
sessionStorage.setItem('activeCardTypeName', item)
|
|
sessionStorage.setItem('activeCardTypeName', item)
|
|
|
activeTabName.value = 'All Notifications'
|
|
activeTabName.value = 'All Notifications'
|
|
|
- getNotificationList()
|
|
|
|
|
|
|
+ getNotificationList(activeTabName.value, true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
const loading = ref(false)
|
|
|
const notificationList = ref<any[]>([])
|
|
const notificationList = ref<any[]>([])
|
|
|
|
|
|
|
|
-const unreadNotificationList = computed(() => {
|
|
|
|
|
- return notificationList.value.filter((item) => !item.info.isRead)
|
|
|
|
|
-})
|
|
|
|
|
-const readNotificationList = computed(() => {
|
|
|
|
|
- return notificationList.value.filter((item) => item.info.isRead)
|
|
|
|
|
|
|
+const unreadNotificationList = ref<any[]>([])
|
|
|
|
|
+
|
|
|
|
|
+const readNotificationList = ref<any[]>([])
|
|
|
|
|
+const pageInfo = ref({
|
|
|
|
|
+ cp: 0,
|
|
|
|
|
+ ps: 30
|
|
|
})
|
|
})
|
|
|
-const getNotificationList = async () => {
|
|
|
|
|
|
|
+const getNotificationList = async (
|
|
|
|
|
+ tabType: string = 'All Notifications',
|
|
|
|
|
+ isChangeNav: boolean = false
|
|
|
|
|
+) => {
|
|
|
loading.value = true
|
|
loading.value = true
|
|
|
|
|
+ if (isChangeNav) {
|
|
|
|
|
+ pageInfo.value.cp = 1
|
|
|
|
|
+ notificationMessageCardRef.value.finished = false
|
|
|
|
|
+ unreadNotificationList.value = []
|
|
|
|
|
+ readNotificationList.value = []
|
|
|
|
|
+ notificationList.value = []
|
|
|
|
|
+ if (activeCardTypeName.value === 'Feature Update') {
|
|
|
|
|
+ pageInfo.value.ps = 100
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pageInfo.value.ps = 30
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pageInfo.value.cp += 1
|
|
|
|
|
+ }
|
|
|
const rulesType = Object.entries(notificationTypeList.value).find(
|
|
const rulesType = Object.entries(notificationTypeList.value).find(
|
|
|
(item) => item[1] === activeCardTypeName.value
|
|
(item) => item[1] === activeCardTypeName.value
|
|
|
)?.[0]
|
|
)?.[0]
|
|
|
|
|
+ let info_type: null | boolean = null
|
|
|
|
|
+ if (tabType === 'All Notifications') {
|
|
|
|
|
+ info_type = null
|
|
|
|
|
+ } else if (tabType === 'Unread') {
|
|
|
|
|
+ info_type = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ info_type = false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
await notificationMsgStore.markMessageAsRead()
|
|
await notificationMsgStore.markMessageAsRead()
|
|
|
$api
|
|
$api
|
|
|
.getSystemMessageData({
|
|
.getSystemMessageData({
|
|
|
- rules_type: rulesType
|
|
|
|
|
|
|
+ rules_type: rulesType,
|
|
|
|
|
+ cp: pageInfo.value.cp,
|
|
|
|
|
+ ps: pageInfo.value.ps,
|
|
|
|
|
+ info_type
|
|
|
})
|
|
})
|
|
|
.then((res) => {
|
|
.then((res) => {
|
|
|
if (res.code === 200) {
|
|
if (res.code === 200) {
|
|
|
const data = res.data
|
|
const data = res.data
|
|
|
- notificationList.value = data.cardList
|
|
|
|
|
- tabCountList.value = data.countList
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否结束加载
|
|
|
|
|
+ if (!data?.cardList?.length || data.cardList.length < pageInfo.value.ps) {
|
|
|
|
|
+ notificationMessageCardRef.value.finished = true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const lists = {
|
|
|
|
|
+ 'All Notifications': { list: notificationList, count: tabCountList },
|
|
|
|
|
+ Unread: { list: unreadNotificationList },
|
|
|
|
|
+ Read: { list: readNotificationList }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const config = lists[tabType]
|
|
|
|
|
+ if (config) {
|
|
|
|
|
+ config.list.value = isChangeNav
|
|
|
|
|
+ ? [...data.cardList]
|
|
|
|
|
+ : [...config.list.value, ...data.cardList]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (config?.count) {
|
|
|
|
|
+ config.count.value = data.countList
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
.finally(() => {
|
|
.finally(() => {
|
|
|
loading.value = false
|
|
loading.value = false
|
|
|
curTabCount.value = []
|
|
curTabCount.value = []
|
|
|
|
|
+ notificationMessageCardRef.value.loading = false
|
|
|
|
|
+
|
|
|
|
|
+ notificationMessageCardRef.value.adjustScrollTop()
|
|
|
})
|
|
})
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- console.error(error)
|
|
|
|
|
loading.value = false
|
|
loading.value = false
|
|
|
curTabCount.value = []
|
|
curTabCount.value = []
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+const notificationMessageCardRef = ref()
|
|
|
|
|
|
|
|
const changeCardRead = () => {
|
|
const changeCardRead = () => {
|
|
|
const readCardMap = notificationMsgStore.readCardMap
|
|
const readCardMap = notificationMsgStore.readCardMap
|
|
@@ -108,12 +171,15 @@ const changeCardRead = () => {
|
|
|
const activeTabName = ref('All Notifications')
|
|
const activeTabName = ref('All Notifications')
|
|
|
const handleTabChange = () => {
|
|
const handleTabChange = () => {
|
|
|
// 当前tab页切换时,更新数据
|
|
// 当前tab页切换时,更新数据
|
|
|
- const readCardMap = notificationMsgStore.readCardMap
|
|
|
|
|
- notificationList.value.forEach((item) => {
|
|
|
|
|
- if (readCardMap.includes(item.info.id)) {
|
|
|
|
|
- item.info.isRead = true
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ // const readCardMap = notificationMsgStore.readCardMap
|
|
|
|
|
+ // notificationList.value.forEach((item) => {
|
|
|
|
|
+ // if (readCardMap.includes(item.info.id)) {
|
|
|
|
|
+ // item.info.isRead = true
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+
|
|
|
|
|
+ pageInfo.value.cp = 1
|
|
|
|
|
+ getNotificationList(activeTabName.value, true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
@@ -174,10 +240,12 @@ onMounted(() => {
|
|
|
<NotificationMessageCard
|
|
<NotificationMessageCard
|
|
|
v-if="activeTabName === 'All Notifications'"
|
|
v-if="activeTabName === 'All Notifications'"
|
|
|
:data="notificationList"
|
|
:data="notificationList"
|
|
|
- @hasCardRead="changeCardRead"
|
|
|
|
|
:isScrollPadding="true"
|
|
:isScrollPadding="true"
|
|
|
:isShowInsertionTime="true"
|
|
:isShowInsertionTime="true"
|
|
|
:updateReadCardsOnChange="false"
|
|
:updateReadCardsOnChange="false"
|
|
|
|
|
+ @hasCardRead="changeCardRead"
|
|
|
|
|
+ @loading="getNotificationList('All Notifications')"
|
|
|
|
|
+ ref="notificationMessageCardRef"
|
|
|
></NotificationMessageCard>
|
|
></NotificationMessageCard>
|
|
|
</div>
|
|
</div>
|
|
|
</el-tab-pane>
|
|
</el-tab-pane>
|
|
@@ -187,9 +255,10 @@ onMounted(() => {
|
|
|
<div
|
|
<div
|
|
|
class="count"
|
|
class="count"
|
|
|
:style="{ 'padding-top': isMac ? 0 : '1px' }"
|
|
:style="{ 'padding-top': isMac ? 0 : '1px' }"
|
|
|
- v-if="unreadNotificationList.length"
|
|
|
|
|
|
|
+ v-if="unreadNotificationList.length > 0 && unreadCardCount > 0"
|
|
|
>
|
|
>
|
|
|
- <span>{{ handleCount(unreadNotificationList.length) }}</span>
|
|
|
|
|
|
|
+ <!-- handleCount(unreadNotificationList.length) || -->
|
|
|
|
|
+ <span>{{ handleCount(unreadCardCount) }}</span>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
<div style="padding-bottom: 20px" v-if="activeTabName === 'Unread'">
|
|
<div style="padding-bottom: 20px" v-if="activeTabName === 'Unread'">
|
|
@@ -199,6 +268,8 @@ onMounted(() => {
|
|
|
:isScrollPadding="true"
|
|
:isScrollPadding="true"
|
|
|
:isShowInsertionTime="true"
|
|
:isShowInsertionTime="true"
|
|
|
:updateReadCardsOnChange="false"
|
|
:updateReadCardsOnChange="false"
|
|
|
|
|
+ @loading="getNotificationList('Unread')"
|
|
|
|
|
+ ref="notificationMessageCardRef"
|
|
|
></NotificationMessageCard>
|
|
></NotificationMessageCard>
|
|
|
</div>
|
|
</div>
|
|
|
</el-tab-pane>
|
|
</el-tab-pane>
|
|
@@ -211,6 +282,8 @@ onMounted(() => {
|
|
|
:isScrollPadding="true"
|
|
:isScrollPadding="true"
|
|
|
:isShowInsertionTime="true"
|
|
:isShowInsertionTime="true"
|
|
|
:data="readNotificationList"
|
|
:data="readNotificationList"
|
|
|
|
|
+ @loading="getNotificationList('Read')"
|
|
|
|
|
+ ref="notificationMessageCardRef"
|
|
|
>
|
|
>
|
|
|
</NotificationMessageCard>
|
|
</NotificationMessageCard>
|
|
|
</div>
|
|
</div>
|