index.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import CoursePlanStep from '@/business-components/course-plan-step'
  2. import SectionDetail from '@/business-components/section-detail'
  3. import UserDetail from '@/business-components/user-detail'
  4. import ColSticky from '@/components/col-sticky'
  5. import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
  6. import request from '@/helpers/request'
  7. import { browser } from '@/helpers/utils'
  8. import { state } from '@/state'
  9. import dayjs from 'dayjs'
  10. import { Button, Dialog, Toast } from 'vant'
  11. import { defineComponent } from 'vue'
  12. import { shareCall } from '../share'
  13. import styles from './index.module.less'
  14. import qs from 'query-string'
  15. export const getAssetsHomeFile = (fileName: string) => {
  16. const path = `../images/${fileName}`
  17. const modules = import.meta.globEager('../images/*')
  18. return modules[path].default
  19. }
  20. interface IProps {
  21. courseTime: string
  22. coursePlan: string
  23. videoPosterUrl?: string
  24. roomUid?: string
  25. liveState?: number
  26. id?: number | string
  27. }
  28. export default defineComponent({
  29. name: 'LiveDetail',
  30. data() {
  31. const query = this.$route.query
  32. return {
  33. recomUserId: query.recomUserId, // 分享人编号
  34. groupId: query.groupId,
  35. live: {} as any,
  36. wxStatus: false
  37. }
  38. },
  39. computed: {
  40. userInfo() {
  41. const live = this.live as any
  42. const planList = live.planList || []
  43. const startTime = planList[0]?.startTime || new Date()
  44. const endTime = planList[0]?.endTime || new Date()
  45. return {
  46. headUrl: live.avatar,
  47. username: live.userName,
  48. id: live.teacherId,
  49. startTime:
  50. `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(startTime).format(
  51. 'HH:mm'
  52. )}~${dayjs(endTime).format('HH:mm')}` || '',
  53. lessonPrice: live.coursePrice,
  54. buyNum: live.studentCount || 0,
  55. lessonNum: live.courseNum || 0, // 课时数
  56. lessonDesc: live.courseIntroduce,
  57. lessonCoverUrl: live.backgroundPic || live.backgroundPicTemplate,
  58. lessonName: live.courseGroupName,
  59. auditVersion:0
  60. }
  61. },
  62. courseInfo() {
  63. const tempArr = [] as IProps[]
  64. const coursePlanList = this.live.planList || []
  65. coursePlanList.forEach((item: any) => {
  66. const startTime = item.startTime || new Date()
  67. const endTime = item.endTime || new Date()
  68. tempArr.push({
  69. courseTime: `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(
  70. startTime
  71. ).format('HH:mm')}~${dayjs(endTime).format('HH:mm')}`,
  72. coursePlan: item.plan,
  73. roomUid: item.roomUid,
  74. liveState: item.liveState,
  75. id: item.courseId
  76. })
  77. })
  78. return tempArr || []
  79. }
  80. },
  81. created() {
  82. if (browser().isApp) {
  83. if (state.platformType === 'STUDENT') {
  84. // 自动跳转到学生端视频课详情购买页
  85. if (browser().ios) {
  86. window.location.replace(
  87. `${location.origin}/student/#/liveDetail??${qs.stringify(
  88. this.$route.query
  89. )}`
  90. )
  91. } else {
  92. postMessage({
  93. api: 'openWebView',
  94. content: {
  95. url: `${location.origin}/student/#/liveDetail??${qs.stringify(
  96. this.$route.query
  97. )}`,
  98. orientation: 1,
  99. isHideTitle: false
  100. }
  101. })
  102. postMessage({ api: 'back' })
  103. }
  104. } else if (state.platformType === 'TEACHER') {
  105. Dialog.alert({
  106. title: '提示',
  107. message: '请使用酷乐秀学生端扫码打开',
  108. confirmButtonColor: '#2dc7aa'
  109. }).then(() => {
  110. postMessage({ api: 'back' })
  111. })
  112. }
  113. } else {
  114. // 如果不在app里面则不需要唤起操作
  115. this.reCall()
  116. }
  117. },
  118. async mounted() {
  119. try {
  120. const res = await request.post('/api-teacher/open/liveShareProfit', {
  121. data: {
  122. bizId: this.groupId,
  123. userId: this.recomUserId
  124. }
  125. })
  126. this.live = res.data.liveCourseGroup || {}
  127. } catch {
  128. //
  129. }
  130. },
  131. methods: {
  132. locationReplace(url: string) {
  133. if (history.replaceState) {
  134. history.replaceState(null, document.title, url)
  135. window.location.reload()
  136. } else {
  137. location.replace(url)
  138. }
  139. },
  140. reCall() {
  141. const { origin } = location
  142. let str = origin + '/student/#/liveDetail'
  143. const params = this.$route.query
  144. str += `?recomUserId=${this.recomUserId}&groupId=${params.groupId}`
  145. shareCall(str, {})
  146. },
  147. onShare() {
  148. if (browser().weixin) {
  149. this.wxStatus = true
  150. return
  151. }
  152. this.reCall()
  153. setTimeout(() => {
  154. window.location.href = location.origin + '/student/#/download'
  155. }, 3000)
  156. }
  157. },
  158. render() {
  159. return (
  160. <div class={[styles['live-detail'], 'mb12']}>
  161. <UserDetail userInfo={this.userInfo} showBuy={false} />
  162. <SectionDetail border>
  163. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  164. </SectionDetail>
  165. <SectionDetail
  166. title="课程列表"
  167. icon="courseList"
  168. border
  169. // contentStyle={{ paddingTop: '0' }}
  170. >
  171. <CoursePlanStep courseInfo={this.courseInfo} />
  172. </SectionDetail>
  173. <ColSticky position="bottom">
  174. <div class={['btnGroup']} style={{ paddingTop: '12px' }}>
  175. <Button block round type="primary" onClick={this.onShare}>
  176. 下载酷乐秀进入课程
  177. </Button>
  178. </div>
  179. </ColSticky>
  180. {this.wxStatus && (
  181. <div
  182. class={styles.wxpopup}
  183. onClick={() => {
  184. this.wxStatus = false
  185. }}
  186. >
  187. <img src={getAssetsHomeFile('wx_bg.png')} alt="" />
  188. </div>
  189. )}
  190. </div>
  191. )
  192. }
  193. })