person.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import axios from '../http'
  2. import { cryptoMsg, decryptoMsg } from '@/util/util.js'
  3. import Message from '@/store/db/Message.js'
  4. export default {
  5. /**
  6. * 用户最新消息
  7. * @param {Object} data
  8. * @param {String} data.group_id
  9. * @param {String} data.client_hash // 客户端最新消息hash
  10. */
  11. async getNewMsg (params) {
  12. let res = await axios.request({
  13. url: 'person/newMsg',
  14. method: 'get',
  15. needLogin: true,
  16. params
  17. })
  18. const objMessage = new Message()
  19. // 如果不同步执行,第一次初始化数据库会出现很奇怪的问题...
  20. await objMessage.saveMsg(params['session_id'], res.data.data)
  21. // 解密数据
  22. res.data.data.list.forEach(item => {
  23. if (item.msg_type == 4) {
  24. item.msg = JSON.parse(decryptoMsg(item.msg))
  25. } else {
  26. item.msg = decryptoMsg(item.msg)
  27. }
  28. })
  29. return res
  30. },
  31. /**
  32. * 用户历史消息
  33. * @param {Object} data
  34. * @param {String} data.group_id
  35. * @param {String} data.client_hash // 客户端最旧消息hash
  36. */
  37. getHistoryMsg (params) {
  38. return axios.request({
  39. url: 'person/historyMsg',
  40. method: 'get',
  41. needLogin: true,
  42. params
  43. })
  44. },
  45. /**
  46. * 发送私聊信息
  47. * @param {Object} data
  48. * @param {Number} data.session_id 会话id
  49. * @param {Number} data.msg_type 消息类型:0:文本,1:图片,2:视频
  50. * @param {String} data.msg 内容
  51. */
  52. sendMsg (data) {
  53. data.msg = cryptoMsg(data.msg)
  54. return axios.request({
  55. url: 'person/sendMsg',
  56. method: 'post',
  57. needLogin: true,
  58. data
  59. })
  60. },
  61. /**
  62. * 发送私聊信息
  63. * @param {Object} data
  64. * @param {String} data.session_id 会话id
  65. * @param {String} data.hash 会话hash
  66. */
  67. repealPersonMsg (data) {
  68. return axios.request({
  69. url: 'person/repealMsg',
  70. method: 'post',
  71. needLogin: true,
  72. data
  73. })
  74. }
  75. }