feat(wms):将首页的枚举值去掉,统一合并到 constants 里,更聚焦点

pull/345/head
YunaiV 2026-05-17 18:17:30 +08:00
parent 84b91c6795
commit 3da4a3f417
6 changed files with 106 additions and 66 deletions

View File

@ -1,19 +1,45 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { WmsHomeStatisticsApi } from '#/api/wms/home';
import { ref } from 'vue'; import { ref } from 'vue';
import { DICT_TYPE } from '@vben/constants'; import { DICT_TYPE } from '@vben/constants';
import { getDictLabel } from '@vben/hooks'; import { getDictLabel } from '@vben/hooks';
import { getOrderSummary } from '#/api/wms/home'; import { getOrderSummary } from '#/api/wms/home';
import { OrderStatusEnum } from '#/views/wms/utils/constants'; import { OrderStatusEnum, OrderTypeEnum } from '#/views/wms/utils/constants';
defineOptions({ name: 'WmsHomeOrderSummaryCards' }); defineOptions({ name: 'WmsHomeOrderSummaryCards' });
const orderDefinitions = [ interface OrderSummaryItem {
{ color: '#2f7df6', title: '入库', type: 1 }, color: string;
{ color: '#18a058', title: '出库', type: 2 }, statuses?: WmsHomeStatisticsApi.OrderStatus[];
{ color: '#f59e0b', title: '移库', type: 3 }, title: string;
{ color: '#7c3aed', title: '盘库', type: 4 }, total?: number;
type: number;
}
const orderDefinitions: OrderSummaryItem[] = [
{
color: '#2f7df6',
title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.RECEIPT).replace(/单$/, ''),
type: OrderTypeEnum.RECEIPT,
},
{
color: '#18a058',
title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.SHIPMENT).replace(/单$/, ''),
type: OrderTypeEnum.SHIPMENT,
},
{
color: '#f59e0b',
title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.MOVEMENT).replace(/单$/, ''),
type: OrderTypeEnum.MOVEMENT,
},
{
color: '#7c3aed',
title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.CHECK).replace(/单$/, ''),
type: OrderTypeEnum.CHECK,
},
]; ];
const statusList = [ const statusList = [
@ -23,12 +49,10 @@ const statusList = [
]; ];
const loading = ref(false); const loading = ref(false);
const summaryList = ref<any[]>( const summaryList = ref<OrderSummaryItem[]>(orderDefinitions);
orderDefinitions.map((item) => ({ ...item, statuses: [], total: 0 })),
);
function getStatusCount(item: any, status: number) { function getStatusCount(item: OrderSummaryItem, status: number) {
return item.statuses?.find((row: any) => row.status === status)?.count || 0; return item.statuses?.find((row) => row.status === status)?.count;
} }
async function load(warehouseId?: number) { async function load(warehouseId?: number) {
@ -39,11 +63,8 @@ async function load(warehouseId?: number) {
const summary = data.find((item) => item.type === definition.type); const summary = data.find((item) => item.type === definition.type);
return { return {
...definition, ...definition,
title: statuses: summary?.statuses,
getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, definition.type)?.replace(/单$/, '') || total: summary?.total,
definition.title,
statuses: summary?.statuses || [],
total: summary?.total || 0,
}; };
}); });
} finally { } finally {

View File

@ -4,6 +4,8 @@ import { DICT_TYPE } from '@vben/constants';
import { getDictLabel } from '@vben/hooks'; import { getDictLabel } from '@vben/hooks';
import { formatDate } from '@vben/utils'; import { formatDate } from '@vben/utils';
import { OrderTypeEnum } from '#/views/wms/utils/constants';
interface OrderDefinition { interface OrderDefinition {
color: string; color: string;
title: string; title: string;
@ -14,41 +16,28 @@ interface OrderDefinition {
type: number; type: number;
} }
const OrderTypeEnum = {
CHECK: 4,
MOVEMENT: 3,
RECEIPT: 1,
SHIPMENT: 2,
} as const;
/** 获取 WMS 单据类型标题,用于消除字典里的“单”后缀 */
function getOrderTypeTitle(type: number, defaultTitle: string) {
const label = getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, type) || defaultTitle;
return label.endsWith('单') ? label.slice(0, -1) : label;
}
const orderDefinitions: OrderDefinition[] = [ const orderDefinitions: OrderDefinition[] = [
{ {
color: '#2f7df6', color: '#2f7df6',
title: getOrderTypeTitle(OrderTypeEnum.RECEIPT, '入库'), title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.RECEIPT).replace(/单$/, ''),
trendField: 'receiptCount', trendField: 'receiptCount',
type: OrderTypeEnum.RECEIPT, type: OrderTypeEnum.RECEIPT,
}, },
{ {
color: '#18a058', color: '#18a058',
title: getOrderTypeTitle(OrderTypeEnum.SHIPMENT, '出库'), title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.SHIPMENT).replace(/单$/, ''),
trendField: 'shipmentCount', trendField: 'shipmentCount',
type: OrderTypeEnum.SHIPMENT, type: OrderTypeEnum.SHIPMENT,
}, },
{ {
color: '#f59e0b', color: '#f59e0b',
title: getOrderTypeTitle(OrderTypeEnum.MOVEMENT, '移库'), title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.MOVEMENT).replace(/单$/, ''),
trendField: 'movementCount', trendField: 'movementCount',
type: OrderTypeEnum.MOVEMENT, type: OrderTypeEnum.MOVEMENT,
}, },
{ {
color: '#7c3aed', color: '#7c3aed',
title: getOrderTypeTitle(OrderTypeEnum.CHECK, '盘库'), title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.CHECK).replace(/单$/, ''),
trendField: 'checkCount', trendField: 'checkCount',
type: OrderTypeEnum.CHECK, type: OrderTypeEnum.CHECK,
}, },

