look-model.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. loadingLook: false, // 观看列表状态
  15. }
  16. },
  17. computed: {
  18. count() {
  19. let count = 0
  20. for (const key in runtimeModel.joinList) {
  21. if (Object.prototype.hasOwnProperty.call(runtimeModel.joinList, key)) {
  22. const item = runtimeModel.joinList[key];
  23. if (item.type === 3) {
  24. count += 1
  25. }
  26. if (count > 3) {
  27. break
  28. }
  29. }
  30. }
  31. return count
  32. },
  33. },
  34. async mounted() {
  35. await this._init()
  36. this.loadingLook = true
  37. event.on(LIVE_EVENT_MESSAGE["RC:Chatroom:Welcome"], this.onWelcome);
  38. setTimeout(() => {
  39. this.loadingLook = false;
  40. })
  41. },
  42. methods: {
  43. async _init() {
  44. try {
  45. const roomUid = sessionStorage.getItem('roomUid')
  46. const res = await request.get(`/api-web/imLiveBroadcastRoom/queryRoomUserInfo`, {
  47. params: {
  48. roomUid: roomUid,
  49. }
  50. })
  51. const resList = res.data
  52. resList.forEach((item: any) => {
  53. // 判断是已经,存在学生
  54. if(!runtimeModel.lookList[item.userId]) {
  55. runtimeModel.lookList[item.userId] = {
  56. id: item.userId,
  57. name: item.userName,
  58. type: 3,
  59. userRoomType: 1,
  60. time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  61. }
  62. }
  63. })
  64. } catch {
  65. //
  66. }
  67. },
  68. onWelcome(value: any) {
  69. // console.log(value)
  70. if (value && value.user) {
  71. const sendTime = dayjs(value.$EventMessage.sentTime || new Date()).format('HH:mm:ss')
  72. let tempObj = {
  73. name: value.user.name,
  74. id: value.user.id,
  75. sendTime,
  76. userRoomType: 1,
  77. type: 3
  78. }
  79. // 判断是否有同一个人
  80. let isExist = runtimeModel.lookList[tempObj.id] ? true : false;
  81. if (!isExist) {
  82. RuntimeModelUtils.addLook(tempObj.id, tempObj);
  83. }
  84. this.loadingLook = false
  85. }
  86. },
  87. async onUpLook(item: any) {
  88. try {
  89. // RC:Chatroom:SeatResponse type teacherName teacherId audienceName audienceId
  90. // 操作类型 1 主讲人同意 2 主讲人拒绝 3 观众同意 4 观众拒绝
  91. // RC:Chatroom:SeatApply type teacherName teacherId audienceName audienceId
  92. // 操作类型 1 主讲人邀请 2 主讲人取消邀请 3 观众申请 4 观众取消申请 5将麦上观众踢下麦
  93. // userRoomType
  94. // 1 普通
  95. // 2 老师邀请
  96. // 3 学生申请
  97. // 4 连麦中
  98. const data = {
  99. audienceName: item.name,
  100. audienceId: item.id,
  101. teacherId: state.user?.id,
  102. teacherName: state.user?.speakerName,
  103. userRoomType: 2,
  104. type: 1
  105. }
  106. await RuntimeUtils.sendMessage(data, 'SeatApply')
  107. } catch {
  108. //
  109. }
  110. },
  111. async onDownLook(item: any) {
  112. try {
  113. const data = {
  114. ...item,
  115. audienceName: item.name,
  116. audienceId: item.id,
  117. teacherId: state.user?.id,
  118. teacherName: state.user?.speakerName,
  119. type: 5,
  120. }
  121. RuntimeModelUtils.addJoin(item.id, data)
  122. RuntimeUtils.sendMessage(data, 'SeatApply')
  123. } catch {
  124. }
  125. },
  126. },
  127. render() {
  128. const list = Object.values(runtimeModel.lookList)
  129. return (
  130. <div>
  131. {list.length > 0 ? list.map((item : any) => (
  132. <div class={styles.itemContent}>
  133. <div class={styles.itemInfo} >
  134. <div class={styles.itemName}>
  135. <p class={styles.userName}>
  136. <span class={styles['name-style']}>{item.name}</span>
  137. </p>
  138. {item.userRoomType !== 4 ? <ElButton size="small" type="primary" disabled={this.count > 3} class={styles.btn} onClick={() => this.onUpLook(item)}>上麦</ElButton> : <ElButton size="small" plain class={[styles.btn, styles.downBtn]} onClick={() => this.onDownLook(item)}>下麦</ElButton>}
  139. </div>
  140. </div>
  141. </div>
  142. )) : 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" />}
  143. </div>
  144. )
  145. }
  146. })