mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 01:49:19 +08:00
perf(订单): 列表分页走时间索引与延迟关联,批量组装 VO,前端默认 30 天下单时间范围
This commit is contained in:
@@ -80,16 +80,57 @@ const productSearchKeyword = ref('');
|
||||
const productLoaded = ref(false);
|
||||
let productSearchTimer: null | ReturnType<typeof setTimeout> = null;
|
||||
|
||||
// 搜索表单
|
||||
/** 与后端 OrderPageQuerySupport 对齐 */
|
||||
const DEFAULT_LIST_DAYS = 30;
|
||||
const MAX_LIST_DAYS = 366;
|
||||
|
||||
function buildDefaultOrderTimeRange() {
|
||||
const end = dayjs().endOf('day');
|
||||
const start = dayjs()
|
||||
.subtract(DEFAULT_LIST_DAYS - 1, 'day')
|
||||
.startOf('day');
|
||||
return {
|
||||
start: start.format('YYYY-MM-DD HH:mm:ss'),
|
||||
end: end.format('YYYY-MM-DD HH:mm:ss'),
|
||||
range: [start, end] as [dayjs.Dayjs, dayjs.Dayjs],
|
||||
};
|
||||
}
|
||||
|
||||
const defaultOrderTime = buildDefaultOrderTimeRange();
|
||||
|
||||
// 搜索表单(默认近 30 天,避免无时间范围扫全表)
|
||||
const searchForm = ref({
|
||||
platformOrderNo: '',
|
||||
shopId: undefined as number | undefined,
|
||||
statusId: undefined as number | undefined,
|
||||
startOrderTime: undefined as string | undefined,
|
||||
endOrderTime: undefined as string | undefined,
|
||||
startOrderTime: defaultOrderTime.start as string | undefined,
|
||||
endOrderTime: defaultOrderTime.end as string | undefined,
|
||||
productId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
function ensureOrderTimeFilters(): boolean {
|
||||
if (!searchForm.value.startOrderTime || !searchForm.value.endOrderTime) {
|
||||
const d = buildDefaultOrderTimeRange();
|
||||
searchForm.value.startOrderTime = d.start;
|
||||
searchForm.value.endOrderTime = d.end;
|
||||
}
|
||||
const start = dayjs(searchForm.value.startOrderTime);
|
||||
const end = dayjs(searchForm.value.endOrderTime);
|
||||
if (!start.isValid() || !end.isValid()) {
|
||||
message.warning('请选择有效的下单时间范围');
|
||||
return false;
|
||||
}
|
||||
if (end.isBefore(start)) {
|
||||
message.warning('下单结束时间不能早于开始时间');
|
||||
return false;
|
||||
}
|
||||
if (end.diff(start, 'day') + 1 > MAX_LIST_DAYS) {
|
||||
message.warning(`下单时间跨度不能超过 ${MAX_LIST_DAYS} 天,请缩小范围`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 当前排序状态
|
||||
const currentSort = ref<null | { field: string; order: 'asc' | 'desc' }>(null);
|
||||
|
||||
@@ -347,6 +388,9 @@ const gridOptions: VxeGridProps<any> = {
|
||||
ajax: {
|
||||
query: async ({ page, form }) => {
|
||||
try {
|
||||
if (!ensureOrderTimeFilters()) {
|
||||
return { items: [], total: 0 };
|
||||
}
|
||||
loading.value = true;
|
||||
// 从表单获取搜索参数
|
||||
const searchParams = form || {};
|
||||
@@ -403,7 +447,7 @@ const formOptions = computed(() => ({
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入平台订单号(回车搜索)',
|
||||
placeholder: '平台订单号(前缀匹配,回车搜索)',
|
||||
onChange: (e: any) => {
|
||||
searchForm.value.platformOrderNo = e.target.value;
|
||||
},
|
||||
@@ -483,29 +527,40 @@ const formOptions = computed(() => ({
|
||||
},
|
||||
{
|
||||
component: 'RangePicker',
|
||||
defaultValue: defaultOrderTime.range,
|
||||
componentProps: {
|
||||
placeholder: ['下单开始时间', '下单结束时间'],
|
||||
allowClear: true,
|
||||
allowClear: false,
|
||||
showTime: { format: 'HH:mm:ss' },
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
style: { width: '100%' },
|
||||
onChange: (val: any) => {
|
||||
searchForm.value.startOrderTime = val && val[0]
|
||||
? (val[0] as dayjs.Dayjs).format('YYYY-MM-DD HH:mm:ss')
|
||||
: undefined;
|
||||
searchForm.value.endOrderTime = val && val[1]
|
||||
? (val[1] as dayjs.Dayjs).format('YYYY-MM-DD HH:mm:ss')
|
||||
: undefined;
|
||||
if (!val || !val[0] || !val[1]) {
|
||||
const d = buildDefaultOrderTimeRange();
|
||||
searchForm.value.startOrderTime = d.start;
|
||||
searchForm.value.endOrderTime = d.end;
|
||||
} else {
|
||||
searchForm.value.startOrderTime = (val[0] as dayjs.Dayjs).format(
|
||||
'YYYY-MM-DD HH:mm:ss',
|
||||
);
|
||||
searchForm.value.endOrderTime = (val[1] as dayjs.Dayjs).format(
|
||||
'YYYY-MM-DD HH:mm:ss',
|
||||
);
|
||||
}
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
},
|
||||
fieldName: 'orderTimeRange',
|
||||
label: '下单时间',
|
||||
rules: 'required',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 2,
|
||||
defaultValues: {
|
||||
orderTimeRange: defaultOrderTime.range,
|
||||
},
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
@@ -618,9 +673,9 @@ function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
// 初始化:保证表单与 searchForm 时间一致
|
||||
onMounted(async () => {
|
||||
// 店铺、订单状态、商品选择器改为点击时懒加载,不再预加载
|
||||
ensureOrderTimeFilters();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user