menus.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. this.$util.JumpPath(url);
  139. }
  140. }
  141. };
  142. </script>
  143. <style lang="scss">
  144. .dot {
  145. width: 100%;
  146. padding-bottom: 20rpx;
  147. .instruct {
  148. width: 50rpx;
  149. height: 36rpx;
  150. line-height: 36rpx;
  151. background-color: rgba(0, 0, 0, 0.8);
  152. color: #fff;
  153. border-radius: 16rpx;
  154. font-size: 24rpx;
  155. text-align: center;
  156. }
  157. .dot-item {
  158. width: 10rpx;
  159. height: 10rpx;
  160. background: rgba(0, 0, 0, .4);
  161. border-radius: 50%;
  162. margin: 0 4px;
  163. &.line_dot-item {
  164. width: 20rpx;
  165. height: 5rpx;
  166. border-radius: 3rpx;
  167. }
  168. }
  169. }
  170. .nav {
  171. &.oneNav{
  172. padding-bottom: 25rpx;
  173. }
  174. .item {
  175. margin-top: 30rpx;
  176. width: 150rpx;
  177. text-align: center;
  178. font-size: 24rpx;
  179. display: inline-block;
  180. .pictrue {
  181. width: 90rpx;
  182. height: 90rpx;
  183. margin: 0 auto;
  184. image {
  185. width: 100%;
  186. height: 100%;
  187. border-radius: 50%;
  188. }
  189. &.on {
  190. image {
  191. border-radius: 0;
  192. }
  193. }
  194. }
  195. .menu-txt {
  196. margin-top: 15rpx;
  197. }
  198. }
  199. }
  200. .swiper {
  201. z-index: 20;
  202. position: relative;
  203. overflow: hidden;
  204. .nav {
  205. .item {
  206. width: 33.3333%;
  207. &.four {
  208. width: 25%;
  209. }
  210. &.five {
  211. width: 20%;
  212. }
  213. }
  214. }
  215. swiper,
  216. .swiper-item {
  217. width: 100%;
  218. display: block;
  219. }
  220. }
  221. </style>