orderStatus.js
2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* @Date: 2026-02-14 11:04:03
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-02-14 11:08:09
* @FilePath: /manulife-weapp/src/config/constants/orderStatus.js
* @Description: 订单状态常量
*/
/**
* 订单状态常量
*
* @description 统一管理订单状态值,避免魔法数字
* @module config/constants
* @author Claude Code
* @created 2026-02-14
*/
/**
* 订单状态常量(API 返回)
*
* @description 前端使用的状态值(与后端 API 一致)
* @constant {string}
*/
export const ORDER_STATUS = {
/** 待处理 - 对应 API 值 '3' */
PENDING: '3',
/** 处理中 - 对应 API 值 '5' */
PROCESSING: '5',
/** 已生成 - 对应 API 值 '7' */
GENERATED: '7',
/** 已查看 - 对应 API 值 '9' */
VIEWED: '9'
}
/**
* 状态映射关系(API 状态 → 前端状态)
*
* @description 用于状态转换的映射表
* @constant {Object<string, string>}
*/
export const ORDER_STATUS_MAP = {
[ORDER_STATUS.PENDING]: 'pending',
[ORDER_STATUS.PROCESSING]: 'processing',
[ORDER_STATUS.GENERATED]: 'generated',
[ORDER_STATUS.VIEWED]: 'viewed'
}
/**
* 状态文本映射
*
* @description 状态对应的显示文本
* @constant {Object<string, string>}
*/
export const ORDER_STATUS_TEXT = {
pending: '待处理',
processing: '处理中',
generated: '已生成',
viewed: '已查看'
}
/**
* 获取前端状态值
*
* @description 将 API 返回的状态值映射为前端使用的状态
* @param {string} apiStatus - API 返回的状态值('3'/'5'/'7'/'9')
* @returns {string} 前端状态值('pending'/'processing'/'generated'/'viewed')
*
* @example
* const frontendStatus = mapOrderStatus('7') // 返回: 'generated'
*/
export function mapOrderStatus(apiStatus) {
return ORDER_STATUS_MAP[apiStatus] || ORDER_STATUS_MAP[ORDER_STATUS.PENDING]
}
/**
* 获取状态显示文本
*
* @description 获取状态对应的显示文本
* @param {string} status - 前端状态值
* @returns {string} 状态显示文本
*
* @example
* const text = getStatusText('processing') // 返回: '处理中'
*/
export function getStatusText(status) {
return ORDER_STATUS_TEXT[status] || '待处理'
}
/**
* 验证状态值是否有效
*
* @description 检查状态值是否为有效的订单状态
* @param {string} status - 待验证的状态值
* @returns {boolean} 是否有效
*
* @example
* isValidStatus('pending') // 返回: true
* isValidStatus('invalid') // 返回: false
*/
export function isValidStatus(status) {
return Object.values(ORDER_STATUS).includes(status)
}