Skip to content

Commit 00bdccb

Browse files
committed
optimize: optimized code
1 parent e21afb8 commit 00bdccb

File tree

6 files changed

+72
-20
lines changed

6 files changed

+72
-20
lines changed

packages/utils/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
},
77
"typesVersions": {
88
"*": {
9-
"*": ["./src/*"]
9+
"*": [
10+
"./src/*"
11+
]
1012
}
1113
},
1214
"dependencies": {
1315
"colord": "2.9.3",
1416
"crypto-js": "4.2.0",
17+
"klona": "2.0.6",
1518
"localforage": "1.10.0",
1619
"nanoid": "5.0.7"
1720
},

packages/utils/src/klona.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { klona as jsonClone } from 'klona/json';
2+
3+
export { jsonClone };

pnpm-lock.yaml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/login/index.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,46 @@ import { getPaletteColorByNumber, mixColor } from '@sa/color';
22
import { Card } from 'antd';
33
import { Outlet } from 'react-router-dom';
44
import WaveBg from '@/components/custom/wave-bg';
5-
import SystemLogo from '@/components/common/system-logo';
6-
import ThemeSchemaSwitch from '@/components/common/ThemeSchemaSwitch';
7-
import LangSwitch from '@/components/common/LangSwitch';
5+
import Header from './modules/Header';
6+
87
import { getDarkMode, getThemeSettings } from '@/store/slice/theme';
98

109
const COLOR_WHITE = '#ffffff';
11-
export function Component() {
10+
11+
12+
function useBgColor() {
1213
const darkMode = useAppSelector(getDarkMode);
1314
const { themeColor } = useAppSelector(getThemeSettings);
14-
const { t } = useTranslation();
1515

1616
const bgThemeColor = darkMode ? getPaletteColorByNumber(themeColor, 600) : themeColor;
1717
const ratio = darkMode ? 0.5 : 0.2;
1818
const bgColor = mixColor(COLOR_WHITE, themeColor, ratio);
1919

20+
return {
21+
bgThemeColor,
22+
bgColor
23+
}
24+
}
25+
26+
export function Component() {
27+
28+
const { bgThemeColor, bgColor } = useBgColor();
29+
30+
2031
return (
2132
<div
2233
className="relative size-full flex-center overflow-hidden bg-layout"
2334
style={{ backgroundColor: bgColor }}
2435
>
25-
<WaveBg themeColor={bgThemeColor}></WaveBg>
36+
<WaveBg themeColor={bgThemeColor} />
2637
<Card
2738
bordered={false}
2839
className="relative z-4 w-auto rd-12px"
2940
>
3041
<div className="w-400px lt-sm:w-300px">
31-
<header className="flex-y-center justify-between">
32-
<SystemLogo className="text-64px text-primary lt-sm:text-48px"></SystemLogo>
33-
<h3 className="text-28px text-primary font-500 lt-sm:text-22px">{t('system.title')}</h3>
34-
<div className="i-flex-col">
35-
<ThemeSchemaSwitch
36-
showTooltip={false}
37-
className="text-20px lt-sm:text-18px"
38-
/>
39-
<LangSwitch showTooltip={false} />
40-
</div>
41-
</header>
42+
<Header />
4243
<main className="pt-24px">
43-
<Outlet></Outlet>
44+
<Outlet />
4445
</main>
4546
</div>
4647
</Card>

src/pages/login/modules/Header.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import SystemLogo from '@/components/common/system-logo';
2+
import ThemeSchemaSwitch from '@/components/common/ThemeSchemaSwitch';
3+
import LangSwitch from '@/components/common/LangSwitch';
4+
5+
const Header = memo(() => {
6+
7+
const { t } = useTranslation();
8+
9+
10+
return (
11+
<header className="flex-y-center justify-between">
12+
<SystemLogo className="text-64px text-primary lt-sm:text-48px"></SystemLogo>
13+
<h3 className="text-28px text-primary font-500 lt-sm:text-22px">{t('system.title')}</h3>
14+
<div className="i-flex-col">
15+
<ThemeSchemaSwitch
16+
showTooltip={false}
17+
className="text-20px lt-sm:text-18px"
18+
/>
19+
<LangSwitch showTooltip={false} />
20+
</div>
21+
</header>
22+
)
23+
})
24+
25+
export default Header

src/pages/login/pwd-login/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Button, Checkbox, Divider, Form, Input, Space } from 'antd';
22
import { loginModuleRecord } from '@/constants/app';
33
import { useLogin } from '@/hooks/common/login';
4+
45
type AccountKey = 'super' | 'admin' | 'user';
56
interface Account {
67
key: AccountKey;
@@ -73,6 +74,7 @@ export function Component() {
7374
>
7475
<Input.Password autoComplete="password"></Input.Password>
7576
</Form.Item>
77+
</Form>
7678
<Space
7779
direction="vertical"
7880
className="w-full"
@@ -129,7 +131,7 @@ export function Component() {
129131
})}
130132
</div>
131133
</Space>
132-
</Form>
134+
133135
</>
134136
);
135137
}

0 commit comments

Comments
 (0)