Browse Source

金币明细的导出

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

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

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

Loading…
Cancel
Save