吉安感知网项目-前端
shuishen
2026-02-03 89380e6260a75d1d3b94de687ebcc2f50d50659d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<template>
    <div class="messagePrompt" v-if="allUnreadItems.length > 0 && showTip">
        <div
            class="messageList"
            :style="{ transform: `translateY(-${currentIndex * 3.8}rem)`, transition: 'transform 0.5s ease' }"
        >
            <div class="messageItem" v-for="(item, index) in allUnreadItems" :key="index">
                <div class="messageleft">
                    <img src="@/assets/images/warning.png" alt="" />
                    <span class="dots"></span>
                    <div class="infodetail">
                        <span>{{ item.name }}</span>
                        <span>{{ item.date }}</span>
                    </div>
                </div>
                <div class="messagebtn" @click="stopmessagetip">不再提醒</div>
            </div>
        </div>
    </div>
</template>
 
<script setup>
import { useStore } from 'vuex'
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import notificationSound from '@/assets/audio/audio_8652e075da.mp3'
import { getOrderOrEventApi } from '@/api/home'
 
const store = useStore()
const consoleShow = computed(() => store?.state?.task?.consoleShow)
let audio = new Audio()
audio.src = notificationSound
audio.volume = 1
audio.loop = true
audio?.pause()
const userInfo = computed(() => store.getters.userInfo)
const todosData = computed(() => store.state.common?.todosData)
const dateRange = computed(() => store.state.home.eventTimeRang)
const showTip = ref(true)
const currentIndex = ref(0)
let carouselTimer = null
const hasUnread = computed(() => todosData.value?.some(i => !i?.is_read))
const allUnreadItems = computed(() => todosData.value?.filter(i => !i.is_read) || [])
const newunread = ref(null)
let refreshInterval = null // 自动刷新待办事项(每5秒)
let pauseTimeout = null // 1分钟后暂停播放
let cfTimeout = null //5分钟重复一次
let retryTimeout = null // 1分钟后重试弹框
const yzxs = ref(true) //一值提醒
const todosParams = {
    type: 1,
    area_code: userInfo.value.detail.areaCode,
    start_time: dateRange.value[0],
    end_time: dateRange.value[1],
}
 
// 轮播
const startCarousel = () => {
    if (carouselTimer) clearInterval(carouselTimer)
    if (allUnreadItems.value.length <= 1) return
 
    carouselTimer = setInterval(() => {
        currentIndex.value = (currentIndex.value + 1) % allUnreadItems.value.length
    }, 3000)
}
// 停止消息提示
const stopmessagetip = () => {
    showTip.value = false
    yzxs.value = false // 设置手动关闭标志
    clearInterval(carouselTimer)
    audio?.pause()
}
watch(allUnreadItems, val => {
    if (!showTip.value) return
 
    if (val && !consoleShow.value && yzxs.value) {
        startCarousel()
        audio?.play()
    } else {
        audio?.pause()
        clearInterval(carouselTimer)
    }
})
 
// 获取待办事项
const getListMatter = async () => {
    const res = await getOrderOrEventApi(todosParams)
    if (!res.data.data || res.data.data?.length === 0) {
        store.commit('setTodosData', [])
        return
    }
    const oldList = (todosData.value || []).filter(i => !i.is_read).map(i => i.id)
    const newList = (res.data.data || []).filter(i => !i.is_read).map(i => i.id)
    const hasNewItem = newList.filter(item => !oldList.includes(item))
    newunread.value = hasNewItem
    if (hasNewItem.length > 0) {
        showTip.value = true
        audio?.play()
        startCarousel()
    }
    store.commit('setTodosData', res.data.data)
}
const startAutoRefresh = () => {
    refreshInterval = setInterval(getListMatter, 5000)
}
 
watch(
    dateRange,
    newVal => {
        if (newVal) {
            todosParams.start_time = newVal[0]
            todosParams.end_time = newVal[1]
            getListMatter()
        }
    },
    { deep: true }
)
 
onMounted(() => {
    getListMatter()
    startAutoRefresh()
    startCarousel()
})
 
onBeforeUnmount(() => {
    refreshInterval && clearInterval(refreshInterval)
    pauseTimeout && clearTimeout(pauseTimeout)
    cfTimeout && clearInterval(cfTimeout)
    retryTimeout && clearTimeout(retryTimeout)
    clearInterval(carouselTimer)
    audio?.pause()
    audio = null
})
</script>
 
<style scoped lang="scss">
.messagePrompt {
    position: absolute;
    top: 105px;
    left: 50%;
    transform: translateX(-50%);
    color: #ffffff;
    border-radius: 4px;
    font-size: 14px;
    width: 633px;
    height: 38px;
    overflow: hidden;
    background: url('@/assets/images/warninfobg.png') no-repeat center;
    background-size: 100% 100%;
 
    .messageList {
        height: 38px;
        width: 100%;
    }
 
    .messageItem {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 633px;
        height: 38px;
        .messageleft {
            display: flex;
            align-items: center;
            margin-left: 85px;
            img {
                width: 32px;
                height: 32px;
            }
            .dots {
                display: inline-block;
                width: 6px;
                height: 6px;
                background: #ff5741;
                border-radius: 50%;
            }
            .infodetail {
                display: flex;
                width: 332px;
                justify-content: space-between;
                margin-left: 7px;
            }
        }
        .messagebtn {
            cursor: pointer;
            margin-right: 57px;
        }
    }
}
</style>