best-unit 1.2.17 → 1.2.19
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/best-unit.cjs +1 -1
- package/dist/best-unit.js +1 -1
- package/package.json +4 -1
- package/BEST_UNIT_USAGE.md +0 -402
- package/index.html +0 -13
- package/src/api/axiosInstance.ts +0 -111
- package/src/api/index.ts +0 -136
- package/src/api/proxy.ts +0 -11
- package/src/components/business/recharge-sdk/components/offline-transfer-form/index.tsx +0 -158
- package/src/components/business/recharge-sdk/components/offline-transfer-form/theme.tsx +0 -238
- package/src/components/business/recharge-sdk/components/online-recharge-form/index.tsx +0 -199
- package/src/components/business/recharge-sdk/components/online-recharge-form/theme.tsx +0 -151
- package/src/components/business/recharge-sdk/components/recharge/index.tsx +0 -152
- package/src/components/business/recharge-sdk/components/recharge/theme.tsx +0 -64
- package/src/components/business/recharge-sdk/index.tsx +0 -37
- package/src/components/business/refresh-button/index.tsx +0 -99
- package/src/components/business/refresh-button/theme.tsx +0 -58
- package/src/components/business/statistical-balance/index.tsx +0 -190
- package/src/components/business/statistical-balance/theme.tsx +0 -110
- package/src/components/common/button/index.tsx +0 -17
- package/src/components/common/button/theme.tsx +0 -48
- package/src/components/common/hover-popover/index.tsx +0 -179
- package/src/components/common/hover-popover/theme.tsx +0 -39
- package/src/components/common/message/index.tsx +0 -321
- package/src/components/common/message/theme.tsx +0 -25
- package/src/components/common/modal/index.tsx +0 -99
- package/src/components/common/modal/theme.tsx +0 -91
- package/src/components/common/select/index.tsx +0 -229
- package/src/components/common/select/theme.tsx +0 -104
- package/src/components/common/upload/index.tsx +0 -140
- package/src/components/common/upload/theme.tsx +0 -89
- package/src/demo/App.tsx +0 -685
- package/src/demo/index.tsx +0 -4
- package/src/demo/testBalanceData.tsx +0 -79
- package/src/demo/theme-config-example.tsx +0 -1
- package/src/local/en.ts +0 -63
- package/src/local/index.ts +0 -36
- package/src/local/zh.ts +0 -62
- package/src/main.ts +0 -26
- package/src/types/global.d.ts +0 -146
- package/src/types/index.ts +0 -31
- package/src/types/preact-custom-element.d.ts +0 -1
- package/src/utils/business/index.ts +0 -132
- package/src/utils/common/index.ts +0 -8
- package/src/vite-env.d.ts +0 -8
- package/tsconfig.app.json +0 -33
- package/tsconfig.json +0 -15
- package/tsconfig.node.json +0 -24
- package/vite.config.ts +0 -24
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import type { FunctionalComponent } from "preact";
|
|
2
|
-
import { useState, useEffect } from "preact/hooks";
|
|
3
|
-
import { t } from "@/local";
|
|
4
|
-
import { Select } from "@/components/common/select";
|
|
5
|
-
import { calcPaymentAmount } from "@/api";
|
|
6
|
-
import { getOnlineRechargeFormTheme } from "./theme";
|
|
7
|
-
|
|
8
|
-
interface OnlineRechargeFormProps {
|
|
9
|
-
formState: {
|
|
10
|
-
amount: string;
|
|
11
|
-
rechargeChannel: string;
|
|
12
|
-
currency: string;
|
|
13
|
-
loading: boolean;
|
|
14
|
-
error: string;
|
|
15
|
-
amountError: string;
|
|
16
|
-
rechargeChannelError: string;
|
|
17
|
-
currencyError: string;
|
|
18
|
-
};
|
|
19
|
-
setFormState: (fn: (state: any) => any) => void;
|
|
20
|
-
onClose: () => void;
|
|
21
|
-
loading: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// 辅助函数:只允许输入数字和小数点,且最多两位小数
|
|
25
|
-
function formatAmountInput(value: string) {
|
|
26
|
-
// 只保留数字和小数点
|
|
27
|
-
value = value.replace(/[^\d.]/g, "");
|
|
28
|
-
// 只保留第一个小数点
|
|
29
|
-
value = value.replace(/\.(?=.*\.)/g, "");
|
|
30
|
-
// 保证最多两位小数
|
|
31
|
-
value = value.replace(/^(\d+)(\.\d{0,2})?.*$/, "$1$2");
|
|
32
|
-
// 去除前导0(保留0.和0.xx)
|
|
33
|
-
value = value.replace(/^0+(\d)/, "$1");
|
|
34
|
-
if (value.startsWith(".")) value = "0" + value;
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
// 辅助函数:格式化为两位小数
|
|
38
|
-
function formatToTwoDecimal(value: string) {
|
|
39
|
-
if (!value) return "";
|
|
40
|
-
const num = parseFloat(value);
|
|
41
|
-
if (isNaN(num)) return "";
|
|
42
|
-
return num.toFixed(2);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const OnlineRechargeForm: FunctionalComponent<
|
|
46
|
-
OnlineRechargeFormProps
|
|
47
|
-
> = ({ formState, setFormState, onClose, loading }) => {
|
|
48
|
-
const allDicts = JSON.parse(sessionStorage.getItem("all_dicts") || "{}");
|
|
49
|
-
const currencyDict = allDicts?.currency || [];
|
|
50
|
-
const channelDict =
|
|
51
|
-
allDicts?.channel?.filter((item: any) => item.payment_support) || [];
|
|
52
|
-
const [actualAmount, setActualAmount] = useState<string>("");
|
|
53
|
-
const [showFeeTip, setShowFeeTip] = useState(false);
|
|
54
|
-
const theme = getOnlineRechargeFormTheme();
|
|
55
|
-
|
|
56
|
-
// 当三个参数都填写完整时,计算实际支付金额
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (formState.currency && formState.amount && formState.rechargeChannel) {
|
|
59
|
-
calcPaymentAmount({
|
|
60
|
-
channel: formState.rechargeChannel,
|
|
61
|
-
amount: formState.amount,
|
|
62
|
-
currency: formState.currency,
|
|
63
|
-
})
|
|
64
|
-
.then((paymentAmount) => {
|
|
65
|
-
setActualAmount(paymentAmount);
|
|
66
|
-
setShowFeeTip(true);
|
|
67
|
-
})
|
|
68
|
-
.catch((error) => {
|
|
69
|
-
console.error("计算支付金额失败:", error);
|
|
70
|
-
setShowFeeTip(false);
|
|
71
|
-
});
|
|
72
|
-
} else {
|
|
73
|
-
setShowFeeTip(false);
|
|
74
|
-
}
|
|
75
|
-
}, [formState.currency, formState.amount, formState.rechargeChannel]);
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<>
|
|
79
|
-
<div style={{ marginBottom: 18 }}>
|
|
80
|
-
<div style={theme.label}>
|
|
81
|
-
<span style={{ color: "#F53F3F" }}>*</span> {t("充值币种")}
|
|
82
|
-
</div>
|
|
83
|
-
<Select
|
|
84
|
-
value={formState.currency}
|
|
85
|
-
onChange={(value) => {
|
|
86
|
-
setFormState((state: any) => ({
|
|
87
|
-
...state,
|
|
88
|
-
currency: value,
|
|
89
|
-
}));
|
|
90
|
-
}}
|
|
91
|
-
options={currencyDict?.map((item: any) => ({
|
|
92
|
-
value: item.value,
|
|
93
|
-
label: item.label,
|
|
94
|
-
}))}
|
|
95
|
-
placeholder={t("请选择充值币种")}
|
|
96
|
-
/>
|
|
97
|
-
</div>
|
|
98
|
-
<div style={{ marginBottom: 18 }}>
|
|
99
|
-
<div style={theme.label}>
|
|
100
|
-
<span style={{ color: "#F53F3F" }}>*</span> {t("充值金额")}
|
|
101
|
-
</div>
|
|
102
|
-
<input
|
|
103
|
-
type="text"
|
|
104
|
-
placeholder={t("请输入充值金额")}
|
|
105
|
-
value={formState.amount}
|
|
106
|
-
onInput={(e) => {
|
|
107
|
-
let value = (e.target as HTMLInputElement).value;
|
|
108
|
-
value = formatAmountInput(value);
|
|
109
|
-
let amountError = "";
|
|
110
|
-
// 只有输入为合法数字且不以小数点结尾时才做区间修正
|
|
111
|
-
if (value && !value.endsWith(".")) {
|
|
112
|
-
let num = parseFloat(value);
|
|
113
|
-
if (!isNaN(num)) {
|
|
114
|
-
if (num < 1) num = 1;
|
|
115
|
-
if (num > 999999.99) num = 999999.99;
|
|
116
|
-
value = num.toString();
|
|
117
|
-
// 如果原始输入有小数点且小数点后有内容,保留小数部分
|
|
118
|
-
if (/\./.test((e.target as HTMLInputElement).value)) {
|
|
119
|
-
const decimalPart = (
|
|
120
|
-
e.target as HTMLInputElement
|
|
121
|
-
).value.split(".")[1];
|
|
122
|
-
if (decimalPart !== undefined && decimalPart.length > 0) {
|
|
123
|
-
value = num.toFixed(Math.min(decimalPart.length, 2));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
setFormState((state: any) => ({
|
|
129
|
-
...state,
|
|
130
|
-
amount: value,
|
|
131
|
-
amountError,
|
|
132
|
-
}));
|
|
133
|
-
}}
|
|
134
|
-
onBlur={(e) => {
|
|
135
|
-
let value = (e.target as HTMLInputElement).value;
|
|
136
|
-
value = formatToTwoDecimal(value);
|
|
137
|
-
setFormState((state: any) => ({
|
|
138
|
-
...state,
|
|
139
|
-
amount: value,
|
|
140
|
-
amountError: "",
|
|
141
|
-
}));
|
|
142
|
-
}}
|
|
143
|
-
style={{
|
|
144
|
-
...theme.input,
|
|
145
|
-
...(formState.amountError ? theme.inputError : {}),
|
|
146
|
-
}}
|
|
147
|
-
/>
|
|
148
|
-
{formState.amountError && (
|
|
149
|
-
<div style={theme.error}>{formState.amountError}</div>
|
|
150
|
-
)}
|
|
151
|
-
</div>
|
|
152
|
-
<div style={{ marginBottom: 24 }}>
|
|
153
|
-
<div style={theme.label}>
|
|
154
|
-
<span style={{ color: "#F53F3F" }}>*</span> {t("支付平台")}
|
|
155
|
-
</div>
|
|
156
|
-
<Select
|
|
157
|
-
value={formState.rechargeChannel}
|
|
158
|
-
onChange={(value) => {
|
|
159
|
-
setFormState((state: any) => ({
|
|
160
|
-
...state,
|
|
161
|
-
rechargeChannel: value,
|
|
162
|
-
rechargeChannelError: value ? "" : state.rechargeChannelError,
|
|
163
|
-
}));
|
|
164
|
-
}}
|
|
165
|
-
options={channelDict?.map((item: any) => ({
|
|
166
|
-
value: item.value,
|
|
167
|
-
label: item.label,
|
|
168
|
-
}))}
|
|
169
|
-
placeholder={t("请选择支付平台")}
|
|
170
|
-
></Select>
|
|
171
|
-
{formState.rechargeChannelError && (
|
|
172
|
-
<div style={theme.error}>{formState.rechargeChannelError}</div>
|
|
173
|
-
)}
|
|
174
|
-
</div>
|
|
175
|
-
{/* 手续费提示 */}
|
|
176
|
-
{showFeeTip && actualAmount && (
|
|
177
|
-
<div style={theme.feeTip}>
|
|
178
|
-
{channelDict.find(
|
|
179
|
-
(item: any) => item.value === formState.rechargeChannel
|
|
180
|
-
)?.label || formState.rechargeChannel}
|
|
181
|
-
{t("需要收取手续费,实际支付金额约为:")}${actualAmount}
|
|
182
|
-
</div>
|
|
183
|
-
)}
|
|
184
|
-
{formState.error && (
|
|
185
|
-
<div style={{ color: "#ff4d4f", marginBottom: 12 }}>
|
|
186
|
-
{formState.error}
|
|
187
|
-
</div>
|
|
188
|
-
)}
|
|
189
|
-
<div style={{ display: "flex", justifyContent: "flex-end", gap: 12 }}>
|
|
190
|
-
<button type="button" onClick={onClose} style={theme.buttonCancel}>
|
|
191
|
-
{t("取消")}
|
|
192
|
-
</button>
|
|
193
|
-
<button type="submit" disabled={loading} style={theme.buttonSubmit}>
|
|
194
|
-
{loading ? t("提交中...") : t("去支付")}
|
|
195
|
-
</button>
|
|
196
|
-
</div>
|
|
197
|
-
</>
|
|
198
|
-
);
|
|
199
|
-
};
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { Size, Theme, type ThemeConfig } from "@/types";
|
|
2
|
-
import { getInitParams } from "@/utils/business";
|
|
3
|
-
const size = getInitParams<Size>("size");
|
|
4
|
-
export const onlineRechargeFormThemes = {
|
|
5
|
-
white: {
|
|
6
|
-
label: {
|
|
7
|
-
marginBottom: size === Size.SMALL ? 4 : 8,
|
|
8
|
-
fontSize: size === Size.SMALL ? 12 : 14,
|
|
9
|
-
color: "#222",
|
|
10
|
-
textAlign: "left",
|
|
11
|
-
display: "block",
|
|
12
|
-
},
|
|
13
|
-
input: {
|
|
14
|
-
width: "100%",
|
|
15
|
-
padding: size === Size.SMALL ? "8px 10px" : "10px 12px",
|
|
16
|
-
borderRadius: 6,
|
|
17
|
-
boxSizing: "border-box",
|
|
18
|
-
border: "1px solid #E5E6EB",
|
|
19
|
-
background: "#fff",
|
|
20
|
-
color: "#222",
|
|
21
|
-
fontSize: size === Size.SMALL ? 12 : 15,
|
|
22
|
-
outline: "none",
|
|
23
|
-
marginBottom: 0,
|
|
24
|
-
},
|
|
25
|
-
inputError: {
|
|
26
|
-
border: "1px solid #ff4d4f",
|
|
27
|
-
},
|
|
28
|
-
selectError: {
|
|
29
|
-
border: "1px solid #ff4d4f",
|
|
30
|
-
},
|
|
31
|
-
error: {
|
|
32
|
-
color: "#ff4d4f",
|
|
33
|
-
fontSize: size === Size.SMALL ? 12 : 13,
|
|
34
|
-
marginTop: size === Size.SMALL ? 2 : 4,
|
|
35
|
-
textAlign: "left",
|
|
36
|
-
},
|
|
37
|
-
buttonCancel: {
|
|
38
|
-
background: "#fff",
|
|
39
|
-
color: "#222",
|
|
40
|
-
border: "1px solid #E5E6EB",
|
|
41
|
-
borderRadius: 6,
|
|
42
|
-
padding: size === Size.SMALL ? "6px 16px" : "8px 24px",
|
|
43
|
-
fontSize: size === Size.SMALL ? 12 : 15,
|
|
44
|
-
cursor: "pointer",
|
|
45
|
-
},
|
|
46
|
-
buttonSubmit: {
|
|
47
|
-
background: "#1890ff",
|
|
48
|
-
color: "#fff",
|
|
49
|
-
border: "none",
|
|
50
|
-
borderRadius: 6,
|
|
51
|
-
padding: size === Size.SMALL ? "6px 16px" : "8px 24px",
|
|
52
|
-
fontSize: size === Size.SMALL ? 12 : 15,
|
|
53
|
-
cursor: "pointer",
|
|
54
|
-
fontWeight: 600,
|
|
55
|
-
},
|
|
56
|
-
feeTip: {
|
|
57
|
-
marginBottom: 24,
|
|
58
|
-
padding: size === Size.SMALL ? "8px 10px" : "12px 16px",
|
|
59
|
-
background: "#f6ffed",
|
|
60
|
-
border: "1px solid #b7eb8f",
|
|
61
|
-
borderRadius: 6,
|
|
62
|
-
fontSize: size === Size.SMALL ? 12 : 14,
|
|
63
|
-
color: "#52c41a",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
dark: {
|
|
67
|
-
label: {
|
|
68
|
-
marginBottom: size === Size.SMALL ? 6 : 8,
|
|
69
|
-
fontSize: size === Size.SMALL ? 12 : 14,
|
|
70
|
-
color: "#fff",
|
|
71
|
-
textAlign: "left",
|
|
72
|
-
display: "block",
|
|
73
|
-
},
|
|
74
|
-
input: {
|
|
75
|
-
width: "100%",
|
|
76
|
-
padding: size === Size.SMALL ? "8px 10px" : "10px 12px",
|
|
77
|
-
borderRadius: 6,
|
|
78
|
-
boxSizing: "border-box",
|
|
79
|
-
border: "1px solid #374151",
|
|
80
|
-
background: "#23262F",
|
|
81
|
-
color: "#fff",
|
|
82
|
-
fontSize: size === Size.SMALL ? 12 : 15,
|
|
83
|
-
outline: "none",
|
|
84
|
-
marginBottom: 0,
|
|
85
|
-
},
|
|
86
|
-
inputError: {
|
|
87
|
-
border: "1px solid #ff4d4f",
|
|
88
|
-
},
|
|
89
|
-
selectError: {
|
|
90
|
-
border: "1px solid #ff4d4f",
|
|
91
|
-
},
|
|
92
|
-
error: {
|
|
93
|
-
color: "#ff4d4f",
|
|
94
|
-
fontSize: size === Size.SMALL ? 12 : 13,
|
|
95
|
-
marginTop: size === Size.SMALL ? 2 : 4,
|
|
96
|
-
textAlign: "left",
|
|
97
|
-
},
|
|
98
|
-
buttonCancel: {
|
|
99
|
-
background: "#23262F",
|
|
100
|
-
color: "#fff",
|
|
101
|
-
border: "none",
|
|
102
|
-
borderRadius: 6,
|
|
103
|
-
padding: size === Size.SMALL ? "6px 16px" : "8px 24px",
|
|
104
|
-
fontSize: size === Size.SMALL ? 12 : 15,
|
|
105
|
-
cursor: "pointer",
|
|
106
|
-
},
|
|
107
|
-
buttonSubmit: {
|
|
108
|
-
background: "#00E8C6",
|
|
109
|
-
color: "#fff",
|
|
110
|
-
border: "none",
|
|
111
|
-
borderRadius: 6,
|
|
112
|
-
padding: size === Size.SMALL ? "6px 16px" : "8px 24px",
|
|
113
|
-
fontSize: size === Size.SMALL ? 12 : 15,
|
|
114
|
-
cursor: "pointer",
|
|
115
|
-
fontWeight: 600,
|
|
116
|
-
},
|
|
117
|
-
feeTip: {
|
|
118
|
-
marginBottom: size === Size.SMALL ? 16 : 24,
|
|
119
|
-
padding: size === Size.SMALL ? "8px 10px" : "12px 16px",
|
|
120
|
-
background: "#1a1a1a",
|
|
121
|
-
border: "1px solid #333",
|
|
122
|
-
borderRadius: 6,
|
|
123
|
-
fontSize: size === Size.SMALL ? 12 : 14,
|
|
124
|
-
color: "#52c41a",
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export function getOnlineRechargeFormTheme() {
|
|
130
|
-
const theme = getInitParams<Theme>("theme");
|
|
131
|
-
const themeConfig = getInitParams<ThemeConfig>("themeConfig");
|
|
132
|
-
const whiteTheme = theme === Theme.WHITE;
|
|
133
|
-
const baseTheme = whiteTheme
|
|
134
|
-
? onlineRechargeFormThemes.white
|
|
135
|
-
: onlineRechargeFormThemes.dark;
|
|
136
|
-
// 如果初始化时传入了按钮配置,则覆盖默认配置
|
|
137
|
-
if (themeConfig) {
|
|
138
|
-
const config = whiteTheme ? themeConfig.white : themeConfig.dark;
|
|
139
|
-
if (config?.color) {
|
|
140
|
-
return {
|
|
141
|
-
...baseTheme,
|
|
142
|
-
buttonSubmit: {
|
|
143
|
-
...baseTheme.buttonSubmit,
|
|
144
|
-
background: config.color,
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return baseTheme;
|
|
151
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from "preact/hooks";
|
|
2
|
-
import { OnlineRechargeForm } from "../online-recharge-form";
|
|
3
|
-
import { OfflineTransferForm } from "../offline-transfer-form";
|
|
4
|
-
import { t } from "@/local";
|
|
5
|
-
import { Modal } from "@/components/common/modal";
|
|
6
|
-
import { getRechargeTheme } from "./theme";
|
|
7
|
-
import { getInitParams } from "@/utils/business";
|
|
8
|
-
import { Size } from "@/types";
|
|
9
|
-
const size = getInitParams<Size>("size");
|
|
10
|
-
interface ModalFormProps {
|
|
11
|
-
visible: boolean;
|
|
12
|
-
onClose: () => void;
|
|
13
|
-
onSubmit: (form: {
|
|
14
|
-
amount: string;
|
|
15
|
-
rechargeChannel: string;
|
|
16
|
-
currency: string;
|
|
17
|
-
}) => Promise<void>;
|
|
18
|
-
color?: string;
|
|
19
|
-
merchantId?: string;
|
|
20
|
-
bizType?: string;
|
|
21
|
-
token?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function Recharge({ visible, onClose, onSubmit }: ModalFormProps) {
|
|
25
|
-
const [formState, setFormState] = useState({
|
|
26
|
-
amount: "",
|
|
27
|
-
rechargeChannel: "",
|
|
28
|
-
currency: "USD",
|
|
29
|
-
loading: false,
|
|
30
|
-
error: "",
|
|
31
|
-
amountError: "",
|
|
32
|
-
rechargeChannelError: "",
|
|
33
|
-
currencyError: "",
|
|
34
|
-
});
|
|
35
|
-
const [offlineFormState, setOfflineFormState] = useState({
|
|
36
|
-
platform: "",
|
|
37
|
-
transactionId: "",
|
|
38
|
-
files: [],
|
|
39
|
-
platformError: "",
|
|
40
|
-
transactionIdError: "",
|
|
41
|
-
filesError: "",
|
|
42
|
-
loading: false,
|
|
43
|
-
});
|
|
44
|
-
const [activeTab, setActiveTab] = useState<"online" | "offline">("online");
|
|
45
|
-
const theme = getRechargeTheme();
|
|
46
|
-
|
|
47
|
-
// 每次关闭弹窗时重置内容
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (!visible) {
|
|
50
|
-
setActiveTab("online");
|
|
51
|
-
setFormState({
|
|
52
|
-
amount: "",
|
|
53
|
-
rechargeChannel: "",
|
|
54
|
-
currency: "USD",
|
|
55
|
-
loading: false,
|
|
56
|
-
error: "",
|
|
57
|
-
amountError: "",
|
|
58
|
-
rechargeChannelError: "",
|
|
59
|
-
currencyError: "",
|
|
60
|
-
});
|
|
61
|
-
setOfflineFormState({
|
|
62
|
-
platform: "",
|
|
63
|
-
transactionId: "",
|
|
64
|
-
files: [],
|
|
65
|
-
platformError: "",
|
|
66
|
-
transactionIdError: "",
|
|
67
|
-
filesError: "",
|
|
68
|
-
loading: false,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}, [visible]);
|
|
72
|
-
|
|
73
|
-
const handleSubmit = async (e: Event) => {
|
|
74
|
-
e.preventDefault();
|
|
75
|
-
let valid = true;
|
|
76
|
-
setFormState((state) => ({
|
|
77
|
-
...state,
|
|
78
|
-
amountError: "",
|
|
79
|
-
rechargeChannelError: "",
|
|
80
|
-
}));
|
|
81
|
-
if (!formState.amount.trim()) {
|
|
82
|
-
setFormState((state) => ({ ...state, amountError: t("请输入充值金额") }));
|
|
83
|
-
valid = false;
|
|
84
|
-
}
|
|
85
|
-
if (!formState.rechargeChannel) {
|
|
86
|
-
setFormState((state) => ({
|
|
87
|
-
...state,
|
|
88
|
-
rechargeChannelError: t("请选择支付平台"),
|
|
89
|
-
}));
|
|
90
|
-
valid = false;
|
|
91
|
-
}
|
|
92
|
-
if (!valid) return;
|
|
93
|
-
setFormState((state) => ({ ...state, loading: true, error: "" }));
|
|
94
|
-
try {
|
|
95
|
-
await onSubmit({
|
|
96
|
-
amount: formState.amount,
|
|
97
|
-
rechargeChannel: formState.rechargeChannel,
|
|
98
|
-
currency: formState.currency,
|
|
99
|
-
});
|
|
100
|
-
onClose();
|
|
101
|
-
} catch {
|
|
102
|
-
setFormState((state) => ({ ...state, error: t("提交失败,请重试") }));
|
|
103
|
-
} finally {
|
|
104
|
-
setFormState((state) => ({ ...state, loading: false }));
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<Modal visible={visible} onClose={onClose} title={t("充值 / 转账")}>
|
|
110
|
-
{/* tab 按钮区域 */}
|
|
111
|
-
<div
|
|
112
|
-
style={{
|
|
113
|
-
display: "flex",
|
|
114
|
-
marginBottom: size === Size.SMALL ? 16 : 28,
|
|
115
|
-
}}
|
|
116
|
-
>
|
|
117
|
-
<button
|
|
118
|
-
type="button"
|
|
119
|
-
onClick={() => setActiveTab("online")}
|
|
120
|
-
style={theme.tabBtn(activeTab === "online", true)}
|
|
121
|
-
>
|
|
122
|
-
{t("在线充值")}
|
|
123
|
-
</button>
|
|
124
|
-
<button
|
|
125
|
-
type="button"
|
|
126
|
-
onClick={() => setActiveTab("offline")}
|
|
127
|
-
style={theme.tabBtn(activeTab === "offline", false)}
|
|
128
|
-
>
|
|
129
|
-
{t("线下转账")}
|
|
130
|
-
</button>
|
|
131
|
-
</div>
|
|
132
|
-
{/* tab 内容区域 */}
|
|
133
|
-
{activeTab === "online" ? (
|
|
134
|
-
<form onSubmit={handleSubmit}>
|
|
135
|
-
<OnlineRechargeForm
|
|
136
|
-
formState={formState}
|
|
137
|
-
setFormState={setFormState}
|
|
138
|
-
onClose={onClose}
|
|
139
|
-
loading={formState.loading}
|
|
140
|
-
/>
|
|
141
|
-
</form>
|
|
142
|
-
) : (
|
|
143
|
-
<OfflineTransferForm
|
|
144
|
-
formState={offlineFormState}
|
|
145
|
-
setFormState={setOfflineFormState}
|
|
146
|
-
onClose={onClose}
|
|
147
|
-
loading={offlineFormState.loading}
|
|
148
|
-
/>
|
|
149
|
-
)}
|
|
150
|
-
</Modal>
|
|
151
|
-
);
|
|
152
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Size, Theme, type ThemeConfig } from "@/types";
|
|
2
|
-
import { getInitParams } from "@/utils/business";
|
|
3
|
-
const size = getInitParams<Size>("size");
|
|
4
|
-
export const rechargeThemes = {
|
|
5
|
-
white: {
|
|
6
|
-
tabBtn: (active: boolean, left: boolean) => ({
|
|
7
|
-
flex: 1,
|
|
8
|
-
background: active ? "#fff" : "#F7F8FA",
|
|
9
|
-
color: active ? "#1890ff" : "#222",
|
|
10
|
-
border: "none",
|
|
11
|
-
borderRadius: left ? "8px 0 0 8px" : "0 8px 8px 0",
|
|
12
|
-
fontWeight: active ? 600 : 400,
|
|
13
|
-
fontSize: size === Size.SMALL ? 12 : 16,
|
|
14
|
-
height: size === Size.SMALL ? 32 : 48,
|
|
15
|
-
boxShadow: active ? "0 2px 8px 0 rgba(20,20,20,0.04)" : "none",
|
|
16
|
-
outline: "none",
|
|
17
|
-
cursor: "pointer",
|
|
18
|
-
borderRight: left ? "1px solid #F0F1F3" : undefined,
|
|
19
|
-
borderLeft: !left ? "1px solid #F0F1F3" : undefined,
|
|
20
|
-
transition: "all 0.2s",
|
|
21
|
-
}),
|
|
22
|
-
},
|
|
23
|
-
dark: {
|
|
24
|
-
tabBtn: (active: boolean, left: boolean) => ({
|
|
25
|
-
flex: 1,
|
|
26
|
-
background: active ? "#23262F" : "#181A20",
|
|
27
|
-
color: active ? "#00E8C6" : "#fff",
|
|
28
|
-
border: "none",
|
|
29
|
-
borderRadius: left ? "8px 0 0 8px" : "0 8px 8px 0",
|
|
30
|
-
fontWeight: active ? 600 : 400,
|
|
31
|
-
fontSize: size === Size.SMALL ? 12 : 16,
|
|
32
|
-
height: size === Size.SMALL ? 32 : 48,
|
|
33
|
-
boxShadow: active ? "0 2px 8px 0 rgba(20,20,20,0.10)" : "none",
|
|
34
|
-
outline: "none",
|
|
35
|
-
cursor: "pointer",
|
|
36
|
-
borderRight: left ? "1px solid #23262F" : undefined,
|
|
37
|
-
borderLeft: !left ? "1px solid #23262F" : undefined,
|
|
38
|
-
transition: "all 0.2s",
|
|
39
|
-
}),
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export function getRechargeTheme() {
|
|
44
|
-
const theme = getInitParams<Theme>("theme");
|
|
45
|
-
const themeConfig = getInitParams<ThemeConfig>("themeConfig");
|
|
46
|
-
const whiteTheme = theme === Theme.WHITE;
|
|
47
|
-
const baseTheme = whiteTheme ? rechargeThemes.white : rechargeThemes.dark;
|
|
48
|
-
|
|
49
|
-
// 如果初始化时传入了主题配置,则覆盖默认配置
|
|
50
|
-
if (themeConfig) {
|
|
51
|
-
const config = whiteTheme ? themeConfig.white : themeConfig.dark;
|
|
52
|
-
if (config?.color) {
|
|
53
|
-
return {
|
|
54
|
-
...baseTheme,
|
|
55
|
-
tabBtn: (active: boolean, left: boolean) => ({
|
|
56
|
-
...baseTheme.tabBtn(active, left),
|
|
57
|
-
color: active ? config.color : baseTheme.tabBtn(active, left).color,
|
|
58
|
-
}),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return baseTheme;
|
|
64
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { useState } from "preact/hooks";
|
|
2
|
-
import { Button } from "@/components/common/button";
|
|
3
|
-
import { Recharge } from "./components/recharge";
|
|
4
|
-
import register from "preact-custom-element";
|
|
5
|
-
import { createOnlineRecharge } from "@/api";
|
|
6
|
-
import { t } from "@/local";
|
|
7
|
-
|
|
8
|
-
export function BestUnit() {
|
|
9
|
-
const [visible, setVisible] = useState(false);
|
|
10
|
-
const handleSubmit = async (form: {
|
|
11
|
-
amount: string;
|
|
12
|
-
rechargeChannel: string;
|
|
13
|
-
currency: string;
|
|
14
|
-
}) => {
|
|
15
|
-
const result = await createOnlineRecharge({
|
|
16
|
-
amount: form.amount,
|
|
17
|
-
currency: form.currency,
|
|
18
|
-
rechargeChannel: form.rechargeChannel,
|
|
19
|
-
});
|
|
20
|
-
window.open(result, "_blank");
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<div>
|
|
25
|
-
<Button onClick={() => setVisible(true)}>{t("充值/转账")}</Button>
|
|
26
|
-
<Recharge
|
|
27
|
-
visible={visible}
|
|
28
|
-
onClose={() => setVisible(false)}
|
|
29
|
-
onSubmit={handleSubmit}
|
|
30
|
-
/>
|
|
31
|
-
</div>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
register(BestUnit, "best-recharge", ["theme"], { shadow: false });
|
|
36
|
-
|
|
37
|
-
export default BestUnit;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { useState } from "preact/hooks";
|
|
2
|
-
import register from "preact-custom-element";
|
|
3
|
-
import { getRefreshButtonTheme, getRefreshButtonSizeStyles } from "./theme";
|
|
4
|
-
import { refreshBalance } from "@/utils/business";
|
|
5
|
-
import { Button } from "@/components/common/button";
|
|
6
|
-
|
|
7
|
-
interface RefreshButtonProps {
|
|
8
|
-
color?: string;
|
|
9
|
-
size?: "small" | "medium" | "large";
|
|
10
|
-
children?: any; // slot 内容
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function RefreshButton({
|
|
14
|
-
color,
|
|
15
|
-
size = "medium",
|
|
16
|
-
children,
|
|
17
|
-
}: RefreshButtonProps) {
|
|
18
|
-
const [isSpinning, setIsSpinning] = useState(false);
|
|
19
|
-
const theme = getRefreshButtonTheme(color);
|
|
20
|
-
const sizeStyles = getRefreshButtonSizeStyles(size);
|
|
21
|
-
|
|
22
|
-
const buttonStyle = {
|
|
23
|
-
...theme,
|
|
24
|
-
...sizeStyles,
|
|
25
|
-
display: "flex",
|
|
26
|
-
alignItems: "center",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// 内联 CSS 动画定义
|
|
30
|
-
const spinAnimation = `
|
|
31
|
-
@keyframes spin {
|
|
32
|
-
from {
|
|
33
|
-
transform: rotate(0deg);
|
|
34
|
-
}
|
|
35
|
-
to {
|
|
36
|
-
transform: rotate(360deg);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.refresh-icon {
|
|
41
|
-
transform-origin: center;
|
|
42
|
-
will-change: transform;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/* 隐藏 fallback content */
|
|
46
|
-
:host {
|
|
47
|
-
display: inline-block;
|
|
48
|
-
}
|
|
49
|
-
`;
|
|
50
|
-
|
|
51
|
-
const handleClick = async () => {
|
|
52
|
-
setIsSpinning(true);
|
|
53
|
-
try {
|
|
54
|
-
// 触发刷新事件
|
|
55
|
-
refreshBalance();
|
|
56
|
-
// 确保动画至少显示一段时间,给用户视觉反馈
|
|
57
|
-
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
58
|
-
} finally {
|
|
59
|
-
setIsSpinning(false);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<>
|
|
65
|
-
{/* 注入 CSS 动画 */}
|
|
66
|
-
<style>{spinAnimation}</style>
|
|
67
|
-
|
|
68
|
-
<Button onClick={handleClick} color={color}>
|
|
69
|
-
<div style={buttonStyle}>
|
|
70
|
-
<svg
|
|
71
|
-
className="refresh-icon"
|
|
72
|
-
width={size === "small" ? "14" : size === "large" ? "24" : "18"}
|
|
73
|
-
height={size === "small" ? "14" : size === "large" ? "24" : "18"}
|
|
74
|
-
viewBox="0 0 24 24"
|
|
75
|
-
fill="none"
|
|
76
|
-
stroke="currentColor"
|
|
77
|
-
strokeWidth="2"
|
|
78
|
-
strokeLinecap="round"
|
|
79
|
-
strokeLinejoin="round"
|
|
80
|
-
style={{
|
|
81
|
-
animation: isSpinning ? "spin 0.6s linear infinite" : "none",
|
|
82
|
-
transition: "all 0.2s ease",
|
|
83
|
-
}}
|
|
84
|
-
>
|
|
85
|
-
<path d="M21 2v6h-6"></path>
|
|
86
|
-
<path d="M3 12a9 9 0 0 1 15-6.7L21 8"></path>
|
|
87
|
-
<path d="M3 22v-6h6"></path>
|
|
88
|
-
<path d="M21 12a9 9 0 0 1-15 6.7L3 16"></path>
|
|
89
|
-
</svg>
|
|
90
|
-
{children && <span>{children}</span>}
|
|
91
|
-
</div>
|
|
92
|
-
</Button>
|
|
93
|
-
</>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
register(RefreshButton, "best-refresh-button", [], { shadow: true });
|
|
98
|
-
|
|
99
|
-
export default RefreshButton;
|