fix: 修复前端若干类型报错

This commit is contained in:
ah--desktop
2026-03-31 23:44:37 +08:00
parent 7f5803ddda
commit 6b434fbf63
38 changed files with 383 additions and 1981 deletions
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
import type { OrderStatusVO } from '#/api/ecommerce/order-status/types';
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
@@ -12,12 +13,8 @@ import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteOrderApi,
getOrderPageApi,
} from '#/api/ecommerce/order';
import { deleteOrderApi, getOrderPageApi } from '#/api/ecommerce/order';
import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status';
import type { OrderStatusVO } from '#/api/ecommerce/order-status/types';
import { getShopPageApi } from '#/api/ecommerce/shop';
import OrderFormModal from './components/OrderFormModal.vue';
@@ -37,7 +34,7 @@ const shopPageSize = 20;
const shopTotal = ref(0);
const shopLoading = ref(false);
const shopSearchKeyword = ref('');
let shopSearchTimer: ReturnType<typeof setTimeout> | null = null;
let shopSearchTimer: null | ReturnType<typeof setTimeout> = null;
// 订单状态选项
const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
@@ -50,7 +47,7 @@ const searchForm = ref({
});
// 当前排序状态
const currentSort = ref<{ field: string; order: 'asc' | 'desc' } | null>(null);
const currentSort = ref<null | { field: string; order: 'asc' | 'desc' }>(null);
// 加载店铺列表(支持分页)
async function fetchShops(page = 1, append = false) {
@@ -63,17 +60,18 @@ async function fetchShops(page = 1, append = false) {
filters: shopSearchKeyword.value ? { name: shopSearchKeyword.value } : {},
};
const data = await getShopPageApi(params);
if (append) {
shopOptions.value = [...shopOptions.value, ...data.records.map((shop: ShopVO.Info) => ({
label: shop.name,
value: shop.id,
}))];
} else {
shopOptions.value = data.records.map((shop: ShopVO.Info) => ({
label: shop.name,
value: shop.id,
}));
}
shopOptions.value = append
? [
...shopOptions.value,
...data.records.map((shop: ShopVO.Info) => ({
label: shop.name,
value: shop.id,
})),
]
: data.records.map((shop: ShopVO.Info) => ({
label: shop.name,
value: shop.id,
}));
shopTotal.value = data.total;
shopPage.value = page;
} catch (error) {
@@ -182,11 +180,6 @@ const gridOptions: VxeGridProps<any> = {
multiple: false,
orders: ['desc', 'asc'],
},
sortChange: ({ field, order }) => {
// 保存排序状态并触发搜索
currentSort.value = { field, order: order || 'desc' };
gridApi?.reload();
},
toolbarConfig: {
custom: true,
refresh: true,
@@ -226,7 +219,10 @@ const gridOptions: VxeGridProps<any> = {
const searchParams = form || {};
// 合并表单值和本地状态
const filters = {
platformOrderNo: searchParams.platformOrderNo || searchForm.value.platformOrderNo || undefined,
platformOrderNo:
searchParams.platformOrderNo ||
searchForm.value.platformOrderNo ||
undefined,
shopId: searchParams.shopId ?? searchForm.value.shopId,
statusId: searchParams.statusId ?? searchForm.value.statusId,
};
@@ -237,7 +233,12 @@ const gridOptions: VxeGridProps<any> = {
};
// 处理排序参数
if (currentSort.value) {
params.sorts = [{ field: currentSort.value.field, order: currentSort.value.order }];
params.sorts = [
{
field: currentSort.value.field,
order: currentSort.value.order,
},
];
}
const data = await getOrderPageApi(params);
return {
@@ -260,13 +261,14 @@ const gridOptions: VxeGridProps<any> = {
};
// 搜索表单配置
const gridReloadRef = ref<(() => void) | null>(null);
const formOptions = computed(() => ({
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入平台订单号(回车搜索)',
onPressEnter: () => gridApi?.reload(),
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'platformOrderNo',
label: '平台订单号',
@@ -283,7 +285,7 @@ const formOptions = computed(() => ({
onPopupScroll: handleShopPopupScroll,
onChange: (val: any) => {
searchForm.value.shopId = val;
gridApi?.reload();
gridReloadRef.value?.();
},
loading: shopLoading,
dropdownMenuColumnStyle: { maxHeight: '300px', overflow: 'auto' },
@@ -299,7 +301,7 @@ const formOptions = computed(() => ({
allowClear: true,
onChange: (val: any) => {
searchForm.value.statusId = val;
gridApi?.reload();
gridReloadRef.value?.();
},
},
fieldName: 'statusId',
@@ -318,6 +320,17 @@ function refreshTable() {
}
}
function handleSortChange({
field,
order,
}: {
field?: string;
order?: 'asc' | 'desc' | null;
}) {
currentSort.value = field ? { field, order: order || 'desc' } : null;
gridReloadRef.value?.();
}
// 获取店铺选项(首次加载)
async function fetchShopOptions() {
await fetchShops(1, false);
@@ -343,6 +356,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
showSearchForm: true,
tableTitle: '订单管理',
});
gridReloadRef.value = () => gridApi.reload();
// 处理添加订单
function handleAdd() {
@@ -381,7 +395,7 @@ onMounted(async () => {
<template>
<Page auto-content-height>
<!-- VbenVxeGrid 表格 -->
<Grid :loading="loading">
<Grid :loading="loading" @sort-change="handleSortChange">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
@@ -417,10 +431,7 @@ onMounted(async () => {
<!-- 订单状态列 -->
<template #orderStatus="{ row }: { row: any }">
<Tag
:color="row.orderStatus?.color || 'blue'"
type="outline"
>
<Tag :color="row.orderStatus?.color || 'blue'" type="outline">
{{ row.statusName || '未知状态' }}
</Tag>
</template>