control.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import popup from "$utils/tool/popup";
  2. import {PopupExportComponent} from "$popup/popup-export/const";
  3. import user from '$config/user';
  4. import {RowWheat} from '../const';
  5. import {InstructionsMessageType} from "$utils/request";
  6. export default <LibMixins>{
  7. data(){
  8. return {
  9. // 当前进行排麦的状态
  10. wheat_status: RowWheat.none
  11. }
  12. },
  13. provide(){
  14. return {
  15. openUserInfo:(event,userInfo)=> this.openUserInfo(event,userInfo),
  16. applyForWheat:(index:number|undefined)=> this.applyForWheat(index),
  17. exitForWheat:()=> this.exitForWheat(),
  18. cancelForWheat:()=> this.cancelForWheat()
  19. }
  20. },
  21. methods:{
  22. // 打开用户信息
  23. openUserInfo(event,userInfo){
  24. popup.$popup.open(PopupExportComponent.user,{
  25. el:event,
  26. value:true,
  27. item:userInfo
  28. });
  29. },
  30. // 申请上麦
  31. applyForWheat(index:number|undefined){
  32. if (this.wheat_status === RowWheat.queuing) {
  33. return popup.$toast('正在排麦中');
  34. } else if (!this.applyForWheatStatus) {
  35. // 如果为管理员触发
  36. if (this.isAdmin) {
  37. return popup.$confirm({
  38. title: this.wheat_status === RowWheat.none ? '是否上麦?' :'是否切换麦位?',
  39. successAsyncText:'上麦成功',
  40. confirm:()=>{
  41. index = typeof index === 'number' ? index : this.getMicroIndex();
  42. if (index != null) {
  43. return new Promise<boolean>( (resolve, reject)=> {
  44. return this.$request({
  45. url:'room/user_up_micro',
  46. data:{
  47. rid: this.$params.rid,
  48. micro_id:typeof index === 'number'?index:''
  49. },
  50. token:true,
  51. failMessage:true,
  52. next:({status})=> this.applyForWheatStatus = status,
  53. message: InstructionsMessageType.other
  54. }).then((data)=>{
  55. if (data.isSuccess) {
  56. this.downMicro({
  57. index,
  58. user:user.user
  59. });
  60. return resolve(true);
  61. } else {
  62. resolve(false);
  63. }
  64. }).catch(reject);
  65. });
  66. } else {
  67. return popup.$toast('暂无可用麦位');
  68. }
  69. }
  70. });
  71. } else {
  72. if (this.hostMicroIsHave) {
  73. return popup.$confirm({
  74. title: '是否申请上麦?',
  75. successAsyncText:'申请成功',
  76. confirm:()=>{
  77. return new Promise<boolean>( (resolve, reject)=> {
  78. return this.$request({
  79. url:'room/enter_room_mc_queue',
  80. data:{
  81. rid: this.$params.rid
  82. },
  83. token:true,
  84. failMessage:true,
  85. next:({status})=> this.applyForWheatStatus = status,
  86. message: InstructionsMessageType.other
  87. }).then((data)=>{
  88. if (data.isSuccess) {
  89. // 设置状态为排麦中
  90. this.setMicroStatus(RowWheat.queuing);
  91. return resolve(true);
  92. } else {
  93. resolve(false);
  94. }
  95. }).catch(reject);
  96. });
  97. }
  98. });
  99. } else {
  100. return popup.$toast('主持麦位暂无用户');
  101. }
  102. }
  103. }
  104. },
  105. // 下麦
  106. exitForWheat(){
  107. if (this.hasMicroInfo(user.uid())) {
  108. if (this.wheat_status === RowWheat.wheat && !this.exitForWheatStatus) {
  109. return popup.$confirm({
  110. title:'是否执行下麦操作?',
  111. successAsyncText:'下麦成功',
  112. confirm:()=>{
  113. return new Promise<boolean>((resolve, reject)=>{
  114. this.$request({
  115. url: this.isHostMicro ? 'room/host_down_micro' :'room/user_down_micro',
  116. data:{
  117. rid: this.$params.rid
  118. },
  119. token:true,
  120. failMessage:true,
  121. next:({status})=> this.exitForWheatStatus = status,
  122. message: InstructionsMessageType.other
  123. }).then((data)=>{
  124. if (data.isSuccess) {
  125. this.upMicro({
  126. uid:user.uid()
  127. });
  128. resolve(true);
  129. } else {
  130. resolve(false);
  131. }
  132. }).catch(reject);
  133. })
  134. }
  135. })
  136. }
  137. }
  138. },
  139. // 取消排麦
  140. cancelForWheat(){
  141. if (this.wheat_status === RowWheat.queuing && !this.cancelForWheatStatus) {
  142. popup.$confirm({
  143. title: '是否取消排麦?',
  144. successAsyncText: '取消成功',
  145. confirm:()=>{
  146. return new Promise((resolve, reject)=>{
  147. return this.$request({
  148. url:'room/quit_room_mc_queue',
  149. data:{
  150. rid: this.$params.rid
  151. },
  152. token:true,
  153. failMessage:true,
  154. next:({status})=> this.cancelForWheatStatus = status,
  155. message: InstructionsMessageType.other
  156. }).then((data)=>{
  157. if (data.isSuccess) {
  158. this.setMicroStatus(RowWheat.none);
  159. return resolve(true);
  160. } else {
  161. resolve(false);
  162. }
  163. }).catch(reject);
  164. });
  165. }
  166. });
  167. }
  168. }
  169. }
  170. }