msgList.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view
  3. class="msgList"
  4. >
  5. <view class="mt30">
  6. <navigator class="msgItem" v-for="(item,index) in msgList" :key="index" :url="`/pages/msgInfo/msgInfo?id=${item.id}`">
  7. <view class="msgItemLeft">
  8. <image class="fixedTitle" src="/static/msg_title_3.jpg"></image>
  9. </view>
  10. <view class="msgItemRight">
  11. <text class="msgItemTitle">{{item.title}}</text>
  12. <text>{{item.added_on}}</text>
  13. </view>
  14. </navigator>
  15. </view>
  16. <view class="loading" v-if="isMore">没有更多数据了</view>
  17. </view>
  18. </template>
  19. <script>
  20. import { messageList } from "../../api/index.js"
  21. export default {
  22. data(){
  23. return {
  24. msgList:[],
  25. isMore:false,
  26. page_index:1,
  27. page_size:10,
  28. scrollType:true
  29. }
  30. },
  31. onShow() {
  32. this.create({
  33. page_index:1,
  34. page_size:10,
  35. })
  36. },
  37. onPullDownRefresh:function(){
  38. this.scrollType=true
  39. this.create({
  40. page_index:1,
  41. page_size:this.page_index*this.page_size,
  42. });
  43. },
  44. onReachBottom:function(){
  45. if(!this.isMore){
  46. this.page_index++;
  47. this.scrollType=false
  48. if(!this.loading){
  49. this.create({
  50. page_index:this.page_index,
  51. page_size:10
  52. })
  53. }
  54. }
  55. },
  56. methods:{
  57. create(params){
  58. const that = this
  59. this.$nextTick(function(){
  60. messageList(params).then(res=>{
  61. uni.stopPullDownRefresh(); //停止下拉刷新动画
  62. const { error_code } = res
  63. if(error_code===200){
  64. const { data } = res
  65. if(data.length<1 || data.length<that.page_size){
  66. that.isMore=true
  67. }
  68. if(that.scrollType){
  69. that.msgList=data
  70. }else{
  71. that.msgList=that.msgList.concat(data)
  72. }
  73. }
  74. })
  75. })
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss">
  81. page{
  82. width: 100%;
  83. height: 100%;
  84. background: $uni-bg-color-normal;
  85. }
  86. .msgList{
  87. width: 100%;
  88. height: 100%;
  89. }
  90. .mt30{
  91. padding-top: 30rpx;
  92. }
  93. .msgItem{
  94. width: 100%;
  95. height: 156rpx;
  96. background-color: $uni-bg-color;
  97. position: relative;
  98. overflow: hidden;
  99. display: flex;
  100. justify-content: space-between;
  101. align-items: center;
  102. margin-bottom: 30rpx;
  103. }
  104. .msgItem::after,.msgItem::before{
  105. content: "";
  106. display: block;
  107. width: 42rpx;
  108. height: 42rpx;
  109. border-radius: 50%;
  110. position: absolute;
  111. background: $uni-bg-color-normal;
  112. left: 138rpx;
  113. }
  114. .msgItem::before{
  115. top: 0;
  116. margin-top: -21rpx;
  117. }
  118. .msgItem::after{
  119. bottom: 0;
  120. margin-bottom: -21rpx;
  121. }
  122. .fixedTitle{
  123. display: block;
  124. width: 72rpx;
  125. height: 35rpx;
  126. background-size: 100% 100%;
  127. }
  128. .msgItemLeft{
  129. width: 159rpx;
  130. height: 100%;
  131. display: flex;
  132. justify-content: center;
  133. align-items: center;
  134. position: relative;
  135. }
  136. .msgItemLeft::after{
  137. content: "";
  138. display: block;
  139. width: 6rpx;
  140. height: 90rpx;
  141. background: url(../../static/border_circle.jpg);
  142. background-size: 100% 100%;
  143. position: absolute;
  144. top: 50%;
  145. right: 0;
  146. margin-top: -45rpx;
  147. margin-right: -3rpx;
  148. }
  149. .msgItemRight{
  150. width: calc(100% - 159rpx - 89rpx - 57rpx);
  151. padding: 0 89rpx 0 57rpx;
  152. overflow: hidden;
  153. text-overflow: ellipsis;
  154. font-size: 24rpx;
  155. color: #999999;
  156. }
  157. .msgItemTitle{
  158. font-size: 28rpx;
  159. color: #323332;
  160. margin-bottom: 10rpx;
  161. display: block;
  162. }
  163. .loading{
  164. font-size: 24rpx;
  165. text-align: center;
  166. padding-bottom: 10px;
  167. }
  168. </style>