fix: 文档轮询错误

This commit is contained in:
shaohuzhang1 2023-12-20 10:57:43 +08:00
parent 791e2ac6ae
commit 777694feaf

View File

@ -102,7 +102,7 @@
</LayoutContainer> </LayoutContainer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, reactive, watch } from 'vue' import { ref, onMounted, reactive, onBeforeUnmount } from 'vue'
import { useRouter, useRoute } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
import documentApi from '@/api/document' import documentApi from '@/api/document'
import { numberFormat } from '@/utils/utils' import { numberFormat } from '@/utils/utils'
@ -115,6 +115,7 @@ const {
} = route as any } = route as any
const loading = ref(false) const loading = ref(false)
let interval: any
const filterText = ref('') const filterText = ref('')
const documentData = ref<any[]>([]) const documentData = ref<any[]>([])
const currentMouseId = ref(null) const currentMouseId = ref(null)
@ -125,17 +126,25 @@ const paginationConfig = reactive({
total: 0 total: 0
}) })
watch(documentData, (list) => { /**
let interval * 初始化轮询
if (list.length > 0 && list.every((item) => item.status === '0')) { */
interval = setInterval(() => { const initInterval = () => {
getList(true) interval = setInterval(() => {
}, 6000) if (documentData.value.length > 0 && documentData.value.every((item) => item.status === '0')) {
} else { getList()
}
}, 6000)
}
/**
* 关闭轮询
*/
const closeInterval = () => {
if (interval) {
clearInterval(interval) clearInterval(interval)
} }
}) }
function refreshDocument(row: any) { function refreshDocument(row: any) {
documentApi.putDocumentRefresh(row.dataset_id, row.id).then((res) => { documentApi.putDocumentRefresh(row.dataset_id, row.id).then((res) => {
getList() getList()
@ -248,6 +257,13 @@ function getList(bool?: boolean) {
onMounted(() => { onMounted(() => {
getList() getList()
//
initInterval()
})
onBeforeUnmount(() => {
//
closeInterval()
}) })
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>