grid-menu-list.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <view class="zaiui-scroll-view-box">
  3. <scroll-view class="zaiui-scroll-view" scroll-x @scroll="navScroll">
  4. <view id="scroll1" class="zaiui-scroll-view-item">
  5. <view class="cu-list grid col-5 no-border">
  6. <block v-for="(item,index) in ListData" :key="index" v-if="index < 10">
  7. <view class="cu-item" @tap="listTap(item,index)">
  8. <view class="grid-icon">
  9. <image class="icon" :src="item.icon || '/static/zaiui/img/more.png'" mode="widthFix"/>
  10. </view>
  11. <view class="cu-tag badge z" :class="['bg-' + item.color]" v-if="item.badge">{{item.badge}}</view>
  12. <text class="text-black">{{item.name}}</text>
  13. </view>
  14. </block>
  15. </view>
  16. </view>
  17. <view id="scroll2" class="zaiui-scroll-view-item" v-if="ListData.length > 10">
  18. <view class="cu-list grid col-5 no-border">
  19. <block v-for="(item,index) in ListData" :key="index" v-if="index >= 10">
  20. <view class="cu-item" @tap="listTap(item,index)">
  21. <view class="grid-icon">
  22. <image class="icon" :src="item.icon || '/static/zaiui/img/more.png'" mode="widthFix" style="max-height: 44px;"></image>
  23. </view>
  24. <view class="cu-tag badge z" :class="['bg-' + item.color]" v-if="item.badge">{{item.badge}}</view>
  25. <text class="text-black">{{item.name}}</text>
  26. </view>
  27. </block>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. <view class="zaiui-scroll-h-view" :style="{width: `${scrollPage * 16}px`}">
  32. <view class="box">
  33. <view class="bg-red dot" :style="{left: `${scrollDot}px`}"></view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import _tool from '@/static/zaiui/util/tools.js';
  40. export default {
  41. name: 'grid-menu-list',
  42. data() {
  43. return {
  44. ListData: [], scrollPage: 1, scrollDot: 0,
  45. };
  46. },
  47. props: {
  48. list_data: {
  49. type: Array,
  50. default: () => {
  51. return []
  52. }
  53. }
  54. },
  55. created() {
  56. this.ListData = this.list_data;
  57. this.getScrollPageNum();
  58. },
  59. watch: {
  60. list_data() {
  61. this.ListData = this.list_data;
  62. this.getScrollPageNum();
  63. }
  64. },
  65. methods: {
  66. getScrollPageNum() {
  67. this.scrollPage = _tool.getPageNum(this.ListData.length,10);
  68. },
  69. navScroll(e) {
  70. //计算公式: 移动距离 /(A总 / B总)
  71. let pageWidth = this.scrollPage * 16;
  72. let Width = e.detail.scrollWidth / pageWidth;
  73. this.scrollDot = e.detail.scrollLeft / Width;
  74. },
  75. listTap(data,index) {
  76. this.$emit('listTap', {
  77. data,
  78. index
  79. });
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .zaiui-scroll-view-box {
  86. position: relative;
  87. .zaiui-scroll-view {
  88. position: relative;
  89. // height: 388upx;
  90. white-space: nowrap;
  91. width: 100%;
  92. .zaiui-scroll-view-item {
  93. display: inline-block;
  94. width: 100%;
  95. .cu-list.grid {
  96. background-color: inherit;
  97. .grid-icon {
  98. margin: 0 30upx;
  99. .icon {
  100. border-radius: 100%;
  101. }
  102. }
  103. }
  104. .cu-list.grid>.cu-item text {
  105. color: #333333;
  106. }
  107. .cu-list.grid>.cu-item .cu-tag {
  108. transform: scale(0.8);
  109. }
  110. }
  111. }
  112. .zaiui-scroll-h-view {
  113. position: absolute;
  114. height: 10upx;
  115. bottom: 2upx;
  116. left: 0;
  117. right: 0;
  118. width: 32px;
  119. margin: auto;
  120. .box {
  121. position: relative;
  122. background: #d0cfcf;
  123. border-radius: 40upx;
  124. width: 100%;
  125. height: 100%;
  126. .dot {
  127. position: absolute;
  128. width: 16px;
  129. height: 100%;
  130. border-radius: 40upx;
  131. top: 0;
  132. left: 0;
  133. right: 0;
  134. bottom: 0;
  135. }
  136. }
  137. }
  138. }
  139. </style>