index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 { storeToRefs } from 'pinia';
  27. import useNoticeStore from '@/store/modules/notice';
  28. const noticeStore = storeToRefs(useNoticeStore());
  29. const { readAll } = useNoticeStore();
  30. // 定义变量内容
  31. const state = reactive({
  32. loading: false
  33. });
  34. const newsList = ref([]) as any;
  35. /**
  36. * 初始化数据
  37. * @returns
  38. */
  39. const getTableData = async () => {
  40. state.loading = true;
  41. newsList.value = noticeStore.state.value.notices;
  42. state.loading = false;
  43. };
  44. //点击消息,写入已读
  45. const onNewsClick = (item: any) => {
  46. newsList.value[item].read = true;
  47. //并且写入pinia
  48. noticeStore.state.value.notices = newsList.value;
  49. };
  50. // 前往通知中心点击
  51. const onGoToGiteeClick = () => {
  52. window.open('https://gitee.com/dromara/RuoYi-Vue-Plus/tree/5.X/');
  53. };
  54. onMounted(() => {
  55. nextTick(() => {
  56. getTableData();
  57. });
  58. });
  59. </script>
  60. <style lang="scss" scoped>
  61. .layout-navbars-breadcrumb-user-news {
  62. .head-box {
  63. display: flex;
  64. border-bottom: 1px solid var(--el-border-color-lighter);
  65. box-sizing: border-box;
  66. color: var(--el-text-color-primary);
  67. justify-content: space-between;
  68. height: 35px;
  69. align-items: center;
  70. .head-box-btn {
  71. color: var(--el-color-primary);
  72. font-size: 13px;
  73. cursor: pointer;
  74. opacity: 0.8;
  75. &:hover {
  76. opacity: 1;
  77. }
  78. }
  79. }
  80. .content-box {
  81. height: 300px;
  82. overflow: auto;
  83. font-size: 13px;
  84. .content-box-item {
  85. padding-top: 12px;
  86. display: flex;
  87. &:last-of-type {
  88. padding-bottom: 12px;
  89. }
  90. .content-box-msg {
  91. color: var(--el-text-color-secondary);
  92. margin-top: 5px;
  93. margin-bottom: 5px;
  94. }
  95. .content-box-time {
  96. color: var(--el-text-color-secondary);
  97. }
  98. .item-conten {
  99. width: 100%;
  100. display: flex;
  101. flex-direction: column;
  102. }
  103. }
  104. }
  105. .foot-box {
  106. height: 35px;
  107. color: var(--el-color-primary);
  108. font-size: 13px;
  109. cursor: pointer;
  110. opacity: 0.8;
  111. display: flex;
  112. align-items: center;
  113. justify-content: center;
  114. border-top: 1px solid var(--el-border-color-lighter);
  115. &:hover {
  116. opacity: 1;
  117. }
  118. }
  119. :deep(.el-empty__description p) {
  120. font-size: 13px;
  121. }
  122. }
  123. </style>