Skip to content

Commit e7778ca

Browse files
committed
Merge branch 'hutu'
2 parents b65c145 + de11374 commit e7778ca

File tree

18 files changed

+608
-367
lines changed

18 files changed

+608
-367
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
│ ├── permission.ts # 权限管理
4040
│ └── App.vue # 入口页面
4141
├── index.html # html模板
42+
├── .env.development # 配置文件
43+
├── .env.production # 配置文件
4244
├── package.json # package.json
4345
├── README.md # README.md
4446
├── tsconfig.json # ts配置

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Vite App</title>
7+
<title>Vue3-Vite-ElementPlus-Admin</title>
88
</head>
99
<body>
1010
<div id="app"></div>

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010
"axios": "^0.24.0",
1111
"echarts": "^5.2.2",
1212
"element-plus": "^1.2.0-beta.6",
13+
"element-resize-detector": "^1.2.4",
1314
"js-cookie": "^3.0.1",
1415
"nprogress": "^0.2.0",
1516
"screenfull": "^6.0.0",
17+
"throttle-debounce": "^3.0.1",
1618
"vue": "^3.2.25",
1719
"vue-router": "^4.0.12",
1820
"vuex": "^4.0.2"
1921
},
2022
"devDependencies": {
23+
"@types/element-resize-detector": "^1.1.3",
2124
"@types/js-cookie": "^3.0.1",
2225
"@types/node": "^16.11.13",
2326
"@types/nprogress": "^0.2.0",
27+
"@types/throttle-debounce": "^2.1.0",
2428
"@typescript-eslint/eslint-plugin": "^5.7.0",
2529
"@typescript-eslint/parser": "^5.7.0",
2630
"@vitejs/plugin-vue": "^2.0.0",

src/App.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<router-view></router-view>
3-
<!-- <el-button @click="test">测试</el-button> -->
43
</template>
54
<script lang="ts" setup>
65
import { computed } from 'vue'
@@ -13,9 +12,6 @@ const headerBg = computed(() => store.state.theme.styles.headerBg)
1312
const mainBg = computed(() => store.state.theme.styles.mainBg)
1413
const subMenuBg = computed(() => store.state.theme.styles.subMenuBg)
1514
const subMenuHover = computed(() => store.state.theme.styles.subMenuHover)
16-
const test = () => {
17-
store.commit('SET_TEST')
18-
}
1915
</script>
2016
<style lang="scss">
2117
#app {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!--
2+
* @Description: echarts图表初始化
3+
* @Author: hutu
4+
* @Date: 2021-12-30 10:32:19
5+
* @LastEditors: hutu
6+
* @LastEditTime: 2022-01-11 08:50:29
7+
-->
8+
<template>
9+
<div :id="prop.id" :style="{ width: prop.width, height: prop.height }"></div>
10+
</template>
11+
<script lang="ts" setup>
12+
import * as echarts from 'echarts/core'
13+
import { BarChart, LineChart, PieChart } from 'echarts/charts'
14+
import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, ToolboxComponent } from 'echarts/components'
15+
import { LabelLayout, UniversalTransition } from 'echarts/features'
16+
import { CanvasRenderer } from 'echarts/renderers'
17+
import { IEchartsOption } from '@/interface'
18+
echarts.use([BarChart, LineChart, PieChart, TitleComponent, TooltipComponent, ToolboxComponent, GridComponent, LegendComponent, LabelLayout, UniversalTransition, CanvasRenderer])
19+
20+
import { ref, onMounted, onBeforeUnmount, onActivated, onDeactivated } from 'vue'
21+
import { debounce } from 'throttle-debounce'
22+
23+
const prop = defineProps<{
24+
id: string
25+
width: string
26+
height: string
27+
option: IEchartsOption
28+
}>()
29+
30+
const chart = ref()
31+
/**
32+
* @desc: 初始化图表
33+
*/
34+
const initChart = () => {
35+
const charts = echarts.init(document.getElementById(prop.id) as HTMLElement)
36+
charts.setOption(prop.option)
37+
chart.value = charts
38+
}
39+
/**
40+
* @desc: 监听窗口变化重置图表
41+
*/
42+
const chartResizeHandler = debounce(100, false, () => {
43+
if (chart.value) {
44+
chart.value.resize({
45+
animation: {
46+
duration: 200
47+
}
48+
})
49+
}
50+
})
51+
/**
52+
* @desc: 添加监听窗口变化事件
53+
*/
54+
const initResizeEvent = () => {
55+
window.addEventListener('resize', chartResizeHandler)
56+
}
57+
/**
58+
* @desc: 移除监听窗口变化事件
59+
*/
60+
const destroyResizeEvent = () => {
61+
window.addEventListener('resize', chartResizeHandler)
62+
}
63+
64+
/**
65+
* @desc: 添加监听侧边栏变化事件
66+
*/
67+
let sidebarElm: HTMLElement
68+
const initSidebarResizeEvent = () => {
69+
sidebarElm = document.getElementsByClassName('sidebar-container')[0] as HTMLElement
70+
sidebarElm && sidebarElm.addEventListener('transitionend', chartResizeHandler)
71+
}
72+
/**
73+
* @desc: 移除监听侧边栏变化事件
74+
*/
75+
const destroySidebarResizeEvent = () => {
76+
sidebarElm && sidebarElm.removeEventListener('transitionend', chartResizeHandler)
77+
}
78+
79+
const mounted = () => {
80+
initChart()
81+
initResizeEvent()
82+
initSidebarResizeEvent()
83+
}
84+
const beforeDestroy = () => {
85+
destroyResizeEvent()
86+
destroySidebarResizeEvent()
87+
}
88+
89+
let firstFlag = false //首次渲染
90+
onMounted(() => {
91+
firstFlag = true
92+
mounted()
93+
})
94+
onBeforeUnmount(() => {
95+
beforeDestroy()
96+
})
97+
onActivated(() => {
98+
//如果首次渲染不重复执行
99+
if (firstFlag) {
100+
firstFlag = false
101+
return false
102+
}
103+
mounted()
104+
})
105+
onDeactivated(() => {
106+
beforeDestroy()
107+
})
108+
</script>

