1
0

app-navigation-icon.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view :style="{backgroundColor: background, height: height}">
  3. <swiper class="app-swiper" style="height: 100%">
  4. <swiper-item :style="{height: height}" 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: 0,
  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. if (newMenus.length === 0 ) return newMenus;
  97. return newMenus;
  98. }
  99. },
  100. watch: {
  101. newData: {
  102. handler: function(newVal) {
  103. this.height = `${uni.upx2px(newVal[0].length * 156)}px`;
  104. },
  105. immediate: true
  106. }
  107. }
  108. }
  109. </script>
  110. <style scoped lang="scss">
  111. .app-swiper-item {
  112. width: #{750rpx};
  113. }
  114. .app-rows {
  115. width: #{750rpx};
  116. margin-top: #{28rpx};
  117. margin-bottom: #{4rpx};
  118. }
  119. .app-icon {
  120. width: #{90rpx};
  121. height: #{90rpx};
  122. }
  123. .app-text {
  124. font-size: #{24rpx};
  125. color: #353535;
  126. height: #{24rpx};
  127. line-height: #{24rpx};
  128. text-align: center;
  129. margin-top: #{8rpx};
  130. word-break: break-all;
  131. text-overflow: ellipsis;
  132. display: -webkit-box;
  133. -webkit-box-orient: vertical;
  134. -webkit-line-clamp: 1;
  135. overflow: hidden;
  136. }
  137. .app-swiper {
  138. width: 100%;
  139. height: 100% !important;
  140. }
  141. </style>