|
@@ -37,7 +37,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { onMounted, ref, watch } from 'vue'
|
|
|
+import { onActivated, onDeactivated, onMounted, ref, watch } from 'vue'
|
|
|
import { useAppStore } from '~src/store'
|
|
|
//import HcTree from "./components/hc-tree.vue"
|
|
|
import HcTree from '~src/components/tree/hc-tree.vue'
|
|
@@ -60,12 +60,35 @@ watch(() => useAppState.getCollapse, (Collapse) => {
|
|
|
|
|
|
//渲染完成
|
|
|
onMounted(async () => {
|
|
|
+
|
|
|
getClassIfyList().then()
|
|
|
+
|
|
|
+
|
|
|
+})
|
|
|
+onActivated(async () => {
|
|
|
+
|
|
|
+
|
|
|
+ isPageVisible.value = true
|
|
|
await updateArchiveprogress()
|
|
|
- if (count.value < 100) {
|
|
|
- Verification(false)
|
|
|
+
|
|
|
+
|
|
|
+ if ( propercent.value < 100 && propercent.value > 0) {
|
|
|
+
|
|
|
+ Verification( true)
|
|
|
}
|
|
|
+
|
|
|
})
|
|
|
+// 在 onUnmounted 中移除事件监听
|
|
|
+onDeactivated(() => {
|
|
|
+isPageVisible.value = false
|
|
|
+ if (timer.value) {
|
|
|
+ clearInterval(timer.value)
|
|
|
+ timer.value = null
|
|
|
+ }
|
|
|
+})
|
|
|
+// 页面可见性状态
|
|
|
+const isPageVisible = ref(true)
|
|
|
+// 处理页面可见性变化
|
|
|
|
|
|
//树加载
|
|
|
const treeLoading = ref(true)
|
|
@@ -236,6 +259,11 @@ const updateArchiveprogress = async () => {
|
|
|
if (!error && code === 200) {
|
|
|
if (data == 100) {
|
|
|
count.value = 100
|
|
|
+ if (tipVal.value) {
|
|
|
+ window.$message.success('更新成功')
|
|
|
+ clearInterval(timer.value) // 停止定时器
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
propercent.value = data
|
|
|
}
|
|
@@ -243,17 +271,25 @@ const updateArchiveprogress = async () => {
|
|
|
const timer = ref(null)
|
|
|
let count = ref(0) // 倒计时
|
|
|
//循环请求接口
|
|
|
+const tipVal = ref(false)
|
|
|
+// 修改 Verification 函数,添加页面可见性检查
|
|
|
+
|
|
|
const Verification = (tip = true) => {
|
|
|
- timer.value = setInterval(() => {
|
|
|
- if (count.value == 100) {
|
|
|
- if (tip) {
|
|
|
- window.$message.success('更新成功')
|
|
|
- }
|
|
|
- clearInterval(timer.value)
|
|
|
- } else {
|
|
|
- updateArchiveprogress()// 请求数据
|
|
|
- }
|
|
|
- }, 5000)
|
|
|
+ if (!isPageVisible.value) return // 如果页面不可见,不启动轮询
|
|
|
+ tipVal.value = tip
|
|
|
+
|
|
|
+ timer.value = setInterval(() => {
|
|
|
+ if (count.value == 100) {
|
|
|
+ if (tip) {
|
|
|
+ window.$message.success('更新成功')
|
|
|
+ }
|
|
|
+ clearInterval(timer.value)
|
|
|
+ } else {
|
|
|
+ if (isPageVisible.value) { // 只在页面可见时请求数据
|
|
|
+ updateArchiveprogress()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 5000)
|
|
|
}
|
|
|
</script>
|
|
|
|