index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. var vm = new Vue({
  2. el: '#mesged',
  3. delimiters: ['{', '}'],
  4. data: function () {
  5. return {
  6. isToggle: false,
  7. isRow: false,
  8. lastData: [],
  9. msgList: [],
  10. timer: null,
  11. messageCount: 0,
  12. messageInfo: {},
  13. imgSrcs: [
  14. {title: '活动优惠', url:'huodong'},
  15. {title: '服务通知', url:'fuwu'},{title: '订阅消息', url:'dingyue'},
  16. {title: '项目动态', url:'xiangmu'},{title: '企业动态', url:'qiye'},
  17. {title: '分析报告', url:'fenxi'},{title: '系统通知', url:'xitong'}
  18. ],
  19. isShowEntrance: true // 是否展示私信入口
  20. }
  21. },
  22. created() {
  23. Object.assign(this.$data, this.$options.data())
  24. this.lastMsg()
  25. this.msgData()
  26. this.getPrivateLetter()
  27. let wxType = getType()
  28. if (!wxType) {
  29. checkMsgCount(true, 0)
  30. }
  31. },
  32. mounted () {
  33. // iosBackRefresh()
  34. keepQuest()
  35. },
  36. beforeDestroy() {
  37. clearInterval(this.timer)
  38. },
  39. methods: {
  40. // 置顶消息
  41. lastMsg() {
  42. const _this = this
  43. $.ajax({
  44. type:'POST',
  45. url:'/jymessageCenter/lastMessage',
  46. success:function (res) {
  47. if (res && res.status == 1) {
  48. _this.lastData = $.isEmptyObject(res.data) ? false : res.data
  49. if (res.data && res.data.content && res.data.content.length > 46) {
  50. _this.isRow = true
  51. } else {
  52. _this.isRow = false
  53. }
  54. }
  55. }
  56. })
  57. },
  58. // 获取私信
  59. getPrivateLetter () {
  60. const _this = this
  61. $.ajax({
  62. type:'POST',
  63. contentType: 'application/json',
  64. url:'/jyapi/message/messageCount',
  65. data: JSON.stringify({
  66. userType: 2
  67. }),
  68. success:function (res) {
  69. if (res && res.error_code === 0 && res.data) {
  70. _this.messageCount = res.count
  71. _this.messageInfo = res.data
  72. if(res.data && res.data.content) {
  73. if(res.data.content.search('<p>') !== -1) {
  74. res.data.content = res.data.content.replace(/<p>/g, '')
  75. }
  76. }
  77. }
  78. }
  79. })
  80. },
  81. // 消息列表
  82. msgData() {
  83. const _this = this
  84. $.ajax({
  85. type:'POST',
  86. url:'/jymessageCenter/classAndNew',
  87. success:function (res) {
  88. if (res && res.status == 1) {
  89. _this.msgList = $.isEmptyObject(res.data) ? false : res.data
  90. }
  91. }
  92. })
  93. },
  94. // 点击置顶消息为已读
  95. topRead(ids, url, type, wxType) {
  96. const _this = this
  97. $.ajax({
  98. type:'POST',
  99. url:'/jymessageCenter/markRead',
  100. data: {
  101. msgId: ids,
  102. msgType: type
  103. },
  104. success:function () {
  105. _this.msgData()
  106. if (url) {
  107. if (getType()) {
  108. //链接中如果是www.jianyu360.cn域名,微信中会唤起app,该用window.open
  109. window.open(url)
  110. } else {
  111. location.href = url
  112. }
  113. }
  114. }
  115. })
  116. },
  117. platType() {
  118. let wxType = getType()
  119. if (wxType) {
  120. return 3
  121. } else {
  122. return 2
  123. }
  124. },
  125. clickMesg(logid) {
  126. const _this = this
  127. $.ajax({
  128. type: 'GET',
  129. url: '/jymessageCenter/clickMessage',
  130. data: {
  131. msgLogId: logid,
  132. platform: _this.platType()
  133. },
  134. success:function () {}
  135. })
  136. },
  137. // 置顶消息跳转
  138. msgClick(url, num, ids, type, logid) {
  139. this.clickMesg(logid)
  140. let wxType = getType()
  141. let appType = androidOrIOS()
  142. if (wxType) {
  143. if (!num) {
  144. this.topRead(ids, url.weChatUrl, type, wxType)
  145. } else {
  146. if (url.weChatUrl) {
  147. //location.href = url.weChatUrl
  148. //链接中如果是www.jianyu360.cn域名,微信中会唤起app,该用window.open
  149. window.open(url.weChatUrl);
  150. }
  151. }
  152. } else {
  153. if (appType == 'android') {
  154. if (!num) {
  155. this.topRead(ids, url.androidUrl, type, wxType)
  156. } else {
  157. if (url.androidUrl) {
  158. location.href = url.androidUrl
  159. }
  160. }
  161. } else {
  162. if (!num) {
  163. this.topRead(ids, url.iosUrl, type, wxType)
  164. } else {
  165. if (url.iosUrl) {
  166. location.href = url.iosUrl
  167. }
  168. }
  169. }
  170. }
  171. },
  172. // 置顶消息展开,收起
  173. toggleClick() {
  174. this.isToggle = !this.isToggle
  175. },
  176. // 私信
  177. msgPriDetailed () {
  178. const params= {
  179. userType: 2
  180. }
  181. sessionStorage.removeItem('conversation-login-clear')
  182. $.ajax({
  183. type: 'POST',
  184. url: '/jyapi/message/userList',
  185. contentType: 'application/json',
  186. data: JSON.stringify(params),
  187. success: function(res) {
  188. if (res.error_code === 0) {
  189. if (res.data && res.data.length !== 0) {
  190. const firstUser = res.data[0]
  191. location.href = `/page_social_mobile/home?receiveAppId=${firstUser.userId}&userType=${firstUser.userType}&pname=${firstUser.name}`
  192. } else {
  193. location.href = '/page_social_mobile/home?receiveAppId=455b495c5c&userType=1&pname=剑鱼标讯'
  194. }
  195. } else {
  196. location.href = '/page_social_mobile/home?receiveAppId=455b495c5c&userType=1&pname=剑鱼标讯'
  197. }
  198. }
  199. })
  200. },
  201. // 列表消息跳转详情页
  202. msgDetailed(type, num) {
  203. let wxType = getType()
  204. if (wxType) {
  205. location.href = '/weixin/frontPage/messageCenter/sess/detail?type=' + type + '&num=' + num
  206. } else {
  207. location.href = '/jyapp/frontPage/messageCenter/sess/detail?type=' + type + '&num=' + num
  208. }
  209. }
  210. }
  211. })