代码简化

master
toesbieya 6 years ago
parent 78f9afce89
commit eb2271d100
  1. 14
      vue/src/layout/component/Main/component/Breadcrumb.vue
  2. 5
      vue/src/layout/component/Navbar/component/RootMenu.vue
  3. 3
      vue/src/layout/component/TagsView/ScrollPane.vue
  4. 92
      vue/src/layout/component/TagsView/index.vue
  5. 36
      vue/src/view/index/indexPage.vue

@ -13,9 +13,11 @@ export default {
data: () => ({data: []}), data: () => ({data: []}),
watch: { watch: {
$route(route) { $route: {
if (route.path.startsWith('/redirect')) return immediate: true,
this.getBreadcrumb() handler(route) {
!route.path.startsWith('/redirect') && this.getBreadcrumb()
}
} }
}, },
@ -24,10 +26,6 @@ export default {
// only show routes with meta.title // only show routes with meta.title
this.data = this.$route.matched.filter(item => item.meta.title) this.data = this.$route.matched.filter(item => item.meta.title)
} }
},
mounted() {
this.getBreadcrumb()
} }
} }
</script> </script>
@ -35,7 +33,7 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.app-breadcrumb { .app-breadcrumb {
width: 100%; width: 100%;
background: #fff; background-color: #ffffff;
padding: 16px 24px; padding: 16px 24px;
.no-redirect { .no-redirect {

@ -25,11 +25,10 @@ export default {
data() { data() {
return { return {
// //
//undefined //undefined-1
//-1
lastVisibleIndex: undefined, lastVisibleIndex: undefined,
//menu-popover //
showPopover: false showPopover: false
} }
}, },

@ -28,7 +28,7 @@ export default {
moveToTarget(currentTag) { moveToTarget(currentTag) {
const $containerWidth = this.$refs.scrollContainer.$el.offsetWidth const $containerWidth = this.$refs.scrollContainer.$el.offsetWidth
const {scrollWidth, scrollLeft} = this.getWrapper() const {scrollWidth, scrollLeft} = this.getWrapper()
const tagList = this.$parent.$refs.tag const tagList = this.$parent.getTags()
let firstTag = null let firstTag = null
let lastTag = null let lastTag = null
@ -73,6 +73,7 @@ export default {
}) })
}, },
//300ms
smoothScroll(val) { smoothScroll(val) {
if (this.rAF) window.cancelAnimationFrame(this.rAF) if (this.rAF) window.cancelAnimationFrame(this.rAF)
let cost = 300, times = cost / 16, gap = val / times + 1 let cost = 300, times = cost / 16, gap = val / times + 1

@ -1,32 +1,3 @@
<template>
<nav class="tags-view-container">
<scroll-pane ref="scrollPane" class="tags-view-wrapper">
<router-link
ref="tag"
v-for="tag in visitedViews"
:key="tag.path"
:class="{'tags-view-item': true, active: isActive(tag)}"
:to="{ path: tag.path, query: tag.query, fullPath: tag.fullPath }"
tag="div"
@contextmenu.prevent.native="e => openMenu(tag, e)"
@dblclick.prevent.native="() => closeSelectedTag(tag)"
>
{{ tag.title }}
<i v-if="!isAffix(tag)" class="el-icon-close" @click.prevent.stop="() => closeSelectedTag(tag)"/>
</router-link>
</scroll-pane>
<context-menu v-model="contextmenu.show" :left="contextmenu.left" :top="contextmenu.top">
<context-menu-item @click="() => refreshSelectedTag(selectedTag)">刷新</context-menu-item>
<context-menu-item v-if="!isAffix(selectedTag)" @click="() => closeSelectedTag(selectedTag)">
关闭
</context-menu-item>
<context-menu-item @click="closeOthersTags">关闭其他</context-menu-item>
<context-menu-item @click="closeAllTags">关闭全部</context-menu-item>
</context-menu>
</nav>
</template>
<script type="text/jsx"> <script type="text/jsx">
import shortcutMixin from '@/layout/mixin/shortcut' import shortcutMixin from '@/layout/mixin/shortcut'
import decideRouterTransitionMixin from '@/layout/mixin/decideRouterTransition' import decideRouterTransitionMixin from '@/layout/mixin/decideRouterTransition'
@ -109,11 +80,14 @@ export default {
addTags(to = this.$route) { addTags(to = this.$route) {
to.meta.title && tagsViewMutations.addView(to) to.meta.title && tagsViewMutations.addView(to)
}, },
getTags() {
return this.$refs.scrollPane.$children[0].$children
},
//tab //tab
moveToCurrentTag() { moveToCurrentTag() {
this.$nextTick(() => { this.$nextTick(() => {
const tag = this.$refs.tag.find(i => i.to.path === this.$route.path) const tag = this.getTags().find(i => i.to.path === this.$route.path)
tag && this.$refs.scrollPane.moveToTarget(tag) tag && this.$refs.scrollPane.moveToTarget(tag)
}) })
}, },
@ -122,9 +96,10 @@ export default {
* 右键菜单选项 * 右键菜单选项
* 刷新所选关闭所选关闭其他关闭所有 * 刷新所选关闭所选关闭其他关闭所有
* */ * */
refreshSelectedTag(view) { refreshSelectedTag() {
tagsViewMutations.delCachedView(view) if (!this.selectedTag) return
this.$nextTick(() => this.$router.replace({path: `/redirect${view.fullPath}`})) tagsViewMutations.delCachedView(this.selectedTag)
this.$nextTick(() => this.$router.replace({path: `/redirect${this.selectedTag.fullPath}`}))
}, },
closeSelectedTag(view) { closeSelectedTag(view) {
if (this.isAffix(view)) return if (this.isAffix(view)) return
@ -156,6 +131,8 @@ export default {
}, },
openMenu(tag, e) { openMenu(tag, e) {
e.preventDefault()
const menuMinWidth = 105 const menuMinWidth = 105
const offsetLeft = this.$el.getBoundingClientRect().left // container margin left const offsetLeft = this.$el.getBoundingClientRect().left // container margin left
const offsetWidth = this.$el.offsetWidth // container width const offsetWidth = this.$el.offsetWidth // container width
@ -167,6 +144,44 @@ export default {
this.contextmenu.show = true this.contextmenu.show = true
this.selectedTag = tag this.selectedTag = tag
},
renderTags(h) {
return this.visitedViews.map(tag => {
const {title, path, query, fullPath} = tag
const active = this.isActive(tag), affix = this.isAffix(tag)
const closeSelectedTag = (e, tag) => {
e.preventDefault()
this.closeSelectedTag(tag)
}
return (
<router-link
key={path}
class={{'tags-view-item': true, active}}
to={{path, query, fullPath}}
tag="div"
v-on:contextmenu_native={e => this.openMenu(tag, e)}
v-on:dblclick_native={e => closeSelectedTag(e, tag)}
>
{title}
{!affix && <i class="el-icon-close" on-click={e => closeSelectedTag(e, tag)}/>}
</router-link>
)
})
},
renderContextmenu(h) {
const menu = this.contextmenu
return (
<context-menu v-model={menu.show} left={menu.left} top={menu.top}>
<context-menu-item on-click={this.refreshSelectedTag}>刷新</context-menu-item>
{!this.isAffix(this.selectedTag) &&
<context-menu-item on-click={() => this.closeSelectedTag(this.selectedTag)}>
关闭
</context-menu-item>}
<context-menu-item on-click={this.closeOthersTags}>关闭其他</context-menu-item>
<context-menu-item on-click={this.closeAllTags}>关闭全部</context-menu-item>
</context-menu>
)
} }
}, },
@ -178,6 +193,17 @@ export default {
mounted() { mounted() {
this.initTags() this.initTags()
this.addTags() this.addTags()
},
render(h) {
return (
<nav class="tags-view-container">
<scroll-pane ref="scrollPane" class="tags-view-wrapper">
{this.renderTags(h)}
</scroll-pane>
{this.renderContextmenu(h)}
</nav>
)
} }
} }
</script> </script>

@ -1,28 +1,30 @@
<template> <script type="text/jsx">
import PanelGroup from './component/PanelGroup'
import DailyProfitStat from "./component/DailyProfitStat"
import DailyFinishOrderStat from "./component/DailyFinishOrderStat"
import TotalProfitGoods from "./component/TotalProfitGoods"
export default {
name: 'index',
functional: true,
render() {
return (
<div> <div>
<panel-group/> <PanelGroup/>
<el-card> <el-card>
<daily-profit-stat/> <DailyProfitStat/>
</el-card> </el-card>
<el-card style="margin: 32px 0"> <el-card style="margin: 32px 0">
<daily-finish-order-stat/> <DailyFinishOrderStat/>
</el-card> </el-card>
<total-profit-goods/> <TotalProfitGoods/>
</div> </div>
</template> )
}
<script>
import PanelGroup from './component/PanelGroup'
import DailyProfitStat from "./component/DailyProfitStat"
import DailyFinishOrderStat from "./component/DailyFinishOrderStat"
import TotalProfitGoods from "./component/TotalProfitGoods"
export default {
name: 'index',
components: {PanelGroup, DailyProfitStat, DailyFinishOrderStat, TotalProfitGoods}
} }
</script> </script>

Loading…
Cancel
Save