import popup from "$utils/tool/popup"; import {PopupExportComponent} from "$popup/popup-export/const"; import user from '$config/user'; import {RowWheat} from '../const'; import {InstructionsMessageType} from "$utils/request"; export default { data(){ return { // 当前进行排麦的状态 wheat_status: RowWheat.none } }, provide(){ return { openUserInfo:(event,userInfo)=> this.openUserInfo(event,userInfo), applyForWheat:(index:number|undefined)=> this.applyForWheat(index), exitForWheat:()=> this.exitForWheat(), cancelForWheat:()=> this.cancelForWheat() } }, methods:{ // 打开用户信息 openUserInfo(event,userInfo){ popup.$popup.open(PopupExportComponent.user,{ el:event, value:true, item:userInfo }); }, // 申请上麦 applyForWheat(index:number|undefined){ if (this.wheat_status === RowWheat.queuing) { return popup.$toast('正在排麦中'); } else if (!this.applyForWheatStatus) { // 如果为管理员触发 if (this.isAdmin) { return popup.$confirm({ title: this.wheat_status === RowWheat.none ? '是否上麦?' :'是否切换麦位?', successAsyncText:'上麦成功', confirm:()=>{ index = typeof index === 'number' ? index : this.getMicroIndex(); if (index != null) { return new Promise( (resolve, reject)=> { return this.$request({ url:'room/user_up_micro', data:{ rid: this.$params.rid, micro_id:typeof index === 'number'?index:'' }, token:true, failMessage:true, next:({status})=> this.applyForWheatStatus = status, message: InstructionsMessageType.other }).then((data)=>{ if (data.isSuccess) { this.downMicro({ index, user:user.user }); return resolve(true); } else { resolve(false); } }).catch(reject); }); } else { return popup.$toast('暂无可用麦位'); } } }); } else { if (this.hostMicroIsHave) { return popup.$confirm({ title: '是否申请上麦?', successAsyncText:'申请成功', confirm:()=>{ return new Promise( (resolve, reject)=> { return this.$request({ url:'room/enter_room_mc_queue', data:{ rid: this.$params.rid }, token:true, failMessage:true, next:({status})=> this.applyForWheatStatus = status, message: InstructionsMessageType.other }).then((data)=>{ if (data.isSuccess) { // 设置状态为排麦中 this.setMicroStatus(RowWheat.queuing); return resolve(true); } else { resolve(false); } }).catch(reject); }); } }); } else { return popup.$toast('主持麦位暂无用户'); } } } }, // 下麦 exitForWheat(){ if (this.hasMicroInfo(user.uid())) { if (this.wheat_status === RowWheat.wheat && !this.exitForWheatStatus) { return popup.$confirm({ title:'是否执行下麦操作?', successAsyncText:'下麦成功', confirm:()=>{ return new Promise((resolve, reject)=>{ this.$request({ url: this.isHostMicro ? 'room/host_down_micro' :'room/user_down_micro', data:{ rid: this.$params.rid }, token:true, failMessage:true, next:({status})=> this.exitForWheatStatus = status, message: InstructionsMessageType.other }).then((data)=>{ if (data.isSuccess) { this.upMicro({ uid:user.uid() }); resolve(true); } else { resolve(false); } }).catch(reject); }) } }) } } }, // 取消排麦 cancelForWheat(){ if (this.wheat_status === RowWheat.queuing && !this.cancelForWheatStatus) { popup.$confirm({ title: '是否取消排麦?', successAsyncText: '取消成功', confirm:()=>{ return new Promise((resolve, reject)=>{ return this.$request({ url:'room/quit_room_mc_queue', data:{ rid: this.$params.rid }, token:true, failMessage:true, next:({status})=> this.cancelForWheatStatus = status, message: InstructionsMessageType.other }).then((data)=>{ if (data.isSuccess) { this.setMicroStatus(RowWheat.none); return resolve(true); } else { resolve(false); } }).catch(reject); }); } }); } } } }