app-navigation-icon.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="app-navigation-icon" :style="{backgroundColor: background, height: height}">
  3. <swiper class="app-swiper">
  4. <swiper-item class="app-swiper-item dir-top-nowrap" v-for="(item, itemIndex) in newData" :key="itemIndex">
  5. <view v-for="(rows, rowsIndex) in item" class="app-rows dir-left-nowrap" :key="rowsIndex">
  6. <view v-for="(columns, columnsIndex) in rows" :key="columnsIndex" class="app-item dir-top-nowrap cross-center" :style="{width: width}">
  7. <app-jump-button form :url="columns.link_url" :open_type="columns.open_type" arrangement="column">
  8. <image class="app-icon" :src="columns.icon_url" :lazy-load="true"></image>
  9. <text :style="{color: color}" class="app-text">{{columns.name}}</text>
  10. </app-jump-button>
  11. </view>
  12. </view>
  13. </swiper-item>
  14. </swiper>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'app-navigation-icon',
  20. data() {
  21. return {
  22. width: uni.upx2px(0)+ 'px',
  23. height: uni.upx2px(0)+ 'px',
  24. }
  25. },
  26. props: {
  27. background: {
  28. type: String,
  29. default() {
  30. return '#ffffff';
  31. }
  32. },
  33. color: {
  34. type: String,
  35. default() {
  36. return '';
  37. }
  38. },
  39. columns: {
  40. type: Number,
  41. default() {
  42. return 3;
  43. }
  44. },
  45. rows: {
  46. type: Number,
  47. default() {
  48. return 4;
  49. }
  50. },
  51. scroll: {
  52. type: Boolean,
  53. default() {
  54. return false;
  55. }
  56. },
  57. navs: {
  58. type: Array,
  59. default() {
  60. return [
  61. ]
  62. }
  63. }
  64. },
  65. computed: {
  66. newData: function() {
  67. this.width = `${uni.upx2px(750/this.columns)}px`;
  68. let menus = [];
  69. let newMenus = [];
  70. let num = Number(this.columns)* this.rows;
  71. if (this.scroll === true) {
  72. for (let i = 0; i < Math.ceil(this.navs.length/num); i++) {
  73. menus.push(this.navs.slice(i*num, (i+1)*num));
  74. }
  75. for (let i = 0; i < menus.length;i++) {
  76. let arr = [];
  77. for (let j = 0; j < Math.ceil(menus[i].length/ Number(this.columns)); j++) {
  78. arr.push(menus[i].slice(j* Number(this.columns), (j+1)* Number(this.columns)));
  79. }
  80. newMenus.push(arr);
  81. }
  82. } else {
  83. if (this.rows === -1) {
  84. menus = [this.navs];
  85. } else {
  86. menus.push(this.navs.slice(0, num));
  87. }
  88. for (let i = 0; i < menus.length;i++) {
  89. let arr = [];
  90. for (let j = 0; j < Math.ceil(menus[i].length/ Number(this.columns)); j++) {
  91. arr.push(menus[i].slice(j* Number(this.columns), (j+1)* Number(this.columns)));
  92. }
  93. newMenus.push(arr);
  94. }
  95. }
  96. this.height = `${uni.upx2px(newMenus[0].length * 156)}px`;
  97. return newMenus;
  98. }
  99. }
  100. }
  101. </script>
  102. <style scoped lang="scss">
  103. .app-navigation-icon {
  104. width: #{750rpx};
  105. .app-swiper-item {
  106. width: #{750rpx};
  107. }
  108. .app-rows {
  109. width: #{750rpx};
  110. margin-top: #{28rpx};
  111. margin-bottom: #{4rpx};
  112. }
  113. .app-icon {
  114. width: #{90rpx};
  115. height: #{90rpx};
  116. }
  117. .app-text {
  118. font-size: #{24rpx};
  119. color: #353535;
  120. height: #{24rpx};
  121. line-height: #{24rpx};
  122. text-align: center;
  123. margin-top: #{8rpx};
  124. word-break: break-all;
  125. text-overflow: ellipsis;
  126. display: -webkit-box;
  127. -webkit-box-orient: vertical;
  128. -webkit-line-clamp: 1;
  129. overflow: hidden;
  130. }
  131. .app-swiper {
  132. height: 100% !important;
  133. }
  134. }
  135. </style>