Mymessage.vue 9.0 KB

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