From 337526cd5eb6b3ea05a924bfd65368ff6b1a8231 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Thu, 14 Jan 2021 16:38:21 +0800 Subject: [PATCH] 删除无用代码 --- layout/h5Page/CNavBar.vue | 62 ++++++++++++++++++++++++------- 1 files changed, 48 insertions(+), 14 deletions(-) diff --git a/layout/h5Page/CNavBar.vue b/layout/h5Page/CNavBar.vue index cd6d74e..b037ade 100644 --- a/layout/h5Page/CNavBar.vue +++ b/layout/h5Page/CNavBar.vue @@ -3,9 +3,9 @@ <AtNavBar :title="title" leftIconType="chevron-left" - :onClickLeftIcon="evt=>goBack()" + :onClickLeftIcon="evt=>onGoBack()" :rightFirstIconType="dropNav ? 'bullet-list' : ''" - :onClickRgIconSt="evt=>dropMenu()" + :onClickRgIconSt="evt=>onDropMenu()" /> <view class="c-nav-bar-drop" @@ -15,10 +15,10 @@ <view class="arrow"></view> <view class="box"> <view - class="item" + class="c-nav-bar-drop-item item" v-for="(nav,index) in dropNav" :key="index" - @tap="evt=>goNav(nav)" + @tap="evt=>onGoNav(nav)" >{{nav.title}}</view> </view> </view> @@ -43,27 +43,61 @@ data() { return { dropShow: false, + dropTimer: -1, + dropActive: false, }; }, methods: { - goBack() { - window.history.go(-1); + onGoBack() { + Taro.navigateBack(); }, - goNav(nav) { + onGoNav(nav) { if (!nav.url) { return; } this.dropShow = false; - let method = 'navigateTo'; - if (/navigate|redirect/.test(nav.method)) { - method = nav.method + 'To'; - } - Taro[method]({ url: nav.url }); + setTimeout(() => { + Taro.navigateTo({ url: nav.url }); + }, 0); }, - dropMenu() { + onDropMenu() { this.dropShow = !this.dropShow; + this.dropActive = true; + clearTimeout(this.dropTimer); + this.dropTimer = setTimeout(() => { + this.dropActive = false; + }, 500); + }, + outCloseMenu(evt) { + setTimeout(() => { + // 未打开时,忽略 + if (!this.dropShow) { + return; + } + // 刚刚打开的一段时间内,忽略 + if (this.dropActive) { + return; + } + // 点击了菜单项,忽略 + const className = evt.target.className; + if ( + className.indexOf('c-nav-bar-drop-item') >= 0 || + className.indexOf('at-nav-bar__container') >= 0 + ) { + return; + } + // 执行关闭 + this.dropShow = false; + }, 0); }, }, - mounted() {}, + mounted() { + Taro.eventCenter.on('pageTouchstart', this.outCloseMenu); + Taro.eventCenter.on('pageClick', this.outCloseMenu); + }, + beforeDestroy() { + Taro.eventCenter.off('pageTouchstart', this.outCloseMenu); + Taro.eventCenter.off('pageClick', this.outCloseMenu); + }, }; </script> \ No newline at end of file -- Gitblit v1.9.1