index.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. // 自动跳转到学生端视频课详情购买页
  43. window.location.replace(
  44. `${location.origin}/student/#/videoDetail?${qs.stringify(
  45. this.$route.query
  46. )}`
  47. )
  48. // 为了处理andoird webview的跳转问题
  49. if (browser().ios) {
  50. window.location.replace(
  51. `${location.origin}/student/#/videoDetail?${qs.stringify(
  52. this.$route.query
  53. )}`
  54. )
  55. } else {
  56. postMessage({
  57. api: 'openWebView',
  58. content: {
  59. url: `${location.origin}/student/#/videoDetail?${qs.stringify(
  60. this.$route.query
  61. )}`,
  62. orientation: 1,
  63. isHideTitle: false
  64. }
  65. })
  66. postMessage({ api: 'back' })
  67. }
  68. // this.locationReplace(
  69. // `${location.origin}/student/#/videoDetail?${qs.stringify(
  70. // this.$route.query
  71. // )}`
  72. // )
  73. return
  74. } else if (state.platformType === 'TEACHER') {
  75. Dialog.alert({
  76. title: '提示',
  77. message: '请使用酷乐秀学生端扫码打开',
  78. confirmButtonColor: '#2dc7aa'
  79. }).then(() => {
  80. postMessage({ api: 'back' })
  81. })
  82. }
  83. } else {
  84. // 如果不在app里面则不需要唤起操作
  85. this.reCall()
  86. }
  87. },
  88. async mounted() {
  89. try {
  90. const res = await request.post(`/api-teacher/open/videoShareProfit`, {
  91. data: {
  92. bizId: this.params.videoLessonGroupId,
  93. userId: this.recomUserId
  94. }
  95. })
  96. const result = res.data || {}
  97. const { lessonGroup, detailList } = result.videoGroup
  98. this.userInfo = {
  99. username: result.name,
  100. headUrl: result.avatar,
  101. buyNum: lessonGroup.countStudent,
  102. lessonNum: lessonGroup.lessonCount,
  103. lessonName: lessonGroup.lessonName,
  104. lessonDesc: lessonGroup.lessonDesc,
  105. lessonPrice: lessonGroup.lessonPrice,
  106. lessonCoverUrl: lessonGroup.lessonCoverUrl
  107. }
  108. this.detailList = detailList || []
  109. } catch {
  110. //
  111. }
  112. },
  113. methods: {
  114. locationReplace(url: string) {
  115. // alert(url)
  116. if (history.replaceState) {
  117. history.replaceState(null, document.title, url)
  118. window.location.reload()
  119. } else {
  120. location.replace(url)
  121. }
  122. },
  123. reCall() {
  124. const { origin } = location
  125. let str = origin + '/student/#/videoDetail'
  126. const params = this.$route.query
  127. str += `?recomUserId=${params.userType && params.userType == 'STUDENT' ? '' : this.recomUserId}&groupId=${params.groupId}`
  128. console.log(str)
  129. shareCall(str, {})
  130. },
  131. onShare() {
  132. if (browser().weixin) {
  133. this.wxStatus = true
  134. return
  135. }
  136. this.reCall()
  137. setTimeout(() => {
  138. window.location.href = location.origin + '/student/#/download'
  139. }, 3000)
  140. }
  141. },
  142. render() {
  143. return (
  144. <div class={[styles['video-detail'], 'mb12']}>
  145. <UserDetail userInfo={this.userInfo} showBuy={false} />
  146. <SectionDetail border>
  147. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  148. </SectionDetail>
  149. <SectionDetail
  150. title="课程列表"
  151. icon="courseList"
  152. contentStyle={{ paddingTop: '0' }}
  153. >
  154. {this.detailList.map((item: any) => (
  155. <CourseVideoItem
  156. class={'mb12'}
  157. detail={{
  158. id: item.id,
  159. title: item.videoTitle,
  160. content: item.videoContent,
  161. imgUrl: item.coverUrl
  162. }}
  163. />
  164. ))}
  165. </SectionDetail>
  166. <ColSticky position="bottom">
  167. <div class={['btnGroup']} style={{ paddingTop: '12px' }}>
  168. <Button block round type="primary" onClick={this.onShare}>
  169. 下载酷乐秀进入课程
  170. </Button>
  171. </div>
  172. </ColSticky>
  173. {this.wxStatus && (
  174. <div
  175. class={styles.wxpopup}
  176. onClick={() => {
  177. this.wxStatus = false
  178. }}
  179. >
  180. <img src={getAssetsHomeFile('wx_bg.png')} alt="" />
  181. </div>
  182. )}
  183. </div>
  184. )
  185. }
  186. })