View File

@ -5,6 +5,16 @@ export const OrderStatusEnum = {
CANCELED: 5, // 已作废 CANCELED: 5, // 已作废
} as const; } as const;
/** 单据类型枚举 */
export const OrderTypeEnum = {
RECEIPT: 1, // 入库
SHIPMENT: 2, // 出库
MOVEMENT: 3, // 移库
CHECK: 4, // 盘库
} as const;
export type OrderType = (typeof OrderTypeEnum)[keyof typeof OrderTypeEnum];
/** 可修改的单据状态 */ /** 可修改的单据状态 */
export const OrderUpdateStatusList: number[] = [OrderStatusEnum.PREPARE]; export const OrderUpdateStatusList: number[] = [OrderStatusEnum.PREPARE];

View File

@ -1,19 +1,45 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { WmsHomeStatisticsApi } from '#/api/wms/home';
import { ref } from 'vue'; import { ref } from 'vue';
import { DICT_TYPE } from '@vben/constants'; import { DICT_TYPE } from '@vben/constants';
import { getDictLabel } from '@vben/hooks'; import { getDictLabel } from '@vben/hooks';
import { getOrderSummary } from '#/api/wms/home'; import { getOrderSummary } from '#/api/wms/home';
import { OrderStatusEnum } from '#/views/wms/utils/constants'; import { OrderStatusEnum, OrderTypeEnum } from '#/views/wms/utils/constants';
defineOptions({ name: 'WmsHomeOrderSummaryCards' }); defineOptions({ name: 'WmsHomeOrderSummaryCards' });
const orderDefinitions = [ interface OrderSummaryItem {
{ color: '#2f7df6', title: '入库', type: 1 }, color: string;
{ color: '#18a058', title: '出库', type: 2 }, statuses?: WmsHomeStatisticsApi.OrderStatus[];
{ color: '#f59e0b', title: '移库', type: 3 }, title: string;
{ color: '#7c3aed', title: '盘库', type: 4 }, total?: number;
type: number;
}
const orderDefinitions: OrderSummaryItem[] = [
{
color: '#2f7df6',
title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.RECEIPT).replace(/单$/, ''),
type: OrderTypeEnum.RECEIPT,
},
{
color: '#18a058',
title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.SHIPMENT).replace(/单$/, ''),
type: OrderTypeEnum.SHIPMENT,
},
{
color: '#f59e0b',
title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.MOVEMENT).replace(/单$/, ''),
type: OrderTypeEnum.MOVEMENT,
},
{
color: '#7c3aed',
title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.CHECK).replace(/单$/, ''),
type: OrderTypeEnum.CHECK,
},
]; ];
const statusList = [ const statusList = [
@ -23,12 +49,10 @@ const statusList = [
]; ];
const loading = ref(false); const loading = ref(false);
const summaryList = ref<any[]>( const summaryList = ref<OrderSummaryItem[]>(orderDefinitions);
orderDefinitions.map((item) => ({ ...item, statuses: [], total: 0 })),
);
function getStatusCount(item: any, status: number) { function getStatusCount(item: OrderSummaryItem, status: number) {
return item.statuses?.find((row: any) => row.status === status)?.count || 0; return item.statuses?.find((row) => row.status === status)?.count;
} }
async function load(warehouseId?: number) { async function load(warehouseId?: number) {
@ -39,11 +63,8 @@ async function load(warehouseId?: number) {
const summary = data.find((item) => item.type === definition.type); const summary = data.find((item) => item.type === definition.type);
return { return {
...definition, ...definition,
title: statuses: summary?.statuses,
getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, definition.type)?.replace(/单$/, '') || total: summary?.total,
definition.title,
statuses: summary?.statuses || [],
total: summary?.total || 0,
}; };
}); });
} finally { } finally {

View File

@ -4,6 +4,8 @@ import { DICT_TYPE } from '@vben/constants';
import { getDictLabel } from '@vben/hooks'; import { getDictLabel } from '@vben/hooks';
import { formatDate } from '@vben/utils'; import { formatDate } from '@vben/utils';
import { OrderTypeEnum } from '#/views/wms/utils/constants';
interface OrderDefinition { interface OrderDefinition {
color: string; color: string;
title: string; title: string;
@ -14,41 +16,28 @@ interface OrderDefinition {
type: number; type: number;
} }
const OrderTypeEnum = {
CHECK: 4,
MOVEMENT: 3,
RECEIPT: 1,
SHIPMENT: 2,
} as const;
/** 获取 WMS 单据类型标题,用于消除字典里的“单”后缀 */
function getOrderTypeTitle(type: number, defaultTitle: string) {
const label = getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, type) || defaultTitle;
return label.endsWith('单') ? label.slice(0, -1) : label;
}
const orderDefinitions: OrderDefinition[] = [ const orderDefinitions: OrderDefinition[] = [
{ {
color: '#2f7df6', color: '#2f7df6',
title: getOrderTypeTitle(OrderTypeEnum.RECEIPT, '入库'), title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.RECEIPT).replace(/单$/, ''),
trendField: 'receiptCount', trendField: 'receiptCount',
type: OrderTypeEnum.RECEIPT, type: OrderTypeEnum.RECEIPT,
}, },
{ {
color: '#18a058', color: '#18a058',
title: getOrderTypeTitle(OrderTypeEnum.SHIPMENT, '出库'), title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.SHIPMENT).replace(/单$/, ''),
trendField: 'shipmentCount', trendField: 'shipmentCount',
type: OrderTypeEnum.SHIPMENT, type: OrderTypeEnum.SHIPMENT,
}, },
{ {
color: '#f59e0b', color: '#f59e0b',
title: getOrderTypeTitle(OrderTypeEnum.MOVEMENT, '移库'), title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.MOVEMENT).replace(/单$/, ''),
trendField: 'movementCount', trendField: 'movementCount',
type: OrderTypeEnum.MOVEMENT, type: OrderTypeEnum.MOVEMENT,
}, },
{ {
color: '#7c3aed', color: '#7c3aed',
title: getOrderTypeTitle(OrderTypeEnum.CHECK, '盘库'), title: getDictLabel(DICT_TYPE.WMS_ORDER_TYPE, OrderTypeEnum.CHECK).replace(/单$/, ''),
trendField: 'checkCount', trendField: 'checkCount',
type: OrderTypeEnum.CHECK, type: OrderTypeEnum.CHECK,
}, },

View File

@ -5,6 +5,16 @@ export const OrderStatusEnum = {
CANCELED: 5, // 已作废 CANCELED: 5, // 已作废
} as const; } as const;
/** 单据类型枚举 */
export const OrderTypeEnum = {
RECEIPT: 1, // 入库
SHIPMENT: 2, // 出库
MOVEMENT: 3, // 移库
CHECK: 4, // 盘库
} as const;
export type OrderType = (typeof OrderTypeEnum)[keyof typeof OrderTypeEnum];
/** 可修改的单据状态 */ /** 可修改的单据状态 */
export const OrderUpdateStatusList: number[] = [OrderStatusEnum.PREPARE]; export const OrderUpdateStatusList: number[] = [OrderStatusEnum.PREPARE];