index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div v-loading="state.loading" class="layout-navbars-breadcrumb-user-news">
  3. <div class="head-box">
  4. <div class="head-box-title">通知公告</div>
  5. <div class="head-box-btn" @click="readAll">全部已读</div>
  6. </div>
  7. <div v-loading="state.loading" class="content-box">
  8. <template v-if="newsList.length > 0">
  9. <div v-for="(v, k) in newsList" :key="k" class="content-box-item" @click="onNewsClick(k)">
  10. <div class="item-conten">
  11. <div>{{ v.message }}</div>
  12. <div class="content-box-msg"></div>
  13. <div class="content-box-time">{{ v.time }}</div>
  14. </div>
  15. <!-- 已读/未读 -->
  16. <span v-if="v.read" class="el-tag el-tag--success el-tag--mini read">已读</span>
  17. <span v-else class="el-tag el-tag--danger el-tag--mini read">未读</span>
  18. </div>
  19. </template>
  20. <el-empty v-else :description="'消息为空'"></el-empty>
  21. </div>
  22. <!-- <div v-if="newsList.length > 0" class="foot-box" @click="onGoToGiteeClick">前往gitee</div> -->
  23. </div>
  24. </template>
  25. <script setup lang="ts" name="layoutBreadcrumbUserNews">
  26. import { useNoticeStore } from '@/store/modules/notice';
  27. const noticeStore = useNoticeStore();
  28. const { readAll } = useNoticeStore();
  29. // 定义变量内容
  30. const state = reactive({
  31. loading: false
  32. });
  33. const newsList = ref([]) as any;
  34. /**
  35. * 初始化数据
  36. * @returns
  37. */
  38. const getTableData = async () => {
  39. state.loading = true;
  40. newsList.value = noticeStore.state.notices;
  41. state.loading = false;
  42. };
  43. //点击消息,写入已读
  44. const onNewsClick = (item: any) => {
  45. newsList.value[item].read = true;
  46. //并且写入pinia
  47. noticeStore.state.notices = newsList.value;
  48. };
  49. // 前往通知中心点击
  50. const onGoToGiteeClick = () => {
  51. window.open('https://gitee.com/dromara/RuoYi-Vue-Plus/tree/5.X/');
  52. };
  53. onMounted(() => {
  54. nextTick(() => {
  55. getTableData();
  56. });
  57. });
  58. </script>
  59. <style lang="scss" scoped>
  60. .layout-navbars-breadcrumb-user-news {
  61. .head-box {
  62. display: flex;
  63. border-bottom: 1px solid var(--el-border-color-lighter);
  64. box-sizing: border-box;
  65. color: var(--el-text-color-primary);
  66. justify-content: space-between;
  67. height: 35px;
  68. align-items: center;
  69. .head-box-btn {
  70. color: var(--el-color-primary);
  71. font-size: 13px;
  72. cursor: pointer;
  73. opacity: 0.8;
  74. &:hover {
  75. opacity: 1;
  76. }
  77. }
  78. }
  79. .content-box {
  80. height: 300px;
  81. overflow: auto;
  82. font-size: 13px;
  83. .content-box-item {
  84. padding-top: 12px;
  85. display: flex;
  86. &:last-of-type {
  87. padding-bottom: 12px;
  88. }
  89. .content-box-msg {
  90. color: var(--el-text-color-secondary);
  91. margin-top: 5px;
  92. margin-bottom: 5px;
  93. }
  94. .content-box-time {
  95. color: var(--el-text-color-secondary);
  96. }
  97. .item-conten {
  98. width: 100%;
  99. display: flex;
  100. flex-direction: column;
  101. }
  102. }
  103. }
  104. .foot-box {
  105. height: 35px;
  106. color: var(--el-color-primary);
  107. font-size: 13px;
  108. cursor: pointer;
  109. opacity: 0.8;
  110. display: flex;
  111. align-items: center;
  112. justify-content: center;
  113. border-top: 1px solid var(--el-border-color-lighter);
  114. &:hover {
  115. opacity: 1;
  116. }
  117. }
  118. :deep(.el-empty__description p) {
  119. font-size: 13px;
  120. }
  121. }
  122. </style>