✨ 毛利分析订单支持异步导出

This commit is contained in:
caojia
2026-11-17 14:55:54 +08:00
parent e104c5a3e9
commit d8f6ceda59
8 changed files with 576 additions and 26 deletions
+92 -13
View File
@@ -1,5 +1,20 @@
<template>
<div class="app-container profit-report">
<Teleport to="body">
<div v-if="exportFloatVisible" class="export-status-float">
<el-tooltip :content="exportMessage || '点击查看详情'" placement="bottom">
<el-button class="export-status-button" type="warning" plain size="small" @click="exportProgressVisible = true">
<span class="export-progress-ring" :style="{ '--export-progress': exportDegree + 'deg' }" aria-hidden="true">
<span class="export-progress-value">{{ exportPercent }}%</span>
</span>
<span class="export-status-text">
<strong>{{ exportFloatTitle }}</strong>
<small>{{ exportFloatSummary }}</small>
</span>
</el-button>
</el-tooltip>
</div>
</Teleport>
<el-card shadow="never" class="search-card">
<el-form :model="query" label-width="88px" @submit.prevent>
<el-row :gutter="16">
@@ -156,7 +171,7 @@
icon="Download"
v-hasPermi="['report:profit:export']"
:loading="exporting"
:disabled="!hasProfitRule() || !hasSearched"
:disabled="!hasProfitRule() || !hasSearched || loading"
@click="handleExport"
>导出订单</el-button>
</div>
@@ -202,6 +217,17 @@
/>
</el-card>
<el-dialog v-model="exportProgressVisible" :title="exportDialogTitle" width="480px" append-to-body :close-on-click-modal="false">
<el-progress :percentage="exportPercent" :status="exportStatus" :stroke-width="14" striped :striped-flow="exporting" />
<div class="export-progress__msg">{{ exportMessage }}</div>
<div class="export-progress__text">导出行数 {{ exportRowCount }}</div>
<p v-if="exporting" class="export-progress__hint">导出在后台进行,可收起弹窗继续操作;请勿关闭或刷新本页</p>
<template #footer>
<el-button v-if="exporting" @click="exportProgressVisible = false">收起</el-button>
<el-button v-else type="primary" @click="exportProgressVisible = false">关闭</el-button>
</template>
</el-dialog>
<!-- 提成设置与编辑弹窗暂停使用。
<el-dialog v-model="commissionDialogVisible" title="业务员固定提成比例" width="760px" append-to-body>
<div class="commission-toolbar">
@@ -240,11 +266,11 @@
</template>
<script setup name="ProfitReport">
import { downloadProfitExport, exportProfitOrders, listProfitAreaRules, listProfitCustomerOptions, listProfitOrders, listProfitSummary } from '@/api/report/profit'
import { listProfitAreaRules, listProfitCustomerOptions, listProfitOrders, listProfitSummary } from '@/api/report/profit'
// 提成功能暂停使用:import { deleteProfitCommissionRate, listProfitCommissionRates, saveProfitCommissionRate } from '@/api/report/profit'
import { parseTime } from '@/utils/bms'
import { ElMessage } from 'element-plus'
import { saveAs } from 'file-saver'
import { exportAsync } from '@/utils/excelExport'
// 提成功能暂停使用:import { ElMessageBox } from 'element-plus'
const { customer_area, bms_currency } = useDict('customer_area', 'bms_currency')
@@ -275,6 +301,23 @@ let rowsRequestVersion = 0
const loading = ref(false)
const hasSearched = ref(false)
const exporting = ref(false)
const exportFinished = ref(false)
const exportProgressVisible = ref(false)
const exportPercent = ref(0)
const exportStatus = ref(undefined)
const exportMessage = ref('')
const exportRowCount = ref(0)
let exportHideTimer = null
const exportFloatVisible = computed(() => exporting.value || exportFinished.value)
const exportDegree = computed(() => Math.round(exportPercent.value / 100 * 360))
const exportFloatTitle = computed(() => exporting.value ? '导出中' : (exportStatus.value === 'exception' ? '导出失败' : '导出完成'))
const exportFloatSummary = computed(() => exportRowCount.value > 0
? `${exportPercent.value}% / ${exportRowCount.value} 行`
: `${exportPercent.value}%`)
const exportDialogTitle = computed(() => exporting.value ? '异步导出进行中' : (exportStatus.value === 'exception' ? '异步导出失败' : '异步导出完成'))
onBeforeUnmount(() => {
clearTimeout(exportHideTimer)
})
const pageNum = ref(1)
const pageSize = ref(10)
// 汇总按币种分组,分页总数复用各币种订单数之和。
@@ -441,23 +484,47 @@ function arBillStatusLabel(value) {
}
async function handleExport() {
if (!hasSearched.value || !validateRequiredFilters()) return
if (exporting.value || !hasSearched.value || !validateRequiredFilters()) return
if (!hasProfitRule() || !validateMultiValueFilters()) return
clearTimeout(exportHideTimer)
exporting.value = true
exportFinished.value = false
exportProgressVisible.value = false
exportPercent.value = 0
exportStatus.value = undefined
exportMessage.value = '正在提交导出任务'
exportRowCount.value = 0
try {
const response = await exportProfitOrders(buildQuery(false))
const exportResult = response.data
const file = await downloadProfitExport(exportResult.exportId)
if (file.type?.includes('json')) {
const error = JSON.parse(await file.text())
throw new Error(error.msg || '下载导出文件失败')
const result = await exportAsync({
baseUrl: '/report/profit/orders/export',
query: buildQuery(false),
filePrefix: '订单维度毛利分析',
showLoading: false,
onProgress: task => {
exportPercent.value = Math.max(0, Math.min(100, Number(task.percent) || 0))
exportRowCount.value = Number(task.rowCount) || 0
exportMessage.value = task.error || task.message || '导出中'
if (task.status === 'FAIL' || task.status === 'FAILED') exportStatus.value = 'exception'
}
})
if (result) {
exportPercent.value = 100
exportStatus.value = 'success'
exportMessage.value = '导出完成'
} else {
if (exportStatus.value !== 'exception') exportMessage.value = '导出失败,请查看提示后重试'
exportStatus.value = 'exception'
}
saveAs(file, exportResult.fileName)
ElMessage.success('报表已导出')
} catch (error) {
ElMessage.error(error?.message || '报表导出失败')
exportStatus.value = 'exception'
exportMessage.value = error?.message || '导出失败,请稍后重试'
} finally {
exporting.value = false
exportFinished.value = true
exportHideTimer = window.setTimeout(() => {
exportFinished.value = false
exportHideTimer = null
}, 1000)
}
}
@@ -545,6 +612,18 @@ watch(() => [
</script>
<style scoped lang="scss">
.export-status-float { position: fixed; top: 92px; right: 24px; z-index: 3001; }
.export-status-button { display: inline-flex; align-items: center; gap: 10px; min-width: 200px; min-height: 68px; padding: 6px 16px 6px 7px; border-radius: 36px; }
.export-progress-ring { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 54px; width: 54px; height: 54px; border-radius: 50%; background: conic-gradient(var(--el-color-warning) 0deg var(--export-progress, 0deg), var(--el-color-warning-light-8) var(--export-progress, 0deg) 360deg); }
.export-progress-ring::after { position: absolute; inset: 5px; content: ''; border-radius: 50%; background: var(--el-bg-color); }
.export-progress-value { position: relative; z-index: 1; color: var(--el-color-warning); font-size: 12px; font-weight: 600; line-height: 1; }
.export-status-text { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; line-height: 1.2; white-space: nowrap; }
.export-status-text strong { font-size: 14px; font-weight: 600; }
.export-status-text small { color: var(--el-text-color-secondary); font-size: 11px; }
.export-progress__msg { margin-top: 12px; color: var(--el-text-color-regular); }
.export-progress__text { margin-top: 8px; color: var(--el-text-color-secondary); font-size: 13px; }
.export-progress__hint { margin-top: 12px; color: var(--el-color-warning); font-size: 12px; }
.search-card,
.table-card {
margin-bottom: 14px;