index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view class="container">
  3. <block v-for="(row, index) in messageList" :key="index">
  4. <view class="msgItem">
  5. <div class="is_read">
  6. <!-- {{row.is_read}} -->
  7. <span v-if="row.is_read"></span>
  8. <span v-else class="red">·</span>
  9. </div>
  10. <div class="msgMsg">{{$u.timeFormat(row.send_time, 'yyyy-mm-dd')}}</div>
  11. <u-card :title="title" :title-size="35" :border="false">
  12. <view class slot="body">
  13. <view class="u-body-item u-flex u-row-between u-p-b-0">
  14. <view class="u-body-item-title u-line-2">{{row.content}}</view>
  15. </view>
  16. </view>
  17. </u-card>
  18. </view>
  19. </block>
  20. <uni-load-more :status="loadStatus"></uni-load-more>
  21. </view>
  22. </template>
  23. <script>
  24. import { mapMutations } from "vuex";
  25. import * as API_Message from "@/api/message.js";
  26. export default {
  27. data() {
  28. return {
  29. title: "系统消息",
  30. subTitle: "未读",
  31. finished: false,
  32. loadStatus: "more",
  33. params: {
  34. pageNumber: 0,
  35. pageSize: 5
  36. },
  37. messageList: []
  38. };
  39. },
  40. onLoad() {
  41. this.GET_MessageList(true);
  42. },
  43. onReachBottom() {
  44. this.params.pageNumber++;
  45. this.GET_MessageList(false);
  46. },
  47. methods: {
  48. ...mapMutations(["logout"]),
  49. /** 获取站内消息 */
  50. GET_MessageList(reset) {
  51. if (reset) {
  52. this.params.pageNumber = 1;
  53. this.messageList = [];
  54. }
  55. uni.showLoading({
  56. title: "加载中"
  57. });
  58. API_Message.getMessages(this.params).then(async response => {
  59. uni.hideLoading();
  60. const { data } = response;
  61. if (!data || !data.length) {
  62. this.messageList.push(...data.data);
  63. this.handleReadPageMessages();
  64. }
  65. });
  66. },
  67. /** 设置消息已读 **/
  68. handleReadPageMessages() {
  69. const ids = this.messageList.map(item => item.id).join(",");
  70. API_Message.messageMarkAsRead(ids).then(async () => {});
  71. }
  72. }
  73. };
  74. </script>
  75. <style scoped lang='scss'>
  76. .is_read{
  77. position: absolute;
  78. right: 25px;
  79. top: 80rpx;
  80. z-index: 999;
  81. }
  82. .container {
  83. background: #f9f9f9;
  84. min-height: 100vh;
  85. }
  86. .red{
  87. color: coral;
  88. font-size: 100rpx;
  89. }
  90. .msgMsg {
  91. text-align: center;
  92. color: $u-tips-color;
  93. }
  94. .msgItem {
  95. padding: 1em 0;
  96. position: relative;
  97. }
  98. </style>