Procházet zdrojové kódy

✨ feat(schema): 扩展订单支付类型以支持微信支付

- 将支付类型(payType)的最大值从3更新为4
- 在支付类型描述中添加"4微信支付"选项
- 更新OrderSchema、CreateOrderDto和UpdateOrderDto中的相关验证规则

♻️ refactor(utils): 优化axios请求头处理逻辑

- 重构hc.ts中的axiosFetch函数,添加全局axios默认头处理
- 支持从axios.defaults.headers.common自动注入Authorization等全局头信息
- 改进headers参数处理,同时支持Headers对象和普通对象格式
- 增强类型安全性和代码可维护性
yourname před 2 dny
rodič
revize
329af75ad1

+ 6 - 6
packages/orders-module-mt/src/schemas/order.mt.schema.ts

@@ -115,8 +115,8 @@ export const OrderSchema = z.object({
     description: '订单类型 1实物订单 2虚拟订单',
     example: 1
   }),
-  payType: z.coerce.number().int().min(0, '支付类型最小为0').max(3, '支付类型最大为3').default(0).openapi({
-    description: '支付类型1积分2礼券3额度支付',
+  payType: z.coerce.number().int().min(0, '支付类型最小为0').max(4, '支付类型最大为4').default(0).openapi({
+    description: '支付类型1积分2礼券3额度支付4微信支付',
     example: 1
   }),
   payState: z.coerce.number().int().min(0, '支付状态最小为0').max(5, '支付状态最大为5').default(0).openapi({
@@ -340,8 +340,8 @@ export const CreateOrderDto = z.object({
     description: '订单类型 1实物订单 2虚拟订单',
     example: 1
   }),
-  payType: z.coerce.number().int().min(0, '支付类型最小为0').max(3, '支付类型最大为3').default(0).openapi({
-    description: '支付类型1积分2礼券3额度支付',
+  payType: z.coerce.number().int().min(0, '支付类型最小为0').max(4, '支付类型最大为4').default(0).openapi({
+    description: '支付类型1积分2礼券3额度支付4微信支付',
     example: 1
   }),
   payState: z.coerce.number().int().min(0, '支付状态最小为0').max(5, '支付状态最大为5').default(0).openapi({
@@ -496,8 +496,8 @@ export const UpdateOrderDto = z.object({
     description: '订单类型 1实物订单 2虚拟订单',
     example: 1
   }),
-  payType: z.coerce.number().int().min(0, '支付类型最小为0').max(3, '支付类型最大为3').optional().openapi({
-    description: '支付类型1积分2礼券3额度支付',
+  payType: z.coerce.number().int().min(0, '支付类型最小为0').max(4, '支付类型最大为4').optional().openapi({
+    description: '支付类型1积分2礼券3额度支付4微信支付',
     example: 1
   }),
   payState: z.coerce.number().int().min(0, '支付状态最小为0').max(5, '支付状态最大为5').optional().openapi({

+ 23 - 4
packages/shared-ui-components/src/utils/hc.ts

@@ -6,10 +6,29 @@ import type { Hono } from 'hono'
 const axiosFetch = async (url: RequestInfo | URL, init?: RequestInit) => {
   const requestHeaders: Record<string, string> = {};
 
-  if (init?.headers instanceof Headers) {
-    init.headers.forEach((value, key) => {
-      requestHeaders[key] = value;
-    })
+  // 添加全局axios默认头(包括Authorization)
+  if (axios.defaults.headers.common) {
+    Object.entries(axios.defaults.headers.common).forEach(([key, value]) => {
+      if (value !== undefined && value !== null) {
+        requestHeaders[key] = value.toString();
+      }
+    });
+  }
+
+  // 处理传入的headers
+  if (init?.headers) {
+    if (init.headers instanceof Headers) {
+      init.headers.forEach((value, key) => {
+        requestHeaders[key] = value;
+      });
+    } else if (typeof init.headers === 'object') {
+      // 处理普通对象格式的headers
+      Object.entries(init.headers).forEach(([key, value]) => {
+        if (value !== undefined && value !== null) {
+          requestHeaders[key] = value.toString();
+        }
+      });
+    }
   }
 
   // 处理URL中的多余斜杠