From f30502d88e477052379fced6a041ab89581be4fd Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Mon, 15 Mar 2021 16:49:44 +0800 Subject: [PATCH] 公共样式兼容小程序 --- layout/h5Page/CNavBar.vue | 37 ++++++++++++++++++++++++++----------- 1 files changed, 26 insertions(+), 11 deletions(-) diff --git a/layout/h5Page/CNavBar.vue b/layout/h5Page/CNavBar.vue index b5dbf3e..50bfc5d 100644 --- a/layout/h5Page/CNavBar.vue +++ b/layout/h5Page/CNavBar.vue @@ -2,11 +2,17 @@ <view class="c-nav-bar"> <AtNavBar :title="title" - leftIconType="chevron-left" - :onClickLeftIcon="evt=>goBack()" + :leftIconType="iconType" + :onClickLeftIcon="evt=>onClickIcon ? onClickIcon() : onGoBack()" :rightFirstIconType="dropNav ? 'bullet-list' : ''" - :onClickRgIconSt="evt=>dropMenu()" + :onClickRgIconSt="evt=>onDropMenu()" /> + <view + class="c-nav-bar-right" + v-if="!dropNav" + > + <slot /> + </view> <view class="c-nav-bar-drop" v-show="dropShow" @@ -18,7 +24,7 @@ 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> @@ -38,6 +44,11 @@ }, props: { title: String, + iconType: { + type: String, + default: 'chevron-left', + }, + onClickIcon: Function, dropNav: Array, }, data() { @@ -48,10 +59,10 @@ }; }, methods: { - goBack() { - window.history.go(-1); + onGoBack() { + Taro.navigateBack(); }, - goNav(nav) { + onGoNav(nav) { if (!nav.url) { return; } @@ -60,7 +71,7 @@ Taro.navigateTo({ url: nav.url }); }, 0); }, - dropMenu() { + onDropMenu() { this.dropShow = !this.dropShow; this.dropActive = true; clearTimeout(this.dropTimer); @@ -69,7 +80,7 @@ }, 500); }, outCloseMenu(evt) { - (() => { + setTimeout(() => { // 未打开时,忽略 if (!this.dropShow) { return; @@ -79,12 +90,16 @@ return; } // 点击了菜单项,忽略 - if (evt.target.className.indexOf('c-nav-bar-drop-item') >= 0) { + 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() { -- Gitblit v1.9.1