onSocketMessage.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. },
  25. /** 获得会话列表 */
  26. getChatList(){
  27. _get.getChatList();
  28. },
  29. /** 获得好友列表 */
  30. getFriendList(){
  31. _get.getFriendList({ up: 1});
  32. },
  33. /** 新好友提醒 */
  34. newFriend(data){
  35. _action.playVoice('/static/voice/friend.mp3');
  36. let num = store.state.new_friend_tips_num + (data.num * 1);
  37. store.commit('set',{ k:'new_friend_tips_num',v:num });
  38. _action.setStatusTips();
  39. },
  40. /** 接收新消息 */
  41. chatData(data){
  42. let chat_data = store.state.page_data.chat_data,
  43. msg_reader_num = 1;
  44. if(chat_data[data.list_id]){
  45. // 如果在与对方的对话界面,更新这个对话的阅读(即反馈接收状态)
  46. if(store.state.page_data.message_query_list_id == data.list_id && store.state.user_info.id != data.data.msg.user_info.uid){
  47. _action.updataNoReader(data.list_id);
  48. msg_reader_num = 0;
  49. }
  50. store.state.page_data.chat_data[data.list_id].list.push(data.data);
  51. }
  52. /** 更新对话列表数据 */
  53. for(let i = 0,j = store.state.page_data.chat_list.length;i < j;i ++){
  54. if(store.state.page_data.chat_list[i].list_id == data.list_id){
  55. let last_msg;
  56. switch(data.data.msg.type * 1){
  57. case 0:
  58. last_msg = data.data.msg.content.text;
  59. break;
  60. case 1:
  61. /** 语音 */
  62. last_msg = '[语音]';
  63. break;
  64. case 2:
  65. /** 图片 */
  66. last_msg = '[图片]';
  67. break;
  68. case 3:
  69. /** 视频 */
  70. last_msg = '[视频]';
  71. break;
  72. case 4:
  73. /** 文件 */
  74. last_msg = '[文件]';
  75. break;
  76. case 5:
  77. /** 红包 */
  78. last_msg = '[红包]';
  79. break;
  80. default:
  81. /** 未知消息类型 */
  82. last_msg = '[未知]';
  83. break;
  84. }
  85. store.state.page_data.chat_list[i].last_msg = last_msg;
  86. store.state.page_data.chat_list[i].no_reader_num += msg_reader_num;
  87. store.state.page_data.chat_list[i].time = data.data.msg.time;
  88. let action_list_data = store.state.page_data.chat_list[i];
  89. store.state.page_data.chat_list.splice(i,1);
  90. store.state.page_data.chat_list.unshift(action_list_data);
  91. break;
  92. }
  93. }
  94. /** 如果不是自己的消息,震动提示 */
  95. if(store.state.user_info.id != data.data.msg.user_info.uid){
  96. uni.vibrateLong();
  97. _action.playVoice('/static/voice/chat.mp3');
  98. }
  99. },
  100. /** 接收好友朋友圈动态提示 */
  101. circleTips(data){
  102. _action.playVoice('/static/voice/circle.mp3');
  103. store.commit('set',{ k:'no_reader_circle',v:1 });
  104. _action.setStatusTips();
  105. },
  106. /** 接收朋友圈好友回复/赞通知 */
  107. cricleChatTips(data){
  108. _action.playVoice('/static/voice/circle.mp3');
  109. let num = store.state.no_reader_circle_chat_num;
  110. num ++;
  111. store.commit('set',{ k:'no_reader_circle_chat_num',v:num });
  112. _action.setStatusTips();
  113. },
  114. /** 撤回消息 */
  115. deleteChat(data){
  116. let chat_data = store.state.page_data.chat_data;
  117. if(chat_data[data.list_id] && chat_data[data.list_id].list.length){
  118. for(let i = 0,j = chat_data[data.list_id].list.length;i < j;i++ ){
  119. if(chat_data[data.list_id].list[i].msg.id == data.msg_id){
  120. store.state.page_data.chat_data[data.list_id].list.splice(i,1);
  121. break;
  122. }
  123. }
  124. }
  125. },
  126. }