Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
174f93fe11 | ||
|
|
6340f1fb54 | ||
|
|
febdc5b8e2 | ||
|
|
b5044b8753 | ||
|
|
00a60b8948 | ||
|
|
17ec70f839 | ||
|
|
ac03a93c64 | ||
|
|
5e8692eae5 | ||
|
|
2e56e93d83 | ||
|
|
11d0ff2ec3 | ||
|
|
8a59025132 | ||
|
|
5488a8ea82 | ||
|
|
18cb82a0fe | ||
|
|
f951358db4 | ||
|
|
a23162117c | ||
|
|
b13e7b89e2 | ||
|
|
2416fd1c71 | ||
|
|
2b7eb832ed | ||
|
|
1532f47da1 | ||
|
|
2fa20de631 | ||
|
|
b51e16bba8 | ||
|
|
8ae6c4fd7a | ||
|
|
53b51f0740 | ||
|
|
92b4be90d0 | ||
|
|
80a6658769 | ||
|
|
f0f4bd8bf2 | ||
|
|
e05b323489 | ||
|
|
7f198b64f1 | ||
|
|
1c87fef28d | ||
|
|
816c22979f | ||
|
|
42f9a27851 | ||
|
|
6a2d2dfdaf | ||
|
|
efd2088745 | ||
|
|
56e8e84eaf | ||
|
|
eccebae596 | ||
|
|
edc36283d9 | ||
|
|
2409cfefc9 | ||
|
|
fae73913de | ||
|
|
69f398c594 | ||
|
|
fe52238ac2 | ||
|
|
a3501e5417 | ||
|
|
52add26905 | ||
|
|
954b034b8b | ||
|
|
e5aa5ace15 | ||
|
|
a6c5ec8581 | ||
|
|
beb395ce32 | ||
|
|
bcfa80a2d5 | ||
|
|
96e5398ad1 | ||
|
|
4b748ee43a | ||
|
|
838e0f9910 | ||
|
|
548e1378f5 | ||
|
|
fb90d79eb3 | ||
|
|
3fb3381a19 | ||
|
|
60d0750695 | ||
|
|
ce9c31f368 | ||
|
|
d4d7148f16 | ||
|
|
b5aba6e007 | ||
|
|
2564fa7382 | ||
|
|
c07be7386c | ||
|
|
c400003ce9 | ||
|
|
d4ffd8e8e4 | ||
|
|
9a6b907c11 | ||
|
|
84d4c7a6f2 | ||
|
|
0497e2052d | ||
|
|
dc8e9e3fef | ||
|
|
518a593c2a | ||
|
|
f7168cc814 | ||
|
|
18217dadc3 | ||
|
|
559a4969c1 | ||
|
|
7bad6cd20a | ||
|
|
e3987c8aa3 | ||
|
|
a46286872d | ||
|
|
9bb7a125e3 | ||
|
|
3c196abccb | ||
|
|
2e8899dfef | ||
|
|
8337768c5a | ||
|
|
034b371ad4 | ||
|
|
1e68b75c68 | ||
|
|
ac1bf7c9bf | ||
|
|
d60e052f05 | ||
|
|
43b71c7532 | ||
|
|
8ee0a99323 | ||
|
|
50febc342c | ||
|
|
c98667245e | ||
|
|
76fdf8e501 | ||
|
|
6270226ead | ||
|
|
ed5afff5d7 | ||
|
|
5d8d38bdf0 | ||
|
|
88af879d31 | ||
|
|
91095f14fb | ||
|
|
65077088b6 | ||
|
|
47666b7193 | ||
|
|
353f73ed0b | ||
|
|
51ed9dab04 | ||
|
|
c8b0faf05d | ||
|
|
3d7609e3f5 | ||
|
|
d9611948d7 | ||
|
|
67053db9ba | ||
|
|
c831c19848 | ||
|
|
ced45bec65 | ||
|
|
13ded5595a | ||
|
|
dfc4a8d713 | ||
|
|
31b9bfa590 | ||
|
|
f93b3c7424 | ||
|
|
3d32ec7210 | ||
|
|
b108d4e287 | ||
|
|
d8ea86fde1 | ||
|
|
58e979bc45 | ||
|
|
d5acf92f8a | ||
|
|
ddd9b9ae97 | ||
|
|
f77bf37be8 | ||
|
|
fb8fcc5028 | ||
|
|
f80daf6cd4 | ||
|
|
092aeceb9d | ||
|
|
7542ac9d87 | ||
|
|
b27ebaaccf | ||
|
|
5b20a7edb8 | ||
|
|
48580cb5b0 | ||
|
|
7c79accda7 | ||
|
|
1182fdeb43 | ||
|
|
694ffb0a81 | ||
|
|
fe8ff2b180 | ||
|
|
ade1db5215 | ||
|
|
5269cbf862 | ||
|
|
d62e43790c | ||
|
|
5766a50bc2 | ||
|
|
c09503aad8 | ||
|
|
f6bc183972 | ||
|
|
a087677c6e | ||
|
|
529a2ecd81 | ||
|
|
3843d1bd3e | ||
|
|
6be7f6ad68 | ||
|
|
30c4fb8032 | ||
|
|
a7dee45720 | ||
|
|
f7c597d957 | ||
|
|
b89e7c6c3d | ||
|
|
0f7a619a34 | ||
|
|
5c1cb120e1 | ||
|
|
9f24e765be | ||
|
|
a23f9881ee | ||
|
|
80e85a571e | ||
|
|
82a412093e | ||
|
|
8986e84dfe | ||
|
|
b6136a092d | ||
|
|
939f46c7e6 | ||
|
|
dd8059693d | ||
|
|
afacd2a8a0 | ||
|
|
4755cf6a25 | ||
|
|
d3e58c85cf | ||
|
|
89a6d6a4c1 | ||
|
|
ecbfeb608b | ||
|
|
f8a8314476 | ||
|
|
b1d7bb9fd7 | ||
|
|
28a84a90cf | ||
|
|
067119eac7 | ||
|
|
3fa19cf977 | ||
|
|
5cbb5e7d40 | ||
|
|
f5c4749954 | ||
|
|
a3ee010286 | ||
|
|
7e8b5f1f63 | ||
|
|
eff88528d3 | ||
|
|
f83e49bd3d | ||
|
|
bd6c689d91 | ||
|
|
f9469a1ea3 | ||
|
|
c0d92fbdd5 | ||
|
|
2079fc1801 | ||
|
|
59d01a6bd9 | ||
|
|
4f29fe5040 | ||
|
|
455ae8aa05 | ||
|
|
db417e6a5f | ||
|
|
8d444f24f8 | ||
|
|
618cd667fc | ||
|
|
f4d5419ba1 | ||
|
|
0d80269e2d | ||
|
|
861e95673d | ||
|
|
997e4a1edd | ||
|
|
bfdf02f065 | ||
|
|
f658b9d6d9 | ||
|
|
671fce2961 | ||
|
|
93c9ffe109 | ||
|
|
17cd414dde | ||
|
|
3bc10291c4 | ||
|
|
8f6c1d0e47 | ||
|
|
f882fe2c32 | ||
|
|
b25644c590 | ||
|
|
626e29a001 | ||
|
|
dca7a6f270 | ||
|
|
05ef2b8eaa | ||
|
|
1819649a3a | ||
|
|
b8f58b2cc1 | ||
|
|
2ceefab18c | ||
|
|
254dd75cd0 | ||
|
|
6e87d66932 | ||
|
|
3a05d74a36 | ||
|
|
4b5f08ccc2 | ||
|
|
cc20050dc8 | ||
|
|
25cf439f03 | ||
|
|
2beae9ea5b | ||
|
|
64a1ab5c60 | ||
|
|
00ef7ab6ca | ||
|
|
08b3c9d1ac | ||
|
|
2287196746 | ||
|
|
9ac679d437 | ||
|
|
db0a5875fa | ||
|
|
38ff16f3cd | ||
|
|
ccbc36f991 | ||
|
|
b47b99bd28 | ||
|
|
55a922427b | ||
|
|
a5525c065c | ||
|
|
840b3c2a84 | ||
|
|
3cef5f0bff | ||
|
|
fa1463939e | ||
|
|
b31099c94d | ||
|
|
fc0899d9d3 | ||
|
|
a7170a4eee | ||
|
|
e04874d074 | ||
|
|
0fc570b138 | ||
|
|
5edbc1a7b5 | ||
|
|
a7cfa05504 | ||
|
|
c0988da176 | ||
|
|
12707793b1 | ||
|
|
06d6732ab2 | ||
|
|
ab6e98aae2 | ||
|
|
a2ef9d781d | ||
|
|
106ee43171 | ||
|
|
36d626c833 | ||
|
|
b0ac85d81d | ||
|
|
25d70b7b49 | ||
|
|
4c5946e8da | ||
|
|
4de1a38c00 | ||
|
|
caadc02fb4 | ||
|
|
3e691aa31f | ||
|
|
fd7ce9027a | ||
|
|
3fdde5f8c4 | ||
|
|
4c5eb721fb | ||
|
|
f3bdb03cae | ||
|
|
9b6112d206 | ||
|
|
beab0fa6f6 | ||
|
|
fa60cab587 | ||
|
|
05da6b3c50 | ||
|
|
0b12f4e6fd | ||
|
|
b9ddf29289 | ||
|
|
10e47b8305 | ||
|
|
0e1c9487f0 | ||
|
|
60f569dbf9 | ||
|
|
bdb803db21 | ||
|
|
634fab4d9f | ||
|
|
34a14865eb | ||
|
|
abcd3a30ce | ||
|
|
9f40bf6f5d | ||
|
|
8a98aef28c | ||
|
|
bb47b4475e | ||
|
|
1bb6c5fbfc | ||
|
|
35fe459420 | ||
|
|
d75ac45c33 | ||
|
|
9927da5088 | ||
|
|
295b4b3b72 | ||
|
|
8464e0ea3f | ||
|
|
4b73457f7f | ||
|
|
eedcf6f1fe | ||
|
|
5b130d9500 | ||
|
|
600f457bc2 | ||
|
|
e1959f74aa | ||
|
|
0f7d04e0b9 | ||
|
|
f91311144b | ||
|
|
529b3cb18f | ||
|
|
bcbefe29e7 | ||
|
|
1dd7037aa0 | ||
|
|
2c2e9396c4 | ||
|
|
69feb6a4f1 | ||
|
|
911b4b9138 | ||
|
|
21cd4b67f0 | ||
|
|
8c7eebe76c | ||
|
|
bb8b00e547 | ||
|
|
f8c7f88ac2 | ||
|
|
c6cc5810ca | ||
|
|
a89ff584fd | ||
|
|
11d824a88d | ||
|
|
f1ab927a7e | ||
|
|
9e0634f449 | ||
|
|
a9006f2954 | ||
|
|
3a021e7879 | ||
|
|
6ea8cc9986 | ||
|
|
4c77151877 | ||
|
|
ea34431cf7 | ||
|
|
7c546ed6b8 | ||
|
|
db53920153 | ||
|
|
c60015bd09 | ||
|
|
d2a3388058 | ||
|
|
384a75622f | ||
|
|
68a62d689c | ||
|
|
8f7968302d | ||
|
|
35a5733e82 | ||
|
|
f6bbbc56ba | ||
|
|
d1d601f028 | ||
|
|
bbb133d0f2 | ||
|
|
9671f57b65 | ||
|
|
d3212c8b49 | ||
|
|
1f01a5b1cc | ||
|
|
95f7f5535f | ||
|
|
8ae031dbbd | ||
|
|
4498f069f0 | ||
|
|
349b895ac5 | ||
|
|
794f27a3c8 | ||
|
|
1def9a6b19 | ||
|
|
cbf1e42c73 | ||
|
|
7c960bb899 | ||
|
|
1a1807df96 | ||
|
|
2d03f17bde | ||
|
|
8cbaa6b281 | ||
|
|
2c0ae66143 | ||
|
|
a54c160d83 | ||
|
|
61fb7b0d86 | ||
|
|
b3beae44df | ||
|
|
d1369e765a | ||
|
|
6185485c68 | ||
|
|
db733ac9ce | ||
|
|
f94fcf58a7 | ||
|
|
7487841385 | ||
|
|
289c4b497d | ||
|
|
c49bfb97dd | ||
|
|
4643dbce17 | ||
|
|
82e8c01b95 | ||
|
|
47ced11e03 | ||
|
|
04d35a3a83 | ||
|
|
1df3a0b8cb | ||
|
|
faa13f58e0 | ||
|
|
58fcc90417 | ||
|
|
0690612477 | ||
|
|
c0344b385a | ||
|
|
214c5998c6 | ||
|
|
b14c01f9f7 | ||
|
|
4a838e7bdb | ||
|
|
4a748e894d | ||
|
|
b576491156 | ||
|
|
17da790651 | ||
|
|
c599cab14a | ||
|
|
4240bad627 | ||
|
|
0017de7b21 | ||
|
|
53a4ebb66e | ||
|
|
5bfca0f86f | ||
|
|
9553aa944a | ||
|
|
35991ff5d6 | ||
|
|
42d703ca1d | ||
|
|
e089ddb223 | ||
|
|
c323b6a8a9 | ||
|
|
bf461f59de | ||
|
|
9974fa831c | ||
|
|
73e41b0de0 | ||
|
|
9aa297a804 | ||
|
|
5c1bcdbd74 | ||
|
|
8c4997fa37 | ||
|
|
d099a22bd9 | ||
|
|
0de0426f72 | ||
|
|
04d5b692b8 | ||
|
|
da6cdcef84 | ||
|
|
fbf2671eaf | ||
|
|
67e050bd6f | ||
|
|
8282f48cdb | ||
|
|
5d903de2a2 | ||
|
|
78deee2de3 | ||
|
|
a09403328e | ||
|
|
45e92e7b7a | ||
|
|
ebe8a40202 | ||
|
|
bd0747ff6f | ||
|
|
b37ec98e17 | ||
|
|
a93db0a038 | ||
|
|
08f9029bf8 | ||
|
|
fb9d2d99d4 | ||
|
|
a374d4d40f | ||
|
|
fb4666195c | ||
|
|
39b6c00c6d | ||
|
|
decb3ef2f1 | ||
|
|
2a9c501ee2 | ||
|
|
60d25a18fb | ||
|
|
39a71d51cf | ||
|
|
5c401f3858 | ||
|
|
cc45ec85fd | ||
|
|
1d66becff5 | ||
|
|
2a4ebcaf9c | ||
|
|
1a792254ca | ||
|
|
d9319f5734 | ||
|
|
81d96fe3a9 | ||
|
|
39fff0e57d | ||
|
|
95058f7890 | ||
|
|
472ef1a231 | ||
|
|
d7de302393 | ||
|
|
e4b1dfc77a | ||
|
|
aed7267253 | ||
|
|
a24b7433a5 | ||
|
|
0b423a6fe0 | ||
|
|
cb98812444 | ||
|
|
b4e30565d2 | ||
|
|
9f40e2c71e | ||
|
|
fb0a2798e7 | ||
|
|
9912b5037d | ||
|
|
bca56bfaad | ||
|
|
542f048a67 | ||
|
|
91c5e7e06c | ||
|
|
972ee69fac | ||
|
|
00c9ef47e9 | ||
|
|
dcad5f4b5f | ||
|
|
e74cda3c0f | ||
|
|
bafbb39883 | ||
|
|
02391e66dc | ||
|
|
762ab30c71 | ||
|
|
6ce6a932e1 | ||
|
|
e7de1896ea | ||
|
|
4391705c9a | ||
|
|
b40bf76270 | ||
|
|
f44aee0af4 | ||
|
|
57a1af9392 | ||
|
|
b16ae64105 | ||
|
|
0912d583c7 | ||
|
|
6eff89aca1 | ||
|
|
6e5e195a30 | ||
|
|
e3efda2764 | ||
|
|
5360c3dbaf | ||
|
|
f6427c50f2 | ||
|
|
22035d1383 | ||
|
|
85949c5927 | ||
|
|
dde746a5fe | ||
|
|
c2ae30575e | ||
|
|
cb5d9f626e | ||
|
|
c6d82409a8 | ||
|
|
fef5d0e688 | ||
|
|
f64e696f7a | ||
|
|
acf99a6a9e | ||
|
|
a76560c38a | ||
|
|
e1eec66e04 | ||
|
|
96d1ee2347 | ||
|
|
2a06463d07 | ||
|
|
899862dc57 | ||
|
|
c8d585889b | ||
|
|
d044423330 | ||
|
|
273a9a5e66 | ||
|
|
0294e0d2b3 | ||
|
|
38daa0826e | ||
|
|
b9e8dea5d9 | ||
|
|
241930cefe | ||
|
|
bed3684a0c | ||
|
|
e1bb684c4c | ||
|
|
4c75a5b421 | ||
|
|
20f809740c | ||
|
|
83294abaf0 | ||
|
|
687dabc777 | ||
|
|
605d6f0f9b | ||
|
|
b1d13f5a71 | ||
|
|
50c740d219 | ||
|
|
a7456d1182 | ||
|
|
804cbb8c56 | ||
|
|
cb13f66b3d | ||
|
|
ec2cd29096 | ||
|
|
412c6dadca | ||
|
|
1ac3768468 | ||
|
|
e622636686 | ||
|
|
2ddeca8f9d | ||
|
|
d1a80e1a64 | ||
|
|
4cfe41ca9e | ||
|
|
cd1d3005e9 | ||
|
|
435161854c | ||
|
|
890287ce72 | ||
|
|
0cc2a40f26 | ||
|
|
849150c9ab | ||
|
|
75ac74ca5e | ||
|
|
9822479d24 | ||
|
|
c456f63e8c | ||
|
|
51ae3a16bd | ||
|
|
bd418b23dc | ||
|
|
af789ee886 | ||
|
|
324bd57e3d | ||
|
|
146bcdcf1c | ||
|
|
60c92b8a98 | ||
|
|
230120fff5 | ||
|
|
ba76498acc | ||
|
|
5e0772fae9 | ||
|
|
7fcd005f06 | ||
|
|
961d420c95 | ||
|
|
a42df69a7f | ||
|
|
59d2c5ae3c | ||
|
|
a6f0f554f0 | ||
|
|
c8c22b3f22 | ||
|
|
67febd3e25 | ||
|
|
dde937f460 | ||
|
|
c3473673da | ||
|
|
f24aef300b | ||
|
|
84e0c46711 | ||
|
|
16e2ac5b6c | ||
|
|
01214077d3 | ||
|
|
1e3957bdd5 | ||
|
|
8e7fa486db | ||
|
|
a72088b7a8 | ||
|
|
419f1e07d1 | ||
|
|
e05ec3d2d5 | ||
|
|
22f90a505c | ||
|
|
66e506db07 | ||
|
|
fa4041e560 | ||
|
|
f8a8225b8c | ||
|
|
75636b2575 | ||
|
|
e44cc4c145 | ||
|
|
343ada135d | ||
|
|
93a6a77c2b | ||
|
|
8bc67b323c | ||
|
|
f684a3b0ae | ||
|
|
5f2115fff6 | ||
|
|
9d654bcd66 | ||
|
|
5f8e72c6ae | ||
|
|
5dde5cae50 | ||
|
|
f730548c8f | ||
|
|
a185bd9463 | ||
|
|
abdc78e123 | ||
|
|
ba49fa6c88 | ||
|
|
870ffa9dc1 | ||
|
|
8afaf1a60e | ||
|
|
6974ac8e14 | ||
|
|
9f274ee17e | ||
|
|
673bcde719 | ||
|
|
6eaf5bb463 | ||
|
|
b463eedb3f | ||
|
|
90350f99ad | ||
|
|
8576015633 | ||
|
|
f5edf39027 | ||
|
|
751781e3e5 | ||
|
|
bc9129bcbe | ||
|
|
c442a33d5e | ||
|
|
902bb06353 | ||
|
|
a0a1b8b3e8 | ||
|
|
eb5cf9da8d | ||
|
|
57386eeb55 | ||
|
|
33a21f2aaa | ||
|
|
d6fd498489 | ||
|
|
386f2969eb | ||
|
|
2fea3a4b40 | ||
|
|
b9c9fe7a97 | ||
|
|
594c4cd670 | ||
|
|
e10c5e28b5 | ||
|
|
fbefb2014d | ||
|
|
909da7edb5 | ||
|
|
349676d908 | ||
|
|
a47f7cc0ce | ||
|
|
8fbdb884c7 | ||
|
|
ec68ce082e | ||
|
|
2b61e3dfd3 | ||
|
|
4c3dddc486 | ||
|
|
ecc683a6bd | ||
|
|
7b2098cf33 | ||
|
|
3784d86344 | ||
|
|
2b22481443 |
@@ -1,2 +1,3 @@
|
|||||||
PORT=9000
|
PORT=9000
|
||||||
UMI_DEV_SERVER_COMPRESS=none
|
UMI_DEV_SERVER_COMPRESS=none
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
src/components/icon-font/iconfont/iconfont.js
|
||||||
+7
-1
@@ -3,7 +3,13 @@ module.exports = {
|
|||||||
rules: {
|
rules: {
|
||||||
'react/no-unstable-nested-components': 1,
|
'react/no-unstable-nested-components': 1,
|
||||||
'no-unused-vars': 'off',
|
'no-unused-vars': 'off',
|
||||||
|
'no-undef': 'error',
|
||||||
'@typescript-eslint/no-unused-vars': 'off',
|
'@typescript-eslint/no-unused-vars': 'off',
|
||||||
'@typescript-eslint/class-name-casing': 'off'
|
'@typescript-eslint/class-name-casing': 'off'
|
||||||
}
|
},
|
||||||
|
globals: {
|
||||||
|
Global: 'readonly',
|
||||||
|
React: 'readonly'
|
||||||
|
},
|
||||||
|
ignorePatterns: ['public/static/']
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,3 +12,4 @@
|
|||||||
/.mfsu
|
/.mfsu
|
||||||
.swc
|
.swc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.idea
|
||||||
+4
-1
@@ -1 +1,4 @@
|
|||||||
npx --no-install lint-staged --quiet
|
#!/bin/sh
|
||||||
|
. "$(dirname "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
npx lint-staged
|
||||||
+4
-8
@@ -1,11 +1,6 @@
|
|||||||
{
|
{
|
||||||
"*.{md,json}": [
|
"*.{md,json}": ["prettier --cache --write"],
|
||||||
"prettier --cache --write"
|
"*.{js,jsx}": ["max lint --fix --eslint-only", "prettier --cache --write"],
|
||||||
],
|
|
||||||
"*.{js,jsx}": [
|
|
||||||
"max lint --fix --eslint-only",
|
|
||||||
"prettier --cache --write"
|
|
||||||
],
|
|
||||||
"*.{css,less}": [
|
"*.{css,less}": [
|
||||||
"max lint --fix --stylelint-only",
|
"max lint --fix --stylelint-only",
|
||||||
"prettier --cache --write"
|
"prettier --cache --write"
|
||||||
@@ -13,5 +8,6 @@
|
|||||||
"*.ts?(x)": [
|
"*.ts?(x)": [
|
||||||
"max lint --fix --eslint-only",
|
"max lint --fix --eslint-only",
|
||||||
"prettier --cache --parser=typescript --write"
|
"prettier --cache --parser=typescript --write"
|
||||||
]
|
],
|
||||||
|
"src/locales/**/*.ts": ["npx tsx src/locales/check.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.umi
|
.umi
|
||||||
.umi-production
|
.umi-production
|
||||||
|
public/static/*.js
|
||||||
|
public/static/*.css
|
||||||
|
src/components/icon-font/iconfont/iconfont.js
|
||||||
|
src/components/icon-font/iconfont/*.css
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -2,5 +2,6 @@ module.exports = {
|
|||||||
extends: require.resolve('@umijs/max/stylelint'),
|
extends: require.resolve('@umijs/max/stylelint'),
|
||||||
rules: {
|
rules: {
|
||||||
'selector-class-pattern': null
|
'selector-class-pattern': null
|
||||||
}
|
},
|
||||||
|
ignoreFiles: ['public/static/*.css']
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
Copyright (c) 2024 The GPUStack authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -44,3 +44,12 @@ npm run dev
|
|||||||
```
|
```
|
||||||
npm run build
|
npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Bugs & Issues
|
||||||
|
|
||||||
|
- Please submit [bugs and issues](https://github.com/gpustack/gpustack/issues) with a label `ui`
|
||||||
|
|
||||||
|
## Links
|
||||||
|
|
||||||
|
- Official website: https://gpustack.ai/
|
||||||
|
- Documents: https://docs.gpustack.ai/latest/overview/
|
||||||
|
|||||||
+18
-7
@@ -1,7 +1,7 @@
|
|||||||
import { defineConfig } from '@umijs/max';
|
import { defineConfig } from '@umijs/max';
|
||||||
|
import keepAlive from './keep-alive';
|
||||||
import proxy from './proxy';
|
import proxy from './proxy';
|
||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
import theme from './theme';
|
|
||||||
import { getBranchInfo } from './utils';
|
import { getBranchInfo } from './utils';
|
||||||
const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
||||||
|
|
||||||
@@ -14,11 +14,20 @@ const isProduction = env === 'production';
|
|||||||
const t = Date.now();
|
const t = Date.now();
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
proxy: {
|
proxy: {
|
||||||
...proxy()
|
...proxy(process.env.PROXY_HOST)
|
||||||
},
|
},
|
||||||
history: {
|
history: {
|
||||||
type: 'hash'
|
type: 'hash'
|
||||||
},
|
},
|
||||||
|
analyze: {
|
||||||
|
analyzerMode: 'server',
|
||||||
|
analyzerPort: 8888,
|
||||||
|
openAnalyzer: true,
|
||||||
|
generateStatsFile: false,
|
||||||
|
statsFilename: 'stats.json',
|
||||||
|
logLevel: 'info',
|
||||||
|
defaultSizes: 'parsed' // stat // gzip
|
||||||
|
},
|
||||||
base: process.env.npm_config_base || '/',
|
base: process.env.npm_config_base || '/',
|
||||||
...(isProduction
|
...(isProduction
|
||||||
? {
|
? {
|
||||||
@@ -41,6 +50,11 @@ export default defineConfig({
|
|||||||
chunkFilename: `css/[name].${t}.chunk.css`
|
chunkFilename: `css/[name].${t}.chunk.css`
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
config.module
|
||||||
|
.rule('worker')
|
||||||
|
.test(/\.worker\.js$/)
|
||||||
|
.use('worker-loader')
|
||||||
|
.loader('worker-loader');
|
||||||
config.output
|
config.output
|
||||||
.filename(`js/[name].${t}.js`)
|
.filename(`js/[name].${t}.js`)
|
||||||
.chunkFilename(`js/[name].${t}.chunk.js`);
|
.chunkFilename(`js/[name].${t}.chunk.js`);
|
||||||
@@ -65,17 +79,14 @@ export default defineConfig({
|
|||||||
presets: ['umi-presets-pro'],
|
presets: ['umi-presets-pro'],
|
||||||
clickToComponent: {},
|
clickToComponent: {},
|
||||||
antd: {
|
antd: {
|
||||||
style: 'less',
|
style: 'less'
|
||||||
configProvider: {
|
|
||||||
componentSize: 'large',
|
|
||||||
theme
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
hash: true,
|
hash: true,
|
||||||
access: {},
|
access: {},
|
||||||
model: {},
|
model: {},
|
||||||
initialState: {},
|
initialState: {},
|
||||||
request: {},
|
request: {},
|
||||||
|
keepalive: keepAlive,
|
||||||
locale: {
|
locale: {
|
||||||
antd: true,
|
antd: true,
|
||||||
baseNavigator: true,
|
baseNavigator: true,
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export const keepAliveRoutes = {
|
||||||
|
text2images: '/playground/text-to-image',
|
||||||
|
speech: '/playground/speech'
|
||||||
|
};
|
||||||
|
|
||||||
|
export default [keepAliveRoutes.text2images, keepAliveRoutes.speech];
|
||||||
+16
-1
@@ -1,4 +1,12 @@
|
|||||||
const proxyTableList = ['cli', 'v1', 'auth', 'v1-openai', 'version', 'proxy'];
|
const proxyTableList = [
|
||||||
|
'cli',
|
||||||
|
'v1',
|
||||||
|
'auth',
|
||||||
|
'v1-openai',
|
||||||
|
'version',
|
||||||
|
'proxy',
|
||||||
|
'update'
|
||||||
|
];
|
||||||
|
|
||||||
// @ts-ingore
|
// @ts-ingore
|
||||||
export default function createProxyTable(target?: string) {
|
export default function createProxyTable(target?: string) {
|
||||||
@@ -10,7 +18,14 @@ export default function createProxyTable(target?: string) {
|
|||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
secure: false,
|
||||||
ws: true,
|
ws: true,
|
||||||
|
log: 'debug',
|
||||||
pathRewrite: (pth: string) => pth.replace(`/^/${api}`, `/${api}`),
|
pathRewrite: (pth: string) => pth.replace(`/^/${api}`, `/${api}`),
|
||||||
|
// onProxyRes: (proxyRes: any, req: any, res: any) => {
|
||||||
|
// console.log('headers=========', {
|
||||||
|
// res: proxyRes.headers,
|
||||||
|
// req: req.headers
|
||||||
|
// });
|
||||||
|
// },
|
||||||
headers: {
|
headers: {
|
||||||
origin: newTarget,
|
origin: newTarget,
|
||||||
Connection: 'keep-alive'
|
Connection: 'keep-alive'
|
||||||
|
|||||||
+61
-7
@@ -1,3 +1,5 @@
|
|||||||
|
import { keepAliveRoutes } from './keep-alive';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
name: 'dashboard',
|
name: 'dashboard',
|
||||||
@@ -9,19 +11,71 @@ export default [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'playground',
|
name: 'playground',
|
||||||
title: 'Playground',
|
icon: 'ExperimentOutlined',
|
||||||
path: '/playground',
|
path: '/playground',
|
||||||
key: 'playground',
|
key: 'playground',
|
||||||
icon: 'Comment',
|
routes: [
|
||||||
component: './playground'
|
{
|
||||||
|
path: '/playground',
|
||||||
|
redirect: '/playground/chat'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'chat',
|
||||||
|
title: 'Chat',
|
||||||
|
path: '/playground/chat',
|
||||||
|
key: 'chat',
|
||||||
|
icon: 'Comment',
|
||||||
|
component: './playground/index'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'text2images',
|
||||||
|
title: 'Text2Images',
|
||||||
|
path: keepAliveRoutes.text2images,
|
||||||
|
key: 'text2images',
|
||||||
|
icon: 'Comment',
|
||||||
|
component: './playground/images'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'speech',
|
||||||
|
title: 'Speech',
|
||||||
|
path: keepAliveRoutes.speech,
|
||||||
|
key: 'speech',
|
||||||
|
icon: 'Comment',
|
||||||
|
component: './playground/speech'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'embedding',
|
||||||
|
title: 'embedding',
|
||||||
|
path: '/playground/embedding',
|
||||||
|
key: 'embedding',
|
||||||
|
icon: 'Comment',
|
||||||
|
component: './playground/embedding'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'rerank',
|
||||||
|
title: 'Rerank',
|
||||||
|
path: '/playground/rerank',
|
||||||
|
key: 'rerank',
|
||||||
|
icon: 'Comment',
|
||||||
|
component: './playground/rerank'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'modelCatalog',
|
||||||
|
path: '/models/catalog',
|
||||||
|
key: 'modelsCatalog',
|
||||||
|
icon: 'icon-catalog',
|
||||||
|
access: 'canSeeAdmin',
|
||||||
|
component: './llmodels/catalog'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'models',
|
name: 'models',
|
||||||
path: '/models',
|
path: '/models/list',
|
||||||
key: 'models',
|
key: 'models',
|
||||||
icon: 'Block',
|
icon: 'Block',
|
||||||
access: 'canSeeAdmin',
|
access: 'canSeeAdmin',
|
||||||
component: './llmodels'
|
component: './llmodels/index'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'resources',
|
name: 'resources',
|
||||||
@@ -35,7 +89,7 @@ export default [
|
|||||||
name: 'apikeys',
|
name: 'apikeys',
|
||||||
path: '/api-keys',
|
path: '/api-keys',
|
||||||
key: 'apikeys',
|
key: 'apikeys',
|
||||||
icon: 'LockOutlined',
|
icon: 'KeyOutlined',
|
||||||
component: './api-keys'
|
component: './api-keys'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -66,7 +120,7 @@ export default [
|
|||||||
name: '404',
|
name: '404',
|
||||||
path: '*',
|
path: '*',
|
||||||
key: '404',
|
key: '404',
|
||||||
layout: false,
|
hideInMenu: true,
|
||||||
component: './404'
|
component: './404'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
export default {
|
|
||||||
'root-entry-name': 'variable',
|
|
||||||
cssVar: true,
|
|
||||||
hashed: false,
|
|
||||||
components: {
|
|
||||||
Input: {
|
|
||||||
inputFontSize: 12
|
|
||||||
},
|
|
||||||
Table: {
|
|
||||||
cellFontSize: 12,
|
|
||||||
rowSelectedHoverBg: 'rgba(230, 230, 230, 0.88)',
|
|
||||||
rowSelectedBg: 'rgb(244, 245, 244)'
|
|
||||||
},
|
|
||||||
Menu: {
|
|
||||||
iconSize: 16,
|
|
||||||
iconMarginInlineEnd: 12,
|
|
||||||
itemHeight: 44,
|
|
||||||
itemColor: 'rgba(0,0,0,1)',
|
|
||||||
itemHoverBg: 'rgba(0,0,0,0.04)',
|
|
||||||
itemActiveBg: 'rgba(0,0,0,0.04)'
|
|
||||||
},
|
|
||||||
Progress: {
|
|
||||||
lineBorderRadius: 4
|
|
||||||
},
|
|
||||||
Select: {
|
|
||||||
itemSelectedBg: 'rgba(0,0,0,0.06)'
|
|
||||||
},
|
|
||||||
Message: {
|
|
||||||
contentPadding: '12px 16px'
|
|
||||||
},
|
|
||||||
Tooltip: {
|
|
||||||
colorBgSpotlight: 'rgba(110,110,110,1)'
|
|
||||||
// sizePopupArrow: 0
|
|
||||||
},
|
|
||||||
Slider: {
|
|
||||||
handleSize: 8,
|
|
||||||
handleSizeHover: 8,
|
|
||||||
trackBg: 'rgba(0,0,0,0.15)',
|
|
||||||
handleColor: 'rgba(0,0,0,0.2)',
|
|
||||||
trackHoverBg: 'rgba(0,0,0,0.25)',
|
|
||||||
handleActiveColor: 'rgba(0,0,0,0.3)',
|
|
||||||
dotActiveBorderColor: 'rgba(0,0,0,0.25)',
|
|
||||||
handleActiveOutlineColor: 'rgba(0,0,0,0.25)',
|
|
||||||
dotBorderColor: 'rgba(0,0,0,0.25)'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
token: {
|
|
||||||
colorPrimary: '#007BFF',
|
|
||||||
colorSuccess: '#54cc98',
|
|
||||||
borderRadius: 4,
|
|
||||||
borderRadiusSM: 2,
|
|
||||||
fontSize: 12,
|
|
||||||
motion: true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1 +1,28 @@
|
|||||||
// only for third party libraries styles
|
// only for third party libraries styles
|
||||||
|
|
||||||
|
.simplebar-scrollbar.simplebar-visible::before {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplebar-scrollbar::before {
|
||||||
|
background: var(--scrollbar-handle-bg);
|
||||||
|
width: var(--scrollbar-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplebar-scrollbar.simplebar-visible.simplebar-hover {
|
||||||
|
&::before {
|
||||||
|
background: var(--scrollbar-handle-hover-bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplebar-scrollbar.scrollbar-handle-light {
|
||||||
|
&::before {
|
||||||
|
background-color: var(--scrollbar-handle-light-bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplebar-scrollbar.simplebar-visible.simplebar-hover.scrollbar-handle-light {
|
||||||
|
&::before {
|
||||||
|
background: var(--scrollbar-handle-light-bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+34
-5
@@ -3,49 +3,75 @@
|
|||||||
"author": "jialin",
|
"author": "jialin",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "max build",
|
"build": "max build",
|
||||||
|
"check:locales": "npx tsx ./src/locales/check.ts",
|
||||||
"dev": "max dev",
|
"dev": "max dev",
|
||||||
"format": "prettier --cache --write .",
|
"format": "prettier --cache --write .",
|
||||||
"postinstall": "max setup",
|
"postinstall": "max setup",
|
||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
|
"preview": "max preview",
|
||||||
"setup": "max setup",
|
"setup": "max setup",
|
||||||
"start": "npm run dev"
|
"start": "npm run dev"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"immer": "^9.0.6"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^5.3.7",
|
"@ant-design/icons": "^5.5.1",
|
||||||
"@ant-design/pro-components": "^2.7.1",
|
"@ant-design/pro-components": "^2.7.19",
|
||||||
|
"@braintree/sanitize-url": "^7.1.1",
|
||||||
"@huggingface/gguf": "^0.1.7",
|
"@huggingface/gguf": "^0.1.7",
|
||||||
"@huggingface/hub": "^0.15.1",
|
"@huggingface/hub": "^0.15.1",
|
||||||
"@huggingface/tasks": "^0.11.6",
|
"@huggingface/tasks": "^0.11.6",
|
||||||
"@monaco-editor/react": "^4.6.0",
|
"@monaco-editor/react": "^4.6.0",
|
||||||
|
"@orcid/bibtex-parse-js": "^0.0.25",
|
||||||
"@react-hook/resize-observer": "^2.0.2",
|
"@react-hook/resize-observer": "^2.0.2",
|
||||||
"@types/lodash": "^4.17.4",
|
"@types/lodash": "^4.17.4",
|
||||||
"@umijs/max": "^4.2.11",
|
"@umijs/max": "^4.2.11",
|
||||||
"@xterm/addon-fit": "^0.10.0",
|
"@xterm/addon-fit": "^0.10.0",
|
||||||
"@xterm/xterm": "^5.5.0",
|
"@xterm/xterm": "^5.5.0",
|
||||||
"ansi-to-html": "^0.7.2",
|
"ansi-to-html": "^0.7.2",
|
||||||
"antd": "^5.18.3",
|
"antd": "^5.21.6",
|
||||||
"antd-style": "^3.6.2",
|
"antd-style": "^3.6.2",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"classnames": "^2.5.1",
|
"classnames": "^2.5.1",
|
||||||
"clipboard": "^2.0.11",
|
"clipboard": "^2.0.11",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"dayjs": "^1.11.11",
|
"dayjs": "^1.11.11",
|
||||||
|
"driver.js": "^1.3.1",
|
||||||
"echarts": "^5.5.1",
|
"echarts": "^5.5.1",
|
||||||
|
"epubjs": "^0.3.93",
|
||||||
"has-ansi": "^5.0.1",
|
"has-ansi": "^5.0.1",
|
||||||
"highlight.js": "^11.10.0",
|
"highlight.js": "^11.10.0",
|
||||||
"jotai": "^2.8.4",
|
"jotai": "^2.8.4",
|
||||||
|
"jszip": "^3.10.1",
|
||||||
|
"katex": "^0.16.21",
|
||||||
|
"lamejs": "github:zhuker/lamejs",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
"mammoth": "^1.8.0",
|
||||||
"marked": "^14.1.0",
|
"marked": "^14.1.0",
|
||||||
|
"ml-dataset-iris": "^1.2.1",
|
||||||
|
"ml-pca": "^4.1.1",
|
||||||
"numeral": "^2.0.6",
|
"numeral": "^2.0.6",
|
||||||
"overlayscrollbars": "^2.10.0",
|
"overlayscrollbars": "^2.10.0",
|
||||||
"overlayscrollbars-react": "^0.5.6",
|
"overlayscrollbars-react": "^0.5.6",
|
||||||
|
"pdfjs-dist": "^4.7.76",
|
||||||
"query-string": "^9.0.0",
|
"query-string": "^9.0.0",
|
||||||
|
"rc-resize-observer": "^1.4.0",
|
||||||
|
"rc-virtual-list": "^3.14.8",
|
||||||
|
"re-resizable": "^6.10.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-hotkeys-hook": "^4.5.0",
|
"react-hotkeys-hook": "^4.5.0",
|
||||||
|
"react-markdown": "^9.0.3",
|
||||||
|
"rehype-katex": "^7.0.1",
|
||||||
|
"remark-gfm": "^4.0.1",
|
||||||
|
"remark-math": "^6.0.0",
|
||||||
"simplebar-react": "^3.2.6",
|
"simplebar-react": "^3.2.6",
|
||||||
"umi-presets-pro": "^2.0.3"
|
"styled-components": "^6.1.15",
|
||||||
|
"umi-presets-pro": "^2.0.3",
|
||||||
|
"wavesurfer.js": "^7.8.8",
|
||||||
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/marked": "^6.0.0",
|
"@types/marked": "^6.0.0",
|
||||||
@@ -68,7 +94,10 @@
|
|||||||
"prettier-plugin-organize-imports": "^3.2.4",
|
"prettier-plugin-organize-imports": "^3.2.4",
|
||||||
"prettier-plugin-packagejson": "^2.5.0",
|
"prettier-plugin-packagejson": "^2.5.0",
|
||||||
"prettier-plugin-two-style-order": "^1.0.1",
|
"prettier-plugin-two-style-order": "^1.0.1",
|
||||||
|
"tsx": "^4.19.3",
|
||||||
"typescript": "^5.4.5",
|
"typescript": "^5.4.5",
|
||||||
"url-loader": "^4.1.1"
|
"url-loader": "^4.1.1",
|
||||||
|
"webpack-bundle-analyzer": "^4.10.2",
|
||||||
|
"worker-loader": "^3.0.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ export default (api: IApi) => {
|
|||||||
api.modifyHTML(($) => {
|
api.modifyHTML(($) => {
|
||||||
const info = JSON.parse(process.env.VERSION || '{}');
|
const info = JSON.parse(process.env.VERSION || '{}');
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV;
|
||||||
|
|
||||||
|
$('html').attr('data-env', env);
|
||||||
|
|
||||||
$('html').attr(
|
$('html').attr(
|
||||||
'data-version',
|
'data-version',
|
||||||
env === 'production'
|
env === 'production' ? info.version || info.commitId : `${info.commitId}`
|
||||||
? info.version || info.commitId
|
|
||||||
: `dev-${info.commitId}`
|
|
||||||
);
|
);
|
||||||
if (env === 'production') {
|
if (env === 'production') {
|
||||||
$('script[src^="/js/umi"]').first?.().remove?.();
|
$('script[src^="/js/umi"]').first?.().remove?.();
|
||||||
|
|||||||
Generated
+3807
-1211
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+43
-4
@@ -1,14 +1,33 @@
|
|||||||
import { GPUStackVersionAtom } from '@/atoms/user';
|
import { GPUStackVersionAtom, UpdateCheckAtom } from '@/atoms/user';
|
||||||
import { setAtomStorage } from '@/atoms/utils';
|
import { setAtomStorage } from '@/atoms/utils';
|
||||||
import { requestConfig } from '@/request-config';
|
import { requestConfig } from '@/request-config';
|
||||||
import {
|
import {
|
||||||
queryCurrentUserState,
|
queryCurrentUserState,
|
||||||
queryVersionInfo
|
queryVersionInfo,
|
||||||
|
updateCheck
|
||||||
} from '@/services/profile/apis';
|
} from '@/services/profile/apis';
|
||||||
|
import { isOnline } from '@/utils';
|
||||||
|
import {
|
||||||
|
IS_FIRST_LOGIN,
|
||||||
|
readState,
|
||||||
|
writeState
|
||||||
|
} from '@/utils/localstore/index';
|
||||||
import { RequestConfig, history } from '@umijs/max';
|
import { RequestConfig, history } from '@umijs/max';
|
||||||
|
|
||||||
const loginPath = '/login';
|
const loginPath = '/login';
|
||||||
|
|
||||||
|
// only for the first login and access from http://localhost
|
||||||
|
|
||||||
|
const checkDefaultPage = async (userInfo: any) => {
|
||||||
|
const isFirstLogin = await readState(IS_FIRST_LOGIN);
|
||||||
|
if (isFirstLogin === null && isOnline()) {
|
||||||
|
writeState(IS_FIRST_LOGIN, true);
|
||||||
|
if (userInfo && userInfo?.is_admin) {
|
||||||
|
history.push('/models/list');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// runtime configuration
|
// runtime configuration
|
||||||
export async function getInitialState(): Promise<{
|
export async function getInitialState(): Promise<{
|
||||||
fetchUserInfo: () => Promise<Global.UserInfo>;
|
fetchUserInfo: () => Promise<Global.UserInfo>;
|
||||||
@@ -16,11 +35,27 @@ export async function getInitialState(): Promise<{
|
|||||||
}> {
|
}> {
|
||||||
const { location } = history;
|
const { location } = history;
|
||||||
|
|
||||||
|
const getUpdateCheck = async () => {
|
||||||
|
try {
|
||||||
|
const data = await updateCheck();
|
||||||
|
|
||||||
|
setAtomStorage(UpdateCheckAtom, {
|
||||||
|
...data
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('updateCheck error', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const fetchUserInfo = async (): Promise<Global.UserInfo> => {
|
const fetchUserInfo = async (): Promise<Global.UserInfo> => {
|
||||||
try {
|
try {
|
||||||
const data = await queryCurrentUserState({
|
const data = await queryCurrentUserState({
|
||||||
skipErrorHandler: true
|
skipErrorHandler: true
|
||||||
});
|
});
|
||||||
|
if (data.is_admin) {
|
||||||
|
getUpdateCheck();
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
history.push(loginPath);
|
history.push(loginPath);
|
||||||
@@ -31,7 +66,11 @@ export async function getInitialState(): Promise<{
|
|||||||
const getAppVersionInfo = async () => {
|
const getAppVersionInfo = async () => {
|
||||||
try {
|
try {
|
||||||
const data = await queryVersionInfo();
|
const data = await queryVersionInfo();
|
||||||
setAtomStorage(GPUStackVersionAtom, data);
|
const isProduction = data.version?.indexOf('0.0.0') === -1;
|
||||||
|
setAtomStorage(GPUStackVersionAtom, {
|
||||||
|
...data,
|
||||||
|
isProduction
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('queryVersionInfo error', error);
|
console.error('queryVersionInfo error', error);
|
||||||
}
|
}
|
||||||
@@ -41,7 +80,7 @@ export async function getInitialState(): Promise<{
|
|||||||
|
|
||||||
if (![loginPath].includes(location.pathname)) {
|
if (![loginPath].includes(location.pathname)) {
|
||||||
const userInfo = await fetchUserInfo();
|
const userInfo = await fetchUserInfo();
|
||||||
|
checkDefaultPage(userInfo);
|
||||||
return {
|
return {
|
||||||
fetchUserInfo,
|
fetchUserInfo,
|
||||||
currentUser: userInfo
|
currentUser: userInfo
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 726 B |
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 118 KiB |
@@ -6,6 +6,10 @@
|
|||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.m-b-6 {
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
.m-b-5 {
|
.m-b-5 {
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
@@ -42,6 +46,18 @@
|
|||||||
margin-left: 40px;
|
margin-left: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.m-t-16 {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.m-t-10 {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.m-0 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.m-r-10 {
|
.m-r-10 {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
@@ -74,9 +90,14 @@
|
|||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.m-t-6 {
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
.flex {
|
.flex {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// space-between
|
// space-between
|
||||||
.flex-between {
|
.flex-between {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -87,6 +108,17 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.justify-start {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.justify-end {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
// align-items: center
|
// align-items: center
|
||||||
.flex-center {
|
.flex-center {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -132,14 +164,34 @@
|
|||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.gap-20 {
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gap-6 {
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-24 {
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
.relative {
|
.relative {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.font-size-0 {
|
||||||
|
font-size: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.font-size-12 {
|
.font-size-12 {
|
||||||
font-size: var(--font-size-base);
|
font-size: var(--font-size-base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.font-size-13 {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
.font-size-14 {
|
.font-size-14 {
|
||||||
font-size: var(--font-size-middle);
|
font-size: var(--font-size-middle);
|
||||||
}
|
}
|
||||||
@@ -148,6 +200,30 @@
|
|||||||
font-size: var(--font-size-large);
|
font-size: var(--font-size-large);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.font-size-20 {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.font-size-24 {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.font-size-32 {
|
||||||
|
font-size: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.m-b-0 {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.m-b-16 {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.m-r-16 {
|
||||||
|
margin-right: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.font-400 {
|
.font-400 {
|
||||||
font-weight: var(--font-weight-normal);
|
font-weight: var(--font-weight-normal);
|
||||||
}
|
}
|
||||||
@@ -156,6 +232,10 @@
|
|||||||
font-weight: var(--font-weight-medium);
|
font-weight: var(--font-weight-medium);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.font-500 {
|
||||||
|
font-weight: var(--font-weight-500);
|
||||||
|
}
|
||||||
|
|
||||||
.font-700 {
|
.font-700 {
|
||||||
font-weight: var(--font-weight-bold);
|
font-weight: var(--font-weight-bold);
|
||||||
}
|
}
|
||||||
@@ -167,3 +247,71 @@
|
|||||||
.text-tertiary {
|
.text-tertiary {
|
||||||
color: var(--ant-color-text-tertiary);
|
color: var(--ant-color-text-tertiary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tips-desc-list {
|
||||||
|
list-style-type: decimal;
|
||||||
|
padding-left: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gap-16 {
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-white-tertiary {
|
||||||
|
color: var(--color-white-tertiary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-white-quaternary {
|
||||||
|
color: var(--color-white-quaternary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-white-light-1 {
|
||||||
|
color: var(--color-white-light-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-white-light-2 {
|
||||||
|
color: var(--color-white-light-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-white-light-3 {
|
||||||
|
color: var(--color-white-light-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-white-light-4 {
|
||||||
|
color: var(--color-white-light-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
padding-inline: 6px 0;
|
||||||
|
padding-block: 0;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea::-webkit-scrollbar {
|
||||||
|
width: var(--scrollbar-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea::-webkit-scrollbar-track {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea::-webkit-scrollbar-thumb {
|
||||||
|
background-color: transparent;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea:hover {
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--color-scrollbar-thumb);
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.bold-text {
|
||||||
|
color: var(--ant-color-text);
|
||||||
|
font-weight: var(--font-weight-medium);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-result-extra {
|
||||||
|
color: var(--ant-color-text-secondary);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
.driver-popover {
|
||||||
|
color: var(--ant-color-text);
|
||||||
|
|
||||||
|
.driver-popover-title {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
color: var(--ant-color-text);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
.ant-pro-layout {
|
.ant-pro-layout {
|
||||||
.ant-pro-sider {
|
.ant-pro-sider {
|
||||||
// &.ant-layout-sider {
|
|
||||||
// background: var(--color-white-1);
|
|
||||||
// }
|
|
||||||
.ant-layout-sider-children {
|
.ant-layout-sider-children {
|
||||||
background-color: var(--color-fill-1);
|
|
||||||
border-inline: none;
|
border-inline: none;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
// padding-inline: 16px;
|
// padding-inline: 16px;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { atom } from 'jotai';
|
||||||
|
|
||||||
|
// models expand keys: create, update , delete,
|
||||||
|
export const modelsExpandKeysAtom = atom<string[]>([]);
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { atom, getDefaultStore } from 'jotai';
|
||||||
|
|
||||||
|
export const routeCacheAtom = atom<any>(new Map());
|
||||||
|
|
||||||
|
export const setRouteCache = (key: string, value: any) => {
|
||||||
|
const store = getDefaultStore();
|
||||||
|
const cache = store.get(routeCacheAtom);
|
||||||
|
cache.set(key, value);
|
||||||
|
store.set(routeCacheAtom, cache);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteRouteCache = (key: string) => {
|
||||||
|
const store = getDefaultStore();
|
||||||
|
const cache = store.get(routeCacheAtom);
|
||||||
|
cache.delete(key);
|
||||||
|
store.set(routeCacheAtom, cache);
|
||||||
|
};
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { colorPrimary } from '@/config/theme';
|
||||||
|
import { atom } from 'jotai';
|
||||||
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
|
type UserSettings = {
|
||||||
|
theme: 'light' | 'realDark';
|
||||||
|
mode: 'light' | 'realDark' | 'auto';
|
||||||
|
colorPrimary: string;
|
||||||
|
isDarkTheme: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultSettings: UserSettings = {
|
||||||
|
theme: 'light',
|
||||||
|
mode: 'auto',
|
||||||
|
isDarkTheme: false,
|
||||||
|
colorPrimary: colorPrimary
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getStorageUserSettings = () => {
|
||||||
|
if (typeof window === 'undefined') return defaultSettings;
|
||||||
|
try {
|
||||||
|
const savedSettings = JSON.parse(
|
||||||
|
localStorage.getItem('userSettings') || '{}'
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
...defaultSettings,
|
||||||
|
...savedSettings
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return defaultSettings;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const userSettingsAtom = atomWithStorage<UserSettings>(
|
||||||
|
'userSettings',
|
||||||
|
defaultSettings
|
||||||
|
);
|
||||||
|
|
||||||
|
export const userSettingsHelperAtom = atom(
|
||||||
|
(get) => get(userSettingsAtom),
|
||||||
|
(get, set, update: Partial<UserSettings>) => {
|
||||||
|
const prev = get(userSettingsAtom);
|
||||||
|
const newSettings = {
|
||||||
|
...prev,
|
||||||
|
...(update || {})
|
||||||
|
};
|
||||||
|
set(userSettingsAtom, {
|
||||||
|
...newSettings,
|
||||||
|
colorPrimary: newSettings.colorPrimary || colorPrimary,
|
||||||
|
isDarkTheme: newSettings.theme === 'realDark'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { getDefaultStore } from 'jotai';
|
||||||
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
|
export const tabActiveAtom = atomWithStorage<Map<string, any>>(
|
||||||
|
'tabActiveStatus',
|
||||||
|
new Map()
|
||||||
|
);
|
||||||
|
|
||||||
|
export const setActiveStatus = (key: string, value: any) => {
|
||||||
|
const store = getDefaultStore();
|
||||||
|
const cache = store.get(tabActiveAtom);
|
||||||
|
cache.set(key, value);
|
||||||
|
store.set(tabActiveAtom, cache);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getActiveStatus = (key: string) => {
|
||||||
|
const store = getDefaultStore();
|
||||||
|
const cache = store.get(tabActiveAtom);
|
||||||
|
return cache.get(key);
|
||||||
|
};
|
||||||
+9
-1
@@ -6,9 +6,17 @@ export const userAtom = atomWithStorage<any>('userInfo', null);
|
|||||||
export const GPUStackVersionAtom = atom<{
|
export const GPUStackVersionAtom = atom<{
|
||||||
version: string;
|
version: string;
|
||||||
git_commit: string;
|
git_commit: string;
|
||||||
|
isProduction: boolean;
|
||||||
}>({
|
}>({
|
||||||
version: '',
|
version: '',
|
||||||
git_commit: ''
|
git_commit: '',
|
||||||
|
isProduction: false
|
||||||
|
});
|
||||||
|
|
||||||
|
export const UpdateCheckAtom = atom<{
|
||||||
|
latest_version: string;
|
||||||
|
}>({
|
||||||
|
latest_version: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
export const initialPasswordAtom = atomWithStorage<string>(
|
export const initialPasswordAtom = atomWithStorage<string>(
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
interface WatchRequest {
|
||||||
|
id: number;
|
||||||
|
token: any;
|
||||||
|
cancel: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
__GPUSTACK_WATCH_REQUEST_CLEAR__: {
|
||||||
|
watchIDValue: number;
|
||||||
|
requestList: WatchRequest[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__GPUSTACK_WATCH_REQUEST_CLEAR__ = {
|
||||||
|
watchIDValue: 0,
|
||||||
|
requestList: []
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateWatchIDValue = () => {
|
||||||
|
window.__GPUSTACK_WATCH_REQUEST_CLEAR__.watchIDValue =
|
||||||
|
window.__GPUSTACK_WATCH_REQUEST_CLEAR__.watchIDValue + 1;
|
||||||
|
return window.__GPUSTACK_WATCH_REQUEST_CLEAR__.watchIDValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateWatchRequest = (watchToken: WatchRequest) => {
|
||||||
|
window.__GPUSTACK_WATCH_REQUEST_CLEAR__.requestList.push(watchToken);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const cancelWatchRequest = (n: number) => {
|
||||||
|
// cancel the before n requests
|
||||||
|
const requestList = window.__GPUSTACK_WATCH_REQUEST_CLEAR__.requestList;
|
||||||
|
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
requestList[i]?.cancel?.();
|
||||||
|
}
|
||||||
|
window.__GPUSTACK_WATCH_REQUEST_CLEAR__.requestList = requestList.slice(n);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const clearWatchRequestId = (id: number) => {
|
||||||
|
const requestList = window.__GPUSTACK_WATCH_REQUEST_CLEAR__.requestList;
|
||||||
|
const newRequestList = requestList.filter((item) => item.id !== id);
|
||||||
|
window.__GPUSTACK_WATCH_REQUEST_CLEAR__.requestList = newRequestList;
|
||||||
|
};
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
.alert-info-block {
|
||||||
|
padding-block: 6px;
|
||||||
|
padding-inline: 10px 16px;
|
||||||
|
position: relative;
|
||||||
|
padding-left: 32px;
|
||||||
|
text-align: left;
|
||||||
|
border-radius: var(--border-radius-base);
|
||||||
|
margin: 0;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
|
||||||
|
.ant-typography {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.danger {
|
||||||
|
border-color: var(--ant-color-error-border);
|
||||||
|
background-color: var(--ant-color-error-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.warning {
|
||||||
|
border-color: var(--ant-color-warning-border);
|
||||||
|
background-color: var(--ant-color-warning-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.transition {
|
||||||
|
color: var(--ant-geekblue-7);
|
||||||
|
background: var(--ant-geekblue-1);
|
||||||
|
border-color: var(--ant-geekblue-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.success {
|
||||||
|
border: 1px solid var(--ant-color-success);
|
||||||
|
color: var(--ant-color-success);
|
||||||
|
background: var(--ant-color-success-bg);
|
||||||
|
|
||||||
|
.content.success {
|
||||||
|
font-weight: var(--font-weight-normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
display: flex;
|
||||||
|
height: 32px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: var(--border-radius-base) var(--border-radius-base) 0 0;
|
||||||
|
|
||||||
|
.info-icon {
|
||||||
|
&.danger {
|
||||||
|
color: var(--ant-color-error);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.warning {
|
||||||
|
color: var(--ant-color-warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.transition {
|
||||||
|
color: var(--ant-geekblue-7);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.success {
|
||||||
|
color: var(--ant-color-success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.text {
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import { WarningFilled } from '@ant-design/icons';
|
||||||
|
import { Typography } from 'antd';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import React from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import OverlayScroller from '../overlay-scroller';
|
||||||
|
import './block.less';
|
||||||
|
interface AlertInfoProps {
|
||||||
|
type: Global.MessageType;
|
||||||
|
message: React.ReactNode;
|
||||||
|
rows?: number;
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
ellipsis?: boolean;
|
||||||
|
style?: React.CSSProperties;
|
||||||
|
contentStyle?: React.CSSProperties;
|
||||||
|
title?: React.ReactNode;
|
||||||
|
maxHeight?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TitleWrapper = styled.div`
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--ant-color-text);
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ContentWrapper = styled.div<{ $hasTitle: boolean }>`
|
||||||
|
word-break: break-word;
|
||||||
|
color: ${(props) =>
|
||||||
|
props.$hasTitle
|
||||||
|
? 'var(--ant-color-text-secondary)'
|
||||||
|
: 'var(--ant-color-text)'};
|
||||||
|
font-weight: var(--font-weight-500);
|
||||||
|
`;
|
||||||
|
|
||||||
|
const AlertInfo: React.FC<AlertInfoProps> = (props) => {
|
||||||
|
const {
|
||||||
|
message,
|
||||||
|
type,
|
||||||
|
rows = 1,
|
||||||
|
ellipsis,
|
||||||
|
style,
|
||||||
|
title,
|
||||||
|
contentStyle,
|
||||||
|
icon,
|
||||||
|
maxHeight = 86
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{message ? (
|
||||||
|
<div
|
||||||
|
className={classNames('alert-info-block', type)}
|
||||||
|
style={{ ...style }}
|
||||||
|
>
|
||||||
|
<Typography.Paragraph
|
||||||
|
ellipsis={
|
||||||
|
ellipsis ?? {
|
||||||
|
rows: rows,
|
||||||
|
tooltip: message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className={classNames('title', type)}>
|
||||||
|
<span className={classNames('info-icon', type)}>
|
||||||
|
{icon ?? <WarningFilled />}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{title && (
|
||||||
|
<TitleWrapper className="title-text">{title}</TitleWrapper>
|
||||||
|
)}
|
||||||
|
<OverlayScroller maxHeight={maxHeight} style={{ ...contentStyle }}>
|
||||||
|
<ContentWrapper
|
||||||
|
$hasTitle={!!title}
|
||||||
|
className={classNames('content', type)}
|
||||||
|
>
|
||||||
|
{message}
|
||||||
|
</ContentWrapper>
|
||||||
|
</OverlayScroller>
|
||||||
|
</Typography.Paragraph>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(AlertInfo);
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { WarningOutlined } from '@ant-design/icons';
|
||||||
|
import { Typography } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface AlertInfoProps {
|
||||||
|
type: 'danger' | 'warning';
|
||||||
|
message: string;
|
||||||
|
rows?: number;
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
ellipsis?: boolean;
|
||||||
|
style?: React.CSSProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AlertInfo: React.FC<AlertInfoProps> = (props) => {
|
||||||
|
const { message, type, rows = 1, ellipsis, style } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{message ? (
|
||||||
|
<Typography.Paragraph
|
||||||
|
type={type}
|
||||||
|
ellipsis={
|
||||||
|
ellipsis !== undefined
|
||||||
|
? ellipsis
|
||||||
|
: {
|
||||||
|
rows: rows,
|
||||||
|
tooltip: message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
style={{
|
||||||
|
textAlign: 'center',
|
||||||
|
padding: '2px 5px',
|
||||||
|
borderRadius: 'var(--border-radius-base)',
|
||||||
|
margin: 0,
|
||||||
|
backgroundColor: 'var(--ant-color-error-bg)',
|
||||||
|
...style
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<WarningOutlined className="m-r-8" />
|
||||||
|
{message}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(AlertInfo);
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
.canvas-wrap {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
text-align: center;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
image-rendering: crisp-edges;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.scroller-wrapper {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
import useResizeObserver from '@/components/logs-viewer/use-size';
|
||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
|
interface AudioAnimationProps {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
maxWidth?: number;
|
||||||
|
scaleFactor?: number;
|
||||||
|
maxBarCount?: number;
|
||||||
|
amplitude?: number;
|
||||||
|
fixedHeight?: boolean;
|
||||||
|
analyserData: {
|
||||||
|
data: Uint8Array;
|
||||||
|
analyser: any;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const AudioAnimation: React.FC<AudioAnimationProps> = (props) => {
|
||||||
|
const {
|
||||||
|
scaleFactor = 1.2,
|
||||||
|
maxBarCount = 128,
|
||||||
|
amplitude = 40,
|
||||||
|
maxWidth,
|
||||||
|
fixedHeight = true,
|
||||||
|
analyserData,
|
||||||
|
width: initialWidth,
|
||||||
|
height: initialHeight
|
||||||
|
} = props;
|
||||||
|
const canvasRef = React.useRef<HTMLCanvasElement>(null);
|
||||||
|
const animationId = React.useRef<number>(0);
|
||||||
|
const isScaled = React.useRef<boolean>(false);
|
||||||
|
const oscillationOffset = React.useRef(0);
|
||||||
|
const direction = React.useRef(1);
|
||||||
|
const scrollerRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
const [width, setWidth] = useState(initialWidth);
|
||||||
|
const [height, setHeight] = useState(initialHeight);
|
||||||
|
const containerRef = React.useRef<any>(null);
|
||||||
|
|
||||||
|
const size = useResizeObserver(scrollerRef);
|
||||||
|
|
||||||
|
const calculateJitter = (
|
||||||
|
i: number,
|
||||||
|
timestamp: number,
|
||||||
|
baseHeight: number,
|
||||||
|
minJitter: number,
|
||||||
|
jitterAmplitude: number
|
||||||
|
) => {
|
||||||
|
//
|
||||||
|
const jitterFactor = Math.sin(timestamp / 200 + i) * 0.5 + 0.5;
|
||||||
|
const jitter =
|
||||||
|
minJitter +
|
||||||
|
jitterFactor * (jitterAmplitude - minJitter) * (baseHeight / maxBarCount);
|
||||||
|
return jitter;
|
||||||
|
};
|
||||||
|
|
||||||
|
const startAudioVisualization = () => {
|
||||||
|
if (!canvasRef.current || !analyserData.data?.length) return;
|
||||||
|
|
||||||
|
const canvas = canvasRef.current;
|
||||||
|
const canvasCtx = canvas.getContext('2d');
|
||||||
|
if (!canvasCtx) return;
|
||||||
|
|
||||||
|
const WIDTH = (canvas.width = width * 2);
|
||||||
|
const HEIGHT = (canvas.height = height * 2);
|
||||||
|
|
||||||
|
if (!isScaled.current) {
|
||||||
|
canvasCtx.scale(2, 2);
|
||||||
|
isScaled.current = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const barWidth = 4;
|
||||||
|
const barSpacing = 6;
|
||||||
|
const centerLine = Math.floor(HEIGHT / 2);
|
||||||
|
|
||||||
|
const jitterAmplitude = amplitude;
|
||||||
|
const minJitter = 10;
|
||||||
|
|
||||||
|
let lastFrameTime = 0;
|
||||||
|
|
||||||
|
const gradient = canvasCtx.createLinearGradient(0, 0, 0, HEIGHT);
|
||||||
|
gradient.addColorStop(0, '#007BFF');
|
||||||
|
gradient.addColorStop(1, '#0069DA');
|
||||||
|
canvasCtx.fillStyle = gradient;
|
||||||
|
|
||||||
|
const draw = (timestamp: number) => {
|
||||||
|
const elapsed = timestamp - lastFrameTime;
|
||||||
|
if (elapsed < 16) {
|
||||||
|
animationId.current = requestAnimationFrame(draw);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastFrameTime = timestamp;
|
||||||
|
|
||||||
|
analyserData.analyser?.current?.getByteFrequencyData(analyserData.data);
|
||||||
|
canvasCtx.clearRect(0, 0, WIDTH, HEIGHT);
|
||||||
|
|
||||||
|
const barCount = Math.min(maxBarCount, analyserData.data.length);
|
||||||
|
const totalWidth = barCount * (barWidth + barSpacing) - barSpacing;
|
||||||
|
let x = WIDTH / 2 - totalWidth / 2 + oscillationOffset.current;
|
||||||
|
|
||||||
|
oscillationOffset.current += direction.current;
|
||||||
|
if (Math.abs(oscillationOffset.current) > 20) {
|
||||||
|
direction.current *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < barCount; i++) {
|
||||||
|
const baseHeight = Math.floor(analyserData.data[i] / 2) * scaleFactor;
|
||||||
|
|
||||||
|
const jitter = calculateJitter(
|
||||||
|
i,
|
||||||
|
timestamp,
|
||||||
|
baseHeight,
|
||||||
|
minJitter,
|
||||||
|
jitterAmplitude
|
||||||
|
);
|
||||||
|
const barHeight = baseHeight + Math.round(jitter);
|
||||||
|
|
||||||
|
const topY = Math.round(centerLine - barHeight / 2);
|
||||||
|
const bottomY = Math.round(centerLine + barHeight / 2);
|
||||||
|
|
||||||
|
canvasCtx.beginPath();
|
||||||
|
canvasCtx.moveTo(x, bottomY);
|
||||||
|
canvasCtx.lineTo(x, topY + 2);
|
||||||
|
canvasCtx.arcTo(x + barWidth, topY + 2, x + barWidth, bottomY, 2);
|
||||||
|
canvasCtx.lineTo(x + barWidth, bottomY);
|
||||||
|
canvasCtx.closePath();
|
||||||
|
canvasCtx.fill();
|
||||||
|
|
||||||
|
x += barWidth + barSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
animationId.current = requestAnimationFrame(draw);
|
||||||
|
};
|
||||||
|
|
||||||
|
draw(performance.now());
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (size) {
|
||||||
|
if (maxWidth) {
|
||||||
|
setWidth(Math.min(size.width, maxWidth));
|
||||||
|
} else {
|
||||||
|
setWidth(size?.width || 0);
|
||||||
|
}
|
||||||
|
if (!fixedHeight) {
|
||||||
|
setHeight(size?.height || 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [size, maxWidth]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!canvasRef.current) return;
|
||||||
|
const clearCanvas = () => {
|
||||||
|
if (canvasRef.current) {
|
||||||
|
const ctx = canvasRef.current.getContext('2d');
|
||||||
|
if (ctx) ctx.clearRect(0, 0, width * 2, height * 2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!analyserData.data?.length || !analyserData.analyser?.current) {
|
||||||
|
clearCanvas();
|
||||||
|
cancelAnimationFrame(animationId.current);
|
||||||
|
animationId.current = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
startAudioVisualization();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelAnimationFrame(animationId.current);
|
||||||
|
clearCanvas();
|
||||||
|
};
|
||||||
|
}, [analyserData, width, height]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="scroller-wrapper"
|
||||||
|
ref={scrollerRef}
|
||||||
|
style={{ width: '100%', height: '100%' }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
ref={containerRef}
|
||||||
|
className="canvas-wrap"
|
||||||
|
style={{ width: '100%', height: '100%' }}
|
||||||
|
>
|
||||||
|
<canvas ref={canvasRef} style={{ display: 'block' }}></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(AudioAnimation);
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
export type AudioEvent =
|
||||||
|
| 'play'
|
||||||
|
| 'playing'
|
||||||
|
| 'pause'
|
||||||
|
| 'timeupdate'
|
||||||
|
| 'ended'
|
||||||
|
| 'loadedmetadata'
|
||||||
|
| 'audioprocess'
|
||||||
|
| 'canplay'
|
||||||
|
| 'ended'
|
||||||
|
| 'loadeddata'
|
||||||
|
| 'seeked'
|
||||||
|
| 'seeking'
|
||||||
|
| 'volumechange';
|
||||||
|
|
||||||
|
export interface AudioPlayerProps {
|
||||||
|
controls?: boolean;
|
||||||
|
autoplay?: boolean;
|
||||||
|
url: string;
|
||||||
|
speed?: number;
|
||||||
|
ref?: any;
|
||||||
|
height?: number;
|
||||||
|
width?: number;
|
||||||
|
duration?: number;
|
||||||
|
onPlay?: () => void;
|
||||||
|
onPlaying?: () => void;
|
||||||
|
onPause?: () => void;
|
||||||
|
onTimeUpdate?: () => void;
|
||||||
|
onEnded?: () => void;
|
||||||
|
onLoadedMetadata?: (duration: number) => void;
|
||||||
|
onAudioProcess?: (current: number) => void;
|
||||||
|
onCanPlay?: () => void;
|
||||||
|
onLoadedData?: () => void;
|
||||||
|
onSeeked?: () => void;
|
||||||
|
onSeeking?: () => void;
|
||||||
|
onVolumeChange?: () => void;
|
||||||
|
onReady?: (duration: number) => void;
|
||||||
|
onAnalyse?: (analyseData: any, frequencyBinCount: any) => void;
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
.player-wrap {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
// background-color: var(--ant-color-fill-quaternary);
|
||||||
|
border-radius: 6px;
|
||||||
|
|
||||||
|
.player-ui {
|
||||||
|
padding: 8px 16px;
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-btn {
|
||||||
|
margin-inline: 30px;
|
||||||
|
height: 22px;
|
||||||
|
width: 22px;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.ant-btn {
|
||||||
|
height: 22px;
|
||||||
|
width: 22px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.backward,
|
||||||
|
.forward {
|
||||||
|
background: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.slider-inner {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-content {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time {
|
||||||
|
width: 52px;
|
||||||
|
text-align: right;
|
||||||
|
|
||||||
|
&.current {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar {
|
||||||
|
margin-inline: 10px;
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
.slider {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-name {
|
||||||
|
margin-bottom: 6px;
|
||||||
|
line-height: 20px;
|
||||||
|
height: 20px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
align-self: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-slider-horizontal {
|
||||||
|
margin-block: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.speaker {
|
||||||
|
margin-left: 10px;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.volume-slider {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 30px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,311 @@
|
|||||||
|
import { formatTime } from '@/utils/index';
|
||||||
|
import {
|
||||||
|
FastBackwardOutlined,
|
||||||
|
FastForwardOutlined,
|
||||||
|
PauseCircleFilled,
|
||||||
|
PlayCircleFilled
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { Button, Slider, Tooltip } from 'antd';
|
||||||
|
import { round } from 'lodash';
|
||||||
|
import React, {
|
||||||
|
forwardRef,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle
|
||||||
|
} from 'react';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
|
interface AudioPlayerProps {
|
||||||
|
autoplay?: boolean;
|
||||||
|
url: string;
|
||||||
|
speed?: number;
|
||||||
|
ref?: any;
|
||||||
|
name: string;
|
||||||
|
height?: number;
|
||||||
|
width?: number;
|
||||||
|
duration?: number;
|
||||||
|
extra?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const speedOptions = [
|
||||||
|
{ label: '1x', value: 1 },
|
||||||
|
{ label: '2x', value: 2 },
|
||||||
|
{ label: '3x', value: 3 },
|
||||||
|
{ label: '4x', value: 4 }
|
||||||
|
];
|
||||||
|
|
||||||
|
const speedConfig = {
|
||||||
|
min: 0.5,
|
||||||
|
max: 2,
|
||||||
|
step: 0.25
|
||||||
|
};
|
||||||
|
|
||||||
|
const AudioPlayer: React.FC<AudioPlayerProps> = forwardRef((props, ref) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
const { autoplay = false, speed: defaultSpeed = 1, extra } = props;
|
||||||
|
const audioRef = React.useRef<HTMLAudioElement>(null);
|
||||||
|
const [audioState, setAudioState] = React.useState<{
|
||||||
|
currentTime: number;
|
||||||
|
duration: number;
|
||||||
|
}>({
|
||||||
|
currentTime: 0,
|
||||||
|
duration: 0
|
||||||
|
});
|
||||||
|
const [playOn, setPlayOn] = React.useState<boolean>(false);
|
||||||
|
const [speakerOn, setSpeakerOn] = React.useState<boolean>(false);
|
||||||
|
const [volume, setVolume] = React.useState<number>(1);
|
||||||
|
const [speed, setSpeed] = React.useState<number>(defaultSpeed);
|
||||||
|
const timer = React.useRef<any>(null);
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
play: () => {
|
||||||
|
audioRef.current?.play();
|
||||||
|
},
|
||||||
|
pause: () => {
|
||||||
|
audioRef.current?.pause();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
const handleShowVolume = useCallback(() => {
|
||||||
|
setSpeakerOn(!speakerOn);
|
||||||
|
}, [speakerOn]);
|
||||||
|
|
||||||
|
const handleSeepdChange = useCallback((value: number | string) => {
|
||||||
|
setSpeed(value as number);
|
||||||
|
audioRef.current!.playbackRate = value as number;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleAudioOnPlay = useCallback(() => {
|
||||||
|
console.log('audio play');
|
||||||
|
timer.current = setInterval(() => {
|
||||||
|
setAudioState((prestate) => {
|
||||||
|
return {
|
||||||
|
currentTime: Math.ceil(audioRef.current?.currentTime || 0),
|
||||||
|
duration:
|
||||||
|
prestate.duration || Math.ceil(audioRef.current?.duration || 0)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (audioRef.current?.paused || audioRef.current?.ended) {
|
||||||
|
clearInterval(timer.current);
|
||||||
|
setPlayOn(false);
|
||||||
|
setAudioState((prestate: any) => {
|
||||||
|
return {
|
||||||
|
currentTime: audioRef.current?.ended ? 0 : prestate.currentTime,
|
||||||
|
duration: prestate.duration
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handlePlay = useCallback(() => {
|
||||||
|
setPlayOn(!playOn);
|
||||||
|
if (playOn) {
|
||||||
|
audioRef.current?.pause();
|
||||||
|
} else {
|
||||||
|
audioRef.current?.play();
|
||||||
|
}
|
||||||
|
}, [playOn]);
|
||||||
|
|
||||||
|
const handleFormatVolume = (val?: number) => {
|
||||||
|
if (val === undefined) {
|
||||||
|
return `${round(volume * 100)}%`;
|
||||||
|
}
|
||||||
|
return `${round(val * 100)}%`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleVolumeChange = useCallback((value: number) => {
|
||||||
|
audioRef.current!.volume = round(value, 2);
|
||||||
|
setVolume(round(value, 2));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const initPlayerConfig = () => {
|
||||||
|
if (audioRef.current) {
|
||||||
|
audioRef.current!.volume = volume;
|
||||||
|
audioRef.current!.playbackRate = speed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLoadedMetadata = useCallback(
|
||||||
|
(data: any) => {
|
||||||
|
const duration = Math.ceil(audioRef.current?.duration || 0);
|
||||||
|
setAudioState({
|
||||||
|
currentTime: 0,
|
||||||
|
duration:
|
||||||
|
duration && duration !== Infinity ? duration : props.duration || 0
|
||||||
|
});
|
||||||
|
setPlayOn(autoplay);
|
||||||
|
},
|
||||||
|
[autoplay, props.duration]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleCurrentChange = useCallback((val: number) => {
|
||||||
|
audioRef.current!.currentTime = val;
|
||||||
|
setAudioState((prestate) => {
|
||||||
|
return {
|
||||||
|
currentTime: val,
|
||||||
|
duration: prestate.duration
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleReduceSpeed = () => {
|
||||||
|
setSpeed((pre) => {
|
||||||
|
if (pre - speedConfig.step < speedConfig.min) {
|
||||||
|
return speedConfig.min;
|
||||||
|
}
|
||||||
|
const next = pre - speedConfig.step;
|
||||||
|
audioRef.current!.playbackRate = next;
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAddSpeed = () => {
|
||||||
|
setSpeed((pre) => {
|
||||||
|
if (pre + speedConfig.step > speedConfig.max) {
|
||||||
|
return speedConfig.max;
|
||||||
|
}
|
||||||
|
const next = pre + speedConfig.step;
|
||||||
|
audioRef.current!.playbackRate = next;
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnLoad = (e: any) => {
|
||||||
|
console.log('onload', e);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDownload = useCallback(() => {
|
||||||
|
const url = props.url || '';
|
||||||
|
const filename = props.name;
|
||||||
|
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = filename;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
}, [props.url, props.name]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (audioRef.current) {
|
||||||
|
initPlayerConfig();
|
||||||
|
}
|
||||||
|
}, [audioRef.current]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
clearInterval(timer.current);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="player-wrap" style={{ width: props.width || '100%' }}>
|
||||||
|
<div className="player-ui">
|
||||||
|
<div className="play-content">
|
||||||
|
<div className="progress-bar">
|
||||||
|
<span className="file-name">{props.name}</span>
|
||||||
|
<div className="slider">
|
||||||
|
{/* <span className="time current">
|
||||||
|
{' '}
|
||||||
|
{formatTime(audioState.currentTime)}
|
||||||
|
</span> */}
|
||||||
|
<div className="slider-inner">
|
||||||
|
<Slider
|
||||||
|
tooltip={{ open: false }}
|
||||||
|
min={0}
|
||||||
|
step={1}
|
||||||
|
styles={{
|
||||||
|
rail: {
|
||||||
|
// height: 6
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
max={audioState.duration}
|
||||||
|
value={audioState.currentTime}
|
||||||
|
onChange={handleCurrentChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/* <span className="time">{formatTime(audioState.duration)}</span> */}
|
||||||
|
</div>
|
||||||
|
<div className="controls">
|
||||||
|
<div className="audio-control flex-center">
|
||||||
|
<span className="time current">
|
||||||
|
{' '}
|
||||||
|
{formatTime(audioState.currentTime)}
|
||||||
|
</span>
|
||||||
|
<Tooltip
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'playground.audio.button.slow'
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
className="backward"
|
||||||
|
disabled={
|
||||||
|
speed === speedConfig.min || speed < speedConfig.min
|
||||||
|
}
|
||||||
|
onClick={handleReduceSpeed}
|
||||||
|
>
|
||||||
|
<FastBackwardOutlined className="font-size-20" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
<span className="play-btn">
|
||||||
|
<Button
|
||||||
|
size="middle"
|
||||||
|
type="text"
|
||||||
|
onClick={handlePlay}
|
||||||
|
disabled={!audioState?.duration}
|
||||||
|
icon={
|
||||||
|
!playOn ? (
|
||||||
|
<PlayCircleFilled
|
||||||
|
style={{ fontSize: '22px' }}
|
||||||
|
></PlayCircleFilled>
|
||||||
|
) : (
|
||||||
|
<PauseCircleFilled
|
||||||
|
style={{ fontSize: '22px' }}
|
||||||
|
></PauseCircleFilled>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
></Button>
|
||||||
|
</span>
|
||||||
|
<Tooltip
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'playground.audio.button.fast'
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
className="forward"
|
||||||
|
disabled={
|
||||||
|
speed === speedConfig.max || speed > speedConfig.max
|
||||||
|
}
|
||||||
|
onClick={handleAddSpeed}
|
||||||
|
>
|
||||||
|
<FastForwardOutlined className="font-size-20" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
<span className="time">{formatTime(audioState.duration)}</span>
|
||||||
|
</div>
|
||||||
|
{extra}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<audio
|
||||||
|
crossOrigin="anonymous"
|
||||||
|
autoPlay={autoplay}
|
||||||
|
src={props.url}
|
||||||
|
ref={audioRef}
|
||||||
|
preload="metadata"
|
||||||
|
style={{ opacity: 0, position: 'absolute', left: '-9999px' }}
|
||||||
|
onPlay={handleAudioOnPlay}
|
||||||
|
onLoadedMetadata={handleLoadedMetadata}
|
||||||
|
></audio>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default React.memo(AudioPlayer);
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
import React, {
|
||||||
|
forwardRef,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle,
|
||||||
|
useRef
|
||||||
|
} from 'react';
|
||||||
|
import { AudioPlayerProps } from './config/type';
|
||||||
|
|
||||||
|
const RawAudioPlayer: React.FC<AudioPlayerProps> = forwardRef((props, ref) => {
|
||||||
|
const { autoplay = false } = props;
|
||||||
|
const audioRef = React.useRef<HTMLAudioElement>(null);
|
||||||
|
|
||||||
|
// =================== audio context ======================
|
||||||
|
const audioContext = useRef<any>(null);
|
||||||
|
const analyser = useRef<any>(null);
|
||||||
|
const dataArray = useRef<any>(null);
|
||||||
|
// ========================================================
|
||||||
|
|
||||||
|
const initAudioContext = useCallback(() => {
|
||||||
|
audioContext.current = new (window.AudioContext ||
|
||||||
|
window.webkitAudioContext)();
|
||||||
|
|
||||||
|
analyser.current = audioContext.current.createAnalyser();
|
||||||
|
analyser.current.fftSize = 512;
|
||||||
|
dataArray.current = new Uint8Array(analyser.current.frequencyBinCount);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const generateVisualData = useCallback(() => {
|
||||||
|
const source = audioContext.current.createMediaElementSource(
|
||||||
|
audioRef.current
|
||||||
|
);
|
||||||
|
source.connect(analyser.current);
|
||||||
|
analyser.current.connect(audioContext.current.destination);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const initEnvents = () => {
|
||||||
|
if (!audioRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('complete', () => {});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('play', () => {
|
||||||
|
props.onAnalyse?.(dataArray.current, analyser);
|
||||||
|
props.onPlay?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('pause', () => {
|
||||||
|
props.onAnalyse?.(dataArray.current, analyser);
|
||||||
|
props.onPause?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('timeupdate', () => {
|
||||||
|
props.onTimeUpdate?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('ended', () => {
|
||||||
|
props.onEnded?.();
|
||||||
|
});
|
||||||
|
// add all other events
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('canplay', () => {
|
||||||
|
props.onCanPlay?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('loadeddata', () => {
|
||||||
|
initEnvents();
|
||||||
|
if (!audioContext.current) {
|
||||||
|
initAudioContext();
|
||||||
|
generateVisualData();
|
||||||
|
}
|
||||||
|
props.onLoadedData?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('seeked', () => {
|
||||||
|
props.onSeeked?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('seeking', () => {
|
||||||
|
props.onSeeking?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('volumechange', () => {
|
||||||
|
props.onVolumeChange?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('audioprocess', () => {
|
||||||
|
const current = audioRef.current?.currentTime || 0;
|
||||||
|
props.onAudioProcess?.(current);
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('playing', () => {
|
||||||
|
props.onPlaying?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('loadedmetadata', () => {
|
||||||
|
const duration = audioRef.current?.duration || 0;
|
||||||
|
props.onLoadedMetadata?.(duration);
|
||||||
|
props.onReady?.(duration);
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('ended', () => {
|
||||||
|
props.onEnded?.();
|
||||||
|
});
|
||||||
|
|
||||||
|
audioRef.current.addEventListener('loadeddata', () => {
|
||||||
|
props.onLoadedData?.();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
play: () => {
|
||||||
|
audioRef.current?.play();
|
||||||
|
},
|
||||||
|
pause: () => {
|
||||||
|
audioRef.current?.pause();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (audioRef.current) {
|
||||||
|
console.log('audioRef.current', audioRef.current, props.url);
|
||||||
|
initEnvents();
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
if (audioContext.current) {
|
||||||
|
audioContext.current.close();
|
||||||
|
}
|
||||||
|
// remove all events
|
||||||
|
|
||||||
|
audioRef.current?.removeEventListener('play', () => {});
|
||||||
|
audioRef.current?.removeEventListener('pause', () => {});
|
||||||
|
audioRef.current?.removeEventListener('timeupdate', () => {});
|
||||||
|
audioRef.current?.removeEventListener('ended', () => {});
|
||||||
|
audioRef.current?.removeEventListener('canplay', () => {});
|
||||||
|
audioRef.current?.removeEventListener('loadeddata', () => {});
|
||||||
|
audioRef.current?.removeEventListener('seeked', () => {});
|
||||||
|
audioRef.current?.removeEventListener('seeking', () => {});
|
||||||
|
audioRef.current?.removeEventListener('volumechange', () => {});
|
||||||
|
audioRef.current?.removeEventListener('audioprocess', () => {});
|
||||||
|
audioRef.current?.removeEventListener('playing', () => {});
|
||||||
|
audioRef.current?.removeEventListener('loadedmetadata', () => {});
|
||||||
|
audioRef.current?.removeEventListener('ended', () => {});
|
||||||
|
audioRef.current?.removeEventListener('loadeddata', () => {});
|
||||||
|
};
|
||||||
|
}, [audioRef.current]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<audio
|
||||||
|
controls
|
||||||
|
autoPlay={autoplay}
|
||||||
|
src={props.url}
|
||||||
|
ref={audioRef}
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
left: '-9999px',
|
||||||
|
opacity: 0
|
||||||
|
}}
|
||||||
|
preload="metadata"
|
||||||
|
></audio>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default RawAudioPlayer;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
.toolbar-wrapper {
|
||||||
|
padding: 0 24px;
|
||||||
|
color: rgba(255, 255, 255, 65%);
|
||||||
|
font-size: 16px;
|
||||||
|
background-color: rgba(0, 0, 0, 10%);
|
||||||
|
border-radius: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-wrapper .anticon {
|
||||||
|
padding: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-wrapper .anticon[disabled] {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-wrapper .anticon:hover {
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
import fallbackImg from '@/assets/images/img_fallback.png';
|
||||||
|
import {
|
||||||
|
DownloadOutlined,
|
||||||
|
EyeOutlined,
|
||||||
|
RotateLeftOutlined,
|
||||||
|
RotateRightOutlined,
|
||||||
|
SwapOutlined,
|
||||||
|
UndoOutlined,
|
||||||
|
ZoomInOutlined,
|
||||||
|
ZoomOutOutlined
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import { Image as AntImage, ImageProps, Space } from 'antd';
|
||||||
|
import { round } from 'lodash';
|
||||||
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
|
const AutoImage: React.FC<
|
||||||
|
ImageProps & {
|
||||||
|
height: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
autoSize?: boolean;
|
||||||
|
preview?: boolean;
|
||||||
|
onLoad?: () => void;
|
||||||
|
}
|
||||||
|
> = (props) => {
|
||||||
|
const { height = 100, width: w, autoSize, preview = true, ...rest } = props;
|
||||||
|
const [width, setWidth] = useState(w || 0);
|
||||||
|
const [isError, setIsError] = useState(false);
|
||||||
|
|
||||||
|
const getImgRatio = useCallback((url: string): Promise<{ ratio: number }> => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
resolve({ ratio: round(img.width / img.height, 2) });
|
||||||
|
};
|
||||||
|
img.onerror = () => {
|
||||||
|
resolve({ ratio: 1 });
|
||||||
|
};
|
||||||
|
img.src = url;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleOnLoad = useCallback(async () => {
|
||||||
|
if (autoSize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { ratio } = await getImgRatio(props.src || '');
|
||||||
|
|
||||||
|
if (typeof height === 'number') {
|
||||||
|
setWidth(height * ratio);
|
||||||
|
} else {
|
||||||
|
throw new Error('Height must be a number');
|
||||||
|
}
|
||||||
|
}, [getImgRatio, height, props.src]);
|
||||||
|
|
||||||
|
const onDownload = useCallback(() => {
|
||||||
|
const url = props.src || '';
|
||||||
|
const filename = Date.now() + '';
|
||||||
|
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = filename;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
}, [props.src]);
|
||||||
|
|
||||||
|
const handleImgLoad = useCallback(() => {
|
||||||
|
props.onLoad?.();
|
||||||
|
setIsError(false);
|
||||||
|
}, [props.onLoad]);
|
||||||
|
|
||||||
|
const handleOnError = useCallback(() => {
|
||||||
|
setIsError(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleOnLoad();
|
||||||
|
}, [handleOnLoad]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setWidth(w || 0);
|
||||||
|
}, [w]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AntImage
|
||||||
|
{...rest}
|
||||||
|
height={isError ? 'auto' : height}
|
||||||
|
width={isError ? '100%' : width}
|
||||||
|
onError={handleOnError}
|
||||||
|
onLoad={handleImgLoad}
|
||||||
|
fallback={fallbackImg}
|
||||||
|
crossOrigin="anonymous"
|
||||||
|
preview={
|
||||||
|
preview &&
|
||||||
|
!isError && {
|
||||||
|
mask: <EyeOutlined />,
|
||||||
|
toolbarRender: (
|
||||||
|
_,
|
||||||
|
{
|
||||||
|
transform: { scale },
|
||||||
|
actions: {
|
||||||
|
onFlipY,
|
||||||
|
onFlipX,
|
||||||
|
onRotateLeft,
|
||||||
|
onRotateRight,
|
||||||
|
onZoomOut,
|
||||||
|
onZoomIn,
|
||||||
|
onReset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) => (
|
||||||
|
<Space size={12} className="toolbar-wrapper">
|
||||||
|
<DownloadOutlined onClick={onDownload} />
|
||||||
|
<SwapOutlined rotate={90} onClick={onFlipY} />
|
||||||
|
<SwapOutlined onClick={onFlipX} />
|
||||||
|
<RotateLeftOutlined onClick={onRotateLeft} />
|
||||||
|
<RotateRightOutlined onClick={onRotateRight} />
|
||||||
|
<ZoomOutOutlined disabled={scale === 1} onClick={onZoomOut} />
|
||||||
|
<ZoomInOutlined disabled={scale === 50} onClick={onZoomIn} />
|
||||||
|
<UndoOutlined onClick={onReset} />
|
||||||
|
</Space>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(AutoImage);
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
.img-wrapper {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.img-wrapper .auto-image {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.img-wrapper .progress-wrapper {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-square {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-square-bg {
|
||||||
|
fill: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-square-fg {
|
||||||
|
fill: none;
|
||||||
|
stroke-linecap: square;
|
||||||
|
stroke-dasharray: 400;
|
||||||
|
stroke-dashoffset: 400;
|
||||||
|
transition: stroke-dashoffset 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-text {
|
||||||
|
position: absolute;
|
||||||
|
color: black;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
.thumb-img {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: var(--border-radius-base);
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.label {
|
||||||
|
position: absolute;
|
||||||
|
top: 4px;
|
||||||
|
left: 4px;
|
||||||
|
height: 20px;
|
||||||
|
line-height: 20px;
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 0 8px;
|
||||||
|
background-color: var(--ant-geekblue-1);
|
||||||
|
z-index: 10;
|
||||||
|
transform: scale(0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-wrapper {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 20px;
|
||||||
|
left: 20px;
|
||||||
|
right: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.small-progress-wrap {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
background-color: rgba(0, 0, 0, 30%);
|
||||||
|
|
||||||
|
.ant-progress-text {
|
||||||
|
color: var(--color-white-secondary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.img {
|
||||||
|
display: flex;
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: var(--border-radius-base);
|
||||||
|
cursor: pointer;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.del {
|
||||||
|
position: absolute;
|
||||||
|
top: -4px;
|
||||||
|
right: -2px;
|
||||||
|
font-size: var(--font-size-middle);
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: var(--color-white-1);
|
||||||
|
display: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
overflow: hidden;
|
||||||
|
pointer-events: all;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
.ant-image .ant-image-mask {
|
||||||
|
opacity: 1;
|
||||||
|
transition: opacity var(--ant-motion-duration-slow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.del {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.single-image {
|
||||||
|
height: 100%;
|
||||||
|
width: inherit;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: var(--border-radius-base);
|
||||||
|
|
||||||
|
&.loading {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.auto-bg-color {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
filter: blur(100px);
|
||||||
|
backdrop-filter: blur(100px);
|
||||||
|
z-index: 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumb-img {
|
||||||
|
position: relative;
|
||||||
|
z-index: 10;
|
||||||
|
border-radius: 0;
|
||||||
|
|
||||||
|
.img {
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-image {
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mask {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
import { CloseCircleOutlined } from '@ant-design/icons';
|
||||||
|
import { Progress, ProgressProps } from 'antd';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { round } from 'lodash';
|
||||||
|
import ResizeObserver from 'rc-resize-observer';
|
||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import AutoImage from './index';
|
||||||
|
import './single-image.less';
|
||||||
|
interface SingleImageProps {
|
||||||
|
loading?: boolean;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
progress?: number;
|
||||||
|
maxHeight?: number;
|
||||||
|
maxWidth?: number;
|
||||||
|
dataUrl: string;
|
||||||
|
label?: React.ReactNode;
|
||||||
|
uid: number;
|
||||||
|
preview?: boolean;
|
||||||
|
autoSize?: boolean;
|
||||||
|
onDelete: (uid: number) => void;
|
||||||
|
onClick?: (item: any) => void;
|
||||||
|
autoBgColor?: boolean;
|
||||||
|
editable?: boolean;
|
||||||
|
style?: React.CSSProperties;
|
||||||
|
loadingSize?: ProgressProps['size'];
|
||||||
|
progressType?: 'line' | 'circle' | 'dashboard';
|
||||||
|
progressColor?: string;
|
||||||
|
progressWidth?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SingleImage: React.FC<SingleImageProps> = (props) => {
|
||||||
|
const {
|
||||||
|
editable,
|
||||||
|
onDelete: handleOnDelete,
|
||||||
|
onClick,
|
||||||
|
autoSize,
|
||||||
|
uid,
|
||||||
|
loading,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
progress,
|
||||||
|
maxHeight,
|
||||||
|
maxWidth,
|
||||||
|
dataUrl = '',
|
||||||
|
label,
|
||||||
|
style,
|
||||||
|
autoBgColor,
|
||||||
|
preview = true,
|
||||||
|
loadingSize = 'default'
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const imgWrapper = React.useRef<HTMLSpanElement>(null);
|
||||||
|
const [imgSize, setImgSize] = React.useState({
|
||||||
|
width: width,
|
||||||
|
height: height
|
||||||
|
});
|
||||||
|
|
||||||
|
const thumImgWrapStyle = React.useMemo(() => {
|
||||||
|
return loading ? { width: '100%', height: '100%' } : {};
|
||||||
|
}, [loading, imgSize]);
|
||||||
|
|
||||||
|
const handleOnClick = useCallback(() => {
|
||||||
|
onClick?.(props);
|
||||||
|
}, [onClick, props]);
|
||||||
|
|
||||||
|
const handleResize = useCallback(
|
||||||
|
(size: { width: number; height: number }) => {
|
||||||
|
if (!autoSize || !size.width || !size.height) return;
|
||||||
|
|
||||||
|
const { width: containerWidth, height: containerHeight } = size;
|
||||||
|
const { width: originalWidth, height: originalHeight } = props;
|
||||||
|
|
||||||
|
if (!originalWidth || !originalHeight) return;
|
||||||
|
|
||||||
|
const widthRatio = containerWidth / originalWidth;
|
||||||
|
const heightRatio = containerHeight / originalHeight;
|
||||||
|
|
||||||
|
const scale = Math.min(widthRatio, heightRatio, 1);
|
||||||
|
|
||||||
|
const newWidth = originalWidth * scale;
|
||||||
|
const newHeight = originalHeight * scale;
|
||||||
|
|
||||||
|
if (newWidth === imgSize.width && newHeight === imgSize.height) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setImgSize({
|
||||||
|
width: newWidth,
|
||||||
|
height: newHeight
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[autoSize, props.width, props.height]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleOnLoad = React.useCallback(async () => {}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ResizeObserver onResize={handleResize}>
|
||||||
|
<div
|
||||||
|
style={{ ...style }}
|
||||||
|
key={uid}
|
||||||
|
className={classNames('single-image', {
|
||||||
|
'auto-bg-color': autoBgColor,
|
||||||
|
'auto-size': autoSize,
|
||||||
|
loading: loading
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{autoBgColor && (
|
||||||
|
<div
|
||||||
|
className="mask"
|
||||||
|
style={{
|
||||||
|
background: `url(${dataUrl}) center center / cover no-repeat`
|
||||||
|
}}
|
||||||
|
></div>
|
||||||
|
)}
|
||||||
|
<span
|
||||||
|
className="thumb-img"
|
||||||
|
style={{ ...thumImgWrapStyle }}
|
||||||
|
ref={imgWrapper}
|
||||||
|
>
|
||||||
|
<>
|
||||||
|
{label && <div className="label">{label}</div>}
|
||||||
|
{loading ? (
|
||||||
|
<span
|
||||||
|
className="progress-wrap"
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
border: '1px solid var(--ant-color-split)',
|
||||||
|
borderRadius: 'var(--border-radius-base)',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
padding: '10px',
|
||||||
|
overflow: 'hidden'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Progress
|
||||||
|
percent={round(progress, 0)}
|
||||||
|
type="dashboard"
|
||||||
|
size={loadingSize}
|
||||||
|
steps={{ count: 50, gap: 2 }}
|
||||||
|
format={() => (
|
||||||
|
<span className="font-size-20">{round(progress, 0)}%</span>
|
||||||
|
)}
|
||||||
|
trailColor="var(--ant-color-fill-secondary)"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span
|
||||||
|
onClick={handleOnClick}
|
||||||
|
className="img"
|
||||||
|
style={{
|
||||||
|
maxHeight: `min(${maxHeight}, 100%)`,
|
||||||
|
maxWidth: `min(${maxWidth}, 100%)`
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<AutoImage
|
||||||
|
style={{ objectFit: 'cover' }}
|
||||||
|
preview={preview}
|
||||||
|
autoSize={autoSize}
|
||||||
|
src={dataUrl}
|
||||||
|
width={imgSize.width || '100%'}
|
||||||
|
height={imgSize.height || 100}
|
||||||
|
onLoad={handleOnLoad}
|
||||||
|
/>
|
||||||
|
{progress && progress < 100 && (
|
||||||
|
<span className="small-progress-wrap">
|
||||||
|
<Progress
|
||||||
|
percent={round(progress, 0)}
|
||||||
|
type="dashboard"
|
||||||
|
size="small"
|
||||||
|
steps={{ count: 25, gap: 3 }}
|
||||||
|
format={() => (
|
||||||
|
<span className="font-size-12">
|
||||||
|
{round(progress, 0)}%
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
strokeColor="var(--color-white-secondary)"
|
||||||
|
trailColor="var(--ant-color-fill-secondary)"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
|
||||||
|
{editable && (
|
||||||
|
<span className="del" onClick={() => handleOnDelete(uid)}>
|
||||||
|
<CloseCircleOutlined />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</ResizeObserver>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SingleImage;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { CloseOutlined } from '@ant-design/icons';
|
||||||
import { Tag, Tooltip, type TagProps } from 'antd';
|
import { Tag, Tooltip, type TagProps } from 'antd';
|
||||||
import debounce from 'lodash/debounce';
|
import { throttle } from 'lodash';
|
||||||
import React, {
|
import React, {
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
@@ -7,23 +8,27 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
useState
|
useState
|
||||||
} from 'react';
|
} from 'react';
|
||||||
|
import { TooltipOverlayScroller } from '../overlay-scroller';
|
||||||
|
|
||||||
// type TagProps = React.ComponentProps<typeof Tag>;
|
// type TagProps = React.ComponentProps<typeof Tag>;
|
||||||
|
|
||||||
interface AutoTooltipProps extends Omit<TagProps, 'title'> {
|
interface AutoTooltipProps extends Omit<TagProps, 'title'> {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
maxWidth?: number | string;
|
maxWidth?: number | string;
|
||||||
|
minWidth?: number | string;
|
||||||
color?: string;
|
color?: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
ghost?: boolean;
|
ghost?: boolean;
|
||||||
title?: React.ReactNode;
|
title?: React.ReactNode;
|
||||||
showTitle?: boolean;
|
showTitle?: boolean;
|
||||||
|
closable?: boolean;
|
||||||
tooltipProps?: React.ComponentProps<typeof Tooltip>;
|
tooltipProps?: React.ComponentProps<typeof Tooltip>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AutoTooltip: React.FC<AutoTooltipProps> = ({
|
const AutoTooltip: React.FC<AutoTooltipProps> = ({
|
||||||
children,
|
children,
|
||||||
maxWidth = '100%',
|
maxWidth = '100%',
|
||||||
|
minWidth,
|
||||||
ghost = false,
|
ghost = false,
|
||||||
title,
|
title,
|
||||||
showTitle = false,
|
showTitle = false,
|
||||||
@@ -32,6 +37,7 @@ const AutoTooltip: React.FC<AutoTooltipProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const contentRef = useRef<HTMLDivElement>(null);
|
const contentRef = useRef<HTMLDivElement>(null);
|
||||||
const [isOverflowing, setIsOverflowing] = useState(false);
|
const [isOverflowing, setIsOverflowing] = useState(false);
|
||||||
|
const resizeObserver = useRef<ResizeObserver | null>(null);
|
||||||
|
|
||||||
const checkOverflow = useCallback(() => {
|
const checkOverflow = useCallback(() => {
|
||||||
if (contentRef.current) {
|
if (contentRef.current) {
|
||||||
@@ -40,19 +46,33 @@ const AutoTooltip: React.FC<AutoTooltipProps> = ({
|
|||||||
}
|
}
|
||||||
}, [contentRef.current]);
|
}, [contentRef.current]);
|
||||||
|
|
||||||
const debouncedCheckOverflow = useMemo(
|
useEffect(() => {
|
||||||
() => debounce(checkOverflow, 200),
|
const element = contentRef.current;
|
||||||
[checkOverflow]
|
if (!element) return;
|
||||||
);
|
resizeObserver.current?.disconnect();
|
||||||
|
resizeObserver.current = new ResizeObserver(() => {
|
||||||
|
checkOverflow();
|
||||||
|
});
|
||||||
|
|
||||||
|
resizeObserver.current?.observe(element);
|
||||||
|
|
||||||
|
// Initial check
|
||||||
|
checkOverflow();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
resizeObserver.current?.disconnect();
|
||||||
|
resizeObserver.current = null;
|
||||||
|
};
|
||||||
|
}, [checkOverflow]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
checkOverflow();
|
const debouncedCheckOverflow = throttle(checkOverflow, 200);
|
||||||
window.addEventListener('resize', debouncedCheckOverflow);
|
window.addEventListener('resize', debouncedCheckOverflow);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('resize', debouncedCheckOverflow);
|
window.removeEventListener('resize', debouncedCheckOverflow);
|
||||||
debouncedCheckOverflow.cancel();
|
debouncedCheckOverflow.cancel();
|
||||||
};
|
};
|
||||||
}, [checkOverflow, debouncedCheckOverflow]);
|
}, [checkOverflow]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
checkOverflow();
|
checkOverflow();
|
||||||
@@ -61,6 +81,7 @@ const AutoTooltip: React.FC<AutoTooltipProps> = ({
|
|||||||
const tagStyle = useMemo(
|
const tagStyle = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
maxWidth,
|
maxWidth,
|
||||||
|
minWidth,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
textOverflow: 'ellipsis',
|
textOverflow: 'ellipsis',
|
||||||
whiteSpace: 'nowrap' as const,
|
whiteSpace: 'nowrap' as const,
|
||||||
@@ -70,20 +91,44 @@ const AutoTooltip: React.FC<AutoTooltipProps> = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<TooltipOverlayScroller
|
||||||
title={isOverflowing || showTitle ? title || children : ''}
|
toolTipProps={{
|
||||||
{...tooltipProps}
|
...tooltipProps,
|
||||||
|
destroyTooltipOnHide: false
|
||||||
|
}}
|
||||||
|
title={isOverflowing || showTitle ? title || children : false}
|
||||||
>
|
>
|
||||||
{ghost ? (
|
{ghost ? (
|
||||||
<div ref={contentRef} style={tagStyle}>
|
<div ref={contentRef} style={tagStyle} data-overflow={isOverflowing}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<Tag {...tagProps} ref={contentRef} style={tagStyle}>
|
<Tag
|
||||||
|
{...tagProps}
|
||||||
|
ref={contentRef}
|
||||||
|
style={{
|
||||||
|
...tagStyle,
|
||||||
|
paddingInline: tagProps.closable ? '8px 22px' : 8,
|
||||||
|
borderRadius: 12
|
||||||
|
}}
|
||||||
|
closeIcon={
|
||||||
|
tagProps.closable ? (
|
||||||
|
<CloseOutlined
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
right: 8,
|
||||||
|
top: 6
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</Tag>
|
</Tag>
|
||||||
)}
|
)}
|
||||||
</Tooltip>
|
</TooltipOverlayScroller>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { OverlayScroller } from '@/components/overlay-scroller';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface TitleTipProps {
|
||||||
|
isOverflowing: boolean;
|
||||||
|
showTitle: boolean;
|
||||||
|
title: React.ReactNode;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TitleTip: React.FC<TitleTipProps> = (props) => {
|
||||||
|
const { isOverflowing, showTitle, title, children } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<OverlayScroller maxHeight={200}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: 'fit-content',
|
||||||
|
maxWidth: 'var(--width-tooltip-max)'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isOverflowing || showTitle ? title || children : ''}
|
||||||
|
</div>
|
||||||
|
</OverlayScroller>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(TitleTip);
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import bibtexParse from '@orcid/bibtex-parse-js';
|
||||||
|
import { Typography } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/*
|
||||||
|
@inproceedings{Lysenko:2010:GMC:1839778.1839781,\
|
||||||
|
author = {Lysenko, Mikola and Nelaturi, Saigopal and Shapiro, Vadim},\
|
||||||
|
title = {Group morphology with convolution algebras},\
|
||||||
|
booktitle = {Proceedings of the 14th ACM Symposium on Solid and Physical Modeling},\
|
||||||
|
series = {SPM '10},\
|
||||||
|
year = {2010},\
|
||||||
|
isbn = {978-1-60558-984-8},\
|
||||||
|
location = {Haifa, Israel},\
|
||||||
|
pages = {11--22},\
|
||||||
|
numpages = {12},\
|
||||||
|
url = {http://doi.acm.org/10.1145/1839778.1839781},\
|
||||||
|
doi = {10.1145/1839778.1839781},\
|
||||||
|
acmid = {1839781},\
|
||||||
|
publisher = {ACM},\
|
||||||
|
address = {New York, NY, USA},\
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const BibTeXViewer: React.FC<{ data: string }> = ({ data }) => {
|
||||||
|
if (!data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const dataList = bibtexParse.toJSON(data);
|
||||||
|
return (
|
||||||
|
<ol>
|
||||||
|
{dataList.map((item: any, index: number) => (
|
||||||
|
<li key={index} style={{ lineHeight: 2 }}>
|
||||||
|
<Typography.Link href={item.entryTags?.url} target="_blank">
|
||||||
|
{item.entryTags?.title}.{' '}
|
||||||
|
</Typography.Link>
|
||||||
|
<Typography.Text>{item.entryTags?.author}. </Typography.Text>
|
||||||
|
<Typography.Text>[{item.entryTags?.year}] </Typography.Text>
|
||||||
|
{item.entryTags?.journal && (
|
||||||
|
<Typography.Text>.({item.entryTags?.journal})</Typography.Text>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ol>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BibTeXViewer;
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { DoubleRightOutlined } from '@ant-design/icons';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { Button } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
interface MoreButtonProps {
|
||||||
|
show: boolean;
|
||||||
|
loadMore: () => void;
|
||||||
|
loading?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MoreWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin-block: 16px;
|
||||||
|
opacity: 1;
|
||||||
|
transition: opacity 0.3s;
|
||||||
|
&.loading {
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const MoreButton: React.FC<MoreButtonProps> = (props) => {
|
||||||
|
const { show, loading, loadMore } = props;
|
||||||
|
const intl = useIntl();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{show ? (
|
||||||
|
<MoreWrapper className={loading ? 'loading' : ''}>
|
||||||
|
<Button
|
||||||
|
onClick={loadMore}
|
||||||
|
size="middle"
|
||||||
|
type="text"
|
||||||
|
icon={<DoubleRightOutlined rotate={90} />}
|
||||||
|
>
|
||||||
|
{intl.formatMessage({ id: 'common.button.more' })}
|
||||||
|
</Button>
|
||||||
|
</MoreWrapper>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MoreButton;
|
||||||
@@ -3,5 +3,5 @@
|
|||||||
background-color: var(--color-white-1);
|
background-color: var(--color-white-1);
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border: 1px solid var(--color-border-1);
|
border: 1px solid var(--ant-color-border);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { Button } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface CheckButtonsProps {
|
||||||
|
options: Global.BaseOption<string | number>[];
|
||||||
|
onChange: (value: string | number) => void;
|
||||||
|
cancelable?: boolean;
|
||||||
|
size?: 'small' | 'middle' | 'large';
|
||||||
|
type?: 'text' | 'primary' | 'default' | 'dashed' | 'link' | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CheckButtons: React.FC<CheckButtonsProps> = (props) => {
|
||||||
|
const [type, setType] = React.useState(props.type || 'text');
|
||||||
|
const [active, setActive] = React.useState<string | number | null>(null);
|
||||||
|
const handleChange = (value: string | number) => {
|
||||||
|
props.onChange(value);
|
||||||
|
if (props.cancelable && active === value) {
|
||||||
|
setActive(null);
|
||||||
|
} else {
|
||||||
|
setActive(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="flex-center gap-6">
|
||||||
|
{props.options?.map?.((option, index) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
size={props.size}
|
||||||
|
key={option.value}
|
||||||
|
onClick={() => handleChange(option.value)}
|
||||||
|
variant="filled"
|
||||||
|
color={active === option.value ? 'default' : undefined}
|
||||||
|
type={type}
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(CheckButtons);
|
||||||
@@ -2,25 +2,41 @@ import { CheckCircleFilled, CopyOutlined } from '@ant-design/icons';
|
|||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Tooltip, message } from 'antd';
|
import { Button, Tooltip, message } from 'antd';
|
||||||
import ClipboardJS from 'clipboard';
|
import ClipboardJS from 'clipboard';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
|
||||||
type CopyButtonProps = {
|
type CopyButtonProps = {
|
||||||
|
children?: React.ReactNode;
|
||||||
text: string;
|
text: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
fontSize?: string;
|
fontSize?: string;
|
||||||
type?: 'text' | 'primary' | 'dashed' | 'link' | 'default';
|
type?: 'text' | 'primary' | 'dashed' | 'link' | 'default';
|
||||||
size?: 'small' | 'middle' | 'large';
|
size?: 'small' | 'middle' | 'large';
|
||||||
shape?: 'circle' | 'round' | 'default';
|
shape?: 'circle' | 'round' | 'default';
|
||||||
|
tips?: string;
|
||||||
|
placement?:
|
||||||
|
| 'top'
|
||||||
|
| 'left'
|
||||||
|
| 'right'
|
||||||
|
| 'bottom'
|
||||||
|
| 'topLeft'
|
||||||
|
| 'topRight'
|
||||||
|
| 'bottomLeft'
|
||||||
|
| 'bottomRight';
|
||||||
|
btnStyle?: React.CSSProperties;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CopyButton: React.FC<CopyButtonProps> = ({
|
const CopyButton: React.FC<CopyButtonProps> = ({
|
||||||
|
children,
|
||||||
|
tips,
|
||||||
text,
|
text,
|
||||||
disabled,
|
disabled,
|
||||||
type = 'text',
|
type = 'text',
|
||||||
shape = 'default',
|
shape = 'default',
|
||||||
fontSize = '14px',
|
fontSize = '14px',
|
||||||
style,
|
style,
|
||||||
|
btnStyle,
|
||||||
|
placement,
|
||||||
size = 'middle'
|
size = 'middle'
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
@@ -47,6 +63,13 @@ const CopyButton: React.FC<CopyButtonProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const tipTitle = useMemo(() => {
|
||||||
|
if (copied) {
|
||||||
|
return intl.formatMessage({ id: 'common.button.copied' });
|
||||||
|
}
|
||||||
|
return tips ?? intl.formatMessage({ id: 'common.button.copy' });
|
||||||
|
}, [copied, intl, tips]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initClipboard();
|
initClipboard();
|
||||||
return () => {
|
return () => {
|
||||||
@@ -55,7 +78,7 @@ const CopyButton: React.FC<CopyButtonProps> = ({
|
|||||||
}, [buttonRef]);
|
}, [buttonRef]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip title={intl.formatMessage({ id: 'common.button.copy' })}>
|
<Tooltip title={tipTitle} placement={placement}>
|
||||||
<Button
|
<Button
|
||||||
className="copy-button"
|
className="copy-button"
|
||||||
ref={buttonRef}
|
ref={buttonRef}
|
||||||
@@ -64,6 +87,7 @@ const CopyButton: React.FC<CopyButtonProps> = ({
|
|||||||
size={size}
|
size={size}
|
||||||
disabled={!!disabled}
|
disabled={!!disabled}
|
||||||
data-clipboard-text={text}
|
data-clipboard-text={text}
|
||||||
|
style={{ ...btnStyle }}
|
||||||
icon={
|
icon={
|
||||||
copied ? (
|
copied ? (
|
||||||
<CheckCircleFilled
|
<CheckCircleFilled
|
||||||
@@ -73,7 +97,9 @@ const CopyButton: React.FC<CopyButtonProps> = ({
|
|||||||
<CopyOutlined style={{ fontSize: fontSize, ...style }} />
|
<CopyOutlined style={{ fontSize: fontSize, ...style }} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
></Button>
|
>
|
||||||
|
{children}
|
||||||
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import { getStorageUserSettings } from '@/atoms/settings';
|
||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import styled, { keyframes } from 'styled-components';
|
||||||
|
|
||||||
|
const duration = 1;
|
||||||
|
|
||||||
|
const fadeOut = keyframes`
|
||||||
|
from {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(1.05);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Mask = styled.div<{ isHiding: boolean }>`
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
background-color: rgba(59, 59, 59, 1);
|
||||||
|
z-index: 9999;
|
||||||
|
animation: ${({ isHiding }) => (isHiding ? fadeOut : 'none')} ${duration}s
|
||||||
|
ease forwards;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const DarkModeMask = () => {
|
||||||
|
const { theme: savedTheme } = getStorageUserSettings();
|
||||||
|
const [visible, setVisible] = useState(savedTheme === 'realDark');
|
||||||
|
const [isHiding, setIsHiding] = useState(false);
|
||||||
|
const maskRef = useRef<HTMLDivElement>(null);
|
||||||
|
const timerRef = useRef<any>(null);
|
||||||
|
|
||||||
|
const initTheme = () => {
|
||||||
|
const html = document.querySelector('html');
|
||||||
|
if (html) {
|
||||||
|
html.setAttribute('data-theme', savedTheme);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
initTheme();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (savedTheme === 'realDark') {
|
||||||
|
setVisible(true);
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
setIsHiding(true);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setIsHiding(true);
|
||||||
|
}
|
||||||
|
}, [savedTheme]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const el = maskRef.current;
|
||||||
|
if (!el) return;
|
||||||
|
|
||||||
|
const handleAnimationEnd = () => {
|
||||||
|
clearTimeout(timerRef.current);
|
||||||
|
setVisible(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
el.addEventListener('animationend', handleAnimationEnd);
|
||||||
|
|
||||||
|
if (isHiding) {
|
||||||
|
timerRef.current = setTimeout(
|
||||||
|
() => {
|
||||||
|
setVisible(false);
|
||||||
|
},
|
||||||
|
duration * 1000 + 100
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return () => el.removeEventListener('animationend', handleAnimationEnd);
|
||||||
|
}, [visible]);
|
||||||
|
|
||||||
|
return visible ? <Mask ref={maskRef} isHiding={isHiding}></Mask> : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DarkModeMask;
|
||||||
@@ -1,41 +1,97 @@
|
|||||||
|
import useBodyScroll from '@/hooks/use-body-scroll';
|
||||||
import { ExclamationCircleFilled } from '@ant-design/icons';
|
import { ExclamationCircleFilled } from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Modal, Space, message, type ModalFuncProps } from 'antd';
|
import {
|
||||||
import { forwardRef, useImperativeHandle, useState } from 'react';
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Modal,
|
||||||
|
Space,
|
||||||
|
message,
|
||||||
|
type ModalFuncProps
|
||||||
|
} from 'antd';
|
||||||
|
import { FC, forwardRef, useImperativeHandle, useState } from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
import Styles from './index.less';
|
import Styles from './index.less';
|
||||||
|
|
||||||
const DeleteModal = forwardRef((props, ref) => {
|
const CheckboxWrapper = styled.div`
|
||||||
|
margin-top: 20px;
|
||||||
|
margin-left: 30px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
.check-text {
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--ant-color-warning);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
interface DeleteModalProps {
|
||||||
|
ref: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DataOptions {
|
||||||
|
content: string;
|
||||||
|
selection?: boolean;
|
||||||
|
name?: string;
|
||||||
|
okText?: string;
|
||||||
|
cancelText?: string;
|
||||||
|
title?: string;
|
||||||
|
operation: string;
|
||||||
|
checkConfig?: {
|
||||||
|
checkText: string;
|
||||||
|
defautlChecked: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const DeleteModal: FC<DeleteModalProps> = forwardRef((props, ref) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const { saveScrollHeight, restoreScrollHeight } = useBodyScroll();
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [config, setConfig] = useState<
|
const [checked, setChecked] = useState(false);
|
||||||
ModalFuncProps & { content: string; selection?: boolean; name?: string }
|
const [config, setConfig] = useState<ModalFuncProps & DataOptions>({} as any);
|
||||||
>({});
|
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
show: (
|
show: (data: ModalFuncProps & DataOptions) => {
|
||||||
data: ModalFuncProps & {
|
saveScrollHeight();
|
||||||
content: string;
|
|
||||||
selection?: boolean;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
) => {
|
|
||||||
setConfig(data);
|
setConfig(data);
|
||||||
|
setChecked(data.checkConfig?.defautlChecked || false);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
},
|
},
|
||||||
hide: () => {
|
hide: () => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
restoreScrollHeight();
|
||||||
|
},
|
||||||
|
configuration: {
|
||||||
|
checked: checked
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
config.onCancel?.();
|
config.onCancel?.();
|
||||||
|
restoreScrollHeight();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
await config.onOk?.();
|
try {
|
||||||
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
const res = await config.onOk?.();
|
||||||
setVisible(false);
|
const isArray = Array.isArray(res);
|
||||||
|
if (isArray) {
|
||||||
|
const allSuccess = res.every(
|
||||||
|
(item: any) => item?.status === 'fulfilled'
|
||||||
|
);
|
||||||
|
if (allSuccess) {
|
||||||
|
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Handle error if needed
|
||||||
|
} finally {
|
||||||
|
setVisible(false);
|
||||||
|
restoreScrollHeight();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -55,10 +111,14 @@ const DeleteModal = forwardRef((props, ref) => {
|
|||||||
footer={
|
footer={
|
||||||
<Space size={20}>
|
<Space size={20}>
|
||||||
<Button onClick={handleCancel} size="middle">
|
<Button onClick={handleCancel} size="middle">
|
||||||
{intl.formatMessage({ id: 'common.button.cancel' })}
|
{config.cancelText
|
||||||
|
? intl.formatMessage({ id: config.cancelText })
|
||||||
|
: intl.formatMessage({ id: 'common.button.cancel' })}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="primary" onClick={handleOk} size="middle">
|
<Button type="primary" onClick={handleOk} size="middle">
|
||||||
{intl.formatMessage({ id: 'common.button.delete' })}
|
{config.okText
|
||||||
|
? intl.formatMessage({ id: config.okText })
|
||||||
|
: intl.formatMessage({ id: 'common.button.delete' })}
|
||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
@@ -67,7 +127,9 @@ const DeleteModal = forwardRef((props, ref) => {
|
|||||||
<span className="title">
|
<span className="title">
|
||||||
<ExclamationCircleFilled />
|
<ExclamationCircleFilled />
|
||||||
<span>
|
<span>
|
||||||
{intl.formatMessage({ id: 'common.title.delete.confirm' })}
|
{config.title
|
||||||
|
? intl.formatMessage({ id: config.title })
|
||||||
|
: intl.formatMessage({ id: 'common.title.delete.confirm' })}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -78,9 +140,7 @@ const DeleteModal = forwardRef((props, ref) => {
|
|||||||
config.content &&
|
config.content &&
|
||||||
intl.formatMessage(
|
intl.formatMessage(
|
||||||
{
|
{
|
||||||
id: config.selection
|
id: config.operation || ''
|
||||||
? 'common.delete.confirm'
|
|
||||||
: 'common.delete.single.confirm'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: intl.formatMessage({ id: config.content }),
|
type: intl.formatMessage({ id: config.content }),
|
||||||
@@ -89,6 +149,18 @@ const DeleteModal = forwardRef((props, ref) => {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
|
{config.checkConfig && (
|
||||||
|
<CheckboxWrapper>
|
||||||
|
<Checkbox
|
||||||
|
checked={checked}
|
||||||
|
onChange={(e) => setChecked(e.target.checked)}
|
||||||
|
>
|
||||||
|
<span className="check-text">
|
||||||
|
{intl.formatMessage({ id: config.checkConfig?.checkText })}
|
||||||
|
</span>
|
||||||
|
</Checkbox>
|
||||||
|
</CheckboxWrapper>
|
||||||
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,34 +1,36 @@
|
|||||||
import * as icons from '@ant-design/icons';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Dropdown, Space } from 'antd';
|
import { Dropdown, DropDownProps } from 'antd';
|
||||||
import type { MenuProps } from 'antd/es/menu';
|
import _ from 'lodash';
|
||||||
import react from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
|
||||||
type DropdownProps = {
|
const DropDownActions: React.FC<DropDownProps> = (props) => {
|
||||||
trigger?: Array<'click' | 'hover' | 'contextMenu'>;
|
const {
|
||||||
items: MenuProps['items'];
|
menu,
|
||||||
onClick: (e: any) => void;
|
trigger = ['hover'],
|
||||||
};
|
placement = 'bottomRight',
|
||||||
const renderIcon = (icon: string) => {
|
children,
|
||||||
if (!icon) {
|
...rest
|
||||||
return null;
|
} = props;
|
||||||
}
|
const intl = useIntl();
|
||||||
// @ts-ignore
|
|
||||||
const Icon = icons[icon] as React.FC;
|
const items = useMemo(() => {
|
||||||
return react.createElement(Icon);
|
return menu?.items?.map((item: any) => ({
|
||||||
};
|
..._.omit(item, 'locale'),
|
||||||
const DropDownActions: React.FC<DropdownProps> = (props) => {
|
label: item.locale ? intl.formatMessage({ id: item.label }) : item.label
|
||||||
const { trigger, items, onClick } = props;
|
}));
|
||||||
|
}, [menu?.items, intl]);
|
||||||
return (
|
return (
|
||||||
<Space>
|
<Dropdown
|
||||||
<Dropdown menu={{ items, onClick }} trigger={trigger}>
|
menu={{
|
||||||
<Button
|
items: items,
|
||||||
onClick={(e) => e.preventDefault()}
|
onClick: menu?.onClick
|
||||||
style={{ fontSize: '14px' }}
|
}}
|
||||||
type="text"
|
trigger={trigger}
|
||||||
icon={renderIcon('MoreOutlined')}
|
placement={placement}
|
||||||
></Button>
|
{...rest}
|
||||||
</Dropdown>
|
>
|
||||||
</Space>
|
{children}
|
||||||
|
</Dropdown>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
.dropdown-button.middle {
|
||||||
|
height: 28px;
|
||||||
|
width: 28px;
|
||||||
|
}
|
||||||
@@ -1,23 +1,39 @@
|
|||||||
import { MoreOutlined } from '@ant-design/icons';
|
import { MoreOutlined } from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Dropdown, Tooltip, type MenuProps } from 'antd';
|
import { Button, Dropdown, Tooltip, type MenuProps } from 'antd';
|
||||||
|
import classNames from 'classnames';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { memo } from 'react';
|
import React from 'react';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
|
type Trigger = 'click' | 'hover';
|
||||||
interface DropdownButtonsProps {
|
interface DropdownButtonsProps {
|
||||||
items: MenuProps['items'];
|
items: MenuProps['items'];
|
||||||
size?: 'small' | 'middle' | 'large';
|
size?: 'small' | 'middle' | 'large';
|
||||||
|
trigger?: Trigger[];
|
||||||
|
showText?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
variant?: 'filled' | 'outlined';
|
||||||
|
color?: string;
|
||||||
|
extra?: React.ReactNode;
|
||||||
onSelect: (val: any, item?: any) => void;
|
onSelect: (val: any, item?: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DropdownButtons: React.FC<DropdownButtonsProps> = ({
|
const DropdownButtons: React.FC<DropdownButtonsProps> = ({
|
||||||
items,
|
items,
|
||||||
size = 'small',
|
size = 'middle',
|
||||||
|
trigger = ['hover'],
|
||||||
|
showText,
|
||||||
|
disabled,
|
||||||
|
variant,
|
||||||
|
color,
|
||||||
|
extra,
|
||||||
onSelect
|
onSelect
|
||||||
}) => {
|
}) => {
|
||||||
|
const headItem = _.head(items);
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const handleMenuClick = (item: any) => {
|
const handleMenuClick = (item: any) => {
|
||||||
console.log('menu click', item.key);
|
|
||||||
const selectItem = _.find(items, { key: item.key });
|
const selectItem = _.find(items, { key: item.key });
|
||||||
onSelect(item.key, selectItem);
|
onSelect(item.key, selectItem);
|
||||||
};
|
};
|
||||||
@@ -34,23 +50,26 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{items?.length === 1 ? (
|
{items?.length === 1 ? (
|
||||||
<Tooltip title={intl.formatMessage({ id: _.head(items)?.label })}>
|
<Tooltip title={intl.formatMessage({ id: headItem?.label })}>
|
||||||
<Button
|
<Button
|
||||||
{..._.head(items)}
|
className={classNames('dropdown-button', size)}
|
||||||
icon={_.get(items, '0.icon')}
|
icon={headItem?.icon}
|
||||||
size={size}
|
size={size}
|
||||||
{..._.get(items, '0.props')}
|
{...headItem?.props}
|
||||||
onClick={handleButtonClick}
|
onClick={handleButtonClick}
|
||||||
></Button>
|
></Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
) : (
|
) : (
|
||||||
<Dropdown.Button
|
<Dropdown.Button
|
||||||
|
disabled={disabled}
|
||||||
|
trigger={trigger}
|
||||||
|
type="primary"
|
||||||
dropdownRender={(menus: any) => {
|
dropdownRender={(menus: any) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="flex flex-column "
|
className="flex flex-column "
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: 'var(--color-white-1)',
|
backgroundColor: 'var(--ant-color-bg-elevated)',
|
||||||
padding: 5,
|
padding: 5,
|
||||||
alignItems: 'flex-start',
|
alignItems: 'flex-start',
|
||||||
borderRadius: 'var(--border-radius-base)',
|
borderRadius: 'var(--border-radius-base)',
|
||||||
@@ -62,9 +81,10 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
|
|||||||
<Button
|
<Button
|
||||||
{...item.props}
|
{...item.props}
|
||||||
type="text"
|
type="text"
|
||||||
size="middle"
|
size={size}
|
||||||
icon={item.icon}
|
icon={item.icon}
|
||||||
key={item.key}
|
key={item.key}
|
||||||
|
disabled={item.disabled}
|
||||||
onClick={() => handleMenuClick(item)}
|
onClick={() => handleMenuClick(item)}
|
||||||
style={{ width: '100%', justifyContent: 'flex-start' }}
|
style={{ width: '100%', justifyContent: 'flex-start' }}
|
||||||
>
|
>
|
||||||
@@ -76,17 +96,47 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
buttonsRender={([leftButton, rightButton]) => [
|
buttonsRender={([leftButton, rightButton]) => [
|
||||||
<Tooltip
|
<>
|
||||||
title={intl.formatMessage({ id: _.head(items)?.label })}
|
{showText ? (
|
||||||
key="leftButton"
|
<Button
|
||||||
>
|
{...headItem?.props}
|
||||||
<Button
|
disabled={headItem?.disabled || disabled}
|
||||||
onClick={handleButtonClick}
|
className={classNames('dropdown-button', size)}
|
||||||
size={size}
|
onClick={handleButtonClick}
|
||||||
icon={_.head(items)?.icon}
|
size={size}
|
||||||
></Button>
|
icon={headItem?.icon}
|
||||||
</Tooltip>,
|
variant={variant}
|
||||||
<Button icon={<MoreOutlined />} size={size} key="menu"></Button>
|
color={color}
|
||||||
|
>
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: headItem?.label
|
||||||
|
})}
|
||||||
|
{extra}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Tooltip
|
||||||
|
title={intl.formatMessage({ id: headItem?.label })}
|
||||||
|
key="leftButton"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
{...headItem?.props}
|
||||||
|
className={classNames('dropdown-button', size)}
|
||||||
|
onClick={handleButtonClick}
|
||||||
|
size={size}
|
||||||
|
icon={headItem?.icon}
|
||||||
|
disabled={headItem?.disabled}
|
||||||
|
></Button>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</>,
|
||||||
|
<Button
|
||||||
|
icon={<MoreOutlined />}
|
||||||
|
size={size}
|
||||||
|
key="menu"
|
||||||
|
variant={variant}
|
||||||
|
color="default"
|
||||||
|
className={classNames('dropdown-button', size)}
|
||||||
|
></Button>
|
||||||
]}
|
]}
|
||||||
></Dropdown.Button>
|
></Dropdown.Button>
|
||||||
)}
|
)}
|
||||||
@@ -94,4 +144,4 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(DropdownButtons);
|
export default DropdownButtons;
|
||||||
|
|||||||
@@ -1,16 +1,8 @@
|
|||||||
import Chart from '@/components/echarts/chart';
|
import Chart from '@/components/echarts/chart';
|
||||||
import {
|
import useChartConfig from '@/components/echarts/config';
|
||||||
barItemConfig,
|
|
||||||
grid,
|
|
||||||
legend,
|
|
||||||
title as titleConfig,
|
|
||||||
tooltip,
|
|
||||||
xAxis,
|
|
||||||
yAxis
|
|
||||||
} from '@/components/echarts/config';
|
|
||||||
import EmptyData from '@/components/empty-data';
|
import EmptyData from '@/components/empty-data';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { memo } from 'react';
|
import React, { memo, useMemo } from 'react';
|
||||||
import { ChartProps } from './types';
|
import { ChartProps } from './types';
|
||||||
|
|
||||||
const BarChart: React.FC<ChartProps> = (props) => {
|
const BarChart: React.FC<ChartProps> = (props) => {
|
||||||
@@ -23,39 +15,41 @@ const BarChart: React.FC<ChartProps> = (props) => {
|
|||||||
legendData,
|
legendData,
|
||||||
title
|
title
|
||||||
} = props;
|
} = props;
|
||||||
|
const {
|
||||||
if (!seriesData.length) {
|
barItemConfig,
|
||||||
return <EmptyData height={height} title={title}></EmptyData>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
title: {
|
|
||||||
text: ''
|
|
||||||
},
|
|
||||||
grid,
|
grid,
|
||||||
tooltip: {
|
legend,
|
||||||
...tooltip
|
title: titleConfig,
|
||||||
// axisPointer: {
|
tooltip,
|
||||||
// type: 'shadow'
|
xAxis,
|
||||||
// }
|
yAxis
|
||||||
},
|
} = useChartConfig();
|
||||||
xAxis: {
|
|
||||||
...xAxis,
|
|
||||||
axisLabel: {
|
|
||||||
...xAxis.axisLabel,
|
|
||||||
formatter: labelFormatter
|
|
||||||
},
|
|
||||||
data: []
|
|
||||||
},
|
|
||||||
yAxis,
|
|
||||||
legend: {
|
|
||||||
...legend,
|
|
||||||
data: []
|
|
||||||
},
|
|
||||||
|
|
||||||
series: []
|
const dataOptions = useMemo((): any => {
|
||||||
};
|
const options = {
|
||||||
const setDataOptions = () => {
|
title: {
|
||||||
|
text: ''
|
||||||
|
},
|
||||||
|
grid,
|
||||||
|
tooltip: {
|
||||||
|
...tooltip
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
...xAxis,
|
||||||
|
axisLabel: {
|
||||||
|
...xAxis.axisLabel,
|
||||||
|
formatter: labelFormatter
|
||||||
|
},
|
||||||
|
data: []
|
||||||
|
},
|
||||||
|
yAxis,
|
||||||
|
legend: {
|
||||||
|
...legend,
|
||||||
|
data: []
|
||||||
|
},
|
||||||
|
|
||||||
|
series: []
|
||||||
|
};
|
||||||
const data = _.map(seriesData, (item: any) => {
|
const data = _.map(seriesData, (item: any) => {
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
@@ -82,16 +76,31 @@ const BarChart: React.FC<ChartProps> = (props) => {
|
|||||||
},
|
},
|
||||||
series: data
|
series: data
|
||||||
};
|
};
|
||||||
};
|
}, [
|
||||||
|
seriesData,
|
||||||
const dataOptions: any = setDataOptions();
|
xAxisData,
|
||||||
|
title,
|
||||||
|
labelFormatter,
|
||||||
|
tooltip,
|
||||||
|
grid,
|
||||||
|
xAxis,
|
||||||
|
yAxis,
|
||||||
|
legend,
|
||||||
|
barItemConfig
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chart
|
<>
|
||||||
height={height}
|
{!seriesData.length ? (
|
||||||
options={dataOptions}
|
<EmptyData height={height} title={title}></EmptyData>
|
||||||
width={width || '100%'}
|
) : (
|
||||||
></Chart>
|
<Chart
|
||||||
|
height={height}
|
||||||
|
options={dataOptions}
|
||||||
|
width={width || '100%'}
|
||||||
|
></Chart>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
const TooltipWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
background-color: rgba(255, 255, 255, 80%);
|
||||||
|
min-width: 100px;
|
||||||
|
max-width: 360px;
|
||||||
|
|
||||||
|
.tooltip-x-name {
|
||||||
|
font-size: var(--font-size-base);
|
||||||
|
color: var(--ant-color-text-tertiary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip-item {
|
||||||
|
color: var(--ant-color-text-secondary);
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.tooltip-item-title {
|
||||||
|
margin-right: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip-value {
|
||||||
|
margin-left: 10px;
|
||||||
|
color: var(--ant-color-text);
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ItemSymbol = styled.span<{ $color: string }>`
|
||||||
|
background-color: ${(props) => props.$color};
|
||||||
|
display: inline-block;
|
||||||
|
marginright: 5px;
|
||||||
|
borderradius: 8px;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
interface ChartTooltipProps {
|
||||||
|
params: any[];
|
||||||
|
callback?: (val: any) => any;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ChartTooltip: React.FC<ChartTooltipProps> = (props) => {
|
||||||
|
const { params, callback } = props;
|
||||||
|
console.log('params====', params);
|
||||||
|
return (
|
||||||
|
<TooltipWrapper>
|
||||||
|
<span className="tooltip-x-name">{params[0]?.axisValue}</span>
|
||||||
|
<>
|
||||||
|
{params.map((item: any, index: number) => {
|
||||||
|
let value = callback?.(item.data.value) || item.data.value;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className="tooltip-item" key={index}>
|
||||||
|
<span className="tooltip-item-name">
|
||||||
|
<ItemSymbol $color={item.color}></ItemSymbol>
|
||||||
|
<span className="tooltip-title">{item.seriesName}</span>:
|
||||||
|
</span>
|
||||||
|
<span className="tooltip-value">{value}</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
</TooltipWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default ChartTooltip;
|
||||||
@@ -1,14 +1,29 @@
|
|||||||
import { throttle } from 'echarts/core';
|
import { throttle } from 'lodash';
|
||||||
import { useCallback, useEffect, useRef } from 'react';
|
import React, {
|
||||||
|
forwardRef,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle,
|
||||||
|
useRef
|
||||||
|
} from 'react';
|
||||||
import echarts, { ECOption } from '.';
|
import echarts, { ECOption } from '.';
|
||||||
|
|
||||||
const Chart: React.FC<{
|
const Chart: React.FC<{
|
||||||
options: ECOption;
|
options: ECOption;
|
||||||
height: number | string;
|
height: number | string;
|
||||||
width: number | string;
|
width: number | string;
|
||||||
}> = ({ options, width, height }) => {
|
ref?: any;
|
||||||
|
}> = forwardRef(({ options, width, height }, ref) => {
|
||||||
const container = useRef<HTMLDivElement>(null);
|
const container = useRef<HTMLDivElement>(null);
|
||||||
const chart = useRef<echarts.EChartsType>();
|
const chart = useRef<echarts.EChartsType>();
|
||||||
|
const resizeable = useRef(false);
|
||||||
|
const resizeObserver = useRef<ResizeObserver>();
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => {
|
||||||
|
return {
|
||||||
|
chart: chart.current
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const init = useCallback(() => {
|
const init = useCallback(() => {
|
||||||
if (container.current) {
|
if (container.current) {
|
||||||
@@ -21,38 +36,57 @@ const Chart: React.FC<{
|
|||||||
chart.current?.resize();
|
chart.current?.resize();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setOption = useCallback((options: ECOption) => {
|
const setOption = useCallback(
|
||||||
chart.current?.clear();
|
(options: ECOption) => {
|
||||||
chart.current?.setOption(options, {
|
chart.current?.clear();
|
||||||
notMerge: true,
|
chart.current?.setOption(options, {
|
||||||
lazyUpdate: true
|
notMerge: true,
|
||||||
});
|
lazyUpdate: true
|
||||||
}, []);
|
});
|
||||||
|
},
|
||||||
|
[options]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
init();
|
if (container.current) {
|
||||||
|
init();
|
||||||
|
}
|
||||||
return () => {
|
return () => {
|
||||||
chart.current?.dispose();
|
chart.current?.dispose();
|
||||||
};
|
};
|
||||||
}, [init]);
|
}, [init]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
resizeable.current = false;
|
||||||
resize();
|
resize();
|
||||||
setOption(options);
|
setOption(options);
|
||||||
|
resizeable.current = true;
|
||||||
}, [options]);
|
}, [options]);
|
||||||
|
|
||||||
// resize on window resize
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleResize = throttle(() => {
|
const handleResize = throttle(() => {
|
||||||
resize();
|
if (resizeable.current) {
|
||||||
|
chart.current?.resize();
|
||||||
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
window.addEventListener('resize', handleResize);
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('resize', handleResize);
|
|
||||||
};
|
|
||||||
}, [resize]);
|
|
||||||
|
|
||||||
return <div ref={container} style={{ width: width, height }}></div>;
|
if (container.current) {
|
||||||
};
|
resizeObserver.current = new ResizeObserver(handleResize);
|
||||||
|
|
||||||
|
resizeObserver.current.observe(container.current);
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
if (container.current) {
|
||||||
|
resizeObserver.current?.unobserve(container.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="chart-wrapper" style={{ width: width, height }}>
|
||||||
|
<div ref={container} style={{ width: width, height }}></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
export default Chart;
|
export default Chart;
|
||||||
|
|||||||
+226
-169
@@ -1,29 +1,21 @@
|
|||||||
|
import useUserSettings from '@/hooks/use-user-settings';
|
||||||
|
import { theme } from 'antd';
|
||||||
import { isFunction } from 'lodash';
|
import { isFunction } from 'lodash';
|
||||||
const chartColorMap = {
|
import { useMemo } from 'react';
|
||||||
tickLineColor: 'rgba(217,217,217,0.5)',
|
|
||||||
axislabelColor: 'rgba(0, 0, 0, 0.4)'
|
|
||||||
};
|
|
||||||
|
|
||||||
export const tooltip = {
|
const formatLargeNumber = (value: number) => {
|
||||||
trigger: 'axis',
|
if (typeof value !== 'number' || isNaN(value)) {
|
||||||
// axisPointer: {
|
return value;
|
||||||
// type: 'shadow'
|
}
|
||||||
// }
|
|
||||||
formatter(params: any, callback?: (val: any) => any) {
|
if (value >= 1e9) {
|
||||||
let result = `<span class="tooltip-x-name">${params[0].axisValue}</span>`;
|
return (value / 1e9).toFixed(1).replace(/\.0$/, '') + 'B';
|
||||||
params.forEach((item: any) => {
|
} else if (value >= 1e6) {
|
||||||
let value = isFunction(callback)
|
return (value / 1e6).toFixed(1).replace(/\.0$/, '') + 'M';
|
||||||
? callback?.(item.data.value)
|
} else if (value >= 1e3) {
|
||||||
: item.data.value;
|
return (value / 1e3).toFixed(1).replace(/\.0$/, '') + 'K';
|
||||||
result += `<span class="tooltip-item">
|
} else {
|
||||||
<span class="tooltip-item-name">
|
return value;
|
||||||
<span style="display:inline-block;margin-right:5px;border-radius:8px;width:8px;height:8px;background-color:${item.color};"></span>
|
|
||||||
<span class="tooltip-title">${item.seriesName}</span>:
|
|
||||||
</span>
|
|
||||||
<span class="tooltip-value">${value}</span>
|
|
||||||
</span>`;
|
|
||||||
});
|
|
||||||
return `<div class="tooltip-wrapper">${result}</div>`;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,157 +26,222 @@ export const grid = {
|
|||||||
containLabel: true
|
containLabel: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export const legend = {
|
export default function useChartConfig() {
|
||||||
itemWidth: 8,
|
const { userSettings, isDarkTheme } = useUserSettings();
|
||||||
itemHeight: 8
|
const { useToken } = theme;
|
||||||
};
|
const { token } = useToken();
|
||||||
|
|
||||||
export const xAxis = {
|
console.log('token:', token);
|
||||||
type: 'category',
|
|
||||||
axisTick: {
|
|
||||||
show: true,
|
|
||||||
lineStyle: {
|
|
||||||
color: chartColorMap.tickLineColor
|
|
||||||
}
|
|
||||||
},
|
|
||||||
axisLabel: {
|
|
||||||
color: chartColorMap.axislabelColor,
|
|
||||||
fontSize: 12
|
|
||||||
},
|
|
||||||
axisLine: {
|
|
||||||
show: false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const yAxis = {
|
const chartColorMap = useMemo(() => {
|
||||||
// max: 100,
|
return {
|
||||||
// min: 0,
|
titleColor: token.colorText,
|
||||||
nameTextStyle: {
|
splitLineColor: token.colorBorder,
|
||||||
padding: [0, 0, 0, -20]
|
tickLineColor: token.colorSplit,
|
||||||
},
|
axislabelColor: token.colorTextTertiary,
|
||||||
splitLine: {
|
gaugeBgColor: token.colorFillSecondary,
|
||||||
show: true,
|
gaugeSplitLineColor: isDarkTheme
|
||||||
lineStyle: {
|
? 'rgba(255,255,255,.3)'
|
||||||
type: 'dashed'
|
: 'rgba(255, 255, 255, 1)',
|
||||||
}
|
gaugeSplitLineColor2: isDarkTheme
|
||||||
},
|
? 'rgba(255,255,255,.5)'
|
||||||
axisLabel: {
|
: 'rgba(255, 255, 255, 1)',
|
||||||
color: chartColorMap.axislabelColor,
|
colorBgContainerHover: isDarkTheme ? '#424242' : '#fff'
|
||||||
fontSize: 12
|
};
|
||||||
},
|
}, [userSettings.theme, isDarkTheme]);
|
||||||
axisTick: {
|
|
||||||
show: false
|
|
||||||
},
|
|
||||||
type: 'value'
|
|
||||||
};
|
|
||||||
|
|
||||||
export const title = {
|
const tooltip = {
|
||||||
show: true,
|
trigger: 'axis',
|
||||||
left: 'center',
|
backgroundColor: chartColorMap.colorBgContainerHover,
|
||||||
textStyle: {
|
borderColor: 'transparent',
|
||||||
fontSize: 12,
|
formatter(params: any, callback?: (val: any) => any) {
|
||||||
color: '#000'
|
let result = `<span class="tooltip-x-name">${params[0].axisValue}</span>`;
|
||||||
},
|
params.forEach((item: any) => {
|
||||||
text: ''
|
let value = isFunction(callback)
|
||||||
};
|
? callback?.(item.data.value)
|
||||||
|
: item.data.value;
|
||||||
|
result += `<span class="tooltip-item">
|
||||||
|
<span class="tooltip-item-name">
|
||||||
|
<span style="display:inline-block;margin-right:5px;border-radius:8px;width:8px;height:8px;background-color:${item.color};"></span>
|
||||||
|
<span class="tooltip-title">${item.seriesName}</span>:
|
||||||
|
</span>
|
||||||
|
<span class="tooltip-value">${value}</span>
|
||||||
|
</span>`;
|
||||||
|
});
|
||||||
|
return `<div class="tooltip-wrapper">${result}</div>`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const barItemConfig = {
|
const legend = {
|
||||||
type: 'bar',
|
itemWidth: 8,
|
||||||
barMaxWidth: 20,
|
itemHeight: 8,
|
||||||
barMinWidth: 8,
|
textStyle: {
|
||||||
// stack: 'total',
|
color: chartColorMap.axislabelColor
|
||||||
barGap: '30%',
|
}
|
||||||
barCategoryGap: '50%'
|
};
|
||||||
};
|
|
||||||
|
|
||||||
export const lineItemConfig = {
|
const xAxis = {
|
||||||
type: 'line',
|
type: 'category',
|
||||||
smooth: true,
|
axisTick: {
|
||||||
showSymbol: false,
|
show: true,
|
||||||
itemStyle: {},
|
lineStyle: {
|
||||||
lineStyle: {
|
color: chartColorMap.tickLineColor
|
||||||
width: 1.5,
|
}
|
||||||
opacity: 0.7
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const gaugeItemConfig = {
|
|
||||||
type: 'gauge',
|
|
||||||
radius: '88%',
|
|
||||||
center: ['50%', '65%'],
|
|
||||||
startAngle: 190,
|
|
||||||
endAngle: -10,
|
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
splitNumber: 5,
|
|
||||||
progress: {
|
|
||||||
show: true,
|
|
||||||
roundCap: false,
|
|
||||||
width: 12
|
|
||||||
},
|
|
||||||
pointer: {
|
|
||||||
length: '80%',
|
|
||||||
width: 4,
|
|
||||||
itemStyle: {
|
|
||||||
color: 'auto'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
axisLine: {
|
|
||||||
roundCap: false,
|
|
||||||
lineStyle: {
|
|
||||||
width: 12,
|
|
||||||
// color: [[1, 'rgba(221, 221, 221, 0.5)']],
|
|
||||||
color: [
|
|
||||||
[0.5, 'rgba(84, 204, 152, 80%)'],
|
|
||||||
[0.8, 'rgba(250, 173, 20, 80%)'],
|
|
||||||
[1, 'rgba(255, 77, 79, 80%)']
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
axisTick: {
|
|
||||||
distance: -12,
|
|
||||||
length: 6,
|
|
||||||
splitNumber: 5,
|
|
||||||
lineStyle: {
|
|
||||||
width: 1.5,
|
|
||||||
color: 'rgba(255, 255, 255, 1)'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
splitLine: {
|
|
||||||
distance: -12,
|
|
||||||
length: 12,
|
|
||||||
lineStyle: {
|
|
||||||
width: 1.5,
|
|
||||||
color: 'rgba(255, 255, 255, 1)'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
axisLabel: {
|
|
||||||
distance: 14,
|
|
||||||
color: 'rgba(0, 0, 0, .5)',
|
|
||||||
fontSize: 12
|
|
||||||
},
|
|
||||||
detail: {
|
|
||||||
lineHeight: 40,
|
|
||||||
height: 40,
|
|
||||||
offsetCenter: [5, 30],
|
|
||||||
valueAnimation: false,
|
|
||||||
fontSize: 20,
|
|
||||||
color: 'rgba(0, 0, 0, 0.88)',
|
|
||||||
formatter(value: any) {
|
|
||||||
return '{value|' + value + '}{unit|%}';
|
|
||||||
},
|
},
|
||||||
rich: {
|
axisLabel: {
|
||||||
value: {
|
color: chartColorMap.axislabelColor,
|
||||||
fontSize: 16,
|
fontSize: 12
|
||||||
fontWeight: '500',
|
},
|
||||||
color: 'rgba(0, 0, 0, 0.88)'
|
axisLine: {
|
||||||
|
show: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const yAxis = {
|
||||||
|
// max: 100,
|
||||||
|
// min: 0,
|
||||||
|
nameTextStyle: {
|
||||||
|
padding: [0, 0, 0, -20]
|
||||||
|
},
|
||||||
|
splitLine: {
|
||||||
|
show: true,
|
||||||
|
lineStyle: {
|
||||||
|
type: 'dashed',
|
||||||
|
color: chartColorMap.splitLineColor
|
||||||
|
}
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
color: chartColorMap.axislabelColor,
|
||||||
|
fontSize: 12,
|
||||||
|
formatter: formatLargeNumber
|
||||||
|
},
|
||||||
|
axisTick: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
type: 'value'
|
||||||
|
};
|
||||||
|
|
||||||
|
const title = {
|
||||||
|
show: true,
|
||||||
|
left: 'center',
|
||||||
|
textStyle: {
|
||||||
|
fontSize: 12,
|
||||||
|
color: chartColorMap.titleColor
|
||||||
|
},
|
||||||
|
text: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
const barItemConfig = {
|
||||||
|
type: 'bar',
|
||||||
|
barMaxWidth: 20,
|
||||||
|
barMinWidth: 8,
|
||||||
|
// stack: 'total',
|
||||||
|
barGap: '30%',
|
||||||
|
barCategoryGap: '50%'
|
||||||
|
};
|
||||||
|
|
||||||
|
const lineItemConfig = {
|
||||||
|
type: 'line',
|
||||||
|
smooth: true,
|
||||||
|
showSymbol: false,
|
||||||
|
itemStyle: {},
|
||||||
|
lineStyle: {
|
||||||
|
width: 1.5,
|
||||||
|
opacity: 0.7
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const gaugeItemConfig = {
|
||||||
|
type: 'gauge',
|
||||||
|
radius: '88%',
|
||||||
|
center: ['50%', '65%'],
|
||||||
|
startAngle: 190,
|
||||||
|
endAngle: -10,
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
splitNumber: 5,
|
||||||
|
progress: {
|
||||||
|
show: true,
|
||||||
|
roundCap: false,
|
||||||
|
width: 12
|
||||||
|
},
|
||||||
|
pointer: {
|
||||||
|
length: '80%',
|
||||||
|
width: 4,
|
||||||
|
itemStyle: {
|
||||||
|
color: 'auto'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
axisLine: {
|
||||||
|
roundCap: false,
|
||||||
|
lineStyle: {
|
||||||
|
width: 12,
|
||||||
|
color: [
|
||||||
|
[0.5, 'rgba(84, 204, 152, 80%)'],
|
||||||
|
[0.8, 'rgba(250, 173, 20, 80%)'],
|
||||||
|
[1, 'rgba(255, 77, 79, 80%)']
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
axisTick: {
|
||||||
|
distance: -11,
|
||||||
|
length: 6,
|
||||||
|
splitNumber: 5,
|
||||||
|
lineStyle: {
|
||||||
|
width: 1.5,
|
||||||
|
color: chartColorMap.gaugeSplitLineColor
|
||||||
|
}
|
||||||
|
},
|
||||||
|
splitLine: {
|
||||||
|
distance: -5,
|
||||||
|
length: 5,
|
||||||
|
lineStyle: {
|
||||||
|
width: 1.5,
|
||||||
|
color: chartColorMap.gaugeSplitLineColor2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
distance: 14,
|
||||||
|
color: chartColorMap.axislabelColor,
|
||||||
|
fontSize: 12
|
||||||
|
},
|
||||||
|
detail: {
|
||||||
|
lineHeight: 40,
|
||||||
|
height: 40,
|
||||||
|
offsetCenter: [5, 30],
|
||||||
|
valueAnimation: false,
|
||||||
|
fontSize: 20,
|
||||||
|
color: chartColorMap.titleColor,
|
||||||
|
formatter(value: any) {
|
||||||
|
return '{value|' + value + '}{unit|%}';
|
||||||
},
|
},
|
||||||
unit: {
|
rich: {
|
||||||
fontSize: 14,
|
value: {
|
||||||
color: 'rgba(0, 0, 0, 0.88)',
|
fontSize: 16,
|
||||||
fontWeight: '500',
|
fontWeight: '500',
|
||||||
padding: [0, 0, 0, 2]
|
color: chartColorMap.titleColor
|
||||||
|
},
|
||||||
|
unit: {
|
||||||
|
fontSize: 14,
|
||||||
|
color: chartColorMap.titleColor,
|
||||||
|
fontWeight: '500',
|
||||||
|
padding: [0, 0, 0, 2]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
return {
|
||||||
|
tooltip,
|
||||||
|
grid,
|
||||||
|
legend,
|
||||||
|
xAxis,
|
||||||
|
yAxis,
|
||||||
|
title,
|
||||||
|
chartColorMap,
|
||||||
|
barItemConfig,
|
||||||
|
lineItemConfig,
|
||||||
|
gaugeItemConfig,
|
||||||
|
isDark: isDarkTheme
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import Chart from '@/components/echarts/chart';
|
import Chart from '@/components/echarts/chart';
|
||||||
import {
|
import useChartConfig from '@/components/echarts/config';
|
||||||
gaugeItemConfig,
|
|
||||||
title as titleConfig
|
|
||||||
} from '@/components/echarts/config';
|
|
||||||
import EmptyData from '@/components/empty-data';
|
import EmptyData from '@/components/empty-data';
|
||||||
import { memo } from 'react';
|
import React, { memo } from 'react';
|
||||||
import { ChartProps } from './types';
|
import { ChartProps } from './types';
|
||||||
|
|
||||||
const GaugeChart: React.FC<Omit<ChartProps, 'seriesData' | 'xAxisData'>> = (
|
const GaugeChart: React.FC<Omit<ChartProps, 'seriesData' | 'xAxisData'>> = (
|
||||||
props
|
props
|
||||||
) => {
|
) => {
|
||||||
|
const {
|
||||||
|
gaugeItemConfig,
|
||||||
|
title: titleConfig,
|
||||||
|
chartColorMap
|
||||||
|
} = useChartConfig();
|
||||||
const { value, height, width, labelFormatter, title, color } = props;
|
const { value, height, width, labelFormatter, title, color } = props;
|
||||||
if (!value && value !== 0) {
|
if (!value && value !== 0) {
|
||||||
return <EmptyData height={height} title={title}></EmptyData>;
|
return <EmptyData height={height} title={title}></EmptyData>;
|
||||||
@@ -32,7 +34,7 @@ const GaugeChart: React.FC<Omit<ChartProps, 'seriesData' | 'xAxisData'>> = (
|
|||||||
...gaugeItemConfig.axisLine.lineStyle,
|
...gaugeItemConfig.axisLine.lineStyle,
|
||||||
color: [
|
color: [
|
||||||
[value / 100, color],
|
[value / 100, color],
|
||||||
[1, 'rgba(221, 221, 221, 0.5)']
|
[1, chartColorMap.gaugeBgColor]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
import Chart from '@/components/echarts/chart';
|
import Chart from '@/components/echarts/chart';
|
||||||
import {
|
import useChartConfig from '@/components/echarts/config';
|
||||||
grid,
|
|
||||||
legend,
|
|
||||||
title as titleConfig,
|
|
||||||
tooltip,
|
|
||||||
xAxis,
|
|
||||||
yAxis
|
|
||||||
} from '@/components/echarts/config';
|
|
||||||
import EmptyData from '@/components/empty-data';
|
import EmptyData from '@/components/empty-data';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { memo } from 'react';
|
import React, { memo, useMemo } from 'react';
|
||||||
import { ChartProps } from './types';
|
import { ChartProps } from './types';
|
||||||
|
|
||||||
const BarChart: React.FC<ChartProps> = (props) => {
|
const BarChart: React.FC<ChartProps> = (props) => {
|
||||||
@@ -22,33 +15,40 @@ const BarChart: React.FC<ChartProps> = (props) => {
|
|||||||
legendData,
|
legendData,
|
||||||
title
|
title
|
||||||
} = props;
|
} = props;
|
||||||
if (!seriesData.length) {
|
const {
|
||||||
return <EmptyData height={height} title={title}></EmptyData>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
title: titleConfig,
|
|
||||||
grid,
|
grid,
|
||||||
tooltip: {
|
legend,
|
||||||
...tooltip
|
title: titleConfig,
|
||||||
},
|
tooltip,
|
||||||
xAxis: {
|
xAxis,
|
||||||
...xAxis,
|
yAxis
|
||||||
axisLabel: {
|
} = useChartConfig();
|
||||||
...xAxis.axisLabel,
|
|
||||||
formatter: labelFormatter
|
|
||||||
}
|
|
||||||
},
|
|
||||||
yAxis,
|
|
||||||
legend: {
|
|
||||||
...legend,
|
|
||||||
data: []
|
|
||||||
},
|
|
||||||
|
|
||||||
series: []
|
const dataOptions = useMemo((): any => {
|
||||||
};
|
const options = {
|
||||||
|
title: {
|
||||||
|
...titleConfig,
|
||||||
|
left: 'start'
|
||||||
|
},
|
||||||
|
grid,
|
||||||
|
tooltip: {
|
||||||
|
...tooltip
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
...xAxis,
|
||||||
|
axisLabel: {
|
||||||
|
...xAxis.axisLabel,
|
||||||
|
formatter: labelFormatter
|
||||||
|
}
|
||||||
|
},
|
||||||
|
yAxis,
|
||||||
|
legend: {
|
||||||
|
...legend,
|
||||||
|
data: []
|
||||||
|
},
|
||||||
|
|
||||||
const setDataOptions = () => {
|
series: []
|
||||||
|
};
|
||||||
const data = _.map(seriesData, (item: any) => {
|
const data = _.map(seriesData, (item: any) => {
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
@@ -69,7 +69,6 @@ const BarChart: React.FC<ChartProps> = (props) => {
|
|||||||
animation: false,
|
animation: false,
|
||||||
title: {
|
title: {
|
||||||
...options.title,
|
...options.title,
|
||||||
left: 'start',
|
|
||||||
text: title
|
text: title
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
@@ -103,16 +102,30 @@ const BarChart: React.FC<ChartProps> = (props) => {
|
|||||||
},
|
},
|
||||||
series: data
|
series: data
|
||||||
};
|
};
|
||||||
};
|
}, [
|
||||||
|
seriesData,
|
||||||
const dataOptions: any = setDataOptions();
|
xAxisData,
|
||||||
|
title,
|
||||||
|
labelFormatter,
|
||||||
|
tooltip,
|
||||||
|
grid,
|
||||||
|
xAxis,
|
||||||
|
yAxis,
|
||||||
|
legend
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chart
|
<>
|
||||||
height={height}
|
{!seriesData.length ? (
|
||||||
options={dataOptions}
|
<EmptyData height={height} title={title}></EmptyData>
|
||||||
width={width || '100%'}
|
) : (
|
||||||
></Chart>
|
<Chart
|
||||||
|
height={height}
|
||||||
|
options={dataOptions}
|
||||||
|
width={width || '100%'}
|
||||||
|
></Chart>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
import type {
|
import type {
|
||||||
// 系列类型的定义后缀都为 SeriesOption
|
|
||||||
BarSeriesOption,
|
BarSeriesOption,
|
||||||
GaugeSeriesOption,
|
GaugeSeriesOption,
|
||||||
LineSeriesOption
|
LineSeriesOption,
|
||||||
|
ScatterSeriesOption
|
||||||
} from 'echarts/charts';
|
} from 'echarts/charts';
|
||||||
import { BarChart, GaugeChart, LineChart } from 'echarts/charts';
|
import { BarChart, GaugeChart, LineChart, ScatterChart } from 'echarts/charts';
|
||||||
import type {
|
import type {
|
||||||
DatasetComponentOption,
|
DatasetComponentOption,
|
||||||
GridComponentOption,
|
GridComponentOption,
|
||||||
// 组件类型的定义后缀都为 ComponentOption
|
|
||||||
TitleComponentOption,
|
TitleComponentOption,
|
||||||
TooltipComponentOption
|
TooltipComponentOption
|
||||||
} from 'echarts/components';
|
} from 'echarts/components';
|
||||||
import {
|
import {
|
||||||
// 数据集组件
|
DataZoomComponent,
|
||||||
DatasetComponent,
|
DatasetComponent,
|
||||||
GridComponent,
|
GridComponent,
|
||||||
LegendComponent,
|
LegendComponent,
|
||||||
TitleComponent,
|
TitleComponent,
|
||||||
TooltipComponent,
|
TooltipComponent,
|
||||||
// 内置数据转换器组件 (filter, sort)
|
// (filter, sort)
|
||||||
TransformComponent
|
TransformComponent
|
||||||
} from 'echarts/components';
|
} from 'echarts/components';
|
||||||
import type { ComposeOption } from 'echarts/core';
|
import type { ComposeOption } from 'echarts/core';
|
||||||
@@ -27,7 +26,6 @@ import * as echarts from 'echarts/core';
|
|||||||
import { LabelLayout, UniversalTransition } from 'echarts/features';
|
import { LabelLayout, UniversalTransition } from 'echarts/features';
|
||||||
import { CanvasRenderer } from 'echarts/renderers';
|
import { CanvasRenderer } from 'echarts/renderers';
|
||||||
|
|
||||||
// 通过 ComposeOption 来组合出一个只有必须组件和图表的 Option 类型
|
|
||||||
type ECOption = ComposeOption<
|
type ECOption = ComposeOption<
|
||||||
| BarSeriesOption
|
| BarSeriesOption
|
||||||
| LineSeriesOption
|
| LineSeriesOption
|
||||||
@@ -36,9 +34,10 @@ type ECOption = ComposeOption<
|
|||||||
| GridComponentOption
|
| GridComponentOption
|
||||||
| DatasetComponentOption
|
| DatasetComponentOption
|
||||||
| GaugeSeriesOption
|
| GaugeSeriesOption
|
||||||
|
| ScatterSeriesOption
|
||||||
>;
|
>;
|
||||||
|
|
||||||
// 注册必须的组件
|
// register components and charts
|
||||||
echarts.use([
|
echarts.use([
|
||||||
LegendComponent,
|
LegendComponent,
|
||||||
TitleComponent,
|
TitleComponent,
|
||||||
@@ -46,8 +45,10 @@ echarts.use([
|
|||||||
GridComponent,
|
GridComponent,
|
||||||
DatasetComponent,
|
DatasetComponent,
|
||||||
TransformComponent,
|
TransformComponent,
|
||||||
|
DataZoomComponent,
|
||||||
BarChart,
|
BarChart,
|
||||||
LineChart,
|
LineChart,
|
||||||
|
ScatterChart,
|
||||||
GaugeChart,
|
GaugeChart,
|
||||||
LabelLayout,
|
LabelLayout,
|
||||||
UniversalTransition,
|
UniversalTransition,
|
||||||
|
|||||||
@@ -1,16 +1,8 @@
|
|||||||
import Chart from '@/components/echarts/chart';
|
import Chart from '@/components/echarts/chart';
|
||||||
import {
|
import useChartConfig from '@/components/echarts/config';
|
||||||
grid,
|
|
||||||
legend,
|
|
||||||
lineItemConfig,
|
|
||||||
title as titleConfig,
|
|
||||||
tooltip,
|
|
||||||
xAxis,
|
|
||||||
yAxis
|
|
||||||
} from '@/components/echarts/config';
|
|
||||||
import EmptyData from '@/components/empty-data';
|
import EmptyData from '@/components/empty-data';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { memo } from 'react';
|
import React, { memo, useMemo } from 'react';
|
||||||
import { ChartProps } from './types';
|
import { ChartProps } from './types';
|
||||||
|
|
||||||
const LineChart: React.FC<ChartProps> = (props) => {
|
const LineChart: React.FC<ChartProps> = (props) => {
|
||||||
@@ -26,9 +18,15 @@ const LineChart: React.FC<ChartProps> = (props) => {
|
|||||||
smooth,
|
smooth,
|
||||||
title
|
title
|
||||||
} = props;
|
} = props;
|
||||||
if (!seriesData.length) {
|
const {
|
||||||
return <EmptyData height={height} title={title}></EmptyData>;
|
grid,
|
||||||
}
|
legend,
|
||||||
|
lineItemConfig,
|
||||||
|
title: titleConfig,
|
||||||
|
tooltip,
|
||||||
|
xAxis,
|
||||||
|
yAxis
|
||||||
|
} = useChartConfig();
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
title: {
|
title: {
|
||||||
@@ -53,13 +51,18 @@ const LineChart: React.FC<ChartProps> = (props) => {
|
|||||||
yAxis,
|
yAxis,
|
||||||
legend: {
|
legend: {
|
||||||
...legend,
|
...legend,
|
||||||
data: legendData
|
data: legendData.map((item: any) => {
|
||||||
|
return {
|
||||||
|
name: item,
|
||||||
|
icon: 'circle'
|
||||||
|
};
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
series: []
|
series: []
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateOptions = (): any => {
|
const dataOptions = useMemo((): any => {
|
||||||
const data = _.map(seriesData, (item: any) => {
|
const data = _.map(seriesData, (item: any) => {
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
@@ -75,7 +78,7 @@ const LineChart: React.FC<ChartProps> = (props) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const optionsConfig = {
|
return {
|
||||||
...options,
|
...options,
|
||||||
animation: false,
|
animation: false,
|
||||||
title: {
|
title: {
|
||||||
@@ -84,7 +87,11 @@ const LineChart: React.FC<ChartProps> = (props) => {
|
|||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
...options.yAxis,
|
...options.yAxis,
|
||||||
name: yAxisName
|
name: yAxisName,
|
||||||
|
nameTextStyle: {
|
||||||
|
fontSize: 12,
|
||||||
|
align: 'right'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
xAxis: {
|
xAxis: {
|
||||||
...options.xAxis,
|
...options.xAxis,
|
||||||
@@ -92,15 +99,20 @@ const LineChart: React.FC<ChartProps> = (props) => {
|
|||||||
},
|
},
|
||||||
series: data
|
series: data
|
||||||
};
|
};
|
||||||
return optionsConfig;
|
}, [seriesData, xAxisData, yAxisName, title, smooth, legendData, options]);
|
||||||
};
|
|
||||||
const dataOptions = generateOptions();
|
|
||||||
return (
|
return (
|
||||||
<Chart
|
<>
|
||||||
height={height}
|
{!seriesData.length ? (
|
||||||
options={dataOptions}
|
<EmptyData height={height} title={title}></EmptyData>
|
||||||
width={width || '100%'}
|
) : (
|
||||||
></Chart>
|
<Chart
|
||||||
|
height={height}
|
||||||
|
options={dataOptions}
|
||||||
|
width={width || '100%'}
|
||||||
|
></Chart>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,217 @@
|
|||||||
|
import Chart from '@/components/echarts/chart';
|
||||||
|
import useChartConfig from '@/components/echarts/config';
|
||||||
|
import EmptyData from '@/components/empty-data';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import React, { memo, useCallback, useMemo, useRef } from 'react';
|
||||||
|
import { ChartProps } from './types';
|
||||||
|
|
||||||
|
const Scatter: React.FC<ChartProps> = (props) => {
|
||||||
|
const { grid, title: titleConfig, isDark, chartColorMap } = useChartConfig();
|
||||||
|
const { seriesData, xAxisData, height, width, showEmpty, title } = props;
|
||||||
|
|
||||||
|
const chart = useRef<any>(null);
|
||||||
|
|
||||||
|
const options = useMemo(() => {
|
||||||
|
const colorMap = isDark
|
||||||
|
? {
|
||||||
|
split: chartColorMap.splitLineColor,
|
||||||
|
axis: chartColorMap.axislabelColor,
|
||||||
|
label: chartColorMap.axislabelColor
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
split: '#F2F2F2',
|
||||||
|
axis: '#dcdcdc',
|
||||||
|
label: '#dcdcdc'
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
animation: false,
|
||||||
|
grid: {
|
||||||
|
...grid,
|
||||||
|
right: 10,
|
||||||
|
top: 10,
|
||||||
|
bottom: 2,
|
||||||
|
left: 2,
|
||||||
|
containLabel: true,
|
||||||
|
borderRadius: 4
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
min: -1,
|
||||||
|
max: 1,
|
||||||
|
scale: false,
|
||||||
|
slient: true,
|
||||||
|
splitNumber: 15,
|
||||||
|
splitLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: colorMap.split
|
||||||
|
}
|
||||||
|
},
|
||||||
|
axisLine: {
|
||||||
|
show: true,
|
||||||
|
lineStyle: {
|
||||||
|
color: colorMap.axis
|
||||||
|
}
|
||||||
|
},
|
||||||
|
axisTick: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
show: true,
|
||||||
|
color: colorMap.label
|
||||||
|
},
|
||||||
|
boundaryGap: [0.05, 0.05]
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
min: -1,
|
||||||
|
max: 1,
|
||||||
|
scale: false,
|
||||||
|
slient: true,
|
||||||
|
splitNumber: 10,
|
||||||
|
boundaryGap: [0.05, 0.05],
|
||||||
|
splitLine: {
|
||||||
|
lineStyle: {
|
||||||
|
color: colorMap.split
|
||||||
|
}
|
||||||
|
},
|
||||||
|
axisLine: {
|
||||||
|
show: true,
|
||||||
|
lineStyle: {
|
||||||
|
color: colorMap.axis
|
||||||
|
}
|
||||||
|
},
|
||||||
|
axisTick: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
show: true,
|
||||||
|
color: colorMap.label
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
symbol: 'roundRect',
|
||||||
|
label: {
|
||||||
|
show: true,
|
||||||
|
shadowColor: 'none',
|
||||||
|
textBorderColor: 'none',
|
||||||
|
formatter: (params: any) => {
|
||||||
|
return params.name;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
series: []
|
||||||
|
};
|
||||||
|
}, [isDark]);
|
||||||
|
|
||||||
|
const findOverlappingPoints = useCallback(
|
||||||
|
(data: any[], currentPoint: any) => {
|
||||||
|
const overlappingPoints = [];
|
||||||
|
const symbolRadius = 16;
|
||||||
|
|
||||||
|
const [x1, y1] = chart.current.chart?.convertToPixel(
|
||||||
|
'grid',
|
||||||
|
currentPoint.value
|
||||||
|
);
|
||||||
|
|
||||||
|
const pixelPoints = data.map((point) => {
|
||||||
|
return {
|
||||||
|
...point,
|
||||||
|
value: chart.current.chart?.convertToPixel('grid', point.value)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let j = 0; j < pixelPoints.length; j++) {
|
||||||
|
if (currentPoint.name === pixelPoints[j].name) {
|
||||||
|
overlappingPoints.push({ ...pixelPoints[j] });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const [x2, y2] = pixelPoints[j].value;
|
||||||
|
|
||||||
|
const distance = Math.sqrt(
|
||||||
|
Math.pow(_.round(x2 - x1, 2), 2) + Math.pow(_.round(y2 - y1, 2), 2)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (distance <= symbolRadius) {
|
||||||
|
overlappingPoints.push({ ...pixelPoints[j] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return overlappingPoints;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderNameInTooltip = useCallback((dataList: any[]) => {
|
||||||
|
if (!dataList.length || dataList.length < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const renderText = (item: any) => {
|
||||||
|
return `<span class="tooltip-item-name">
|
||||||
|
<span style="display:flex;justify-content:center;align-items: center;color:#fff;
|
||||||
|
margin-right:0;border-radius:4px;width:14px;
|
||||||
|
height:14px;background-color:${item?.itemStyle?.color};"
|
||||||
|
>${item.name}</span>
|
||||||
|
</span>`;
|
||||||
|
};
|
||||||
|
return renderText;
|
||||||
|
}, []);
|
||||||
|
const dataOptions = useMemo((): any => {
|
||||||
|
const seriseDataList = seriesData.map((item: any, index: number) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
itemStyle: {
|
||||||
|
color: '#5470c6'
|
||||||
|
},
|
||||||
|
symbolSize: 16
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
...options,
|
||||||
|
tooltip: {
|
||||||
|
trigger: 'item',
|
||||||
|
borderWidth: 0,
|
||||||
|
backgroundColor: chartColorMap.colorBgContainerHover,
|
||||||
|
borderColor: 'transparent',
|
||||||
|
formatter(params: any, callback?: (val: any) => any) {
|
||||||
|
const dataList = findOverlappingPoints(seriseDataList, params.data);
|
||||||
|
let result = '';
|
||||||
|
const renderText: any = renderNameInTooltip(dataList);
|
||||||
|
dataList.forEach((item: any) => {
|
||||||
|
result += `
|
||||||
|
<span class="tooltip-item" style="justify-content: flex-start;">
|
||||||
|
${renderText ? renderText(item) : ''}
|
||||||
|
<span class="tooltip-value">${item.text}</span>
|
||||||
|
</span>`;
|
||||||
|
});
|
||||||
|
return `<div class="tooltip-wrapper">${result}</div>`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
...titleConfig,
|
||||||
|
text: title
|
||||||
|
},
|
||||||
|
series: {
|
||||||
|
type: 'scatter',
|
||||||
|
labelLayout: {
|
||||||
|
hideOverlap: true
|
||||||
|
},
|
||||||
|
data: seriseDataList
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [seriesData, xAxisData, title, options, findOverlappingPoints]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{!seriesData.length && showEmpty ? (
|
||||||
|
<EmptyData height={height} title={title}></EmptyData>
|
||||||
|
) : (
|
||||||
|
<Chart
|
||||||
|
ref={chart}
|
||||||
|
height={height}
|
||||||
|
options={dataOptions}
|
||||||
|
width={width || '100%'}
|
||||||
|
></Chart>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(Scatter);
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
export interface ChartProps {
|
export interface ChartProps {
|
||||||
seriesData: any[];
|
seriesData: any[];
|
||||||
|
showEmpty?: boolean;
|
||||||
xAxisData: string[];
|
xAxisData: string[];
|
||||||
legendData?: string[];
|
legendData?: string[];
|
||||||
labelFormatter?: (val?: any) => string;
|
labelFormatter?: (val?: any) => string;
|
||||||
tooltipValueFormatter?: (val?: any) => string;
|
tooltipValueFormatter?: (val: any) => string;
|
||||||
height: string | number;
|
height: string | number;
|
||||||
width?: string | number;
|
width?: string | number;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
|||||||
@@ -9,28 +9,13 @@
|
|||||||
|
|
||||||
.editor-header {
|
.editor-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
height: 40px;
|
padding-block: 0;
|
||||||
padding: 0 10px;
|
padding-inline: 12px 10px;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: rgb(56, 56, 56);
|
background-color: var(--color-editor-header-bg);
|
||||||
|
|
||||||
.ant-select-selector {
|
|
||||||
background-color: rgba(255, 255, 255, 9%) !important;
|
|
||||||
color: rgba(255, 255, 255, 70%);
|
|
||||||
border-radius: var(--border-radius-2px);
|
|
||||||
|
|
||||||
.ant-select-selection-item {
|
|
||||||
color: rgba(255, 255, 255, 70%);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.ant-select-arrow {
|
|
||||||
color: rgba(255, 255, 255, 70%);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// set scrollbar style
|
// set scrollbar style
|
||||||
|
|
||||||
.scrollbar {
|
.scrollbar {
|
||||||
.slider {
|
.slider {
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
|||||||
@@ -1,33 +1,40 @@
|
|||||||
import { Select } from 'antd';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
import CopyButton from '../copy-button';
|
import CopyButton from '../copy-button';
|
||||||
|
import SegmentLine from '../segment-line';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
|
|
||||||
|
const Wrapper = styled.div<{ $height: number }>`
|
||||||
|
height: ${(props) => props.$height}px;
|
||||||
|
`;
|
||||||
|
|
||||||
interface EditorwrapProps {
|
interface EditorwrapProps {
|
||||||
|
headerHeight?: number;
|
||||||
header?: React.ReactNode;
|
header?: React.ReactNode;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
showHeader?: boolean;
|
showHeader?: boolean;
|
||||||
copyText: string;
|
copyText: string;
|
||||||
defaultValue?: string;
|
defaultValue?: string;
|
||||||
langOptions?: { label: string; value: string }[];
|
langOptions?: Global.BaseOption<string | number>[];
|
||||||
styles?: {
|
styles?: {
|
||||||
wrapper?: React.CSSProperties;
|
wrapper?: React.CSSProperties;
|
||||||
header?: React.CSSProperties;
|
header?: React.CSSProperties;
|
||||||
content?: React.CSSProperties;
|
content?: React.CSSProperties;
|
||||||
};
|
};
|
||||||
onChangeLang?: (value: string) => void;
|
onChangeLang?: (value: string | number) => void;
|
||||||
}
|
}
|
||||||
const EditorWrap: React.FC<EditorwrapProps> = ({
|
const EditorWrap: React.FC<EditorwrapProps> = ({
|
||||||
|
headerHeight = 40,
|
||||||
header,
|
header,
|
||||||
children,
|
children,
|
||||||
copyText,
|
copyText,
|
||||||
langOptions,
|
langOptions = [],
|
||||||
onChangeLang,
|
onChangeLang,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
styles = {},
|
styles = {},
|
||||||
showHeader = true
|
showHeader = true
|
||||||
}) => {
|
}) => {
|
||||||
const handleChangeLang = (value: string) => {
|
const handleChangeLang = (value: string | number) => {
|
||||||
onChangeLang?.(value);
|
onChangeLang?.(value);
|
||||||
};
|
};
|
||||||
const renderHeader = () => {
|
const renderHeader = () => {
|
||||||
@@ -36,15 +43,14 @@ const EditorWrap: React.FC<EditorwrapProps> = ({
|
|||||||
}
|
}
|
||||||
if (showHeader) {
|
if (showHeader) {
|
||||||
return (
|
return (
|
||||||
<div className="editor-header">
|
<Wrapper className="editor-header" $height={headerHeight}>
|
||||||
<Select
|
<SegmentLine
|
||||||
|
height={headerHeight}
|
||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
style={{ width: 120 }}
|
size="small"
|
||||||
size="middle"
|
|
||||||
variant="filled"
|
|
||||||
options={langOptions}
|
options={langOptions}
|
||||||
onChange={handleChangeLang}
|
onChange={handleChangeLang}
|
||||||
></Select>
|
></SegmentLine>
|
||||||
<CopyButton
|
<CopyButton
|
||||||
text={copyText}
|
text={copyText}
|
||||||
size="small"
|
size="small"
|
||||||
@@ -52,7 +58,7 @@ const EditorWrap: React.FC<EditorwrapProps> = ({
|
|||||||
color: 'rgba(255,255,255,.7)'
|
color: 'rgba(255,255,255,.7)'
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
// footer all styles
|
|
||||||
.footer {
|
|
||||||
bottom: 0;
|
|
||||||
width: 100%;
|
|
||||||
background-color: transparent;
|
|
||||||
padding: 20px 0;
|
|
||||||
text-align: center;
|
|
||||||
font-size: var(--font-size-middle);
|
|
||||||
color: var(--color-text-2);
|
|
||||||
|
|
||||||
.footer-content-left-text {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,30 +3,60 @@ import { getAtomStorage } from '@/atoms/utils';
|
|||||||
import VersionInfo, { modalConfig } from '@/components/version-info';
|
import VersionInfo, { modalConfig } from '@/components/version-info';
|
||||||
import externalLinks from '@/constants/external-links';
|
import externalLinks from '@/constants/external-links';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Modal, Space } from 'antd';
|
import { Button, Divider, Modal } from 'antd';
|
||||||
import './index.less';
|
import { createStyles } from 'antd-style';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
const CompanyWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
padding-inline: 0 8px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const useStyles = createStyles(({ token, css }) => ({
|
||||||
|
footer: css`
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
background-color: transparent;
|
||||||
|
padding: 20px 0;
|
||||||
|
text-align: center;
|
||||||
|
font-size: var(--font-size-middle);
|
||||||
|
color: ${token.colorTextTertiary};
|
||||||
|
`,
|
||||||
|
'footer-content-left-text': {
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center'
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
const Footer: React.FC = () => {
|
const Footer: React.FC = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const [modal, contextHolder] = Modal.useModal();
|
||||||
|
const { styles } = useStyles();
|
||||||
|
|
||||||
const showVersion = () => {
|
const showVersion = () => {
|
||||||
Modal.info({
|
modal.info({
|
||||||
...modalConfig,
|
...modalConfig,
|
||||||
|
width: 460,
|
||||||
content: <VersionInfo intl={intl} />
|
content: <VersionInfo intl={intl} />
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="footer">
|
<>
|
||||||
<div className="footer-content">
|
{contextHolder}
|
||||||
<div className="footer-content-left">
|
<div className={styles.footer}>
|
||||||
<div className="footer-content-left-text">
|
<div className="footer-content">
|
||||||
<Space size={4}>
|
<div className="footer-content-left">
|
||||||
<span>©</span>
|
<div className={styles['footer-content-left-text']}>
|
||||||
<span> {new Date().getFullYear()}</span>
|
<CompanyWrapper>
|
||||||
<span> {intl.formatMessage({ id: 'settings.company' })}</span>
|
<span>©</span>
|
||||||
</Space>
|
<span> {new Date().getFullYear()}</span>
|
||||||
<Space size={8} style={{ marginLeft: 18 }}>
|
<span> {intl.formatMessage({ id: 'settings.company' })}</span>
|
||||||
|
</CompanyWrapper>
|
||||||
|
<Divider type="vertical" />
|
||||||
<Button
|
<Button
|
||||||
type="link"
|
type="link"
|
||||||
size="small"
|
size="small"
|
||||||
@@ -35,14 +65,15 @@ const Footer: React.FC = () => {
|
|||||||
>
|
>
|
||||||
{intl.formatMessage({ id: 'common.button.help' })}
|
{intl.formatMessage({ id: 'common.button.help' })}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Divider type="vertical" />
|
||||||
<Button type="link" size="small" onClick={showVersion}>
|
<Button type="link" size="small" onClick={showVersion}>
|
||||||
{getAtomStorage(GPUStackVersionAtom)?.version}
|
{getAtomStorage(GPUStackVersionAtom)?.version}
|
||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,18 @@ import './styles/dark.less';
|
|||||||
|
|
||||||
interface CodeViewerProps {
|
interface CodeViewerProps {
|
||||||
code: string;
|
code: string;
|
||||||
|
copyValue?: string;
|
||||||
lang: string;
|
lang: string;
|
||||||
autodetect?: boolean;
|
autodetect?: boolean;
|
||||||
ignoreIllegals?: boolean;
|
ignoreIllegals?: boolean;
|
||||||
copyable?: boolean;
|
copyable?: boolean;
|
||||||
height?: string | number;
|
height?: string | number;
|
||||||
|
style?: React.CSSProperties;
|
||||||
}
|
}
|
||||||
const DarkViewer: React.FC<CodeViewerProps> = (props) => {
|
const DarkViewer: React.FC<CodeViewerProps> = (props) => {
|
||||||
const {
|
const {
|
||||||
code,
|
code,
|
||||||
|
copyValue,
|
||||||
lang,
|
lang,
|
||||||
autodetect,
|
autodetect,
|
||||||
ignoreIllegals,
|
ignoreIllegals,
|
||||||
@@ -22,8 +25,10 @@ const DarkViewer: React.FC<CodeViewerProps> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<CodeViewer
|
<CodeViewer
|
||||||
|
style={props.style}
|
||||||
height={height}
|
height={height}
|
||||||
code={code}
|
code={code}
|
||||||
|
copyValue={copyValue}
|
||||||
lang={lang}
|
lang={lang}
|
||||||
theme="dark"
|
theme="dark"
|
||||||
autodetect={autodetect}
|
autodetect={autodetect}
|
||||||
|
|||||||
@@ -4,26 +4,32 @@ import './styles/light.less';
|
|||||||
|
|
||||||
interface CodeViewerProps {
|
interface CodeViewerProps {
|
||||||
code: string;
|
code: string;
|
||||||
|
copyValue?: string;
|
||||||
lang: string;
|
lang: string;
|
||||||
autodetect?: boolean;
|
autodetect?: boolean;
|
||||||
ignoreIllegals?: boolean;
|
ignoreIllegals?: boolean;
|
||||||
copyable?: boolean;
|
copyable?: boolean;
|
||||||
height?: string | number;
|
height?: string | number;
|
||||||
|
style?: React.CSSProperties;
|
||||||
}
|
}
|
||||||
const LightViewer: React.FC<CodeViewerProps> = (props) => {
|
const LightViewer: React.FC<CodeViewerProps> = (props) => {
|
||||||
const {
|
const {
|
||||||
code,
|
code,
|
||||||
|
copyValue,
|
||||||
lang,
|
lang,
|
||||||
autodetect,
|
autodetect,
|
||||||
ignoreIllegals,
|
ignoreIllegals,
|
||||||
copyable,
|
copyable,
|
||||||
|
style,
|
||||||
height = 'auto'
|
height = 'auto'
|
||||||
} = props || {};
|
} = props || {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CodeViewer
|
<CodeViewer
|
||||||
|
style={style}
|
||||||
height={height}
|
height={height}
|
||||||
code={code}
|
code={code}
|
||||||
|
copyValue={copyValue}
|
||||||
lang={lang}
|
lang={lang}
|
||||||
theme="light"
|
theme="light"
|
||||||
autodetect={autodetect}
|
autodetect={autodetect}
|
||||||
|
|||||||
@@ -1,26 +1,86 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import hljs from 'highlight.js';
|
import hljs from 'highlight.js';
|
||||||
import { memo, useMemo } from 'react';
|
import { memo, useMemo } from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
import CopyButton from '../copy-button';
|
import CopyButton from '../copy-button';
|
||||||
import { escapeHtml } from './utils';
|
import { escapeHtml } from './utils';
|
||||||
|
|
||||||
interface CodeViewerProps {
|
interface CodeViewerProps {
|
||||||
code: string;
|
code: string;
|
||||||
|
copyValue?: string;
|
||||||
lang: string;
|
lang: string;
|
||||||
autodetect?: boolean;
|
autodetect?: boolean;
|
||||||
ignoreIllegals?: boolean;
|
ignoreIllegals?: boolean;
|
||||||
copyable?: boolean;
|
copyable?: boolean;
|
||||||
height?: string | number;
|
height?: string | number;
|
||||||
theme?: 'light' | 'dark';
|
theme?: 'light' | 'dark';
|
||||||
|
style?: React.CSSProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CodeHeaderProps {
|
||||||
|
copyValue: string;
|
||||||
|
copyable: boolean;
|
||||||
|
lang: string;
|
||||||
|
theme: 'light' | 'dark';
|
||||||
|
}
|
||||||
|
|
||||||
|
const CodeHeaderWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
height: 32px;
|
||||||
|
padding: 0 12px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--ant-color-text-tertiary);
|
||||||
|
background-color: #fafafa;
|
||||||
|
border-top-left-radius: 4px;
|
||||||
|
border-top-right-radius: 4px;
|
||||||
|
&.dark {
|
||||||
|
background-color: var(--color-editor-header-bg);
|
||||||
|
color: rgba(255, 255, 255, 0.65);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Wrapper = styled.div`
|
||||||
|
border-radius: var(--border-radius-mini);
|
||||||
|
`;
|
||||||
|
|
||||||
|
const CodeHeader: React.FC<CodeHeaderProps> = ({
|
||||||
|
copyValue,
|
||||||
|
lang,
|
||||||
|
theme,
|
||||||
|
copyable
|
||||||
|
}) => {
|
||||||
|
if (!copyable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<CodeHeaderWrapper
|
||||||
|
className={classNames({
|
||||||
|
dark: theme === 'dark',
|
||||||
|
light: theme === 'light'
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<span>{lang}</span>
|
||||||
|
<CopyButton
|
||||||
|
text={copyValue}
|
||||||
|
size="small"
|
||||||
|
style={{ color: '#abb2bf' }}
|
||||||
|
></CopyButton>
|
||||||
|
</CodeHeaderWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const CodeViewer: React.FC<CodeViewerProps> = (props) => {
|
const CodeViewer: React.FC<CodeViewerProps> = (props) => {
|
||||||
const {
|
const {
|
||||||
code,
|
code = '',
|
||||||
|
copyValue,
|
||||||
lang,
|
lang,
|
||||||
autodetect = true,
|
autodetect = true,
|
||||||
ignoreIllegals = true,
|
ignoreIllegals = true,
|
||||||
copyable = true,
|
copyable = true,
|
||||||
height = 'auto'
|
height = 'auto',
|
||||||
|
style
|
||||||
} = props || {};
|
} = props || {};
|
||||||
|
|
||||||
const highlightedCode = useMemo(() => {
|
const highlightedCode = useMemo(() => {
|
||||||
@@ -59,33 +119,39 @@ const CodeViewer: React.FC<CodeViewerProps> = (props) => {
|
|||||||
}, [code, lang, autodetect, ignoreIllegals]);
|
}, [code, lang, autodetect, ignoreIllegals]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<pre
|
<Wrapper>
|
||||||
className={classNames(
|
<CodeHeader
|
||||||
'code-pre custome-scrollbar custom-scrollbar-horizontal ',
|
copyValue={copyValue || code}
|
||||||
{
|
lang={lang}
|
||||||
dark: props.theme === 'dark',
|
copyable={copyable}
|
||||||
light: props.theme === 'light',
|
theme={props.theme || 'light'}
|
||||||
copyable: copyable
|
></CodeHeader>
|
||||||
}
|
<pre
|
||||||
)}
|
className={classNames(
|
||||||
style={{
|
'code-pre custome-scrollbar custom-scrollbar-horizontal ',
|
||||||
height: height
|
{
|
||||||
}}
|
dark: props.theme === 'dark',
|
||||||
>
|
light: props.theme === 'light'
|
||||||
<code
|
}
|
||||||
className={highlightedCode.className}
|
)}
|
||||||
dangerouslySetInnerHTML={{
|
style={{
|
||||||
__html: highlightedCode.value
|
marginBottom: 0,
|
||||||
|
height: height,
|
||||||
|
...style
|
||||||
}}
|
}}
|
||||||
></code>
|
>
|
||||||
{copyable && (
|
<code
|
||||||
<CopyButton
|
style={{ minHeight: height }}
|
||||||
text={code}
|
className={classNames(highlightedCode.className, {
|
||||||
size="small"
|
dark: props.theme === 'dark',
|
||||||
style={{ color: '#abb2bf' }}
|
light: props.theme === 'light'
|
||||||
></CopyButton>
|
})}
|
||||||
)}
|
dangerouslySetInnerHTML={{
|
||||||
</pre>
|
__html: highlightedCode.value
|
||||||
|
}}
|
||||||
|
></code>
|
||||||
|
</pre>
|
||||||
|
</Wrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import useUserSettings from '@/hooks/use-user-settings';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import CodeViewerDark from './code-viewer-dark';
|
import CodeViewerDark from './code-viewer-dark';
|
||||||
import CodeViewerLight from './code-viewer-light';
|
import CodeViewerLight from './code-viewer-light';
|
||||||
@@ -8,29 +9,45 @@ const HighlightCode: React.FC<{
|
|||||||
lang?: string;
|
lang?: string;
|
||||||
copyable?: boolean;
|
copyable?: boolean;
|
||||||
theme?: 'light' | 'dark';
|
theme?: 'light' | 'dark';
|
||||||
|
fixedTheme?: 'light' | 'dark';
|
||||||
height?: string | number;
|
height?: string | number;
|
||||||
|
style?: React.CSSProperties;
|
||||||
|
copyValue?: string;
|
||||||
}> = (props) => {
|
}> = (props) => {
|
||||||
const {
|
const {
|
||||||
|
style,
|
||||||
code,
|
code,
|
||||||
|
copyValue,
|
||||||
lang = 'bash',
|
lang = 'bash',
|
||||||
copyable = true,
|
copyable = true,
|
||||||
theme = 'dark',
|
theme,
|
||||||
height = 'auto'
|
height = 'auto'
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const { userSettings } = useUserSettings();
|
||||||
|
|
||||||
|
const currentTheme = React.useMemo(() => {
|
||||||
|
const res = theme || userSettings.theme === 'realDark' ? 'dark' : 'light';
|
||||||
|
return res;
|
||||||
|
}, [theme, userSettings.theme]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="high-light-wrapper hj-wrapper">
|
<div className="high-light-wrapper hj-wrapper">
|
||||||
{theme === 'dark' ? (
|
{currentTheme === 'dark' ? (
|
||||||
<CodeViewerDark
|
<CodeViewerDark
|
||||||
lang={lang}
|
lang={lang}
|
||||||
code={code}
|
code={code}
|
||||||
|
copyValue={copyValue}
|
||||||
copyable={copyable}
|
copyable={copyable}
|
||||||
height={height}
|
height={height}
|
||||||
|
style={style}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<CodeViewerLight
|
<CodeViewerLight
|
||||||
|
style={style}
|
||||||
lang={lang}
|
lang={lang}
|
||||||
code={code}
|
code={code}
|
||||||
|
copyValue={copyValue}
|
||||||
copyable={copyable}
|
copyable={copyable}
|
||||||
height={height}
|
height={height}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ hue-6-2: #e6c07b
|
|||||||
.code-pre.dark {
|
.code-pre.dark {
|
||||||
.hljs {
|
.hljs {
|
||||||
color: #abb2bf;
|
color: #abb2bf;
|
||||||
background: #282c34;
|
background: var(--color-editor-dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
.hljs-comment,
|
.hljs-comment,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.high-light-wrapper {
|
.high-light-wrapper {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
font-size: var(--font-size-base);
|
font-size: var(--font-size-code);
|
||||||
|
|
||||||
.hljs {
|
.hljs {
|
||||||
font-weight: var(--font-weight-normal);
|
font-weight: var(--font-weight-normal);
|
||||||
@@ -20,18 +20,30 @@
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
&.light {
|
||||||
&::-webkit-scrollbar-thumb {
|
&:hover {
|
||||||
background-color: var(--color-scrollbar-thumb);
|
&::-webkit-scrollbar-thumb {
|
||||||
border-radius: 4px;
|
background-color: var(--color-scrollbar-thumb);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.dark {
|
||||||
|
&:hover {
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--scrollbar-handle-light-bg);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.code-pre {
|
.code-pre {
|
||||||
padding-inline: 12px 12px;
|
padding-inline: 12px 12px;
|
||||||
|
border-radius: 0 0 var(--border-radius-mini) var(--border-radius-mini);
|
||||||
position: relative;
|
position: relative;
|
||||||
border-radius: var(--border-radius-mini);
|
white-space: pre-wrap;
|
||||||
|
|
||||||
code {
|
code {
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
@@ -48,11 +60,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.dark {
|
&.dark {
|
||||||
background-color: #282c34;
|
background-color: var(--color-editor-dark);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--scrollbar-handle-light-bg);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.light {
|
&.light {
|
||||||
background-color: rgb(250, 250, 250);
|
background-color: rgb(250, 250, 250);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--color-scrollbar-thumb);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ hue-6-2: #c18401
|
|||||||
.code-pre.light {
|
.code-pre.light {
|
||||||
.hljs {
|
.hljs {
|
||||||
color: #383a42;
|
color: #383a42;
|
||||||
background: #fafafa;
|
background: var(--color-editor-light);
|
||||||
}
|
}
|
||||||
|
|
||||||
.hljs-comment,
|
.hljs-comment,
|
||||||
|
|||||||
@@ -0,0 +1,351 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: iconfont; /* Project id 4613488 */
|
||||||
|
src: url('iconfont.woff2?t=1747231573342') format('woff2'),
|
||||||
|
url('iconfont.woff?t=1747231573342') format('woff'),
|
||||||
|
url('iconfont.ttf?t=1747231573342') format('truetype');
|
||||||
|
}
|
||||||
|
|
||||||
|
.iconfont {
|
||||||
|
font-family: iconfont !important;
|
||||||
|
font-size: 16px;
|
||||||
|
font-style: normal;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-dark_theme::before {
|
||||||
|
content: "\e646";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-theme-auto-1::before {
|
||||||
|
content: "\e660";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-theme-auto::before {
|
||||||
|
content: "\e663";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-auto-theme-1::before {
|
||||||
|
content: "\e664";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-auto-theme::before {
|
||||||
|
content: "\e662";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-cols_3::before {
|
||||||
|
content: "\e65c";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-cols_6::before {
|
||||||
|
content: "\e65d";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-cols_2::before {
|
||||||
|
content: "\e65e";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-cols_4::before {
|
||||||
|
content: "\e65f";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-a-save1::before {
|
||||||
|
content: "\e65b";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-uncollapse_all::before {
|
||||||
|
content: "\e657";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-collapse::before {
|
||||||
|
content: "\e656";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-rocket-launch::before {
|
||||||
|
content: "\e689";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-user-filled::before {
|
||||||
|
content: "\e625";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-assistant::before {
|
||||||
|
content: "\e62d";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-assistant-filled::before {
|
||||||
|
content: "\e847";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-save3::before {
|
||||||
|
content: "\e655";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-fankuifaqs::before {
|
||||||
|
content: "\e7bf";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-issues::before {
|
||||||
|
content: "\e816";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-neicun::before {
|
||||||
|
content: "\e688";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-collapse_all::before {
|
||||||
|
content: "\e66f";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-down::before {
|
||||||
|
content: "\e654";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-fenxiang::before {
|
||||||
|
content: "\e604";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-mosaic-2::before {
|
||||||
|
content: "\e64f";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-stars::before {
|
||||||
|
content: "\e8a8";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-mosaic::before {
|
||||||
|
content: "\e636";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-outline-play::before {
|
||||||
|
content: "\e653";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-SelectionInverse::before {
|
||||||
|
content: "\eace";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-justice1::before {
|
||||||
|
content: "\e652";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-New_img::before {
|
||||||
|
content: "\e733";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-new_release_outlined::before {
|
||||||
|
content: "\e66c";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-new-releases::before {
|
||||||
|
content: "\e60f";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-catalog::before {
|
||||||
|
content: "\e62b";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-save2::before {
|
||||||
|
content: "\e635";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-left-template::before {
|
||||||
|
content: "\e62a";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-logs::before {
|
||||||
|
content: "\e6ec";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-gpu::before {
|
||||||
|
content: "\e71e";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-filled-gpu::before {
|
||||||
|
content: "\e6de";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-outline-gpu::before {
|
||||||
|
content: "\e641";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-ts-tubiao_webserver::before {
|
||||||
|
content: "\e716";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-server::before {
|
||||||
|
content: "\e66a";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-host::before {
|
||||||
|
content: "\e7c6";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-playcircle::before {
|
||||||
|
content: "\e80f";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-recreate::before {
|
||||||
|
content: "\e6a5";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-save1::before {
|
||||||
|
content: "\e647";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-save::before {
|
||||||
|
content: "\e67c";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-upload_image::before {
|
||||||
|
content: "\e613";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-sound-wave::before {
|
||||||
|
content: "\e619";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-rank1::before {
|
||||||
|
content: "\e7cb";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-cube::before {
|
||||||
|
content: "\e769";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-speaker-slash::before {
|
||||||
|
content: "\ebb6";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-random::before {
|
||||||
|
content: "\e603";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-suijisenlin::before {
|
||||||
|
content: "\e60e";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-stop2::before {
|
||||||
|
content: "\e8db";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-stop::before {
|
||||||
|
content: "\e60b";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-image::before {
|
||||||
|
content: "\e62c";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-stopcircle-fill::before {
|
||||||
|
content: "\e7cc";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-playcircle-fill::before {
|
||||||
|
content: "\e7cd";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-SpeakerSlash::before {
|
||||||
|
content: "\e661";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-SpeakerHigh::before {
|
||||||
|
content: "\e670";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-user_voice::before {
|
||||||
|
content: "\e667";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-audio::before {
|
||||||
|
content: "\e985";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-hard-disk::before {
|
||||||
|
content: "\eb1d";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-new::before {
|
||||||
|
content: "\e612";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-tu2::before {
|
||||||
|
content: "\e607";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-robot::before {
|
||||||
|
content: "\e634";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-robot1::before {
|
||||||
|
content: "\e602";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-aizhineng::before {
|
||||||
|
content: "\e672";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-copy::before {
|
||||||
|
content: "\e720";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-AIzhineng::before {
|
||||||
|
content: "\e608";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-clear::before {
|
||||||
|
content: "\e60a";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-keyboard::before {
|
||||||
|
content: "\e61b";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-networkerror::before {
|
||||||
|
content: "\e624";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-external-link::before {
|
||||||
|
content: "\e66b";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-huggingface::before {
|
||||||
|
content: "\e7d1";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-ollama::before {
|
||||||
|
content: "\e601";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-a-layout6-line::before {
|
||||||
|
content: "\e9ef";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-a-Layout5::before {
|
||||||
|
content: "\e610";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-English::before {
|
||||||
|
content: "\e8b3";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-chinese::before {
|
||||||
|
content: "\e611";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-yingguo::before {
|
||||||
|
content: "\e606";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-code::before {
|
||||||
|
content: "\e84f";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-stop1::before {
|
||||||
|
content: "\e783";
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-command::before {
|
||||||
|
content: "\e600";
|
||||||
|
}
|
||||||
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,597 @@
|
|||||||
|
{
|
||||||
|
"id": "4613488",
|
||||||
|
"name": "gpustack",
|
||||||
|
"font_family": "iconfont",
|
||||||
|
"css_prefix_text": "icon-",
|
||||||
|
"description": "",
|
||||||
|
"glyphs": [
|
||||||
|
{
|
||||||
|
"icon_id": "44028047",
|
||||||
|
"name": "dark_theme",
|
||||||
|
"font_class": "dark_theme",
|
||||||
|
"unicode": "e646",
|
||||||
|
"unicode_decimal": 58950
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44094552",
|
||||||
|
"name": "theme-auto-1",
|
||||||
|
"font_class": "theme-auto-1",
|
||||||
|
"unicode": "e660",
|
||||||
|
"unicode_decimal": 58976
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44094551",
|
||||||
|
"name": "theme-auto",
|
||||||
|
"font_class": "theme-auto",
|
||||||
|
"unicode": "e663",
|
||||||
|
"unicode_decimal": 58979
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44094550",
|
||||||
|
"name": "theme",
|
||||||
|
"font_class": "auto-theme-1",
|
||||||
|
"unicode": "e664",
|
||||||
|
"unicode_decimal": 58980
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44092227",
|
||||||
|
"name": "routine_36dp_1F1F1F_FILL0_wght400_GRAD0_opsz24",
|
||||||
|
"font_class": "auto-theme",
|
||||||
|
"unicode": "e662",
|
||||||
|
"unicode_decimal": 58978
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44086334",
|
||||||
|
"name": "cols_3",
|
||||||
|
"font_class": "cols_3",
|
||||||
|
"unicode": "e65c",
|
||||||
|
"unicode_decimal": 58972
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44086333",
|
||||||
|
"name": "cols_6",
|
||||||
|
"font_class": "cols_6",
|
||||||
|
"unicode": "e65d",
|
||||||
|
"unicode_decimal": 58973
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44086332",
|
||||||
|
"name": "cols_2",
|
||||||
|
"font_class": "cols_2",
|
||||||
|
"unicode": "e65e",
|
||||||
|
"unicode_decimal": 58974
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44086331",
|
||||||
|
"name": "cols_4",
|
||||||
|
"font_class": "cols_4",
|
||||||
|
"unicode": "e65f",
|
||||||
|
"unicode_decimal": 58975
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "44065884",
|
||||||
|
"name": "save",
|
||||||
|
"font_class": "a-save1",
|
||||||
|
"unicode": "e65b",
|
||||||
|
"unicode_decimal": 58971
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "43808249",
|
||||||
|
"name": "uncollapse_all",
|
||||||
|
"font_class": "uncollapse_all",
|
||||||
|
"unicode": "e657",
|
||||||
|
"unicode_decimal": 58967
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "43807590",
|
||||||
|
"name": "collapse",
|
||||||
|
"font_class": "collapse",
|
||||||
|
"unicode": "e656",
|
||||||
|
"unicode_decimal": 58966
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "22575690",
|
||||||
|
"name": "rocket-launch",
|
||||||
|
"font_class": "rocket-launch",
|
||||||
|
"unicode": "e689",
|
||||||
|
"unicode_decimal": 59017
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "6050653",
|
||||||
|
"name": "user",
|
||||||
|
"font_class": "user-filled",
|
||||||
|
"unicode": "e625",
|
||||||
|
"unicode_decimal": 58917
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "37486588",
|
||||||
|
"name": "assistant",
|
||||||
|
"font_class": "assistant",
|
||||||
|
"unicode": "e62d",
|
||||||
|
"unicode_decimal": 58925
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "43220044",
|
||||||
|
"name": "AIAssistant",
|
||||||
|
"font_class": "assistant-filled",
|
||||||
|
"unicode": "e847",
|
||||||
|
"unicode_decimal": 59463
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "43626126",
|
||||||
|
"name": "save",
|
||||||
|
"font_class": "save3",
|
||||||
|
"unicode": "e655",
|
||||||
|
"unicode_decimal": 58965
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "20186129",
|
||||||
|
"name": "反馈faqs",
|
||||||
|
"font_class": "fankuifaqs",
|
||||||
|
"unicode": "e7bf",
|
||||||
|
"unicode_decimal": 59327
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "42800361",
|
||||||
|
"name": "issues",
|
||||||
|
"font_class": "issues",
|
||||||
|
"unicode": "e816",
|
||||||
|
"unicode_decimal": 59414
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "8211955",
|
||||||
|
"name": "ram",
|
||||||
|
"font_class": "neicun",
|
||||||
|
"unicode": "e688",
|
||||||
|
"unicode_decimal": 59016
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "37125227",
|
||||||
|
"name": "collapse_all",
|
||||||
|
"font_class": "collapse_all",
|
||||||
|
"unicode": "e66f",
|
||||||
|
"unicode_decimal": 58991
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "43363249",
|
||||||
|
"name": "down",
|
||||||
|
"font_class": "down",
|
||||||
|
"unicode": "e654",
|
||||||
|
"unicode_decimal": 58964
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "159932",
|
||||||
|
"name": "search",
|
||||||
|
"font_class": "fenxiang",
|
||||||
|
"unicode": "e604",
|
||||||
|
"unicode_decimal": 58884
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "40678285",
|
||||||
|
"name": "mosaic",
|
||||||
|
"font_class": "mosaic-2",
|
||||||
|
"unicode": "e64f",
|
||||||
|
"unicode_decimal": 58959
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "22859935",
|
||||||
|
"name": "stars",
|
||||||
|
"font_class": "stars",
|
||||||
|
"unicode": "e8a8",
|
||||||
|
"unicode_decimal": 59560
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "39566959",
|
||||||
|
"name": "mosaic",
|
||||||
|
"font_class": "mosaic",
|
||||||
|
"unicode": "e636",
|
||||||
|
"unicode_decimal": 58934
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "43256197",
|
||||||
|
"name": "play circle",
|
||||||
|
"font_class": "outline-play",
|
||||||
|
"unicode": "e653",
|
||||||
|
"unicode_decimal": 58963
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "27116743",
|
||||||
|
"name": "SelectionInverse",
|
||||||
|
"font_class": "SelectionInverse",
|
||||||
|
"unicode": "eace",
|
||||||
|
"unicode_decimal": 60110
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "43035036",
|
||||||
|
"name": "justice",
|
||||||
|
"font_class": "justice1",
|
||||||
|
"unicode": "e652",
|
||||||
|
"unicode_decimal": 58962
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "1740853",
|
||||||
|
"name": "New_img",
|
||||||
|
"font_class": "New_img",
|
||||||
|
"unicode": "e733",
|
||||||
|
"unicode_decimal": 59187
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "9745732",
|
||||||
|
"name": "new_release_outlined",
|
||||||
|
"font_class": "new_release_outlined",
|
||||||
|
"unicode": "e66c",
|
||||||
|
"unicode_decimal": 58988
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "40667024",
|
||||||
|
"name": "new-releases",
|
||||||
|
"font_class": "new-releases",
|
||||||
|
"unicode": "e60f",
|
||||||
|
"unicode_decimal": 58895
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "41920256",
|
||||||
|
"name": "catalog",
|
||||||
|
"font_class": "catalog",
|
||||||
|
"unicode": "e62b",
|
||||||
|
"unicode_decimal": 58923
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "13851416",
|
||||||
|
"name": "save",
|
||||||
|
"font_class": "save2",
|
||||||
|
"unicode": "e635",
|
||||||
|
"unicode_decimal": 58933
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "3238366",
|
||||||
|
"name": "模板",
|
||||||
|
"font_class": "left-template",
|
||||||
|
"unicode": "e62a",
|
||||||
|
"unicode_decimal": 58922
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "26746089",
|
||||||
|
"name": "logs",
|
||||||
|
"font_class": "logs",
|
||||||
|
"unicode": "e6ec",
|
||||||
|
"unicode_decimal": 59116
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "1132892",
|
||||||
|
"name": "gpu",
|
||||||
|
"font_class": "gpu",
|
||||||
|
"unicode": "e71e",
|
||||||
|
"unicode_decimal": 59166
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "38418656",
|
||||||
|
"name": "GPUxCPU",
|
||||||
|
"font_class": "filled-gpu",
|
||||||
|
"unicode": "e6de",
|
||||||
|
"unicode_decimal": 59102
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "7556336",
|
||||||
|
"name": "gpu",
|
||||||
|
"font_class": "outline-gpu",
|
||||||
|
"unicode": "e641",
|
||||||
|
"unicode_decimal": 58945
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "8040181",
|
||||||
|
"name": "webserver",
|
||||||
|
"font_class": "ts-tubiao_webserver",
|
||||||
|
"unicode": "e716",
|
||||||
|
"unicode_decimal": 59158
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "6587064",
|
||||||
|
"name": "server",
|
||||||
|
"font_class": "server",
|
||||||
|
"unicode": "e66a",
|
||||||
|
"unicode_decimal": 58986
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "40493325",
|
||||||
|
"name": "host",
|
||||||
|
"font_class": "host",
|
||||||
|
"unicode": "e7c6",
|
||||||
|
"unicode_decimal": 59334
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "6151262",
|
||||||
|
"name": "play circle",
|
||||||
|
"font_class": "playcircle",
|
||||||
|
"unicode": "e80f",
|
||||||
|
"unicode_decimal": 59407
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "25197526",
|
||||||
|
"name": "recreate",
|
||||||
|
"font_class": "recreate",
|
||||||
|
"unicode": "e6a5",
|
||||||
|
"unicode_decimal": 59045
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "12689724",
|
||||||
|
"name": "save",
|
||||||
|
"font_class": "save1",
|
||||||
|
"unicode": "e647",
|
||||||
|
"unicode_decimal": 58951
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "15838524",
|
||||||
|
"name": "save",
|
||||||
|
"font_class": "save",
|
||||||
|
"unicode": "e67c",
|
||||||
|
"unicode_decimal": 59004
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "8782480",
|
||||||
|
"name": "upload_image",
|
||||||
|
"font_class": "upload_image",
|
||||||
|
"unicode": "e613",
|
||||||
|
"unicode_decimal": 58899
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "14464883",
|
||||||
|
"name": "sound-wave",
|
||||||
|
"font_class": "sound-wave",
|
||||||
|
"unicode": "e619",
|
||||||
|
"unicode_decimal": 58905
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "37200543",
|
||||||
|
"name": "rank",
|
||||||
|
"font_class": "rank1",
|
||||||
|
"unicode": "e7cb",
|
||||||
|
"unicode_decimal": 59339
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "5127275",
|
||||||
|
"name": "cube",
|
||||||
|
"font_class": "cube",
|
||||||
|
"unicode": "e769",
|
||||||
|
"unicode_decimal": 59241
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "28326047",
|
||||||
|
"name": "speaker-slash",
|
||||||
|
"font_class": "speaker-slash",
|
||||||
|
"unicode": "ebb6",
|
||||||
|
"unicode_decimal": 60342
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "13059398",
|
||||||
|
"name": "随机",
|
||||||
|
"font_class": "random",
|
||||||
|
"unicode": "e603",
|
||||||
|
"unicode_decimal": 58883
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "5978743",
|
||||||
|
"name": "random-forest",
|
||||||
|
"font_class": "suijisenlin",
|
||||||
|
"unicode": "e60e",
|
||||||
|
"unicode_decimal": 58894
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "15617444",
|
||||||
|
"name": "stop",
|
||||||
|
"font_class": "stop2",
|
||||||
|
"unicode": "e8db",
|
||||||
|
"unicode_decimal": 59611
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "8327181",
|
||||||
|
"name": "stop",
|
||||||
|
"font_class": "stop",
|
||||||
|
"unicode": "e60b",
|
||||||
|
"unicode_decimal": 58891
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "714031",
|
||||||
|
"name": "image",
|
||||||
|
"font_class": "image",
|
||||||
|
"unicode": "e62c",
|
||||||
|
"unicode_decimal": 58924
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "6151140",
|
||||||
|
"name": "stop circle-fill",
|
||||||
|
"font_class": "stopcircle-fill",
|
||||||
|
"unicode": "e7cc",
|
||||||
|
"unicode_decimal": 59340
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "6151141",
|
||||||
|
"name": "play circle-fill",
|
||||||
|
"font_class": "playcircle-fill",
|
||||||
|
"unicode": "e7cd",
|
||||||
|
"unicode_decimal": 59341
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "23563264",
|
||||||
|
"name": "SpeakerSlash",
|
||||||
|
"font_class": "SpeakerSlash",
|
||||||
|
"unicode": "e661",
|
||||||
|
"unicode_decimal": 58977
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "23563318",
|
||||||
|
"name": "SpeakerHigh",
|
||||||
|
"font_class": "SpeakerHigh",
|
||||||
|
"unicode": "e670",
|
||||||
|
"unicode_decimal": 58992
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "41955357",
|
||||||
|
"name": " user_voice",
|
||||||
|
"font_class": "user_voice",
|
||||||
|
"unicode": "e667",
|
||||||
|
"unicode_decimal": 58983
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "29174196",
|
||||||
|
"name": "audio",
|
||||||
|
"font_class": "audio",
|
||||||
|
"unicode": "e985",
|
||||||
|
"unicode_decimal": 59781
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "40073465",
|
||||||
|
"name": "hard-disk",
|
||||||
|
"font_class": "hard-disk",
|
||||||
|
"unicode": "eb1d",
|
||||||
|
"unicode_decimal": 60189
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "12717507",
|
||||||
|
"name": "new",
|
||||||
|
"font_class": "new",
|
||||||
|
"unicode": "e612",
|
||||||
|
"unicode_decimal": 58898
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "36135335",
|
||||||
|
"name": "mdp-template-modelscope",
|
||||||
|
"font_class": "tu2",
|
||||||
|
"unicode": "e607",
|
||||||
|
"unicode_decimal": 58887
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "10710692",
|
||||||
|
"name": "robot",
|
||||||
|
"font_class": "robot",
|
||||||
|
"unicode": "e634",
|
||||||
|
"unicode_decimal": 58932
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "12070718",
|
||||||
|
"name": "robot",
|
||||||
|
"font_class": "robot1",
|
||||||
|
"unicode": "e602",
|
||||||
|
"unicode_decimal": 58882
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "10791813",
|
||||||
|
"name": "ai智能",
|
||||||
|
"font_class": "aizhineng",
|
||||||
|
"unicode": "e672",
|
||||||
|
"unicode_decimal": 58994
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "19418384",
|
||||||
|
"name": "copy",
|
||||||
|
"font_class": "copy",
|
||||||
|
"unicode": "e720",
|
||||||
|
"unicode_decimal": 59168
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "40757798",
|
||||||
|
"name": "AI智能",
|
||||||
|
"font_class": "AIzhineng",
|
||||||
|
"unicode": "e608",
|
||||||
|
"unicode_decimal": 58888
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "36263088",
|
||||||
|
"name": "clear",
|
||||||
|
"font_class": "clear",
|
||||||
|
"unicode": "e60a",
|
||||||
|
"unicode_decimal": 58890
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "5297059",
|
||||||
|
"name": "keyboard",
|
||||||
|
"font_class": "keyboard",
|
||||||
|
"unicode": "e61b",
|
||||||
|
"unicode_decimal": 58907
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "11539157",
|
||||||
|
"name": "network error",
|
||||||
|
"font_class": "networkerror",
|
||||||
|
"unicode": "e624",
|
||||||
|
"unicode_decimal": 58916
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "14465073",
|
||||||
|
"name": "external-link",
|
||||||
|
"font_class": "external-link",
|
||||||
|
"unicode": "e66b",
|
||||||
|
"unicode_decimal": 58987
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "38465464",
|
||||||
|
"name": "huggingface",
|
||||||
|
"font_class": "huggingface",
|
||||||
|
"unicode": "e7d1",
|
||||||
|
"unicode_decimal": 59345
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "40568411",
|
||||||
|
"name": "ollama",
|
||||||
|
"font_class": "ollama",
|
||||||
|
"unicode": "e601",
|
||||||
|
"unicode_decimal": 58881
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "24341846",
|
||||||
|
"name": "layout 6-line",
|
||||||
|
"font_class": "a-layout6-line",
|
||||||
|
"unicode": "e9ef",
|
||||||
|
"unicode_decimal": 59887
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "31345353",
|
||||||
|
"name": "a-Layout5",
|
||||||
|
"font_class": "a-Layout5",
|
||||||
|
"unicode": "e610",
|
||||||
|
"unicode_decimal": 58896
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "10031665",
|
||||||
|
"name": "English",
|
||||||
|
"font_class": "English",
|
||||||
|
"unicode": "e8b3",
|
||||||
|
"unicode_decimal": 59571
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "9134244",
|
||||||
|
"name": "chinese",
|
||||||
|
"font_class": "chinese",
|
||||||
|
"unicode": "e611",
|
||||||
|
"unicode_decimal": 58897
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "12176725",
|
||||||
|
"name": "english",
|
||||||
|
"font_class": "yingguo",
|
||||||
|
"unicode": "e606",
|
||||||
|
"unicode_decimal": 58886
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "34453176",
|
||||||
|
"name": "code",
|
||||||
|
"font_class": "code",
|
||||||
|
"unicode": "e84f",
|
||||||
|
"unicode_decimal": 59471
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "12579515",
|
||||||
|
"name": "stop",
|
||||||
|
"font_class": "stop1",
|
||||||
|
"unicode": "e783",
|
||||||
|
"unicode_decimal": 59267
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"icon_id": "1842082",
|
||||||
|
"name": "command",
|
||||||
|
"font_class": "command",
|
||||||
|
"unicode": "e600",
|
||||||
|
"unicode_decimal": 58880
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,8 @@
|
|||||||
import { createFromIconfontCN } from '@ant-design/icons';
|
import { createFromIconfontCN } from '@ant-design/icons';
|
||||||
|
import './iconfont/iconfont.js';
|
||||||
|
|
||||||
const IconFont = createFromIconfontCN({
|
const IconFont = createFromIconfontCN({
|
||||||
scriptUrl: '//at.alicdn.com/t/c/font_4613488_4jkdkc8jcf7.js'
|
scriptUrl: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
export default IconFont;
|
export default IconFont;
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
/**
|
||||||
|
* Creates a canvas element and its rendering context.
|
||||||
|
* @param {number} width - Canvas width.
|
||||||
|
* @param {number} height - Canvas height.
|
||||||
|
* @returns {{ canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D }} - The created canvas and context.
|
||||||
|
*/
|
||||||
|
function createCanvas(
|
||||||
|
width: number,
|
||||||
|
height: number
|
||||||
|
): { canvas: HTMLCanvasElement; ctx: CanvasRenderingContext2D } {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
canvas.width = width;
|
||||||
|
canvas.height = height;
|
||||||
|
return { canvas, ctx: canvas.getContext('2d')! };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a pixel is white.
|
||||||
|
* @param {Uint8ClampedArray} pixels - The image pixel data.
|
||||||
|
* @param {number} x - The pixel's X coordinate.
|
||||||
|
* @param {number} y - The pixel's Y coordinate.
|
||||||
|
* @param {number} width - The image width.
|
||||||
|
* @returns {boolean} - Whether the pixel is white.
|
||||||
|
*/
|
||||||
|
function isWhite(
|
||||||
|
pixels: Uint8ClampedArray,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
width: number
|
||||||
|
): boolean {
|
||||||
|
let index = (y * width + x) * 4;
|
||||||
|
return (
|
||||||
|
pixels[index] === 255 &&
|
||||||
|
pixels[index + 1] === 255 &&
|
||||||
|
pixels[index + 2] === 255
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a flood fill to find all connected white pixels.
|
||||||
|
* @param {Uint8ClampedArray} pixels - The image pixel data.
|
||||||
|
* @param {number} width - The image width.
|
||||||
|
* @param {number} height - The image height.
|
||||||
|
* @param {number} x - The starting X coordinate.
|
||||||
|
* @param {number} y - The starting Y coordinate.
|
||||||
|
* @param {boolean[][]} visited - A 2D array to track visited pixels.
|
||||||
|
* @param {Array<{ x: number, y: number }>} block - The list of coordinates forming a white block.
|
||||||
|
*/
|
||||||
|
function floodFill(
|
||||||
|
pixels: Uint8ClampedArray,
|
||||||
|
width: number,
|
||||||
|
height: number,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
visited: boolean[][],
|
||||||
|
block: Array<{ x: number; y: number }>
|
||||||
|
): void {
|
||||||
|
let stack: Array<[number, number]> = [[x, y]];
|
||||||
|
let directions: Array<[number, number]> = [
|
||||||
|
[1, 0],
|
||||||
|
[-1, 0],
|
||||||
|
[0, 1],
|
||||||
|
[0, -1], // 4-directional search (can be extended to 8-directional)
|
||||||
|
[1, 1],
|
||||||
|
[-1, -1],
|
||||||
|
[1, -1],
|
||||||
|
[-1, 1] // Diagonal directions
|
||||||
|
];
|
||||||
|
|
||||||
|
while (stack.length) {
|
||||||
|
let [cx, cy] = stack.pop()!;
|
||||||
|
if (
|
||||||
|
cx < 0 ||
|
||||||
|
cy < 0 ||
|
||||||
|
cx >= width ||
|
||||||
|
cy >= height ||
|
||||||
|
visited[cy][cx] ||
|
||||||
|
!isWhite(pixels, cx, cy, width)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
visited[cy][cx] = true;
|
||||||
|
block.push({ x: cx, y: cy });
|
||||||
|
|
||||||
|
directions.forEach(([dx, dy]) => stack.push([cx + dx, cy + dy]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts all white blocks from an image.
|
||||||
|
* @param {ImageData} imageData - The image pixel data.
|
||||||
|
* @returns {Array<Array<{ x: number, y: number }>>} - List of white blocks, each containing pixel coordinates.
|
||||||
|
*/
|
||||||
|
function getWhiteBlocks(
|
||||||
|
imageData: ImageData
|
||||||
|
): Array<Array<{ x: number; y: number }>> {
|
||||||
|
const { data, width, height } = imageData;
|
||||||
|
let visited: boolean[][] = Array.from({ length: height }, () =>
|
||||||
|
new Array(width).fill(false)
|
||||||
|
);
|
||||||
|
let whiteBlocks: Array<Array<{ x: number; y: number }>> = [];
|
||||||
|
|
||||||
|
for (let y = 0; y < height; y++) {
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
if (isWhite(data, x, y, width) && !visited[y][x]) {
|
||||||
|
let block: Array<{ x: number; y: number }> = [];
|
||||||
|
floodFill(data, width, height, x, y, visited, block);
|
||||||
|
whiteBlocks.push(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return whiteBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads an image from a file.
|
||||||
|
* @param {File} file - The image file.
|
||||||
|
* @returns {Promise<HTMLImageElement>} - The loaded image element.
|
||||||
|
*/
|
||||||
|
function loadImage(file: string): Promise<HTMLImageElement> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const img = new Image();
|
||||||
|
img.src = file;
|
||||||
|
img.onload = () => resolve(img);
|
||||||
|
img.onerror = () => reject(new Error('Image loading failed'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the image file and extracts white blocks.
|
||||||
|
* @param {File} file - The uploaded image file.
|
||||||
|
* @returns {Promise<Array<Array<{ x: number, y: number }>>>} - List of white blocks with pixel coordinates.
|
||||||
|
*/
|
||||||
|
async function processImage(
|
||||||
|
file: string
|
||||||
|
): Promise<Array<Array<{ x: number; y: number }>>> {
|
||||||
|
const img = await loadImage(file);
|
||||||
|
const { canvas, ctx } = createCanvas(img.width, img.height);
|
||||||
|
ctx.drawImage(img, 0, 0);
|
||||||
|
|
||||||
|
const imageData = ctx.getImageData(0, 0, img.width, img.height);
|
||||||
|
const whiteBlocks = getWhiteBlocks(imageData);
|
||||||
|
|
||||||
|
URL.revokeObjectURL(img.src);
|
||||||
|
return whiteBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { processImage };
|
||||||
@@ -0,0 +1,437 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import React, { useCallback, useMemo, useRef } from 'react';
|
||||||
|
|
||||||
|
type Point = { x: number; y: number; lineWidth: number };
|
||||||
|
type Stroke = Point[];
|
||||||
|
const COLOR = 'rgba(0, 0, 255, 0.3)';
|
||||||
|
|
||||||
|
export default function useDrawing(props: {
|
||||||
|
isDisabled?: boolean;
|
||||||
|
invertMask: boolean;
|
||||||
|
maskUpload?: any[];
|
||||||
|
lineWidth: number;
|
||||||
|
translatePos: { current: { x: number; y: number } };
|
||||||
|
onSave: (imageData: { mask: string | null; img: string }) => void;
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
isDisabled,
|
||||||
|
invertMask,
|
||||||
|
maskUpload,
|
||||||
|
lineWidth,
|
||||||
|
translatePos,
|
||||||
|
onSave
|
||||||
|
} = props;
|
||||||
|
const mouseDownState = useRef<boolean>(false);
|
||||||
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
|
const overlayCanvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
|
const offscreenCanvasRef = useRef<any>(null);
|
||||||
|
const currentStroke = useRef<Point[]>([]);
|
||||||
|
const strokesRef = useRef<Stroke[]>([]);
|
||||||
|
const isDrawing = useRef<boolean>(false);
|
||||||
|
const cursorRef = useRef<HTMLDivElement>(null);
|
||||||
|
const autoScale = useRef<number>(1);
|
||||||
|
const baseScale = useRef<number>(1);
|
||||||
|
const contentPos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
||||||
|
const maskStorkeRef = useRef<Stroke[]>([]);
|
||||||
|
const isLoadingMaskRef = useRef<boolean>(false);
|
||||||
|
|
||||||
|
const disabled = useMemo(() => {
|
||||||
|
return isDisabled || invertMask || !!maskUpload?.length;
|
||||||
|
}, [isDisabled, invertMask, maskUpload]);
|
||||||
|
|
||||||
|
const setStrokes = (strokes: Stroke[]) => {
|
||||||
|
strokesRef.current = strokes;
|
||||||
|
};
|
||||||
|
|
||||||
|
const setMaskStrokes = (strokes: Stroke[]) => {
|
||||||
|
maskStorkeRef.current = strokes;
|
||||||
|
};
|
||||||
|
|
||||||
|
const inpaintArea = useCallback(
|
||||||
|
(data: Uint8ClampedArray<ArrayBufferLike>) => {
|
||||||
|
for (let i = 0; i < data.length; i += 4) {
|
||||||
|
const alpha = data[i + 3];
|
||||||
|
if (alpha > 0) {
|
||||||
|
data[i] = 255; // Red
|
||||||
|
data[i + 1] = 255; // Green
|
||||||
|
data[i + 2] = 255; // Blue
|
||||||
|
data[i + 3] = 255; // Alpha
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const generateImage = useCallback(() => {
|
||||||
|
const canvas = canvasRef.current!;
|
||||||
|
return canvas.toDataURL('image/png');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const generateMask = useCallback(() => {
|
||||||
|
if (strokesRef.current.length === 0 && maskStorkeRef.current.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const overlayCanvas = overlayCanvasRef.current!;
|
||||||
|
const maskCanvas = document.createElement('canvas');
|
||||||
|
maskCanvas.width = overlayCanvas.width;
|
||||||
|
maskCanvas.height = overlayCanvas.height;
|
||||||
|
const maskCtx = maskCanvas.getContext('2d')!;
|
||||||
|
const overlayCtx = overlayCanvas.getContext('2d')!;
|
||||||
|
|
||||||
|
const imageData = overlayCtx.getImageData(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
overlayCanvas.width,
|
||||||
|
overlayCanvas.height
|
||||||
|
);
|
||||||
|
const data = imageData.data;
|
||||||
|
|
||||||
|
inpaintArea(data);
|
||||||
|
|
||||||
|
maskCtx.putImageData(imageData, 0, 0);
|
||||||
|
|
||||||
|
maskCtx.globalCompositeOperation = 'destination-over';
|
||||||
|
maskCtx.fillStyle = 'black';
|
||||||
|
maskCtx.fillRect(0, 0, maskCanvas.width, maskCanvas.height);
|
||||||
|
|
||||||
|
return maskCanvas.toDataURL('image/png');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const saveImage = () => {
|
||||||
|
const mask = generateMask();
|
||||||
|
const img = generateImage();
|
||||||
|
onSave({ mask, img });
|
||||||
|
};
|
||||||
|
|
||||||
|
const creatOffscreenCanvas = useCallback(() => {
|
||||||
|
if (!offscreenCanvasRef.current) {
|
||||||
|
offscreenCanvasRef.current = document.createElement('canvas');
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const setTransform = useCallback(() => {
|
||||||
|
creatOffscreenCanvas();
|
||||||
|
const ctx = canvasRef.current?.getContext('2d');
|
||||||
|
const overlayCtx = overlayCanvasRef.current?.getContext('2d');
|
||||||
|
const offCtx = offscreenCanvasRef.current?.getContext('2d');
|
||||||
|
|
||||||
|
if (!ctx || !overlayCtx) return;
|
||||||
|
|
||||||
|
ctx!.resetTransform();
|
||||||
|
overlayCtx!.resetTransform();
|
||||||
|
offCtx!.resetTransform();
|
||||||
|
|
||||||
|
const { current: scale } = autoScale;
|
||||||
|
const { x: translateX, y: translateY } = translatePos.current;
|
||||||
|
ctx!.setTransform(scale, 0, 0, scale, translateX, translateY);
|
||||||
|
overlayCtx!.setTransform(scale, 0, 0, scale, translateX, translateY);
|
||||||
|
offCtx!.setTransform(scale, 0, 0, scale, translateX, translateY);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getTransformedPoint = (offsetX: number, offsetY: number) => {
|
||||||
|
const { current: scale } = autoScale;
|
||||||
|
console.log('lineWidth:----------', lineWidth, autoScale.current);
|
||||||
|
|
||||||
|
const { x: translateX, y: translateY } = translatePos.current;
|
||||||
|
|
||||||
|
const transformedX = (offsetX - translateX) / scale;
|
||||||
|
const transformedY = (offsetY - translateY) / scale;
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: transformedX,
|
||||||
|
y: transformedY
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTransformLineWidth = (w = 1) => {
|
||||||
|
console.log('lineWidth:', lineWidth, autoScale.current);
|
||||||
|
const width = w || lineWidth;
|
||||||
|
return width / autoScale.current;
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawLine = useCallback(
|
||||||
|
(
|
||||||
|
ctx: CanvasRenderingContext2D,
|
||||||
|
point: Point,
|
||||||
|
options: {
|
||||||
|
lineWidth: number;
|
||||||
|
color: string;
|
||||||
|
compositeOperation: 'source-over' | 'destination-out';
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
const { lineWidth, color, compositeOperation } = options;
|
||||||
|
|
||||||
|
ctx.lineWidth = getTransformLineWidth(lineWidth);
|
||||||
|
ctx.lineCap = 'round';
|
||||||
|
ctx.lineJoin = 'round';
|
||||||
|
ctx.globalCompositeOperation = compositeOperation;
|
||||||
|
|
||||||
|
const { x, y } = getTransformedPoint(point.x, point.y);
|
||||||
|
|
||||||
|
ctx.lineTo(x, y);
|
||||||
|
if (compositeOperation === 'source-over') {
|
||||||
|
ctx.strokeStyle = color;
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
},
|
||||||
|
[getTransformLineWidth]
|
||||||
|
);
|
||||||
|
|
||||||
|
const drawStroke = useCallback(
|
||||||
|
(
|
||||||
|
ctx: CanvasRenderingContext2D,
|
||||||
|
stroke: Stroke | Point[],
|
||||||
|
options: {
|
||||||
|
lineWidth?: number;
|
||||||
|
color: string;
|
||||||
|
compositeOperation: 'source-over' | 'destination-out';
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
const { color, compositeOperation } = options;
|
||||||
|
ctx.lineCap = 'round';
|
||||||
|
ctx.lineJoin = 'round';
|
||||||
|
ctx.globalCompositeOperation = compositeOperation;
|
||||||
|
ctx.save();
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
|
||||||
|
stroke.forEach((point, i) => {
|
||||||
|
const { x, y } = getTransformedPoint(point.x, point.y);
|
||||||
|
ctx.lineWidth = getTransformLineWidth(point.lineWidth);
|
||||||
|
if (i === 0) {
|
||||||
|
ctx.moveTo(x, y);
|
||||||
|
} else {
|
||||||
|
ctx.lineTo(x, y);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (compositeOperation === 'source-over') {
|
||||||
|
ctx.strokeStyle = color;
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.restore();
|
||||||
|
},
|
||||||
|
[getTransformLineWidth, getTransformedPoint]
|
||||||
|
);
|
||||||
|
|
||||||
|
const draw = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
'Drawing:',
|
||||||
|
isDrawing.current,
|
||||||
|
currentStroke.current,
|
||||||
|
strokesRef.current
|
||||||
|
);
|
||||||
|
if (!isDrawing.current || !mouseDownState.current) return;
|
||||||
|
|
||||||
|
const { offsetX, offsetY } = e.nativeEvent;
|
||||||
|
const currentX = offsetX;
|
||||||
|
const currentY = offsetY;
|
||||||
|
console.log('currentStroke:', currentStroke.current);
|
||||||
|
currentStroke.current.push({
|
||||||
|
x: currentX,
|
||||||
|
y: currentY,
|
||||||
|
lineWidth
|
||||||
|
});
|
||||||
|
|
||||||
|
const ctx = overlayCanvasRef.current!.getContext('2d');
|
||||||
|
|
||||||
|
ctx!.save();
|
||||||
|
|
||||||
|
drawLine(
|
||||||
|
ctx!,
|
||||||
|
{ x: currentX, y: currentY, lineWidth },
|
||||||
|
{ lineWidth, color: COLOR, compositeOperation: 'destination-out' }
|
||||||
|
);
|
||||||
|
drawLine(
|
||||||
|
ctx!,
|
||||||
|
{ x: currentX, y: currentY, lineWidth },
|
||||||
|
{ lineWidth, color: COLOR, compositeOperation: 'source-over' }
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx!.restore();
|
||||||
|
};
|
||||||
|
|
||||||
|
const startDrawing = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isDrawing.current = true;
|
||||||
|
|
||||||
|
currentStroke.current = [];
|
||||||
|
const { offsetX, offsetY } = e.nativeEvent;
|
||||||
|
|
||||||
|
const currentX = offsetX;
|
||||||
|
const currentY = offsetY;
|
||||||
|
|
||||||
|
currentStroke.current.push({
|
||||||
|
x: currentX,
|
||||||
|
y: currentY,
|
||||||
|
lineWidth
|
||||||
|
});
|
||||||
|
|
||||||
|
const ctx = overlayCanvasRef.current!.getContext('2d');
|
||||||
|
setTransform();
|
||||||
|
const { x, y } = getTransformedPoint(currentX, currentY);
|
||||||
|
ctx!.beginPath();
|
||||||
|
ctx!.moveTo(x, y);
|
||||||
|
|
||||||
|
draw(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
const endDrawing = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isDrawing.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('End Drawing:', e);
|
||||||
|
|
||||||
|
isDrawing.current = false;
|
||||||
|
|
||||||
|
strokesRef.current.push(_.cloneDeep(currentStroke.current));
|
||||||
|
|
||||||
|
currentStroke.current = [];
|
||||||
|
|
||||||
|
saveImage();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseMove = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
overlayCanvasRef.current!.style.cursor = 'none';
|
||||||
|
cursorRef.current!.style.display = 'block';
|
||||||
|
cursorRef.current!.style.top = `${e.clientY - (lineWidth / 2) * autoScale.current}px`;
|
||||||
|
cursorRef.current!.style.left = `${e.clientX - (lineWidth / 2) * autoScale.current}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseLeave = () => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isDrawing.current = false;
|
||||||
|
overlayCanvasRef.current!.style.cursor = 'default';
|
||||||
|
cursorRef.current!.style.display = 'none';
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseEnter = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
|
console.log('mouse enter:', mouseDownState.current);
|
||||||
|
if (disabled) {
|
||||||
|
overlayCanvasRef.current!.style.cursor = 'default';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// if (mouseDownState.current) {
|
||||||
|
// isDrawing.current = true;
|
||||||
|
// }
|
||||||
|
overlayCanvasRef.current!.style.cursor = 'none';
|
||||||
|
cursorRef.current!.style.display = 'block';
|
||||||
|
cursorRef.current!.style.top = `${e.clientY - (lineWidth / 2) * autoScale.current}px`;
|
||||||
|
cursorRef.current!.style.left = `${e.clientX - (lineWidth / 2) * autoScale.current}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearOverlayCanvas = useCallback(() => {
|
||||||
|
const ctx = overlayCanvasRef.current!.getContext('2d');
|
||||||
|
const offCtx = offscreenCanvasRef.current?.getContext('2d');
|
||||||
|
|
||||||
|
offCtx!.resetTransform();
|
||||||
|
ctx!.resetTransform();
|
||||||
|
ctx!.clearRect(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
overlayCanvasRef.current!.width,
|
||||||
|
overlayCanvasRef.current!.height
|
||||||
|
);
|
||||||
|
offCtx!.clearRect(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
overlayCanvasRef.current!.width,
|
||||||
|
overlayCanvasRef.current!.height
|
||||||
|
);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const clearCanvas = useCallback(() => {
|
||||||
|
const canvas = canvasRef.current!;
|
||||||
|
const ctx = canvasRef.current!.getContext('2d');
|
||||||
|
const offCtx = offscreenCanvasRef.current?.getContext('2d');
|
||||||
|
ctx!.resetTransform();
|
||||||
|
ctx!.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
offCtx!.resetTransform();
|
||||||
|
offCtx!.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const resetCanvas = useCallback(() => {
|
||||||
|
const canvas = canvasRef.current!;
|
||||||
|
const overlayCanvas = overlayCanvasRef.current!;
|
||||||
|
const offscreenCanvas = offscreenCanvasRef.current!;
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
const overlayCtx = overlayCanvas.getContext('2d');
|
||||||
|
const offCtx = offscreenCanvasRef.current?.getContext('2d');
|
||||||
|
|
||||||
|
autoScale.current = 1;
|
||||||
|
baseScale.current = 1;
|
||||||
|
translatePos.current = { x: 0, y: 0 };
|
||||||
|
contentPos.current = { x: 0, y: 0 };
|
||||||
|
|
||||||
|
canvas.style.transform = 'scale(1)';
|
||||||
|
overlayCanvas.style.transform = 'scale(1)';
|
||||||
|
offscreenCanvas.style.transform = 'scale(1)';
|
||||||
|
|
||||||
|
cursorRef.current!.style.width = `${lineWidth}px`;
|
||||||
|
cursorRef.current!.style.height = `${lineWidth}px`;
|
||||||
|
|
||||||
|
ctx!.resetTransform();
|
||||||
|
overlayCtx!.resetTransform();
|
||||||
|
offCtx!.resetTransform();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const fitView = () => {
|
||||||
|
resetCanvas();
|
||||||
|
autoScale.current = baseScale.current;
|
||||||
|
translatePos.current = { x: 0, y: 0 };
|
||||||
|
setTransform();
|
||||||
|
overlayCanvasRef.current!.style.transform = `scale(${autoScale.current})`;
|
||||||
|
canvasRef.current!.style.transform = `scale(${autoScale.current})`;
|
||||||
|
offscreenCanvasRef.current!.style.transform = `scale(${autoScale.current})`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
canvasRef,
|
||||||
|
overlayCanvasRef,
|
||||||
|
offscreenCanvasRef,
|
||||||
|
cursorRef,
|
||||||
|
strokesRef,
|
||||||
|
currentStroke,
|
||||||
|
isDrawing,
|
||||||
|
mouseDownState,
|
||||||
|
autoScale,
|
||||||
|
baseScale,
|
||||||
|
maskStorkeRef,
|
||||||
|
isLoadingMaskRef,
|
||||||
|
creatOffscreenCanvas,
|
||||||
|
setMaskStrokes,
|
||||||
|
fitView,
|
||||||
|
setStrokes,
|
||||||
|
resetCanvas,
|
||||||
|
draw,
|
||||||
|
getTransformLineWidth,
|
||||||
|
getTransformedPoint,
|
||||||
|
drawStroke,
|
||||||
|
startDrawing,
|
||||||
|
endDrawing,
|
||||||
|
handleMouseMove,
|
||||||
|
handleMouseLeave,
|
||||||
|
handleMouseEnter,
|
||||||
|
saveImage,
|
||||||
|
generateMask,
|
||||||
|
generateImage,
|
||||||
|
setTransform,
|
||||||
|
clearOverlayCanvas,
|
||||||
|
clearCanvas
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import React, { MutableRefObject, useState } from 'react';
|
||||||
|
|
||||||
|
export default function useZoom(props: {
|
||||||
|
overlayCanvasRef: any;
|
||||||
|
canvasRef: any;
|
||||||
|
offscreenCanvasRef: any;
|
||||||
|
cursorRef: any;
|
||||||
|
lineWidth: number;
|
||||||
|
autoScale: MutableRefObject<number>;
|
||||||
|
baseScale: MutableRefObject<number>;
|
||||||
|
translatePos: MutableRefObject<{ x: number; y: number }>;
|
||||||
|
isLoadingMaskRef: MutableRefObject<boolean>;
|
||||||
|
}) {
|
||||||
|
const MIN_SCALE = 0.2;
|
||||||
|
const MAX_SCALE = 8;
|
||||||
|
const ZOOM_SPEED = 0.1;
|
||||||
|
const {
|
||||||
|
overlayCanvasRef,
|
||||||
|
canvasRef,
|
||||||
|
offscreenCanvasRef,
|
||||||
|
cursorRef,
|
||||||
|
lineWidth,
|
||||||
|
translatePos,
|
||||||
|
autoScale,
|
||||||
|
baseScale,
|
||||||
|
isLoadingMaskRef
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const [activeScale, setActiveScale] = useState<number>(1);
|
||||||
|
|
||||||
|
const setCanvasTransformOrigin = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
|
if (autoScale.current <= MIN_SCALE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (autoScale.current >= MAX_SCALE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rect = overlayCanvasRef.current!.getBoundingClientRect();
|
||||||
|
const mouseX = e.clientX - rect.left;
|
||||||
|
const mouseY = e.clientY - rect.top;
|
||||||
|
|
||||||
|
const originX = mouseX / rect.width;
|
||||||
|
const originY = mouseY / rect.height;
|
||||||
|
|
||||||
|
overlayCanvasRef.current!.style.transformOrigin = `${originX * 100}% ${originY * 100}%`;
|
||||||
|
canvasRef.current!.style.transformOrigin = `${originX * 100}% ${originY * 100}%`;
|
||||||
|
offscreenCanvasRef.current!.style.transformOrigin = `${originX * 100}% ${originY * 100}%`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateZoom = (scaleChange: number, mouseX: number, mouseY: number) => {
|
||||||
|
const newScale = _.round(autoScale.current + scaleChange, 2);
|
||||||
|
|
||||||
|
if (newScale < MIN_SCALE || newScale > MAX_SCALE) return;
|
||||||
|
|
||||||
|
const { current: oldScale } = autoScale;
|
||||||
|
const { x: oldTranslateX, y: oldTranslateY } = translatePos.current;
|
||||||
|
|
||||||
|
const centerX = (mouseX - oldTranslateX) / oldScale;
|
||||||
|
const centerY = (mouseY - oldTranslateY) / oldScale;
|
||||||
|
|
||||||
|
autoScale.current = newScale;
|
||||||
|
|
||||||
|
const newTranslateX = mouseX - centerX * newScale;
|
||||||
|
const newTranslateY = mouseY - centerY * newScale;
|
||||||
|
|
||||||
|
translatePos.current = { x: newTranslateX, y: newTranslateY };
|
||||||
|
};
|
||||||
|
|
||||||
|
const applyCanvasTransform = () => {
|
||||||
|
const scale = autoScale.current;
|
||||||
|
const transform = `scale(${scale})`;
|
||||||
|
|
||||||
|
overlayCanvasRef.current!.style.transform = transform;
|
||||||
|
canvasRef.current!.style.transform = transform;
|
||||||
|
offscreenCanvasRef.current!.style.transform = transform;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleZoom = (event: React.WheelEvent<HTMLCanvasElement>) => {
|
||||||
|
const scaleChange = event.deltaY > 0 ? -ZOOM_SPEED : ZOOM_SPEED;
|
||||||
|
|
||||||
|
// current mouse position
|
||||||
|
const canvas = overlayCanvasRef.current!;
|
||||||
|
const rect = canvas.getBoundingClientRect();
|
||||||
|
|
||||||
|
const mouseX = event.clientX - rect.left;
|
||||||
|
const mouseY = event.clientY - rect.top;
|
||||||
|
applyCanvasTransform();
|
||||||
|
|
||||||
|
setCanvasTransformOrigin(event);
|
||||||
|
updateZoom(scaleChange, mouseX, mouseY);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateCursorSize = () => {
|
||||||
|
cursorRef.current!.style.width = `${lineWidth * autoScale.current}px`;
|
||||||
|
cursorRef.current!.style.height = `${lineWidth * autoScale.current}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateCursorPosOnZoom = (e: any) => {
|
||||||
|
cursorRef.current!.style.top = `${e.clientY - (lineWidth / 2) * autoScale.current}px`;
|
||||||
|
cursorRef.current!.style.left = `${e.clientX - (lineWidth / 2) * autoScale.current}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnWheel = (event: any) => {
|
||||||
|
if (isLoadingMaskRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
// stop
|
||||||
|
handleZoom(event);
|
||||||
|
updateCursorSize();
|
||||||
|
updateCursorPosOnZoom(event);
|
||||||
|
setActiveScale(autoScale.current);
|
||||||
|
};
|
||||||
|
|
||||||
|
const throttleHandleOnWheel = _.throttle((event: any) => {
|
||||||
|
handleOnWheel(event);
|
||||||
|
}, 16);
|
||||||
|
|
||||||
|
return {
|
||||||
|
handleOnWheel: handleOnWheel,
|
||||||
|
setActiveScale,
|
||||||
|
activeScale,
|
||||||
|
autoScale,
|
||||||
|
baseScale
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
.editor-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
.tools {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-content {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.overlay-canvas:hover {
|
||||||
|
cursor: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.overlay-canvas.overlay-canvas--disabled:hover {
|
||||||
|
cursor: default !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-mask {
|
||||||
|
&:hover {
|
||||||
|
.close-btn {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,636 @@
|
|||||||
|
import { Spin } from 'antd';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import React, {
|
||||||
|
forwardRef,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState
|
||||||
|
} from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import useDrawing from './hooks/use-drawing';
|
||||||
|
import useZoom from './hooks/use-zoom';
|
||||||
|
import './index.less';
|
||||||
|
import { ImageActionsBar, ToolsBar } from './tools-bar';
|
||||||
|
|
||||||
|
const LoadWrapper = styled.div<{ width?: number; height?: number }>`
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100%;
|
||||||
|
width: ${(props) => `${props.width}px` || '100%'};
|
||||||
|
z-index: 100;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Loading = (props: { width: number; height: number }) => {
|
||||||
|
const { width, height } = props;
|
||||||
|
return (
|
||||||
|
<LoadWrapper width={width} height={height}>
|
||||||
|
<Spin spinning></Spin>
|
||||||
|
</LoadWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
type Point = { x: number; y: number; lineWidth: number };
|
||||||
|
type Stroke = Point[];
|
||||||
|
|
||||||
|
type CanvasImageEditorProps = {
|
||||||
|
ref?: any;
|
||||||
|
loading: boolean;
|
||||||
|
imageSrc: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
imguid: string | number;
|
||||||
|
maskUpload?: any[];
|
||||||
|
clearUploadMask?: () => void;
|
||||||
|
onSave: (imageData: { mask: string | null; img: string }) => void;
|
||||||
|
onScaleImageSize?: (data: { width: number; height: number }) => void;
|
||||||
|
handleUpdateImageList: (fileList: any[]) => void;
|
||||||
|
handleUpdateMaskList: (fileList: any[]) => void;
|
||||||
|
uploadButton?: React.ReactNode;
|
||||||
|
accept?: string;
|
||||||
|
imageStatus: {
|
||||||
|
isOriginal: boolean;
|
||||||
|
isResetNeeded: boolean;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const COLOR = 'rgba(0, 0, 255, 0.3)';
|
||||||
|
|
||||||
|
const CanvasImageEditor: React.FC<CanvasImageEditorProps> = forwardRef(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
loading,
|
||||||
|
imageSrc,
|
||||||
|
disabled: isDisabled,
|
||||||
|
imageStatus,
|
||||||
|
maskUpload,
|
||||||
|
accept,
|
||||||
|
onSave,
|
||||||
|
onScaleImageSize,
|
||||||
|
handleUpdateImageList,
|
||||||
|
handleUpdateMaskList
|
||||||
|
},
|
||||||
|
ref
|
||||||
|
) => {
|
||||||
|
const invertWorkerRef = useRef<any>(null);
|
||||||
|
const loadMaksWorkerRef = useRef<any>(null);
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const [lineWidth, setLineWidth] = useState<number>(60);
|
||||||
|
const translatePos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
||||||
|
const negativeMaskRef = useRef<boolean>(false);
|
||||||
|
const [invertMask, setInvertMask] = useState<boolean>(false);
|
||||||
|
const timer = useRef<any>(null);
|
||||||
|
const [loadingSize, setLoadingSize] = useState({
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
loading: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
canvasRef,
|
||||||
|
overlayCanvasRef,
|
||||||
|
offscreenCanvasRef,
|
||||||
|
cursorRef,
|
||||||
|
strokesRef,
|
||||||
|
currentStroke,
|
||||||
|
mouseDownState,
|
||||||
|
autoScale,
|
||||||
|
baseScale,
|
||||||
|
maskStorkeRef,
|
||||||
|
isLoadingMaskRef,
|
||||||
|
setMaskStrokes,
|
||||||
|
draw,
|
||||||
|
drawStroke,
|
||||||
|
startDrawing,
|
||||||
|
endDrawing,
|
||||||
|
handleMouseMove,
|
||||||
|
handleMouseLeave,
|
||||||
|
handleMouseEnter,
|
||||||
|
saveImage,
|
||||||
|
resetCanvas,
|
||||||
|
creatOffscreenCanvas,
|
||||||
|
generateMask,
|
||||||
|
getTransformLineWidth,
|
||||||
|
getTransformedPoint,
|
||||||
|
setStrokes,
|
||||||
|
setTransform,
|
||||||
|
clearOverlayCanvas,
|
||||||
|
clearCanvas,
|
||||||
|
fitView
|
||||||
|
} = useDrawing({
|
||||||
|
lineWidth: lineWidth,
|
||||||
|
translatePos: translatePos,
|
||||||
|
isDisabled: isDisabled,
|
||||||
|
invertMask,
|
||||||
|
maskUpload,
|
||||||
|
onSave: onSave
|
||||||
|
});
|
||||||
|
|
||||||
|
const { handleOnWheel, setActiveScale, activeScale } = useZoom({
|
||||||
|
overlayCanvasRef,
|
||||||
|
canvasRef,
|
||||||
|
offscreenCanvasRef,
|
||||||
|
cursorRef,
|
||||||
|
lineWidth,
|
||||||
|
translatePos,
|
||||||
|
autoScale,
|
||||||
|
baseScale,
|
||||||
|
isLoadingMaskRef
|
||||||
|
});
|
||||||
|
|
||||||
|
const disabled = useMemo(() => {
|
||||||
|
return isDisabled || invertMask || !!maskUpload?.length;
|
||||||
|
}, [isDisabled, invertMask, maskUpload]);
|
||||||
|
|
||||||
|
// update the canvas size
|
||||||
|
const updateCanvasSize = useCallback(() => {
|
||||||
|
const canvas = canvasRef.current!;
|
||||||
|
const overlayCanvas = overlayCanvasRef.current!;
|
||||||
|
const offscreenCanvas = offscreenCanvasRef.current!;
|
||||||
|
|
||||||
|
overlayCanvas.width = canvas.width;
|
||||||
|
overlayCanvas.height = canvas.height;
|
||||||
|
offscreenCanvas.width = canvas.width;
|
||||||
|
offscreenCanvas.height = canvas.height;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const downloadMask = useCallback(() => {
|
||||||
|
const mask = generateMask();
|
||||||
|
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.download = `mask_${dayjs().format('YYYYMMDDHHmmss')}.png`;
|
||||||
|
link.href = mask || '';
|
||||||
|
link.click();
|
||||||
|
}, [generateMask]);
|
||||||
|
|
||||||
|
const onReset = useCallback(() => {
|
||||||
|
clearOverlayCanvas();
|
||||||
|
setStrokes([]);
|
||||||
|
setMaskStrokes([]);
|
||||||
|
saveImage();
|
||||||
|
currentStroke.current = [];
|
||||||
|
console.log('Resetting strokes', currentStroke.current);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const loadMaskPixs = (maskStrokes: Stroke[], mainStrokes?: Stroke[]) => {
|
||||||
|
try {
|
||||||
|
if (!maskStrokes.length && !mainStrokes?.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoadingMaskRef.current = true;
|
||||||
|
|
||||||
|
const offscreenCanvas = new OffscreenCanvas(
|
||||||
|
overlayCanvasRef.current!.width,
|
||||||
|
overlayCanvasRef.current!.height
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!loadMaksWorkerRef.current) {
|
||||||
|
loadMaksWorkerRef.current = new Worker(
|
||||||
|
new URL('./offscreen-worker.ts', import.meta.url),
|
||||||
|
{
|
||||||
|
type: 'module'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadMaksWorkerRef.current!.onmessage = (event: any) => {
|
||||||
|
if (event.data.type === 'done' && event.data.imageData) {
|
||||||
|
console.log('load mask done');
|
||||||
|
// draw the data to the overlay canvas
|
||||||
|
const ctx = overlayCanvasRef.current!.getContext('2d')!;
|
||||||
|
ctx.putImageData(event.data.imageData, 0, 0);
|
||||||
|
|
||||||
|
isLoadingMaskRef.current = false;
|
||||||
|
saveImage();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// send offscreen canvas to worker
|
||||||
|
loadMaksWorkerRef.current?.postMessage(
|
||||||
|
{ canvas: offscreenCanvas, type: 'init' },
|
||||||
|
[offscreenCanvas]
|
||||||
|
);
|
||||||
|
|
||||||
|
// send draw data to worker
|
||||||
|
loadMaksWorkerRef.current?.postMessage({
|
||||||
|
type: 'draw',
|
||||||
|
maskStrokes: maskStrokes,
|
||||||
|
strokes: mainStrokes || []
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('error---', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const redrawStrokes = async (strokes: Stroke[]) => {
|
||||||
|
if (!strokes.length && !maskStorkeRef.current.length) {
|
||||||
|
clearOverlayCanvas();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadMaskPixs(maskStorkeRef.current, strokes);
|
||||||
|
};
|
||||||
|
|
||||||
|
const undo = useCallback(() => {
|
||||||
|
if (
|
||||||
|
strokesRef.current.length === 0 &&
|
||||||
|
maskStorkeRef.current.length === 0
|
||||||
|
) {
|
||||||
|
clearOverlayCanvas();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastlength = strokesRef.current.length;
|
||||||
|
|
||||||
|
const newStrokes = strokesRef.current.slice(0, -1);
|
||||||
|
setStrokes(newStrokes);
|
||||||
|
|
||||||
|
if (
|
||||||
|
!newStrokes.length &&
|
||||||
|
lastlength === 0 &&
|
||||||
|
maskStorkeRef.current.length
|
||||||
|
) {
|
||||||
|
setMaskStrokes([]);
|
||||||
|
}
|
||||||
|
clearTimeout(timer.current);
|
||||||
|
timer.current = setTimeout(() => {
|
||||||
|
redrawStrokes(newStrokes);
|
||||||
|
}, 100);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const downloadOriginImage = () => {
|
||||||
|
const canvas = canvasRef.current!;
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.download = `image_${dayjs().format('YYYYMMDDHHmmss')}.png`;
|
||||||
|
link.href = canvas.toDataURL('image/png');
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
};
|
||||||
|
|
||||||
|
const downloadNewImage = () => {
|
||||||
|
if (!imageSrc) return;
|
||||||
|
|
||||||
|
const img = new Image();
|
||||||
|
img.src = imageSrc;
|
||||||
|
img.onload = () => {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
canvas.width = imageStatus.width;
|
||||||
|
canvas.height = imageStatus.height;
|
||||||
|
|
||||||
|
const ctx = canvas.getContext('2d')!;
|
||||||
|
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
const url = canvas.toDataURL('image/png');
|
||||||
|
const filename = `${canvas.width}x${canvas.height}_${dayjs().format('YYYYMMDDHHmmss')}.png`;
|
||||||
|
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = filename;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const download = () => {
|
||||||
|
if (imageStatus.isOriginal) {
|
||||||
|
downloadOriginImage();
|
||||||
|
} else {
|
||||||
|
downloadNewImage();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawImage = useCallback(async () => {
|
||||||
|
if (!containerRef.current || !canvasRef.current) return;
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
const img = new Image();
|
||||||
|
img.src = imageSrc;
|
||||||
|
img.onload = () => {
|
||||||
|
const canvas = canvasRef.current!;
|
||||||
|
const ctx = canvas!.getContext('2d');
|
||||||
|
const container = containerRef.current;
|
||||||
|
baseScale.current = Math.min(
|
||||||
|
container!.offsetWidth / img.width,
|
||||||
|
container!.offsetHeight / img.height,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
// if need to fit the image to the container, show * baseScale.current
|
||||||
|
canvas!.width = img.width;
|
||||||
|
canvas!.height = img.height;
|
||||||
|
|
||||||
|
// fit the image to the container
|
||||||
|
autoScale.current = 1;
|
||||||
|
creatOffscreenCanvas();
|
||||||
|
updateCanvasSize();
|
||||||
|
clearCanvas();
|
||||||
|
|
||||||
|
ctx!.drawImage(img, 0, 0, canvas!.width, canvas!.height);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, [imageSrc]);
|
||||||
|
|
||||||
|
const invertPainting = (isChecked: boolean) => {
|
||||||
|
const ctx = overlayCanvasRef.current!.getContext('2d');
|
||||||
|
|
||||||
|
if (!ctx) return;
|
||||||
|
|
||||||
|
if (isChecked) {
|
||||||
|
const canvasWidth = overlayCanvasRef.current!.width;
|
||||||
|
const canvasHeight = overlayCanvasRef.current!.height;
|
||||||
|
|
||||||
|
clearOverlayCanvas();
|
||||||
|
|
||||||
|
const offscreenCanvas = new OffscreenCanvas(
|
||||||
|
overlayCanvasRef.current!.width,
|
||||||
|
overlayCanvasRef.current!.height
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!invertWorkerRef.current) {
|
||||||
|
invertWorkerRef.current = new Worker(
|
||||||
|
new URL('./invert-worker.ts', import.meta.url),
|
||||||
|
{
|
||||||
|
type: 'module'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
invertWorkerRef.current.onmessage = (event: any) => {
|
||||||
|
if (event.data.type === 'done' && event.data.imageData) {
|
||||||
|
// draw the data to the overlay canvas
|
||||||
|
const ctx = overlayCanvasRef.current!.getContext('2d')!;
|
||||||
|
ctx.putImageData(event.data.imageData, 0, 0);
|
||||||
|
|
||||||
|
isLoadingMaskRef.current = false;
|
||||||
|
saveImage();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// send offscreen canvas to worker
|
||||||
|
invertWorkerRef.current?.postMessage(
|
||||||
|
{ canvas: offscreenCanvas, type: 'init' },
|
||||||
|
[offscreenCanvas]
|
||||||
|
);
|
||||||
|
|
||||||
|
// send draw data to worker
|
||||||
|
const imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
|
||||||
|
invertWorkerRef.current?.postMessage({
|
||||||
|
type: 'draw',
|
||||||
|
width: imageData.width,
|
||||||
|
height: imageData.height,
|
||||||
|
strokes: strokesRef.current,
|
||||||
|
maskStrokes: maskStorkeRef.current
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
redrawStrokes(strokesRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateCursorSize = () => {
|
||||||
|
cursorRef.current!.style.width = `${lineWidth * autoScale.current}px`;
|
||||||
|
cursorRef.current!.style.height = `${lineWidth * autoScale.current}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const initializeImage = useCallback(async () => {
|
||||||
|
await drawImage();
|
||||||
|
onScaleImageSize?.({
|
||||||
|
width: canvasRef.current!.width,
|
||||||
|
height: canvasRef.current!.height
|
||||||
|
});
|
||||||
|
|
||||||
|
if (imageStatus.isResetNeeded) {
|
||||||
|
onReset();
|
||||||
|
resetCanvas();
|
||||||
|
} else if (
|
||||||
|
(strokesRef.current.length || maskStorkeRef.current.length) &&
|
||||||
|
imageStatus.isOriginal &&
|
||||||
|
!negativeMaskRef.current
|
||||||
|
) {
|
||||||
|
redrawStrokes(strokesRef.current);
|
||||||
|
} else if (
|
||||||
|
(strokesRef.current.length || maskStorkeRef.current.length) &&
|
||||||
|
imageStatus.isOriginal &&
|
||||||
|
negativeMaskRef.current
|
||||||
|
) {
|
||||||
|
invertPainting(true);
|
||||||
|
}
|
||||||
|
console.log('Image status:', imageStatus, negativeMaskRef.current);
|
||||||
|
|
||||||
|
updateCursorSize();
|
||||||
|
}, [drawImage, imageStatus.isOriginal, imageStatus.isResetNeeded]);
|
||||||
|
|
||||||
|
const handleFitView = () => {
|
||||||
|
fitView();
|
||||||
|
setActiveScale(autoScale.current);
|
||||||
|
updateCursorSize();
|
||||||
|
redrawStrokes(strokesRef.current);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleBrushSizeChange = (value: number) => {
|
||||||
|
setLineWidth(value);
|
||||||
|
cursorRef.current!.style.width = `${value}px`;
|
||||||
|
cursorRef.current!.style.height = `${value}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnChangeMask = (e: any) => {
|
||||||
|
negativeMaskRef.current = e.target.checked;
|
||||||
|
invertPainting(e.target.checked);
|
||||||
|
setInvertMask(e.target.checked);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
initializeImage();
|
||||||
|
}, [initializeImage]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleUndoShortcut = (e: KeyboardEvent) => {
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.key === 'z') {
|
||||||
|
undo();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseDown = (e: MouseEvent) => {
|
||||||
|
mouseDownState.current = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseUp = (e: MouseEvent) => {
|
||||||
|
mouseDownState.current = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('keydown', handleUndoShortcut);
|
||||||
|
// mouse down
|
||||||
|
window.addEventListener('mousedown', handleMouseDown);
|
||||||
|
|
||||||
|
// mouse up
|
||||||
|
window.addEventListener('mouseup', handleMouseUp);
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timer.current);
|
||||||
|
window.removeEventListener('keydown', handleUndoShortcut);
|
||||||
|
window.removeEventListener('mousedown', handleMouseDown);
|
||||||
|
window.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleDeleteMask = () => {
|
||||||
|
setInvertMask(false);
|
||||||
|
redrawStrokes(strokesRef.current);
|
||||||
|
saveImage();
|
||||||
|
};
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
clearMask: handleDeleteMask,
|
||||||
|
loadMaskPixs: async function (strokes: Stroke[]) {
|
||||||
|
setMaskStrokes(strokes);
|
||||||
|
setStrokes([]);
|
||||||
|
setTransform();
|
||||||
|
clearOverlayCanvas();
|
||||||
|
loadMaskPixs(strokes);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
invertWorkerRef.current = new Worker(
|
||||||
|
new URL('./invert-worker.ts', import.meta.url),
|
||||||
|
{
|
||||||
|
type: 'module'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
loadMaksWorkerRef.current = new Worker(
|
||||||
|
new URL('./offscreen-worker.ts', import.meta.url),
|
||||||
|
{
|
||||||
|
type: 'module'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
invertWorkerRef.current?.terminate();
|
||||||
|
loadMaksWorkerRef.current?.terminate();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (maskUpload?.length) {
|
||||||
|
// clear the overlay canvas
|
||||||
|
clearOverlayCanvas();
|
||||||
|
}
|
||||||
|
}, [maskUpload]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (disabled && cursorRef.current) {
|
||||||
|
cursorRef.current!.style.display = 'none';
|
||||||
|
}
|
||||||
|
}, [disabled]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="editor-wrapper">
|
||||||
|
<div className="flex-between">
|
||||||
|
<ToolsBar
|
||||||
|
handleBrushSizeChange={handleBrushSizeChange}
|
||||||
|
undo={undo}
|
||||||
|
onClear={onReset}
|
||||||
|
handleFitView={handleFitView}
|
||||||
|
handleUpdateImageList={handleUpdateImageList}
|
||||||
|
handleUpdateMaskList={handleUpdateMaskList}
|
||||||
|
disabled={disabled}
|
||||||
|
lineWidth={lineWidth}
|
||||||
|
invertMask={invertMask}
|
||||||
|
loading={loading}
|
||||||
|
accept={accept}
|
||||||
|
></ToolsBar>
|
||||||
|
|
||||||
|
<ImageActionsBar
|
||||||
|
handleOnChangeMask={handleOnChangeMask}
|
||||||
|
invertMask={invertMask}
|
||||||
|
downloadMask={downloadMask}
|
||||||
|
download={download}
|
||||||
|
isOriginal={imageStatus.isOriginal}
|
||||||
|
disabled={isDisabled || !!maskUpload?.length}
|
||||||
|
maskUpload={maskUpload}
|
||||||
|
></ImageActionsBar>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="editor-content"
|
||||||
|
ref={containerRef}
|
||||||
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
flex: 1
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loadingSize.loading && (
|
||||||
|
<Loading
|
||||||
|
width={loadingSize.width}
|
||||||
|
height={loadingSize.height}
|
||||||
|
></Loading>
|
||||||
|
)}
|
||||||
|
<canvas ref={canvasRef} style={{ position: 'absolute', zIndex: 1 }} />
|
||||||
|
<canvas
|
||||||
|
ref={overlayCanvasRef}
|
||||||
|
className={classNames('overlay-canvas', {
|
||||||
|
'overlay-canvas--disabled': disabled
|
||||||
|
})}
|
||||||
|
style={{ position: 'absolute', zIndex: 10, cursor: 'none' }}
|
||||||
|
onMouseDown={(event) => {
|
||||||
|
if (isLoadingMaskRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mouseDownState.current = true;
|
||||||
|
startDrawing(event);
|
||||||
|
}}
|
||||||
|
onMouseUp={(event) => {
|
||||||
|
if (isLoadingMaskRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mouseDownState.current = false;
|
||||||
|
endDrawing(event);
|
||||||
|
}}
|
||||||
|
onMouseEnter={handleMouseEnter}
|
||||||
|
onWheel={handleOnWheel}
|
||||||
|
onMouseMove={(e) => {
|
||||||
|
if (isLoadingMaskRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleMouseMove(e);
|
||||||
|
draw(e);
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
if (isLoadingMaskRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
endDrawing(e);
|
||||||
|
handleMouseLeave();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
ref={cursorRef}
|
||||||
|
style={{
|
||||||
|
display: 'none',
|
||||||
|
position: 'fixed',
|
||||||
|
width: lineWidth * activeScale,
|
||||||
|
height: lineWidth * activeScale,
|
||||||
|
backgroundColor: COLOR,
|
||||||
|
borderRadius: '50%',
|
||||||
|
pointerEvents: 'none',
|
||||||
|
cursor: 'none',
|
||||||
|
zIndex: 5
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default React.memo(CanvasImageEditor);
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/// <reference lib="webworker" />
|
||||||
|
|
||||||
|
let offscreenCanvas: OffscreenCanvas;
|
||||||
|
let ctx: OffscreenCanvasRenderingContext2D;
|
||||||
|
|
||||||
|
const COLOR = 'rgba(0, 0, 255, 0.3)';
|
||||||
|
|
||||||
|
type Point = { x: number; y: number; lineWidth: number };
|
||||||
|
type Stroke = Point[];
|
||||||
|
|
||||||
|
self.onmessage = (event) => {
|
||||||
|
const { width, height, strokes, maskStrokes } = event.data;
|
||||||
|
|
||||||
|
if (event.data.type === 'init') {
|
||||||
|
offscreenCanvas = event.data.canvas;
|
||||||
|
ctx = offscreenCanvas!.getContext('2d')!;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.data.type === 'draw') {
|
||||||
|
ctx.fillStyle = COLOR;
|
||||||
|
ctx.fillRect(0, 0, width, height);
|
||||||
|
|
||||||
|
ctx.globalCompositeOperation = 'destination-out';
|
||||||
|
|
||||||
|
[...strokes].forEach((stroke: Stroke) => {
|
||||||
|
stroke.forEach((point: { x: number; y: number; lineWidth: number }) => {
|
||||||
|
const lineWidth = point.lineWidth;
|
||||||
|
ctx.fillStyle = 'rgba(0,0,0,1)';
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(point.x, point.y, lineWidth / 2, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// points
|
||||||
|
maskStrokes?.forEach((stroke: Stroke) => {
|
||||||
|
stroke.forEach((point: { x: number; y: number; lineWidth: number }) => {
|
||||||
|
const lineWidth = 4;
|
||||||
|
ctx.fillStyle = 'rgba(0,0,0,1)';
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(point.x, point.y, lineWidth / 2, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const newImageData = ctx.getImageData(0, 0, width, height);
|
||||||
|
self.postMessage({ type: 'done', imageData: newImageData }, [
|
||||||
|
newImageData.data.buffer
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export {};
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
let offscreenCanvas: OffscreenCanvas;
|
||||||
|
let ctx: OffscreenCanvasRenderingContext2D;
|
||||||
|
|
||||||
|
const COLOR = 'rgba(0, 0, 255, 0.3)';
|
||||||
|
|
||||||
|
type Point = { x: number; y: number; lineWidth: number };
|
||||||
|
type Stroke = Point[];
|
||||||
|
|
||||||
|
const postDone = () => {
|
||||||
|
const imageData = ctx.getImageData(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
offscreenCanvas.width,
|
||||||
|
offscreenCanvas.height
|
||||||
|
);
|
||||||
|
self.postMessage({ type: 'done', imageData });
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawFillRect = (
|
||||||
|
ctx: OffscreenCanvasRenderingContext2D,
|
||||||
|
stroke: Stroke,
|
||||||
|
options: any
|
||||||
|
) => {
|
||||||
|
const { color } = options;
|
||||||
|
|
||||||
|
stroke?.forEach(({ x, y }) => {
|
||||||
|
const width = options.lineWidth || 10;
|
||||||
|
|
||||||
|
ctx.save();
|
||||||
|
ctx.fillStyle = 'rgba(0,0,0,1)';
|
||||||
|
ctx.globalCompositeOperation = 'destination-out';
|
||||||
|
ctx.fillRect(x - width / 2, y - width / 2, width, width);
|
||||||
|
|
||||||
|
ctx.globalCompositeOperation = 'source-over';
|
||||||
|
ctx.fillStyle = color;
|
||||||
|
ctx.fillRect(x - width / 2, y - width / 2, width, width);
|
||||||
|
ctx.restore();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawStrokes = (strokes: Stroke[]) => {
|
||||||
|
strokes?.forEach((stroke) => {
|
||||||
|
drawFillRect(ctx, stroke, {
|
||||||
|
color: COLOR
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawLine = (
|
||||||
|
stroke: Stroke | Point[],
|
||||||
|
options: {
|
||||||
|
lineWidth?: number;
|
||||||
|
color: string;
|
||||||
|
compositeOperation: 'source-over' | 'destination-out';
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
const { color, compositeOperation } = options;
|
||||||
|
ctx.lineCap = 'round';
|
||||||
|
ctx.lineJoin = 'round';
|
||||||
|
ctx.globalCompositeOperation = compositeOperation;
|
||||||
|
ctx.save();
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
|
||||||
|
stroke?.forEach((point, i) => {
|
||||||
|
const { x, y } = point;
|
||||||
|
ctx.lineWidth = point.lineWidth || 10;
|
||||||
|
if (i === 0) {
|
||||||
|
ctx.moveTo(x, y);
|
||||||
|
} else {
|
||||||
|
ctx.lineTo(x, y);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (compositeOperation === 'source-over') {
|
||||||
|
ctx.strokeStyle = color;
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.restore();
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawLines = (strokes: Stroke[]) => {
|
||||||
|
strokes?.forEach((stroke: Point[], index) => {
|
||||||
|
drawLine(stroke, {
|
||||||
|
color: COLOR,
|
||||||
|
compositeOperation: 'destination-out'
|
||||||
|
});
|
||||||
|
|
||||||
|
drawLine(stroke, {
|
||||||
|
color: COLOR,
|
||||||
|
compositeOperation: 'source-over'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
self.onmessage = (event) => {
|
||||||
|
if (event.data.type === 'init') {
|
||||||
|
offscreenCanvas = event.data.canvas;
|
||||||
|
ctx = offscreenCanvas!.getContext('2d')!;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.data.type === 'draw') {
|
||||||
|
ctx?.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
||||||
|
const { maskStrokes, strokes } = event.data;
|
||||||
|
drawStrokes(maskStrokes);
|
||||||
|
drawLines(strokes);
|
||||||
|
postDone();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export {};
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
import IconFont from '@/components/icon-font';
|
||||||
|
import { KeyMap } from '@/config/hotkeys';
|
||||||
|
import UploadImg from '@/pages/playground/components/upload-img';
|
||||||
|
import {
|
||||||
|
ClearOutlined,
|
||||||
|
DownloadOutlined,
|
||||||
|
ExpandOutlined,
|
||||||
|
FormatPainterOutlined,
|
||||||
|
UndoOutlined
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { Button, Checkbox, Slider, Tooltip } from 'antd';
|
||||||
|
import { CheckboxChangeEvent } from 'antd/es/checkbox';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface ToolsBarProps {
|
||||||
|
disabled: boolean;
|
||||||
|
loading: boolean;
|
||||||
|
lineWidth: number;
|
||||||
|
uploadButton?: React.ReactNode;
|
||||||
|
invertMask?: boolean;
|
||||||
|
accept?: string;
|
||||||
|
handleBrushSizeChange: (value: number) => void;
|
||||||
|
undo: () => void;
|
||||||
|
onClear: () => void;
|
||||||
|
handleFitView: () => void;
|
||||||
|
handleUpdateImageList: (fileList: any[]) => void;
|
||||||
|
handleUpdateMaskList: (fileList: any[]) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ToolsBar: React.FC<ToolsBarProps> = (props) => {
|
||||||
|
const {
|
||||||
|
disabled,
|
||||||
|
loading,
|
||||||
|
lineWidth,
|
||||||
|
invertMask,
|
||||||
|
accept,
|
||||||
|
handleBrushSizeChange,
|
||||||
|
undo,
|
||||||
|
onClear,
|
||||||
|
handleFitView,
|
||||||
|
handleUpdateImageList,
|
||||||
|
handleUpdateMaskList
|
||||||
|
} = props;
|
||||||
|
const intl = useIntl();
|
||||||
|
return (
|
||||||
|
<div className="tools">
|
||||||
|
<Tooltip
|
||||||
|
placement="bottomLeft"
|
||||||
|
arrow={false}
|
||||||
|
overlayInnerStyle={{
|
||||||
|
background: 'var(--color-white-1)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'flex-start',
|
||||||
|
width: 160
|
||||||
|
}}
|
||||||
|
title={
|
||||||
|
<div className="flex-column" style={{ width: '100%' }}>
|
||||||
|
<span className="text-secondary">
|
||||||
|
{intl.formatMessage({ id: 'playground.image.brushSize' })}
|
||||||
|
</span>
|
||||||
|
<Slider
|
||||||
|
disabled={disabled}
|
||||||
|
style={{ marginBlock: '4px 6px', marginLeft: 0, flex: 1 }}
|
||||||
|
vertical={false}
|
||||||
|
defaultValue={lineWidth}
|
||||||
|
min={10}
|
||||||
|
max={100}
|
||||||
|
onChange={handleBrushSizeChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button size="middle" type="text">
|
||||||
|
<FormatPainterOutlined className="font-size-14" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
<span>
|
||||||
|
[{KeyMap.UNDO.textKeybinding}]
|
||||||
|
<span className="m-l-5">
|
||||||
|
{intl.formatMessage({ id: 'common.button.undo' })}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button onClick={undo} size="middle" type="text" disabled={disabled}>
|
||||||
|
<UndoOutlined className="font-size-14" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title={intl.formatMessage({ id: 'common.button.clear' })}>
|
||||||
|
<Button onClick={onClear} size="middle" type="text" disabled={disabled}>
|
||||||
|
<ClearOutlined className="font-size-14" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
<UploadImg
|
||||||
|
disabled={loading || invertMask}
|
||||||
|
handleUpdateImgList={handleUpdateImageList}
|
||||||
|
size="middle"
|
||||||
|
accept={accept}
|
||||||
|
></UploadImg>
|
||||||
|
<UploadImg
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'playground.image.mask.upload'
|
||||||
|
})}
|
||||||
|
icon={<IconFont type="icon-mosaic-2"></IconFont>}
|
||||||
|
disabled={loading || invertMask}
|
||||||
|
handleUpdateImgList={handleUpdateMaskList}
|
||||||
|
size="middle"
|
||||||
|
accept={accept}
|
||||||
|
></UploadImg>
|
||||||
|
<Tooltip title={intl.formatMessage({ id: 'playground.image.fitview' })}>
|
||||||
|
<Button
|
||||||
|
onClick={handleFitView}
|
||||||
|
size="middle"
|
||||||
|
type="text"
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<ExpandOutlined className="font-size-14" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface ImageActionsBarProps {
|
||||||
|
disabled: boolean;
|
||||||
|
maskUpload?: any[];
|
||||||
|
isOriginal: boolean;
|
||||||
|
invertMask: boolean;
|
||||||
|
handleOnChangeMask: (e: CheckboxChangeEvent) => void;
|
||||||
|
downloadMask: () => void;
|
||||||
|
download: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ImageActionsBar: React.FC<ImageActionsBarProps> = (props) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
const {
|
||||||
|
disabled,
|
||||||
|
isOriginal,
|
||||||
|
invertMask,
|
||||||
|
handleOnChangeMask,
|
||||||
|
downloadMask,
|
||||||
|
download
|
||||||
|
} = props;
|
||||||
|
return (
|
||||||
|
<div className="tools">
|
||||||
|
{isOriginal && (
|
||||||
|
<>
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
<span style={{ whiteSpace: 'pre-wrap' }}>
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: 'playground.image.negativeMask.tips'
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
onChange={handleOnChangeMask}
|
||||||
|
className="flex-center"
|
||||||
|
checked={invertMask}
|
||||||
|
disabled={disabled}
|
||||||
|
>
|
||||||
|
<span className="font-size-12">
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: 'playground.image.negativeMask'
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</Checkbox>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'playground.image.saveMask'
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Button onClick={downloadMask} size="middle" type="text">
|
||||||
|
<IconFont className="font-size-14" type="icon-save1"></IconFont>
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{!isOriginal && (
|
||||||
|
<Tooltip
|
||||||
|
title={intl.formatMessage({ id: 'playground.image.download' })}
|
||||||
|
>
|
||||||
|
<Button onClick={download} size="middle" type="text">
|
||||||
|
<DownloadOutlined className="font-size-14" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { ImageActionsBar, ToolsBar };
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useIntl } from '@umijs/max';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import Inner from './inner';
|
import Inner from './inner';
|
||||||
@@ -8,15 +9,20 @@ interface LabelSelectorProps {
|
|||||||
btnText?: string;
|
btnText?: string;
|
||||||
description?: React.ReactNode;
|
description?: React.ReactNode;
|
||||||
onChange?: (labels: Record<string, any>) => void;
|
onChange?: (labels: Record<string, any>) => void;
|
||||||
|
onBlur?: (e: any, type: string, index: number) => void;
|
||||||
|
onDelete?: (index: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LabelSelector: React.FC<LabelSelectorProps> = ({
|
const LabelSelector: React.FC<LabelSelectorProps> = ({
|
||||||
labels,
|
labels,
|
||||||
onChange,
|
onChange,
|
||||||
|
onBlur,
|
||||||
|
onDelete,
|
||||||
label,
|
label,
|
||||||
btnText,
|
btnText,
|
||||||
description
|
description
|
||||||
}) => {
|
}) => {
|
||||||
|
const intl = useIntl();
|
||||||
const [labelsData, setLabelsData] = useState({});
|
const [labelsData, setLabelsData] = useState({});
|
||||||
const [labelList, setLabelList] = useState<{ key: string; value: string }[]>(
|
const [labelList, setLabelList] = useState<{ key: string; value: string }[]>(
|
||||||
[]
|
[]
|
||||||
@@ -33,7 +39,6 @@ const LabelSelector: React.FC<LabelSelectorProps> = ({
|
|||||||
});
|
});
|
||||||
setLabelList(list);
|
setLabelList(list);
|
||||||
}
|
}
|
||||||
console.log('labelsData=========', labelsData);
|
|
||||||
}, [labels]);
|
}, [labels]);
|
||||||
|
|
||||||
const handleLabelListChange = useCallback(
|
const handleLabelListChange = useCallback(
|
||||||
@@ -43,19 +48,51 @@ const LabelSelector: React.FC<LabelSelectorProps> = ({
|
|||||||
[setLabelList]
|
[setLabelList]
|
||||||
);
|
);
|
||||||
const handleLabelsChange = (data: Record<string, any>) => {
|
const handleLabelsChange = (data: Record<string, any>) => {
|
||||||
|
console.log('handleLabelsChange', data);
|
||||||
setLabelsData(data);
|
setLabelsData(data);
|
||||||
onChange?.(data);
|
onChange?.(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleOnPaste = (
|
||||||
|
e: React.ClipboardEvent<HTMLTextAreaElement>,
|
||||||
|
index: number
|
||||||
|
) => {
|
||||||
|
const clipboardText = e.clipboardData.getData('text');
|
||||||
|
if (!clipboardText || clipboardText.indexOf('=') === -1) return;
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const lines = clipboardText
|
||||||
|
.split(/\r?\n/)
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.filter((line) => line && line.includes('='));
|
||||||
|
|
||||||
|
const parsedData = lines.map((line) => {
|
||||||
|
const [key, value] = line.split('=').map((part) => part.trim());
|
||||||
|
return { key, value };
|
||||||
|
});
|
||||||
|
console.log(lines, parsedData);
|
||||||
|
|
||||||
|
setLabelList((prevPairs) => {
|
||||||
|
const newPairs = [...prevPairs];
|
||||||
|
newPairs.splice(index, 1, ...parsedData);
|
||||||
|
return newPairs;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Inner
|
<Inner
|
||||||
label={label}
|
label={label}
|
||||||
btnText={btnText}
|
btnText={btnText}
|
||||||
description={description}
|
description={
|
||||||
|
description ?? intl.formatMessage({ id: 'models.form.keyvalue.paste' })
|
||||||
|
}
|
||||||
labels={labelsData}
|
labels={labelsData}
|
||||||
labelList={labelList}
|
labelList={labelList}
|
||||||
onChange={handleLabelsChange}
|
onChange={handleLabelsChange}
|
||||||
onLabelListChange={handleLabelListChange}
|
onLabelListChange={handleLabelListChange}
|
||||||
|
onPaste={handleOnPaste}
|
||||||
|
onBlur={onBlur}
|
||||||
|
onDelete={onDelete}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ interface LabelSelectorProps {
|
|||||||
labelList: Array<{ key: string; value: string }>;
|
labelList: Array<{ key: string; value: string }>;
|
||||||
onLabelListChange: (list: { key: string; value: string }[]) => void;
|
onLabelListChange: (list: { key: string; value: string }[]) => void;
|
||||||
onChange?: (labels: Record<string, any>) => void;
|
onChange?: (labels: Record<string, any>) => void;
|
||||||
|
onPaste?: (e: any, index: number) => void;
|
||||||
|
onBlur?: (e: any, type: string, index: number) => void;
|
||||||
|
onDelete?: (index: number) => void;
|
||||||
description?: React.ReactNode;
|
description?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,12 +23,16 @@ const Inner: React.FC<LabelSelectorProps> = ({
|
|||||||
labelList,
|
labelList,
|
||||||
onChange,
|
onChange,
|
||||||
onLabelListChange,
|
onLabelListChange,
|
||||||
|
onPaste,
|
||||||
|
onBlur,
|
||||||
|
onDelete,
|
||||||
label,
|
label,
|
||||||
btnText,
|
btnText,
|
||||||
description
|
description
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||||
|
const boxRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const updateLabels = (list: { key: string; value: string }[]) => {
|
const updateLabels = (list: { key: string; value: string }[]) => {
|
||||||
const newLabels = _.reduce(
|
const newLabels = _.reduce(
|
||||||
@@ -40,7 +47,7 @@ const Inner: React.FC<LabelSelectorProps> = ({
|
|||||||
);
|
);
|
||||||
onChange?.(newLabels);
|
onChange?.(newLabels);
|
||||||
};
|
};
|
||||||
const handleOnChange = (index: string, label: any) => {
|
const handleOnChange = (index: number, label: any) => {
|
||||||
const list = _.cloneDeep(labelList);
|
const list = _.cloneDeep(labelList);
|
||||||
list[index] = label;
|
list[index] = label;
|
||||||
onLabelListChange(list);
|
onLabelListChange(list);
|
||||||
@@ -57,24 +64,20 @@ const Inner: React.FC<LabelSelectorProps> = ({
|
|||||||
];
|
];
|
||||||
onLabelListChange(newLabelList);
|
onLabelListChange(newLabelList);
|
||||||
updateLabels(newLabelList);
|
updateLabels(newLabelList);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
// button scroll to view
|
|
||||||
buttonRef.current?.scrollIntoView?.({ behavior: 'smooth' });
|
|
||||||
}, 100);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnDelete = (index: string) => {
|
const handleOnDelete = (index: number) => {
|
||||||
const list = _.cloneDeep(labelList);
|
const list = _.cloneDeep(labelList);
|
||||||
list.splice(parseInt(index), 1);
|
list.splice(index, 1);
|
||||||
onLabelListChange(list);
|
onLabelListChange(list);
|
||||||
updateLabels(list);
|
updateLabels(list);
|
||||||
|
onDelete?.(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper label={label} description={description}>
|
<Wrapper label={label} description={description}>
|
||||||
<>
|
<>
|
||||||
{_.map(labelList, (item: any, index: string) => {
|
{labelList?.map((item: any, index: number) => {
|
||||||
return (
|
return (
|
||||||
<LabelItem
|
<LabelItem
|
||||||
key={index}
|
key={index}
|
||||||
@@ -83,6 +86,8 @@ const Inner: React.FC<LabelSelectorProps> = ({
|
|||||||
labelList={labelList}
|
labelList={labelList}
|
||||||
onDelete={() => handleOnDelete(index)}
|
onDelete={() => handleOnDelete(index)}
|
||||||
onChange={(obj) => handleOnChange(index, obj)}
|
onChange={(obj) => handleOnChange(index, obj)}
|
||||||
|
onPaste={(e) => onPaste?.(e, index)}
|
||||||
|
onBlur={(e: any, type: string) => onBlur?.(e, type, index)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ interface LabelItemProps {
|
|||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
labelList: { key: string; value: string }[];
|
labelList: { key: string; value: string }[];
|
||||||
onChange?: (params: { key: string; value: string }) => void;
|
onChange?: (params: { key: string; value: string }) => void;
|
||||||
|
onPaste?: (e: any) => void;
|
||||||
|
onBlur?: (e: any, type: string) => void;
|
||||||
}
|
}
|
||||||
const LabelItem: React.FC<LabelItemProps> = ({
|
const LabelItem: React.FC<LabelItemProps> = ({
|
||||||
label,
|
label,
|
||||||
@@ -26,7 +28,9 @@ const LabelItem: React.FC<LabelItemProps> = ({
|
|||||||
keyAddon,
|
keyAddon,
|
||||||
valueAddon,
|
valueAddon,
|
||||||
onChange,
|
onChange,
|
||||||
onDelete
|
onDelete,
|
||||||
|
onPaste,
|
||||||
|
onBlur
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
@@ -47,7 +51,7 @@ const LabelItem: React.FC<LabelItemProps> = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyOnBlur = (e: any) => {
|
const handleKeyOnBlur = (e: any, type: string) => {
|
||||||
const val = e.target.value;
|
const val = e.target.value;
|
||||||
// has duplicate key
|
// has duplicate key
|
||||||
const duplicates = _.filter(
|
const duplicates = _.filter(
|
||||||
@@ -66,6 +70,7 @@ const LabelItem: React.FC<LabelItemProps> = ({
|
|||||||
} else {
|
} else {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}
|
}
|
||||||
|
onBlur?.(e, type);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -81,7 +86,8 @@ const LabelItem: React.FC<LabelItemProps> = ({
|
|||||||
label={intl.formatMessage({ id: 'common.input.key' })}
|
label={intl.formatMessage({ id: 'common.input.key' })}
|
||||||
value={label.key}
|
value={label.key}
|
||||||
onChange={handleOnKeyChange}
|
onChange={handleOnKeyChange}
|
||||||
onBlur={handleKeyOnBlur}
|
onBlur={(e: any) => handleKeyOnBlur(e, 'key')}
|
||||||
|
onPaste={onPaste}
|
||||||
></SealInput.Input>
|
></SealInput.Input>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
@@ -94,6 +100,7 @@ const LabelItem: React.FC<LabelItemProps> = ({
|
|||||||
label={intl.formatMessage({ id: 'common.input.value' })}
|
label={intl.formatMessage({ id: 'common.input.value' })}
|
||||||
value={label.value}
|
value={label.value}
|
||||||
onChange={handleOnValueChange}
|
onChange={handleOnValueChange}
|
||||||
|
onBlur={(e: any) => onBlur?.(e, 'value')}
|
||||||
></SealInput.Input>
|
></SealInput.Input>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user