navBar.vue 8.3 KB

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