best-unit 0.0.37 → 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/dist/best-unit.cjs +7 -7
- package/dist/best-unit.js +2977 -2898
- package/dist/types/global.d.ts +4 -4
- package/dist/types/index.ts +9 -0
- package/package.json +1 -1
- package/src/components/business/recharge-sdk/components/OfflineTransferForm.tsx +6 -3
- package/src/components/business/recharge-sdk/components/OnlineRechargeForm.tsx +6 -2
- package/src/components/business/recharge-sdk/components/Recharge.tsx +8 -10
- package/src/components/business/recharge-sdk/index.tsx +2 -19
- package/src/components/business/statistical-balance/index.tsx +113 -61
- package/src/components/common/HoverPopover.tsx +43 -8
- package/src/components/common/Upload.tsx +90 -37
- package/src/demo/App.tsx +188 -35
- package/src/local/index.ts +4 -10
- package/src/types/global.d.ts +4 -4
- package/src/types/index.ts +9 -0
- package/src/utils/business/index.ts +8 -4
package/dist/types/global.d.ts
CHANGED
|
@@ -7,15 +7,15 @@ export declare function initFundUnit(params: {
|
|
|
7
7
|
merchant_id?: string;
|
|
8
8
|
biz_type?: string;
|
|
9
9
|
fund_balance_id?: string;
|
|
10
|
-
theme?:
|
|
11
|
-
locale?:
|
|
10
|
+
theme?: Theme;
|
|
11
|
+
locale?: Locale;
|
|
12
12
|
}): {
|
|
13
13
|
token: string;
|
|
14
14
|
merchantId?: string;
|
|
15
15
|
bizType?: string;
|
|
16
16
|
fundBalanceId?: string;
|
|
17
|
-
theme?:
|
|
18
|
-
locale:
|
|
17
|
+
theme?: Theme;
|
|
18
|
+
locale: Locale;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
// Vite 代理配置类型
|
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
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,13 +18,7 @@ interface ModalFormProps {
|
|
|
17
18
|
token?: string;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export function Recharge({
|
|
21
|
-
visible,
|
|
22
|
-
onClose,
|
|
23
|
-
onSubmit,
|
|
24
|
-
color,
|
|
25
|
-
whiteTheme = true,
|
|
26
|
-
}: ModalFormProps & { whiteTheme?: boolean }) {
|
|
21
|
+
export function Recharge({ visible, onClose, onSubmit }: ModalFormProps) {
|
|
27
22
|
const [formState, setFormState] = useState({
|
|
28
23
|
amount: "",
|
|
29
24
|
rechargeChannel: "",
|
|
@@ -115,6 +110,11 @@ export function Recharge({
|
|
|
115
110
|
}
|
|
116
111
|
};
|
|
117
112
|
|
|
113
|
+
const fundUnitParams = JSON.parse(
|
|
114
|
+
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
115
|
+
);
|
|
116
|
+
const whiteTheme = fundUnitParams.theme === Theme.WHITE;
|
|
117
|
+
|
|
118
118
|
const theme = whiteTheme
|
|
119
119
|
? {
|
|
120
120
|
modalBg: "#fff",
|
|
@@ -221,7 +221,7 @@ export function Recharge({
|
|
|
221
221
|
borderRadius: 12,
|
|
222
222
|
minWidth: 400,
|
|
223
223
|
maxWidth: 400,
|
|
224
|
-
color:
|
|
224
|
+
color: theme.modalColor,
|
|
225
225
|
boxShadow: theme.modalBoxShadow,
|
|
226
226
|
position: "relative",
|
|
227
227
|
}}
|
|
@@ -261,7 +261,6 @@ export function Recharge({
|
|
|
261
261
|
setFormState={setFormState}
|
|
262
262
|
onClose={onClose}
|
|
263
263
|
loading={formState.loading}
|
|
264
|
-
whiteTheme={whiteTheme}
|
|
265
264
|
/>
|
|
266
265
|
) : (
|
|
267
266
|
<OfflineTransferForm
|
|
@@ -269,7 +268,6 @@ export function Recharge({
|
|
|
269
268
|
setFormState={setOfflineFormState}
|
|
270
269
|
onClose={onClose}
|
|
271
270
|
loading={offlineFormState.loading}
|
|
272
|
-
whiteTheme={whiteTheme}
|
|
273
271
|
/>
|
|
274
272
|
)}
|
|
275
273
|
</form>
|
|
@@ -5,11 +5,8 @@ import register from "preact-custom-element";
|
|
|
5
5
|
import { createOnlineRecharge } from "../../../api";
|
|
6
6
|
import { t } from "../../../local";
|
|
7
7
|
|
|
8
|
-
export function BestUnit(
|
|
8
|
+
export function BestUnit() {
|
|
9
9
|
const [visible, setVisible] = useState(false);
|
|
10
|
-
const [whiteTheme, setWhiteTheme] = useState(true);
|
|
11
|
-
const color = props.theme?.primaryColor;
|
|
12
|
-
|
|
13
10
|
const handleSubmit = async (form: {
|
|
14
11
|
amount: string;
|
|
15
12
|
rechargeChannel: string;
|
|
@@ -25,27 +22,13 @@ export function BestUnit(props: any) {
|
|
|
25
22
|
|
|
26
23
|
return (
|
|
27
24
|
<div>
|
|
28
|
-
<ThemedButton
|
|
25
|
+
<ThemedButton onClick={() => setVisible(true)}>
|
|
29
26
|
{t("充值/转账")}
|
|
30
27
|
</ThemedButton>
|
|
31
|
-
<button
|
|
32
|
-
style={{
|
|
33
|
-
marginLeft: 16,
|
|
34
|
-
padding: "8px 16px",
|
|
35
|
-
borderRadius: 6,
|
|
36
|
-
border: "1px solid #eee",
|
|
37
|
-
cursor: "pointer",
|
|
38
|
-
}}
|
|
39
|
-
onClick={() => setWhiteTheme((v) => !v)}
|
|
40
|
-
>
|
|
41
|
-
{whiteTheme ? t("切换为暗黑主题") : t("切换为白色主题")}
|
|
42
|
-
</button>
|
|
43
28
|
<Recharge
|
|
44
29
|
visible={visible}
|
|
45
30
|
onClose={() => setVisible(false)}
|
|
46
31
|
onSubmit={handleSubmit}
|
|
47
|
-
color={color}
|
|
48
|
-
whiteTheme={whiteTheme}
|
|
49
32
|
/>
|
|
50
33
|
</div>
|
|
51
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
|
-
|
|
86
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
64
|
-
|
|
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("移除")}
|