live-reply.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {getEventParam, throttle, toast} from "../../../../utils/utils";
  2. import Config from "../../../../model/config";
  3. import {storeBindingsBehavior} from "mobx-miniprogram-bindings";
  4. import {timStore} from "../../../../store/tim";
  5. // var log = require('../../../../utils/log');
  6. import {LOG_TAGS} from '../../../../model/enum';
  7. import MyLogManager from "../../../../utils/log";
  8. var log = new MyLogManager(LOG_TAGS.LIVE);
  9. Component({
  10. behaviors: [storeBindingsBehavior],
  11. properties: {
  12. showHand: Boolean,
  13. showMsg: Boolean,
  14. groupId: String,
  15. userSig: String,
  16. user: Object,
  17. },
  18. data: {
  19. message: '',
  20. bottom: 0,
  21. top: 0,
  22. handing: false,
  23. time: Config.LIVE_CD_TIME,
  24. timeData: {}
  25. },
  26. storeBindings: {
  27. store: timStore,
  28. fields: ['sdkReady', 'groupReady', "messageList", "handReply"],
  29. actions: ['login', 'setUser', 'logout']
  30. },
  31. observers: {
  32. groupId: async function (newV, oldV) {
  33. if (newV) {
  34. log.info('live-reply groupId:', this.data.groupId);
  35. log.info('newV ', newV);
  36. log.info('oldV ', oldV);
  37. await this.setUser(this.data.user, this.data.groupId, this.data.userSig);
  38. await this.login()
  39. }
  40. },
  41. handReply: async function (newV) {
  42. const countDown = this.selectComponent('.control-count-down');
  43. countDown && countDown.reset();
  44. this.finished()
  45. },
  46. },
  47. attached() {
  48. wx.hideShareMenu();
  49. },
  50. methods: {
  51. async reLogin(e) {
  52. try{
  53. await this.logout();
  54. } catch(err) {
  55. console.log('logout error', err);
  56. }
  57. await this.setUser(this.data.user, this.data.groupId, this.data.userSig);
  58. await this.login()
  59. },
  60. changeMessage(e) {
  61. this.setData({
  62. message: getEventParam(e)
  63. })
  64. },
  65. reply:throttle(function (e){
  66. this.triggerEvent("message", {msg: this.data.message});
  67. }),
  68. handClick:throttle(function (e){
  69. if (this.data.handing) {
  70. return
  71. }
  72. this.setData({
  73. handing: true,
  74. })
  75. this.triggerEvent("hand");
  76. }),
  77. clear() {
  78. this.setData({
  79. message: ""
  80. })
  81. },
  82. finished(noTip) {
  83. this.setData({
  84. handing: false,
  85. })
  86. if (noTip) {
  87. toast("举手暂无应答,请稍后重试")
  88. }
  89. },
  90. onChange(e) {
  91. this.setData({
  92. timeData: getEventParam(e),
  93. });
  94. },
  95. onFocus(e) {
  96. const keyboradHeight = getEventParam(e, "height");
  97. this.setData({
  98. top: keyboradHeight
  99. })
  100. },
  101. onBlur() {
  102. this.setData({
  103. top: 0
  104. })
  105. },
  106. }
  107. });