Skip to content

Commit

Permalink
Merge branch 'hutu'
Browse files Browse the repository at this point in the history
  • Loading branch information
lpya committed Jan 11, 2022
2 parents b65c145 + de11374 commit e7778ca
Show file tree
Hide file tree
Showing 18 changed files with 608 additions and 367 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
│ ├── permission.ts # 权限管理
│ └── App.vue # 入口页面
├── index.html # html模板
├── .env.development # 配置文件
├── .env.production # 配置文件
├── package.json # package.json
├── README.md # README.md
├── tsconfig.json # ts配置
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<title>Vue3-Vite-ElementPlus-Admin</title>
</head>
<body>
<div id="app"></div>
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
"axios": "^0.24.0",
"echarts": "^5.2.2",
"element-plus": "^1.2.0-beta.6",
"element-resize-detector": "^1.2.4",
"js-cookie": "^3.0.1",
"nprogress": "^0.2.0",
"screenfull": "^6.0.0",
"throttle-debounce": "^3.0.1",
"vue": "^3.2.25",
"vue-router": "^4.0.12",
"vuex": "^4.0.2"
},
"devDependencies": {
"@types/element-resize-detector": "^1.1.3",
"@types/js-cookie": "^3.0.1",
"@types/node": "^16.11.13",
"@types/nprogress": "^0.2.0",
"@types/throttle-debounce": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"@vitejs/plugin-vue": "^2.0.0",
Expand Down
4 changes: 0 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<router-view></router-view>
<!-- <el-button @click="test">测试</el-button> -->
</template>
<script lang="ts" setup>
import { computed } from 'vue'
Expand All @@ -13,9 +12,6 @@ const headerBg = computed(() => store.state.theme.styles.headerBg)
const mainBg = computed(() => store.state.theme.styles.mainBg)
const subMenuBg = computed(() => store.state.theme.styles.subMenuBg)
const subMenuHover = computed(() => store.state.theme.styles.subMenuHover)
const test = () => {
store.commit('SET_TEST')
}
</script>
<style lang="scss">
#app {
Expand Down
108 changes: 108 additions & 0 deletions src/components/EchartInit/Index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!--
* @Description: echarts图表初始化
* @Author: hutu
* @Date: 2021-12-30 10:32:19
* @LastEditors: hutu
* @LastEditTime: 2022-01-11 08:50:29
-->
<template>
<div :id="prop.id" :style="{ width: prop.width, height: prop.height }"></div>
</template>
<script lang="ts" setup>
import * as echarts from 'echarts/core'
import { BarChart, LineChart, PieChart } from 'echarts/charts'
import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, ToolboxComponent } from 'echarts/components'
import { LabelLayout, UniversalTransition } from 'echarts/features'
import { CanvasRenderer } from 'echarts/renderers'
import { IEchartsOption } from '@/interface'
echarts.use([BarChart, LineChart, PieChart, TitleComponent, TooltipComponent, ToolboxComponent, GridComponent, LegendComponent, LabelLayout, UniversalTransition, CanvasRenderer])
import { ref, onMounted, onBeforeUnmount, onActivated, onDeactivated } from 'vue'
import { debounce } from 'throttle-debounce'
const prop = defineProps<{
id: string
width: string
height: string
option: IEchartsOption
}>()
const chart = ref()
/**
* @desc: 初始化图表
*/
const initChart = () => {
const charts = echarts.init(document.getElementById(prop.id) as HTMLElement)
charts.setOption(prop.option)
chart.value = charts
}
/**
* @desc: 监听窗口变化重置图表
*/
const chartResizeHandler = debounce(100, false, () => {
if (chart.value) {
chart.value.resize({
animation: {
duration: 200
}
})
}
})
/**
* @desc: 添加监听窗口变化事件
*/
const initResizeEvent = () => {
window.addEventListener('resize', chartResizeHandler)
}
/**
* @desc: 移除监听窗口变化事件
*/
const destroyResizeEvent = () => {
window.addEventListener('resize', chartResizeHandler)
}
/**
* @desc: 添加监听侧边栏变化事件
*/
let sidebarElm: HTMLElement
const initSidebarResizeEvent = () => {
sidebarElm = document.getElementsByClassName('sidebar-container')[0] as HTMLElement
sidebarElm && sidebarElm.addEventListener('transitionend', chartResizeHandler)
}
/**
* @desc: 移除监听侧边栏变化事件
*/
const destroySidebarResizeEvent = () => {
sidebarElm && sidebarElm.removeEventListener('transitionend', chartResizeHandler)
}
const mounted = () => {
initChart()
initResizeEvent()
initSidebarResizeEvent()
}
const beforeDestroy = () => {
destroyResizeEvent()
destroySidebarResizeEvent()
}
let firstFlag = false //首次渲染
onMounted(() => {
firstFlag = true
mounted()
})
onBeforeUnmount(() => {
beforeDestroy()
})
onActivated(() => {
//如果首次渲染不重复执行
if (firstFlag) {
firstFlag = false
return false
}
mounted()
})
onDeactivated(() => {
beforeDestroy()
})
</script>
53 changes: 0 additions & 53 deletions src/components/InitEcharts/Index.vue

This file was deleted.

