menus.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <!-- 金刚区 -->
  3. <view v-show="!isSortType && menus.length" :class="bgStyle?'borderRadius15':''" :style="{background:bgColor,margin:'0 '+prConfig*2+'rpx',marginTop:mbConfig*2+'rpx'}">
  4. <view v-if="isMany">
  5. <view class="swiper">
  6. <swiper :interval="interval" :duration="duration" :style="'height:'+(navHigh+13)+'px;'" @change='bannerfun'>
  7. <block>
  8. <swiper-item v-for="(item,indexw) in menuList" :key="indexw">
  9. <view class="nav acea-row" :id="'nav' + indexw">
  10. <view :style="'color:' + titleColor" class="item" :class="number===1?'four':number===2?'five':''" v-for="(itemn,indexn) in item.list" :key="indexn" @click="menusTap(itemn.info[1].value)">
  11. <view class="pictrue skeleton-radius" :class="menuStyle?'':'on'">
  12. <image :src="itemn.img" mode="aspectFill"></image>
  13. </view>
  14. <view class="menu-txt">{{ itemn.info[0].value }}</view>
  15. </view>
  16. </view>
  17. </swiper-item>
  18. </block>
  19. </swiper>
  20. </view>
  21. <view class="dot acea-row row-center-wrapper" v-if="docConfig<2 && menuList.length>1">
  22. <view class="dot-item" :class="{ 'line_dot-item': docConfig === 0,'': docConfig === 1}" :style="active==index?'background:'+ dotColor:''" v-for="(item,index) in menuList"></view>
  23. </view>
  24. </view>
  25. <view class="nav oneNav" v-else>
  26. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex" show-scrollbar="false">
  27. <block v-for="(item, index) in menus" :key="index">
  28. <view class="item" :style="'color:' + titleColor" @click="menusTap(item.info[1].value)">
  29. <view class="pictrue skeleton-radius" :class="menuStyle?'':'on'">
  30. <image :src="item.img" mode="aspectFill"></image>
  31. </view>
  32. <view class="menu-txt">{{ item.info[0].value }}</view>
  33. </view>
  34. </block>
  35. </scroll-view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. name: 'menus',
  42. props: {
  43. dataConfig: {
  44. type: Object,
  45. default: () => {}
  46. },
  47. isSortType: {
  48. type: String | Number,
  49. default: 0
  50. }
  51. },
  52. data() {
  53. return {
  54. interval: 3000,
  55. duration: 500,
  56. menus: this.dataConfig.menuConfig.list || [],
  57. titleColor: this.dataConfig.titleColor.color[0].item,
  58. mbConfig: this.dataConfig.mbConfig.val,
  59. rowsNum: this.dataConfig.rowsNum.type,
  60. number: this.dataConfig.number.type,
  61. isMany: this.dataConfig.tabConfig.tabVal,
  62. menuStyle: this.dataConfig.menuStyle.type,
  63. docConfig: this.dataConfig.pointerStyle.type,
  64. dotColor: this.dataConfig.pointerColor.color[0].item,
  65. bgColor: this.dataConfig.bgColor.color[0].item,
  66. bgStyle: this.dataConfig.bgStyle.type,
  67. prConfig: this.dataConfig.prConfig.val,
  68. navHigh: 170,
  69. menuList: [],
  70. active: 0
  71. };
  72. },
  73. created() {},
  74. mounted() {
  75. if (this.rowsNum === 0) {
  76. if (this.number === 0) {
  77. this.pageNum(6)
  78. } else if (this.number === 1) {
  79. this.pageNum(8)
  80. } else {
  81. this.pageNum(10)
  82. }
  83. } else if (this.rowsNum === 1) {
  84. if (this.number === 0) {
  85. this.pageNum(9)
  86. } else if (this.number === 1) {
  87. this.pageNum(12)
  88. } else {
  89. this.pageNum(15)
  90. }
  91. } else {
  92. if (this.number === 0) {
  93. this.pageNum(12)
  94. } else if (this.number === 1) {
  95. this.pageNum(16)
  96. } else {
  97. this.pageNum(20)
  98. }
  99. }
  100. this.$nextTick(() => {
  101. if (this.menuList.length&&this.isMany) {
  102. let that = this
  103. // #ifdef H5
  104. that.menuHeight()
  105. // #endif
  106. // #ifndef H5
  107. setTimeout(() => {
  108. that.menuHeight()
  109. },150)
  110. // #endif
  111. }
  112. })
  113. },
  114. methods: {
  115. bannerfun(e) {
  116. this.active = e.detail.current;
  117. },
  118. menuHeight(){
  119. let that = this;
  120. const query = uni.createSelectorQuery().in(this);
  121. query.select('#nav0').boundingClientRect(data => {
  122. that.navHigh = data.height;
  123. }).exec();
  124. },
  125. pageNum(num) {
  126. let count = Math.ceil(this.menus.length / num);
  127. let goodArray = new Array();
  128. for (let i = 0; i < count; i++) {
  129. let list = this.menus.slice(i * num, i * num + num);
  130. if (list.length)
  131. goodArray.push({
  132. list: list
  133. });
  134. }
  135. this.$set(this, 'menuList', goodArray);
  136. },
  137. menusTap(url) {
  138. if(url == '/pages/short_video/appSwiper/index' || url == '/pages/short_video/nvueSwiper/index'){
  139. //#ifdef APP
  140. url = '/pages/short_video/appSwiper/index'
  141. //#endif
  142. //#ifndef APP
  143. url = '/pages/short_video/nvueSwiper/index'
  144. //#endif
  145. }
  146. if (url.indexOf("http") != -1) {
  147. // #ifdef H5
  148. location.href = url
  149. // #endif
  150. // #ifdef MP || APP-PLUS
  151. uni.navigateTo({
  152. url: `/pages/annex/web_view/index?url=${url}`
  153. });
  154. // #endif
  155. } else {
  156. if (['/pages/goods_cate/goods_cate', '/pages/order_addcart/order_addcart', '/pages/user/index', '/pages/store_cate/store_cate']
  157. .indexOf(url) == -1) {
  158. uni.navigateTo({
  159. url: url
  160. })
  161. } else {
  162. uni.reLaunch({
  163. url: url
  164. })
  165. }
  166. }
  167. }
  168. }
  169. };
  170. </script>
  171. <style lang="scss">
  172. .dot {
  173. width: 100%;
  174. padding-bottom: 20rpx;
  175. .instruct {
  176. width: 50rpx;
  177. height: 36rpx;
  178. line-height: 36rpx;
  179. background-color: rgba(0, 0, 0, 0.8);
  180. color: #fff;
  181. border-radius: 16rpx;
  182. font-size: 24rpx;
  183. text-align: center;
  184. }
  185. .dot-item {
  186. width: 10rpx;
  187. height: 10rpx;
  188. background: rgba(0, 0, 0, .4);
  189. border-radius: 50%;
  190. margin: 0 4px;
  191. &.line_dot-item {
  192. width: 20rpx;
  193. height: 5rpx;
  194. border-radius: 3rpx;
  195. }
  196. }
  197. }
  198. .nav {
  199. &.oneNav{
  200. padding-bottom: 25rpx;
  201. }
  202. .item {
  203. margin-top: 30rpx;
  204. width: 160rpx;
  205. text-align: center;
  206. font-size: 24rpx;
  207. display: inline-block;
  208. .pictrue {
  209. width: 90rpx;
  210. height: 90rpx;
  211. margin: 0 auto;
  212. image {
  213. width: 100%;
  214. height: 100%;
  215. border-radius: 50%;
  216. }
  217. &.on {
  218. image {
  219. border-radius: 0;
  220. }
  221. }
  222. }
  223. .menu-txt {
  224. margin-top: 15rpx;
  225. }
  226. }
  227. }
  228. .swiper {
  229. z-index: 20;
  230. position: relative;
  231. overflow: hidden;
  232. .nav {
  233. .item {
  234. width: 33.3333%;
  235. &.four {
  236. width: 25%;
  237. }
  238. &.five {
  239. width: 20%;
  240. }
  241. }
  242. }
  243. swiper,
  244. .swiper-item {
  245. width: 100%;
  246. display: block;
  247. }
  248. }
  249. </style>