add layout settings

This commit is contained in:
huzhushan 2021-07-23 14:51:36 +08:00
parent eddc049953
commit 4ea866e38d
10 changed files with 231 additions and 33 deletions

View File

@ -15,3 +15,4 @@ $collapseMenuActiveColor: $menuTextColor; // 菜单宽度折叠后,已选中
$collapseMenuActiveBorderColor: $mainColor; // 菜单宽度折叠后已选中菜单的边框颜色 $collapseMenuActiveBorderColor: $mainColor; // 菜单宽度折叠后已选中菜单的边框颜色
$collapseMenuActiveBorderWidth: 2px; // 菜单宽度折叠后已选中菜单的边框宽度 $collapseMenuActiveBorderWidth: 2px; // 菜单宽度折叠后已选中菜单的边框宽度
$arrowColor: #909399; // 展开/收起箭头颜色 $arrowColor: #909399; // 展开/收起箭头颜色
$horizontalMenuHeight: 40px; // 菜单栏水平排列时候的高度

75
src/defaultSettings.js Normal file
View File

@ -0,0 +1,75 @@
/*
* |~~~~~~~|
* | |
* | |
* | |
* | |
* | |
* |~.\\\_\~~~~~~~~~~~~~~xx~~~ ~~~~~~~~~~~~~~~~~~~~~/_//;~|
* | \ o \_ ,XXXXX), _..-~ o / |
* | ~~\ ~-. XXXXX`)))), _.--~~ .-~~~ |
* ~~~~~~~`\ ~\~~~XXX' _/ ';)) |~~~~~~..-~ _.-~ ~~~~~~~
* `\ ~~--`_\~\, ;;;\)__.---.~~~ _.-~
* ~-. `:;;/;; \ _..-~~
* ~-._ `'' /-~-~
* `\ / /
* | , | |
* | ' / |
* \/; |
* ;; |
* `; . |
* |~~~-----.....|
* | \ \
* | /\~~--...__ |
* (| `\ __-\|
* || \_ /~ |
* |) \~-' |
* | | \ '
* | | \ :
* \ | | |
* | ) ( )
* \ /; /\ |
* | |/ |
* | | |
* \ .' ||
* | | | |
* ( | | |
* | \ \ |
* || o `.)|
* |`\\) |
* | |
* | |
*
* @Descripttion:
* @version:
* @Date: 2021-07-22 17:22:14
* @LastEditors: huzhushan@126.com
* @LastEditTime: 2021-07-23 14:44:42
* @Author: huzhushan@126.com
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
* @Github: https://github.com/huzhushan/vue3-element-admin
* @Donate: https://huzhushan.gitee.io/vue3-element-admin/donate/
*/
export default {
menus: {
// 菜单栏排列方式
mode: 'vertical', // horizontal: 水平排列 vertical: 垂直排列
},
tagsbar: {
// 标签栏是否显示
isShow: true,
},
breadcrumbs: {
// 面包屑导航是否显示
isShow: true,
},
topbar: {
// 顶栏是否固定
isFixed: true,
},
layout: {
// 是否流式布局
isFluid: true,
},
}

View File

