@yyp92-cli/template-react-pc 2.1.0 → 2.2.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/package.json +4 -1
- package/CHANGELOG.md +0 -55
- package/template/.env.development +0 -5
- package/template/.env.production +0 -4
- package/template/.env.test +0 -4
- package/template/.eslintrc.cjs +0 -18
- package/template/README.md +0 -15
- package/template/index.html +0 -13
- package/template/package.json +0 -42
- package/template/pnpm-lock.yaml +0 -3570
- package/template/public/vite.svg +0 -1
- package/template/src/antdTheme/darkTheme.ts +0 -285
- package/template/src/antdTheme/lightTheme.ts +0 -286
- package/template/src/app.scss +0 -29
- package/template/src/app.tsx +0 -14
- package/template/src/assets/iconfont/demo.css +0 -539
- package/template/src/assets/iconfont/demo_index.html +0 -211
- package/template/src/assets/iconfont/iconfont.css +0 -19
- package/template/src/assets/iconfont/iconfont.js +0 -1
- package/template/src/assets/iconfont/iconfont.json +0 -16
- package/template/src/assets/iconfont/iconfont.ttf +0 -0
- package/template/src/assets/iconfont/iconfont.woff +0 -0
- package/template/src/assets/iconfont/iconfont.woff2 +0 -0
- package/template/src/assets/react.svg +0 -1
- package/template/src/components/403/index.tsx +0 -22
- package/template/src/components/404/index.tsx +0 -24
- package/template/src/components/index.ts +0 -3
- package/template/src/components/layout/content/index.module.scss +0 -22
- package/template/src/components/layout/content/index.tsx +0 -109
- package/template/src/components/layout/footer/index.module.scss +0 -12
- package/template/src/components/layout/footer/index.tsx +0 -15
- package/template/src/components/layout/header/index.module.scss +0 -21
- package/template/src/components/layout/header/index.tsx +0 -115
- package/template/src/components/layout/index.module.scss +0 -8
- package/template/src/components/layout/index.tsx +0 -47
- package/template/src/components/layout/side/index.module.scss +0 -31
- package/template/src/components/layout/side/index.tsx +0 -109
- package/template/src/components/layout-horizontal/content/index.module.scss +0 -22
- package/template/src/components/layout-horizontal/content/index.tsx +0 -105
- package/template/src/components/layout-horizontal/footer/index.module.scss +0 -12
- package/template/src/components/layout-horizontal/footer/index.tsx +0 -15
- package/template/src/components/layout-horizontal/header/index.module.scss +0 -23
- package/template/src/components/layout-horizontal/header/index.tsx +0 -115
- package/template/src/components/layout-horizontal/index.module.scss +0 -8
- package/template/src/components/layout-horizontal/index.tsx +0 -48
- package/template/src/components/layout-horizontal/side/index.module.scss +0 -32
- package/template/src/components/layout-horizontal/side/index.tsx +0 -104
- package/template/src/components/login/index.module.scss +0 -23
- package/template/src/components/login/index.tsx +0 -133
- package/template/src/global/constants.ts +0 -5
- package/template/src/pages/home/index.module.scss +0 -0
- package/template/src/pages/home/index.tsx +0 -90
- package/template/src/router/router.tsx +0 -190
- package/template/src/service/api.ts +0 -9
- package/template/src/service/config.ts +0 -9
- package/template/src/service/index.ts +0 -1
- package/template/src/service/request/index.ts +0 -267
- package/template/src/service/request/type.ts +0 -5
- package/template/src/service/service.ts +0 -27
- package/template/src/store/antdToken.ts +0 -35
- package/template/src/store/login.ts +0 -38
- package/template/src/store/menus.ts +0 -30
- package/template/src/store/permission.ts +0 -30
- package/template/src/store/token.ts +0 -30
- package/template/src/theme/darkTheme.scss +0 -47
- package/template/src/theme/lightTheme.scss +0 -49
- package/template/src/utils/base64ToBlob.ts +0 -41
- package/template/src/utils/cache.ts +0 -44
- package/template/src/utils/changeTheme.ts +0 -14
- package/template/src/utils/download.ts +0 -45
- package/template/src/utils/filterMenu.ts +0 -34
- package/template/src/utils/index.ts +0 -5
- package/template/src/vite-env.d.ts +0 -5
- package/template/tsconfig.json +0 -45
- package/template/tsconfig.node.json +0 -10
- package/template/vite.config.ts +0 -49
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react'
|
|
2
|
-
import { ConfigProvider } from 'antd'
|
|
3
|
-
import dayjs from 'dayjs';
|
|
4
|
-
import 'dayjs/locale/zh-cn';
|
|
5
|
-
import zhCN from 'antd/locale/zh_CN'
|
|
6
|
-
import { antdTokenStore } from '@/store/antdToken'
|
|
7
|
-
import { getDarkTheme } from '@/utils'
|
|
8
|
-
import Content from './content'
|
|
9
|
-
|
|
10
|
-
import styles from './index.module.scss'
|
|
11
|
-
|
|
12
|
-
interface LayoutProps {
|
|
13
|
-
[key: string]: any
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const Layout: React.FC<LayoutProps> = ({ }) => {
|
|
17
|
-
const {antdToken} = antdTokenStore()
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
getDarkTheme(false)
|
|
21
|
-
dayjs.locale('zh-cn')
|
|
22
|
-
}, [])
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// ********** 操作 **********
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// ********** 渲染 **********
|
|
29
|
-
return (
|
|
30
|
-
<div className={styles.layout}>
|
|
31
|
-
<ConfigProvider
|
|
32
|
-
// 主题
|
|
33
|
-
theme={antdToken}
|
|
34
|
-
locale={zhCN}
|
|
35
|
-
|
|
36
|
-
button={{
|
|
37
|
-
// 设置为 false 时,移除按钮中 2 个汉字之间的空格
|
|
38
|
-
autoInsertSpace: false,
|
|
39
|
-
}}
|
|
40
|
-
>
|
|
41
|
-
<Content />
|
|
42
|
-
</ConfigProvider>
|
|
43
|
-
</div>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default Layout
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
.side {
|
|
2
|
-
flex-shrink: 0;
|
|
3
|
-
width: 200px;
|
|
4
|
-
height: 100%;
|
|
5
|
-
display: flex;
|
|
6
|
-
flex-direction: column;
|
|
7
|
-
|
|
8
|
-
.logo {
|
|
9
|
-
height: 50px;
|
|
10
|
-
box-sizing: border-box;
|
|
11
|
-
flex-shrink: 0;
|
|
12
|
-
display: flex;
|
|
13
|
-
align-items: center;
|
|
14
|
-
justify-content: center;
|
|
15
|
-
border-bottom: 1px solid var(--border-color-base);
|
|
16
|
-
border-right: 1px solid var(--border-color-base);
|
|
17
|
-
|
|
18
|
-
img {
|
|
19
|
-
width: 32px;
|
|
20
|
-
height: 32px;
|
|
21
|
-
margin-right: 12px;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.menu {
|
|
27
|
-
flex: 1;
|
|
28
|
-
overflow-y: auto;
|
|
29
|
-
border-right: 1px solid var(--border-color-base) !important;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import React, {useEffect, useLayoutEffect} from 'react'
|
|
2
|
-
import {Menu} from 'antd'
|
|
3
|
-
import type { MenuProps } from 'antd';
|
|
4
|
-
import {useNavigate, useLocation} from 'react-router-dom'
|
|
5
|
-
import {ComponentMap} from '@/router/router'
|
|
6
|
-
import { menusStore } from '@/store/menus'
|
|
7
|
-
import { tokenStore } from '@/store/token'
|
|
8
|
-
|
|
9
|
-
import styles from './index.module.scss'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type MenuItem = Required<MenuProps>['items'][number];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
interface SideProps {
|
|
16
|
-
[key: string]: any
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const Side: React.FC<SideProps> = () => {
|
|
20
|
-
const location = useLocation()
|
|
21
|
-
const navigate = useNavigate()
|
|
22
|
-
const {menus} = menusStore()
|
|
23
|
-
const {token} = tokenStore()
|
|
24
|
-
|
|
25
|
-
// 激活的父菜单
|
|
26
|
-
const [openKeys, setOpenKeys] = React.useState<string[]>([])
|
|
27
|
-
// 激活的菜单项
|
|
28
|
-
const [selectedKeys, setSelectedKeys] = React.useState<string[]>([])
|
|
29
|
-
// 菜单
|
|
30
|
-
const [newMenuList, setNewMenuList] = React.useState<MenuItem[]>([])
|
|
31
|
-
|
|
32
|
-
useLayoutEffect(() => {
|
|
33
|
-
const newMenuList = menus.map((item: any) => {
|
|
34
|
-
const Icon = ComponentMap[item.icon]
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
...item,
|
|
38
|
-
icon: <Icon />
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
setNewMenuList(newMenuList)
|
|
42
|
-
}, [menus])
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
const {pathname} = location ?? {}
|
|
46
|
-
const newPathname = pathname.slice(1)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const pathnameList = newPathname.split('/')
|
|
50
|
-
|
|
51
|
-
if (pathnameList.length === 1) {
|
|
52
|
-
setOpenKeys([])
|
|
53
|
-
setSelectedKeys([pathnameList[0]])
|
|
54
|
-
}
|
|
55
|
-
else if (pathnameList.length === 2 || pathnameList.length === 3) {
|
|
56
|
-
setOpenKeys([pathnameList[0]])
|
|
57
|
-
setSelectedKeys([pathnameList[1]])
|
|
58
|
-
}
|
|
59
|
-
}, [])
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// ********* 操作 ********
|
|
63
|
-
const onMenuItemOpenChange: MenuProps['onOpenChange'] = (openKeys: string[]) => {
|
|
64
|
-
const currentKey = openKeys.slice(-1)
|
|
65
|
-
setOpenKeys(currentKey)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const onMenuItemClick: MenuProps['onClick'] = (e: any) => {
|
|
69
|
-
const {keyPath} = e ?? {}
|
|
70
|
-
|
|
71
|
-
if (keyPath.length === 1) {
|
|
72
|
-
setSelectedKeys(keyPath[0])
|
|
73
|
-
navigate(`/${keyPath[0]}`)
|
|
74
|
-
}
|
|
75
|
-
else if (keyPath.length === 2) {
|
|
76
|
-
setSelectedKeys(keyPath[0])
|
|
77
|
-
navigate(`/${keyPath[1]}/${keyPath[0]}`)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// ********* 渲染 ********
|
|
83
|
-
return (
|
|
84
|
-
<div className={styles.side}>
|
|
85
|
-
<div className={styles.logo}>
|
|
86
|
-
<img
|
|
87
|
-
src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
|
|
88
|
-
alt="logo"
|
|
89
|
-
/>
|
|
90
|
-
|
|
91
|
-
<span>后台管理系统</span>
|
|
92
|
-
</div>
|
|
93
|
-
|
|
94
|
-
<Menu
|
|
95
|
-
className={styles.menu}
|
|
96
|
-
style={{
|
|
97
|
-
width: 200,
|
|
98
|
-
height: '100%'
|
|
99
|
-
}}
|
|
100
|
-
mode={'inline'}
|
|
101
|
-
items={newMenuList}
|
|
102
|
-
openKeys={openKeys}
|
|
103
|
-
selectedKeys={selectedKeys}
|
|
104
|
-
onOpenChange={onMenuItemOpenChange}
|
|
105
|
-
onClick={onMenuItemClick}
|
|
106
|
-
/>
|
|
107
|
-
</div>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
.layoutContent {
|
|
2
|
-
flex: 1;
|
|
3
|
-
width: 100%;
|
|
4
|
-
height: 100%;
|
|
5
|
-
display: flex;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.wraper {
|
|
9
|
-
flex: 1;
|
|
10
|
-
width: 100%;
|
|
11
|
-
height: 100%;
|
|
12
|
-
display: flex;
|
|
13
|
-
flex-direction: column;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.contentInner {
|
|
17
|
-
flex: 1;
|
|
18
|
-
display: flex;
|
|
19
|
-
flex-direction: column;
|
|
20
|
-
box-sizing: border-box;
|
|
21
|
-
padding: 16px 20px;
|
|
22
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import React, {useState, useEffect} from 'react'
|
|
2
|
-
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
|
|
3
|
-
|
|
4
|
-
import { Header } from '../header'
|
|
5
|
-
import { Footer } from '../footer'
|
|
6
|
-
import { routerConfig } from '@/router/router'
|
|
7
|
-
import type { RouterConfigItemProps } from '@/router/router'
|
|
8
|
-
import { permissionStore } from '@/store/permission'
|
|
9
|
-
import { tokenStore } from '@/store/token'
|
|
10
|
-
import { menusStore } from '@/store/menus'
|
|
11
|
-
|
|
12
|
-
import styles from './index.module.scss'
|
|
13
|
-
|
|
14
|
-
interface ContentProps {
|
|
15
|
-
[key: string]: any
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const Content: React.FC<ContentProps> = ({ }) => {
|
|
20
|
-
const location = useLocation()
|
|
21
|
-
const navigate = useNavigate()
|
|
22
|
-
const {token} = tokenStore()
|
|
23
|
-
const {menus} = menusStore()
|
|
24
|
-
const {
|
|
25
|
-
permissions
|
|
26
|
-
} = permissionStore()
|
|
27
|
-
|
|
28
|
-
const [currentRouter, setCurrentRouter] = useState<RouterConfigItemProps>()
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
const { pathname } = location ?? {}
|
|
32
|
-
const newPathname = pathname.slice(1)
|
|
33
|
-
|
|
34
|
-
if (!token) {
|
|
35
|
-
navigate('/login')
|
|
36
|
-
}
|
|
37
|
-
else if (newPathname !== '') {
|
|
38
|
-
const pathnameList = newPathname.split('/')
|
|
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
|
-
}
|
|
51
|
-
|
|
52
|
-
return false
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (getCcondition()) {
|
|
56
|
-
let newCurrentRouter: any = {}
|
|
57
|
-
|
|
58
|
-
if (pathnameList.length === 1) {
|
|
59
|
-
newCurrentRouter = routerConfig[0]?.children?.find((group: any) => group.key === pathnameList[0]) ?? {}
|
|
60
|
-
}
|
|
61
|
-
else if (pathnameList.length === 2) {
|
|
62
|
-
const parent = routerConfig[0]?.children?.find((group: any) => group.key === pathnameList[0]) ?? {}
|
|
63
|
-
newCurrentRouter = parent?.children?.find((item: any) => item.key === pathnameList[1])
|
|
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
|
-
}
|
|
69
|
-
|
|
70
|
-
setCurrentRouter(newCurrentRouter)
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
navigate('/403')
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
navigate(`/${menus[0]?.key}/${menus[0]?.children?.[0]?.key}`)
|
|
78
|
-
}
|
|
79
|
-
}, [location])
|
|
80
|
-
|
|
81
|
-
// ********** 渲染 **********
|
|
82
|
-
const renderContent = () => {
|
|
83
|
-
if (!currentRouter) {
|
|
84
|
-
return null
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<div className={styles.layoutContent}>
|
|
89
|
-
<div className={styles.wraper}>
|
|
90
|
-
{!currentRouter?.showFullScreen && <Header />}
|
|
91
|
-
|
|
92
|
-
<div className={styles.contentInner}>
|
|
93
|
-
<Outlet />
|
|
94
|
-
</div>
|
|
95
|
-
|
|
96
|
-
{!currentRouter?.showFullScreen && <Footer />}
|
|
97
|
-
</div>
|
|
98
|
-
</div>
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return renderContent()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export default Content
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
.footer {
|
|
2
|
-
flex-shrink: 0;
|
|
3
|
-
width: 100%;
|
|
4
|
-
height: 50px;
|
|
5
|
-
box-sizing: border-box;
|
|
6
|
-
border-top: 1px solid var(--border-color-base);
|
|
7
|
-
display: flex;
|
|
8
|
-
justify-content: center;
|
|
9
|
-
align-items: center;
|
|
10
|
-
font-size: 12px;
|
|
11
|
-
background: var(--bg-grey-color);
|
|
12
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
import styles from './index.module.scss'
|
|
4
|
-
|
|
5
|
-
interface FooterProps {
|
|
6
|
-
[key: string]: any
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const Footer: React.FC<FooterProps> = ({}) => {
|
|
10
|
-
return (
|
|
11
|
-
<div className={styles.footer}>
|
|
12
|
-
<div>财务系统注意事项</div>
|
|
13
|
-
</div>
|
|
14
|
-
)
|
|
15
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
.header {
|
|
2
|
-
box-sizing: border-box;
|
|
3
|
-
flex-shrink: 0;
|
|
4
|
-
width: 100%;
|
|
5
|
-
height: 50px;
|
|
6
|
-
padding: 0 20px;
|
|
7
|
-
display: flex;
|
|
8
|
-
justify-content: space-between;
|
|
9
|
-
align-items: center;
|
|
10
|
-
border-bottom: 1px solid var(--border-color-base);
|
|
11
|
-
|
|
12
|
-
.avatar {
|
|
13
|
-
flex-shrink: 0;
|
|
14
|
-
margin-left: 20px;
|
|
15
|
-
display: flex;
|
|
16
|
-
align-items: center;
|
|
17
|
-
|
|
18
|
-
& > div {
|
|
19
|
-
margin-left: 10px;
|
|
20
|
-
font-size: 12px;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
2
|
-
import {useNavigate} from 'react-router-dom'
|
|
3
|
-
import { Avatar, Button, Dropdown, Switch, Tooltip } from 'antd'
|
|
4
|
-
import type { MenuProps } from 'antd'
|
|
5
|
-
import { FullscreenExitOutlined, FullscreenOutlined, UserOutlined } from '@ant-design/icons'
|
|
6
|
-
import { getDarkTheme } from '@/utils'
|
|
7
|
-
import { userInfoStore } from '@/store/login'
|
|
8
|
-
import { antdTokenStore } from '@/store/antdToken'
|
|
9
|
-
import { tokenStore } from '@/store/token'
|
|
10
|
-
import { menusStore } from '@/store/menus'
|
|
11
|
-
import { permissionStore } from '@/store/permission'
|
|
12
|
-
import {Side} from '../side'
|
|
13
|
-
|
|
14
|
-
import styles from './index.module.scss'
|
|
15
|
-
|
|
16
|
-
interface HeaderProps {
|
|
17
|
-
[key: string]: any
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const Header: React.FC<HeaderProps> = ({}) => {
|
|
21
|
-
const navigate = useNavigate()
|
|
22
|
-
const {clearUserInfo} = userInfoStore()
|
|
23
|
-
const {setAntdToken} = antdTokenStore()
|
|
24
|
-
const {clearToken} = tokenStore()
|
|
25
|
-
const {clearMenus} = menusStore()
|
|
26
|
-
const {clearPermissions} = permissionStore()
|
|
27
|
-
const [isFullScreen, setIsFullScreen] = useState<boolean>(false)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// ********* 操作 *********
|
|
31
|
-
const handleLogout = () => {
|
|
32
|
-
clearToken()
|
|
33
|
-
clearUserInfo()
|
|
34
|
-
clearMenus()
|
|
35
|
-
clearPermissions()
|
|
36
|
-
|
|
37
|
-
navigate('/login')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const handleFullScreen = () => {
|
|
41
|
-
// dom对象的一个属性:可以用来判断当前是不是全屏模式
|
|
42
|
-
// 全屏:true, 不是全屏:false
|
|
43
|
-
const full = document.fullscreenElement
|
|
44
|
-
|
|
45
|
-
if (!full) {
|
|
46
|
-
setIsFullScreen(true)
|
|
47
|
-
document.documentElement.requestFullscreen()
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
setIsFullScreen(false)
|
|
51
|
-
document.exitFullscreen()
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const handleChangeTheme = (checked: boolean) => {
|
|
56
|
-
getDarkTheme(checked)
|
|
57
|
-
setAntdToken(checked)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// ********* 渲染 *********
|
|
62
|
-
const items: MenuProps['items'] = [
|
|
63
|
-
{
|
|
64
|
-
label: (
|
|
65
|
-
<div
|
|
66
|
-
onClick={handleLogout}
|
|
67
|
-
>退出登录</div>
|
|
68
|
-
),
|
|
69
|
-
key: '0',
|
|
70
|
-
},
|
|
71
|
-
]
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<div className={styles.header}>
|
|
75
|
-
<Side />
|
|
76
|
-
|
|
77
|
-
<div className={styles.avatar}>
|
|
78
|
-
<Tooltip title="切换主题">
|
|
79
|
-
<Switch
|
|
80
|
-
checkedChildren="暗黑"
|
|
81
|
-
unCheckedChildren="明亮"
|
|
82
|
-
defaultChecked={false}
|
|
83
|
-
onChange={handleChangeTheme}
|
|
84
|
-
/>
|
|
85
|
-
</Tooltip>
|
|
86
|
-
|
|
87
|
-
<Tooltip title="全屏">
|
|
88
|
-
<Button
|
|
89
|
-
style={{
|
|
90
|
-
margin: '0 10px'
|
|
91
|
-
}}
|
|
92
|
-
shape="circle"
|
|
93
|
-
icon={
|
|
94
|
-
!isFullScreen
|
|
95
|
-
? <FullscreenOutlined />
|
|
96
|
-
: <FullscreenExitOutlined />
|
|
97
|
-
}
|
|
98
|
-
onClick={handleFullScreen}
|
|
99
|
-
/>
|
|
100
|
-
</Tooltip>
|
|
101
|
-
|
|
102
|
-
<Avatar
|
|
103
|
-
style={{ backgroundColor: '#87d068' }}
|
|
104
|
-
icon={<UserOutlined />}
|
|
105
|
-
/>
|
|
106
|
-
|
|
107
|
-
<Dropdown
|
|
108
|
-
menu={{ items }}
|
|
109
|
-
>
|
|
110
|
-
<div>{'xxx 已登录'}</div>
|
|
111
|
-
</Dropdown>
|
|
112
|
-
</div>
|
|
113
|
-
</div>
|
|
114
|
-
)
|
|
115
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react'
|
|
2
|
-
import { ConfigProvider } from 'antd'
|
|
3
|
-
import dayjs from 'dayjs';
|
|
4
|
-
import 'dayjs/locale/zh-cn';
|
|
5
|
-
import zhCN from 'antd/locale/zh_CN';
|
|
6
|
-
import { getDarkTheme } from '@/utils'
|
|
7
|
-
import { antdTokenStore } from '@/store/antdToken'
|
|
8
|
-
import Content from './content'
|
|
9
|
-
|
|
10
|
-
import styles from './index.module.scss'
|
|
11
|
-
|
|
12
|
-
interface LayoutProps {
|
|
13
|
-
[key: string]: any
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const Layout: React.FC<LayoutProps> = ({ }) => {
|
|
17
|
-
const {antdToken} = antdTokenStore()
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
getDarkTheme(false)
|
|
21
|
-
dayjs.locale('zh-cn')
|
|
22
|
-
}, [])
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// ********** 操作 **********
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// ********** 渲染 **********
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<div className={styles.layout}>
|
|
32
|
-
<ConfigProvider
|
|
33
|
-
// 主题
|
|
34
|
-
theme={antdToken}
|
|
35
|
-
locale={zhCN}
|
|
36
|
-
|
|
37
|
-
button={{
|
|
38
|
-
// 设置为 false 时,移除按钮中 2 个汉字之间的空格
|
|
39
|
-
autoInsertSpace: false,
|
|
40
|
-
}}
|
|
41
|
-
>
|
|
42
|
-
<Content />
|
|
43
|
-
</ConfigProvider>
|
|
44
|
-
</div>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default Layout
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
.side {
|
|
2
|
-
flex: 1;
|
|
3
|
-
width: 100%;
|
|
4
|
-
height: 100%;
|
|
5
|
-
display: flex;
|
|
6
|
-
overflow: hidden;
|
|
7
|
-
|
|
8
|
-
.logo {
|
|
9
|
-
width: 169px;
|
|
10
|
-
height: 50px;
|
|
11
|
-
box-sizing: border-box;
|
|
12
|
-
flex-shrink: 0;
|
|
13
|
-
display: flex;
|
|
14
|
-
align-items: center;
|
|
15
|
-
justify-content: center;
|
|
16
|
-
border-right: 1px solid var(--border-color-base);
|
|
17
|
-
border-bottom: none;
|
|
18
|
-
|
|
19
|
-
img {
|
|
20
|
-
width: 32px;
|
|
21
|
-
height: 32px;
|
|
22
|
-
margin-right: 12px;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.menu {
|
|
28
|
-
flex: 1;
|
|
29
|
-
overflow-x: auto;
|
|
30
|
-
overflow-y: hidden;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import React, {useEffect, useLayoutEffect} from 'react'
|
|
2
|
-
import {Menu} from 'antd'
|
|
3
|
-
import type { MenuProps } from 'antd';
|
|
4
|
-
import {useNavigate, useLocation} from 'react-router-dom'
|
|
5
|
-
import {ComponentMap} from '@/router/router'
|
|
6
|
-
import { menusStore } from '@/store/menus'
|
|
7
|
-
|
|
8
|
-
import styles from './index.module.scss'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type MenuItem = Required<MenuProps>['items'][number];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
interface SideProps {
|
|
15
|
-
[key: string]: any
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const Side: React.FC<SideProps> = ({}) => {
|
|
19
|
-
const navigate = useNavigate();
|
|
20
|
-
const location = useLocation()
|
|
21
|
-
const {menus} = menusStore()
|
|
22
|
-
|
|
23
|
-
// 激活的父菜单
|
|
24
|
-
const [openKeys, setOpenKeys] = React.useState<string[]>([])
|
|
25
|
-
// 激活的菜单项
|
|
26
|
-
const [selectedKeys, setSelectedKeys] = React.useState<string[]>([])
|
|
27
|
-
// 菜单
|
|
28
|
-
const [menuList, setMenuList] = React.useState<MenuItem[]>([])
|
|
29
|
-
|
|
30
|
-
useLayoutEffect(() => {
|
|
31
|
-
const newMenuList = menus.map((item: any) => {
|
|
32
|
-
const Icon = ComponentMap[item.icon]
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
...item,
|
|
36
|
-
icon: <Icon />
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
setMenuList(newMenuList)
|
|
40
|
-
}, [menus])
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
const {pathname} = location ?? {}
|
|
44
|
-
const newPathname = pathname.slice(1)
|
|
45
|
-
const pathnameList = newPathname.split('/')
|
|
46
|
-
|
|
47
|
-
if (pathnameList.length === 1) {
|
|
48
|
-
setOpenKeys([])
|
|
49
|
-
setSelectedKeys([pathnameList[0]])
|
|
50
|
-
}
|
|
51
|
-
else if (pathnameList.length === 2 || pathnameList.length === 3) {
|
|
52
|
-
// setOpenKeys([pathnameList[0]])
|
|
53
|
-
setSelectedKeys([pathnameList[1]])
|
|
54
|
-
}
|
|
55
|
-
}, [])
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// ********* 操作 ********
|
|
59
|
-
const onMenuItemOpenChange: MenuProps['onOpenChange'] = (openKeys: string[]) => {
|
|
60
|
-
const currentKey = openKeys.slice(-1)
|
|
61
|
-
setOpenKeys(currentKey)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const onMenuItemClick: MenuProps['onClick'] = (e: any) => {
|
|
65
|
-
const {keyPath} = e ?? {}
|
|
66
|
-
|
|
67
|
-
if (keyPath.length === 1) {
|
|
68
|
-
setSelectedKeys(keyPath[0])
|
|
69
|
-
navigate(`/${keyPath[0]}`)
|
|
70
|
-
}
|
|
71
|
-
else if (keyPath.length === 2) {
|
|
72
|
-
setSelectedKeys(keyPath[0])
|
|
73
|
-
navigate(`/${keyPath[1]}/${keyPath[0]}`)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// ********* 渲染 ********
|
|
79
|
-
return (
|
|
80
|
-
<div className={styles.side}>
|
|
81
|
-
<div className={styles.logo}>
|
|
82
|
-
<img
|
|
83
|
-
src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
|
|
84
|
-
alt="logo"
|
|
85
|
-
/>
|
|
86
|
-
|
|
87
|
-
<span>后台管理系统</span>
|
|
88
|
-
</div>
|
|
89
|
-
|
|
90
|
-
<Menu
|
|
91
|
-
className={styles.menu}
|
|
92
|
-
style={{
|
|
93
|
-
borderBottom: 'none'
|
|
94
|
-
}}
|
|
95
|
-
mode={'horizontal'}
|
|
96
|
-
items={menuList}
|
|
97
|
-
openKeys={openKeys}
|
|
98
|
-
selectedKeys={selectedKeys}
|
|
99
|
-
onOpenChange={onMenuItemOpenChange}
|
|
100
|
-
onClick={onMenuItemClick}
|
|
101
|
-
/>
|
|
102
|
-
</div>
|
|
103
|
-
)
|
|
104
|
-
}
|