join-model.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { defineComponent } from "vue";
  2. import styles from './index.module.less'
  3. import { ElButton } from'element-plus'
  4. import event, { LIVE_EVENT_MESSAGE } from '/src/components/live-broadcast/event';
  5. import { state } from '/src/state'
  6. import dayjs from 'dayjs';
  7. import Empty from "/src/components/empty";
  8. import runtime, * as RuntimeUtils from '/src/components/live-broadcast/runtime'
  9. export default defineComponent({
  10. props: {
  11. data: {
  12. type: Array,
  13. default: () => ([])
  14. }
  15. },
  16. data() {
  17. return {
  18. joinList: {} as {[key: string]: any}, // 连麦学生列表
  19. loadingJoin: false, // 连麦列表状态
  20. }
  21. },
  22. computed: {
  23. count() {
  24. let count = 0
  25. for (const key in this.joinList) {
  26. if (Object.prototype.hasOwnProperty.call(this.joinList, key)) {
  27. const item = this.joinList[key];
  28. if (item.type === 3) {
  29. count += 1
  30. }
  31. if (count > 3) {
  32. break
  33. }
  34. }
  35. }
  36. return count
  37. },
  38. },
  39. mounted() {
  40. event.on(LIVE_EVENT_MESSAGE['RC:Chatroom:SeatApply'], this.onSeatApply);
  41. event.on(LIVE_EVENT_MESSAGE['RM:RTC:SwitchRole'], this.onSwitchRole);
  42. },
  43. methods: {
  44. onSeatApply(evt: any) {
  45. if (evt.type === 3) {
  46. this.joinList[evt.audienceId] = {
  47. name: evt.audienceName,
  48. id: evt.audienceId,
  49. type: evt.type,
  50. }
  51. }
  52. },
  53. agree(item: any) {
  54. if (this.count > 3) {
  55. return
  56. }
  57. const data = {
  58. ...item,
  59. audienceName: item.name,
  60. audienceId: item.id,
  61. teacherId: state.user?.id,
  62. teacherName: state.user?.realName,
  63. type: 1,
  64. }
  65. this.joinList[item.id] = data
  66. RuntimeUtils.sendMessage(data, 'SeatResponse')
  67. },
  68. refuse() {
  69. },
  70. onSwitchRole(evt: any) {
  71. if (this.joinList[evt.userId] && evt.role === 2) {
  72. delete this.joinList[evt.userId]
  73. }
  74. }
  75. },
  76. render() {
  77. const list = Object.values(this.joinList)
  78. return (
  79. <div style={{ minHeight: '100%', position: 'relative' }}>
  80. {list.length > 0 ? list.map((item : any) => (
  81. <div class={styles.itemContent}>
  82. <img src="/src/assets/home/placehorder-icon.png" alt="" />
  83. <div class={styles.itemInfo}>
  84. <div class={styles.itemName}>
  85. <p class={styles.userName}>{item.name}</p>
  86. </div>
  87. {item.type === 3 ? (
  88. <div class={styles.joinText}>
  89. <div class={styles.join}>
  90. 申请连麦
  91. </div>
  92. <ElButton size="small" disabled={this.count > 3} class={styles.btn} onClick={() => this.agree(item)}>上麦</ElButton>
  93. </div>
  94. ) : (
  95. <div class={styles.joinText}>
  96. <div class={styles.join}>
  97. 正在连麦
  98. </div>
  99. <ElButton size="small" class={styles.btn} onClick={this.refuse}>下麦</ElButton>
  100. </div>
  101. )}
  102. </div>
  103. </div>
  104. )) : this.loadingJoin ? <div class={styles.loadingStyle} v-loading={this.loadingJoin} element-loading-background="rgba(0, 0, 0, 0.8)"></div> : <Empty style={{ paddingTop: '120px' }} text="暂无学员发起连麦!" icon="noData-no-join" />}
  105. </div>
  106. )
  107. }
  108. })