index.tsx 6.1 KB

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