@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.
@@ -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 { lightToken } from '@/antdTheme/lightTheme'
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(0)
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={lightToken}
33
+ theme={antdToken}
46
34
  locale={zhCN}
47
35
 
48
36
  button={{
@@ -88,7 +88,7 @@ export const Side: React.FC<SideProps> = () => {
88
88
  alt="logo"
89
89
  />
90
90
 
91
- <span>财务系统</span>
91
+ <span>后台管理系统</span>
92
92
  </div>
93
93
 
94
94
  <Menu
@@ -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 { lightToken } from '@/antdTheme/lightTheme'
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(0)
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={lightToken}
34
+ theme={antdToken}
46
35
  locale={zhCN}
47
36
 
48
37
  button={{
@@ -84,7 +84,7 @@ export const Side: React.FC<SideProps> = ({}) => {
84
84
  alt="logo"
85
85
  />
86
86
 
87
- <span>财务系统</span>
87
+ <span>后台管理系统</span>
88
88
  </div>
89
89
 
90
90
  <Menu
@@ -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 === 'yang' && values.password === '123456') {
55
+ if (values.username === 'admin' && values.password === '123456') {
56
56
  setPermissions(defaultList)
57
57
  setToken('111')
58
58
  setUserInfo({
59
- userName: 'yang',
59
+ userName: 'admin',
60
60
  userId: '001'
61
61
  })
62
62
 
@@ -2,3 +2,4 @@ export const LOGIN_TOKEN = 'login/token'
2
2
  export const USER_INFO = 'userInfo'
3
3
  export const MENUS = 'menus'
4
4
  export const PERMISSION = 'permission'
5
+ export const ANTDTOKEN = 'antd/token'
@@ -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
+ )