index.vue 3.4 KB

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