customMenu.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view>
  3. <!-- #ifdef MP || APP-PLUS -->
  4. <view style="visibility: hidden;" :style="{ height: navHeight + 'px' }" v-if="isFixed"></view>
  5. <!-- #endif -->
  6. <view class="navTabBox tabNav" :class="{isFixed:isFixed}" :style="'background: '+ bgColor[0].item +';margin-top:'+mbConfig+'rpx;color:'+txtColor+';top:'+isTop">
  7. <view class="longTab" :style='"width:"+mainWidth+"px"'>
  8. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="true">
  9. <view class="longItem" :style='"width:"+isWidth+"px"' :data-index="index" :class="index===tabClick?'click':''" v-for="(item,index) in tabTitle" :key="index" :id="'id'+index" @click="goDetail(index,item)">{{item.info[0].value}}</view>
  10. <view class="underlineBox" :style='"transform:translateX("+isLeft+"px);width:"+isWidth+"px"'>
  11. <view class="underline bg-color-red"></view>
  12. </view>
  13. </scroll-view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import {merPath} from "@/utils/index"
  20. // +----------------------------------------------------------------------
  21. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  22. // +----------------------------------------------------------------------
  23. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  24. // +----------------------------------------------------------------------
  25. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  26. // +----------------------------------------------------------------------
  27. // | Author: CRMEB Team <admin@crmeb.com>
  28. // +----------------------------------------------------------------------
  29. let app = getApp();
  30. export default {
  31. name: 'customMenu',
  32. props: {
  33. dataConfig: {
  34. type: Object,
  35. default: () => {}
  36. },
  37. isFixed: {
  38. type: Boolean,
  39. default: false
  40. },
  41. merId:{}
  42. },
  43. data() {
  44. return {
  45. tabClick: 0, //导航栏被点击
  46. isLeft: 0, //导航栏下划线位置
  47. isWidth: 0, //每个导航栏占位
  48. mainWidth: 0,
  49. tabLeft:0,
  50. swiperIndex:0,
  51. childIndex:0,
  52. childID:0,
  53. tabTitle:this.dataConfig.menuConfig.list,
  54. bgColor:this.dataConfig.bgColor.color,
  55. mbConfig:this.dataConfig.mbConfig.val*2,
  56. txtColor:this.dataConfig.txtColor.color[0].item,
  57. fixedTop: 0,
  58. isTop: 0,
  59. navHeight: 0,
  60. };
  61. },
  62. created() {
  63. var that = this
  64. // 获取设备宽度
  65. uni.getSystemInfo({
  66. success(e) {
  67. that.mainWidth = e.windowWidth
  68. that.isWidth = (e.windowWidth-65) / 4
  69. }
  70. })
  71. setTimeout((e) => {
  72. const query = uni.createSelectorQuery().in(this);
  73. query.select('.navTabBox').boundingClientRect(data => {
  74. that.navHeight = data.height
  75. that.$emit('bindHeight', data)
  76. }).exec();
  77. }, 200)
  78. // #ifdef MP || APP-PLUS
  79. this.isTop = (uni.getSystemInfoSync().statusBarHeight + 43) + 'px'
  80. // #endif
  81. // #ifdef H5
  82. this.isTop = 0
  83. // #endif
  84. },
  85. methods: {
  86. goDetail(index,url){
  87. this.childIndex = 0;
  88. if(this.tabTitle.length>3){
  89. var tempIndex = index - 2;
  90. tempIndex = tempIndex<=0 ? 0 : tempIndex;
  91. this.tabLeft = (index-2) * this.isWidth //设置下划线位置
  92. }
  93. this.tabClick = index //设置导航点击了哪一个
  94. this.isLeft = index * this.isWidth //设置下划线位置
  95. let urls = url.info[1].value
  96. urls = merPath(urls, this.merId)
  97. console.log(urls,'urls');
  98. if(urls.indexOf("http") != -1){
  99. // #ifdef H5
  100. location.href = urls
  101. // #endif
  102. }else{
  103. if(['/pages/goods_cate/goods_cate','/pages/order_addcart/order_addcart','/pages/user/index'].indexOf(urls) == -1){
  104. uni.navigateTo({
  105. url:urls
  106. })
  107. }else{
  108. uni.switchTab({
  109. url:urls
  110. })
  111. }
  112. }
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss">
  118. .tabNav {
  119. padding-top: 24rpx;
  120. }
  121. .navTabBox {
  122. width: 100%;
  123. color: rgba(255, 255, 255, 1);
  124. position: relative;
  125. padding-bottom: 20rpx;
  126. &.isFixed {
  127. z-index: 45;
  128. position: fixed;
  129. left: 0;
  130. width: 100%;
  131. /* #ifdef H5 */
  132. padding-top: 20rpx;
  133. top: 0;
  134. /* #endif */
  135. }
  136. .click {
  137. color: white;
  138. }
  139. .longTab {
  140. padding-bottom: 20rpx;
  141. .longItem{
  142. height: 50upx;
  143. display: inline-block;
  144. line-height: 50upx;
  145. text-align: center;
  146. font-size: 28rpx;
  147. color: #333333;
  148. max-width: 160rpx;
  149. white-space: nowrap;
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. &.click{
  153. font-weight: bold;
  154. font-size: 30rpx;
  155. color: #E93323;
  156. }
  157. }
  158. .underlineBox {
  159. height: 3px;
  160. width: 20%;
  161. display: flex;
  162. align-content: center;
  163. justify-content: center;
  164. transition: .5s;
  165. .underline {
  166. width: 33rpx;
  167. height: 4rpx;
  168. }
  169. }
  170. }
  171. }
  172. .child-box{
  173. width: 100%;
  174. position: relative;
  175. // height: 152rpx;
  176. background-color: #fff;
  177. /* #ifdef H5 */
  178. box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.02);
  179. /* #endif */
  180. /* #ifdef MP */
  181. box-shadow: 0 2rpx 3rpx 1rpx #f9f9f9;
  182. /* #endif */
  183. .wrapper{
  184. display: flex;
  185. align-items: center;
  186. padding: 20rpx 0;
  187. background: #fff;
  188. }
  189. .child-item{
  190. flex-shrink: 0;
  191. width:140rpx;
  192. display: flex;
  193. flex-direction: column;
  194. align-items: center;
  195. justify-content: center;
  196. margin-left: 10rpx;
  197. image{
  198. width: 90rpx;
  199. height: 90rpx;
  200. border-radius: 50%;
  201. }
  202. .txt{
  203. font-size: 24rpx;
  204. color: #282828;
  205. text-align: center;
  206. margin-top: 10rpx;
  207. }
  208. &.on{
  209. image{
  210. border: 1px solid $theme-color-opacity;
  211. }
  212. .txt{
  213. color: $theme-color;
  214. }
  215. }
  216. }
  217. }
  218. </style>