menus.vue 5.7 KB

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