import {getEventParam, throttle, toast} from "../../../../utils/utils"; import Config from "../../../../model/config"; import {storeBindingsBehavior} from "mobx-miniprogram-bindings"; import {timStore} from "../../../../store/tim"; // var log = require('../../../../utils/log'); import {LOG_TAGS} from '../../../../model/enum'; import MyLogManager from "../../../../utils/log"; var log = new MyLogManager(LOG_TAGS.LIVE); Component({ behaviors: [storeBindingsBehavior], properties: { showHand: Boolean, showMsg: Boolean, groupId: String, userSig: String, user: Object, }, data: { message: '', bottom: 0, top: 0, handing: false, time: Config.LIVE_CD_TIME, timeData: {} }, storeBindings: { store: timStore, fields: ['sdkReady', 'groupReady', "messageList", "handReply"], actions: ['login', 'setUser', 'logout'] }, observers: { groupId: async function (newV, oldV) { if (newV) { log.info('live-reply groupId:', this.data.groupId); log.info('newV ', newV); log.info('oldV ', oldV); await this.setUser(this.data.user, this.data.groupId, this.data.userSig); await this.login() } }, handReply: async function (newV) { const countDown = this.selectComponent('.control-count-down'); countDown && countDown.reset(); this.finished() }, }, attached() { wx.hideShareMenu(); }, methods: { async reLogin(e) { try{ await this.logout(); } catch(err) { console.log('logout error', err); } await this.setUser(this.data.user, this.data.groupId, this.data.userSig); await this.login() }, changeMessage(e) { this.setData({ message: getEventParam(e) }) }, reply:throttle(function (e){ this.triggerEvent("message", {msg: this.data.message}); }), handClick:throttle(function (e){ if (this.data.handing) { return } this.setData({ handing: true, }) this.triggerEvent("hand"); }), clear() { this.setData({ message: "" }) }, finished(noTip) { this.setData({ handing: false, }) if (noTip) { toast("举手暂无应答,请稍后重试") } }, onChange(e) { this.setData({ timeData: getEventParam(e), }); }, onFocus(e) { const keyboradHeight = getEventParam(e, "height"); this.setData({ top: keyboradHeight }) }, onBlur() { this.setData({ top: 0 }) }, } });