| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- <script>
- export default {
- name: "adminLayout",
- props: {
- indexPath: {
- default: '/'
- },
- headerHeight: {
- default: '35px'
- },
- sideBarWidth: {
- default: '270px'
- },
- sideBarHeight: {
- default: '35px'
- },
- bgColor: {default: '#fff'},
- contentBgColor: {default: '#eeeeee'},
- sideBarColor: {default: '#001529'},
- sideTextColor: {default: '#fff'},
- sideTextActiveColor: {default: '#ffffffa6'},
- headerBgColor: {default: '#014175'},
- // 文本颜色, 主要文本颜色 次要文本颜色
- textColor: {default: '#333'},
- mainTextColor: {default: '#333'},
- textColorHover: {default: '#fff'},
- mainTextColorHover: {default: '#fff'},
- btnColor: {default: '#086fb6'},
- btnColorHover: {default: '#086fb6'},
- btnTextColor: {default: '#fff'},
- btnTextColorHover: {default: '#fff'},
- sidebarMenus: {
- default(){
- return []
- }
- },
- interactSideBar: {
- default: true
- },
- logoTitle: {
- default: ''
- },
- headerMenus: {
- default(){
- return []
- }
- },
- headerMenuKey: {
- default: ''
- },
- userName: {
- default: ''
- },
- btnLink: {
- type: Boolean,
- default: false
- },
- activeKey: {
- default: ''
- },
- },
- data(){
- return {
- isShowSideBar: true,
- cssText: '',
- sideMenus: [],
- }
- },
- beforeMount() {
- this.init_computedStyle();
- },
- watch:{
- sidebarMenus(){
- this.init_comSideBar();
- },
- },
- mounted() {
- this.init_comSideBar();
- },
- methods:{
- init_comSideBar(){
- // 循环遍历菜单
- this.sideMenus = this.sidebarMenus.map((item)=>{
- let newItem = {...item};
- newItem.isShow = false;
- return newItem;
- });
- },
- switchHandle(){
- if(!this.interactSideBar){return console.log('不允许交互sidebar');}
- this.isShowSideBar = !this.isShowSideBar;
- this.init_computedStyle();
- },
- switchSideBarMenuHandle(item){
- item.isShow = !item.isShow;
- },
- /**
- * 计算dom元素样式
- */
- init_computedStyle(){
- let cssText = `
- --headerHeight: ${this.headerHeight};
- --sideBarWidth: ${this.isShowSideBar?this.sideBarWidth:this.sideBarHeight};
- --baseSideBarWidth: ${this.sideBarWidth};
- --sideBarHeight: ${this.sideBarHeight};
- --bg-color: ${this.bgColor};
- --content-bg-color: ${this.contentBgColor};
- --sideBarBgColor: ${this.sideBarColor};
- --sideTextColor: ${this.sideTextColor};
- --sideTextActiveColor: ${this.sideTextActiveColor};
- --header-color: ${this.headerBgColor};
- --text-color: ${this.textColor};
- --main-text-color: ${this.mainTextColor};
- --text-color-hover: ${this.textColorHover};
- --main-text-color-hover: ${this.mainTextColorHover};
- --btn-color: ${this.btnColor};
- --btn-color-hover: ${this.btnColorHover};
- --btn-text-color: ${this.btnTextColor};
- --btn-text-color-hover: ${this.btnTextColorHover};
- `;
- this.cssText = cssText;
- },
- }
- }
- </script>
- <template>
- <!-- 管理员控制台布局 永久性头部,可伸缩侧边栏-->
- <div class="lay-con" :style="cssText">
- <!-- 头部横条 -->
- <div class="lay-header" >
- <div class="lay-logo">
- <slot name="logo">
- <h1>
- <a :href="indexPath">
- {{logoTitle}}
- </a>
- </h1>
- </slot>
- </div>
- <div class="lay-menus">
- <div class="menus">
- <span
- v-for="item in headerMenus"
- :key="item.key"
- :class="`menu ${headerMenuKey===item.key?'':''}`"
- >
- <a :href="item.href">{{item.text}}</a>
- </span>
- </div>
- <div class="bell">
- <slot name="bell"> </slot>
- </div>
- <div class="user">
- <slot name="user">
- <span>{{userName}}</span>
- </slot>
- </div>
- </div>
- </div>
- <!-- 内容部分-->
- <div class="lay-box" >
- <div :class="`lay-sideBar ${!isShowSideBar?'lay-sideBar-hide':''}`" >
- <!-- 侧边按钮 -->
- <div class="lay-sideBar-control" @click="switchHandle">
- <svg-icon :icon-class="isShowSideBar?'prev':'next'"/>
- </div>
- <!-- 侧边栏,带标题,icon,下拉菜单-->
- <div v-for="(item,i) in sideMenus"
- :key="'sideBar-'+i"
- :class="`bar-menu-item ${item.isShow?'bar-menu-item-show':''}`"
- >
- <div class="menu-title">
- <span class="icon"> <svg-icon :icon-class="item.icon"/> </span>
- <span class="text">{{ item.title }}</span>
- <span class="icon option" @click="switchSideBarMenuHandle(item)">
- <svg-icon :icon-class="item.isShow?'arrow-up':'arrow-down'"/>
- </span>
- </div>
- <div class="sub-menu-box">
- <div v-for="sub in item.child"
- :key="sub.key"
- :class="`menu-item ${activeKey===sub.key?'menu-items-show':''}`"
- >
- <a :href="sub.path">{{sub.title}}</a>
- </div>
- </div>
- </div>
- </div>
- <div class="lay-content" >
- <slot></slot>
- </div>
- </div>
- </div>
- </template>
- <style scoped>
- .lay-con {
- --headerHeight: v-bind(headerHeight);
- --sideBarWidth: v-bind(sideBarWidth);
- --sideBarHeight: v-bind(sideBarHeight);
- --baseSideBarWidth: v-bind(sideBarWidth);
- --bg-color: v-bind(bgColor);
- --content-bg-color: v-bind(contentBgColor);
- --sideBarBgColor: v-bind(sideBarColor);
- --side-text-color: v-bind(sideTextColor);
- --side-text-active-color: v-bind(sideTextActiveColor);
- --header-color: v-bind(headerBgColor);
- --text-color: v-bind(textColor);
- --main-text-color: v-bind(mainTextColor);
- --text-color-hover: v-bind(textColorHover);
- --main-text-color-hover: v-bind(mainTextColorHover);
- --btn-color: v-bind(btnColor);
- --btn-color-hover: v-bind(btnColorHover);
- --btn-text-color: v-bind(btnTextColor);
- --btn-text-color-hover: v-bind(btnTextColorHover);
- width: 100vw;
- height: 100vh;
- overflow: hidden;
- background-color: var(--sideBarBgColor);
- position: relative;
- }
- .lay-header{
- background-color: var(--header-color);
- display: flex;
- width: 100%;
- height: var(--headerHeight);
- flex-direction: row;
- }
- .lay-header > *{
- width: 50%;
- height: 100%;
- display: flex;
- align-items: center;
- }
- .lay-logo{
- margin-left: 15px;
- margin-right: 15px;
- box-sizing: border-box;
- }
- .lay-menus{
- justify-content: end;
- }
- .lay-menus .menus{
- display: flex;
- padding: 0 5px;
- }
- .lay-menus .menus .menu{
- padding: 5px 15px;
- }
- .lay-menus .menus .menu:hover{
- color: var(--text-color-hover);
- }
- .lay-box {
- width: 100%;
- height:calc(100% - var(--headerHeight));
- display: flex;
- }
- .lay-box > *{
- transition: width .7s;
- height: 100%;
- position: relative;
- }
- .lay-sideBar{
- width: var(--sideBarWidth);
- color: var(--side-text-color);
- }
- .lay-content{
- width: calc(100% - var(--sideBarWidth));
- height: 100%;
- overflow: auto;
- background-color: var(--content-bg-color);
- }
- .lay-sideBar-control{
- position: relative;
- width: 25px;
- height: 25px;
- left: 50%;
- top: 0px;
- margin-top: 5px;
- transform: translate(-50%, 0);
- border-radius: 3px;
- border: 1px solid black;
- z-index: 999;
- cursor: pointer;
- display: flex;
- justify-content: center;
- align-items: center;
- background-color: var(--sideBarBgColor);
- }
- .lay-sideBar-control:hover{
- border-color: #f0ad4e;
- background-color: #f0ad4e;
- color: var(--side-text-active-color);
- }
- .bar-menu-item{
- width: 100%;
- height: auto;
- position: relative;
- margin-top: 5px;
- }
- .bar-menu-item .menu-title{
- display: flex;
- width: 100%;
- height: var(--sideBarHeight);
- align-items: center;
- box-sizing: border-box;
- padding-left: 5px;
- padding-right: 5px;
- cursor: default;
- overflow: hidden;
- }
- .bar-menu-item .menu-title:hover{
- color: var(--btn-text-color-hover);
- }
- .bar-menu-item .menu-title .icon{
- width: var(--sideBarHeight);
- height: var(--sideBarHeight);
- display: flex;
- justify-content: center;
- align-items: center;
- color: var(--side-text-color);
- flex-shrink: 0;
- }
- .bar-menu-item .menu-title .icon *{
- color: inherit;
- }
- .bar-menu-item .menu-title .option{
- cursor: pointer;
- color: var(--side-text-color);
- font-size: 1.5rem;
- }
- .bar-menu-item .menu-title .option:hover{
- color: var(--side-text-active-color);
- }
- .bar-menu-item .menu-title .text{
- width: calc(100% - var(--sideBarHeight) - var(--sideBarHeight));
- display: flex;
- align-items: center;
- }
- .bar-menu-item .sub-menu-box{
- width: 100%;
- height: 0;
- overflow: hidden;
- transition: height .7s;
- }
- .bar-menu-item .sub-menu-box .menu-item{
- width: 100%;
- height: calc(var(--sideBarHeight) - 5px);
- box-sizing: border-box;
- padding-left: calc(var(--sideBarHeight) + 5px);
- cursor: pointer;
- }
- .bar-menu-item .sub-menu-box .menu-item > a{
- width: 100%;
- height: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .bar-menu-item .sub-menu-box .menu-item:hover{
- color: var(--btn-text-color-hover);
- background-color: var(--btn-color-hover);
- }
- .bar-menu-item-show{
- height: auto;
- }
- .bar-menu-item-show .sub-menu-box{
- height: auto;
- }
- .lay-sideBar-hide .lay-sideBar{
- padding-top: 50px;
- }
- .lay-sideBar-hide .bar-menu-item{
- box-sizing: border-box;
- margin: 10px 0;
- border-top: 1px solid var(--sideBarBgColor);
- }
- .lay-sideBar-hide .bar-menu-item .menu-title {
- padding-left: 0;
- padding-right: 0;
- }
- .lay-sideBar-hide .bar-menu-item .sub-menu-box{
- position: absolute;
- display: none;
- top: 0;
- left: 100%;
- height: auto;
- width: calc(var(--baseSideBarWidth) - var(--sideBarWidth));
- padding: 10px 0;
- box-shadow: 1px 1px 3px darkgray;
- z-index: 9999;
- background-color: var(--sideBarBgColor);
- }
- .lay-sideBar-hide .bar-menu-item:hover{
- border-top: 1px solid var(--bg-color);
- }
- .lay-sideBar-hide .bar-menu-item:hover .sub-menu-box{
- display: block;
- }
- </style>
|