@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @yyp92-cli/template-react-pc
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 路由修改
8
+
3
9
  ## 1.3.0
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yyp92-cli/template-react-pc",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -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 (newPathname !== '') {
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 { localCache } from '@/utils'
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
- if (newPathname === '') {
49
- const token = localCache.getCache(LOGIN_TOKEN)
48
+
49
+ const pathnameList = newPathname.split('/')
50
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
- }
51
+ if (pathnameList.length === 1) {
52
+ setOpenKeys([])
53
+ setSelectedKeys([pathnameList[0]])
62
54
  }
63
- else {
64
- const pathnameList = newPathname.split('/')
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
- if (newPathname !== '') {
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 (newPathname === '') {
49
- const token = localCache.getCache(LOGIN_TOKEN)
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
- const pathnameList = newPathname.split('/')
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
- // import Layout from '@/components/layout'
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}`