look-model.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { defineComponent } from "vue";
  2. import { ElButton } from 'element-plus'
  3. import runtime, * as RuntimeUtils from '/src/components/live-broadcast/runtime'
  4. import styles from './index.module.less'
  5. import event, { LIVE_EVENT_MESSAGE } from '/src/components/live-broadcast/event';
  6. import { state } from '/src/state'
  7. import dayjs from 'dayjs';
  8. import Empty from "/src/components/empty";
  9. import runtimeModel, * as RuntimeModelUtils from '/src/components/live-message/model/runtime'
  10. import request from "/src/helpers/request";
  11. export default defineComponent({
  12. data() {
  13. return {
  14. lookList: [] as any[], // 观看学生列表
  15. loadingLook: false, // 观看列表状态
  16. }
  17. },
  18. mounted() {
  19. // this._init()
  20. this.loadingLook = true
  21. event.on(LIVE_EVENT_MESSAGE["RC:Chatroom:Welcome"], this.onWelcome);
  22. event.on(LIVE_EVENT_MESSAGE['RM:RTC:SwitchRole'], this.onSwitchRole);
  23. setTimeout(() => {
  24. this.loadingLook = false;
  25. })
  26. },
  27. methods: {
  28. async _init() {
  29. try {
  30. const roomUid = sessionStorage.getItem('roomUid')
  31. const res = await request.get(`/api-web/imLiveBroadcastRoom/queryRoomUserInfo`, {
  32. params: {
  33. roomUid: roomUid,
  34. }
  35. })
  36. console.log('_init', res)
  37. } catch {
  38. //
  39. }
  40. },
  41. onWelcome(value: any) {
  42. console.log(value)
  43. if (value && value.user) {
  44. const sendTime = dayjs(value.$EventMessage.sentTime || new Date()).format('HH:mm:ss')
  45. let tempObj = {
  46. name: value.user.name,
  47. id: value.user.id,
  48. sendTime
  49. }
  50. // 判断是否有同一个人
  51. let isExist = false;
  52. runtimeModel.lookList.forEach((item: any) => {
  53. if (item.id === tempObj.id) {
  54. isExist = true
  55. }
  56. })
  57. if (!isExist) {
  58. RuntimeModelUtils.addLook(tempObj);
  59. }
  60. this.loadingLook = false
  61. }
  62. },
  63. async onUpLook(item: any) {
  64. try {
  65. // RC:Chatroom:SeatResponse type teacherName teacherId audienceName audienceId
  66. // 操作类型 1 主讲人同意 2 主讲人拒绝 3 观众同意 4 观众拒绝
  67. // RC:Chatroom:SeatApply type teacherName teacherId audienceName audienceId
  68. // 操作类型 1 主讲人邀请 2 主讲人取消邀请 3 观众申请 4 观众取消申请 5将麦上观众踢下麦
  69. const data = {
  70. audienceName: item.name,
  71. audienceId: item.id,
  72. teacherId: state.user?.id,
  73. teacherName: state.user?.speakerName,
  74. type: 1
  75. }
  76. await RuntimeUtils.sendMessage(data, 'SeatApply')
  77. } catch {
  78. //
  79. }
  80. },
  81. async onDownLook(item: any) {
  82. try {
  83. const data = {
  84. ...item,
  85. audienceName: item.name,
  86. audienceId: item.id,
  87. teacherId: state.user?.id,
  88. teacherName: state.user?.speakerName,
  89. type: 5,
  90. }
  91. RuntimeModelUtils.addJoin(item.id, data)
  92. RuntimeUtils.sendMessage(data, 'SeatApply')
  93. } catch {
  94. }
  95. },
  96. onSwitchRole(evt: any) {
  97. console.log(evt, 'onSwitchRole look-modal')
  98. if (evt.role === 2) {
  99. runtimeModel.lookList.forEach((item: any) => {
  100. if(item.id == evt.userId) {
  101. item.type = 1
  102. }
  103. })
  104. this.$forceUpdate()
  105. }
  106. }
  107. },
  108. render() {
  109. return (
  110. <div>
  111. {runtimeModel.lookList.length > 0 ? runtimeModel.lookList.map((item : any) => (
  112. <div class={styles.itemContent}>
  113. <div class={styles.itemInfo} >
  114. <div class={styles.itemName}>
  115. <p class={styles.userName}>{item.name}</p>
  116. {item.type !== 1 ? <ElButton size="small" type="primary" class={styles.btn} onClick={() => this.onUpLook(item)}>上麦</ElButton> : <ElButton size="small" plain class={[styles.btn, styles.downBtn]} onClick={() => this.onDownLook(item)}>下麦</ElButton>}
  117. </div>
  118. </div>
  119. </div>
  120. )) : this.loadingLook ? <div class={styles.loadingStyle} ><div class="el-loading-mask" style="background-color: rgba(0, 0, 0, 0.8);"><div class="el-loading-spinner"><svg class="circular" viewBox="25 25 50 50"><circle class="path" cx="50" cy="50" r="20" fill="none"></circle></svg></div></div></div> : <Empty style={{ paddingTop: '120px' }} text="暂无学员观看!" icon="noData-no-user" />}
  121. </div>
  122. )
  123. }
  124. })