app-navigation-icon.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. <block v-for="(columns, columnsIndex) in rows" :key="columnsIndex">
  7. <!--#ifdef MP-->
  8. <view class="app-item dir-top-nowrap cross-center" :style="{width: width}">
  9. <app-jump-button form :url="columns.link_url" :params="columns.params" :open_type="columns.open_type" arrangement="column">
  10. <image class="app-icon" :src="columns.icon_url" :lazy-load="true"></image>
  11. <text :style="{color: color}" class="app-text">{{columns.name}}</text>
  12. </app-jump-button>
  13. </view>
  14. <!--#endif-->
  15. <!--#ifdef H5-->
  16. <view v-if="columns.open_type !== 'app'" class="app-item dir-top-nowrap cross-center" :style="{width: width}">
  17. <app-jump-button form :url="columns.link_url" :params="columns.params" :open_type="columns.open_type" arrangement="column">
  18. <image class="app-icon" :src="columns.icon_url" :lazy-load="true"></image>
  19. <text :style="{color: color}" class="app-text">{{columns.name}}</text>
  20. </app-jump-button>
  21. </view>
  22. <view v-else :id="columns.id" :style="{width: width}">
  23. </view>
  24. <!--#endif-->
  25. </block>
  26. </view>
  27. </swiper-item>
  28. </swiper>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. name: 'app-navigation-icon',
  34. data() {
  35. return {
  36. width: uni.upx2px(0)+ 'px',
  37. height: 0,
  38. }
  39. },
  40. props: {
  41. background: {
  42. type: String,
  43. default() {
  44. return '#ffffff';
  45. }
  46. },
  47. color: {
  48. type: String,
  49. default() {
  50. return '#353535';
  51. }
  52. },
  53. columns: {
  54. type: Number,
  55. default() {
  56. return 3;
  57. }
  58. },
  59. rows: {
  60. type: Number,
  61. default() {
  62. return 4;
  63. }
  64. },
  65. scroll: {
  66. type: Boolean,
  67. default() {
  68. return false;
  69. }
  70. },
  71. navs: {
  72. type: Array,
  73. default() {
  74. return [
  75. ]
  76. }
  77. }
  78. },
  79. computed: {
  80. newData: function() {
  81. this.width = `${uni.upx2px(750/this.columns)}px`;
  82. let menus = [];
  83. let newMenus = [];
  84. let num = Number(this.columns)* this.rows;
  85. // #ifdef H5
  86. this.navs.forEach(item => {
  87. if (item.open_type === 'app') {
  88. let width = uni.upx2px(90)+ 'px';
  89. let margin = uni.upx2px(8) + 'px';
  90. let font = uni.upx2px(24) + 'px';
  91. item.id = this.$utils.guid('app-navigation-icon');
  92. let username = this.$utils.getUrlParamApp(item.link_url, 'username');
  93. let path = this.$utils.getUrlParamApp(item.link_url, 'path');
  94. let text = `<div style="width:${this.width};-webkit-align-items: center;align-items: center;display: -webkit-box;display: -webkit-flex;display: flex;-webkit-box-orient: vertical;-webkit-flex-direction: column;flex-direction: column;flex-wrap: nowrap;"><img src="${item.icon_url}" width="${width}" height="${width}" />
  95. <text style="color:${this.color};font-size: ${font};height:${font};line-height: ${font};text-align: center;margin-top: ${margin};word-break: break-all;text-overflow: ellipsis;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp:1;overflow: hidden;">${item.name}</text>
  96. </div>`;
  97. this.$utils.createWxOpenLaunchWeapp(item.id, username, path, text);
  98. }
  99. });
  100. // #endif
  101. if (this.scroll === true) {
  102. for (let i = 0; i < Math.ceil(this.navs.length/num); i++) {
  103. menus.push(this.navs.slice(i*num, (i+1)*num));
  104. }
  105. for (let i = 0; i < menus.length;i++) {
  106. let arr = [];
  107. for (let j = 0; j < Math.ceil(menus[i].length/ Number(this.columns)); j++) {
  108. let men = menus[i].slice(j* Number(this.columns), (j+1)* Number(this.columns));
  109. arr.push(men);
  110. }
  111. newMenus.push(arr);
  112. }
  113. } else {
  114. if (this.rows === -1) {
  115. menus = [this.navs];
  116. } else {
  117. menus.push(this.navs.slice(0, num));
  118. }
  119. for (let i = 0; i < menus.length;i++) {
  120. let arr = [];
  121. for (let j = 0; j < Math.ceil(menus[i].length/ Number(this.columns)); j++) {
  122. let men = menus[i].slice(j* Number(this.columns), (j+1)* Number(this.columns));
  123. arr.push(men);
  124. }
  125. newMenus.push(arr);
  126. }
  127. }
  128. if (newMenus.length === 0 ) return newMenus;
  129. return newMenus;
  130. }
  131. },
  132. watch: {
  133. newData: {
  134. handler: function(newVal) {
  135. this.height = `${uni.upx2px(newVal[0].length * 156)}px`;
  136. },
  137. immediate: true
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped lang="scss">
  143. .app-swiper-item {
  144. width: #{750rpx};
  145. }
  146. .app-rows {
  147. width: #{750rpx};
  148. margin-top: #{28rpx};
  149. margin-bottom: #{4rpx};
  150. }
  151. .app-icon {
  152. width: #{90rpx};
  153. height: #{90rpx};
  154. }
  155. .app-text {
  156. font-size: #{24rpx};
  157. color: #353535;
  158. height: #{24rpx};
  159. line-height: #{24rpx};
  160. text-align: center;
  161. margin-top: #{8rpx};
  162. word-break: break-all;
  163. text-overflow: ellipsis;
  164. display: -webkit-box;
  165. -webkit-box-orient: vertical;
  166. -webkit-line-clamp: 1;
  167. overflow: hidden;
  168. }
  169. .app-swiper {
  170. width: 100%;
  171. height: 100% !important;
  172. }
  173. </style>