best-unit 0.0.49 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "0.0.49",
4
+ "version": "0.0.50",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
@@ -6,6 +6,7 @@ import type {
6
6
  } from "axios";
7
7
  import { message } from "../components/common/Message";
8
8
  import { Locale } from "../types";
9
+ import { filterEmptyValues } from "../utils/common";
9
10
 
10
11
  export interface CreateAxiosOptions {
11
12
  baseURL?: string;
@@ -30,6 +31,13 @@ export function createAxiosInstance(options: CreateAxiosOptions = {}) {
30
31
  "x-locale": locale === Locale.ZH ? "zh-CN" : "en-US",
31
32
  } as any;
32
33
 
34
+ if (config.params) {
35
+ config.params = filterEmptyValues(config.params);
36
+ }
37
+ if (config.data) {
38
+ config.data = filterEmptyValues(config.data);
39
+ }
40
+
33
41
  return config;
34
42
  });
35
43
 
package/src/api/index.ts CHANGED
@@ -64,6 +64,7 @@ export const createOfflineRecharge = async (data: any) => {
64
64
  const params = {
65
65
  merchant_id: Number(fundUnitParams.merchantId),
66
66
  biz_type: fundUnitParams.bizType,
67
+ fund_balance_id: fundUnitParams.fundBalanceId,
67
68
  source_operator: String(fundUnitParams.userId),
68
69
  transfer_no: data.transferNo,
69
70
  transfer_channel: data.transferChannel,
@@ -83,6 +84,8 @@ export const createOnlineRecharge = async (data: any) => {
83
84
  const params = {
84
85
  merchant_id: Number(fundUnitParams.merchantId),
85
86
  biz_type: fundUnitParams.bizType,
87
+ fund_balance_id: fundUnitParams.fundBalanceId,
88
+
86
89
  source_operator: String(fundUnitParams.userId),
87
90
  amount: data.amount,
88
91
  currency: data.currency,
@@ -6,3 +6,30 @@ export function printCurrentTime() {
6
6
  const now = new Date();
7
7
  console.log("Current time:", now.toISOString());
8
8
  }
9
+
10
+ /**
11
+ * 过滤对象中的空值(null 和 undefined)
12
+ * @param obj 要过滤的对象
13
+ * @returns 过滤后的新对象
14
+ */
15
+ export function filterEmptyValues(
16
+ obj: Record<string, any>
17
+ ): Record<string, any> {
18
+ return Object.entries(obj).reduce((acc, [key, value]) => {
19
+ // 如果值是对象且不是数组,递归处理
20
+ if (value && typeof value === "object" && !Array.isArray(value)) {
21
+ const filtered = filterEmptyValues(value);
22
+ // 只有当过滤后的对象有属性时才添加
23
+ if (Object.keys(filtered).length > 0) {
24
+ acc[key] = filtered;
25
+ }
26
+ return acc;
27
+ }
28
+
29
+ // 如果值不为 null 或 undefined,则保留
30
+ if (value !== null && value !== undefined) {
31
+ acc[key] = value;
32
+ }
33
+ return acc;
34
+ }, {} as Record<string, any>);
35
+ }