index.tsx 6.2 KB

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