graceSwipeList.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="grace-swipe-list" :style="{width:width+'rpx'}">
  3. <graceTouch v-for="(item, index) in msgsIn" :key="index" @thStart="thStart" @thMove="thMove" @thEnd="thEnd" :datas="[index]">
  4. <view class="grace-swipe-list-item" :style="{width:width+'rpx'}">
  5. <view class="grace-swipe-list-item-body" :style="{width:width+'rpx', marginLeft:(item.x * -1) + 'px'}">
  6. <view class="grace-swipe-list-img" :style="{width:imgSize[0], height:imgSize[1]}">
  7. <image :src="item.img" mode="widthFix" :style="{width:imgSize[0], height:imgSize[1], borderRadius:'6rpx'}"></image>
  8. <view class="grace-swipe-list-point" v-if="item.msgnumber > 0">{{item.msgnumber}}</view>
  9. </view>
  10. <view class="grace-swipe-list-content">
  11. <view class="grace-swipe-list-title">
  12. <text class="grace-swipe-list-title-text" :style="{fontSize:fontSizes[0], color:fontColors[0]}">{{item.title}}</text>
  13. <text class="grace-swipe-list-title-text" :style="{fontSize:fontSizes[1], color:fontColors[1], flexShrink:0, marginLeft:'25rpx', marginRight:'25rpx'}">{{item.time}}</text>
  14. </view>
  15. <text class="grace-swipe-list-desc" :style="{fontSize:fontSizes[2], color:fontColors[2], marginTop:'6rpx'}">{{item.content}}</text>
  16. </view>
  17. </view>
  18. <view class="grace-swipe-btns" :style="{width:item.x+'px'}">
  19. <view class="grace-swipe-btn" v-for="(btn, btnIndex) in item.btns" :key="btnIndex"
  20. :style="{backgroundColor:btn.bgColor}" @tap.stop="btnTap(index, btnIndex)">
  21. <text class="grace-swipe-btn-text">{{btn.name}}</text>
  22. </view>
  23. </view>
  24. </view>
  25. </graceTouch>
  26. </view>
  27. </template>
  28. <script>
  29. import graceTouch from "./graceTouch.vue";
  30. export default{
  31. props:{
  32. width:{type:Number, default:750},
  33. msgs:{type:Array,default:function(){return [];}},
  34. imgSize:{type:Array,default:function(){return ['80rpx', '80rpx'];}},
  35. fontSizes:{type:Array,default:function(){return ['28rpx','22rpx', '22rpx'];}},
  36. fontColors:{type:Array,default:function(){return ['#323232','#888888', '#888888'];}},
  37. btnWidth:{type:Number, default:160}
  38. },
  39. data() {
  40. return {
  41. msgsIn: [],
  42. damping : 0.1
  43. }
  44. },
  45. created:function(){
  46. this.init(this.msgs);
  47. },
  48. watch:{
  49. msgs : function(nv){
  50. this.init(nv);
  51. }
  52. },
  53. methods:{
  54. init:function(msgs){
  55. var newmsg = [];
  56. msgs.forEach((item) => { item.x = 0; newmsg.push(item); });
  57. this.msgsIn = newmsg;
  58. },
  59. setItems : function (msgs){
  60. },
  61. thStart : function(e, index){
  62. this.damping = 0.1;
  63. var i = 0;
  64. this.msgsIn.forEach((item) => {
  65. if(i != index){
  66. if(item.x > 10){this.toZero(i);}
  67. }
  68. i++;
  69. });
  70. },
  71. thMove : function (e, index){
  72. var item = this.msgsIn[index];
  73. item.x -= e[0][0] * this.damping;
  74. if(item.x > this.btnWidth){item.x = this.btnWidth;}
  75. if(item.x < 0){item.x = 0;}
  76. this.msgsIn.splice(index, 1, item);
  77. this.damping *= 1.2;
  78. },
  79. thEnd : function(e, index){
  80. if(e[1] < 150){
  81. if(this.msgsIn[index].x >= 5){
  82. this.toZero(index);
  83. return;
  84. }
  85. if(Math.abs(e[0][0]) < 30){this.$emit('itemTap',index);}
  86. return ;
  87. }
  88. var item = this.msgsIn[index];
  89. if(item.x < this.btnWidth / 3){item.x = 0;}else{item.x = this.btnWidth;}
  90. this.msgsIn.splice(index, 1, item);
  91. },
  92. toZero:function(index){
  93. if(this.msgsIn[index].x < 0 ){
  94. this.msgsIn[index].x = 0;
  95. this.msgsIn.splice(index, 1, this.msgs[index]);
  96. return;
  97. }
  98. this.msgsIn[index].x -= 10;
  99. this.msgsIn.splice(index, 1, this.msgsIn[index]);
  100. setTimeout(()=>{this.toZero(index);},10);
  101. },
  102. btnTap : function (index, indexBtn) {
  103. this.$emit('btnTap',index, indexBtn);
  104. }
  105. },
  106. components:{
  107. graceTouch
  108. }
  109. }
  110. </script>
  111. <style>
  112. .grace-swipe-list{overflow:hidden;}
  113. .grace-swipe-list-item{overflow:hidden; position:relative;}
  114. .grace-swipe-list-item-body{display:flex; flex-direction:row; flex-wrap:nowrap; font-size:0; align-items:center;}
  115. .grace-swipe-list-img{flex-shrink:0; margin-left:25rpx; font-size:0; position:relative;}
  116. .grace-swipe-list-point{border-radius:32rpx; height:32rpx; line-height:32rpx; padding:0 10rpx; font-size:20rpx; background-color:#FF0036; color:#FFFFFF; position:absolute; z-index:1; right:0; top:0;}
  117. .grace-swipe-list-content{width:750rpx; overflow:hidden; padding-top:25rpx; padding-bottom:25rpx; margin-left:22rpx; border-bottom:1px solid #F1F2F3;}
  118. .grace-swipe-list-title{display:flex; flex-direction:row; flex-wrap:nowrap; justify-content:space-between; overflow:hidden;}
  119. .grace-swipe-list-title-text{line-height:38rpx; height:38rpx; overflow:hidden; display:block;}
  120. .grace-swipe-list-desc{line-height:32rpx; height:32rpx; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; width:100%; padding-right:25rpx; box-sizing:border-box; display:block;}
  121. .grace-swipe-btns{width:0rpx; position:absolute; z-index:1; right:0; top:0; height:116rpx; display:flex; flex-direction:row; flex-wrap:nowrap;}
  122. .grace-swipe-btn{width:400rpx; height:125rpx; display:flex; flex-direction:row; flex-wrap:nowrap; justify-content:center; align-items:center; box-sizing:border-box; padding:20rpx; overflow:hidden;}
  123. .grace-swipe-btn-text{line-height:36rpx; height:36rpx; overflow:hidden; display:block; font-size:28rpx; color:#FFFFFF;}
  124. </style>