Explorar o código

refactor(订单类型): 简化订单类型定义并移除严格模式

yz hai 2 semanas
pai
achega
dc77a7699c

+ 1 - 1
src/api/types/order.d.ts

@@ -4,7 +4,7 @@ import { AxiosResponse } from 'axios';
 /**
  * 订单类型枚举
  */
-export type OrderType = 'PURCHASE' | 'SALES' | 'RETURN';
+export type OrderType = 0 | 1  // 0: 未知类型, 1: 普通订单;
 
 /**
  * 订单状态枚举

+ 3 - 5
src/components/order-form/types.d.ts

@@ -7,12 +7,10 @@
  * 订单类型枚举
  */
 export enum OrderType {
+  /** 未知类型 */
+  UNKNOWN = 0,
   /** 普通订单 */
-  NORMAL = 1,
-  /** 紧急订单 */
-  URGENT = 2,
-  /** 预订订单 */
-  RESERVATION = 3
+  NORMAL = 1
 }
 
 /**

+ 1 - 1
src/constants/material.js

@@ -29,7 +29,7 @@
  * @typedef {Object} OrderFormModel
  * @property {string} id - 订单ID
  * @property {string} orderNo - 订单编号
- * @property {number} orderType - 订单类型:1普通 2紧急 3预订
+ * @property {number} orderType - 订单类型:0未知 1普通
  * @property {number} orderStatus - 订单状态:0草稿 1待审核 2已审核 3已发货 4已完成 5已取消
  * @property {string} customerName - 客户名称
  * @property {string} customerContact - 客户联系方式

+ 30 - 38
src/constants/order.js

@@ -6,16 +6,13 @@
 /**
  * 订单类型枚举
  * @readonly
- * @enum {number}
  */
-export const ORDER_TYPES = {
+export const ORDER_TYPES = Object.freeze({
+  /** 未知类型 */
+  UNKNOWN: 0,
   /** 普通订单 */
-  NORMAL: 1,
-  /** 紧急订单 */
-  URGENT: 2,
-  /** 预订订单 */
-  RESERVATION: 3
-}
+  NORMAL: 1
+})
 
 /**
  * 订单类型枚举(订单表单模块兼容性别名)
@@ -27,9 +24,8 @@ export const OrderType = ORDER_TYPES
 /**
  * 订单状态枚举
  * @readonly
- * @enum {number}
  */
