|
@@ -2,8 +2,11 @@
|
|
|
import { onBeforeRouteUpdate } from 'vue-router'
|
|
import { onBeforeRouteUpdate } from 'vue-router'
|
|
|
import NotificationMessageCard from '@/components/NotificationMessageCard/src/NotificationMessageCard.vue'
|
|
import NotificationMessageCard from '@/components/NotificationMessageCard/src/NotificationMessageCard.vue'
|
|
|
import { useUserStore } from '@/stores/modules/user'
|
|
import { useUserStore } from '@/stores/modules/user'
|
|
|
|
|
+import { useNotificationMessage } from '@/stores/modules/notificationMessage'
|
|
|
|
|
+import dayjs from 'dayjs'
|
|
|
|
|
|
|
|
const userStore = useUserStore()
|
|
const userStore = useUserStore()
|
|
|
|
|
+const notificationMessageStore = useNotificationMessage()
|
|
|
const notificationList = ref([])
|
|
const notificationList = ref([])
|
|
|
// const notificationList = [
|
|
// const notificationList = [
|
|
|
// {
|
|
// {
|
|
@@ -112,34 +115,53 @@ const curCard = computed(() => {
|
|
|
})
|
|
})
|
|
|
const curIndex = ref(0)
|
|
const curIndex = ref(0)
|
|
|
// 设置定时器进行自动轮播
|
|
// 设置定时器进行自动轮播
|
|
|
-let intervalId = null
|
|
|
|
|
|
|
+let trainingIntervalId = null
|
|
|
|
|
+
|
|
|
|
|
+// 轮询最新未读消息
|
|
|
|
|
+let newMessageIntervalId = null
|
|
|
|
|
+// 轮询最新未读消息
|
|
|
|
|
+const pollingNewMessage = () => {
|
|
|
|
|
+ if (newMessageIntervalId) return
|
|
|
|
|
+ // 每隔5分钟轮询一次
|
|
|
|
|
+ newMessageIntervalId = setInterval(() => {
|
|
|
|
|
+ getNotificationList(dayjs().format('MM/DD/YYYY HH:mm:ss'))
|
|
|
|
|
+ }, 300000)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 登录后自动轮播消息
|
|
|
|
|
+const trainingCardAfterLogin = () => {
|
|
|
|
|
+ curIndex.value = curIndex.value + 1
|
|
|
|
|
+ // 如果到达最后一个消息,设置为null以清除显示
|
|
|
|
|
+ if (curIndex.value >= notificationList.value.length) {
|
|
|
|
|
+ clearInterval(trainingIntervalId)
|
|
|
|
|
+ pollingNewMessage()
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
const nextNotification = () => {
|
|
const nextNotification = () => {
|
|
|
let result = true
|
|
let result = true
|
|
|
// 更新当前索引和卡片
|
|
// 更新当前索引和卡片
|
|
|
curIndex.value = curIndex.value + 1
|
|
curIndex.value = curIndex.value + 1
|
|
|
- // curCard.value = notificationList[curIndex.value]
|
|
|
|
|
// 如果消息为password或者feature类型,暂停自动轮播
|
|
// 如果消息为password或者feature类型,暂停自动轮播
|
|
|
if (
|
|
if (
|
|
|
curCard.value?.notificationType === 'password' ||
|
|
curCard.value?.notificationType === 'password' ||
|
|
|
curCard.value?.notificationType === 'feature'
|
|
curCard.value?.notificationType === 'feature'
|
|
|
) {
|
|
) {
|
|
|
- clearInterval(intervalId)
|
|
|
|
|
|
|
+ clearInterval(trainingIntervalId)
|
|
|
result = false
|
|
result = false
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 如果到达最后一个消息,设置为null以清除显示
|
|
// 如果到达最后一个消息,设置为null以清除显示
|
|
|
if (curIndex.value >= notificationList.value.length) {
|
|
if (curIndex.value >= notificationList.value.length) {
|
|
|
- clearInterval(intervalId)
|
|
|
|
|
- // curCard.value = null
|
|
|
|
|
|
|
+ clearInterval(trainingIntervalId)
|
|
|
result = false
|
|
result = false
|
|
|
}
|
|
}
|
|
|
return result
|
|
return result
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 轮询时的轮播定时器
|
|
|
const initTrainingCard = () => {
|
|
const initTrainingCard = () => {
|
|
|
if (curCard.value?.notificationType === 'event') {
|
|
if (curCard.value?.notificationType === 'event') {
|
|
|
- intervalId = setInterval(nextNotification, 2000)
|
|
|
|
|
|
|
+ trainingIntervalId = setInterval(nextNotification, 2000)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -147,38 +169,56 @@ onBeforeRouteUpdate((to, from, next) => {
|
|
|
if (from.name === 'Login' && userStore.userName) {
|
|
if (from.name === 'Login' && userStore.userName) {
|
|
|
getNotificationList()
|
|
getNotificationList()
|
|
|
}
|
|
}
|
|
|
|
|
+ if (to.name === 'Login') {
|
|
|
|
|
+ clearInterval(trainingIntervalId)
|
|
|
|
|
+ clearInterval(newMessageIntervalId)
|
|
|
|
|
+ }
|
|
|
next()
|
|
next()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-const getNotificationList = () => {
|
|
|
|
|
- // if (localStorage.getItem('showFeatureAfterLogin') !== 'true') return
|
|
|
|
|
- // // 获取数据
|
|
|
|
|
-
|
|
|
|
|
- // localStorage.removeItem('showFeatureAfterLogin')
|
|
|
|
|
|
|
+const emit = defineEmits<{ hasNewMessage: [] }>()
|
|
|
|
|
+const getNotificationList = (time?: string) => {
|
|
|
$api
|
|
$api
|
|
|
.getNotificationList({
|
|
.getNotificationList({
|
|
|
rules_type: 'all',
|
|
rules_type: 'all',
|
|
|
- info_type: true
|
|
|
|
|
|
|
+ info_type: true,
|
|
|
|
|
+ current_time: time
|
|
|
})
|
|
})
|
|
|
.then((res) => {
|
|
.then((res) => {
|
|
|
if (res.code === 200) {
|
|
if (res.code === 200) {
|
|
|
|
|
+ curIndex.value = 0
|
|
|
notificationList.value = res.data
|
|
notificationList.value = res.data
|
|
|
- console.log(curCard.value, 'curCard')
|
|
|
|
|
- initTrainingCard()
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (time && res.data.length > 0) {
|
|
|
|
|
+ emit('hasNewMessage')
|
|
|
|
|
+ initTrainingCard()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ trainingIntervalId = setInterval(trainingCardAfterLogin, 2000)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 关闭消息,如果是登录后自动轮播的消息,则需清除定时器,如果不是则继续轮播下一条消息
|
|
|
const closeMessage = () => {
|
|
const closeMessage = () => {
|
|
|
|
|
+ if (!newMessageIntervalId) {
|
|
|
|
|
+ clearInterval(trainingIntervalId)
|
|
|
|
|
+ curIndex.value = -1
|
|
|
|
|
+ pollingNewMessage()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 如果当前消息为event类型,则需先清除定时器
|
|
// 如果当前消息为event类型,则需先清除定时器
|
|
|
if (curCard.value?.notificationType === 'event') {
|
|
if (curCard.value?.notificationType === 'event') {
|
|
|
- clearInterval(intervalId)
|
|
|
|
|
|
|
+ clearInterval(trainingIntervalId)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const result = nextNotification()
|
|
const result = nextNotification()
|
|
|
if (result) {
|
|
if (result) {
|
|
|
- intervalId = setInterval(nextNotification, 2000)
|
|
|
|
|
|
|
+ trainingIntervalId = setInterval(nextNotification, 2000)
|
|
|
}
|
|
}
|
|
|
|
|
+ // 将当前消息标记为已读
|
|
|
|
|
+ notificationMessageStore.setReadCardMap(curCard.value?.info?.id)
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
@@ -204,9 +244,9 @@ const closeMessage = () => {
|
|
|
width: 432px;
|
|
width: 432px;
|
|
|
padding: 16px;
|
|
padding: 16px;
|
|
|
padding-bottom: 0;
|
|
padding-bottom: 0;
|
|
|
- background-color: #fff;
|
|
|
|
|
|
|
+ background-color: var(--color-dialog-body-bg);
|
|
|
border-radius: 12px;
|
|
border-radius: 12px;
|
|
|
- box-shadow: 4px 4px 16px 0px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
+ box-shadow: 4px 4px 32px 0px rgba(0, 0, 0, 0.2);
|
|
|
.close-icon {
|
|
.close-icon {
|
|
|
position: absolute;
|
|
position: absolute;
|
|
|
top: 14px;
|
|
top: 14px;
|