fix:fix site info
This commit is contained in:
@@ -199,9 +199,10 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted, nextTick, watch, onBeforeUnmount } from 'vue'
|
||||
import { ref, reactive, computed, onMounted, nextTick, watch, onBeforeUnmount, onActivated, onDeactivated } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Search, Plus, Loading } from '@element-plus/icons-vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
getTickerList,
|
||||
getTicketDetail,
|
||||
@@ -212,6 +213,10 @@ import {
|
||||
parseFilesToImages
|
||||
} from '@/api/ticket'
|
||||
|
||||
// 路由相关
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
// 管理员ID列表(客服ID)
|
||||
const adminUserIds = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // 假设这些ID是客服ID
|
||||
|
||||
@@ -229,6 +234,11 @@ const hasMore = ref(true)
|
||||
const refreshTimer = ref(null)
|
||||
const refreshInterval = 5000 // 5秒刷新一次
|
||||
|
||||
// 页面可见性状态
|
||||
const isPageVisible = ref(true)
|
||||
// 当前路由路径,用于检测路由变化
|
||||
const currentRoutePath = ref(route.path)
|
||||
|
||||
// 工单数据
|
||||
const ticketList = ref([])
|
||||
const currentTicket = ref(null)
|
||||
@@ -751,6 +761,11 @@ const startAutoRefresh = () => {
|
||||
stopAutoRefresh()
|
||||
|
||||
refreshTimer.value = setInterval(() => {
|
||||
// 检查页面可见性和路由是否还在当前页面
|
||||
if (!isPageVisible.value || route.path !== currentRoutePath.value) {
|
||||
return
|
||||
}
|
||||
|
||||
// 如果当前有工单选中,则刷新聊天记录
|
||||
if (currentTicket.value && selectedTicketId.value) {
|
||||
// 静默刷新聊天记录,不显示loading状态
|
||||
@@ -867,7 +882,38 @@ const refreshTicketMessages = async (workId) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理页面可见性变化
|
||||
const handleVisibilityChange = () => {
|
||||
isPageVisible.value = !document.hidden
|
||||
|
||||
if (isPageVisible.value && route.path === currentRoutePath.value) {
|
||||
// 页面变为可见且还在当前路由时,重新启动定时器
|
||||
startAutoRefresh()
|
||||
} else {
|
||||
// 页面不可见或路由已改变时,停止定时器
|
||||
stopAutoRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
// 监听路由变化
|
||||
watch(() => route.path, (newPath, oldPath) => {
|
||||
if (newPath !== currentRoutePath.value) {
|
||||
// 路由已经离开当前页面,立即停止所有请求
|
||||
console.log('路由变化:从', oldPath, '到', newPath, ',停止工单数据请求')
|
||||
stopAutoRefresh()
|
||||
isPageVisible.value = false
|
||||
} else if (newPath === currentRoutePath.value) {
|
||||
// 路由返回到当前页面,重新启动请求
|
||||
console.log('路由返回到工单页面,重新启动数据请求')
|
||||
isPageVisible.value = true
|
||||
startAutoRefresh()
|
||||
}
|
||||
}, { immediate: false })
|
||||
|
||||
onMounted(() => {
|
||||
// 记录当前路由路径
|
||||
currentRoutePath.value = route.path
|
||||
|
||||
// 获取工单列表
|
||||
fetchTicketList()
|
||||
|
||||
@@ -880,6 +926,9 @@ onMounted(() => {
|
||||
listElement.addEventListener('scroll', handleScroll)
|
||||
}
|
||||
|
||||
// 监听页面可见性变化
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange)
|
||||
|
||||
// 启动自动刷新
|
||||
startAutoRefresh()
|
||||
})
|
||||
@@ -893,6 +942,24 @@ onBeforeUnmount(() => {
|
||||
if (listElement) {
|
||||
listElement.removeEventListener('scroll', handleScroll)
|
||||
}
|
||||
|
||||
// 移除页面可见性监听
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange)
|
||||
})
|
||||
|
||||
// 组件激活时(keep-alive场景)
|
||||
onActivated(() => {
|
||||
console.log('组件激活,重新启动工单数据请求')
|
||||
currentRoutePath.value = route.path
|
||||
isPageVisible.value = true
|
||||
startAutoRefresh()
|
||||
})
|
||||
|
||||
// 组件失活时(keep-alive场景)
|
||||
onDeactivated(() => {
|
||||
console.log('组件失活,停止工单数据请求')
|
||||
isPageVisible.value = false
|
||||
stopAutoRefresh()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user