best-unit 1.2.19 → 1.2.21
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/BEST_UNIT_USAGE.md +402 -0
- package/dist/best-unit.cjs +13 -13
- package/dist/best-unit.js +1352 -1328
- package/index.html +13 -0
- package/package.json +1 -4
- package/src/api/axiosInstance.ts +111 -0
- package/src/api/index.ts +136 -0
- package/src/api/proxy.ts +11 -0
- package/src/components/business/recharge-sdk/components/offline-transfer-form/index.tsx +158 -0
- package/src/components/business/recharge-sdk/components/offline-transfer-form/theme.tsx +238 -0
- package/src/components/business/recharge-sdk/components/online-recharge-form/index.tsx +199 -0
- package/src/components/business/recharge-sdk/components/online-recharge-form/theme.tsx +159 -0
- package/src/components/business/recharge-sdk/components/recharge/index.tsx +152 -0
- package/src/components/business/recharge-sdk/components/recharge/theme.tsx +68 -0
- package/src/components/business/recharge-sdk/index.tsx +37 -0
- package/src/components/business/refresh-button/index.tsx +99 -0
- package/src/components/business/refresh-button/theme.tsx +58 -0
- package/src/components/business/statistical-balance/index.tsx +190 -0
- package/src/components/business/statistical-balance/theme.tsx +117 -0
- package/src/components/common/button/index.tsx +17 -0
- package/src/components/common/button/theme.tsx +56 -0
- package/src/components/common/hover-popover/index.tsx +182 -0
- package/src/components/common/hover-popover/theme.tsx +39 -0
- package/src/components/common/message/index.tsx +321 -0
- package/src/components/common/message/theme.tsx +25 -0
- package/src/components/common/modal/index.tsx +99 -0
- package/src/components/common/modal/theme.tsx +99 -0
- package/src/components/common/select/index.tsx +229 -0
- package/src/components/common/select/theme.tsx +104 -0
- package/src/components/common/upload/index.tsx +140 -0
- package/src/components/common/upload/theme.tsx +95 -0
- package/src/demo/App.tsx +685 -0
- package/src/demo/index.tsx +4 -0
- package/src/demo/testBalanceData.tsx +79 -0
- package/src/demo/theme-config-example.tsx +1 -0
- package/src/local/en.ts +64 -0
- package/src/local/index.ts +36 -0
- package/src/local/zh.ts +63 -0
- package/src/main.ts +26 -0
- package/src/types/global.d.ts +146 -0
- package/src/types/index.ts +31 -0
- package/src/types/preact-custom-element.d.ts +1 -0
- package/src/utils/business/index.ts +132 -0
- package/src/utils/common/index.ts +8 -0
- package/src/vite-env.d.ts +8 -0
- package/tsconfig.app.json +33 -0
- package/tsconfig.json +15 -0
- package/tsconfig.node.json +24 -0
- package/vite.config.ts +24 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useState } from "preact/hooks";
|
|
2
|
+
import { getBalanceData } from "@/utils/business";
|
|
3
|
+
|
|
4
|
+
interface TestBalanceDataProps {
|
|
5
|
+
isDark: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function TestBalanceData({ isDark }: TestBalanceDataProps) {
|
|
9
|
+
const [balanceData, setBalanceData] = useState<any>(null);
|
|
10
|
+
const [balanceLoading, setBalanceLoading] = useState(false);
|
|
11
|
+
|
|
12
|
+
// 测试 getBalanceData 函数
|
|
13
|
+
const testGetBalanceData = async () => {
|
|
14
|
+
setBalanceLoading(true);
|
|
15
|
+
try {
|
|
16
|
+
const result = await getBalanceData();
|
|
17
|
+
setBalanceData(result);
|
|
18
|
+
console.log("getBalanceData 测试结果:", result);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error("getBalanceData 测试失败:", error);
|
|
21
|
+
setBalanceData({ error: "获取失败" });
|
|
22
|
+
} finally {
|
|
23
|
+
setBalanceLoading(false);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
style={{
|
|
30
|
+
marginBottom: 20,
|
|
31
|
+
padding: 16,
|
|
32
|
+
border: "2px solid #52c41a",
|
|
33
|
+
borderRadius: 8,
|
|
34
|
+
backgroundColor: "#f6ffed",
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<h3 style={{ marginTop: 0, marginBottom: 12, color: "#52c41a" }}>
|
|
38
|
+
🧪 getBalanceData 函数测试:
|
|
39
|
+
</h3>
|
|
40
|
+
<button
|
|
41
|
+
onClick={testGetBalanceData}
|
|
42
|
+
disabled={balanceLoading}
|
|
43
|
+
style={{
|
|
44
|
+
padding: "8px 16px",
|
|
45
|
+
backgroundColor: balanceLoading ? "#d9d9d9" : "#52c41a",
|
|
46
|
+
color: "#fff",
|
|
47
|
+
border: "none",
|
|
48
|
+
borderRadius: 6,
|
|
49
|
+
cursor: balanceLoading ? "not-allowed" : "pointer",
|
|
50
|
+
marginBottom: 12,
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
{balanceLoading ? "测试中..." : "测试 getBalanceData 函数"}
|
|
54
|
+
</button>
|
|
55
|
+
|
|
56
|
+
{balanceData && (
|
|
57
|
+
<div
|
|
58
|
+
style={{
|
|
59
|
+
marginTop: 12,
|
|
60
|
+
padding: 12,
|
|
61
|
+
backgroundColor: isDark ? "#23262F" : "#fff",
|
|
62
|
+
border: "1px solid #d9d9d9",
|
|
63
|
+
borderRadius: 6,
|
|
64
|
+
fontSize: "12px",
|
|
65
|
+
fontFamily: "monospace",
|
|
66
|
+
whiteSpace: "pre-wrap",
|
|
67
|
+
maxHeight: "200px",
|
|
68
|
+
overflow: "auto",
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<strong>测试结果:</strong>
|
|
72
|
+
{JSON.stringify(balanceData, null, 2)}
|
|
73
|
+
</div>
|
|
74
|
+
)}
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default TestBalanceData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/src/local/en.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// 英文语言包
|
|
2
|
+
export const en: Record<string, string> = {
|
|
3
|
+
确定: "Confirm",
|
|
4
|
+
// 余额相关
|
|
5
|
+
余额详情: "Balance Details",
|
|
6
|
+
真实金额: "Real Balance",
|
|
7
|
+
冻结金额: "Frozen Amount",
|
|
8
|
+
信用额度: "Credit Limit",
|
|
9
|
+
已用额度: "Credit Used",
|
|
10
|
+
可用余额: "Available Balance",
|
|
11
|
+
暂无数据: "No Data",
|
|
12
|
+
"金额需在1到999999.99之间": "Amount must be between 1 and 999999.99",
|
|
13
|
+
|
|
14
|
+
// 充值相关
|
|
15
|
+
"充值 / 转账": "Recharge / Transfer",
|
|
16
|
+
在线充值: "Online Recharge",
|
|
17
|
+
线下转账: "Offline Transfer",
|
|
18
|
+
充值币种: "Recharge Currency",
|
|
19
|
+
充值金额: "Recharge Amount",
|
|
20
|
+
支付平台: "Payment Platform",
|
|
21
|
+
请选择充值币种: "Please select recharge currency",
|
|
22
|
+
请输入充值金额: "Please enter recharge amount",
|
|
23
|
+
请选择支付平台: "Please select payment platform",
|
|
24
|
+
"需要收取手续费,实际支付金额约为:":
|
|
25
|
+
"requires a handling fee, the actual payment amount is approximately: ",
|
|
26
|
+
"提交失败,请重试": "Submit failed, please try again",
|
|
27
|
+
"提交中...": "Submitting...",
|
|
28
|
+
去支付: "Go to Pay",
|
|
29
|
+
取消: "Cancel",
|
|
30
|
+
关闭: "Close",
|
|
31
|
+
|
|
32
|
+
// 离线转账相关
|
|
33
|
+
第三方支付平台: "Third-party Payment Platform",
|
|
34
|
+
交易ID: "Transaction ID",
|
|
35
|
+
请输入转账交易ID: "Please enter transfer transaction ID",
|
|
36
|
+
上传文件: "Upload Files",
|
|
37
|
+
请上传转账凭证: "Please upload transfer voucher",
|
|
38
|
+
离线充值创建成功: "Offline recharge created successfully",
|
|
39
|
+
|
|
40
|
+
// 通用
|
|
41
|
+
"加载中...": "Loading...",
|
|
42
|
+
错误: "Error",
|
|
43
|
+
成功: "Success",
|
|
44
|
+
必填: "Required",
|
|
45
|
+
|
|
46
|
+
// 按钮文本
|
|
47
|
+
"充值/转账": "Recharge/Transfer",
|
|
48
|
+
切换为暗黑主题: "Switch to Dark Theme",
|
|
49
|
+
切换为白色主题: "Switch to Light Theme",
|
|
50
|
+
|
|
51
|
+
// 上传组件相关
|
|
52
|
+
点击或拖拽文件到此处上传: "Click or drag files here to upload",
|
|
53
|
+
"支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传":
|
|
54
|
+
"Supports JPG, PNG, PDF formats, single file not exceeding 20MB, maximum",
|
|
55
|
+
个文件: "files can be uploaded",
|
|
56
|
+
"正在上传...": "Uploading...",
|
|
57
|
+
已上传: "Uploaded",
|
|
58
|
+
移除: "Remove",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// 根据中文key获取英文文本的函数
|
|
62
|
+
export function getEnText(zhKey: string): string {
|
|
63
|
+
return en[zhKey] || zhKey; // 如果找不到英文,返回中文key
|
|
64
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getZhText, zh } from "./zh";
|
|
2
|
+
import { getEnText, en } from "./en";
|
|
3
|
+
import { Locale } from "@/types";
|
|
4
|
+
|
|
5
|
+
// 获取当前语言
|
|
6
|
+
export function getCurrentLocale(): Locale {
|
|
7
|
+
const fundUnitParams = JSON.parse(
|
|
8
|
+
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
9
|
+
);
|
|
10
|
+
return fundUnitParams.locale || Locale.ZH;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// 获取国际化文本
|
|
14
|
+
export function getLocaleText() {
|
|
15
|
+
const locale = getCurrentLocale();
|
|
16
|
+
return locale === Locale.ZH ? zh : en;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 获取指定语言的文本
|
|
20
|
+
export function getLocaleTextByLang(locale: Locale) {
|
|
21
|
+
return locale === Locale.ZH ? zh : en;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 使用中文key的t函数
|
|
25
|
+
export function t(zhKey: string): string {
|
|
26
|
+
const locale = getCurrentLocale();
|
|
27
|
+
|
|
28
|
+
if (locale === "zh") {
|
|
29
|
+
return getZhText(zhKey);
|
|
30
|
+
} else {
|
|
31
|
+
return getEnText(zhKey);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 导出所有语言包
|
|
36
|
+
export { zh, en };
|
package/src/local/zh.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// 中文语言包
|
|
2
|
+
export const zh: Record<string, string> = {
|
|
3
|
+
确定: "确定",
|
|
4
|
+
// 余额相关
|
|
5
|
+
余额详情: "余额详情",
|
|
6
|
+
真实金额: "真实金额",
|
|
7
|
+
冻结金额: "冻结金额",
|
|
8
|
+
信用额度: "信用额度",
|
|
9
|
+
已用额度: "已用额度",
|
|
10
|
+
可用余额: "可用余额",
|
|
11
|
+
暂无数据: "暂无数据",
|
|
12
|
+
"金额需在1到999999.99之间": "金额需在1到999999.99之间",
|
|
13
|
+
|
|
14
|
+
// 充值相关
|
|
15
|
+
"充值 / 转账": "充值 / 转账",
|
|
16
|
+
在线充值: "在线充值",
|
|
17
|
+
线下转账: "线下转账",
|
|
18
|
+
充值币种: "充值币种",
|
|
19
|
+
充值金额: "充值金额",
|
|
20
|
+
支付平台: "支付平台",
|
|
21
|
+
请选择充值币种: "请选择充值币种",
|
|
22
|
+
请输入充值金额: "请输入充值金额",
|
|
23
|
+
请选择支付平台: "请选择支付平台",
|
|
24
|
+
"需要收取手续费,实际支付金额约为:": "需要收取手续费,实际支付金额约为:",
|
|
25
|
+
"提交失败,请重试": "提交失败,请重试",
|
|
26
|
+
"提交中...": "提交中...",
|
|
27
|
+
去支付: "去支付",
|
|
28
|
+
取消: "取消",
|
|
29
|
+
关闭: "关闭",
|
|
30
|
+
|
|
31
|
+
// 离线转账相关
|
|
32
|
+
第三方支付平台: "第三方支付平台",
|
|
33
|
+
交易ID: "交易ID",
|
|
34
|
+
请输入转账交易ID: "请输入转账交易ID",
|
|
35
|
+
上传文件: "上传文件",
|
|
36
|
+
请上传转账凭证: "请上传转账凭证",
|
|
37
|
+
离线充值创建成功: "离线充值创建成功",
|
|
38
|
+
|
|
39
|
+
// 通用
|
|
40
|
+
"加载中...": "加载中...",
|
|
41
|
+
错误: "错误",
|
|
42
|
+
成功: "成功",
|
|
43
|
+
必填: "必填",
|
|
44
|
+
|
|
45
|
+
// 按钮文本
|
|
46
|
+
"充值/转账": "充值/转账",
|
|
47
|
+
切换为暗黑主题: "切换为暗黑主题",
|
|
48
|
+
切换为白色主题: "切换为白色主题",
|
|
49
|
+
|
|
50
|
+
// 上传组件相关
|
|
51
|
+
点击或拖拽文件到此处上传: "点击或拖拽文件到此处上传",
|
|
52
|
+
"支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传":
|
|
53
|
+
"支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传",
|
|
54
|
+
个文件: "个文件",
|
|
55
|
+
"正在上传...": "正在上传...",
|
|
56
|
+
已上传: "已上传",
|
|
57
|
+
移除: "移除",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// 根据中文key获取文本的函数
|
|
61
|
+
export function getZhText(zhKey: string): string {
|
|
62
|
+
return zh[zhKey] || zhKey;
|
|
63
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { npmTest, printCurrentTime } from "@/utils/common/index";
|
|
2
|
+
import {
|
|
3
|
+
initFundUnit,
|
|
4
|
+
getBalanceData,
|
|
5
|
+
refreshBalance,
|
|
6
|
+
} from "@/utils/business/index";
|
|
7
|
+
import { viteProxy } from "@/api/proxy";
|
|
8
|
+
|
|
9
|
+
import "@/components/business/recharge-sdk";
|
|
10
|
+
import "@/components/business/statistical-balance";
|
|
11
|
+
import "@/components/business/refresh-button";
|
|
12
|
+
|
|
13
|
+
// 可选:导出组件列表或版本信息
|
|
14
|
+
export const components = [
|
|
15
|
+
"best-recharge",
|
|
16
|
+
"best-statistical-balance",
|
|
17
|
+
"best-refresh-button",
|
|
18
|
+
];
|
|
19
|
+
export {
|
|
20
|
+
npmTest,
|
|
21
|
+
printCurrentTime,
|
|
22
|
+
initFundUnit,
|
|
23
|
+
getBalanceData,
|
|
24
|
+
refreshBalance,
|
|
25
|
+
viteProxy,
|
|
26
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
export enum Size {
|
|
21
|
+
SMALL = "small",
|
|
22
|
+
MEDIUM = "medium",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 类型定义
|
|
26
|
+
export interface BalanceData {
|
|
27
|
+
fundBalanceId: string;
|
|
28
|
+
merchantId: number;
|
|
29
|
+
bizType: string;
|
|
30
|
+
currency: string;
|
|
31
|
+
totalAmount: string;
|
|
32
|
+
frozenAmount: string;
|
|
33
|
+
creditLimit: string;
|
|
34
|
+
creditUsed: string;
|
|
35
|
+
isCredit: boolean;
|
|
36
|
+
availableAmount: string;
|
|
37
|
+
pendingAmount: string;
|
|
38
|
+
status: string;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface InitParams {
|
|
43
|
+
token: string;
|
|
44
|
+
merchant_id?: string;
|
|
45
|
+
biz_type?: string;
|
|
46
|
+
fund_balance_id?: string;
|
|
47
|
+
user_id: string;
|
|
48
|
+
theme?: Theme;
|
|
49
|
+
locale?: Locale;
|
|
50
|
+
env: Env;
|
|
51
|
+
size?: Size;
|
|
52
|
+
themeConfig?: ThemeConfig;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ThemeConfig {
|
|
56
|
+
white?: {
|
|
57
|
+
color?: string;
|
|
58
|
+
fontSize?: number;
|
|
59
|
+
};
|
|
60
|
+
dark?: {
|
|
61
|
+
color?: string;
|
|
62
|
+
fontSize?: number;
|
|
63
|
+
};
|
|
64
|
+
global?: {
|
|
65
|
+
size?: Size;
|
|
66
|
+
fontSize?: number;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export declare function npmTest(): void;
|
|
71
|
+
|
|
72
|
+
export declare function printCurrentTime(): void;
|
|
73
|
+
|
|
74
|
+
export declare function initFundUnit(params: {
|
|
75
|
+
token: string;
|
|
76
|
+
merchant_id?: string;
|
|
77
|
+
biz_type?: string;
|
|
78
|
+
fund_balance_id?: string;
|
|
79
|
+
user_id: string;
|
|
80
|
+
theme?: Theme;
|
|
81
|
+
locale?: Locale;
|
|
82
|
+
env: Env;
|
|
83
|
+
size?: Size;
|
|
84
|
+
themeConfig?: ThemeConfig;
|
|
85
|
+
}): {
|
|
86
|
+
token: string;
|
|
87
|
+
merchantId?: string;
|
|
88
|
+
bizType?: string;
|
|
89
|
+
fundBalanceId?: string;
|
|
90
|
+
theme?: Theme;
|
|
91
|
+
locale: Locale;
|
|
92
|
+
env: Env;
|
|
93
|
+
size?: Size;
|
|
94
|
+
themeConfig?: ThemeConfig;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export declare function getBalanceData(): Promise<BalanceData>;
|
|
98
|
+
|
|
99
|
+
export declare function refreshBalance(): void;
|
|
100
|
+
|
|
101
|
+
// Vite 代理配置类型
|
|
102
|
+
export declare const viteProxy: {
|
|
103
|
+
"/api": {
|
|
104
|
+
target: string;
|
|
105
|
+
changeOrigin: boolean;
|
|
106
|
+
rewrite: (path: string) => string;
|
|
107
|
+
secure: boolean;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
declare global {
|
|
112
|
+
interface Window {
|
|
113
|
+
bestUnit: {
|
|
114
|
+
initFundUnit: (params: {
|
|
115
|
+
token: string;
|
|
116
|
+
merchant_id: string;
|
|
117
|
+
biz_type: string;
|
|
118
|
+
user_id: string;
|
|
119
|
+
fund_balance_id?: string;
|
|
120
|
+
locale?: "zh" | "en";
|
|
121
|
+
theme?: Theme;
|
|
122
|
+
size?: Size;
|
|
123
|
+
themeConfig?: ThemeConfig;
|
|
124
|
+
env: Env;
|
|
125
|
+
}) => void;
|
|
126
|
+
getBalanceData: () => any;
|
|
127
|
+
refreshBalance: () => void;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
namespace JSX {
|
|
132
|
+
interface IntrinsicElements {
|
|
133
|
+
"best-recharge": {
|
|
134
|
+
theme?: any;
|
|
135
|
+
merchant_id?: string;
|
|
136
|
+
biz_type?: string;
|
|
137
|
+
token?: string;
|
|
138
|
+
[key: string]: any;
|
|
139
|
+
};
|
|
140
|
+
"best-statistical-balance": any;
|
|
141
|
+
"best-refresh-button": any;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export {};
|
|
146
|
+
/// <reference path="./preact-custom-element.d.ts" />
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export enum Locale {
|
|
2
|
+
ZH = "zh",
|
|
3
|
+
EN = "en",
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export enum Theme {
|
|
7
|
+
WHITE = "white",
|
|
8
|
+
DARK = "dark",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export enum Env {
|
|
12
|
+
DEV = "dev",
|
|
13
|
+
DEVELOPMENT = "development",
|
|
14
|
+
TEST = "test",
|
|
15
|
+
PROD = "prod",
|
|
16
|
+
PRODUCTION = "production",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export enum Size {
|
|
20
|
+
SMALL = "small",
|
|
21
|
+
MEDIUM = "medium",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ThemeConfig {
|
|
25
|
+
white?: {
|
|
26
|
+
color?: string;
|
|
27
|
+
};
|
|
28
|
+
dark?: {
|
|
29
|
+
color?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'preact-custom-element'
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { getAllDicts, getBalance } from "@/api";
|
|
2
|
+
import { resetHttpInstance } from "@/api/axiosInstance";
|
|
3
|
+
import { Locale, Size, Theme, type Env } from "@/types";
|
|
4
|
+
|
|
5
|
+
// 余额数据结构接口
|
|
6
|
+
export interface BalanceData {
|
|
7
|
+
fundBalanceId: string;
|
|
8
|
+
merchantId: number;
|
|
9
|
+
bizType: string;
|
|
10
|
+
currency: string;
|
|
11
|
+
totalAmount: string;
|
|
12
|
+
frozenAmount: string;
|
|
13
|
+
creditLimit: string;
|
|
14
|
+
creditUsed: string;
|
|
15
|
+
isCredit: boolean;
|
|
16
|
+
availableAmount: string;
|
|
17
|
+
pendingAmount: string;
|
|
18
|
+
status: string;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ThemeConfig {
|
|
23
|
+
white?: {
|
|
24
|
+
color?: string;
|
|
25
|
+
};
|
|
26
|
+
dark?: {
|
|
27
|
+
color?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface InitParams {
|
|
32
|
+
token: string;
|
|
33
|
+
merchant_id?: string;
|
|
34
|
+
biz_type?: string;
|
|
35
|
+
fund_balance_id?: string;
|
|
36
|
+
user_id: string;
|
|
37
|
+
theme?: Theme;
|
|
38
|
+
locale?: Locale;
|
|
39
|
+
env: Env;
|
|
40
|
+
size?: Size;
|
|
41
|
+
themeConfig?: ThemeConfig;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 获取余额数据并暴露给外部系统
|
|
45
|
+
export async function getBalanceData() {
|
|
46
|
+
let balanceData = JSON.parse(sessionStorage.getItem("balanceData") || "{}");
|
|
47
|
+
if (balanceData && Object.keys(balanceData).length > 0) {
|
|
48
|
+
return balanceData;
|
|
49
|
+
}
|
|
50
|
+
balanceData = await getBalance();
|
|
51
|
+
return balanceData;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function initFundUnit(params: InitParams) {
|
|
55
|
+
const {
|
|
56
|
+
merchant_id,
|
|
57
|
+
biz_type,
|
|
58
|
+
fund_balance_id,
|
|
59
|
+
user_id,
|
|
60
|
+
theme = Theme.WHITE,
|
|
61
|
+
locale = Locale.ZH,
|
|
62
|
+
env,
|
|
63
|
+
size,
|
|
64
|
+
themeConfig,
|
|
65
|
+
} = params;
|
|
66
|
+
console.log(params, "InitParams1111");
|
|
67
|
+
const token = "Bearer " + params.token;
|
|
68
|
+
sessionStorage.setItem(
|
|
69
|
+
"fund_unit_params",
|
|
70
|
+
JSON.stringify({
|
|
71
|
+
merchantId: merchant_id,
|
|
72
|
+
bizType: biz_type,
|
|
73
|
+
fundBalanceId: fund_balance_id,
|
|
74
|
+
userId: user_id,
|
|
75
|
+
token,
|
|
76
|
+
theme,
|
|
77
|
+
locale,
|
|
78
|
+
env,
|
|
79
|
+
size,
|
|
80
|
+
themeConfig,
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
// 重置 axios 实例,确保使用新的配置
|
|
84
|
+
resetHttpInstance();
|
|
85
|
+
|
|
86
|
+
getAllDicts();
|
|
87
|
+
return {
|
|
88
|
+
token,
|
|
89
|
+
merchantId: merchant_id,
|
|
90
|
+
bizType: biz_type,
|
|
91
|
+
fundBalanceId: fund_balance_id,
|
|
92
|
+
userId: user_id,
|
|
93
|
+
theme,
|
|
94
|
+
locale,
|
|
95
|
+
env,
|
|
96
|
+
size,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getInitParams<T = InitParams>(key?: string | string[]): T {
|
|
101
|
+
const fundUnitParams = JSON.parse(
|
|
102
|
+
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
if (!key) {
|
|
106
|
+
return fundUnitParams as T;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Array.isArray(key)) {
|
|
110
|
+
const result: Partial<InitParams> = {};
|
|
111
|
+
key.forEach((k) => {
|
|
112
|
+
result[k as keyof InitParams] = fundUnitParams[k as keyof InitParams];
|
|
113
|
+
});
|
|
114
|
+
return result as T;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return fundUnitParams[key] as T;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 触发余额刷新事件
|
|
122
|
+
*/
|
|
123
|
+
export function refreshBalance() {
|
|
124
|
+
const refreshEvent = new CustomEvent("refresh-balance", {
|
|
125
|
+
detail: {},
|
|
126
|
+
bubbles: true,
|
|
127
|
+
composed: true,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// 从document开始分发事件
|
|
131
|
+
document.dispatchEvent(refreshEvent);
|
|
132
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"baseUrl": ".",
|
|
10
|
+
"paths": {
|
|
11
|
+
"@/*": ["src/*"],
|
|
12
|
+
"react": ["./node_modules/preact/compat/"],
|
|
13
|
+
"react-dom": ["./node_modules/preact/compat/"]
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
/* Bundler mode */
|
|
17
|
+
"moduleResolution": "bundler",
|
|
18
|
+
"allowImportingTsExtensions": true,
|
|
19
|
+
"verbatimModuleSyntax": true,
|
|
20
|
+
"moduleDetection": "force",
|
|
21
|
+
"noEmit": true,
|
|
22
|
+
"jsx": "react-jsx",
|
|
23
|
+
"jsxImportSource": "preact",
|
|
24
|
+
|
|
25
|
+
/* Linting */
|
|
26
|
+
"strict": true,
|
|
27
|
+
"noUnusedLocals": true,
|
|
28
|
+
"noUnusedParameters": true,
|
|
29
|
+
"noFallthroughCasesInSwitch": true,
|
|
30
|
+
"noUncheckedSideEffectImports": true
|
|
31
|
+
},
|
|
32
|
+
"include": ["src"]
|
|
33
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"declarationDir": "dist",
|
|
5
|
+
"declarationMap": false,
|
|
6
|
+
},
|
|
7
|
+
"files": [],
|
|
8
|
+
"references": [
|
|
9
|
+
{ "path": "./tsconfig.app.json" },
|
|
10
|
+
{ "path": "./tsconfig.node.json" }
|
|
11
|
+
],
|
|
12
|
+
"editor.codeActionsOnSave": {
|
|
13
|
+
"source.fixAll.eslint": true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
+
"target": "ES2023",
|
|
5
|
+
"lib": ["ES2023"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"verbatimModuleSyntax": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
|
|
16
|
+
/* Linting */
|
|
17
|
+
"strict": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedSideEffectImports": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["vite.config.ts"]
|
|
24
|
+
}
|