@yyp92-cli/template-react-mobile 1.3.0 → 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
CHANGED
package/package.json
CHANGED
|
@@ -4,10 +4,11 @@ import NavBar from '../navBar'
|
|
|
4
4
|
import TabBar from '../tabBar'
|
|
5
5
|
import { permissionStore } from '@/store/permission'
|
|
6
6
|
import { routerConfig, type RouterConfigItemProps } from '@/router/router'
|
|
7
|
-
|
|
8
|
-
import styles from './index.module.scss'
|
|
9
7
|
import { localCache } from '@/utils'
|
|
10
8
|
import { LOGIN_TOKEN } from '@/global/constants'
|
|
9
|
+
import { tokenStore } from '@/store/token'
|
|
10
|
+
|
|
11
|
+
import styles from './index.module.scss'
|
|
11
12
|
|
|
12
13
|
interface ContentProps {
|
|
13
14
|
[key: string]: any
|
|
@@ -20,6 +21,7 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
20
21
|
const {
|
|
21
22
|
permissions
|
|
22
23
|
} = permissionStore()
|
|
24
|
+
const {token} = tokenStore()
|
|
23
25
|
|
|
24
26
|
const [currentRouter, setCurrentRouter] = useState<RouterConfigItemProps>()
|
|
25
27
|
|
|
@@ -27,7 +29,10 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
27
29
|
const {pathname} = location ?? {}
|
|
28
30
|
const newPathname = pathname.slice(1)
|
|
29
31
|
|
|
30
|
-
if (
|
|
32
|
+
if (!token) {
|
|
33
|
+
navigate('/login')
|
|
34
|
+
}
|
|
35
|
+
else if (newPathname !== '') {
|
|
31
36
|
if (permissions.includes(newPathname)) {
|
|
32
37
|
const newCurrentRouter: any = routerConfig[0]?.children?.find((group: any) => group.key === newPathname) ?? {}
|
|
33
38
|
|
|
@@ -38,11 +43,9 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
else {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
navigate('/login')
|
|
45
|
-
}
|
|
46
|
+
const newCurrentRouter: any = routerConfig[0]?.children?.find((group: any) => permissions.includes(group.key) ) ?? {}
|
|
47
|
+
setCurrentRouter(newCurrentRouter)
|
|
48
|
+
navigate(newCurrentRouter.path)
|
|
46
49
|
}
|
|
47
50
|
}, [location])
|
|
48
51
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {useNavigate
|
|
1
|
+
import {FC, useState, useEffect, useLayoutEffect} from 'react'
|
|
2
|
+
import {useNavigate} from 'react-router-dom'
|
|
3
3
|
import {TabBar as AntTabBar} from 'antd-mobile'
|
|
4
|
-
import
|
|
4
|
+
import { ComponentMap } from '@/router/router'
|
|
5
5
|
import styles from './index.module.scss'
|
|
6
6
|
import { menusStore } from '@/store/menus'
|
|
7
7
|
|
|
@@ -9,7 +9,6 @@ interface TabBarProps {}
|
|
|
9
9
|
|
|
10
10
|
const TabBar: FC<TabBarProps> = () => {
|
|
11
11
|
const navigate = useNavigate()
|
|
12
|
-
const newLocation = useLocation()
|
|
13
12
|
const {menus} = menusStore()
|
|
14
13
|
|
|
15
14
|
const [tabs, setTabs] = useState<any[]>([])
|
|
@@ -105,7 +105,7 @@ instance.interceptors.request.use(
|
|
|
105
105
|
addPendingRequest(config)
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
const token = localCache.getCache(LOGIN_TOKEN)
|
|
108
|
+
const token = localCache.getCache(LOGIN_TOKEN)?.state?.token
|
|
109
109
|
|
|
110
110
|
if (config.headers && token) {
|
|
111
111
|
config.headers.Authorization = `Bearer ${token}`
|