menus.vue 5.3 KB

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