Browse Source

金币明细的导出

milestone-20260415-金币优化4期
zhangrenyuan 16 hours ago
parent
commit
e6d5e9441c
  1. 83
      src/views/recharge/gold/coinRechargeDetail.vue

83
src/views/recharge/gold/coinRechargeDetail.vue

@ -1,6 +1,6 @@
<script setup>
// - Hash
import { onMounted, ref, watch } from 'vue'
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import moment from 'moment'
import API from '@/util/http.js'
@ -531,10 +531,12 @@ const exportExcel = async function () {
}
const exportListVisible = ref(false)
// 3
const EXPORT_LIST_POLL_INTERVAL = 3000
let exportListPollingTimer = null
//
const openExportList = () => {
getExportList()
exportListVisible.value = true
}
@ -542,9 +544,47 @@ const openExportList = () => {
const exportList = ref([])
//
const exportListLoading = ref(false)
//
const exportListRequesting = ref(false)
// /
const hasPendingExportTask = (list = []) => {
return list.some(item => item.state === 0 || item.state === 1)
}
//
const stopExportListPolling = () => {
if (exportListPollingTimer) {
clearInterval(exportListPollingTimer)
exportListPollingTimer = null
}
}
//
const startExportListPolling = () => {
if (exportListPollingTimer) {
return
}
exportListPollingTimer = setInterval(() => {
//
if (!exportListVisible.value) {
stopExportListPolling()
return
}
getExportList({ showLoading: false, silentError: true })
}, EXPORT_LIST_POLL_INTERVAL)
}
//
const getExportList = async () => {
exportListLoading.value = true
const getExportList = async ({ showLoading = true, silentError = false } = {}) => {
//
if (exportListRequesting.value) {
return
}
if (showLoading) {
exportListLoading.value = true
}
exportListRequesting.value = true
try {
const result = await API({ url: '/export/export' })
if (result.code === 200) {
@ -552,14 +592,29 @@ const getExportList = async () => {
return item.type === 2; //2
});
exportList.value = filteredData
// /
if (exportListVisible.value && hasPendingExportTask(filteredData)) {
startExportListPolling()
} else {
stopExportListPolling()
}
} else {
ElMessage.error(result.msg || t('elmessage.getExportListError'))
stopExportListPolling()
if (!silentError) {
ElMessage.error(result.msg || t('elmessage.getExportListError'))
}
}
} catch (error) {
console.error('获取导出列表出错:', error)
ElMessage.error(t('elmessage.getExportListError'))
stopExportListPolling()
if (!silentError) {
ElMessage.error(t('elmessage.getExportListError'))
}
} finally {
exportListLoading.value = false
exportListRequesting.value = false
if (showLoading) {
exportListLoading.value = false
}
}
}
//
@ -604,6 +659,20 @@ const getTagText = (state) => {
}
}
//
watch(exportListVisible, (visible) => {
if (visible) {
getExportList()
} else {
stopExportListPolling()
}
})
//
onBeforeUnmount(() => {
stopExportListPolling()
})
</script>

Loading…
Cancel
Save