index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import ColSticky from '@/components/col-sticky'
  2. import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
  3. import request from '@/helpers/request'
  4. import { browser } from '@/helpers/utils'
  5. import { state } from '@/state'
  6. import { Button, Dialog, Toast } from 'vant'
  7. import { defineComponent } from 'vue'
  8. import styles from './index.module.less'
  9. import iconDefault from '@/common/images/icon_teacher.png'
  10. export const getAssetsHomeFile = (fileName: string) => {
  11. const path = `./images/${fileName}`
  12. const modules = import.meta.globEager('./images/*')
  13. return modules[path].default
  14. }
  15. export default defineComponent({
  16. name: 'shareLiveRoom',
  17. data() {
  18. return {
  19. query: {
  20. ...this.$route.query
  21. // id: 'COOLESHOW-TEMP-416-1663833046284',
  22. // userId: 416
  23. },
  24. liveRoom: {} as any, //直播间信息
  25. teacher: {} as any,
  26. student: {} as any, // 分享人信息
  27. wxStatus: false
  28. }
  29. },
  30. async mounted() {
  31. await this.getData()
  32. this.openApp()
  33. },
  34. methods: {
  35. // 获取直播信息和分享人信息
  36. async getData() {
  37. try {
  38. const { data } = await request.get(
  39. `/api-student/open/liveRoom/detail/${this.query.id}`,
  40. {
  41. params: {
  42. userId: this.query.userId
  43. }
  44. }
  45. )
  46. this.liveRoom = data
  47. this.teacher = data.teacher || {}
  48. this.student = data.student || {}
  49. } catch {}
  50. },
  51. // 分享进入
  52. openApp() {
  53. if (browser().weixin) {
  54. // 微信浏览器
  55. this.wxStatus = true
  56. return
  57. }
  58. if (!browser().isApp) {
  59. // 不是APP
  60. this.onWakeApp()
  61. return
  62. }
  63. if (browser().isApp) {
  64. if (state.platformType === 'STUDENT') {
  65. this.onJoinLiveRoom()
  66. } else if (state.platformType === 'TEACHER') {
  67. Dialog.alert({
  68. title: '提示',
  69. message: '请使用酷乐秀学生端扫码打开',
  70. confirmButtonColor: '#2dc7aa'
  71. }).then(() => {
  72. postMessage({ api: 'back' })
  73. })
  74. }
  75. }
  76. },
  77. //进入直播间
  78. onJoinLiveRoom() {
  79. postMessage({
  80. api: 'joinLiveRoom',
  81. content: {
  82. roomId: this.liveRoom.roomUid,
  83. teacherId: this.liveRoom.speakerId
  84. }
  85. })
  86. },
  87. // 唤醒APP
  88. onWakeApp() {
  89. const query = {
  90. action: 'app', // app, h5
  91. pageTag: 'liveRoom', // 页面标识
  92. params: JSON.stringify({ liveRoomId: this.query.id })
  93. }
  94. const iosStr = encodeURIComponent(JSON.stringify(query))
  95. if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  96. // ColexiuStudent 唤起学生端
  97. // ColexiuTeacher 唤起老师端
  98. window.location.href = `ColexiuStudent://linkUrl=${iosStr}`
  99. } else if (/(Android)/i.test(navigator.userAgent)) {
  100. window.location.href = `colexiustudent://html:8888/SplashActivity?url=${iosStr}`
  101. } else {
  102. Toast('请用手机或移动设备打开')
  103. }
  104. }
  105. },
  106. render() {
  107. return (
  108. <div class={styles.container}>
  109. <div class={styles.wrap}>
  110. <div class={styles.userWrap}>
  111. <div class={styles.user}>
  112. <div class={styles.avator}>
  113. <img src={this.teacher.avatar || iconDefault} />
  114. </div>
  115. <div class={styles.tips}>
  116. <img src={getAssetsHomeFile('icon-live.png')} />
  117. <span>直播中</span>
  118. </div>
  119. </div>
  120. </div>
  121. <div class={styles.titleWrap}>
  122. <div class={styles.title}>{this.liveRoom.roomTitle}</div>
  123. <div class={styles.liveUser}>
  124. 主讲人:{this.teacher.realName || this.teacher.username}
  125. </div>
  126. </div>
  127. <div class={styles.content}>
  128. <div class={styles.top}>直播内容</div>
  129. <div>{this.liveRoom.liveRemark}</div>
  130. <div class={styles.comentWrap}>
  131. <div class={styles.contentAvator}>
  132. <img src={this.student.avatar || iconDefault} />
  133. </div>
  134. <div>
  135. <div class={styles.comentTitle}>
  136. 快进入老师的直播间一起围观~
  137. </div>
  138. <div class={styles.comentDes}>
  139. {this.teacher.realName || this.student.username} 为您推荐
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. <ColSticky position="bottom">
  146. <div class={['btnGroup']} style={{ paddingTop: '12px' }}>
  147. <Button
  148. color="linear-gradient(180deg, #59E5D5 0%, #2DC7AA 100%)"
  149. block
  150. round
  151. type="primary"
  152. onClick={this.openApp}
  153. >
  154. 开启酷乐秀进入直播间!
  155. </Button>
  156. </div>
  157. </ColSticky>
  158. {this.wxStatus && (
  159. <div
  160. class={styles.wxpopup}
  161. onClick={() => {
  162. this.wxStatus = false
  163. }}
  164. >
  165. <img src={getAssetsHomeFile('wx_bg.png')} alt="" />
  166. </div>
  167. )}
  168. </div>
  169. )
  170. }
  171. })