SiteMessageHome.vue 5.0 KB

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