item-list.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { defineComponent } from "vue";
  2. // import { ElTag, ElIcon, ElButton } from "element-plus";
  3. import styles from './item-list.module.less';
  4. import event, { LIVE_EVENT_MESSAGE } from '/src/components/live-broadcast/event';
  5. import dayjs from 'dayjs';
  6. import Empty from "../empty";
  7. // import VirtualList from 'vue-virtual-scroll-list';
  8. import LookModel from './model/look-model';
  9. import JoinModel from './model/join-model';
  10. import MessageModel from './model/message-model';
  11. import { state } from '/src/state'
  12. type itemType = 'message' | 'join' | 'look'
  13. export default defineComponent({
  14. props: {
  15. type: {
  16. type: String,
  17. default: 'join' as itemType
  18. }
  19. },
  20. data() {
  21. return {
  22. messageList: [] as any[], // 回复学生列表
  23. joinList: [] as any[], // 连麦学生列表
  24. lookList: [] as any[], // 观看学生列表
  25. loadingMessage: false, // 消息列表状态
  26. loadingJoin: false, // 连麦列表状态
  27. loadingLook: false, // 观看列表状态
  28. }
  29. },
  30. mounted() {
  31. this.initStatus()
  32. event.on(LIVE_EVENT_MESSAGE["RC:Chatroom:Welcome"], this.onWelcome);
  33. event.on(LIVE_EVENT_MESSAGE["RC:TxtMsg"], this.onMessage);
  34. //
  35. setTimeout(() => {
  36. console.log('messageList', this.messageList)
  37. if(this.type === 'join') {
  38. this.loadingJoin = false;
  39. } else if(this.type === 'look') {
  40. this.loadingLook = false;
  41. } else if(this.type === 'message') {
  42. this.loadingMessage = false;
  43. }
  44. }, 2000);
  45. },
  46. methods: {
  47. initStatus() {
  48. if(this.type === 'join') {
  49. this.loadingJoin = this.joinList.length > 0 ? false : true;
  50. } else if(this.type === 'look') {
  51. this.loadingLook = this.lookList.length > 0 ? false : true;
  52. } else if(this.type === 'message') {
  53. this.loadingMessage = this.messageList.length > 0 ? false : true;
  54. }
  55. },
  56. onMessage(value: any) {
  57. if (value && value.user) {
  58. console.log(state.user)
  59. console.log(value)
  60. const sendTime = dayjs(value.$EventMessage.sentTime || new Date()).format('HH:mm:ss')
  61. let tempObj = {
  62. name: value.user?.name,
  63. id: value.user.id,
  64. isSelf: false,
  65. content: value.content,
  66. sendTime
  67. }
  68. // 判断是否是主播
  69. if (value.user.id === state.user.id) {
  70. tempObj.isSelf = true
  71. }
  72. this.messageList.push(tempObj);
  73. this.loadingLook = false
  74. }
  75. console.log(this.messageList)
  76. },
  77. onWelcome(value: any) {
  78. console.log(value)
  79. if (value && value.user) {
  80. const sendTime = dayjs(value.$EventMessage.sentTime || new Date()).format('HH:mm:ss')
  81. let tempObj = {
  82. name: value.user.name,
  83. id: value.user.id,
  84. sendTime
  85. }
  86. // 判断是否有同一个人
  87. let isExist = false;
  88. this.lookList.forEach((item: any) => {
  89. if (item.id === tempObj.id) {
  90. isExist = true
  91. }
  92. })
  93. if (!isExist) {
  94. this.lookList.push(tempObj);
  95. }
  96. this.loadingLook = false
  97. }
  98. }
  99. },
  100. beforeUnmount() {
  101. event.off(LIVE_EVENT_MESSAGE["RC:Chatroom:Welcome"], this.onmessage);
  102. event.off(LIVE_EVENT_MESSAGE["RC:TxtMsg"], this.onmessage);
  103. },
  104. render() {
  105. return (
  106. <div style={{ minHeight: '100%', position: 'relative' }}>
  107. {/* {this.type === 'message' ?
  108. this.messageList && this.messageList.length > 0 ? this.messageList.map(item => (
  109. <MessageModel data={this.messageList} />
  110. )) : this.loadingMessage ? <div class={styles.loadingStyle} v-loading={this.loadingMessage} element-loading-background="rgba(0, 0, 0, 0.8)"></div> : <Empty text="暂无学员互动!" icon="noData-no-message" />
  111. : null}
  112. {this.type === 'join' ?
  113. this.joinList && this.joinList.length > 0 ? this.joinList.map(item => (
  114. <JoinModel data={this.joinList} />
  115. )) : this.loadingJoin ? <div class={styles.loadingStyle} v-loading={this.loadingJoin} element-loading-background="rgba(0, 0, 0, 0.8)"></div> : <Empty text="暂无学员发起连麦!" icon="noData-no-join" />
  116. : null}
  117. {this.type === 'look' ?
  118. this.lookList && this.lookList.length > 0 ? this.lookList.map(item => (
  119. <LookModel data={this.lookList} />
  120. )) : this.loadingLook ? <div class={styles.loadingStyle} v-loading={this.loadingLook} element-loading-background="rgba(0, 0, 0, 0.8)"></div> : <Empty text="暂无学员观看!" icon="noData-no-user" />
  121. : null} */}
  122. </div>
  123. )
  124. }
  125. })