fix some bugs

This commit is contained in:
Pan 2017-12-14 17:06:39 +08:00 committed by 花裤衩
parent 12012e3b24
commit 5b7aafacc4
2 changed files with 10 additions and 9 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="scroll-container" ref="scrollContainer" @mousewheel="handleScroll"> <div class="scroll-container" ref="scrollContainer" @wheel.prevent="handleScroll" >
<div class="scroll-wrapper" ref="scrollWrapper" :style="{top: top + 'px'}"> <div class="scroll-wrapper" ref="scrollWrapper" :style="{top: top + 'px'}">
<slot></slot> <slot></slot>
</div> </div>
@ -8,6 +8,7 @@
<script> <script>
const delta = 15 const delta = 15
export default { export default {
name: 'scrollBar', name: 'scrollBar',
data() { data() {
@ -17,19 +18,19 @@ export default {
}, },
methods: { methods: {
handleScroll(e) { handleScroll(e) {
e.preventDefault() const eventDelta = e.wheelDelta || -e.deltaY * 3
const $container = this.$refs.scrollContainer const $container = this.$refs.scrollContainer
const $containerHeight = $container.offsetHeight const $containerHeight = $container.offsetHeight
const $wrapper = this.$refs.scrollWrapper const $wrapper = this.$refs.scrollWrapper
const $wrapperHeight = $wrapper.offsetHeight const $wrapperHeight = $wrapper.offsetHeight
if (e.wheelDelta > 0) { if (eventDelta > 0) {
this.top = Math.min(0, this.top + e.wheelDelta) this.top = Math.min(0, this.top + eventDelta)
} else { } else {
if ($containerHeight - delta < $wrapperHeight) { if ($containerHeight - delta < $wrapperHeight) {
if (this.top < -($wrapperHeight - $containerHeight + delta)) { if (this.top < -($wrapperHeight - $containerHeight + delta)) {
this.top = this.top this.top = this.top
} else { } else {
this.top = Math.max(this.top + e.wheelDelta, $containerHeight - $wrapperHeight - delta) this.top = Math.max(this.top + eventDelta, $containerHeight - $wrapperHeight - delta)
} }
} else { } else {
this.top = 0 this.top = 0

View File

@ -1,21 +1,21 @@
<template> <template>
<div class="menu-wrapper"> <div class="menu-wrapper">
<template v-for="item in routes"> <template v-for="item in routes" v-if="!item.hidden&&item.children">
<router-link v-if="!item.hidden&&item.children&&item.children.length===1" :to="item.path+'/'+item.children[0].path" :key="item.children[0].name"> <router-link v-if="item.children.length===1 && !item.children[0].children" :to="item.path+'/'+item.children[0].path" :key="item.children[0].name">
<el-menu-item :index="item.path+'/'+item.children[0].path" class='submenu-title-noDropdown'> <el-menu-item :index="item.path+'/'+item.children[0].path" class='submenu-title-noDropdown'>
<svg-icon v-if="item.children[0].meta&&item.children[0].meta.icon" :icon-class="item.children[0].meta.icon"></svg-icon> <svg-icon v-if="item.children[0].meta&&item.children[0].meta.icon" :icon-class="item.children[0].meta.icon"></svg-icon>
<span v-if="item.children[0].meta&&item.children[0].meta.title">{{item.children[0].meta.title}}</span> <span v-if="item.children[0].meta&&item.children[0].meta.title">{{item.children[0].meta.title}}</span>
</el-menu-item> </el-menu-item>
</router-link> </router-link>
<el-submenu v-if="!item.hidden&&item.children&&item.children.length>1" :index="item.name||item.path" :key="item.name"> <el-submenu v-else :index="item.name||item.path" :key="item.name">
<template slot="title"> <template slot="title">
<svg-icon v-if="item.meta&&item.meta.icon" :icon-class="item.meta.icon"></svg-icon> <svg-icon v-if="item.meta&&item.meta.icon" :icon-class="item.meta.icon"></svg-icon>
<span v-if="item.meta&&item.meta.title">{{item.meta.title}}</span> <span v-if="item.meta&&item.meta.title">{{item.meta.title}}</span>
</template> </template>
<template v-if="!child.hidden" v-for="child in item.children"> <template v-for="child in item.children" v-if="!child.hidden">
<sidebar-item class="nest-menu" v-if="child.children&&child.children.length>0" :routes="[child]" :key="child.path"></sidebar-item> <sidebar-item class="nest-menu" v-if="child.children&&child.children.length>0" :routes="[child]" :key="child.path"></sidebar-item>
<router-link v-else :to="item.path+'/'+child.path" :key="child.name"> <router-link v-else :to="item.path+'/'+child.path" :key="child.name">