best-unit 1.2.5 → 1.2.6
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/dist/types/global.d.ts
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
+
// 枚举定义
|
|
2
|
+
export enum Locale {
|
|
3
|
+
ZH = "zh",
|
|
4
|
+
EN = "en",
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum Theme {
|
|
8
|
+
WHITE = "white",
|
|
9
|
+
DARK = "dark",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export enum Env {
|
|
13
|
+
DEV = "dev",
|
|
14
|
+
DEVELOPMENT = "development",
|
|
15
|
+
TEST = "test",
|
|
16
|
+
PROD = "prod",
|
|
17
|
+
PRODUCTION = "production",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 类型定义
|
|
21
|
+
export interface BalanceData {
|
|
22
|
+
fundBalanceId: string; // 余额账户id
|
|
23
|
+
merchantId: number; // 商户id
|
|
24
|
+
bizType: string; // 业务类型
|
|
25
|
+
currency: string; // 币种
|
|
26
|
+
totalAmount: string; // 真实金额
|
|
27
|
+
availableAmount: string; // 可用余额
|
|
28
|
+
frozenAmount: string; // 冻结金额
|
|
29
|
+
pendingAmount: string; // 待处理金额
|
|
30
|
+
status: string; // 状态
|
|
31
|
+
createdAt: string; // 创建时间
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface InitParams {
|
|
35
|
+
token: string;
|
|
36
|
+
merchant_id?: string;
|
|
37
|
+
biz_type?: string;
|
|
38
|
+
fund_balance_id?: string;
|
|
39
|
+
user_id: string;
|
|
40
|
+
theme?: Theme;
|
|
41
|
+
locale?: Locale;
|
|
42
|
+
env: Env;
|
|
43
|
+
themeConfig?: ThemeConfig;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ThemeConfig {
|
|
47
|
+
white?: {
|
|
48
|
+
color?: string;
|
|
49
|
+
};
|
|
50
|
+
dark?: {
|
|
51
|
+
color?: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
1
55
|
export declare function npmTest(): void;
|
|
2
56
|
|
|
3
57
|
export declare function printCurrentTime(): void;
|
|
@@ -23,7 +77,7 @@ export declare function initFundUnit(params: {
|
|
|
23
77
|
themeConfig?: ThemeConfig;
|
|
24
78
|
};
|
|
25
79
|
|
|
26
|
-
export declare function getBalanceData():
|
|
80
|
+
export declare function getBalanceData(): Promise<BalanceData>;
|
|
27
81
|
|
|
28
82
|
export declare function refreshBalance(): void;
|
|
29
83
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 外部项目使用示例
|
|
2
|
+
import {
|
|
3
|
+
getBalanceData,
|
|
4
|
+
type BalanceData,
|
|
5
|
+
type InitParams,
|
|
6
|
+
type ThemeConfig,
|
|
7
|
+
type Locale,
|
|
8
|
+
type Theme,
|
|
9
|
+
type Env,
|
|
10
|
+
} from "best-unit";
|
|
11
|
+
|
|
12
|
+
// 使用 BalanceData 类型
|
|
13
|
+
async function handleBalanceData() {
|
|
14
|
+
try {
|
|
15
|
+
const balance: BalanceData = await getBalanceData();
|
|
16
|
+
console.log(`余额账户: ${balance.fundBalanceId}`);
|
|
17
|
+
console.log(`可用余额: ${balance.availableAmount} ${balance.currency}`);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error("获取余额失败:", error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 使用 InitParams 类型
|
|
24
|
+
function initializeApp() {
|
|
25
|
+
const params: InitParams = {
|
|
26
|
+
token: "your-token-here",
|
|
27
|
+
user_id: "user-123",
|
|
28
|
+
env: Env.DEV,
|
|
29
|
+
theme: Theme.WHITE,
|
|
30
|
+
locale: Locale.ZH,
|
|
31
|
+
themeConfig: {
|
|
32
|
+
white: {
|
|
33
|
+
color: "#52c41a", // 绿色
|
|
34
|
+
},
|
|
35
|
+
dark: {
|
|
36
|
+
color: "#722ed1", // 紫色
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// 调用初始化函数
|
|
42
|
+
// initFundUnit(params);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 使用 ThemeConfig 类型
|
|
46
|
+
function createCustomTheme(primaryColor: string): ThemeConfig {
|
|
47
|
+
return {
|
|
48
|
+
white: {
|
|
49
|
+
color: primaryColor,
|
|
50
|
+
},
|
|
51
|
+
dark: {
|
|
52
|
+
color: primaryColor,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 类型安全的余额处理函数
|
|
58
|
+
function processBalance(balance: BalanceData): {
|
|
59
|
+
total: number;
|
|
60
|
+
available: number;
|
|
61
|
+
frozen: number;
|
|
62
|
+
pending: number;
|
|
63
|
+
} {
|
|
64
|
+
return {
|
|
65
|
+
total: parseFloat(balance.totalAmount),
|
|
66
|
+
available: parseFloat(balance.availableAmount),
|
|
67
|
+
frozen: parseFloat(balance.frozenAmount),
|
|
68
|
+
pending: parseFloat(balance.pendingAmount),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 导出示例函数
|
|
73
|
+
export { handleBalanceData, initializeApp, createCustomTheme, processBalance };
|
|
74
|
+
|
|
75
|
+
// 使用说明:
|
|
76
|
+
// 1. 从 'best-unit' 导入类型和函数
|
|
77
|
+
// 2. 所有类型都提供完整的 TypeScript 支持
|
|
78
|
+
// 3. 支持智能提示和类型检查
|
|
79
|
+
// 4. 可以在任何 TypeScript 项目中使用
|
package/src/types/global.d.ts
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
+
// 枚举定义
|
|
2
|
+
export enum Locale {
|
|
3
|
+
ZH = "zh",
|
|
4
|
+
EN = "en",
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum Theme {
|
|
8
|
+
WHITE = "white",
|
|
9
|
+
DARK = "dark",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export enum Env {
|
|
13
|
+
DEV = "dev",
|
|
14
|
+
DEVELOPMENT = "development",
|
|
15
|
+
TEST = "test",
|
|
16
|
+
PROD = "prod",
|
|
17
|
+
PRODUCTION = "production",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 类型定义
|
|
21
|
+
export interface BalanceData {
|
|
22
|
+
fundBalanceId: string; // 余额账户id
|
|
23
|
+
merchantId: number; // 商户id
|
|
24
|
+
bizType: string; // 业务类型
|
|
25
|
+
currency: string; // 币种
|
|
26
|
+
totalAmount: string; // 真实金额
|
|
27
|
+
availableAmount: string; // 可用余额
|
|
28
|
+
frozenAmount: string; // 冻结金额
|
|
29
|
+
pendingAmount: string; // 待处理金额
|
|
30
|
+
status: string; // 状态
|
|
31
|
+
createdAt: string; // 创建时间
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface InitParams {
|
|
35
|
+
token: string;
|
|
36
|
+
merchant_id?: string;
|
|
37
|
+
biz_type?: string;
|
|
38
|
+
fund_balance_id?: string;
|
|
39
|
+
user_id: string;
|
|
40
|
+
theme?: Theme;
|
|
41
|
+
locale?: Locale;
|
|
42
|
+
env: Env;
|
|
43
|
+
themeConfig?: ThemeConfig;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ThemeConfig {
|
|
47
|
+
white?: {
|
|
48
|
+
color?: string;
|
|
49
|
+
};
|
|
50
|
+
dark?: {
|
|
51
|
+
color?: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
1
55
|
export declare function npmTest(): void;
|
|
2
56
|
|
|
3
57
|
export declare function printCurrentTime(): void;
|
|
@@ -23,7 +77,7 @@ export declare function initFundUnit(params: {
|
|
|
23
77
|
themeConfig?: ThemeConfig;
|
|
24
78
|
};
|
|
25
79
|
|
|
26
|
-
export declare function getBalanceData():
|
|
80
|
+
export declare function getBalanceData(): Promise<BalanceData>;
|
|
27
81
|
|
|
28
82
|
export declare function refreshBalance(): void;
|
|
29
83
|
|