gui-slide-list.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <scroll-view
  3. class="gui-slide-list gui-absolute-full"
  4. :scroll-y="scY"
  5. :show-scrollbar="false"
  6. :style="{width:width+'rpx'}"
  7. @scrolltolower="scrolltolower">
  8. <view
  9. class="gui-slide-list-item gui-border-b"
  10. v-for="(item, index) in msgsIn"
  11. :key="index"
  12. :style="{width:width+'rpx'}">
  13. <view
  14. class="gui-flex gui-row gui-nowrap gui-align-items-center"
  15. :style="{
  16. width:(width + btnWidth)+'rpx',
  17. overflow:'hidden',
  18. transform:'translateX('+(moveIndex != index ? 0 : x)+'px)'
  19. }">
  20. <view
  21. class="gui-slide-list-img-wrap"
  22. hover-class="gui-tap"
  23. @tap.stop.prevnet="itemTap(index)">
  24. <image
  25. :src="item.img"
  26. class="gui-slide-list-img"
  27. mode="aspectFill"></image>
  28. <text
  29. class="gui-slide-list-point gui-block gui-bg-red gui-color-white"
  30. v-if="item.msgnumber > 0">{{item.msgnumber}}</text>
  31. </view>
  32. <view
  33. class="gui-slide-list-content"
  34. hover-class="gui-tap">
  35. <gui-touch
  36. @thStart="thStart"
  37. @thMove="thMove"
  38. @thEnd="thEnd"
  39. @tapme="itemTap(index)"
  40. :datas="[index]">
  41. <view class="gui-flex gui-row gui-nowrap gui-space-between">
  42. <text
  43. class="gui-slide-list-title-text gui-primary-text gui-block">{{item.title}}</text>
  44. <text
  45. class="gui-slide-list-desc gui-block gui-color-gray">{{item.time}}</text>
  46. </view>
  47. <text
  48. class="gui-slide-list-desc gui-third-text gui-block gui-ellipsis">{{item.content}}</text>
  49. </gui-touch>
  50. </view>
  51. <view
  52. class="gui-slide-btns gui-flex gui-row gui-nowrap"
  53. :style="{width:(btnWidth-2) +'rpx'}">
  54. <text
  55. class="gui-slide-btn gui-block gui-text-center"
  56. v-for="(btn, btnIndex) in item.btns"
  57. :key="btnIndex"
  58. :style="{backgroundColor:btn.bgColor}"
  59. @tap.stop.prevnet="btnTap(index, btnIndex)">{{btn.name}}</text>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 加载组件 -->
  64. <view style="padding:20rpx;">
  65. <gui-loadmore
  66. ref="loadmoreinslidelist"></gui-loadmore>
  67. </view>
  68. </scroll-view>
  69. </template>
  70. <script>
  71. export default{
  72. name : "gui-slide-list",
  73. props : {
  74. width : { type : Number, default : 750},
  75. msgs : { type : Array, default : function(){return [];}},
  76. btnWidth : { type : Number, default : 320}
  77. },
  78. data() {
  79. return {
  80. msgsIn : [],
  81. damping : 0.29,
  82. moveIndex : -1,
  83. x : 0,
  84. oX : 0,
  85. scY : true,
  86. btnWidthpx:160,
  87. touchStart:false
  88. }
  89. },
  90. created:function(){
  91. this.init(this.msgs);
  92. this.btnWidthpx = (uni.upx2px(this.btnWidth) * -1) + 2;
  93. },
  94. watch:{
  95. msgs : function(nv){
  96. this.init(nv);
  97. }
  98. },
  99. methods:{
  100. init : function(msgs){
  101. this.moveIndex = -1;
  102. this.msgsIn = msgs;
  103. },
  104. thStart : function(e, index){
  105. this.x = 0;
  106. this.moveIndex = index[0];
  107. this.damping = 0.25;
  108. },
  109. thMove : function (e, index){
  110. var x = e[0][0];
  111. var y = e[0][1];
  112. if(Math.abs(x) < Math.abs(y)){
  113. this.scY = true;
  114. return ;
  115. }else{
  116. this.scY = false;
  117. }
  118. if(x < 0){
  119. this.x += x * this.damping;
  120. if(this.x < this.btnWidthpx){this.x = this.btnWidthpx;}
  121. this.damping *= 1.02;
  122. }else{
  123. this.scY = true;
  124. }
  125. },
  126. thEnd : function(e, index){
  127. if(this.x > this.btnWidthpx / 8){
  128. this.x = 0;
  129. }else{
  130. this.x = this.btnWidthpx;
  131. }
  132. this.scY = true;
  133. this.oX = this.x;
  134. },
  135. btnTap : function (index, indexBtn) {
  136. this.$emit('btnTap',index, indexBtn);
  137. },
  138. itemTap : function (index) {
  139. if(this.oX < 0){
  140. this.oX = 0;
  141. this.moveIndex = -1;
  142. return ;
  143. }
  144. this.$emit('itemTap',index);
  145. this.moveIndex = -1;
  146. this.oX = 0;
  147. },
  148. scrolltolower : function () {
  149. var laodStatus = this.$refs.loadmoreinslidelist.loadMoreStatus;
  150. if(laodStatus == 0){
  151. this.$emit('scrolltolower');
  152. }
  153. },
  154. startLoadig : function(){
  155. this.$refs.loadmoreinslidelist.loading();
  156. },
  157. nomore : function () {
  158. this.$refs.loadmoreinslidelist.nomore();
  159. },
  160. endLoading : function(){
  161. this.$refs.loadmoreinslidelist.stoploadmore();
  162. }
  163. },
  164. emits:['btnTap', 'scrolltolower']
  165. }
  166. </script>
  167. <style scoped>
  168. </style>