src/components/InitEcharts/Index.vue

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/layout/Index.vue

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
* @Author: hutu
44
* @Date: 2021-12-07 08:36:02
55
* @LastEditors: hutu
6-
* @LastEditTime: 2021-12-30 14:38:55
6+
* @LastEditTime: 2022-01-07 08:45:25
77
-->
88
<template>
9-
<div class="layout">
10-
<div class="layout-menu app-sidebar-bg" :style="{ minWidth: menuCollapse ? '64px' : '210px' }">
11-
<Sidebar :list="accessRoutes" :route="route.path" :collapse="menuCollapse" />
12-
</div>
13-
<div class="layout-main">
14-
<div class="layout-header app-header-bg">
9+
<div class="layout" :class="menuCollapse ? 'hideSidebar' : 'openSidebar'">
10+
<Sidebar class="sidebar-container app-sidebar-bg" :list="accessRoutes" :route="route.path" :collapse="menuCollapse" />
11+
<div class="main-container">
12+
<div class="main-container-header app-header-bg">
1513
<Navbar />
1614
</div>
17-
<div class="layout-content app-main-bg">
15+
<div class="main-container-content app-main-bg">
1816
<AppMain />
1917
</div>
2018
</div>
@@ -35,20 +33,3 @@ const route = useRoute()
3533
const menuCollapse = computed(() => store.state.permission.menuCollapse)
3634
const accessRoutes = computed(() => store.state.permission.accessRoutes)
3735
</script>
38-
39-
<style lang="scss">
40-
.layout {
41-
display: flex;
42-
.layout-menu {
43-
transition: all 0.3s;
44-
overflow: hidden;
45-
}
46-
.layout-main {
47-
flex: 1;
48-
.layout-header {
49-
height: 50px;
50-
border-bottom: 1px solid #eee;
51-
}
52-
}
53-
}
54-
</style>

src/layout/components/Sidebar.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* @Author: hutu
44
* @Date: 2021-12-07 08:36:02
55
* @LastEditors: hutu
6-
* @LastEditTime: 2021-12-28 17:32:33
6+
* @LastEditTime: 2022-01-06 17:37:47
77
-->
88
<template>
99
<div class="sidebar">
10-
<el-menu :background-color="styles.menuBg" :text-color="styles.menuTextColor" :active-text-color="styles.menuTextActiveColor" :default-active="props.route" mode="vertical" :collapse="props.collapse" :router="true">
11-
<SidebarItem :list="props.list" :isFirst="true" />
12-
</el-menu>
10+
<el-scrollbar wrap-class="scrollbar-wrapper">
11+
<el-menu :background-color="styles.menuBg" :text-color="styles.menuTextColor" :active-text-color="styles.menuTextActiveColor" :default-active="props.route" mode="vertical" :collapse="props.collapse" :router="true">
12+
<SidebarItem :list="props.list" :isFirst="true" />
13+
</el-menu>
14+
</el-scrollbar>
1315
</div>
1416
</template>
1517

