index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <tips-custom>
  3. <template #default>
  4. <el-button type="primary" text @click="readAll">全部标记为已读</el-button>
  5. </template>
  6. </tips-custom>
  7. <el-card shadow="hover">
  8. <div>
  9. <el-empty description="暂无数据" v-if="data.length === 0"></el-empty>
  10. <div class="flex flex-col" v-else>
  11. <el-collapse @change="change" accordion>
  12. <el-collapse-item v-for="i in data" :name="i.id" :key="i.id">
  13. <template #title>
  14. <div class="flex flex-center flex-justify-between full-width">
  15. <div
  16. class="padding-left flex flex-align-center flex-justify-start"
  17. >
  18. <div
  19. class="dot"
  20. :style="i.readFlag === 0 ? '' : 'background-color: #d6d6d6'"
  21. />
  22. <span>{{ i.titile }}</span>
  23. </div>
  24. <span class="padding-right">{{ i.createTime }}</span>
  25. </div>
  26. </template>
  27. <div class="full-width flex flex-justify-start padding">
  28. <span v-if="i.msgCategory === 1" class="ml-20">{{
  29. i.msgContent
  30. }}</span>
  31. <msg2 v-else-if="i.msgCategory === 2" :info="i" />
  32. </div>
  33. </el-collapse-item>
  34. </el-collapse>
  35. <div class="full-width flex flex-justify-between mt-20">
  36. <div></div>
  37. <div class="flex flex-center">
  38. <span class="mr-15">共{{ total }}条</span>
  39. <el-pagination
  40. layout="prev, pager, next"
  41. :total="total"
  42. :page-size="page.size"
  43. @current-change="changePage"
  44. v-model:current-page="page.current"
  45. />
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </el-card>
  51. </template>
  52. <route>
  53. {
  54. name: '通知中心',
  55. meta: { 'back':true, 'show':false}
  56. }
  57. </route>
  58. <script>
  59. import msg2 from '@/views/msg/component/msg2.vue'
  60. import tipsCustom from '@/components/tips-custom/index.vue'
  61. export default {
  62. components: {
  63. msg2,
  64. tipsCustom
  65. },
  66. data() {
  67. return {
  68. data: [],
  69. page: {
  70. current: 1,
  71. size: 15
  72. },
  73. total: ''
  74. }
  75. },
  76. created() {
  77. this.list()
  78. },
  79. methods: {
  80. list() {
  81. this.$api.msg.list(this.page).then(res => {
  82. if (res.code === 200) {
  83. this.data = res.data.records
  84. this.total = res.data.total
  85. }
  86. })
  87. },
  88. changePage(val) {
  89. this.page.current = val
  90. this.list()
  91. },
  92. readAll() {
  93. this.$api.msg.readAll().then(res => {
  94. if (res.code === 200) {
  95. this.$message.success(res.msg)
  96. this.list()
  97. } else {
  98. this.$message.error(res.msg)
  99. }
  100. })
  101. },
  102. change(row) {
  103. const tmp = this.data.find(ele => ele.id === row)
  104. if (tmp && tmp.readFlag === 1) {
  105. return
  106. }
  107. this.$api.msg.markRead({ id: row }).then(res => {
  108. if (res.code === 200) {
  109. this.data = this.data.map(ele => {
  110. if (ele.id === row) {
  111. ele.readFlag = 1
  112. this.$bus.emit('read')
  113. }
  114. return ele
  115. })
  116. }
  117. })
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .dot {
  124. background-color: red;
  125. width: 10px;
  126. height: 10px;
  127. margin-right: 10px;
  128. border-radius: 10px;
  129. }
  130. :deep(.el-collapse-item__header):hover {
  131. background-color: #efefef;
  132. }
  133. </style>