best-unit 0.0.43 → 0.0.44

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/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>组件库 Demo</title>
7
+ <title>Best Unit</title>
8
8
  </head>
9
9
  <body>
10
10
  <div id="app"></div>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "0.0.43",
4
+ "version": "0.0.44",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
@@ -5,16 +5,16 @@ import type {
5
5
  InternalAxiosRequestConfig,
6
6
  } from "axios";
7
7
  import { message } from "../components/common/Message";
8
+ import { Locale } from "../types";
8
9
 
9
10
  export interface CreateAxiosOptions {
10
11
  baseURL?: string;
11
12
  timeout?: number;
12
- getLocale?: () => string | null;
13
13
  onError?: (msg: string, error: any) => void;
14
14
  }
15
15
 
16
16
  export function createAxiosInstance(options: CreateAxiosOptions = {}) {
17
- const { baseURL = "/api", timeout = 10000, getLocale, onError } = options;
17
+ const { baseURL = "/api", timeout = 10000, onError } = options;
18
18
 
19
19
  const instance: AxiosInstance = axios.create({ baseURL, timeout });
20
20
 
@@ -23,17 +23,13 @@ export function createAxiosInstance(options: CreateAxiosOptions = {}) {
23
23
  const fundUnitParams = JSON.parse(
24
24
  sessionStorage.getItem("fund_unit_params") || "{}"
25
25
  );
26
- const { token } = fundUnitParams;
27
- config.headers = { ...config.headers, Authorization: token } as any;
26
+ const { token, locale } = fundUnitParams;
27
+ config.headers = {
28
+ ...config.headers,
29
+ Authorization: token,
30
+ "x-locale": locale === Locale.ZH ? "zh-CN" : "en-US",
31
+ } as any;
28
32
 
29
- if (getLocale) {
30
- const locale = getLocale();
31
- if (locale)
32
- config.headers = {
33
- ...config.headers,
34
- "Accept-Language": locale,
35
- } as any;
36
- }
37
33
  return config;
38
34
  });
39
35
 
package/src/api/index.ts CHANGED
@@ -94,5 +94,23 @@ export const createOnlineRecharge = async (data: any) => {
94
94
  });
95
95
  };
96
96
 
97
+ interface CalcPaymentAmountParams {
98
+ channel: string; // 支付平台,如 "stripe"
99
+ amount: string; // 充值金额,如 "10"
100
+ currency: string; // 币种,如 "USD"
101
+ }
102
+
103
+ // 计算支付金额
104
+ export const calcPaymentAmount = async (data: CalcPaymentAmountParams) => {
105
+ return http
106
+ .get("/calc-payment-amount", {
107
+ params: data,
108
+ })
109
+ .then((res) => {
110
+ const data = res.data;
111
+ return data.payment_amount;
112
+ });
113
+ };
114
+
97
115
  // 示例用法:
98
116
  // getBalance({ merchant_id: '1128', biz_type: 'ad', token: 'xxx' }).then(res => console.log(res));
@@ -1,7 +1,9 @@
1
1
  import type { FunctionalComponent } from "preact";
2
+ import { useState, useEffect } from "preact/hooks";
2
3
  import { t } from "../../../../local";
3
4
  import { Theme } from "../../../../types";
4
5
  import { Select } from "../../../common/Select";
6
+ import { calcPaymentAmount } from "../../../../api";
5
7
 