-export const ORDER_STATUS = {
+export const ORDER_STATUS = Object.freeze({
   /** 草稿 */
   DRAFT: 0,
   /** 已提交/待审核 */
@@ -42,7 +38,7 @@ export const ORDER_STATUS = {
   COMPLETED: 4,
   /** 已取消 */
   CANCELLED: 5
-}
+})
 
 /**
  * 订单状态枚举(订单表单模块兼容性别名)
@@ -68,7 +64,7 @@ export const OrderStatus = {
  * 订单明细状态枚举
  * @readonly
  */
-export const ORDER_ITEM_STATUS = {
+export const ORDER_ITEM_STATUS = Object.freeze({
   /** 未确认 */
   UNCONFIRMED: 0,
   /** 已确认 */
@@ -77,7 +73,7 @@ export const ORDER_ITEM_STATUS = {
   PARTIAL_SHIPPED: 2,
   /** 已完成 */
   COMPLETED: 3
-}
+})
 
 /**
  * 物料明细状态枚举(订单表单模块兼容性别名)
@@ -104,20 +100,15 @@ export const MaterialDetailDataSource = {
  * @type {Record<number, {readonly label: string, readonly type: string, readonly color: string}>}
  */
 export const ORDER_TYPE_CONFIG = {
+  [ORDER_TYPES.UNKNOWN]: {
+    label: '未知类型',
+    type: 'info',
+    color: '#909399'
+  },
   [ORDER_TYPES.NORMAL]: {
     label: '普通订单',
     type: 'primary',
     color: '#409EFF'
-  },
-  [ORDER_TYPES.URGENT]: {
-    label: '紧急订单',
-    type: 'danger',
-    color: '#F56C6C'
-  },
-  [ORDER_TYPES.RESERVATION]: {
-    label: '预订订单',
-    type: 'warning',
-    color: '#E6A23C'
   }
 }
 
@@ -190,16 +181,17 @@ export const ORDER_ITEM_STATUS_CONFIG = {
 /**
  * 订单类型选项数据
  * @readonly
- * @type {ReadonlyArray<{readonly label: '普通订单', readonly value: 1}>}
+ * @type {ReadonlyArray<{readonly label: string, readonly value: typeof ORDER_TYPES[keyof typeof ORDER_TYPES]}>}
  */
 export const ORDER_TYPE_OPTIONS = [
+  { label: '未知类型', value: ORDER_TYPES.UNKNOWN },
   { label: '普通订单', value: ORDER_TYPES.NORMAL }
 ]
 
 /**
  * 订单状态选项数据
  * @readonly
- * @type {ReadonlyArray<{readonly label: string, readonly value: 0 | 1 | 2 | 3 | 4 | 5}>}
+ * @type {ReadonlyArray<{readonly label: string, readonly value:typeof ORDER_STATUS[keyof typeof ORDER_STATUS]}>}
  */
 export const ORDER_STATUS_OPTIONS = [
   { label: '草稿', value: ORDER_STATUS.DRAFT },
@@ -213,7 +205,7 @@ export const ORDER_STATUS_OPTIONS = [
 /**
  * 订单明细状态选项数据
  * @readonly
- * @type {ReadonlyArray<{readonly label: string, readonly value: 0 | 1 | 2 | 3}>}
+ * @type {ReadonlyArray<{readonly label: string, readonly value: typeof ORDER_ITEM_STATUS[keyof typeof ORDER_ITEM_STATUS]}>}
  */
 export const ORDER_ITEM_STATUS_OPTIONS = [
   { label: '未确认', value: ORDER_ITEM_STATUS.UNCONFIRMED },
@@ -225,7 +217,7 @@ export const ORDER_ITEM_STATUS_OPTIONS = [
 /**
  * 物料明细状态选项列表(订单表单模块兼容性别名)
  * @readonly
- * @type {Array<{readonly value: number, readonly label: string}>}
+ * @type {ReadonlyArray<{readonly label: string, readonly value: number}>}
  */
 export const MATERIAL_DETAIL_STATUS_OPTIONS = ORDER_ITEM_STATUS_OPTIONS
 
@@ -257,8 +249,8 @@ export function getOrderTypeLabel(orderType) {
 
 /**
  * 获取订单类型Element UI标签类型
- * @param {1} orderType - 订单类型值
- * @returns {'primary' | 'info'} Element UI标签类型
+ * @param {typeof ORDER_TYPES[keyof typeof ORDER_TYPES]} orderType - 订单类型值
+ * @returns {string} Element UI标签类型
  */
 export function getOrderTypeTagType(orderType) {
   const config = ORDER_TYPE_CONFIG[orderType]
@@ -267,7 +259,7 @@ export function getOrderTypeTagType(orderType) {
 
 /**
  * 获取订单类型颜色
- * @param {1} orderType - 订单类型值
+ * @param {typeof ORDER_TYPES[keyof typeof ORDER_TYPES]} orderType - 订单类型值
  * @returns {string} 十六进制颜色值
  */
 export function getOrderTypeColor(orderType) {
@@ -277,7 +269,7 @@ export function getOrderTypeColor(orderType) {
 
 /**
  * 获取订单状态标签
- * @param {0 | 1 | 2 | 3 | 4 | 5} status - 订单状态值
+ * @param {typeof ORDER_STATUS[keyof typeof ORDER_STATUS]} status - 订单状态值
  * @returns {string} 订单状态标签
  */
 export function getOrderStatusLabel(status) {
@@ -287,8 +279,8 @@ export function getOrderStatusLabel(status) {
 
 /**
  * 获取订单状态Element UI标签类型
- * @param {0 | 1 | 2 | 3 | 4 | 5} status - 订单状态值
- * @returns {'info' | 'warning' | 'primary' | 'success' | 'danger'} Element UI标签类型
+ * @param {typeof ORDER_STATUS[keyof typeof ORDER_STATUS]} status - 订单状态值
+ * @returns {string} Element UI标签类型
  */
 export function getOrderStatusTagType(status) {
   const config = ORDER_STATUS_CONFIG[status]
@@ -297,7 +289,7 @@ export function getOrderStatusTagType(status) {
 
 /**
  * 获取订单状态颜色
- * @param {0 | 1 | 2 | 3 | 4 | 5} status - 订单状态值
+ * @param {typeof ORDER_STATUS[keyof typeof ORDER_STATUS]} status - 订单状态值
  * @returns {string} 十六进制颜色值
  */
 export function getOrderStatusColor(status) {
@@ -307,7 +299,7 @@ export function getOrderStatusColor(status) {
 
 /**
  * 获取订单明细状态标签
- * @param {0 | 1 | 2 | 3} itemStatus - 订单明细状态值
+ * @param {typeof ORDER_ITEM_STATUS[keyof typeof ORDER_ITEM_STATUS]} itemStatus - 订单明细状态值
  * @returns {string} 订单明细状态标签
  */
 export function getOrderItemStatusLabel(itemStatus) {
@@ -318,7 +310,7 @@ export function getOrderItemStatusLabel(itemStatus) {
 /**
  * 获取订单明细状态Element UI标签类型
  * @param {typeof ORDER_ITEM_STATUS[keyof typeof ORDER_ITEM_STATUS]} itemStatus - 订单明细状态值
- * @returns {'warning' | 'primary' | 'success' | 'info'} Element UI标签类型
+ * @returns {string} Element UI标签类型
  */
 export function getOrderItemStatusTagType(itemStatus) {
   const config = ORDER_ITEM_STATUS_CONFIG[itemStatus]
@@ -337,7 +329,7 @@ export function getOrderItemStatusColor(itemStatus) {
 
 /**
  * 检查订单是否可以编辑
- * @param {0 | 1 | 2 | 3 | 4 | 5} status - 订单状态值
+ * @param {typeof ORDER_STATUS[keyof typeof ORDER_STATUS]} status - 订单状态值
  * @returns {boolean} 是否可以编辑
  */
 export function isOrderEditable(status) {
@@ -346,7 +338,7 @@ export function isOrderEditable(status) {
 
 /**
  * 检查订单是否可以取消
- * @param {0 | 1 | 2 | 3 | 4 | 5} status - 订单状态值
+ * @param {typeof ORDER_STATUS[keyof typeof ORDER_STATUS]} status - 订单状态值
  * @returns {boolean} 是否可以取消
  */
 export function isOrderCancellable(status) {

+ 2 - 2
src/mixins/order/orderFormMixin.js

@@ -173,13 +173,13 @@ export default {
 
       /**
        * 订单类型选项
-       * @type {Array<{label: string, value: number}>}
+       * @type {ReadonlyArray<{label: string, value: typeof ORDER_TYPES[keyof typeof ORDER_TYPES]}>}
        */
       orderTypeOptions: ORDER_TYPE_OPTIONS,
 
       /**
        * 订单状态选项
-       * @type {Array<{label: string, value: number}>}
+       * @type {ReadonlyArray<{label: string, value: number}>}
        */
       orderStatusOptions: ORDER_STATUS_OPTIONS
     }

+ 0 - 1
tsconfig.json

@@ -11,7 +11,6 @@
     "skipLibCheck": true,
     "esModuleInterop": true,
     "allowSyntheticDefaultImports": true,
-    "strict": true,
     "forceConsistentCasingInFileNames": true,
     "module": "esnext",
     "moduleResolution": "node",