menus.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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" :style="[textColor]" :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" :style="[textColor]" :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. let list = this.dataConfig.menuConfig.list || [];
  103. let menuList = [];
  104. list.forEach(item=>{
  105. if(item.show){
  106. menuList.push(item);
  107. }
  108. })
  109. return menuList
  110. },
  111. isShowConfig(){
  112. return this.dataConfig.showConfig.tabVal
  113. },
  114. boxStyle(){
  115. return {
  116. padding: `${this.dataConfig.topConfig.val * 2}rpx ${this.dataConfig.prConfig.val * 2}rpx ${this.dataConfig.bottomConfig.val * 2}rpx`,
  117. marginTop: `${this.dataConfig.mbConfig.val * 2}rpx`,
  118. background: this.dataConfig.bottomBgColor.color[0].item,
  119. }
  120. },
  121. textColor(){
  122. console.log(this.dataConfig,'this.dataConfig.textColor')
  123. return {
  124. color: this.dataConfig.textColor ? this.dataConfig.textColor.color[0].item : '#333'
  125. }
  126. },
  127. boxContentStyle() {
  128. let borderRadius = `${this.dataConfig.fillet.val * 2}rpx`;
  129. if (this.dataConfig.fillet.type) {
  130. borderRadius =
  131. `${this.dataConfig.fillet.valList[0].val * 2}rpx ${this.dataConfig.fillet.valList[1].val * 2}rpx ${this.dataConfig.fillet.valList[3].val * 2}rpx ${this.dataConfig.fillet.valList[2].val * 2}rpx`;
  132. }
  133. return {
  134. borderRadius,
  135. background: `linear-gradient(90deg, ${this.dataConfig.bgColor.color[0].item} 0%, ${this.dataConfig.bgColor.color[1].item} 100%)`,
  136. };
  137. },
  138. imgStyle(){
  139. let borderRadius = `${this.dataConfig.filletImg.val * 2}rpx`;
  140. if (this.dataConfig.filletImg.type) {
  141. borderRadius =
  142. `${this.dataConfig.filletImg.valList[0].val * 2}rpx ${this.dataConfig.filletImg.valList[1].val * 2}rpx ${this.dataConfig.filletImg.valList[3].val * 2}rpx ${this.dataConfig.filletImg.valList[2].val * 2}rpx`;
  143. }
  144. return borderRadius
  145. },
  146. //分几行展示,一行展示多少个
  147. gridColumns() {
  148. if (this.dataConfig.number.tabVal == 0) {
  149. return {
  150. gridTemplateColumns: 'repeat(3, 1fr)'
  151. }
  152. } else if (this.dataConfig.number.tabVal == 1) {
  153. return {
  154. gridTemplateColumns: 'repeat(4, 1fr)'
  155. }
  156. } else {
  157. return {
  158. gridTemplateColumns: 'repeat(5, 1fr)'
  159. }
  160. }
  161. },
  162. menuStyleConfig(){
  163. return this.dataConfig.menuStyleConfig.tabVal
  164. },
  165. dotColor(){
  166. return this.dataConfig.pointerBgColor.color[0].item
  167. },
  168. dotSelectColor(){
  169. return this.dataConfig.pointerColor.color[0].item
  170. }
  171. },
  172. mounted() {
  173. this.getSwiperCount();
  174. this.$nextTick(() => {
  175. if (this.menuList.length&&this.isShowConfig) {
  176. let that = this
  177. // #ifdef H5
  178. that.menuHeight()
  179. // #endif
  180. // #ifndef H5
  181. setTimeout(() => {
  182. that.menuHeight()
  183. },150)
  184. // #endif
  185. }
  186. })
  187. },
  188. methods: {
  189. getSwiperCount(){
  190. /* rowsNum 显示行数 0: 1行 1: 2行 2: 3行 3 4行 */
  191. /* number 单行显示 0: 3个 1: 4个 2: 5个 */
  192. this.pageNum((this.rowsNum + 1) * (this.number + 3));
  193. },
  194. bannerfun(e) {
  195. this.active = e.detail.current;
  196. },
  197. menuHeight(){
  198. let that = this;
  199. const query = uni.createSelectorQuery().in(this);
  200. query.select('#nav0').boundingClientRect(data => {
  201. that.navHigh = data.height;
  202. }).exec();
  203. },
  204. pageNum(num) {
  205. let count = Math.ceil(this.menus.length / num);
  206. let goodArray = new Array();
  207. for (let i = 0; i < count; i++) {
  208. let list = this.menus.slice(i * num, i * num + num);
  209. if (list.length)
  210. goodArray.push({
  211. list: list
  212. });
  213. }
  214. this.$set(this, 'menuList', goodArray);
  215. },
  216. menusTap(url) {
  217. this.$util.JumpPath(url);
  218. }
  219. }
  220. };
  221. </script>
  222. <style lang="scss">
  223. .dot {
  224. width: 100%;
  225. padding-bottom: 20rpx;
  226. .instruct {
  227. width: 50rpx;
  228. height: 36rpx;
  229. line-height: 36rpx;
  230. background-color: rgba(0, 0, 0, 0.8);
  231. color: #fff;
  232. border-radius: 16rpx;
  233. font-size: 24rpx;
  234. text-align: center;
  235. }
  236. .dot-item {
  237. width: 10rpx;
  238. height: 10rpx;
  239. background: rgba(0, 0, 0, .4);
  240. border-radius: 50%;
  241. margin: 0 4px;
  242. &.line_dot-item {
  243. width: 20rpx;
  244. height: 6rpx;
  245. border-radius: 3rpx;
  246. }
  247. }
  248. }
  249. .nav {
  250. .item {
  251. margin-right: 42rpx;
  252. width: 90rpx;
  253. text-align: center;
  254. font-size: 24rpx;
  255. display: inline-block;
  256. }
  257. }
  258. .menu {
  259. display: grid;
  260. grid-template-rows: auto;
  261. grid-row-gap: 24rpx;
  262. width: 100%;
  263. padding: 20rpx 0;
  264. }
  265. .swiper {
  266. z-index: 20;
  267. position: relative;
  268. overflow: hidden;
  269. swiper,
  270. .swiper-item {
  271. width: 100%;
  272. display: block;
  273. }
  274. }
  275. </style>