From 607ca3a52f33a14e83533b5f8c34252016c819c3 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Wed, 09 Dec 2020 10:44:24 +0800 Subject: [PATCH] 允许 polit 在 createOptions 时,插入 data --- layout/h5Page/CNavBar.vue | 42 +++++++++++++++++++++++++++++++++++------- 1 files changed, 35 insertions(+), 7 deletions(-) diff --git a/layout/h5Page/CNavBar.vue b/layout/h5Page/CNavBar.vue index cd6d74e..75bed2e 100644 --- a/layout/h5Page/CNavBar.vue +++ b/layout/h5Page/CNavBar.vue @@ -15,7 +15,7 @@ <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)" @@ -43,6 +43,8 @@ data() { return { dropShow: false, + dropTimer: -1, + dropActive: false, }; }, methods: { @@ -54,16 +56,42 @@ return; } this.dropShow = false; - let method = 'navigateTo'; - if (/navigate|redirect/.test(nav.method)) { - method = nav.method + 'To'; - } - Taro[method]({ url: nav.url }); + Taro.navigateTo({ url: nav.url }); }, dropMenu() { this.dropShow = !this.dropShow; + this.dropActive = true; + clearTimeout(this.dropTimer); + this.dropTimer = setTimeout(() => { + this.dropActive = false; + }, 500); + }, + outCloseMenu(evt) { + (() => { + // 未打开时,忽略 + if (!this.dropShow) { + return; + } + // 刚刚打开的一段时间内,忽略 + if (this.dropActive) { + return; + } + // 点击了菜单项,忽略 + if (evt.target.className.indexOf('c-nav-bar-drop-item') >= 0) { + return; + } + // 执行关闭 + this.dropShow = false; + })(); }, }, - 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