feat(订单导出): 导出下拉四项统一先选字段,「导出全部」也挂上字段设置
This commit is contained in:
parent
897d95f046
commit
674f159780
@ -118,6 +118,7 @@
|
||||
:mode="exportColumnsMode"
|
||||
:loading="exportColumnsLoading"
|
||||
:storage-key="exportColumnsStorageKey"
|
||||
:scope="exportColumnsScope"
|
||||
@confirm="confirmExportColumns"
|
||||
/>
|
||||
|
||||
@ -313,6 +314,7 @@ const {
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsStorageKey,
|
||||
exportColumnsScope,
|
||||
confirmExportColumns
|
||||
} = pageExport
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
>
|
||||
<div class="export-columns-dialog">
|
||||
<div class="export-columns-tip">
|
||||
勾选需要导出的字段,未勾选的字段将不出现在导出文件中。
|
||||
勾选需要导出的字段,未勾选的字段将不出现在导出文件中。{{ scope === 'selection' ? '导出范围:仅导出已勾选的订单。' : '导出范围:按当前筛选条件导出全部订单。' }}
|
||||
</div>
|
||||
|
||||
<!-- 顶部工具条:搜索 + 全选/反选/清空 -->
|
||||
@ -96,12 +96,15 @@ const props = withDefaults(
|
||||
defineProps<{
|
||||
visible: boolean
|
||||
mode?: OrderExportColumnMode
|
||||
/** 导出范围:all=导出全部 / selection=导出选中(仅影响标题与提示文案) */
|
||||
scope?: 'all' | 'selection'
|
||||
loading?: boolean
|
||||
/** 持久化 key(按用户/页面/模式独立),为空则不持久化 */
|
||||
storageKey?: string
|
||||
}>(),
|
||||
{
|
||||
mode: 'waybill',
|
||||
scope: 'all',
|
||||
loading: false,
|
||||
storageKey: ''
|
||||
}
|
||||
@ -112,9 +115,11 @@ const emit = defineEmits<{
|
||||
(e: 'confirm', columns: string[]): void
|
||||
}>()
|
||||
|
||||
const dialogTitle = computed(() =>
|
||||
props.mode === 'item' ? '导出选中(含明细)字段设置' : '导出选中(不含明细)字段设置'
|
||||
)
|
||||
const dialogTitle = computed(() => {
|
||||
const scopeLabel = props.scope === 'selection' ? '导出选中' : '导出全部'
|
||||
const modeLabel = props.mode === 'item' ? '含明细' : '不含明细'
|
||||
return `${scopeLabel}(${modeLabel})字段设置`
|
||||
})
|
||||
|
||||
/** 当前模式可导出的字段(按分组) */
|
||||
const columnGroups = computed(() => getOrderExportColumnGroupsByMode(props.mode))
|
||||
|
||||
@ -467,8 +467,8 @@ export const ORDER_TOOLBAR_BUTTONS: Record<string, ToolbarButtonConfig> = {
|
||||
action: 'handleExportWaybill',
|
||||
buttonType: 'dropdown',
|
||||
dropdownOptions: [
|
||||
{ label: '不含明细', action: 'handleExportWaybill' },
|
||||
{ label: '含明细', action: 'handleExportItem', divided: true },
|
||||
{ label: '导出全部(不含明细)', action: 'handleExportWaybill' },
|
||||
{ label: '导出全部(含明细)', action: 'handleExportItem', divided: true },
|
||||
{ label: '导出选中(不含明细)', action: 'handleExportSelectionWaybill', divided: true },
|
||||
{ label: '导出选中(含明细)', action: 'handleExportSelectionItem' }
|
||||
]
|
||||
|
||||
@ -114,6 +114,7 @@
|
||||
:mode="exportColumnsMode"
|
||||
:loading="exportColumnsLoading"
|
||||
:storage-key="exportColumnsStorageKey"
|
||||
:scope="exportColumnsScope"
|
||||
@confirm="confirmExportColumns"
|
||||
/>
|
||||
|
||||
@ -308,6 +309,7 @@ const {
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsStorageKey,
|
||||
exportColumnsScope,
|
||||
confirmExportColumns
|
||||
} = pageExport
|
||||
|
||||
|
||||
@ -279,6 +279,7 @@
|
||||
:mode="exportColumnsMode"
|
||||
:loading="exportColumnsLoading"
|
||||
:storage-key="exportColumnsStorageKey"
|
||||
:scope="exportColumnsScope"
|
||||
@confirm="confirmExportColumns"
|
||||
/>
|
||||
|
||||
@ -557,6 +558,7 @@ const {
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsStorageKey,
|
||||
exportColumnsScope,
|
||||
confirmExportColumns
|
||||
} = pageExport
|
||||
|
||||
|
||||
@ -114,6 +114,7 @@
|
||||
:mode="exportColumnsMode"
|
||||
:loading="exportColumnsLoading"
|
||||
:storage-key="exportColumnsStorageKey"
|
||||
:scope="exportColumnsScope"
|
||||
@confirm="confirmExportColumns"
|
||||
/>
|
||||
|
||||
@ -308,6 +309,7 @@ const {
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsStorageKey,
|
||||
exportColumnsScope,
|
||||
confirmExportColumns
|
||||
} = pageExport
|
||||
|
||||
|
||||
@ -369,6 +369,7 @@
|
||||
:mode="exportColumnsMode"
|
||||
:loading="exportColumnsLoading"
|
||||
:storage-key="exportColumnsStorageKey"
|
||||
:scope="exportColumnsScope"
|
||||
@confirm="confirmExportColumns"
|
||||
/>
|
||||
|
||||
@ -696,6 +697,7 @@ const {
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsStorageKey,
|
||||
exportColumnsScope,
|
||||
confirmExportColumns
|
||||
} = pageExport
|
||||
|
||||
|
||||
@ -181,6 +181,7 @@
|
||||
:mode="exportColumnsMode"
|
||||
:loading="exportColumnsLoading"
|
||||
:storage-key="exportColumnsStorageKey"
|
||||
:scope="exportColumnsScope"
|
||||
@confirm="confirmExportColumns"
|
||||
/>
|
||||
|
||||
@ -323,6 +324,7 @@ const {
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsStorageKey,
|
||||
exportColumnsScope,
|
||||
confirmExportColumns
|
||||
} = pageExport
|
||||
|
||||
|
||||
@ -373,6 +373,7 @@
|
||||
:mode="exportColumnsMode"
|
||||
:loading="exportColumnsLoading"
|
||||
:storage-key="exportColumnsStorageKey"
|
||||
:scope="exportColumnsScope"
|
||||
@confirm="confirmExportColumns"
|
||||
/>
|
||||
|
||||
@ -660,6 +661,7 @@ const {
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsStorageKey,
|
||||
exportColumnsScope,
|
||||
confirmExportColumns
|
||||
} = pageExport
|
||||
|
||||
|
||||
@ -162,6 +162,7 @@
|
||||
:mode="exportColumnsMode"
|
||||
:loading="exportColumnsLoading"
|
||||
:storage-key="exportColumnsStorageKey"
|
||||
:scope="exportColumnsScope"
|
||||
@confirm="confirmExportColumns"
|
||||
/>
|
||||
|
||||
@ -397,6 +398,7 @@ const {
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsStorageKey,
|
||||
exportColumnsScope,
|
||||
handleExport,
|
||||
handleExportWaybill,
|
||||
handleExportItem,
|
||||
|
||||
@ -7,6 +7,9 @@ import { ORDER_INDEX_EXPORT_SCOPES, sanitizeOrderListWhere } from './order-index
|
||||
import { exportUpperTableRows } from './export'
|
||||
import { translateOrderField } from '../config/order-common-config'
|
||||
|
||||
/** 导出范围:all=按筛选条件导出全部,selection=仅导出勾选行 */
|
||||
export type OrderExportScope = 'all' | 'selection'
|
||||
|
||||
/** 提取选中行的订单 id(过滤空值) */
|
||||
function extractSelectionIds(rows: any[]): Array<number | string> {
|
||||
return rows
|
||||
@ -26,11 +29,15 @@ export function createOrderPageExport(options: {
|
||||
const asyncExport = useOrderAsyncExport(options.storageKey)
|
||||
const exportSelectionLoading = ref(false)
|
||||
|
||||
/** 导出选中(含明细/不含明细)字段选择对话框状态 */
|
||||
/** 导出字段设置对话框状态(导出全部 / 导出选中 共用,用 exportColumnsScope 区分) */
|
||||
const exportColumnsDialogVisible = ref(false)
|
||||
const exportColumnsMode = ref<OrderExportMode>('waybill')
|
||||
const exportColumnsLoading = ref(false)
|
||||
/** 导出选中字段配置持久化 key(按 用户/角色/页面/模式 独立保存;前缀区别于字段设置,避免被“故障修复”清除) */
|
||||
/** 本次导出的范围:all=按当前筛选条件导出全部,selection=仅导出勾选行 */
|
||||
const exportColumnsScope = ref<OrderExportScope>('all')
|
||||
/** 本次导出勾选行的订单 id(仅 selection 范围使用) */
|
||||
const exportColumnsOrderIds = ref<Array<number | string>>([])
|
||||
/** 字段配置持久化 key(按 用户/角色/页面/模式 独立保存;前缀区别于字段设置,避免被“故障修复”清除) */
|
||||
const exportColumnsStorageKey = ref('')
|
||||
|
||||
function getExportColumnsStorageKey(mode: OrderExportMode): string {
|
||||
@ -40,26 +47,27 @@ export function createOrderPageExport(options: {
|
||||
return `order_export_columns_${userId}_${roleId}_${options.scopeKey}_${mode}`
|
||||
}
|
||||
|
||||
async function handleExport(exportMode: OrderExportMode = 'waybill') {
|
||||
const scope = ORDER_INDEX_EXPORT_SCOPES[options.scopeKey]
|
||||
if (!scope) {
|
||||
ElMessage.error('未配置导出范围')
|
||||
return
|
||||
}
|
||||
await asyncExport.submitExportTask({
|
||||
...scope,
|
||||
where: sanitizeOrderListWhere(options.buildWhere()),
|
||||
sort: options.buildSort?.(),
|
||||
export_mode: exportMode
|
||||
})
|
||||
/** 打开字段设置对话框;ids 为空表示导出全部(不加 id 过滤) */
|
||||
function openExportColumnsDialog(mode: OrderExportMode, ids: Array<number | string> = []) {
|
||||
exportColumnsMode.value = mode
|
||||
exportColumnsScope.value = ids.length ? 'selection' : 'all'
|
||||
exportColumnsOrderIds.value = ids
|
||||
exportColumnsStorageKey.value = getExportColumnsStorageKey(mode)
|
||||
exportColumnsDialogVisible.value = true
|
||||
}
|
||||
|
||||
/** 导出(不含明细):先选字段,再按当前筛选条件导出全部 */
|
||||
async function handleExportWaybill() {
|
||||
await handleExport('waybill')
|
||||
openExportColumnsDialog('waybill')
|
||||
}
|
||||
|
||||
/** 导出(含明细):先选字段,再按当前筛选条件导出全部 */
|
||||
async function handleExportItem() {
|
||||
await handleExport('item')
|
||||
openExportColumnsDialog('item')
|
||||
}
|
||||
|
||||
async function handleExport() {
|
||||
await handleExportWaybill()
|
||||
}
|
||||
|
||||
async function handleExportSelection() {
|
||||
@ -83,34 +91,34 @@ export function createOrderPageExport(options: {
|
||||
}
|
||||
}
|
||||
|
||||
/** 打开导出选中字段选择对话框(含明细/不含明细) */
|
||||
function openExportColumnsDialog(mode: OrderExportMode) {
|
||||
if (!options.selectionRows.value.length) {
|
||||
async function handleExportSelectionWaybill() {
|
||||
const ids = extractSelectionIds(options.selectionRows.value)
|
||||
if (!ids.length) {
|
||||
ElMessage.warning('请先勾选要导出的订单')
|
||||
return
|
||||
}
|
||||
exportColumnsMode.value = mode
|
||||
exportColumnsStorageKey.value = getExportColumnsStorageKey(mode)
|
||||
exportColumnsDialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleExportSelectionWaybill() {
|
||||
openExportColumnsDialog('waybill')
|
||||
openExportColumnsDialog('waybill', ids)
|
||||
}
|
||||
|
||||
async function handleExportSelectionItem() {
|
||||
openExportColumnsDialog('item')
|
||||
const ids = extractSelectionIds(options.selectionRows.value)
|
||||
if (!ids.length) {
|
||||
ElMessage.warning('请先勾选要导出的订单')
|
||||
return
|
||||
}
|
||||
openExportColumnsDialog('item', ids)
|
||||
}
|
||||
|
||||
/** 字段选择确认后,提交 order.export 异步导出选中订单 */
|
||||
/** 字段选择确认后,提交 order.export 异步导出(全部 / 选中) */
|
||||
async function confirmExportColumns(columns: string[]) {
|
||||
const scope = ORDER_INDEX_EXPORT_SCOPES[options.scopeKey]
|
||||
if (!scope) {
|
||||
ElMessage.error('未配置导出范围')
|
||||
return
|
||||
}
|
||||
const ids = extractSelectionIds(options.selectionRows.value)
|
||||
if (!ids.length) {
|
||||
const isSelection = exportColumnsScope.value === 'selection'
|
||||
const ids = exportColumnsOrderIds.value
|
||||
if (isSelection && !ids.length) {
|
||||
ElMessage.warning('请先勾选要导出的订单')
|
||||
return
|
||||
}
|
||||
@ -121,7 +129,7 @@ export function createOrderPageExport(options: {
|
||||
...scope,
|
||||
where: sanitizeOrderListWhere({
|
||||
...options.buildWhere(),
|
||||
id: { operator: 'in', value: ids }
|
||||
...(isSelection ? { id: { operator: 'in', value: ids } } : {})
|
||||
}),
|
||||
sort: options.buildSort?.(),
|
||||
export_mode: exportColumnsMode.value,
|
||||
@ -141,6 +149,7 @@ export function createOrderPageExport(options: {
|
||||
exportColumnsDialogVisible,
|
||||
exportColumnsMode,
|
||||
exportColumnsLoading,
|
||||
exportColumnsScope,
|
||||
exportColumnsStorageKey,
|
||||
handleExport: handleExportWaybill,
|
||||
handleExportWaybill,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user