Commit 02e88153 authored by yanzhongrong's avatar yanzhongrong

初始化框架

parent 4c18a3f4
<template> <template>
<div class="navbar"> <div class="navbar">
<hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> <!-- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
<breadcrumb class="breadcrumb-container" />
<!-- <breadcrumb class="breadcrumb-container" /> -->
<div class="log">后台管理系统</div>
<Sidebar />
<div class="right-menu"> <div class="right-menu">
<el-dropdown class="avatar-container" trigger="click"> <el-dropdown class="avatar-container" trigger="click">
<div class="avatar-wrapper"> <div class="avatar-wrapper">
...@@ -13,17 +14,11 @@ ...@@ -13,17 +14,11 @@
<el-dropdown-menu slot="dropdown" class="user-dropdown"> <el-dropdown-menu slot="dropdown" class="user-dropdown">
<router-link to="/"> <router-link to="/">
<el-dropdown-item> <el-dropdown-item>
Home 首页
</el-dropdown-item> </el-dropdown-item>
</router-link> </router-link>
<a target="_blank" href="https://github.com/PanJiaChen/vue-admin-template/">
<el-dropdown-item>Github</el-dropdown-item>
</a>
<a target="_blank" href="https://panjiachen.github.io/vue-element-admin-site/#/">
<el-dropdown-item>Docs</el-dropdown-item>
</a>
<el-dropdown-item divided @click.native="logout"> <el-dropdown-item divided @click.native="logout">
<span style="display:block;">Log Out</span> <span style="display:block;">退出</span>
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
...@@ -35,11 +30,12 @@ ...@@ -35,11 +30,12 @@
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb' import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger' import Hamburger from '@/components/Hamburger'
import Sidebar from './Sidebar/index.vue'
export default { export default {
components: { components: {
Breadcrumb, Breadcrumb,
Hamburger Hamburger,
Sidebar
}, },
computed: { computed: {
...mapGetters([ ...mapGetters([
...@@ -61,12 +57,16 @@ export default { ...@@ -61,12 +57,16 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.navbar { .navbar {
height: 50px; height: 80px;
overflow: hidden; overflow: hidden;
position: relative; position: relative;
background: #fff; background: #fff;
box-shadow: 0 1px 4px rgba(0,21,41,.08); box-shadow: 0 1px 4px rgba(0,21,41,.08);
.log {
font-size: 20px;
color: #fff;
float: left;
}
.hamburger-container { .hamburger-container {
line-height: 46px; line-height: 46px;
height: 100%; height: 100%;
......
<template> <template>
<div v-if="!item.hidden"> <div v-if="!item.hidden" class="menu-wrapper">
<template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow"> <template
<app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)"> v-if="
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}"> hasOneShowingChild(item.children, item) &&
<item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title" /> (!onlyOneChild.children || onlyOneChild.noShowingChildren) &&
!item.alwaysShow
"
>
<app-link
v-if="onlyOneChild.meta"
:to="
resolvePath(
onlyOneChild.path +
(onlyOneChild.meta.querys ? '?' + onlyOneChild.meta.querys : '')
)
"
>
<el-menu-item
:index="resolvePath(onlyOneChild.path)"
:class="{ 'submenu-title-noDropdown': !isNest }"
>
<icon-item
:icon="onlyOneChild.meta.icon || (item.meta && item.meta.icon)"
:title="onlyOneChild.meta.title"
/>
</el-menu-item> </el-menu-item>
</app-link> </app-link>
</template> </template>
<el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body> <template v-else>
<template slot="title"> <el-submenu ref="subMenu" :index="resolvePath(item.path)">
<item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" /> <template slot="title">
</template> <icon-item
<sidebar-item v-if="item.meta"
v-for="child in item.children" :icon="item.meta && item.meta.icon"
:key="child.path" :title="item.meta.title"
:is-nest="true" />
:item="child" </template>
:base-path="resolvePath(child.path)" <sidebar-item
class="nest-menu" v-for="child in item.children"
/> :key="child.path"
</el-submenu> :is-nest="true"
:item="child"
:base-path="resolvePath(child.path)"
class="nest-menu"
/>
</el-submenu>
</template>
</div> </div>
</template> </template>
<script> <script>
import path from 'path' import path from "path";
import { isExternal } from '@/utils/validate' import { isExternal } from "@/utils/validate";
import Item from './Item' import IconItem from "./Item.vue";
import AppLink from './Link' import AppLink from "./Link";
import FixiOSBug from './FixiOSBug'
export default { export default {
name: 'SidebarItem', name: "SidebarItem",
components: { Item, AppLink }, components: { IconItem, AppLink },
mixins: [FixiOSBug],
props: { props: {
// route object // route object
item: { item: {
type: Object, type: Object,
required: true required: true,
}, },
isNest: { isNest: {
type: Boolean, type: Boolean,
default: false default: false,
}, },
basePath: { basePath: {
type: String, type: String,
default: '' default: "",
} },
}, },
data() { data() {
// To fix https://github.com/PanJiaChen/vue-admin-template/issues/237 // To fix https://github.com/PanJiaChen/vue-admin-template/issues/237
// TODO: refactor with render function // TODO: refactor with render function
this.onlyOneChild = null this.onlyOneChild = null;
return {} return {};
}, },
methods: { methods: {
hasOneShowingChild(children = [], parent) { hasOneShowingChild(children = [], parent) {
const showingChildren = children.filter(item => { const showingChildren = children.filter(item => {
if (item.hidden) { if (item.hidden) {
return false return false;
} else { } else {
// Temp set(will be used if only has one showing child) // Temp set(will be used if only has one showing child)
this.onlyOneChild = item this.onlyOneChild = item;
return true return true;
} }
}) });
// When there is only one child router, the child router is displayed by default // When there is only one child router, the child router is displayed by default
if (showingChildren.length === 1) { if (showingChildren.length === 1) {
return true return true;
} }
// Show parent if there are no child router to display // Show parent if there are no child router to display
if (showingChildren.length === 0) { if (showingChildren.length === 0) {
this.onlyOneChild = { ... parent, path: '', noShowingChildren: true } this.onlyOneChild = { ...parent, path: "", noShowingChildren: true };
return true return true;
} }
return false return false;
}, },
resolvePath(routePath) { resolvePath(routePath) {
if (isExternal(routePath)) { if (isExternal(routePath)) {
return routePath return routePath;
} }
if (isExternal(this.basePath)) { if (isExternal(this.basePath)) {
return this.basePath return this.basePath;
} }
return path.resolve(this.basePath, routePath) return path.resolve(this.basePath, routePath);
} },
},
};
</script>
<style lang="scss" scoped>
.menu-wrapper {
&:focus {
outline: none;
}
a {
text-decoration: none;
color: inherit;
display: inline-block;
width: 100%;
} }
} }
</script> </style>
<template> <template>
<div :class="{'has-logo':showLogo}"> <div :class="{ 'has-logo': showLogo }">
<logo v-if="showLogo" :collapse="isCollapse" /> <el-menu
<el-scrollbar wrap-class="scrollbar-wrapper"> :default-active="activeMenu"
<el-menu :unique-opened="false"
:default-active="activeMenu" :collapse-transition="false"
:collapse="isCollapse" mode="horizontal"
:background-color="variables.menuBg" :background-color="variables.menuBg"
:text-color="variables.menuText" :text-color="variables.menuText"
:unique-opened="false" :active-text-color="variables.menuActiveText"
:active-text-color="variables.menuActiveText" class="frame-menu"
:collapse-transition="false" >
mode="vertical" <sidebar-item
> v-for="route in routes"
<sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" /> :key="route.path"
</el-menu> :item="route"
</el-scrollbar> :base-path="route.path"
ref="list"
/>
</el-menu>
</div> </div>
</template> </template>
...@@ -34,13 +37,13 @@ export default { ...@@ -34,13 +37,13 @@ export default {
return this.$router.options.routes return this.$router.options.routes
}, },
activeMenu() { activeMenu() {
const route = this.$route const route = this.$route;
const { meta, path } = route const { meta, path } = route;
// if set path, the sidebar will highlight the path you set // if set path, the sidebar will highlight the path you set
if (meta.activeMenu) { if (meta.activeMenu) {
return meta.activeMenu return meta.activeMenu;
} }
return path return path;
}, },
showLogo() { showLogo() {
return this.$store.state.settings.sidebarLogo return this.$store.state.settings.sidebarLogo
...@@ -48,9 +51,63 @@ export default { ...@@ -48,9 +51,63 @@ export default {
variables() { variables() {
return variables return variables
}, },
isCollapse() {
return !this.sidebar.opened
}
} }
} }
</script> </script>
<style lang="scss" scoped>
.frame-menu {
border: none;
height: 100%;
width: 100% !important;
white-space: nowrap;
&.el-menu--horizontal {
border-bottom: none !important;
> .menu-wrapper {
display: inline-block;
> a {
// display: inline-block;
> .el-menu-item {
display: inline-block;
margin: 0;
border-bottom: 2px solid transparent;
padding: 0 5px;
}
}
> .el-submenu {
display: inline-block;
.el-submenu__title {
border-bottom: 2px solid transparent;
padding: 0 5px;
// &:hover {
// background-color: #fff;
// }
}
.el-submenu__icon-arrow {
position: static;
vertical-align: middle;
margin-left: 8px;
margin-top: -3px;
}
}
}
}
&.el-menu--collapse > .menu-wrapper {
> a > .el-menu-item span,
> .el-submenu > .el-submenu__title span {
height: 0;
width: 0;
overflow: hidden;
visibility: hidden;
display: inline-block;
}
> a > .el-menu-item .el-submenu__icon-arrow,
> .el-submenu > .el-submenu__title .el-submenu__icon-arrow {
display: none;
}
}
.el-submenu.is-active > .el-submenu__title {
color: #fff !important;
}
}
</style>
\ No newline at end of file
<template> <template>
<div :class="classObj" class="app-wrapper"> <div :class="classObj" class="app-wrapper">
<navbar />
<div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" /> <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
<sidebar class="sidebar-container" /> <div :class="{sidebarHide: sidebar.hide}" class="main-container">
<div class="main-container">
<div :class="{'fixed-header':fixedHeader}">
<navbar />
</div>
<app-main /> <app-main />
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { Navbar, Sidebar, AppMain } from './components' import { Navbar, Sidebar, AppMain, Topbar } from './components'
import ResizeMixin from './mixin/ResizeHandler' import ResizeMixin from './mixin/ResizeHandler'
export default { export default {
...@@ -20,7 +17,8 @@ export default { ...@@ -20,7 +17,8 @@ export default {
components: { components: {
Navbar, Navbar,
Sidebar, Sidebar,
AppMain AppMain,
Topbar
}, },
mixins: [ResizeMixin], mixins: [ResizeMixin],
computed: { computed: {
......
...@@ -60,7 +60,7 @@ export const constantRoutes = [ ...@@ -60,7 +60,7 @@ export const constantRoutes = [
component: Layout, component: Layout,
redirect: '/example/table', redirect: '/example/table',
name: 'Example', name: 'Example',
meta: { title: 'Example', icon: 'el-icon-s-help' }, meta: { title: 'Example', icon: 'example' },
children: [ children: [
{ {
path: 'table', path: 'table',
...@@ -77,89 +77,6 @@ export const constantRoutes = [ ...@@ -77,89 +77,6 @@ export const constantRoutes = [
] ]
}, },
{
path: '/form',
component: Layout,
children: [
{
path: 'index',
name: 'Form',
component: () => import('@/views/form/index'),
meta: { title: 'Form', icon: 'form' }
}
]
},
{
path: '/nested',
component: Layout,
redirect: '/nested/menu1',
name: 'Nested',
meta: {
title: 'Nested',
icon: 'nested'
},
children: [
{
path: 'menu1',
component: () => import('@/views/nested/menu1/index'), // Parent router-view
name: 'Menu1',
meta: { title: 'Menu1' },
children: [
{
path: 'menu1-1',
component: () => import('@/views/nested/menu1/menu1-1'),
name: 'Menu1-1',
meta: { title: 'Menu1-1' }
},
{
path: 'menu1-2',
component: () => import('@/views/nested/menu1/menu1-2'),
name: 'Menu1-2',
meta: { title: 'Menu1-2' },
children: [
{
path: 'menu1-2-1',
component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
name: 'Menu1-2-1',
meta: { title: 'Menu1-2-1' }
},
{
path: 'menu1-2-2',
component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
name: 'Menu1-2-2',
meta: { title: 'Menu1-2-2' }
}
]
},
{
path: 'menu1-3',
component: () => import('@/views/nested/menu1/menu1-3'),
name: 'Menu1-3',
meta: { title: 'Menu1-3' }
}
]
},
{
path: 'menu2',
component: () => import('@/views/nested/menu2/index'),
name: 'Menu2',
meta: { title: 'menu2' }
}
]
},
{
path: 'external-link',
component: Layout,
children: [
{
path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
meta: { title: 'External Link', icon: 'link' }
}
]
},
// 404 page must be placed at the end !!! // 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true } { path: '*', redirect: '/404', hidden: true }
] ]
......
...@@ -3,22 +3,22 @@ ...@@ -3,22 +3,22 @@
.main-container { .main-container {
min-height: 100%; min-height: 100%;
transition: margin-left .28s; transition: margin-left .28s;
margin-left: $sideBarWidth; // margin-left: $sideBarWidth;
position: relative; position: relative;
} }
.sidebar-container { .sidebar-container {
transition: width 0.28s; transition: width 0.28s;
width: $sideBarWidth !important; // width: $sideBarWidth !important;
background-color: $menuBg; // background-color: $menuBg;
height: 100%; // height: 100%;
position: fixed; // position: fixed;
font-size: 0px; // font-size: 0px;
top: 0; // top: 0;
bottom: 0; // bottom: 0;
left: 0; // left: 0;
z-index: 1001; // z-index: 1001;
overflow: hidden; // overflow: hidden;
// reset element-ui css // reset element-ui css
.horizontal-collapse-transition { .horizontal-collapse-transition {
......
<template>
<div class="app-container">
<el-form ref="form" :model="form" label-width="120px">
<el-form-item label="Activity name">
<el-input v-model="form.name" />
</el-form-item>
<el-form-item label="Activity zone">
<el-select v-model="form.region" placeholder="please select your zone">
<el-option label="Zone one" value="shanghai" />
<el-option label="Zone two" value="beijing" />
</el-select>
</el-form-item>
<el-form-item label="Activity time">
<el-col :span="11">
<el-date-picker v-model="form.date1" type="date" placeholder="Pick a date" style="width: 100%;" />
</el-col>
<el-col :span="2" class="line">-</el-col>
<el-col :span="11">
<el-time-picker v-model="form.date2" type="fixed-time" placeholder="Pick a time" style="width: 100%;" />
</el-col>
</el-form-item>
<el-form-item label="Instant delivery">
<el-switch v-model="form.delivery" />
</el-form-item>
<el-form-item label="Activity type">
<el-checkbox-group v-model="form.type">
<el-checkbox label="Online activities" name="type" />
<el-checkbox label="Promotion activities" name="type" />
<el-checkbox label="Offline activities" name="type" />
<el-checkbox label="Simple brand exposure" name="type" />
</el-checkbox-group>
</el-form-item>
<el-form-item label="Resources">
<el-radio-group v-model="form.resource">
<el-radio label="Sponsor" />
<el-radio label="Venue" />
</el-radio-group>
</el-form-item>
<el-form-item label="Activity form">
<el-input v-model="form.desc" type="textarea" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">Create</el-button>
<el-button @click="onCancel">Cancel</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
form: {
name: '',
region: '',
date1: '',
date2: '',
delivery: false,
type: [],
resource: '',
desc: ''
}
}
},
methods: {
onSubmit() {
this.$message('submit!')
},
onCancel() {
this.$message({
message: 'cancel!',
type: 'warning'
})
}
}
}
</script>
<style scoped>
.line{
text-align: center;
}
</style>
<template>
<div style="padding:30px;">
<el-alert :closable="false" title="menu 1">
<router-view />
</el-alert>
</div>
</template>
<template>
<div style="padding:30px;">
<el-alert :closable="false" title="menu 1-1" type="success">
<router-view />
</el-alert>
</div>
</template>
<template>
<div style="padding:30px;">
<el-alert :closable="false" title="menu 1-2" type="success">
<router-view />
</el-alert>
</div>
</template>
<template functional>
<div style="padding:30px;">
<el-alert :closable="false" title="menu 1-2-1" type="warning" />
</div>
</template>
<template functional>
<div style="padding:30px;">
<el-alert :closable="false" title="menu 1-2-2" type="warning" />
</div>
</template>
<template functional>
<div style="padding:30px;">
<el-alert :closable="false" title="menu 1-3" type="success" />
</div>
</template>
<template>
<div style="padding:30px;">
<el-alert :closable="false" title="menu 2" />
</div>
</template>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment