- 导出范围:支持 ids(导出选中,最多 500 条)或按筛选条件全部 - 导出内容:export_mode=order(默认,一行一个订单,不含明细)/ item(一行一个商品明细,订单字段重复) - 订单导出新增「序列号数量」「序列号列表」列;含明细时按行号取该行 SN(行号为空按商品编码兜底) - 前端导出按钮:订单类型弹窗选择「导出选中 / 按条件全部」与「订单行 / 含明细」,其余类型行为不变 - 导出任务页隐藏 ids 这类由页面自动携带的筛选字段(filters[].hidden) - 补充 exportDefs 订单导出单测(两种模式、选中、权限、参数顺序) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
121 lines
4.2 KiB
Vue
121 lines
4.2 KiB
Vue
<script setup lang="ts">
|
||
import { computed, ref } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import { useExportTasks } from '@/composables/useExportTasks'
|
||
import type { ExportFilters, ExportType } from '@/api/exportTask'
|
||
|
||
/**
|
||
* 导出按钮(列表页通用)
|
||
*
|
||
* 用法:<ExportButton type="product" :filters="exportFilters" />
|
||
* 点击后按当前页面筛选条件提交导出任务,完成时自动下载(逻辑见 composables/useExportTasks)。
|
||
*
|
||
* 订单导出(type="order")额外提供两个维度,提交前弹窗选择:
|
||
* - 范围:导出选中的 N 条(按订单ID) / 按当前筛选条件导出全部
|
||
* - 内容:订单行(一行一个订单,不含明细) / 订单含明细(一行一个商品,订单字段重复填充,带每行序列号)
|
||
*/
|
||
|
||
const props = withDefaults(
|
||
defineProps<{
|
||
/** 导出类型(后端注册表 key) */
|
||
type: ExportType
|
||
/** 当前页面的筛选条件(字段名需与后端该类型的筛选项一致) */
|
||
filters?: ExportFilters
|
||
/** 按钮文案 */
|
||
label?: string
|
||
/** 按钮尺寸 */
|
||
size?: 'large' | 'default' | 'small'
|
||
/** 是否朴素按钮(列表页次级操作) */
|
||
plain?: boolean
|
||
/** 列表当前勾选的记录ID(订单导出「导出选中」用) */
|
||
selectedIds?: number[]
|
||
}>(),
|
||
{
|
||
filters: () => ({}),
|
||
label: '导出',
|
||
size: 'default',
|
||
plain: false,
|
||
selectedIds: () => [],
|
||
},
|
||
)
|
||
|
||
/** 单次导出选中最多条数(与后端 ids 白名单上限一致) */
|
||
const MAX_SELECTED = 500
|
||
|
||
const { submitting, submit } = useExportTasks()
|
||
const text = computed(() => props.label)
|
||
|
||
/** 订单导出走弹窗(区分范围与内容),其它类型点一下直接按条件导出 */
|
||
const isOrderExport = computed(() => props.type === 'order')
|
||
const dialogVisible = ref(false)
|
||
const scope = ref<'selected' | 'filtered'>('filtered')
|
||
const mode = ref<'order' | 'item'>('order')
|
||
|
||
const selectedCount = computed(() => (props.selectedIds || []).length)
|
||
|
||
function handleClick() {
|
||
if (!isOrderExport.value) {
|
||
submit(props.type, props.filters || {})
|
||
return
|
||
}
|
||
// 有勾选时默认导出选中,否则默认按条件全部
|
||
scope.value = selectedCount.value ? 'selected' : 'filtered'
|
||
mode.value = 'order'
|
||
dialogVisible.value = true
|
||
}
|
||
|
||
async function confirmOrderExport() {
|
||
const filters: ExportFilters = { ...(props.filters || {}), export_mode: mode.value }
|
||
if (scope.value === 'selected') {
|
||
const ids = (props.selectedIds || []).slice(0, MAX_SELECTED)
|
||
if (!ids.length) {
|
||
ElMessage.warning('请先在列表中勾选要导出的订单')
|
||
return
|
||
}
|
||
filters.ids = ids.join(',')
|
||
}
|
||
await submit(props.type, filters)
|
||
dialogVisible.value = false
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<el-button type="success" :size="size" :plain="plain" :loading="submitting" @click="handleClick">
|
||
<el-icon><Download /></el-icon>
|
||
<span>{{ text }}</span>
|
||
</el-button>
|
||
|
||
<el-dialog v-model="dialogVisible" title="导出订单" width="440px" append-to-body>
|
||
<el-form label-width="76px" size="small">
|
||
<el-form-item label="导出范围">
|
||
<el-radio-group v-model="scope">
|
||
<el-radio value="selected" :disabled="!selectedCount">
|
||
导出选中({{ selectedCount }} 条)
|
||
</el-radio>
|
||
<el-radio value="filtered">按条件全部</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<el-form-item label="导出内容">
|
||
<el-radio-group v-model="mode">
|
||
<el-radio value="order">订单行(不含明细)</el-radio>
|
||
<el-radio value="item">订单含明细(每商品一行)</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<el-form-item v-if="selectedCount > MAX_SELECTED && scope === 'selected'" label=" ">
|
||
<span class="hint">单次最多导出 {{ MAX_SELECTED }} 条选中订单,超出部分请分批导出</span>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="dialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="submitting" @click="confirmOrderExport">提交导出</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.hint {
|
||
color: var(--el-text-color-secondary);
|
||
font-size: 12px;
|
||
}
|
||
</style>
|