31 changes: 6 additions & 25 deletions src/layout/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
* @Author: hutu
* @Date: 2021-12-07 08:36:02
* @LastEditors: hutu
* @LastEditTime: 2021-12-30 14:38:55
* @LastEditTime: 2022-01-07 08:45:25
-->
<template>
<div class="layout">
<div class="layout-menu app-sidebar-bg" :style="{ minWidth: menuCollapse ? '64px' : '210px' }">
<Sidebar :list="accessRoutes" :route="route.path" :collapse="menuCollapse" />
</div>
<div class="layout-main">
<div class="layout-header app-header-bg">
<div class="layout" :class="menuCollapse ? 'hideSidebar' : 'openSidebar'">
<Sidebar class="sidebar-container app-sidebar-bg" :list="accessRoutes" :route="route.path" :collapse="menuCollapse" />
<div class="main-container">
<div class="main-container-header app-header-bg">
<Navbar />
</div>
<div class="layout-content app-main-bg">
<div class="main-container-content app-main-bg">
<AppMain />
</div>
</div>
Expand All @@ -35,20 +33,3 @@ const route = useRoute()
const menuCollapse = computed(() => store.state.permission.menuCollapse)
const accessRoutes = computed(() => store.state.permission.accessRoutes)
</script>

<style lang="scss">
.layout {
display: flex;
.layout-menu {
transition: all 0.3s;
overflow: hidden;
}
.layout-main {
flex: 1;
.layout-header {
height: 50px;
border-bottom: 1px solid #eee;
}
}
}
</style>
10 changes: 6 additions & 4 deletions src/layout/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* @Author: hutu
* @Date: 2021-12-07 08:36:02
* @LastEditors: hutu
* @LastEditTime: 2021-12-28 17:32:33
* @LastEditTime: 2022-01-06 17:37:47
-->
<template>
<div class="sidebar">
<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">
<SidebarItem :list="props.list" :isFirst="true" />
</el-menu>
<el-scrollbar wrap-class="scrollbar-wrapper">
<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">
<SidebarItem :list="props.list" :isFirst="true" />
</el-menu>
</el-scrollbar>
</div>
</template>

Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '@/styles/index.scss' //全局样式
import '@/assets/iconfont/iconfont.scss'
const app = createApp(App)

import { ElButton, ElMenu, ElIcon, ElBreadcrumb, ElBreadcrumbItem, ElInput, ElForm, ElFormItem, ElTooltip, ElDropdown, ElDropdownItem, ElDropdownMenu } from 'element-plus'
import { ElButton, ElMenu, ElIcon, ElBreadcrumb, ElBreadcrumbItem, ElInput, ElForm, ElFormItem, ElTooltip, ElDropdown, ElDropdownItem, ElDropdownMenu, ElRow, ElCol, ElScrollbar } from 'element-plus'
import 'element-plus/theme-chalk/index.css'
app.use(ElButton)
app.use(ElMenu)
Expand All @@ -20,6 +20,10 @@ app.use(ElTooltip)
app.use(ElDropdown)
app.use(ElDropdownMenu)
app.use(ElDropdownItem)
app.use(ElRow)
app.use(ElCol)
app.use(ElScrollbar)

import './permission'

app.use(router)
Expand Down
87 changes: 49 additions & 38 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
@import "./sidebar.scss";
@import './sidebar.scss';

* {
padding: 0px;
margin: 0px;
padding: 0px;
margin: 0px;
}
a{
text-decoration: none;
a {
text-decoration: none;
}
#app {
font-size: 14px;
}

// // 自定义滚动条
// ::-webkit-scrollbar {
// width: 6px;
// /*滚动条宽度*/
// height: 6px;
// /*滚动条高度*/
// transform: translateX(-50px);
// }
position: fixed;
height: 100%;
width: 100%;
font-size: 14px;

// /*定义滚动条轨道 */
// ::-webkit-scrollbar-track {
// background-color: transparent;
// /*滚动条的背景颜色*/
// }

// /*定义滑块 */
// ::-webkit-scrollbar-thumb {
// cursor: pointer;
// background-color: #d2e0ed;
// border-radius: 2px;
// /*滚动条的背景颜色*/
// }

// ::-webkit-scrollbar-thumb:hover {
// background-color: #d2e0ed;
// /*滚动条的背景颜色*/
// }
// ::-webkit-scrollbar-thumb:active {
// background-color: #d2e0ed;
// /*滚动条的背景颜色*/
// }
.layout {
position: relative;
height: 100%;
width: 100%;
.sidebar-container {
position: fixed;
height: 100%;
top: 0px;
z-index: 1001;
overflow: hidden;
transition: width 0.28s;
-moz-transition: width 0.28s;
-webkit-transition: width 0.28s;
-o-transition: width 0.28s;
}
.main-container {
transition: margin-left 0.28s;
-moz-transition: margin-left 0.28s;
-webkit-transition: margin-left 0.28s;
-o-transition: margin-left 0.28s;
}
}
.openSidebar {
.sidebar-container {
width: 210px !important;
}
.main-container {
margin-left: 210px;
}
}
.hideSidebar {
.sidebar-container {
width: 64px !important;
}
.main-container {
margin-left: 64px;
}
}
}
Loading

0 comments on commit e7778ca

Please sign in to comment.