navBar.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view :data-theme="theme">
  3. <view class="cart_nav acea-row" :style="{ height: navH + 'rpx', background: isScrolling ? '#fff' : backgroundColor}"
  4. :class="isBackgroundColor?'backgroundColor':''">
  5. <!-- #ifdef MP-->
  6. <view class="mp-header" :style="{ height: navH + 'rpx'}">
  7. <view class="sys-head" :style="{ height: sysHeight+'px' }"></view>
  8. <view v-if="isShowMenu && isShowBack" class="select_nav flex justify-center align-center" id="home" :style="{top: sysHeight+6+'px'}">
  9. <text class="iconfont f-s-36 icon-ic_left px-20" @tap="returns"></text>
  10. <text class="iconfont f-s-36 icon-ic_menu3 px-20" @tap.stop="showNav"></text>
  11. <text class="nav_line"></text>
  12. </view>
  13. <view v-if="!isShowMenu && isShowBack" @tap="returns" class="return-box" :style="{top: sysHeight+6+'px'}">
  14. <text class="iconfont f-s-36 icon-ic_leftarrow px-20" :style="{ color:iconColor}"></text>
  15. </view>
  16. <view class="nav_title" :style="{ height: '80rpx',lineHeight: '80rpx', color:iconColor}">
  17. {{navTitle}}
  18. <slot name="default"></slot>
  19. </view>
  20. </view>
  21. <!-- #endif -->
  22. <!-- #ifdef H5 -->
  23. <view v-show="isShowMenu && isShowBack" id="home" class="home acea-row row-center-wrapper iconfont f-s-36 icon-ic_leftarrow h5_back z-999"
  24. :style="{ top: homeTop + 'rpx'}" @tap="goToHome">
  25. </view>
  26. <view class="nav_title" :style="{ height: '80rpx',lineHeight: '80rpx', color:iconColor}">
  27. {{navTitle}}
  28. <slot name="default"></slot>
  29. </view>
  30. <view v-show="isShowMenu && isShowBack" class="right_select" :style="{ top: homeTop + 'rpx' }" @tap="showNav">
  31. <text class="iconfont icon-ic_more"></text>
  32. </view>
  33. <!-- #endif -->
  34. <!-- #ifdef APP-PLUS -->
  35. <view v-if="isShowBack" id="home" class="home acea-row row-center-wrapper f-s-36 iconfont icon-ic_leftarrow h5_back z-999"
  36. :style="{ top: (homeTop+20) + 'rpx' , color:iconColor}" @tap="returns">
  37. </view>
  38. <view v-if="isShowBack" class="nav_title" :style="{ top: (homeTop+20) + 'rpx' , color:iconColor}">
  39. {{navTitle}}
  40. <slot name="default"></slot>
  41. </view>
  42. <!-- #endif -->
  43. </view>
  44. <view class="dialog_nav" :style='"top:"+navH+"rpx;"' v-show="currentPage" style="z-index: 99999999;">
  45. <view class="dialog_nav_item" v-for="(item,index) in selectNavList" :key="index"
  46. @click="linkPage(item.url)" :class="item.after">
  47. <text class="iconfont" :class="item.icon"></text>
  48. <text class="pl-20">{{item.name}}</text>
  49. </view>
  50. </view>
  51. <view v-if="isHeight" :style="{ height: `${navH}rpx` }"></view>
  52. </view>
  53. </template>
  54. <script>
  55. // +----------------------------------------------------------------------
  56. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  57. // +----------------------------------------------------------------------
  58. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  59. // +----------------------------------------------------------------------
  60. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  61. // +----------------------------------------------------------------------
  62. // | Author: CRMEB Team <admin@crmeb.com>
  63. // +----------------------------------------------------------------------
  64. import animationType from '@/utils/animationType.js'
  65. import {
  66. mapGetters
  67. } from "vuex";
  68. let app = getApp();
  69. let sysHeight = uni.getSystemInfoSync().statusBarHeight;
  70. export default {
  71. props: {
  72. //是否展示返回按钮
  73. isShowBack: {
  74. type: Boolean,
  75. default: true
  76. },
  77. navTitle: {
  78. type: String,
  79. default: ''
  80. },
  81. backgroundColor: {
  82. type: String,
  83. default: 'transparent'
  84. },
  85. //头部背景色是否使用主题色颜色
  86. isBackgroundColor: {
  87. type: Boolean,
  88. default: true
  89. },
  90. // icon、标题颜色
  91. iconColor: {
  92. type: String,
  93. default: '#333333'
  94. },
  95. isHeight: {
  96. type: Boolean,
  97. default: true
  98. },
  99. //是否展示菜单标
  100. isShowMenu: {
  101. type: Boolean,
  102. default: true
  103. },
  104. // 滚动至下部
  105. isScrolling: {
  106. type: Boolean,
  107. default: false
  108. },
  109. goBack: {
  110. type: String,
  111. default: ''
  112. }
  113. },
  114. computed: mapGetters(['globalData']),
  115. data() {
  116. return {
  117. theme: app.globalData.theme,
  118. sysHeight: sysHeight,
  119. homeTop: 18,
  120. navH: "",
  121. currentPage: false,
  122. returnShow: false,
  123. selectNavList: [{
  124. name: '首页',
  125. icon: 'icon-ic_mall',
  126. url: '/pages/index/index',
  127. after:'dialog_after'
  128. },
  129. {
  130. name: '搜索',
  131. icon: 'icon-ic_search',
  132. url: '/pages/goods/goods_search/index',
  133. after:'dialog_after'
  134. },
  135. // {
  136. // name: '我的收藏',
  137. // icon: 'icon-shoucang3',
  138. // url: '/pages/goods/user_goods_collection/index',
  139. // after:'dialog_after'
  140. // },
  141. {
  142. name: '个人中心',
  143. icon: 'icon-a-ic_user1',
  144. url: '/pages/user/index'
  145. },
  146. ]
  147. }
  148. },
  149. created() {
  150. var pages = getCurrentPages();
  151. this.returnShow = pages.length === 1 ? false : true;
  152. this.$nextTick(function() {
  153. // #ifdef MP
  154. const menuButton = uni.getMenuButtonBoundingClientRect();
  155. const query = uni.createSelectorQuery().in(this);
  156. query
  157. .select('#home')
  158. .boundingClientRect(data => {
  159. if (data) this.homeTop = menuButton.top * 2 + menuButton.height - data.height;
  160. })
  161. .exec();
  162. // #endif
  163. // #ifdef APP-PLUS
  164. this.homeTop = sysHeight * 2;
  165. // #endif
  166. });
  167. // #ifdef MP || APP-PLUS
  168. // 获取导航高度;
  169. this.navH = this.globalData.navHeight;
  170. // #endif
  171. // #ifdef H5
  172. this.navH = 80;
  173. // #endif
  174. this.$emit('getNavH', this.navH)
  175. },
  176. methods: {
  177. returns: function() {
  178. if(this.returnShow){
  179. if(this.goBack){
  180. this.$util.navigateTo(`${this.goBack}`);
  181. }else{
  182. uni.navigateBack(-1);
  183. }
  184. }else{
  185. this.$util.navigateTo('/pages/index/index');
  186. }
  187. },
  188. //返回首页
  189. goToHome() {
  190. uni.navigateBack(-1);
  191. },
  192. showNav() {
  193. this.currentPage = !this.currentPage;
  194. },
  195. //下拉导航页面跳转
  196. linkPage(url) {
  197. this.$util.navigateTo(url);
  198. this.currentPage = false
  199. },
  200. touchStart() {
  201. this.currentPage = false;
  202. }
  203. }
  204. }
  205. </script>
  206. <style scoped lang="scss">
  207. /* #ifdef MP || APP-PLUS */
  208. .mp-header {
  209. z-index: 999;
  210. position: fixed;
  211. left: 0;
  212. top: 0;
  213. width: 100%;
  214. /* #ifdef H5 */
  215. padding-bottom: 20rpx;
  216. /* #endif */
  217. }
  218. /* #endif */
  219. .pl-20 {
  220. padding-left: 20rpx;
  221. }
  222. .backgroundColor {
  223. @include main_bg_color(theme);
  224. }
  225. .cart_nav {
  226. position: fixed;
  227. top: 0;
  228. left: 0;
  229. z-index: 99;
  230. width: 100%;
  231. }
  232. .navbarCon {
  233. position: absolute;
  234. bottom: 0;
  235. height: 100rpx;
  236. width: 100%;
  237. }
  238. .h5_back {
  239. color: #000;
  240. position: fixed;
  241. left: 20rpx;
  242. text-align: center;
  243. width: 50rpx;
  244. height: 50rpx;
  245. line-height: 50rpx;
  246. background: rgba(255, 255, 255, 0.3);
  247. border: 1px solid rgba(0, 0, 0, 0.1);
  248. border-radius: 50%;
  249. }
  250. .return-box{
  251. height: 60rpx;
  252. line-height: 58rpx;
  253. left: 14rpx;
  254. position: fixed;
  255. font-size: 18px;
  256. z-index: 999;
  257. }
  258. .select_nav {
  259. width: 170rpx !important;
  260. height: 60rpx !important;
  261. border-radius: 33rpx;
  262. background: rgba(255, 255, 255, 0.6);
  263. border: 1rpx solid rgba(0, 0, 0, 0.1);
  264. color: #000;
  265. position: fixed;
  266. font-size: 18px;
  267. line-height: 58rpx;
  268. z-index: 1000;
  269. left: 14rpx;
  270. }
  271. .px-20 {
  272. padding: 0 20rpx 0;
  273. }
  274. .nav_line {
  275. content: '';
  276. display: inline-block;
  277. width: 1px;
  278. height: 34rpx;
  279. background: #e8dfdf;
  280. position: absolute;
  281. left: 0;
  282. right: 0;
  283. margin: auto;
  284. }
  285. .container_detail {
  286. /* #ifdef MP */
  287. margin-top: 32rpx;
  288. /* #endif */
  289. }
  290. .tab_nav {
  291. width: 100%;
  292. height: 48px;
  293. padding: 0 30rpx 0;
  294. }
  295. .nav_title {
  296. //width: 200rpx;
  297. color: #fff;
  298. font-size: 36rpx;
  299. position: fixed;
  300. text-align: center;
  301. left: 0;
  302. right: 0;
  303. margin: auto;
  304. }
  305. .right_select {
  306. width: 50rpx;
  307. height: 50rpx;
  308. background: rgba(255, 255, 255, 0.3);
  309. border: 1px solid rgba(0, 0, 0, 0.1);
  310. border-radius: 50%;
  311. position: fixed;
  312. right: 20rpx;
  313. text-align: center;
  314. line-height: 50rpx;
  315. }
  316. .px-20 {
  317. padding: 0 20rpx 0;
  318. }
  319. .justify-center {
  320. justify-content: center;
  321. }
  322. .align-center {
  323. align-items: center;
  324. }
  325. .dialog_nav {
  326. position: fixed;
  327. /* #ifdef MP */
  328. left: 14rpx;
  329. /* #endif */
  330. /* #ifdef H5 || APP-PLUS*/
  331. right: 14rpx;
  332. /* #endif */
  333. background: #FFFFFF;
  334. box-shadow: 0px 0px 16rpx rgba(0, 0, 0, 0.08);
  335. z-index: 99999999 !important;
  336. border-radius: 14rpx;
  337. &::before {
  338. content: '';
  339. width: 0;
  340. height: 0;
  341. position: absolute;
  342. /* #ifdef MP */
  343. left: 0;
  344. right: 0;
  345. margin: auto;
  346. /* #endif */
  347. /* #ifdef H5 || APP-PLUS */
  348. right: 8px;
  349. /* #endif */
  350. top: -9px;
  351. border-bottom: 10px solid #fff;
  352. border-left: 10px solid transparent;
  353. /*transparent 表示透明*/
  354. border-right: 10px solid transparent;
  355. }
  356. }
  357. .dialog_nav_item {
  358. width: 100%;
  359. height: 84rpx;
  360. line-height: 84rpx;
  361. padding: 0 28rpx 0;
  362. box-sizing: border-box;
  363. border-bottom: #eee;
  364. font-size: 28rpx;
  365. color: #333;
  366. position: relative;
  367. .iconfont {
  368. font-size: 32rpx;
  369. color: #333 !important;
  370. }
  371. }
  372. .dialog_after{
  373. ::after {
  374. content: '';
  375. position: absolute;
  376. width: 86px;
  377. height: 1px;
  378. background-color: #EEEEEE;
  379. bottom: 0;
  380. right: 0;
  381. }
  382. }
  383. </style>