Mymessage.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <!-- -->
  2. <template>
  3. <div class="Mymessage">
  4. <EditTitle :title="title" />
  5. <div class="cc-content">
  6. <h2 class="cc-title" v-if="total_count">{{ $t("Key69") }}</h2>
  7. <div
  8. class="cc-main-box"
  9. v-infinite-scroll="load"
  10. infinite-scroll-disabled="disabled"
  11. >
  12. <div
  13. class="cc-main"
  14. v-for="(item, key, index) in listObj"
  15. :key="'all' + index"
  16. >
  17. <p class="cc-date">{{ key }}</p>
  18. <div
  19. class="cc-main-item"
  20. v-for="(msgItem, dateIndex) in item"
  21. :key="'msglist' + dateIndex"
  22. @click="viewDetail(msgItem)"
  23. >
  24. <div
  25. class="cc-msg-pic"
  26. :class="key == currDate ? 'sys-active' : 'no-active'"
  27. >
  28. <img :src="msgItem.sender_type == 0 ? sysIcon : teachIcon" />
  29. </div>
  30. <div class="cc-msg">
  31. <div class="cc-msg-title">
  32. {{ msgItem.sender_name }} {{ msgItem.time }}
  33. </div>
  34. <div class="cc-msg-main">
  35. <div
  36. class="cc-msg-content"
  37. :class="[msgItem.is_read == 'true' ? 'active' : '']"
  38. v-html="msgItem.content"
  39. ></div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <p class="notice-text" v-if="loading">{{ $t("Key463") }}...</p>
  46. <p class="notice-text" v-if="noMore&&total_count">{{ $t("Key462") }}</p>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import EditTitle from "../common/EditTitle.vue";
  52. import { getLearnWebContent } from "@/api/ajax";
  53. import { createComprisonFunction } from "@/utils/index";
  54. export default {
  55. name: "Mymessage",
  56. components: {
  57. EditTitle,
  58. },
  59. data() {
  60. return {
  61. pageSize: 20,
  62. pageNum: 0,
  63. total_page: 1,
  64. total_count: 0,
  65. loading: false,
  66. height: "20px",
  67. currDate: "",
  68. sysIcon: require("../../assets/Personalcenter/system-msg-icon.png"),
  69. teachIcon: require("../../assets/Personalcenter/teacher-msg-icon.png"),
  70. listObj: {},
  71. title: this.$t("Key68"),
  72. };
  73. },
  74. computed: {
  75. noMore() {
  76. return this.pageNum >= this.total_page;
  77. },
  78. disabled() {
  79. return this.loading || this.noMore;
  80. },
  81. },
  82. watch: {},
  83. //方法集合
  84. methods: {
  85. //可实现滚动到底部时自动执行加载方法
  86. load() {
  87. this.loading = true;
  88. this.pageNum++;
  89. let MethodName = "page_query-PageQueryMyMessageList";
  90. let data = {
  91. read_status: -1,
  92. message_type: -1,
  93. page_capacity: this.pageSize,
  94. cur_page: this.pageNum,
  95. };
  96. getLearnWebContent(MethodName, data).then((res) => {
  97. this.loading = false;
  98. let list = res.message_list;
  99. this.total_page = res.total_page;
  100. this.total_count = res.total_count
  101. if (list && list.length > 0) {
  102. list = list.map((item) => {
  103. item.isShow = false;
  104. return item;
  105. });
  106. this.listObj = this.handleSortByDate(list);
  107. }
  108. });
  109. },
  110. load1() {
  111. this.pageNum++;
  112. let list = this.message_list[this.pageNum];
  113. if (list && list.length > 0) {
  114. list = list.map((item) => {
  115. item.isShow = false;
  116. return item;
  117. });
  118. this.listObj = this.handleSortByDate(list);
  119. }
  120. },
  121. //按日期分类
  122. handleSortByDate(list) {
  123. let listObj = JSON.parse(JSON.stringify(this.listObj));
  124. list.forEach((item) => {
  125. let dateArr = item.send_time.split(" ");
  126. let date = dateArr[0];
  127. let time = dateArr[1];
  128. item.time = time;
  129. item.sec = this.timeTosec(time);
  130. if (listObj.hasOwnProperty(date)) {
  131. listObj[date].push(item);
  132. } else {
  133. listObj[date] = [];
  134. listObj[date].push(item);
  135. }
  136. });
  137. for (let key in listObj) {
  138. let value = listObj[key];
  139. listObj[key] = this.handleSortBySec(value);
  140. }
  141. return listObj;
  142. },
  143. //按时间排序
  144. handleSortBySec(list) {
  145. let resList = JSON.parse(JSON.stringify(list));
  146. resList.sort(createComprisonFunction("sec"));
  147. resList.reverse();
  148. return resList;
  149. },
  150. //时分秒转化给秒
  151. timeTosec(time) {
  152. var s = "";
  153. var hour = time.split(":")[0];
  154. var min = time.split(":")[1];
  155. var sec = time.split(":")[2];
  156. s = Number(hour * 3600) + Number(min * 60) + Number(sec);
  157. return s;
  158. },
  159. //查看消息详情
  160. viewDetail(msgItem) {
  161. msgItem.isShow = !msgItem.isShow;
  162. let date = msgItem.send_time.split(" ");
  163. if (msgItem.is_read == "false") {
  164. let MethodName = "message-message_manager-ReadMyMessage";
  165. let data = {
  166. id: msgItem.id,
  167. };
  168. getLearnWebContent(MethodName, data).then((res) => {
  169. msgItem.is_read = "true";
  170. this.getNotReadMessage();
  171. if (msgItem.message_type == 101) {
  172. window.location.href = `/GCLS-Learn/#/EnterSys?tab=TaskList&enter=main&dateStamp=${date[0]}`;
  173. }
  174. });
  175. } else {
  176. if (msgItem.message_type == 101) {
  177. window.location.href = `/GCLS-Learn/#/EnterSys?tab=TaskList&enter=main&dateStamp=${date[0]}`;
  178. }
  179. }
  180. },
  181. //是否存在我未阅读的消息
  182. getNotReadMessage() {
  183. let MethodName = "message-message_manager-IsExistMyMessage_NotRead";
  184. let data = {};
  185. getLearnWebContent(MethodName, data).then((res) => {
  186. this.$store.dispatch("message/updateIsExist", res.is_exist);
  187. });
  188. },
  189. },
  190. //生命周期 - 创建完成(可以访问当前this实例)
  191. created() {},
  192. //生命周期 - 挂载完成(可以访问DOM元素)
  193. mounted() {
  194. //今天的时间
  195. var day2 = new Date();
  196. let month = day2.getMonth() + 1;
  197. month = month < 10 ? "0" + month : month;
  198. let day = day2.getDate();
  199. day = day < 10 ? "0" + day : day;
  200. var s2 = day2.getFullYear() + "-" + month + "-" + day;
  201. this.currDate = s2;
  202. },
  203. beforeCreate() {}, //生命周期 - 创建之前
  204. beforeMount() {}, //生命周期 - 挂载之前
  205. beforeUpdate() {}, //生命周期 - 更新之前
  206. updated() {}, //生命周期 - 更新之后
  207. beforeDestroy() {}, //生命周期 - 销毁之前
  208. destroyed() {}, //生命周期 - 销毁完成
  209. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  210. };
  211. </script>
  212. <style lang='scss' scoped>
  213. //@import url(); 引入公共css类
  214. .Mymessage {
  215. .notice-text {
  216. width: 100%;
  217. text-align: center;
  218. font-size: 12px;
  219. }
  220. .cc-content {
  221. box-sizing: border-box;
  222. width: 100%;
  223. padding: 24px 0px;
  224. .cc-title {
  225. font-size: 16px;
  226. line-height: 150%;
  227. color: #000000;
  228. padding: 0 40px;
  229. margin-bottom: 16px;
  230. }
  231. .cc-main-box {
  232. height: 734px;
  233. padding: 0 40px;
  234. box-sizing: border-box;
  235. overflow-y: auto;
  236. overflow: -moz-scrollbars-none; /*Firefox*/
  237. scrollbar-width: none; /*Firefox*/
  238. -ms-overflow-style: none; /*IE10+*/
  239. &::-webkit-scrollbar {
  240. width: 0 !important;
  241. }
  242. }
  243. .cc-main {
  244. padding-bottom: 24px;
  245. .cc-date {
  246. font-size: 14px;
  247. line-height: 150%;
  248. color: #000000;
  249. }
  250. &-item {
  251. display: flex;
  252. justify-content: flex-start;
  253. align-items: flex-start;
  254. padding: 24px 0;
  255. box-sizing: border-box;
  256. border-bottom: 1px rgba(44, 44, 44, 0.15) solid;
  257. cursor: pointer;
  258. .cc-msg-pic {
  259. display: flex;
  260. justify-content: center;
  261. align-items: center;
  262. width: 40px;
  263. height: 40px;
  264. border-radius: 100%;
  265. &.sys-active {
  266. background: #ff9900;
  267. }
  268. &.teach-active {
  269. background: #27c579;
  270. }
  271. &.no-active {
  272. background: #d5d5d5;
  273. }
  274. > img {
  275. width: 16px;
  276. height: 16px;
  277. }
  278. }
  279. .cc-msg {
  280. margin: 0 16px;
  281. &-main {
  282. display: flex;
  283. justify-content: flex-start;
  284. align-items: flex-start;
  285. .dian {
  286. font-size: 14px;
  287. line-height: 150%;
  288. color: #2c2c2c;
  289. font-weight: bold;
  290. }
  291. }
  292. &-title {
  293. font-size: 12px;
  294. line-height: 150%;
  295. color: #2c2c2c;
  296. opacity: 0.7;
  297. margin-bottom: 1px;
  298. }
  299. &-content {
  300. max-width: 712px;
  301. // height: 20px;
  302. font-size: 14px;
  303. line-height: 150%;
  304. color: #2c2c2c;
  305. font-weight: bold;
  306. &.overflow {
  307. overflow: hidden;
  308. white-space: nowrap;
  309. text-overflow: ellipsis;
  310. }
  311. &.active {
  312. font-weight: normal;
  313. }
  314. &.showAll {
  315. height: auto;
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. </style>