gui-slide-list.vue 5.0 KB

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