123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 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 <LibMixins>{
- 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<boolean>( (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<boolean>( (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<boolean>((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);
- });
- }
- });
- }
- }
- }
- }
|