@yyp92-cli/template-react-pc 1.2.1 → 1.4.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/src/components/layout/content/index.tsx +51 -19
- package/template/src/components/layout/side/index.tsx +10 -26
- package/template/src/components/layout-horizontal/content/index.tsx +40 -8
- package/template/src/components/layout-horizontal/side/index.tsx +7 -25
- package/template/src/components/login/index.tsx +13 -1
- package/template/src/pages/home/index.tsx +5 -0
- package/template/src/router/router.tsx +26 -0
- package/template/src/service/request/index.ts +1 -1
- package/template/src/store/login.ts +2 -6
- package/template/src/store/token.ts +28 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -6,6 +6,8 @@ import {Footer} from '../footer'
|
|
|
6
6
|
import {routerConfig} from '@/router/router'
|
|
7
7
|
import type {RouterConfigItemProps} from '@/router/router'
|
|
8
8
|
import { permissionStore } from '@/store/permission'
|
|
9
|
+
import { tokenStore } from '@/store/token'
|
|
10
|
+
import { menusStore } from '@/store/menus'
|
|
9
11
|
|
|
10
12
|
import styles from './index.module.scss'
|
|
11
13
|
|
|
@@ -21,22 +23,37 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
21
23
|
const {
|
|
22
24
|
permissions
|
|
23
25
|
} = permissionStore()
|
|
26
|
+
const {token} = tokenStore()
|
|
27
|
+
const {menus} = menusStore()
|
|
24
28
|
|
|
25
|
-
const [currentRouter, setCurrentRouter] = useState<RouterConfigItemProps>()
|
|
29
|
+
const [currentRouter, setCurrentRouter] = useState<RouterConfigItemProps | any>()
|
|
26
30
|
|
|
27
31
|
useEffect(() => {
|
|
28
32
|
const {pathname} = location ?? {}
|
|
29
33
|
const newPathname = pathname.slice(1)
|
|
30
34
|
|
|
31
|
-
if (
|
|
35
|
+
if (!token) {
|
|
36
|
+
navigate('/login')
|
|
37
|
+
}
|
|
38
|
+
else if (newPathname !== '') {
|
|
32
39
|
const pathnameList = newPathname.split('/')
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
const getCcondition = () => {
|
|
41
|
+
if (pathnameList.length === 1) {
|
|
42
|
+
return permissions.includes(pathnameList[0])
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (pathnameList.length === 2) {
|
|
46
|
+
return permissions.includes(pathnameList[1])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (pathnameList.length === 3) {
|
|
50
|
+
return permissions.includes(`${pathnameList[1]}/${pathnameList[2]}`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
38
55
|
|
|
39
|
-
if (
|
|
56
|
+
if (getCcondition()) {
|
|
40
57
|
let newCurrentRouter: any = {}
|
|
41
58
|
|
|
42
59
|
if (pathnameList.length === 1) {
|
|
@@ -46,6 +63,10 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
46
63
|
const parent = routerConfig[0]?.children?.find((group: any) => group.key === pathnameList[0]) ?? {}
|
|
47
64
|
newCurrentRouter = parent?.children?.find((item: any) => item.key === pathnameList[1])
|
|
48
65
|
}
|
|
66
|
+
else if (pathnameList.length === 3) {
|
|
67
|
+
const parent = routerConfig[0]?.children?.find((group: any) => group.key === pathnameList[0]) ?? {}
|
|
68
|
+
newCurrentRouter = parent?.children?.find((item: any) => item.key === `${pathnameList[1]}/${pathnameList[2]}`)
|
|
69
|
+
}
|
|
49
70
|
|
|
50
71
|
setCurrentRouter(newCurrentRouter)
|
|
51
72
|
}
|
|
@@ -53,25 +74,36 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
53
74
|
navigate('/403')
|
|
54
75
|
}
|
|
55
76
|
}
|
|
77
|
+
else {
|
|
78
|
+
navigate(`/${menus[0]?.key}/${menus[0]?.children?.[0]?.key}`)
|
|
79
|
+
}
|
|
56
80
|
}, [location])
|
|
57
81
|
|
|
58
82
|
|
|
59
83
|
// ********** 渲染 **********
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
84
|
+
const renderContent = () => {
|
|
85
|
+
if (!currentRouter) {
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
63
88
|
|
|
64
|
-
|
|
65
|
-
|
|
89
|
+
return (
|
|
90
|
+
<div className={styles.layoutContent}>
|
|
91
|
+
{!currentRouter?.showFullScreen && <Side />}
|
|
66
92
|
|
|
67
|
-
<div className={styles.
|
|
68
|
-
<
|
|
69
|
-
|
|
93
|
+
<div className={styles.wraper}>
|
|
94
|
+
{!currentRouter?.showFullScreen && <Header />}
|
|
95
|
+
|
|
96
|
+
<div className={styles.contentInner}>
|
|
97
|
+
<Outlet />
|
|
98
|
+
</div>
|
|
70
99
|
|
|
71
|
-
|
|
100
|
+
{!currentRouter?.showFullScreen && <Footer />}
|
|
101
|
+
</div>
|
|
72
102
|
</div>
|
|
73
|
-
|
|
74
|
-
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return renderContent()
|
|
75
107
|
}
|
|
76
108
|
|
|
77
109
|
export default Content
|
|
@@ -4,8 +4,7 @@ import type { MenuProps } from 'antd';
|
|
|
4
4
|
import {useNavigate, useLocation} from 'react-router-dom'
|
|
5
5
|
import {ComponentMap} from '@/router/router'
|
|
6
6
|
import { menusStore } from '@/store/menus'
|
|
7
|
-
import {
|
|
8
|
-
import { LOGIN_TOKEN } from '@/global/constants'
|
|
7
|
+
import { tokenStore } from '@/store/token'
|
|
9
8
|
|
|
10
9
|
import styles from './index.module.scss'
|
|
11
10
|
|
|
@@ -21,6 +20,7 @@ export const Side: React.FC<SideProps> = () => {
|
|
|
21
20
|
const location = useLocation()
|
|
22
21
|
const navigate = useNavigate()
|
|
23
22
|
const {menus} = menusStore()
|
|
23
|
+
const {token} = tokenStore()
|
|
24
24
|
|
|
25
25
|
// 激活的父菜单
|
|
26
26
|
const [openKeys, setOpenKeys] = React.useState<string[]>([])
|
|
@@ -45,32 +45,16 @@ export const Side: React.FC<SideProps> = () => {
|
|
|
45
45
|
const {pathname} = location ?? {}
|
|
46
46
|
const newPathname = pathname.slice(1)
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
|
|
49
|
+
const pathnameList = newPathname.split('/')
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
setOpenKeys([openKey])
|
|
56
|
-
setSelectedKeys([selectedKey])
|
|
57
|
-
navigate(`/${menus[0]?.key}/${menus[0]?.children?.[0]?.key}`)
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
navigate('/login')
|
|
61
|
-
}
|
|
51
|
+
if (pathnameList.length === 1) {
|
|
52
|
+
setOpenKeys([])
|
|
53
|
+
setSelectedKeys([pathnameList[0]])
|
|
62
54
|
}
|
|
63
|
-
else {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (pathnameList.length === 1) {
|
|
67
|
-
setOpenKeys([])
|
|
68
|
-
setSelectedKeys([pathnameList[0]])
|
|
69
|
-
}
|
|
70
|
-
else if (pathnameList.length === 2) {
|
|
71
|
-
setOpenKeys([pathnameList[0]])
|
|
72
|
-
setSelectedKeys([pathnameList[1]])
|
|
73
|
-
}
|
|
55
|
+
else if (pathnameList.length === 2 || pathnameList.length === 3) {
|
|
56
|
+
setOpenKeys([pathnameList[0]])
|
|
57
|
+
setSelectedKeys([pathnameList[1]])
|
|
74
58
|
}
|
|
75
59
|
}, [])
|
|
76
60
|
|
|
@@ -6,6 +6,8 @@ import { Footer } from '../footer'
|
|
|
6
6
|
import { routerConfig } from '@/router/router'
|
|
7
7
|
import type { RouterConfigItemProps } from '@/router/router'
|
|
8
8
|
import { permissionStore } from '@/store/permission'
|
|
9
|
+
import { tokenStore } from '@/store/token'
|
|
10
|
+
import { menusStore } from '@/store/menus'
|
|
9
11
|
|
|
10
12
|
import styles from './index.module.scss'
|
|
11
13
|
|
|
@@ -17,6 +19,8 @@ interface ContentProps {
|
|
|
17
19
|
const Content: React.FC<ContentProps> = ({ }) => {
|
|
18
20
|
const location = useLocation()
|
|
19
21
|
const navigate = useNavigate()
|
|
22
|
+
const {token} = tokenStore()
|
|
23
|
+
const {menus} = menusStore()
|
|
20
24
|
const {
|
|
21
25
|
permissions
|
|
22
26
|
} = permissionStore()
|
|
@@ -27,15 +31,28 @@ const Content: React.FC<ContentProps> = ({ }) => {
|
|
|
27
31
|
const { pathname } = location ?? {}
|
|
28
32
|
const newPathname = pathname.slice(1)
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
if (!token) {
|
|
35
|
+
navigate('/login')
|
|
36
|
+
}
|
|
37
|
+
else if (newPathname !== '') {
|
|
31
38
|
const pathnameList = newPathname.split('/')
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
const getCcondition = () => {
|
|
40
|
+
if (pathnameList.length === 1) {
|
|
41
|
+
return permissions.includes(pathnameList[0])
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (pathnameList.length === 2) {
|
|
45
|
+
return permissions.includes(pathnameList[1])
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (pathnameList.length === 3) {
|
|
49
|
+
return permissions.includes(`${pathnameList[1]}/${pathnameList[2]}`)
|
|
50
|
+
}
|
|
37
51
|
|
|
38
|
-
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (getCcondition()) {
|
|
39
56
|
let newCurrentRouter: any = {}
|
|
40
57
|
|
|
41
58
|
if (pathnameList.length === 1) {
|
|
@@ -45,6 +62,10 @@ const Content: React.FC<ContentProps> = ({ }) => {
|
|
|
45
62
|
const parent = routerConfig[0]?.children?.find((group: any) => group.key === pathnameList[0]) ?? {}
|
|
46
63
|
newCurrentRouter = parent?.children?.find((item: any) => item.key === pathnameList[1])
|
|
47
64
|
}
|
|
65
|
+
else if (pathnameList.length === 3) {
|
|
66
|
+
const parent = routerConfig[0]?.children?.find((group: any) => group.key === pathnameList[0]) ?? {}
|
|
67
|
+
newCurrentRouter = parent?.children?.find((item: any) => item.key === `${pathnameList[1]}/${pathnameList[2]}`)
|
|
68
|
+
}
|
|
48
69
|
|
|
49
70
|
setCurrentRouter(newCurrentRouter)
|
|
50
71
|
}
|
|
@@ -52,10 +73,18 @@ const Content: React.FC<ContentProps> = ({ }) => {
|
|
|
52
73
|
navigate('/403')
|
|
53
74
|
}
|
|
54
75
|
}
|
|
76
|
+
else {
|
|
77
|
+
navigate(`/${menus[0]?.key}/${menus[0]?.children?.[0]?.key}`)
|
|
78
|
+
}
|
|
55
79
|
}, [location])
|
|
56
80
|
|
|
57
81
|
// ********** 渲染 **********
|
|
58
|
-
|
|
82
|
+
const renderContent = () => {
|
|
83
|
+
if (!currentRouter) {
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
59
88
|
<div className={styles.layoutContent}>
|
|
60
89
|
<div className={styles.wraper}>
|
|
61
90
|
{!currentRouter?.showFullScreen && <Header />}
|
|
@@ -68,6 +97,9 @@ const Content: React.FC<ContentProps> = ({ }) => {
|
|
|
68
97
|
</div>
|
|
69
98
|
</div>
|
|
70
99
|
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return renderContent()
|
|
71
103
|
}
|
|
72
104
|
|
|
73
105
|
export default Content
|
|
@@ -44,33 +44,15 @@ export const Side: React.FC<SideProps> = ({}) => {
|
|
|
44
44
|
useEffect(() => {
|
|
45
45
|
const {pathname} = location ?? {}
|
|
46
46
|
const newPathname = pathname.slice(1)
|
|
47
|
+
const pathnameList = newPathname.split('/')
|
|
47
48
|
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (token) {
|
|
52
|
-
const openKey = menus[0]?.key
|
|
53
|
-
const selectedKey = menus[0]?.children?.[0]?.key
|
|
54
|
-
|
|
55
|
-
// setOpenKeys([openKey])
|
|
56
|
-
setSelectedKeys([selectedKey])
|
|
57
|
-
navigate(`/${menus[0]?.key}/${menus[0]?.children?.[0]?.key}`)
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
navigate('/login')
|
|
61
|
-
}
|
|
49
|
+
if (pathnameList.length === 1) {
|
|
50
|
+
setOpenKeys([])
|
|
51
|
+
setSelectedKeys([pathnameList[0]])
|
|
62
52
|
}
|
|
63
|
-
else {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (pathnameList.length === 1) {
|
|
67
|
-
setOpenKeys([])
|
|
68
|
-
setSelectedKeys([pathnameList[0]])
|
|
69
|
-
}
|
|
70
|
-
else if (pathnameList.length === 2) {
|
|
71
|
-
// setOpenKeys([pathnameList[0]])
|
|
72
|
-
setSelectedKeys([pathnameList[1]])
|
|
73
|
-
}
|
|
53
|
+
else if (pathnameList.length === 2 || pathnameList.length === 3) {
|
|
54
|
+
// setOpenKeys([pathnameList[0]])
|
|
55
|
+
setSelectedKeys([pathnameList[1]])
|
|
74
56
|
}
|
|
75
57
|
}, [])
|
|
76
58
|
|
|
@@ -3,6 +3,8 @@ import {useNavigate, useSearchParams} from 'react-router-dom'
|
|
|
3
3
|
import { Button, Checkbox, Form, Input } from 'antd'
|
|
4
4
|
import { permissionStore } from '@/store/permission'
|
|
5
5
|
import { menusStore } from '@/store/menus'
|
|
6
|
+
import {userInfoStore} from '@/store/login'
|
|
7
|
+
import {tokenStore} from '@/store/token'
|
|
6
8
|
import { filterMenu } from '@/utils'
|
|
7
9
|
import { routerConfig } from '@/router/router'
|
|
8
10
|
|
|
@@ -30,7 +32,9 @@ const defaultList = [
|
|
|
30
32
|
'group22',
|
|
31
33
|
'group23',
|
|
32
34
|
'group24',
|
|
33
|
-
'group3'
|
|
35
|
+
'group3',
|
|
36
|
+
'group11/detail',
|
|
37
|
+
'group11/screen-detail'
|
|
34
38
|
]
|
|
35
39
|
|
|
36
40
|
const Login: React.FC<LoginProps> = ({}) => {
|
|
@@ -41,6 +45,8 @@ const Login: React.FC<LoginProps> = ({}) => {
|
|
|
41
45
|
setPermissions
|
|
42
46
|
} = permissionStore()
|
|
43
47
|
const {setMenus} = menusStore()
|
|
48
|
+
const {setUserInfo} = userInfoStore()
|
|
49
|
+
const {setToken} = tokenStore()
|
|
44
50
|
|
|
45
51
|
// ********操作 ********
|
|
46
52
|
const onFinish = async (values: any) => {
|
|
@@ -48,6 +54,12 @@ const Login: React.FC<LoginProps> = ({}) => {
|
|
|
48
54
|
|
|
49
55
|
if (values.username === 'yang' && values.password === '123456') {
|
|
50
56
|
setPermissions(defaultList)
|
|
57
|
+
setToken('111')
|
|
58
|
+
setUserInfo({
|
|
59
|
+
userName: 'yang',
|
|
60
|
+
userId: '001'
|
|
61
|
+
})
|
|
62
|
+
|
|
51
63
|
|
|
52
64
|
// todo模拟接口
|
|
53
65
|
setTimeout(() => {
|
|
@@ -78,6 +78,11 @@ const Home: React.FC<HomeProps> = () => {
|
|
|
78
78
|
<p>Bla bla ...</p>
|
|
79
79
|
</Modal>
|
|
80
80
|
</div>
|
|
81
|
+
|
|
82
|
+
<div style={{ marginTop: 20 }}>
|
|
83
|
+
<Button onClick={() => navigate('/group1/group11/detail')}>详情</Button>
|
|
84
|
+
<Button onClick={() => navigate('/group1/group11/screen-detail')}>详情-全屏</Button>
|
|
85
|
+
</div>
|
|
81
86
|
</div>
|
|
82
87
|
)
|
|
83
88
|
}
|
|
@@ -47,6 +47,7 @@ export const routerConfig: any[] = [
|
|
|
47
47
|
key: 'group11',
|
|
48
48
|
icon: null,
|
|
49
49
|
hideInMenu: false,
|
|
50
|
+
showFullScreen: false,
|
|
50
51
|
element: <Home />
|
|
51
52
|
},
|
|
52
53
|
{
|
|
@@ -55,6 +56,7 @@ export const routerConfig: any[] = [
|
|
|
55
56
|
key: 'group12',
|
|
56
57
|
icon: null,
|
|
57
58
|
hideInMenu: false,
|
|
59
|
+
showFullScreen: false,
|
|
58
60
|
element: <>group12</>
|
|
59
61
|
},
|
|
60
62
|
{
|
|
@@ -63,8 +65,27 @@ export const routerConfig: any[] = [
|
|
|
63
65
|
key: 'group13',
|
|
64
66
|
icon: null,
|
|
65
67
|
hideInMenu: false,
|
|
68
|
+
showFullScreen: false,
|
|
66
69
|
element: <>group13</>
|
|
67
70
|
},
|
|
71
|
+
{
|
|
72
|
+
label: '分组11-详情',
|
|
73
|
+
path: 'group11/detail',
|
|
74
|
+
key: 'group11/detail',
|
|
75
|
+
icon: null,
|
|
76
|
+
hideInMenu: true,
|
|
77
|
+
showFullScreen: false,
|
|
78
|
+
element: <>分组11-详情</>
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: '分组11-详情-全屏',
|
|
82
|
+
path: 'group11/screen-detail',
|
|
83
|
+
key: 'group11/screen-detail',
|
|
84
|
+
icon: null,
|
|
85
|
+
hideInMenu: true,
|
|
86
|
+
showFullScreen: true,
|
|
87
|
+
element: <>分组11-详情-全屏</>
|
|
88
|
+
},
|
|
68
89
|
]
|
|
69
90
|
},
|
|
70
91
|
|
|
@@ -82,6 +103,7 @@ export const routerConfig: any[] = [
|
|
|
82
103
|
index: true,
|
|
83
104
|
icon: null,
|
|
84
105
|
hideInMenu: false,
|
|
106
|
+
showFullScreen: false,
|
|
85
107
|
element: <>group21</>,
|
|
86
108
|
},
|
|
87
109
|
{
|
|
@@ -90,6 +112,7 @@ export const routerConfig: any[] = [
|
|
|
90
112
|
key: 'group22',
|
|
91
113
|
icon: null,
|
|
92
114
|
hideInMenu: false,
|
|
115
|
+
showFullScreen: false,
|
|
93
116
|
element: <>group22</>,
|
|
94
117
|
},
|
|
95
118
|
{
|
|
@@ -98,6 +121,7 @@ export const routerConfig: any[] = [
|
|
|
98
121
|
key: 'group23',
|
|
99
122
|
icon: null,
|
|
100
123
|
hideInMenu: false,
|
|
124
|
+
showFullScreen: false,
|
|
101
125
|
element: <>group23</>,
|
|
102
126
|
},
|
|
103
127
|
{
|
|
@@ -118,6 +142,7 @@ export const routerConfig: any[] = [
|
|
|
118
142
|
key: 'group3',
|
|
119
143
|
icon: 'icon-2',
|
|
120
144
|
hideInMenu: false,
|
|
145
|
+
showFullScreen: true,
|
|
121
146
|
element: <>group3</>
|
|
122
147
|
}
|
|
123
148
|
]
|
|
@@ -155,6 +180,7 @@ export const routerConfig: any[] = [
|
|
|
155
180
|
element: <Page404 />,
|
|
156
181
|
icon: null,
|
|
157
182
|
hideInMenu: true,
|
|
183
|
+
showFullScreen: true,
|
|
158
184
|
children: [],
|
|
159
185
|
},
|
|
160
186
|
]
|
|
@@ -103,7 +103,7 @@ instance.interceptors.request.use(
|
|
|
103
103
|
addPendingRequest(config)
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
const token = localCache.getCache(LOGIN_TOKEN)
|
|
106
|
+
const token = localCache.getCache(LOGIN_TOKEN)?.state?.token
|
|
107
107
|
|
|
108
108
|
if (config.headers && token) {
|
|
109
109
|
config.headers.Authorization = `Bearer ${token}`
|
|
@@ -9,15 +9,13 @@ type UserInfoStoreState = {
|
|
|
9
9
|
userInfo: {
|
|
10
10
|
userId: string,
|
|
11
11
|
userName: string
|
|
12
|
-
}
|
|
13
|
-
token: string
|
|
12
|
+
}
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
type UserInfoStoreActions = {
|
|
17
16
|
setUserInfo: (
|
|
18
17
|
userInfo: UserInfoStoreState['userInfo']
|
|
19
|
-
) => void
|
|
20
|
-
setToken: (token: string) => void
|
|
18
|
+
) => void
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
type UserInfoStore = UserInfoStoreState & UserInfoStoreActions
|
|
@@ -29,9 +27,7 @@ export const userInfoStore = create<UserInfoStore>()(
|
|
|
29
27
|
userName: '小明',
|
|
30
28
|
userId: '111'
|
|
31
29
|
},
|
|
32
|
-
token: '',
|
|
33
30
|
setUserInfo: (userInfo) => set({userInfo}),
|
|
34
|
-
setToken: (token) => set({token})
|
|
35
31
|
}),
|
|
36
32
|
{
|
|
37
33
|
name: USER_INFO
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * 用户信息
|
|
3
|
+
*/
|
|
4
|
+
import { create } from 'zustand'
|
|
5
|
+
import { persist } from 'zustand/middleware'
|
|
6
|
+
import { LOGIN_TOKEN} from '@/global/constants'
|
|
7
|
+
|
|
8
|
+
type UserInfoStoreState = {
|
|
9
|
+
token: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type UserInfoStoreActions = {
|
|
13
|
+
setToken: (token: string) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type UserInfoStore = UserInfoStoreState & UserInfoStoreActions
|
|
17
|
+
|
|
18
|
+
export const tokenStore = create<UserInfoStore>()(
|
|
19
|
+
persist(
|
|
20
|
+
(set) => ({
|
|
21
|
+
token: '',
|
|
22
|
+
setToken: (token) => set({token})
|
|
23
|
+
}),
|
|
24
|
+
{
|
|
25
|
+
name: LOGIN_TOKEN
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
)
|