menus.vue 5.2 KB

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