index.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import CourseVideoItem from '@/business-components/course-video-item'
  2. import SectionDetail from '@/business-components/section-detail'
  3. import UserDetail from '@/business-components/user-detail'
  4. import { Button, Dialog, Toast } from 'vant'
  5. import { defineComponent } from 'vue'
  6. import styles from './index.module.less'
  7. import request from '@/helpers/request'
  8. import ColSticky from '@/components/col-sticky'
  9. import { shareCall } from '../share'
  10. import { browser } from '@/helpers/utils'
  11. import { postMessage } from '@/helpers/native-message'
  12. import { state } from '@/state'
  13. import qs from 'query-string'
  14. export const getAssetsHomeFile = (fileName: string) => {
  15. const path = `../images/${fileName}`
  16. const modules = import.meta.globEager('../images/*')
  17. return modules[path].default
  18. }
  19. export default defineComponent({
  20. name: 'VideoDetail',
  21. data() {
  22. const query = this.$route.query
  23. return {
  24. userInfo: {} as any,
  25. detailList: [],
  26. buyUserList: [], // 购买学生数
  27. dataShow: true, // 判断是否有数据
  28. loading: false,
  29. finished: false,
  30. recomUserId: query.recomUserId, // 分享人编号
  31. params: {
  32. videoLessonGroupId: query.groupId,
  33. page: 1,
  34. rows: 20
  35. },
  36. wxStatus: false
  37. }
  38. },
  39. created() {
  40. if (browser().isApp) {
  41. if (state.platformType === 'STUDENT') {
  42. const query = this.$route.query
  43. query.recomUserId =
  44. query.userType && query.userType == 'STUDENT' ? '' : query.recomUserId
  45. // 自动跳转到学生端视频课详情购买页
  46. // 为了处理andoird webview的跳转问题
  47. if (browser().ios) {
  48. window.location.replace(
  49. `${location.origin}/student/#/videoDetail?${qs.stringify(query)}`
  50. )
  51. } else {
  52. postMessage({
  53. api: 'openWebView',
  54. content: {
  55. url: `${location.origin}/student/#/videoDetail?${qs.stringify(
  56. query
  57. )}`,
  58. orientation: 1,
  59. isHideTitle: false
  60. }
  61. })
  62. postMessage({ api: 'back' })
  63. }
  64. return
  65. } else if (state.platformType === 'TEACHER') {
  66. Dialog.alert({
  67. title: '提示',
  68. message: '请使用酷乐秀学生端扫码打开',
  69. confirmButtonColor: '#2dc7aa'
  70. }).then(() => {
  71. postMessage({ api: 'back' })
  72. })
  73. }
  74. } else {
  75. // 如果不在app里面则不需要唤起操作
  76. this.reCall()
  77. }
  78. },
  79. async mounted() {
  80. try {
  81. const res = await request.post(`/api-teacher/open/videoShareProfit`, {
  82. data: {
  83. bizId: this.params.videoLessonGroupId,
  84. userId: this.recomUserId
  85. }
  86. })
  87. const result = res.data || {}
  88. const { lessonGroup, detailList } = result.videoGroup
  89. this.userInfo = {
  90. username: result.name,
  91. headUrl: result.avatar,
  92. buyNum: lessonGroup.countStudent,
  93. lessonNum: lessonGroup.lessonCount,
  94. lessonName: lessonGroup.lessonName,
  95. lessonDesc: lessonGroup.lessonDesc,
  96. lessonPrice: lessonGroup.lessonPrice,
  97. relationType: lessonGroup.relationType,
  98. lessonCoverUrl: lessonGroup.lessonCoverUrl
  99. }
  100. this.detailList = detailList || []
  101. } catch {
  102. //
  103. }
  104. },
  105. methods: {
  106. locationReplace(url: string) {
  107. // alert(url)
  108. if (history.replaceState) {
  109. history.replaceState(null, document.title, url)
  110. window.location.reload()
  111. } else {
  112. location.replace(url)
  113. }
  114. },
  115. reCall() {
  116. const { origin } = location
  117. let str = origin + '/student/#/videoDetail'
  118. const params = this.$route.query
  119. str += `?recomUserId=${
  120. params.userType && params.userType == 'STUDENT' ? '' : this.recomUserId
  121. }&groupId=${params.groupId}`
  122. console.log(str)
  123. shareCall(str, {})
  124. },
  125. onShare() {
  126. if (browser().weixin) {
  127. this.wxStatus = true
  128. return
  129. }
  130. this.reCall()
  131. setTimeout(() => {
  132. window.location.href = location.origin + '/student/#/download'
  133. }, 3000)
  134. }
  135. },
  136. render() {
  137. return (
  138. <div class={[styles['video-detail'], 'mb12']}>
  139. <UserDetail userInfo={this.userInfo} showBuy={false} />
  140. <SectionDetail border>
  141. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  142. </SectionDetail>
  143. <SectionDetail
  144. title="课程列表"
  145. icon="courseList"
  146. contentStyle={{ paddingTop: '0' }}
  147. >
  148. {this.detailList.map((item: any) => (
  149. <CourseVideoItem
  150. class={'mb12'}
  151. detail={{
  152. id: item.id,
  153. title: item.videoTitle,
  154. content: item.videoContent,
  155. imgUrl: item.coverUrl
  156. }}
  157. />
  158. ))}
  159. </SectionDetail>
  160. <ColSticky position="bottom">
  161. <div class={['btnGroup']} style={{ paddingTop: '12px' }}>
  162. <Button block round type="primary" onClick={this.onShare}>
  163. 下载酷乐秀进入课程
  164. </Button>
  165. </div>
  166. </ColSticky>
  167. {this.wxStatus && (
  168. <div
  169. class={styles.wxpopup}
  170. onClick={() => {
  171. this.wxStatus = false
  172. }}
  173. >
  174. <img src={getAssetsHomeFile('wx_bg.png')} alt="" />
  175. </div>
  176. )}
  177. </div>
  178. )
  179. }
  180. })