6
8
  interface OnlineRechargeFormProps {
7
9
  formState: {
@@ -30,6 +32,29 @@ export const OnlineRechargeForm: FunctionalComponent<
30
32
  sessionStorage.getItem("fund_unit_params") || "{}"
31
33
  );
32
34
  const whiteTheme = fundUnitParams.theme === Theme.WHITE;
35
+ const [actualAmount, setActualAmount] = useState<string>("");
36
+ const [showFeeTip, setShowFeeTip] = useState(false);
37
+
38
+ // 当三个参数都填写完整时,计算实际支付金额
39
+ useEffect(() => {
40
+ if (formState.currency && formState.amount && formState.rechargeChannel) {
41
+ calcPaymentAmount({
42
+ channel: formState.rechargeChannel,
43
+ amount: formState.amount,
44
+ currency: formState.currency,
45
+ })
46
+ .then((paymentAmount) => {
47
+ setActualAmount(paymentAmount);
48
+ setShowFeeTip(true);
49
+ })
50
+ .catch((error) => {
51
+ console.error("计算支付金额失败:", error);
52
+ setShowFeeTip(false);
53
+ });
54
+ } else {
55
+ setShowFeeTip(false);
56
+ }
57
+ }, [formState.currency, formState.amount, formState.rechargeChannel]);
33
58
 
34
59
  const theme = whiteTheme
35
60
  ? {
@@ -277,6 +302,25 @@ export const OnlineRechargeForm: FunctionalComponent<
277
302
  <div style={theme.error}>{formState.rechargeChannelError}</div>
278
303
  )}
279
304
  </div>
305
+ {/* 手续费提示 */}
306
+ {showFeeTip && actualAmount && (
307
+ <div
308
+ style={{
309
+ marginBottom: 24,
310
+ padding: "12px 16px",
311
+ background: whiteTheme ? "#f6ffed" : "#1a1a1a",
312
+ border: `1px solid ${whiteTheme ? "#b7eb8f" : "#333"}`,
313
+ borderRadius: 6,
314
+ fontSize: 14,
315
+ color: whiteTheme ? "#52c41a" : "#52c41a",
316
+ }}
317
+ >
318
+ {channelDict.find(
319
+ (item: any) => item.value === formState.rechargeChannel
320
+ )?.label || formState.rechargeChannel}
321
+ {t("需要收取手续费,实际支付金额约为:")}${actualAmount}
322
+ </div>
323
+ )}
280
324
  {formState.error && (
281
325
  <div style={{ color: "#ff4d4f", marginBottom: 12 }}>
282
326
  {formState.error}
package/src/local/en.ts CHANGED
@@ -6,6 +6,7 @@ export const en: Record<string, string> = {
6
6
  冻结金额: "Frozen Amount",
7
7
  总可用: "Total Available",
8
8
  暂无数据: "No Data",
9
+ "金额需在1到999999.99之间": "Amount must be between 1 and 999999.99",
9
10
 
10
11
  // 充值相关
11
12
  "充值 / 转账": "Recharge / Transfer",
@@ -17,6 +18,8 @@ export const en: Record<string, string> = {
17
18
  请选择充值币种: "Please select recharge currency",
18
19
  请输入充值金额: "Please enter recharge amount",
19
20
  请选择支付平台: "Please select payment platform",
21
+ "需要收取手续费,实际支付金额约为:":
22
+ "requires a handling fee, the actual payment amount is approximately: ",
20
23
  "提交失败,请重试": "Submit failed, please try again",
21
24
  "提交中...": "Submitting...",
22
25
  去支付: "Go to Pay",
package/src/local/zh.ts CHANGED
@@ -6,6 +6,7 @@ export const zh: Record<string, string> = {
6
6
  冻结金额: "冻结金额",
7
7
  总可用: "总可用",
8
8
  暂无数据: "暂无数据",
9
+ "金额需在1到999999.99之间": "金额需在1到999999.99之间",
9
10
 
10
11
  // 充值相关
11
12
  "充值 / 转账": "充值 / 转账",
@@ -17,6 +18,7 @@ export const zh: Record<string, string> = {
17
18
  请选择充值币种: "请选择充值币种",
18
19
  请输入充值金额: "请输入充值金额",
19
20
  请选择支付平台: "请选择支付平台",
21
+ "需要收取手续费,实际支付金额约为:": "需要收取手续费,实际支付金额约为:",
20
22
  "提交失败,请重试": "提交失败,请重试",
21
23
  "提交中...": "提交中...",
22
24
  去支付: "去支付",
package/dist/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/public/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>