SiteMessageHome.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <main-layout>
  3. <i-breadcrumb
  4. style="text-align: left; padding-left: 20px; height: 40px; line-height: 40px;
  5. background-color: #fafafa;"
  6. >
  7. 当前所在位置:
  8. <i-breadcrumb-item>公告通知</i-breadcrumb-item>
  9. </i-breadcrumb>
  10. <div class="home">
  11. <div style="font-size: 18px; font-weight: 500; color: #222C32;">
  12. 公告通知
  13. </div>
  14. <i-button>
  15. <div class="mark-read-block" @click="markRead">
  16. <img src="./svgs/sms-read.svg" /> &nbsp;标记为已读
  17. </div>
  18. </i-button>
  19. </div>
  20. <div class="site-message-container">
  21. <div style="text-align: left; color: #999; margin-bottom: 5px;">
  22. *仅保留近1年的公告通知。
  23. </div>
  24. <Table
  25. ref="selection"
  26. border
  27. :columns="columns"
  28. :data="siteMessagesComputed"
  29. ></Table>
  30. <Page
  31. :total="siteMessages.length"
  32. :page-size="pageSize"
  33. :current.sync="page"
  34. style="text-align: right; margin-top: 10px;"
  35. />
  36. </div>
  37. </main-layout>
  38. </template>
  39. <script>
  40. // import moment from "moment";
  41. import { mapState, mapMutations } from "vuex";
  42. export default {
  43. name: "SiteMessageHome",
  44. data() {
  45. return {
  46. columns: [
  47. {
  48. type: "selection",
  49. width: 60,
  50. align: "center",
  51. },
  52. {
  53. title: "标题",
  54. key: "title",
  55. render: (h, params) => {
  56. return (
  57. <router-link
  58. to={"/site-message/" + params.row.id + "?fromPage=" + this.page}
  59. style="display: flex"
  60. ondragstart="return false;"
  61. >
  62. <img
  63. class={
  64. params.row.hasRead
  65. ? "mhome-message-read"
  66. : "mhome-message-unread"
  67. }
  68. />
  69. <span class="mhome-message-title">{params.row.title}</span>
  70. </router-link>
  71. );
  72. },
  73. },
  74. {
  75. title: "发送时间",
  76. key: "publishTime",
  77. width: "150",
  78. },
  79. ],
  80. page: 1,
  81. pageSize: 10,
  82. };
  83. },
  84. computed: {
  85. ...mapState(["user", "siteMessages", "siteMessagesTimeStamp"]),
  86. siteMessagesComputed() {
  87. return this.siteMessages.slice(
  88. (this.page - 1) * this.pageSize,
  89. this.page * this.pageSize
  90. );
  91. },
  92. },
  93. async mounted() {
  94. window._hmt.push(["_trackEvent", "站内消息列表页面", "进入页面"]);
  95. await this.getList();
  96. if (this.$route.query.fromPage) {
  97. this.page = +this.$route.query.fromPage;
  98. }
  99. },
  100. methods: {
  101. ...mapMutations(["updateSiteMessages", "updateSiteMessagesTimeStamp"]),
  102. async getList() {
  103. try {
  104. const noticeRes = (await this.$http.get(
  105. "/api/ecs_exam_work/notice/getUserNoticeList?" +
  106. this.user.id +
  107. this.siteMessagesTimeStamp
  108. )).data;
  109. this.updateSiteMessages(noticeRes);
  110. } catch (error) {
  111. console.log(error);
  112. this.$Message.error({
  113. content: "获取公告通知异常",
  114. duration: 15,
  115. closable: true,
  116. });
  117. }
  118. },
  119. async markRead() {
  120. // console.log(this.$refs.selection.getSelection());
  121. const selectIds = this.$refs.selection.getSelection().map(v => v.id);
  122. if (selectIds.length === 0) {
  123. this.$Message.warning({
  124. content: "请先选择消息",
  125. duration: 10,
  126. closable: true,
  127. });
  128. return;
  129. }
  130. await this.$http.post(
  131. "/api/ecs_exam_work/notice/updateNoticeReadStatus?noticeId=" +
  132. selectIds.join(",")
  133. );
  134. window._hmt.push(["_trackEvent", "站内消息详情页面", "发送已读成功"]);
  135. this.updateSiteMessagesTimeStamp(Date.now());
  136. await this.getList();
  137. },
  138. },
  139. };
  140. </script>
  141. <style scoped>
  142. .home {
  143. margin: 20px;
  144. display: flex;
  145. justify-content: space-between;
  146. }
  147. .mark-read-block {
  148. line-height: 16px;
  149. /* border-radius: 6px;
  150. border: 1px solid rgba(238, 238, 238, 1); */
  151. /* padding: 0 10px; */
  152. display: flex;
  153. align-items: center;
  154. }
  155. .site-message-container {
  156. display: flex;
  157. flex-direction: column;
  158. margin: 20px;
  159. padding: 20px;
  160. border: 1px solid #eeeeee;
  161. border-radius: 6px;
  162. }
  163. </style>
  164. <style>
  165. .mhome-message-read {
  166. width: 16px;
  167. height: 14px;
  168. background-image: url(./svgs/sms-read.svg);
  169. }
  170. .mhome-message-unread {
  171. width: 16px;
  172. height: 14px;
  173. background-image: url(./svgs/sms-unread.svg);
  174. }
  175. .mhome-message-title {
  176. line-height: 14px;
  177. margin-left: 8px;
  178. }
  179. </style>