forked from gxwebsoft/mp-10550
refactor(order): 优化订单列表性能并移除冗余推荐人信息
- 移除经销商页面中的推荐人显示信息 - 将订单商品详情从单独接口请求改为直接从分页接口获取,避免N+1查询问题 - 添加normalizeOrderGoodsList函数实现订单商品数据结构标准化 - 统一门店名称文字颜色样式为灰色 - 简化支付工具类中的重复API端点调用
This commit is contained in:
@@ -108,7 +108,7 @@ const DealerIndex: React.FC = () => {
|
||||
<View className="text-sm" style={{
|
||||
color: 'rgba(255, 255, 255, 0.8)'
|
||||
}}>
|
||||
ID: {dealerUser.userId} | 推荐人: {dealerUser.refereeId || '无'}
|
||||
ID: {dealerUser.userId}
|
||||
</View>
|
||||
</View>
|
||||
<View className="text-right hidden">
|
||||
|
||||
@@ -181,7 +181,7 @@ const StoreIndex: React.FC = () => {
|
||||
{/* 门店信息 */}
|
||||
<View className="mx-4 -mt-6 rounded-xl p-4 relative z-10 bg-white">
|
||||
<View className="flex items-center justify-between mb-2">
|
||||
<Text className="font-semibold text-gray-800">当前门店</Text>
|
||||
<Text className="font-semibold text-gray-400">当前门店</Text>
|
||||
<View
|
||||
className="text-gray-400 text-sm"
|
||||
onClick={() => Taro.switchTab({url: '/pages/index/index'})}
|
||||
|
||||
@@ -51,7 +51,7 @@ export default function StoreOrders() {
|
||||
|
||||
<View className="px-3">
|
||||
<View className="bg-white rounded-lg p-3 mb-3">
|
||||
<Text className="text-sm text-gray-600">当前门店:</Text>
|
||||
<Text className="text-sm text-gray-400">当前门店:</Text>
|
||||
<Text className="text-base font-medium">
|
||||
{boundStoreId
|
||||
? (selectedStore?.id === boundStoreId ? (selectedStore?.name || `门店ID: ${boundStoreId}`) : `门店ID: ${boundStoreId}`)
|
||||
|
||||
@@ -84,6 +84,30 @@ interface OrderWithGoods extends ShopOrder {
|
||||
orderGoodsList?: ShopOrderGoods[];
|
||||
}
|
||||
|
||||
// 后端订单分页接口通常已返回 orderGoods(订单商品明细)。
|
||||
// 这里把各种可能的字段名做一次归一化,避免再为每个订单额外请求一次“订单商品”接口。
|
||||
const normalizeOrderGoodsList = (order: any): ShopOrderGoods[] => {
|
||||
const raw =
|
||||
order?.orderGoods ||
|
||||
order?.orderGoodsList ||
|
||||
order?.goodsList ||
|
||||
order?.goods ||
|
||||
[];
|
||||
if (!Array.isArray(raw)) return [];
|
||||
|
||||
return raw.map((g: any) => ({
|
||||
...g,
|
||||
goodsId: g?.goodsId ?? g?.itemId ?? g?.goods_id,
|
||||
skuId: g?.skuId ?? g?.sku_id,
|
||||
// 当接口只返回了最小字段时,用订单标题兜底,避免列表出现空白商品名
|
||||
goodsName: g?.goodsName ?? g?.goodsTitle ?? g?.title ?? g?.name ?? order?.title ?? '商品',
|
||||
image: g?.image ?? g?.goodsImage ?? g?.cover ?? g?.pic,
|
||||
spec: g?.spec ?? g?.specInfo ?? g?.spec_name,
|
||||
totalNum: g?.totalNum ?? g?.quantity ?? g?.num ?? g?.count,
|
||||
price: g?.price ?? g?.payPrice ?? g?.goodsPrice ?? g?.unitPrice
|
||||
}));
|
||||
};
|
||||
|
||||
interface OrderListProps {
|
||||
onReload?: () => void;
|
||||
searchParams?: ShopOrderParam;
|
||||
@@ -230,31 +254,11 @@ function OrderList(props: OrderListProps) {
|
||||
const res = await pageShopOrder(searchConditions);
|
||||
|
||||
if (res?.list && res?.list.length > 0) {
|
||||
// 批量获取订单商品信息,限制并发数量
|
||||
const batchSize = 3; // 限制并发数量为3
|
||||
const ordersWithGoods: OrderWithGoods[] = [];
|
||||
|
||||
for (let i = 0; i < res.list.length; i += batchSize) {
|
||||
const batch = res.list.slice(i, i + batchSize);
|
||||
const batchResults = await Promise.all(
|
||||
batch.map(async (order) => {
|
||||
try {
|
||||
const orderGoods = await listShopOrderGoods({orderId: order.orderId});
|
||||
return {
|
||||
// 订单分页接口已返回 orderGoods:直接读取并归一化,避免 N+1 请求导致列表加载慢
|
||||
const ordersWithGoods: OrderWithGoods[] = res.list.map((order: any) => ({
|
||||
...order,
|
||||
orderGoodsList: orderGoods || []
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取订单商品失败:', error);
|
||||
return {
|
||||
...order,
|
||||
orderGoodsList: []
|
||||
};
|
||||
}
|
||||
})
|
||||
);
|
||||
ordersWithGoods.push(...batchResults);
|
||||
}
|
||||
orderGoodsList: normalizeOrderGoodsList(order)
|
||||
}));
|
||||
|
||||
// 使用函数式更新避免依赖 list
|
||||
setList(prevList => {
|
||||
|
||||
@@ -191,9 +191,8 @@ export class PaymentHandler {
|
||||
// 后端字段可能叫 dealerId 或 storeId,这里都带上,服务端忽略未知字段即可。
|
||||
// 这里做一次路径兼容(camel vs kebab),避免接口路径不一致导致整单失败。
|
||||
const list = await this.listByCompatEndpoint<ShopStoreRider>(
|
||||
['/shop/shop-store-rider', '/shop/shop-store-rider'],
|
||||
['/shop/shop-store-rider'],
|
||||
{
|
||||
dealerId: storeId,
|
||||
storeId: storeId,
|
||||
status: 1
|
||||
}
|
||||
@@ -224,7 +223,7 @@ export class PaymentHandler {
|
||||
private static async getWarehouses(): Promise<ShopWarehouse[]> {
|
||||
if (this.warehousesCache) return this.warehousesCache;
|
||||
const list = await this.listByCompatEndpoint<ShopWarehouse>(
|
||||
['/shop/shop-warehouse', '/shop/shop-warehouse'],
|
||||
['/shop/shop-warehouse'],
|
||||
{}
|
||||
);
|
||||
const usable = (list || []).filter(w => w?.isDelete !== 1 && (w.status === undefined || w.status === 1));
|
||||
|
||||
Reference in New Issue
Block a user