@yyp92-cli/template-react-pc 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 +6 -0
- package/package.json +1 -1
- package/template/src/components/layout/content/index.tsx +11 -1
- package/template/src/components/layout/side/index.tsx +10 -26
- package/template/src/components/layout-horizontal/content/index.tsx +11 -1
- package/template/src/components/layout-horizontal/side/index.tsx +7 -25
- package/template/src/router/router.tsx +2 -2
- package/template/src/service/request/index.ts +1 -1
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,6 +23,8 @@ 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
29
|
const [currentRouter, setCurrentRouter] = useState<RouterConfigItemProps | any>()
|
|
26
30
|
|
|
@@ -28,7 +32,10 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
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
40
|
const getCcondition = () => {
|
|
34
41
|
if (pathnameList.length === 1) {
|
|
@@ -67,6 +74,9 @@ const Content: React.FC<ContentProps> = ({}) => {
|
|
|
67
74
|
navigate('/403')
|
|
68
75
|
}
|
|
69
76
|
}
|
|
77
|
+
else {
|
|
78
|
+
navigate(`/${menus[0]?.key}/${menus[0]?.children?.[0]?.key}`)
|
|
79
|
+
}
|
|
70
80
|
}, [location])
|
|
71
81
|
|
|
72
82
|
|
|
@@ -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 || pathnameList.length === 3) {
|
|
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,7 +31,10 @@ 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
39
|
const getCcondition = () => {
|
|
33
40
|
if (pathnameList.length === 1) {
|
|
@@ -66,6 +73,9 @@ const Content: React.FC<ContentProps> = ({ }) => {
|
|
|
66
73
|
navigate('/403')
|
|
67
74
|
}
|
|
68
75
|
}
|
|
76
|
+
else {
|
|
77
|
+
navigate(`/${menus[0]?.key}/${menus[0]?.children?.[0]?.key}`)
|
|
78
|
+
}
|
|
69
79
|
}, [location])
|
|
70
80
|
|
|
71
81
|
// ********** 渲染 **********
|
|
@@ -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 || pathnameList.length === 3) {
|
|
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
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import {createBrowserRouter} from 'react-router-dom'
|
|
3
3
|
import { AppstoreOutlined, MailOutlined, NodeCollapseOutlined, SettingOutlined } from '@ant-design/icons';
|
|
4
|
-
|
|
5
|
-
import Layout from '@/components/layout-horizontal'
|
|
4
|
+
import Layout from '@/components/layout'
|
|
5
|
+
// import Layout from '@/components/layout-horizontal'
|
|
6
6
|
import Home from '@/pages/home'
|
|
7
7
|
import { Page403 } from '@/components/403'
|
|
8
8
|
import { Page404 } from '@/components/404'
|
|
@@ -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}`
|