Message.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. class Message {
  2. /**
  3. * 消息ID
  4. */
  5. msgId = "";
  6. /**
  7. * 消息类型
  8. */
  9. msgType = 1;
  10. /**
  11. * 消息类型
  12. */
  13. code = "";
  14. /**
  15. * 认证通行证
  16. */
  17. token = "";
  18. /**
  19. * 消息数据
  20. */
  21. data = "";
  22. /**
  23. * 确认帧ID
  24. */
  25. askId = "";
  26. /**
  27. * 需要对方确认应答
  28. */
  29. ask = false;
  30. /**
  31. * 是否回复数据
  32. */
  33. reply = false;
  34. /**
  35. * 其他数据
  36. */
  37. remark = "";
  38. /**
  39. *
  40. * @param {Object} data 消息数据
  41. * @param {Object} MsgType 消息类型 1: 普通包文 ,2:消息确认帧
  42. * @param {Object} code 消息类型[]
  43. * @param {Object} ask 需要对方确认应答
  44. * @param {Object} isReply 是否应答数据
  45. */
  46. constructor(data = '',code = '',ask = false,MsgType = 1,isReply = false) {
  47. this.data = data;
  48. this.msgType = MsgType;
  49. this.code = code;
  50. this.ask = ask;
  51. this.reply = isReply;
  52. }
  53. getJson() {
  54. return JSON.stringify(this.getData());
  55. }
  56. getData(){
  57. return {
  58. data : this.data,
  59. msgType : this.msgType,
  60. code : this.code,
  61. ask : this.ask,
  62. reply : this.reply,
  63. msgId : this.msgId,
  64. askId : this.askId,
  65. remark : this.remark
  66. };
  67. }
  68. }
  69. export default Message