best-unit 0.0.38 → 0.0.39

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.38",
4
+ "version": "0.0.39",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
@@ -3,6 +3,7 @@ import { Upload } from "../../../common/Upload";
3
3
  import { createOfflineRecharge } from "../../../../api";
4
4
  import { message } from "../../../common/Message";
5
5
  import { t } from "../../../../local";
6
+ import { Theme } from "../../../../types";
6
7
 
7
8
  interface OfflineTransferFormProps {
8
9
  formState: {
@@ -17,16 +18,18 @@ interface OfflineTransferFormProps {
17
18
  setFormState: (fn: (state: any) => any) => void;
18
19
  onClose: () => void;
19
20
  loading: boolean;
20
- whiteTheme?: boolean;
21
21
  }
22
22
 
23
23
  export const OfflineTransferForm: FunctionalComponent<
24
24
  OfflineTransferFormProps
25
- > = ({ formState, setFormState, onClose, loading, whiteTheme = false }) => {
25
+ > = ({ formState, setFormState, onClose, loading }) => {
26
26
  const allDicts = JSON.parse(sessionStorage.getItem("all_dicts") || "{}");
27
27
  console.log(allDicts, "allDicts");
28
28
  const channelDict = allDicts?.channel || [];
29
-
29
+ const fundUnitParams = JSON.parse(
30
+ sessionStorage.getItem("fund_unit_params") || "{}"
31
+ );
32
+ const whiteTheme = fundUnitParams.theme === Theme.WHITE;
30
33
  // 样式对象
31
34
  const theme = whiteTheme
32
35
  ? {
@@ -1,5 +1,6 @@
1
1
  import type { FunctionalComponent } from "preact";
2
2
  import { t } from "../../../../local";
3
+ import { Theme } from "../../../../types";
3
4
 
4
5
  interface OnlineRechargeFormProps {
5
6
  formState: {
@@ -15,16 +16,19 @@ interface OnlineRechargeFormProps {
15
16
  setFormState: (fn: (state: any) => any) => void;
16
17
  onClose: () => void;
17
18
  loading: boolean;
18
- whiteTheme?: boolean;
19
19
  }
20
20
 
21
21
  export const OnlineRechargeForm: FunctionalComponent<
22
22
  OnlineRechargeFormProps
23
- > = ({ formState, setFormState, onClose, loading, whiteTheme = false }) => {
23
+ > = ({ formState, setFormState, onClose, loading }) => {
24
24
  const allDicts = JSON.parse(sessionStorage.getItem("all_dicts") || "{}");
25
25
  const currencyDict = allDicts?.currency || [];
26
26
  const channelDict =
27
27
  allDicts?.channel?.filter((item: any) => item.payment_support) || [];
28
+ const fundUnitParams = JSON.parse(
29
+ sessionStorage.getItem("fund_unit_params") || "{}"
30
+ );
31
+ const whiteTheme = fundUnitParams.theme === Theme.WHITE;
28
32
 
29
33
  const theme = whiteTheme
30
34
  ? {
@@ -2,6 +2,7 @@ import { useState, useEffect } from "preact/hooks";
2
2
  import { OnlineRechargeForm } from "./OnlineRechargeForm";
3
3
  import { OfflineTransferForm } from "./OfflineTransferForm";
4
4
  import { t } from "../../../../local";
5
+ import { Theme } from "../../../../types";
5
6
 
6
7
  interface ModalFormProps {
7
8
  visible: boolean;
@@ -17,12 +18,7 @@ interface ModalFormProps {
17
18
  token?: string;
18
19
  }
19
20
 
20
- export function Recharge({
21
- visible,
22
- onClose,
23
- onSubmit,
24
- whiteTheme = true,
25
- }: ModalFormProps & { whiteTheme?: boolean }) {
21
+ export function Recharge({ visible, onClose, onSubmit }: ModalFormProps) {
26
22
  const [formState, setFormState] = useState({
27
23
  amount: "",
28
24
  rechargeChannel: "",
@@ -114,6 +110,11 @@ export function Recharge({
114
110
  }
115
111
  };
116
112
 
113
+ const fundUnitParams = JSON.parse(
114
+ sessionStorage.getItem("fund_unit_params") || "{}"
115
+ );
116
+ const whiteTheme = fundUnitParams.theme === Theme.WHITE;
117
+
117
118
  const theme = whiteTheme
118
119
  ? {
119
120
  modalBg: "#fff",
@@ -260,7 +261,6 @@ export function Recharge({
260
261
  setFormState={setFormState}
261
262
  onClose={onClose}
262
263
  loading={formState.loading}
263
- whiteTheme={whiteTheme}
264
264
  />
265
265
  ) : (
266
266
  <OfflineTransferForm
@@ -268,7 +268,6 @@ export function Recharge({
268
268
  setFormState={setOfflineFormState}
269
269
  onClose={onClose}
270
270
  loading={offlineFormState.loading}
271
- whiteTheme={whiteTheme}
272
271
  />
273
272
  )}
274
273
  </form>
@@ -4,13 +4,9 @@ import { Recharge } from "./components/Recharge";
4
4
  import register from "preact-custom-element";
5
5
  import { createOnlineRecharge } from "../../../api";
6
6
  import { t } from "../../../local";
7
- import { Theme } from "../../../types";
8
7
 
9
8
  export function BestUnit() {
10
9
  const [visible, setVisible] = useState(false);
11
- const fundUnitParams = JSON.parse(
12
- sessionStorage.getItem("fund_unit_params") || "{}"
13
- );
14
10
  const handleSubmit = async (form: {
15
11
  amount: string;
16
12
  rechargeChannel: string;
@@ -33,7 +29,6 @@ export function BestUnit() {
33
29
  visible={visible}
34
30
  onClose={() => setVisible(false)}
35
31
  onSubmit={handleSubmit}
36
- whiteTheme={fundUnitParams.theme === Theme.WHITE}
37
32
  />
38
33
  </div>
39
34
  );
@@ -3,6 +3,7 @@ import HoverPopover, { type PopoverPosition } from "../../common/HoverPopover";
3
3
  import { getBalance } from "../../../api";
4
4
  import { t } from "../../../local";
5
5
  import register from "preact-custom-element";
6
+ import { Theme } from "../../../types";
6
7
 
7
8
  function formatNumber(num: number) {
8
9
  return num.toLocaleString("en-US", {
@@ -11,6 +12,105 @@ function formatNumber(num: number) {
11
12
  });
12
13
  }
13
14
 
15
+ const balanceTheme = {
16
+ white: {
17
+ popoverTitle: {
18
+ fontSize: 16,
19
+ fontWeight: 600,
20
+ color: "#222",
21
+ marginBottom: 16,
22
+ textAlign: "center",
23
+ },
24
+ detailRow: {
25
+ display: "flex",
26
+ justifyContent: "space-between",
27
+ alignItems: "center",
28
+ padding: "8px 0",
29
+ borderBottom: "1px solid #e5e7eb",
30
+ fontSize: 15,
31
+ },
32
+ detailLabel: {
33
+ display: "flex",
34
+ alignItems: "center",
35
+ color: "#6b7280",
36
+ fontWeight: 500,
37
+ },
38
+ detailDot: (color: string) => ({
39
+ display: "inline-block",
40
+ width: 8,
41
+ height: 8,
42
+ borderRadius: "50%",
43
+ background: color,
44
+ marginRight: 8,
45
+ }),
46
+ detailValue: (color: string) => ({
47
+ color,
48
+ fontWeight: 600,
49
+ fontSize: 15,
50
+ }),
51
+ main: {
52
+ fontSize: 24,
53
+ fontWeight: 800,
54
+ color: "#111827",
55
+ display: "inline-block",
56
+ },
57
+ currency: {
58
+ fontSize: 18,
59
+ color: "#6b7280",
60
+ marginLeft: 8,
61
+ fontWeight: 600,
62
+ },
63
+ },
64
+ dark: {
65
+ popoverTitle: {
66
+ fontSize: 16,
67
+ fontWeight: 600,
68
+ color: "#fff",
69
+ marginBottom: 16,
70
+ textAlign: "center",
71
+ },
72
+ detailRow: {
73
+ display: "flex",
74
+ justifyContent: "space-between",
75
+ alignItems: "center",
76
+ padding: "8px 0",
77
+ borderBottom: "1px solid #23262F",
78
+ fontSize: 15,
79
+ },
80
+ detailLabel: {
81
+ display: "flex",
82
+ alignItems: "center",
83
+ color: "#B5B8BE",
84
+ fontWeight: 500,
85
+ },
86
+ detailDot: (color: string) => ({
87
+ display: "inline-block",
88
+ width: 8,
89
+ height: 8,
90
+ borderRadius: "50%",
91
+ background: color,
92
+ marginRight: 8,
93
+ }),
94
+ detailValue: (color: string) => ({
95
+ color,
96
+ fontWeight: 600,
97
+ fontSize: 15,
98
+ }),
99
+ main: {
100
+ fontSize: 24,
101
+ fontWeight: 800,
102
+ color: "#fff",
103
+ display: "inline-block",
104
+ },
105
+ currency: {
106
+ fontSize: 18,
107
+ color: "#B5B8BE",
108
+ marginLeft: 8,
109
+ fontWeight: 600,
110
+ },
111
+ },
112
+ };
113
+
14
114
  function StatisticalBalance(props: { popoverPosition?: PopoverPosition }) {
15
115
  const [balanceData, setBalanceData] = useState({
16
116
  available: 0,
@@ -65,56 +165,24 @@ function StatisticalBalance(props: { popoverPosition?: PopoverPosition }) {
65
165
  fetchBalance();
66
166
  }, []);
67
167
 
168
+ const fundUnitParams = JSON.parse(
169
+ sessionStorage.getItem("fund_unit_params") || "{}"
170
+ );
171
+ const whiteTheme = fundUnitParams.theme === Theme.WHITE;
172
+ const theme = balanceTheme[whiteTheme ? "white" : "dark"];
173
+
68
174
  return (
69
175
  <HoverPopover
70
176
  popover={
71
177
  <>
72
- <div
73
- style={{
74
- fontSize: 16,
75
- fontWeight: 600,
76
- color: "#222",
77
- marginBottom: 16,
78
- textAlign: "center",
79
- }}
80
- >
81
- {t("余额详情")}
82
- </div>
178
+ <div style={theme.popoverTitle}>{t("余额详情")}</div>
83
179
  {balanceData.details.map((item) => (
84
- <div
85
- key={item.label}
86
- style={{
87
- display: "flex",
88
- justifyContent: "space-between",
89
- alignItems: "center",
90
- padding: "8px 0",
91
- borderBottom: "1px solid #e5e7eb",
92
- fontSize: 15,
93
- }}
94
- >
95
- <span
96
- style={{
97
- display: "flex",
98
- alignItems: "center",
99
- color: "#6b7280",
100
- fontWeight: 500,
101
- }}
102
- >
103
- <span
104
- style={{
105
- display: "inline-block",
106
- width: 8,
107
- height: 8,
108
- borderRadius: "50%",
109
- background: item.dot,
110
- marginRight: 8,
111
- }}
112
- />
180
+ <div key={item.label} style={theme.detailRow}>
181
+ <span style={theme.detailLabel}>
182
+ <span style={theme.detailDot(item.dot)} />
113
183
  {item.label}
114
184
  </span>
115
- <span
116
- style={{ color: item.color, fontWeight: 600, fontSize: 15 }}
117
- >
185
+ <span style={theme.detailValue(item.color)}>
118
186
  {balanceData.symbol}
119
187
  {formatNumber(item.value)}
120
188
  </span>
@@ -124,26 +192,10 @@ function StatisticalBalance(props: { popoverPosition?: PopoverPosition }) {
124
192
  }
125
193
  popoverPosition={props.popoverPosition || "bottom"}
126
194
  >
127
- <div
128
- style={{
129
- fontSize: 24,
130
- fontWeight: 800,
131
- color: "#111827",
132
- display: "inline-block",
133
- }}
134
- >
195
+ <div style={theme.main}>
135
196
  {balanceData.symbol}
136
197
  {formatNumber(balanceData.available)}
137
- <span
138
- style={{
139
- fontSize: 18,
140
- color: "#6b7280",
141
- marginLeft: 8,
142
- fontWeight: 600,
143
- }}
144
- >
145
- {balanceData.currency}
146
- </span>
198
+ <span style={theme.currency}>{balanceData.currency}</span>
147
199
  </div>
148
200
  </HoverPopover>
149
201
  );
@@ -1,5 +1,6 @@
1
1
  import { useState, useRef } from "preact/hooks";
2
2
  import type { FunctionalComponent, JSX } from "preact";
3
+ import { Theme } from "../../types";
3
4
 
4
5
  export type PopoverPosition = "top" | "bottom" | "leftTop" | "rightTop";
5
6
  interface HoverPopoverProps {
@@ -65,22 +66,56 @@ const HoverPopover: FunctionalComponent<HoverPopoverProps> = ({
65
66
  }, 120);
66
67
  };
67
68
 
69
+ const popoverTheme = {
70
+ white: {
71
+ popover: {
72
+ background: "#fff",
73
+ color: "#222",
74
+ boxShadow: "0 4px 16px rgba(0,0,0,0.12)",
75
+ border: "none",
76
+ },
77
+ arrow: {
78
+ top: "#fff",
79
+ bottom: "#fff",
80
+ left: "#fff",
81
+ right: "#fff",
82
+ },
83
+ },
84
+ dark: {
85
+ popover: {
86
+ background: "#23262F",
87
+ color: "#fff",
88
+ boxShadow: "0 4px 16px rgba(0,0,0,0.32)",
89
+ border: "1px solid #444C5C",
90
+ },
91
+ arrow: {
92
+ top: "#23262F",
93
+ bottom: "#23262F",
94
+ left: "#23262F",
95
+ right: "#23262F",
96
+ },
97
+ },
98
+ };
99
+
68
100
  // 弹层定位样式
101
+ const fundUnitParams = JSON.parse(
102
+ sessionStorage.getItem("fund_unit_params") || "{}"
103
+ );
104
+ const whiteTheme = fundUnitParams.theme === Theme.WHITE;
105
+ const theme = popoverTheme[whiteTheme ? "white" : "dark"];
106
+
69
107
  let popoverStyle: any = {
70
108
  position: "absolute",
71
109
  zIndex: 999,
72
- background: "#fff",
73
- color: "#222",
74
110
  borderRadius: 6,
75
111
  fontSize: 15,
76
112
  minWidth: popoverMinWidth,
77
113
  width: popoverWidth,
78
114
  padding: "8px 14px",
79
- boxShadow: "0 4px 16px rgba(0,0,0,0.12)",
80
115
  pointerEvents: "auto",
81
116
  textAlign: "center",
82
- border: "none",
83
117
  animation: "fadeInUp 0.3s",
118
+ ...theme.popover,
84
119
  };
85
120
  let arrowStyle: any = {
86
121
  position: "absolute",
@@ -102,7 +137,7 @@ const HoverPopover: FunctionalComponent<HoverPopoverProps> = ({
102
137
  transform: "translateX(-50%)",
103
138
  borderLeft: "8px solid transparent",
104
139
  borderRight: "8px solid transparent",
105
- borderTop: "8px solid #fff",
140
+ borderTop: `8px solid ${theme.arrow.top}`,
106
141
  };
107
142
  } else if (position === "bottom") {
108
143
  popoverStyle = {
@@ -119,7 +154,7 @@ const HoverPopover: FunctionalComponent<HoverPopoverProps> = ({
119
154
  transform: "translateX(-50%)",
120
155
  borderLeft: "8px solid transparent",
121
156
  borderRight: "8px solid transparent",
122
- borderBottom: "8px solid #fff",
157
+ borderBottom: `8px solid ${theme.arrow.bottom}`,
123
158
  };
124
159
  } else if (position === "leftTop") {
125
160
  popoverStyle = {
@@ -135,7 +170,7 @@ const HoverPopover: FunctionalComponent<HoverPopoverProps> = ({
135
170
  top: 12,
136
171
  borderTop: "8px solid transparent",
137
172
  borderBottom: "8px solid transparent",
138
- borderLeft: "8px solid #fff",
173
+ borderLeft: `8px solid ${theme.arrow.left}`,
139
174
  };
140
175
  } else if (position === "rightTop") {
141
176
  popoverStyle = {
@@ -151,7 +186,7 @@ const HoverPopover: FunctionalComponent<HoverPopoverProps> = ({
151
186
  top: 12,
152
187
  borderTop: "8px solid transparent",
153
188
  borderBottom: "8px solid transparent",
154
- borderRight: "8px solid #fff",
189
+ borderRight: `8px solid ${theme.arrow.right}`,
155
190
  };
156
191
  }
157
192
 
@@ -2,6 +2,7 @@ import type { FunctionalComponent } from "preact";
2
2
  import { useRef, useState } from "preact/hooks";
3
3
  import { uploadFile } from "../../api";
4
4
  import { t } from "../../local";
5
+ import { Theme } from "../../types";
5
6
 
6
7
  interface UploadProps {
7
8
  value?: string[];
@@ -12,6 +13,85 @@ interface UploadProps {
12
13
  disabled?: boolean;
13
14
  }
14
15
 
16
+ const uploadTheme = {
17
+ white: {
18
+ container: {
19
+ border: "1px dashed #E5E6EB",
20
+ borderRadius: 8,
21
+ background: "#FCFCFD",
22
+ padding: 24,
23
+ textAlign: "center",
24
+ cursor: "pointer",
25
+ minHeight: 120,
26
+ display: "flex",
27
+ flexDirection: "column",
28
+ alignItems: "center",
29
+ justifyContent: "center",
30
+ color: "#999",
31
+ fontSize: 15,
32
+ },
33
+ fileItem: {
34
+ display: "flex",
35
+ alignItems: "center",
36
+ background: "#F7F8FA",
37
+ borderRadius: 8,
38
+ padding: "12px 16px",
39
+ marginBottom: 8,
40
+ fontSize: 15,
41
+ color: "#222",
42
+ justifyContent: "space-between",
43
+ },
44
+ removeBtn: {
45
+ background: "#FF4D4F",
46
+ color: "#fff",
47
+ border: "none",
48
+ borderRadius: 6,
49
+ padding: "4px 14px",
50
+ fontSize: 15,
51
+ marginLeft: 16,
52
+ cursor: "pointer",
53
+ },
54
+ },
55
+ dark: {
56
+ container: {
57
+ border: "1.5px dashed #444C5C",
58
+ borderRadius: 8,
59
+ background: "#181A20",
60
+ padding: 24,
61
+ textAlign: "center",
62
+ cursor: "pointer",
63
+ minHeight: 120,
64
+ display: "flex",
65
+ flexDirection: "column",
66
+ alignItems: "center",
67
+ justifyContent: "center",
68
+ color: "#999",
69
+ fontSize: 15,
70
+ },
71
+ fileItem: {
72
+ display: "flex",
73
+ alignItems: "center",
74
+ background: "#23262F",
75
+ borderRadius: 8,
76
+ padding: "12px 16px",
77
+ marginBottom: 8,
78
+ fontSize: 15,
79
+ color: "#fff",
80
+ justifyContent: "space-between",
81
+ },
82
+ removeBtn: {
83
+ background: "#FF4D4F",
84
+ color: "#fff",
85
+ border: "none",
86
+ borderRadius: 6,
87
+ padding: "4px 14px",
88
+ fontSize: 15,
89
+ marginLeft: 16,
90
+ cursor: "pointer",
91
+ },
92
+ },
93
+ };
94
+
15
95
  export const Upload: FunctionalComponent<UploadProps> = ({
16
96
  value = [],
17
97
  onChange,
@@ -23,6 +103,12 @@ export const Upload: FunctionalComponent<UploadProps> = ({
23
103
  const fileInputRef = useRef<HTMLInputElement>(null);
24
104
  const [uploading, setUploading] = useState(false);
25
105
  const [progress, setProgress] = useState(0);
106
+ const fundUnitParams = JSON.parse(
107
+ sessionStorage.getItem("fund_unit_params") || "{}"
108
+ );
109
+ const whiteTheme = fundUnitParams.theme === Theme.WHITE;
110
+ const themeKey = whiteTheme ? "white" : "dark";
111
+ const theme = uploadTheme[themeKey];
26
112
 
27
113
  const handleFileChange = async (e: any) => {
28
114
  const files: File[] = Array.from(e.target.files as FileList).slice(
@@ -60,19 +146,8 @@ export const Upload: FunctionalComponent<UploadProps> = ({
60
146
  <div>
61
147
  <div
62
148
  style={{
63
- border: "1px dashed #E5E6EB",
64
- borderRadius: 8,
65
- background: "#FCFCFD",
66
- padding: 24,
67
- textAlign: "center",
68
- cursor: disabled ? "not-allowed" : "pointer",
69
- minHeight: 120,
70
- display: "flex",
71
- flexDirection: "column",
72
- alignItems: "center",
73
- justifyContent: "center",
74
- color: "#999",
75
- fontSize: 15,
149
+ ...theme.container,
150
+ cursor: disabled ? "not-allowed" : theme.container.cursor,
76
151
  opacity: disabled ? 0.6 : 1,
77
152
  }}
78
153
  onClick={() => !disabled && fileInputRef.current?.click()}
@@ -103,20 +178,7 @@ export const Upload: FunctionalComponent<UploadProps> = ({
103
178
  {value && value.length > 0 && (
104
179
  <div style={{ marginTop: 12 }}>
105
180
  {value.map((url, idx) => (
106
- <div
107
- key={url}
108
- style={{
109
- display: "flex",
110
- alignItems: "center",
111
- background: "#F7F8FA",
112
- borderRadius: 8,
113
- padding: "12px 16px",
114
- marginBottom: 8,
115
- fontSize: 15,
116
- color: "#222",
117
- justifyContent: "space-between",
118
- }}
119
- >
181
+ <div key={url} style={theme.fileItem}>
120
182
  <div style={{ display: "flex", alignItems: "center", flex: 1 }}>
121
183
  <span style={{ fontWeight: 500, wordBreak: "break-all" }}>
122
184
  {url.split("/").pop()}
@@ -131,16 +193,7 @@ export const Upload: FunctionalComponent<UploadProps> = ({
131
193
  e.stopPropagation();
132
194
  handleRemove(idx);
133
195
  }}
134
- style={{
135
- background: "#FF4D4F",
136
- color: "#fff",
137
- border: "none",
138
- borderRadius: 6,
139
- padding: "4px 14px",
140
- fontSize: 15,
141
- marginLeft: 16,
142
- cursor: "pointer",
143
- }}
196
+ style={theme.removeBtn}
144
197
  disabled={disabled}
145
198
  >
146
199
  {t("移除")}