@ -27,7 +27,7 @@
* @version: * @version:
* @Date: 2021-04-20 11:06:21 * @Date: 2021-04-20 11:06:21
* @LastEditors: huzhushan@126.com * @LastEditors: huzhushan@126.com
* @LastEditTime: 2021-04-21 12:46:48 * @LastEditTime: 2021-07-23 11:07:24
* @Author: huzhushan@126.com * @Author: huzhushan@126.com
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @HomePage: https://huzhushan.gitee.io/vue3-element-admin
* @Github: https://github.com/huzhushan/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin
@ -38,6 +38,7 @@
<el-scrollbar class="scroll"> <el-scrollbar class="scroll">
<el-menu <el-menu
class="menu" class="menu"
:mode="mode"
:collapse="collapse" :collapse="collapse"
:uniqueOpened="true" :uniqueOpened="true"
:router="true" :router="true"
@ -66,6 +67,10 @@ export default defineComponent({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
mode: {
type: String,
default: 'vertical',
},
}, },
setup() { setup() {
const route = useRoute() const route = useRoute()
@ -130,9 +135,23 @@ export default defineComponent({
.el-submenu__title i { .el-submenu__title i {
color: $arrowColor; color: $arrowColor;
} }
//
.el-menu--horizontal {
.el-menu-item,
.el-submenu .el-submenu__title {
height: $horizontalMenuHeight;
line-height: $horizontalMenuHeight;
}
.el-menu-item.is-active,
.el-submenu.is-active .el-submenu__title {
border: none;
}
}
</style> </style>
<style lang="scss" scoped> <style lang="scss" scoped>
.scroll { .scroll {
height: auto;
flex: 1; flex: 1;
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;

View File

@ -25,7 +25,7 @@
* @version: * @version:
* @Date: 2021-04-20 11:06:21 * @Date: 2021-04-20 11:06:21
* @LastEditors: huzhushan@126.com * @LastEditors: huzhushan@126.com
* @LastEditTime: 2021-04-21 12:46:24 * @LastEditTime: 2021-07-23 09:36:42
* @Author: huzhushan@126.com * @Author: huzhushan@126.com
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @HomePage: https://huzhushan.gitee.io/vue3-element-admin
* @Github: https://github.com/huzhushan/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin

View File

@ -13,7 +13,7 @@
* @version: * @version:
* @Date: 2021-04-20 11:06:21 * @Date: 2021-04-20 11:06:21
* @LastEditors: huzhushan@126.com * @LastEditors: huzhushan@126.com
* @LastEditTime: 2021-04-21 12:47:18 * @LastEditTime: 2021-07-23 14:39:22
* @Author: huzhushan@126.com * @Author: huzhushan@126.com
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @HomePage: https://huzhushan.gitee.io/vue3-element-admin
* @Github: https://github.com/huzhushan/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin
@ -21,7 +21,7 @@
--> -->
<template> <template>
<div class="tags-container"> <div class="tags-container" :class="{ hide: !isTagsbarShow }">
<el-scrollbar <el-scrollbar
ref="scrollContainer" ref="scrollContainer"
:vertical="false" :vertical="false"
@ -68,13 +68,16 @@
</template> </template>
<script> <script>
import { defineComponent } from 'vue' import { defineComponent, inject, computed } from 'vue'
import { useTags } from './hooks/useTags' import { useTags } from './hooks/useTags'
import { useContextMenu } from './hooks/useContextMenu' import { useContextMenu } from './hooks/useContextMenu'
export default defineComponent({ export default defineComponent({
name: 'Tagsbar', name: 'Tagsbar',
setup() { setup() {
const defaultSettings = inject('defaultSettings')
const isTagsbarShow = computed(() => defaultSettings.tagsbar.isShow)
const tags = useTags() const tags = useTags()
const contextMenu = useContextMenu(tags.tagList) const contextMenu = useContextMenu(tags.tagList)
@ -84,6 +87,7 @@ export default defineComponent({
} }
return { return {
isTagsbarShow,
onScroll, onScroll,
...tags, ...tags,
...contextMenu, ...contextMenu,
@ -97,8 +101,10 @@ export default defineComponent({
height: 32px; height: 32px;
width: 100%; width: 100%;
background: #fff; background: #fff;
border-bottom: 1px solid #eaeaea; border-bottom: 1px solid #e0e4ef;
&.hide {
display: none;
}
.scroll-container { .scroll-container {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
@ -128,8 +134,8 @@ export default defineComponent({
margin-right: 15px; margin-right: 15px;
} }
&.active { &.active {
color: $mainColor; color: #303133;
border-bottom: 2px solid $mainColor; background: #f5f5f5;
} }
.title { .title {
display: inline-block; display: inline-block;
@ -141,7 +147,7 @@ export default defineComponent({
} }
.el-icon-close { .el-icon-close {
color: #5c5c5c; color: #5c5c5c;
margin-left: 2px; margin-left: 8px;
width: 16px; width: 16px;
height: 16px; height: 16px;
vertical-align: 2px; vertical-align: 2px;

View File

@ -27,7 +27,7 @@
* @version: * @version:
* @Date: 2021-04-20 11:06:21 * @Date: 2021-04-20 11:06:21
* @LastEditors: huzhushan@126.com * @LastEditors: huzhushan@126.com
* @LastEditTime: 2021-04-21 12:47:34 * @LastEditTime: 2021-07-23 14:13:23
* @Author: huzhushan@126.com * @Author: huzhushan@126.com
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @HomePage: https://huzhushan.gitee.io/vue3-element-admin
* @Github: https://github.com/huzhushan/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin
@ -36,9 +36,9 @@
<template> <template>
<el-breadcrumb <el-breadcrumb
separator="/" separator-class="el-icon-arrow-right"
class="breadcrumb" class="breadcrumb"
:class="{ mobile: device === 'mobile' }" :class="{ mobile: device === 'mobile', show: isHorizontalMenu }"
> >
<el-breadcrumb-item <el-breadcrumb-item
v-for="(item, index) in breadcrumbs" v-for="(item, index) in breadcrumbs"
@ -51,7 +51,14 @@
</el-breadcrumb> </el-breadcrumb>
</template> </template>
<script> <script>
import { defineComponent, computed, ref, onBeforeMount, watch } from 'vue' import {
defineComponent,
computed,
ref,
onBeforeMount,
watch,
inject,
} from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { useStore } from 'vuex' import { useStore } from 'vuex'
@ -63,6 +70,11 @@ export default defineComponent({
const route = router.currentRoute // 使useRoutewatch const route = router.currentRoute // 使useRoutewatch
const breadcrumbs = ref([]) const breadcrumbs = ref([])
const defaultSettings = inject('defaultSettings')
const isHorizontalMenu = computed(
() => defaultSettings.menus.mode === 'horizontal'
)
const getBreadcrumbs = route => { const getBreadcrumbs = route => {
const home = [{ path: '/', meta: { title: '首页' } }] const home = [{ path: '/', meta: { title: '首页' } }]
if (route.name === 'home') { if (route.name === 'home') {
@ -87,6 +99,7 @@ export default defineComponent({
return { return {
device, device,
breadcrumbs, breadcrumbs,
isHorizontalMenu,
} }
}, },
}) })
@ -113,5 +126,19 @@ export default defineComponent({
&.mobile { &.mobile {
display: none; display: none;
} }
&.show {
display: block;
margin: 0;
padding: 16px;
background: #f5f5f5;
}
}
</style>
<style lang="scss">
.el-breadcrumb__inner {
&.is-link,
a {
color: #5c5c5c;
}
} }
</style> </style>

View File

@ -37,7 +37,7 @@
* @version: * @version:
* @Date: 2021-04-21 09:18:32 * @Date: 2021-04-21 09:18:32
* @LastEditors: huzhushan@126.com * @LastEditors: huzhushan@126.com
* @LastEditTime: 2021-04-21 12:47:46 * @LastEditTime: 2021-07-23 13:42:10
* @Author: huzhushan@126.com * @Author: huzhushan@126.com
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @HomePage: https://huzhushan.gitee.io/vue3-element-admin
* @Github: https://github.com/huzhushan/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin
@ -45,11 +45,15 @@
--> -->
<template> <template>
<div class="header"> <div class="header" :class="{ 'no-border': isHorizontalMenu }">
<div class="navigation"> <div class="navigation">
<logo v-if="device === 'mobile'" class="mobile" /> <logo
<hamburger /> v-if="isShowLogo"
<breadcrumbs /> class="mobile"
:class="{ 'show-title': isHorizontalMenu }"
/>
<hamburger v-if="isShowHamburger" />
<breadcrumbs v-if="isShowBreadcrumbs" />
</div> </div>
<div class="action"> <div class="action">
<error-log /> <error-log />
@ -58,7 +62,7 @@
</div> </div>
</template> </template>
<script> <script>
import { defineComponent, computed } from 'vue' import { defineComponent, computed, inject } from 'vue'
import Logo from '@/layout/components/Sidebar/Logo.vue' import Logo from '@/layout/components/Sidebar/Logo.vue'
import Hamburger from './Hamburger.vue' import Hamburger from './Hamburger.vue'
import Breadcrumbs from './Breadcrumbs.vue' import Breadcrumbs from './Breadcrumbs.vue'
@ -75,11 +79,31 @@ export default defineComponent({
ErrorLog, ErrorLog,
}, },
setup() { setup() {
const defaultSettings = inject('defaultSettings')
const store = useStore() const store = useStore()
const device = computed(() => store.state.app.device) const device = computed(() => store.state.app.device)
const isHorizontalMenu = computed(
() => defaultSettings.menus.mode === 'horizontal'
)
const isShowLogo = computed(
() => isHorizontalMenu.value || device.value === 'mobile'
)
const isShowHamburger = computed(() => !isHorizontalMenu.value)
const isShowBreadcrumbs = computed(
() => defaultSettings.breadcrumbs.isShow && !isHorizontalMenu.value
)
return { return {
device, device,
isHorizontalMenu,
isShowLogo,
isShowHamburger,
isShowBreadcrumbs,
} }
}, },
}) })
@ -87,9 +111,12 @@ export default defineComponent({
<style lang="scss" scoped> <style lang="scss" scoped>
.header { .header {
height: 48px; height: 48px;
border-bottom: 1px solid #eaeaea; border-bottom: 1px solid #e0e4ef;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
&.no-border {
border: none;
}
.navigation { .navigation {
display: flex; display: flex;
align-items: center; align-items: center;
@ -110,4 +137,10 @@ export default defineComponent({
display: none; display: none;
} }
} }
.show-title {
::v-deep(.title) {
display: block;
color: #333;
}
}
</style> </style>

View File

@ -27,7 +27,7 @@
* @version: * @version:
* @Date: 2021-04-20 11:06:21 * @Date: 2021-04-20 11:06:21
* @LastEditors: huzhushan@126.com * @LastEditors: huzhushan@126.com
* @LastEditTime: 2021-04-21 12:46:00 * @LastEditTime: 2021-07-23 14:39:15
* @Author: huzhushan@126.com * @Author: huzhushan@126.com
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @HomePage: https://huzhushan.gitee.io/vue3-element-admin
* @Github: https://github.com/huzhushan/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin
@ -35,24 +35,28 @@
--> -->
<template> <template>
<div class="wrapper"> <div class="wrapper" :class="{ fluid: isFluid }">
<sidebar /> <sidebar v-if="!isHorizontalMenu" />
<div class="right"> <div class="right" :class="{ flex: isTopbarFixed }">
<div class="top"> <div class="top">
<topbar /> <topbar />
<menus mode="horizontal" v-if="isHorizontalMenu" />
<tagsbar /> <tagsbar />
<breadcrumbs v-if="isBreadcrumbsShow" />
</div> </div>
<div class="main"> <div class="main" :class="{ pt0: isBreadcrumbsShow }">
<Content /> <Content />
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { defineComponent } from 'vue' import { defineComponent, computed, inject } from 'vue'
import Sidebar from './components/Sidebar/index.vue' import Sidebar from './components/Sidebar/index.vue'
import Topbar from './components/Topbar/index.vue' import Topbar from './components/Topbar/index.vue'
import Menus from './components/Sidebar/Menus.vue'
import Tagsbar from './components/Tagsbar/index.vue' import Tagsbar from './components/Tagsbar/index.vue'
import Breadcrumbs from './components/Topbar/Breadcrumbs.vue'
import Content from './components/Content/index.vue' import Content from './components/Content/index.vue'
import { useResizeHandler } from './hooks/useResizeHandler' import { useResizeHandler } from './hooks/useResizeHandler'
@ -61,11 +65,30 @@ export default defineComponent({
components: { components: {
Sidebar, Sidebar,
Topbar, Topbar,
Menus,
Tagsbar, Tagsbar,
Breadcrumbs,
Content, Content,
}, },
setup() { setup() {
useResizeHandler() useResizeHandler()
const defaultSettings = inject('defaultSettings')
const isFluid = computed(() => defaultSettings.layout.isFluid)
const isTopbarFixed = computed(() => defaultSettings.topbar.isFixed)
const isHorizontalMenu = computed(
() => defaultSettings.menus.mode === 'horizontal'
)
const isBreadcrumbsShow = computed(
() => isHorizontalMenu.value && defaultSettings.breadcrumbs.isShow
)
return {
isFluid,
isTopbarFixed,
isHorizontalMenu,
isBreadcrumbsShow,
}
}, },
}) })
</script> </script>
@ -73,21 +96,32 @@ export default defineComponent({
<style lang="scss" scoped> <style lang="scss" scoped>
.wrapper { .wrapper {
display: flex; display: flex;
margin: 0 auto;
width: 1440px;
height: 100%; height: 100%;
&.fluid {
width: 100%;
}
.right { .right {
flex: 1; flex: 1;
overflow: hidden; overflow: auto;
display: flex; &.flex {
flex-direction: column; overflow: hidden;
display: flex;
flex-direction: column;
}
.top { .top {
background: #fff; background: #fff;
} }
.main { .main {
flex: 1; flex: 1;
background: #f0f2f5; background: #f5f5f5;
padding: 16px; padding: 16px;
overflow: auto; overflow: auto;
&.pt0 {
padding-top: 0;
}
} }
} }
} }

View File

@ -27,7 +27,7 @@
* @version: * @version:
* @Date: 2021-04-20 11:06:21 * @Date: 2021-04-20 11:06:21
* @LastEditors: huzhushan@126.com * @LastEditors: huzhushan@126.com
* @LastEditTime: 2021-04-23 11:08:56 * @LastEditTime: 2021-07-22 18:04:34
* @Author: huzhushan@126.com * @Author: huzhushan@126.com
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @HomePage: https://huzhushan.gitee.io/vue3-element-admin
* @Github: https://github.com/huzhushan/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin
@ -58,6 +58,10 @@ import './permission'
// 引入svg图标注册脚本 // 引入svg图标注册脚本
import 'vite-plugin-svg-icons/register' import 'vite-plugin-svg-icons/register'
// 引入全局设置
import defaultSettings from './defaultSettings'
app.provide('defaultSettings', defaultSettings)
// 注册全局组件 // 注册全局组件
import * as Components from './global-components' import * as Components from './global-components'
Object.entries(Components).forEach(([key, component]) => { Object.entries(Components).forEach(([key, component]) => {

View File

@ -52,7 +52,6 @@ export default defineComponent({
{ label: '邮箱', prop: 'userEmail' }, { label: '邮箱', prop: 'userEmail' },
{ {
label: '操作', label: '操作',
fixed: 'right',
width: 180, width: 180,
align: 'center', align: 'center',
tdSlot: 'operate', // tdSlot: 'operate', //