message-template-index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // 微信端
  2. function iosBackRefresh () {
  3. var isPageHide = false
  4. window.addEventListener('pageshow', function () {
  5. if (isPageHide) {
  6. location.reload()
  7. }
  8. })
  9. window.addEventListener('pagehide', function () {
  10. isPageHide = true
  11. })
  12. }
  13. var temp = '<div class="side-line" v-if="lists.length"><div class="list-msg"><div class="l-msg"><div class="words" v-for="item in lists" :key="item.id"><img class="dot-img" src="../images/no-read-dot.png" v-if="item.isRead == 0"><img class="dot-img" src="../images/read-dot.png" v-else><h3 :class="{isActive: item.isRead == 0}">@@item.msg_type@@</h3><span @click="titleGoto(item)">@@item.title@@</span><p>@@item.createtime@@</p></div></div><img @click="gotoUrl" class="r-msg" src="../images/jyxia.png"></div></div>'
  14. var vm = new Vue({
  15. el: '#vue-message-index-app',
  16. delimiters: ['@@', '@@'],
  17. template: temp,
  18. data: function () {
  19. return {
  20. lists: []
  21. }
  22. },
  23. created() {
  24. this.getList()
  25. },
  26. mounted() {
  27. iosBackRefresh()
  28. },
  29. methods: {
  30. getList() {
  31. var _this = this
  32. $.ajax({
  33. type:'POST',
  34. url:'/jymessageCenter/latestNews',
  35. success:function (res) {
  36. if (res.data) {
  37. res.data.forEach(v => {
  38. v.msg_type = _this.msgType(v.msg_type)
  39. v.createtime = dateMatter(v.createtime, 'out')
  40. })
  41. _this.lists = res.data
  42. }
  43. }
  44. })
  45. },
  46. topRead(ids, url, type) {
  47. const _this = this
  48. $.ajax({
  49. type: 'POST',
  50. url:'/jymessageCenter/markRead',
  51. data: {
  52. msgId: ids,
  53. msgType: type
  54. },
  55. success:function () {
  56. if (url) {
  57. window.open(url)
  58. } else {
  59. _this.getList()
  60. }
  61. }
  62. })
  63. },
  64. titleGoto(item) {
  65. let wxType = getType()
  66. let appType = androidOrIOS()
  67. let urls = item.url
  68. if (wxType) {
  69. if (item.isRead == 0) {
  70. this.topRead(item.id, urls.weChatUrl, item.msg_type)
  71. } else {
  72. if (urls.weChatUrl) {
  73. //链接中如果是www.jianyu360.cn域名,微信中会唤起app,该用window.open
  74. window.open(urls.weChatUrl)
  75. } else {
  76. return
  77. }
  78. }
  79. } else {
  80. if (appType == 'android') {
  81. if (item.isRead == 0) {
  82. this.topRead(item.id, urls.androidUrl, item.msg_type)
  83. } else {
  84. if (urls.androidUrl) {
  85. location.href = urls.androidUrl
  86. } else {
  87. return
  88. }
  89. }
  90. } else {
  91. if (item.isRead == 0) {
  92. this.topRead(item.id, urls.iosUrl, item.msg_type)
  93. } else {
  94. if (urls.iosUrl) {
  95. location.href = urls.iosUrl
  96. } else {
  97. return
  98. }
  99. }
  100. }
  101. }
  102. },
  103. gotoUrl() {
  104. // location.href = '/weixin/frontPage/messageCenter/sess/index?msg=2'
  105. window.open('/weixin/frontPage/messageCenter/sess/index?msg=2')
  106. },
  107. msgType(val) {
  108. const obj = {
  109. '1': '活动优惠',
  110. '2': '服务通知',
  111. '3': '订阅消息',
  112. '4': '项目动态 ',
  113. '5': '企业动态',
  114. '6': '分析报告 ',
  115. '7': '系统通知',
  116. }
  117. return obj[val]
  118. }
  119. }
  120. })