menus.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <!-- 导航组 -->
  3. <view v-show="menus.length" :style="[boxStyle]">
  4. <view v-if="isMany === 1">
  5. <view class="swiper">
  6. <swiper :interval="interval" :duration="duration" :style="'height:'+ navHigh +'px;'"
  7. @change='bannerfun'>
  8. <block>
  9. <swiper-item v-for="(item,indexw) in menuList" :key="indexw">
  10. <view class="menu acea-row" :id="'nav' + indexw" :style="[gridColumns]">
  11. <view :style="[titleColor]" class="item" :class="number===1?'four':number===2?'five':''"
  12. v-for="(itemn,indexn) in item.list" :key="indexn"
  13. @click="menusTap(itemn.info[1].value)">
  14. <view class="pictrue skeleton-radius">
  15. <easy-loadimage :image-src="itemn.img" :radius="dataConfig.contentStyle.val">
  16. </easy-loadimage>
  17. </view>
  18. <view class="menu-txt">{{ itemn.info[0].value }}</view>
  19. </view>
  20. </view>
  21. </swiper-item>
  22. </block>
  23. </swiper>
  24. </view>
  25. <view class="dot acea-row row-center-wrapper" v-if="docConfig<2 && menuList.length>1">
  26. <view class="dot-item line_dot-item" :style="active==index?'background:'+ dotColor:''"
  27. v-for="(item,index) in menuList"></view>
  28. </view>
  29. </view>
  30. <view class="nav oneNav" v-else>
  31. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex" show-scrollbar="false">
  32. <block v-for="(item, index) in menus" :key="index">
  33. <view class="item" v-if="item.status" :style="[titleColor]" @click="menusTap(item.info[1].value)">
  34. <view class="pictrue skeleton-radius">
  35. <easy-loadimage :image-src="item.img" :radius="dataConfig.contentStyle.val">
  36. </easy-loadimage>
  37. </view>
  38. <view class="menu-txt">{{ item.info[0].value }}</view>
  39. </view>
  40. </block>
  41. </scroll-view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. // +----------------------------------------------------------------------
  47. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  48. // +----------------------------------------------------------------------
  49. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  50. // +----------------------------------------------------------------------
  51. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  52. // +----------------------------------------------------------------------
  53. // | Author: CRMEB Team <admin@crmeb.com>
  54. // +----------------------------------------------------------------------
  55. import easyLoadimage from '@/components/base/easy-loadimage.vue';
  56. export default {
  57. name: 'menus',
  58. props: {
  59. dataConfig: {
  60. type: Object,
  61. default: () => {}
  62. }
  63. },
  64. components: {
  65. easyLoadimage
  66. },
  67. data() {
  68. return {
  69. interval: 3000,
  70. duration: 500,
  71. menus: this.dataConfig.menuConfig.list || [],
  72. rowsNum: this.dataConfig.rowsNum.tabVal,
  73. number: this.dataConfig.number.tabVal,
  74. isMany: this.dataConfig.tabConfig.tabVal,
  75. docConfig: 0,
  76. dotColor: '#E93323',
  77. menuList: [],
  78. active: 0,
  79. navHigh: 0
  80. };
  81. },
  82. computed: {
  83. //最外层盒子的样式
  84. boxStyle() {
  85. return {
  86. borderRadius: this.dataConfig.bgStyle.val * 2 + 'rpx',
  87. background: `linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`,
  88. margin: this.dataConfig.mbConfig.val * 2 + 'rpx' + ' ' + this.dataConfig.lrConfig.val * 2 + 'rpx' +' ' + 0,
  89. padding: this.dataConfig.upConfig.val * 2 + 'rpx' + ' ' + 0 + ' ' + this.dataConfig.downConfig.val *2 + 'rpx'
  90. }
  91. },
  92. //分几行展示,一行展示多少个
  93. gridColumns() {
  94. if (this.dataConfig.number.tabVal == 0) {
  95. return {
  96. gridRowGap: this.dataConfig.contentConfig.val * 2 + 'rpx',
  97. gridTemplateColumns: 'repeat(3, 1fr)'
  98. }
  99. } else if (this.dataConfig.number.tabVal == 1) {
  100. return {
  101. gridRowGap: this.dataConfig.contentConfig.val * 2 + 'rpx',
  102. gridTemplateColumns: 'repeat(4, 1fr)'
  103. }
  104. } else {
  105. return {
  106. gridRowGap: this.dataConfig.contentConfig.val * 2 + 'rpx',
  107. gridTemplateColumns: 'repeat(5, 1fr)'
  108. }
  109. }
  110. },
  111. //标题颜色
  112. titleColor() {
  113. return {
  114. 'color': this.dataConfig.titleColor.color[0].item,
  115. }
  116. },
  117. //内容圆角
  118. menuStyle() {
  119. return {
  120. 'border-radius': this.dataConfig.contentStyle.val + 'px'
  121. }
  122. }
  123. },
  124. mounted() {
  125. if (this.rowsNum === 0) {
  126. if (this.number === 0) {
  127. this.pageNum(6)
  128. } else if (this.number === 1) {
  129. this.pageNum(8)
  130. } else {
  131. this.pageNum(10)
  132. }
  133. } else if (this.rowsNum === 1) {
  134. if (this.number === 0) {
  135. this.pageNum(9)
  136. } else if (this.number === 1) {
  137. this.pageNum(12)
  138. } else {
  139. this.pageNum(15)
  140. }
  141. } else {
  142. if (this.number === 0) {
  143. this.pageNum(12)
  144. } else if (this.number === 1) {
  145. this.pageNum(16)
  146. } else {
  147. this.pageNum(20)
  148. }
  149. }
  150. this.$nextTick(() => {
  151. if (this.menuList.length && this.isMany===1) {
  152. let that = this
  153. // #ifdef H5
  154. that.menuHeight()
  155. // #endif
  156. // #ifndef H5
  157. setTimeout(() => {
  158. that.menuHeight()
  159. }, 150)
  160. // #endif
  161. }
  162. })
  163. },
  164. methods: {
  165. bannerfun(e) {
  166. this.active = e.detail.current;
  167. },
  168. menuHeight() {
  169. let that = this;
  170. const query = uni.createSelectorQuery().in(this);
  171. query.select('#nav0').boundingClientRect(data => {
  172. that.navHigh = data.height;
  173. }).exec();
  174. },
  175. pageNum(num) {
  176. let menus = this.menus.filter(item=>item.status);
  177. let count = Math.ceil(menus.length / num);
  178. let goodArray = new Array();
  179. for (let i = 0; i < count; i++) {
  180. let list = menus.slice(i * num, i * num + num);
  181. if (list.length)
  182. goodArray.push({
  183. list: list
  184. });
  185. }
  186. this.$set(this, 'menuList', goodArray);
  187. },
  188. menusTap(url) {
  189. this.$util.navigateTo(url);
  190. }
  191. }
  192. };
  193. </script>
  194. <style lang="scss" scoped>
  195. .dot {
  196. width: 100%;
  197. margin-top: 30rpx;
  198. .instruct {
  199. width: 50rpx;
  200. height: 36rpx;
  201. line-height: 36rpx;
  202. background-color: rgba(0, 0, 0, 0.8);
  203. color: #fff;
  204. border-radius: 16rpx;
  205. font-size: 24rpx;
  206. text-align: center;
  207. }
  208. .dot-item {
  209. width: 10rpx;
  210. height: 10rpx;
  211. background: rgba(0, 0, 0, .4);
  212. border-radius: 50%;
  213. margin: 0 4px;
  214. &.line_dot-item {
  215. width: 20rpx;
  216. height: 5rpx;
  217. border-radius: 3rpx;
  218. }
  219. }
  220. }
  221. .nav {
  222. .item {
  223. width: 160rpx;
  224. text-align: center;
  225. font-size: 24rpx;
  226. display: inline-block;
  227. .pictrue {
  228. width: 90rpx;
  229. height: 90rpx;
  230. margin: 0 auto;
  231. image {
  232. width: 100%;
  233. height: 100%;
  234. border-radius: 50%;
  235. }
  236. &.on {
  237. image {
  238. border-radius: 0;
  239. }
  240. }
  241. }
  242. .menu-txt {
  243. margin-top: 15rpx;
  244. }
  245. }
  246. }
  247. .swiper {
  248. z-index: 20;
  249. position: relative;
  250. overflow: hidden;
  251. .menu {
  252. display: grid;
  253. grid-template-rows: auto;
  254. width: 100%;
  255. padding: 0 20rpx;
  256. .item {
  257. .pictrue {
  258. width: 90rpx;
  259. height: 90rpx;
  260. margin: 0 auto;
  261. image {
  262. width: 100%;
  263. height: 100%;
  264. border-radius: 50%;
  265. }
  266. &.on {
  267. image {
  268. border-radius: 0;
  269. }
  270. }
  271. }
  272. .menu-txt {
  273. text-align: center;
  274. font-size: 12px;
  275. margin-top: 14rpx;
  276. }
  277. }
  278. }
  279. swiper,
  280. .swiper-item {
  281. width: 100%;
  282. display: block;
  283. }
  284. }
  285. </style>