onSocketMessage.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import store from './store/';
  2. import _get from './_get';
  3. import _action from './_action';
  4. export default {
  5. /** 验证token */
  6. checkToken(res) {
  7. if(res.err){
  8. _action.checkFail();
  9. } else {
  10. /** 设置为登陆状态 */
  11. store.commit('set',{ k:'socket_state',v:1 });
  12. /** 获取基础数据 */
  13. _get.base();
  14. }
  15. },
  16. /** 下线 */
  17. offline(res){
  18. // uni.showModal({
  19. // content: '你的账号在另一客户端登陆,如果不是你本人操作,请修改你的密码',
  20. // success(){
  21. // _action.checkFail();
  22. // },
  23. // });
  24. _action.checkFail();
  25. // uni.navigateTo({
  26. // url:'/pages/in/login'
  27. // })
  28. },
  29. /** 获得会话列表 */
  30. getChatList(){
  31. _get.getChatList();
  32. },
  33. /** 获得好友列表 */
  34. getFriendList(){
  35. _get.getFriendList({ up: 1});
  36. },
  37. /** 新好友提醒 */
  38. newFriend(data){
  39. _action.playVoice('/static/voice/friend.mp3');
  40. let num = store.state.new_friend_tips_num + (data.num * 1);
  41. store.commit('set',{ k:'new_friend_tips_num',v:num });
  42. _action.setStatusTips();
  43. },
  44. timeData(data){
  45. console.log(data);
  46. },
  47. /** 接收新消息 */
  48. chatData(data){
  49. let chat_data = store.state.page_data.chat_data,
  50. msg_reader_num = 1;
  51. if(chat_data[data.list_id]){
  52. // 如果在与对方的对话界面,更新这个对话的阅读(即反馈接收状态)
  53. if(store.state.page_data.message_query_list_id == data.list_id && store.state.user_info.id != data.data.msg.user_info.uid){
  54. _action.updataNoReader(data.list_id);
  55. msg_reader_num = 0;
  56. }
  57. store.state.page_data.chat_data[data.list_id].list.push(data.data);
  58. }
  59. console.log(data);
  60. /** 更新对话列表数据 */
  61. for(let i = 0,j = store.state.page_data.chat_list.length;i < j;i ++){
  62. if(store.state.page_data.chat_list[i].list_id == data.list_id){
  63. let last_msg;
  64. switch(data.data.msg.type * 1){
  65. case 0:
  66. last_msg = data.data.msg.content.text;
  67. break;
  68. case 1:
  69. /** 语音 */
  70. last_msg = '[语音]';
  71. break;
  72. case 2:
  73. /** 图片 */
  74. last_msg = '[图片]';
  75. break;
  76. case 3:
  77. /** 视频 */
  78. last_msg = '[视频]';
  79. break;
  80. case 4:
  81. /** 文件 */
  82. last_msg = '[文件]';
  83. break;
  84. case 5:
  85. /** 红包 */
  86. last_msg = '[红包]';
  87. break;
  88. default:
  89. /** 未知消息类型 */
  90. last_msg = '[未知]';
  91. break;
  92. }
  93. store.state.page_data.chat_list[i].last_msg = last_msg;
  94. store.state.page_data.chat_list[i].no_reader_num += msg_reader_num;
  95. store.state.page_data.chat_list[i].time = data.data.msg.time;
  96. let action_list_data = store.state.page_data.chat_list[i];
  97. store.state.page_data.chat_list.splice(i,1);
  98. store.state.page_data.chat_list.unshift(action_list_data);
  99. break;
  100. }
  101. }
  102. /** 如果不是自己的消息,震动提示 */
  103. if(store.state.user_info.id != data.data.msg.user_info.uid){
  104. uni.vibrateLong();
  105. _action.playVoice('/static/voice/chat.mp3');
  106. }
  107. },
  108. /** 接收好友朋友圈动态提示 */
  109. circleTips(data){
  110. _action.playVoice('/static/voice/circle.mp3');
  111. store.commit('set',{ k:'no_reader_circle',v:1 });
  112. _action.setStatusTips();
  113. },
  114. /** 接收朋友圈好友回复/赞通知 */
  115. cricleChatTips(data){
  116. _action.playVoice('/static/voice/circle.mp3');
  117. let num = store.state.no_reader_circle_chat_num;
  118. num ++;
  119. store.commit('set',{ k:'no_reader_circle_chat_num',v:num });
  120. _action.setStatusTips();
  121. },
  122. /** 撤回消息 */
  123. deleteChat(data){
  124. let chat_data = store.state.page_data.chat_data;
  125. if(chat_data[data.list_id] && chat_data[data.list_id].list.length){
  126. for(let i = 0,j = chat_data[data.list_id].list.length;i < j;i++ ){
  127. if(chat_data[data.list_id].list[i].msg.id == data.msg_id){
  128. store.state.page_data.chat_data[data.list_id].list.splice(i,1);
  129. break;
  130. }
  131. }
  132. }
  133. },
  134. }