index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div>
  3. <el-popover placement="bottom" width="600" trigger="click">
  4. <!-- icon 展示 -->
  5. <el-badge slot="reference" :is-dot="unreadCount > 0" type="danger">
  6. <svg-icon icon-class="message" @click="getList"/>
  7. </el-badge>
  8. <!-- 弹出列表 -->
  9. <el-table v-loading="loading" :data="list">
  10. <el-table-column width="120" property="templateNickname" label="发送人" />
  11. <el-table-column width="180" property="title" label="发送时间">
  12. <template slot-scope="scope">
  13. <span>{{ parseTime(scope.row.createTime) }}</span>
  14. </template>
  15. </el-table-column>
  16. <el-table-column label="类型" align="center" prop="templateType" width="100">
  17. <template v-slot="scope">
  18. <dict-tag :type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE" :value="scope.row.templateType" />
  19. </template>
  20. </el-table-column>
  21. <el-table-column property="templateContent" label="内容" />
  22. </el-table>
  23. <!-- 更多 -->
  24. <div style="text-align: right; margin-top: 10px">
  25. <el-button type="primary" size="mini" @click="goMyList">查看全部</el-button>
  26. </div>
  27. </el-popover>
  28. </div>
  29. </template>
  30. <script>
  31. import {getUnreadNotifyMessageCount, getUnreadNotifyMessageList} from "@/api/system/notify/message";
  32. export default {
  33. name: 'NotifyMessage',
  34. data() {
  35. return {
  36. // 遮罩层
  37. loading: false,
  38. // 列表
  39. list: [],
  40. // 未读数量,
  41. unreadCount: 0,
  42. }
  43. },
  44. created() {
  45. // 首次加载小红点
  46. this.getUnreadCount()
  47. // 轮询刷新小红点
  48. window.timer = setInterval(()=>{
  49. this.getUnreadCount()
  50. },1000 * 60 * 2)
  51. },
  52. methods: {
  53. getList: function() {
  54. this.loading = true;
  55. getUnreadNotifyMessageList().then(response => {
  56. this.list = response.data;
  57. this.loading = false;
  58. // 强制设置 unreadCount 为 0,避免小红点因为轮询太慢,不消除
  59. this.unreadCount = 0
  60. });
  61. },
  62. getUnreadCount: function() {
  63. getUnreadNotifyMessageCount().then(response => {
  64. this.unreadCount = response.data;
  65. })
  66. },
  67. goMyList: function() {
  68. this.$router.push({
  69. name: 'MyNotifyMessage'
  70. });
  71. }
  72. }
  73. }
  74. </script>
  75. <style>
  76. .el-badge__content.is-fixed {
  77. top: 10px; /* 保证徽章的位置 */
  78. }
  79. </style>