src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '@/styles/index.scss' //全局样式
66
import '@/assets/iconfont/iconfont.scss'
77
const app = createApp(App)
88

9-
import { ElButton, ElMenu, ElIcon, ElBreadcrumb, ElBreadcrumbItem, ElInput, ElForm, ElFormItem, ElTooltip, ElDropdown, ElDropdownItem, ElDropdownMenu } from 'element-plus'
9+
import { ElButton, ElMenu, ElIcon, ElBreadcrumb, ElBreadcrumbItem, ElInput, ElForm, ElFormItem, ElTooltip, ElDropdown, ElDropdownItem, ElDropdownMenu, ElRow, ElCol, ElScrollbar } from 'element-plus'
1010
import 'element-plus/theme-chalk/index.css'
1111
app.use(ElButton)
1212
app.use(ElMenu)
@@ -20,6 +20,10 @@ app.use(ElTooltip)
2020
app.use(ElDropdown)
2121
app.use(ElDropdownMenu)
2222
app.use(ElDropdownItem)
23+
app.use(ElRow)
24+
app.use(ElCol)
25+
app.use(ElScrollbar)
26+
2327
import './permission'
2428

2529
app.use(router)

src/styles/index.scss

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
1-
@import "./sidebar.scss";
1+
@import './sidebar.scss';
2+
23
* {
3-
padding: 0px;
4-
margin: 0px;
4+
padding: 0px;
5+
margin: 0px;
56
}
6-
a{
7-
text-decoration: none;
7+
a {
8+
text-decoration: none;
89
}
910
#app {
10-
font-size: 14px;
11-
}
12-
13-
// // 自定义滚动条
14-
// ::-webkit-scrollbar {
15-
// width: 6px;
16-
// /*滚动条宽度*/
17-
// height: 6px;
18-
// /*滚动条高度*/
19-
// transform: translateX(-50px);
20-
// }
11+
position: fixed;
12+
height: 100%;
13+
width: 100%;
14+
font-size: 14px;
2115

22-
// /*定义滚动条轨道 */
23-
// ::-webkit-scrollbar-track {
24-
// background-color: transparent;
25-
// /*滚动条的背景颜色*/
26-
// }
27-
28-
// /*定义滑块 */
29-
// ::-webkit-scrollbar-thumb {
30-
// cursor: pointer;
31-
// background-color: #d2e0ed;
32-
// border-radius: 2px;
33-
// /*滚动条的背景颜色*/
34-
// }
35-
36-
// ::-webkit-scrollbar-thumb:hover {
37-
// background-color: #d2e0ed;
38-
// /*滚动条的背景颜色*/
39-
// }
40-
// ::-webkit-scrollbar-thumb:active {
41-
// background-color: #d2e0ed;
42-
// /*滚动条的背景颜色*/
43-
// }
16+
.layout {
17+
position: relative;
18+
height: 100%;
19+
width: 100%;
20+
.sidebar-container {
21+
position: fixed;
22+
height: 100%;
23+
top: 0px;
24+
z-index: 1001;
25+
overflow: hidden;
26+
transition: width 0.28s;
27+
-moz-transition: width 0.28s;
28+
-webkit-transition: width 0.28s;
29+
-o-transition: width 0.28s;
30+
}
31+
.main-container {
32+
transition: margin-left 0.28s;
33+
-moz-transition: margin-left 0.28s;
34+
-webkit-transition: margin-left 0.28s;
35+
-o-transition: margin-left 0.28s;
36+
}
37+
}
38+
.openSidebar {
39+
.sidebar-container {
40+
width: 210px !important;
41+
}
42+
.main-container {
43+
margin-left: 210px;
44+
}
45+
}
46+
.hideSidebar {
47+
.sidebar-container {
48+
width: 64px !important;
49+
}
50+
.main-container {
51+
margin-left: 64px;
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)