menus.vue 7.0 KB

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