@yyp92-cli/template-react-pc 1.5.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/template/README.md +6 -0
- package/template/package.json +2 -3
- package/template/pnpm-lock.yaml +719 -732
- package/template/src/antdTheme/darkTheme.ts +285 -1
- package/template/src/antdTheme/lightTheme.ts +272 -54
- package/template/src/components/layout/footer/index.tsx +1 -1
- package/template/src/components/layout/header/index.tsx +3 -0
- package/template/src/components/layout/index.tsx +8 -20
- package/template/src/components/layout/side/index.tsx +1 -1
- package/template/src/components/layout-horizontal/header/index.tsx +3 -0
- package/template/src/components/layout-horizontal/index.tsx +6 -17
- package/template/src/components/layout-horizontal/side/index.tsx +1 -1
- package/template/src/components/login/index.tsx +2 -2
- package/template/src/global/constants.ts +1 -0
- package/template/src/store/antdToken.ts +35 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import React, { useEffect } from 'react'
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
2
|
import { ConfigProvider } from 'antd'
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import 'dayjs/locale/zh-cn';
|
|
5
|
-
import zhCN from 'antd/locale/zh_CN'
|
|
6
|
-
import {
|
|
5
|
+
import zhCN from 'antd/locale/zh_CN'
|
|
6
|
+
import { antdTokenStore } from '@/store/antdToken'
|
|
7
|
+
import { getDarkTheme } from '@/utils'
|
|
7
8
|
import Content from './content'
|
|
8
9
|
|
|
9
10
|
import styles from './index.module.scss'
|
|
@@ -13,36 +14,23 @@ interface LayoutProps {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const Layout: React.FC<LayoutProps> = ({ }) => {
|
|
17
|
+
const {antdToken} = antdTokenStore()
|
|
18
|
+
|
|
16
19
|
useEffect(() => {
|
|
17
|
-
getDarkTheme(
|
|
20
|
+
getDarkTheme(false)
|
|
18
21
|
dayjs.locale('zh-cn')
|
|
19
22
|
}, [])
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
// ********** 操作 **********
|
|
23
|
-
// 主题切换
|
|
24
|
-
const getDarkTheme = (theme: number) => {
|
|
25
|
-
// 获取根元素
|
|
26
|
-
const root = document.documentElement;
|
|
27
|
-
|
|
28
|
-
if (theme != 1) {
|
|
29
|
-
// 修改 data-theme 属性的值为 "light"
|
|
30
|
-
root.setAttribute('data-theme', 'light');
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// 修改 data-theme 属性的值为 "dark"
|
|
35
|
-
root.setAttribute('data-theme', 'dark');
|
|
36
|
-
}
|
|
37
26
|
|
|
38
27
|
|
|
39
28
|
// ********** 渲染 **********
|
|
40
|
-
|
|
41
29
|
return (
|
|
42
30
|
<div className={styles.layout}>
|
|
43
31
|
<ConfigProvider
|
|
44
32
|
// 主题
|
|
45
|
-
theme={
|
|
33
|
+
theme={antdToken}
|
|
46
34
|
locale={zhCN}
|
|
47
35
|
|
|
48
36
|
button={{
|
|
@@ -5,6 +5,7 @@ import type { MenuProps } from 'antd'
|
|
|
5
5
|
import { FullscreenExitOutlined, FullscreenOutlined, UserOutlined } from '@ant-design/icons'
|
|
6
6
|
import { getDarkTheme } from '@/utils'
|
|
7
7
|
import { userInfoStore } from '@/store/login'
|
|
8
|
+
import { antdTokenStore } from '@/store/antdToken'
|
|
8
9
|
import { tokenStore } from '@/store/token'
|
|
9
10
|
import { menusStore } from '@/store/menus'
|
|
10
11
|
import { permissionStore } from '@/store/permission'
|
|
@@ -19,6 +20,7 @@ interface HeaderProps {
|
|
|
19
20
|
export const Header: React.FC<HeaderProps> = ({}) => {
|
|
20
21
|
const navigate = useNavigate()
|
|
21
22
|
const {clearUserInfo} = userInfoStore()
|
|
23
|
+
const {setAntdToken} = antdTokenStore()
|
|
22
24
|
const {clearToken} = tokenStore()
|
|
23
25
|
const {clearMenus} = menusStore()
|
|
24
26
|
const {clearPermissions} = permissionStore()
|
|
@@ -52,6 +54,7 @@ export const Header: React.FC<HeaderProps> = ({}) => {
|
|
|
52
54
|
|
|
53
55
|
const handleChangeTheme = (checked: boolean) => {
|
|
54
56
|
getDarkTheme(checked)
|
|
57
|
+
setAntdToken(checked)
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
|
|
@@ -3,7 +3,8 @@ import { ConfigProvider } from 'antd'
|
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import 'dayjs/locale/zh-cn';
|
|
5
5
|
import zhCN from 'antd/locale/zh_CN';
|
|
6
|
-
import {
|
|
6
|
+
import { getDarkTheme } from '@/utils'
|
|
7
|
+
import { antdTokenStore } from '@/store/antdToken'
|
|
7
8
|
import Content from './content'
|
|
8
9
|
|
|
9
10
|
import styles from './index.module.scss'
|
|
@@ -13,27 +14,15 @@ interface LayoutProps {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const Layout: React.FC<LayoutProps> = ({ }) => {
|
|
17
|
+
const {antdToken} = antdTokenStore()
|
|
18
|
+
|
|
16
19
|
useEffect(() => {
|
|
17
|
-
getDarkTheme(
|
|
20
|
+
getDarkTheme(false)
|
|
18
21
|
dayjs.locale('zh-cn')
|
|
19
22
|
}, [])
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
// ********** 操作 **********
|
|
23
|
-
// 主题切换
|
|
24
|
-
const getDarkTheme = (theme: number) => {
|
|
25
|
-
// 获取根元素
|
|
26
|
-
const root = document.documentElement;
|
|
27
|
-
|
|
28
|
-
if (theme != 1) {
|
|
29
|
-
// 修改 data-theme 属性的值为 "light"
|
|
30
|
-
root.setAttribute('data-theme', 'light');
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// 修改 data-theme 属性的值为 "dark"
|
|
35
|
-
root.setAttribute('data-theme', 'dark');
|
|
36
|
-
}
|
|
37
26
|
|
|
38
27
|
|
|
39
28
|
// ********** 渲染 **********
|
|
@@ -42,7 +31,7 @@ const Layout: React.FC<LayoutProps> = ({ }) => {
|
|
|
42
31
|
<div className={styles.layout}>
|
|
43
32
|
<ConfigProvider
|
|
44
33
|
// 主题
|
|
45
|
-
theme={
|
|
34
|
+
theme={antdToken}
|
|
46
35
|
locale={zhCN}
|
|
47
36
|
|
|
48
37
|
button={{
|
|
@@ -52,11 +52,11 @@ const Login: React.FC<LoginProps> = ({}) => {
|
|
|
52
52
|
const onFinish = async (values: any) => {
|
|
53
53
|
console.log('Success:', values)
|
|
54
54
|
|
|
55
|
-
if (values.username === '
|
|
55
|
+
if (values.username === 'admin' && values.password === '123456') {
|
|
56
56
|
setPermissions(defaultList)
|
|
57
57
|
setToken('111')
|
|
58
58
|
setUserInfo({
|
|
59
|
-
userName: '
|
|
59
|
+
userName: 'admin',
|
|
60
60
|
userId: '001'
|
|
61
61
|
})
|
|
62
62
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * 用户信息
|
|
3
|
+
*/
|
|
4
|
+
import { create } from 'zustand'
|
|
5
|
+
import { persist } from 'zustand/middleware'
|
|
6
|
+
import { ANTDTOKEN} from '@/global/constants'
|
|
7
|
+
import { lightToken } from '@/antdTheme/lightTheme'
|
|
8
|
+
import { darkToken } from '@/antdTheme/darkTheme'
|
|
9
|
+
|
|
10
|
+
type AntdTokenStoreState = {
|
|
11
|
+
antdToken: any
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type AntdTokenStoreActions = {
|
|
15
|
+
setAntdToken: (
|
|
16
|
+
antdToken: AntdTokenStoreState['antdToken']
|
|
17
|
+
) => void,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type AntdTokenStore = AntdTokenStoreState & AntdTokenStoreActions
|
|
21
|
+
|
|
22
|
+
export const antdTokenStore = create<AntdTokenStore>()(
|
|
23
|
+
persist(
|
|
24
|
+
(set) => ({
|
|
25
|
+
antdToken: {},
|
|
26
|
+
setAntdToken: (isDark) => {
|
|
27
|
+
const antdToken = isDark ? darkToken : lightToken
|
|
28
|
+
return set({antdToken})
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
{
|
|
32
|
+
name: ANTDTOKEN
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
)
|