侧边栏修改

master
toesbieya 6 years ago
parent 9e41c496db
commit d5e9791473
  1. 21
      vue/src/layout/components/Sidebar/components/SidebarItem.vue
  2. 1
      vue/src/layout/components/Sidebar/index.vue
  3. 2
      vue/src/router/modules/stock.js
  4. 3
      vue/src/views/app/login.vue

@ -1,17 +1,10 @@
<script type="text/jsx"> <script type="text/jsx">
import path from 'path'
import SidebarItemContent from './SidebarItemContent' import SidebarItemContent from './SidebarItemContent'
function resolvePath(basePath, routePath = '') {
const indexOf = basePath.indexOf(routePath)
const samePath = basePath.length === indexOf + routePath.length
return indexOf && samePath ? basePath : path.resolve(basePath, routePath)
}
function getOnlyChild(item) { function getOnlyChild(item) {
const children = item.children || [] const children = item.children || []
if (children.length === 1) return children[0] if (children.length === 1) return item.alwaysShow ? null : children[0]
if (children.length < 1) return {...item, path: undefined, children: undefined} if (children.length < 1) return {...item, path: undefined, children: undefined}
@ -24,22 +17,20 @@
item: Object, item: Object,
isNest: Boolean, isNest: Boolean,
showParent: Boolean, showParent: Boolean,
collapse: Boolean, collapse: Boolean
basePath: {type: String, default: ''}
}, },
render(h, context) { render(h, context) {
function renderNode({item, isNest, showParent, collapse, basePath}) { function renderNode({item, isNest, showParent, collapse}) {
let onlyOneChild = getOnlyChild(item) let onlyOneChild = getOnlyChild(item)
const showSingle = onlyOneChild && !onlyOneChild.children const showSingle = onlyOneChild && !onlyOneChild.children
if (showSingle) { if (showSingle) {
const index = resolvePath(basePath, onlyOneChild.path)
const icon = onlyOneChild.meta.icon || (item.meta && item.meta.icon) const icon = onlyOneChild.meta.icon || (item.meta && item.meta.icon)
const title = onlyOneChild.meta.title const title = onlyOneChild.meta.title
return ( return (
<el-menu-item <el-menu-item
index={index} index={onlyOneChild.fullPath}
class={{'submenu-title-noDropdown': !isNest, 'nest-menu': isNest}} class={{'submenu-title-noDropdown': !isNest, 'nest-menu': isNest}}
> >
<SidebarItemContent icon={icon} title={title}/> <SidebarItemContent icon={icon} title={title}/>
@ -47,14 +38,12 @@
) )
} }
else { else {
const index = resolvePath(basePath, item.path)
const icon = (item.meta && item.meta.icon) || (onlyOneChild.meta && onlyOneChild.meta.icon) const icon = (item.meta && item.meta.icon) || (onlyOneChild.meta && onlyOneChild.meta.icon)
const title = item.meta.title const title = item.meta.title
const children = item.children.map(child => renderNode({ const children = item.children.map(child => renderNode({
isNest: true, isNest: true,
item: child, item: child,
basePath: resolvePath(basePath, child.path),
showParent, showParent,
collapse collapse
})) }))
@ -72,7 +61,7 @@
} }
return ( return (
<el-submenu class={{'nest-menu': isNest}} index={index} popper-append-to-body> <el-submenu class={{'nest-menu': isNest}} index={item.fullPath} popper-append-to-body>
<SidebarItemContent slot="title" icon={icon} title={title}/> <SidebarItemContent slot="title" icon={icon} title={title}/>
{children} {children}
</el-submenu> </el-submenu>

@ -24,7 +24,6 @@
:key="route.path" :key="route.path"
:show-parent="sidebarShowParent" :show-parent="sidebarShowParent"
:collapse="sidebarCollapse" :collapse="sidebarCollapse"
:base-path="route.path"
:item="route" :item="route"
/> />
</el-menu> </el-menu>

@ -5,7 +5,7 @@ const router = {
path: '/stock', path: '/stock',
component: Layout, component: Layout,
alwaysShow: true, alwaysShow: true,
meta: {title: '库存管理', icon: 'stock', breadcrumb: false}, meta: {title: '库存管理', icon: 'stock'},
children: [ children: [
{ {
path: 'current', path: 'current',

@ -58,6 +58,7 @@
import {loginBackgroundAnimate} from '@/config' import {loginBackgroundAnimate} from '@/config'
import {isEmpty} from "@/utils" import {isEmpty} from "@/utils"
import md5 from "js-md5" import md5 from "js-md5"
import {elSuccess} from "@/utils/message"
export default { export default {
name: 'login', name: 'login',
@ -97,6 +98,7 @@
}) })
}, },
success() { success() {
elSuccess('登陆成功')
let redirect = this.$route.query.redirect || '/' let redirect = this.$route.query.redirect || '/'
window.location.href = '/#' + redirect window.location.href = '/#' + redirect
}, },
@ -126,6 +128,7 @@
else this.$refs.password.focus() else this.$refs.password.focus()
}, },
beforeDestroy() { beforeDestroy() {
this.$message.closeAll()
this.removeEvent() this.removeEvent()
this.rain && this.rain.stop() this.rain && this.rain.stop()
} }

Loading…
Cancel
Save