index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="webview">
  3. <template v-if="url">
  4. <web-view :webview-styles="webviewStyles" :src="url"></web-view>
  5. </template>
  6. <u-popup v-model="showAuth" mode="center" border-radius="30">
  7. <view class="popCentent">
  8. <view class="tips">您还没有开通直播课程,无法观看</view>
  9. <view class="btns" @click="toAuth()">立即开通</view>
  10. </view>
  11. </u-popup>
  12. </view>
  13. </template>
  14. <script>
  15. import { WEBVIEW_URL } from '@/common/request.js'
  16. import { mapGetters } from 'vuex'
  17. export default {
  18. components: {},
  19. data() {
  20. return {
  21. url: "",
  22. webviewStyles: {
  23. progress: {
  24. color: "#007AFF",
  25. },
  26. },
  27. options: {},
  28. optObj: {},
  29. goodsId: 0,
  30. chapterId: 0,
  31. moduleId: 0,
  32. courseId: 0,
  33. sectionId: 0,
  34. orderGoodsId: 0,
  35. paramObj: {},
  36. showAuth: false,
  37. checkStatus: 0, // 0没有权限,1有权限
  38. goodsStatus: 0, // 0未上架,1上架
  39. sectionType: 2, // 2直播
  40. vid: '', // 回放id
  41. };
  42. },
  43. // onShareAppMessage() {
  44. // let item = this.paramObj
  45. // let moduleId = item.moduleId || 0
  46. // let chapterId = item.chapterId || 0
  47. // let sectionId = item.sectionId
  48. // let uuid = new Date().valueOf() + ""
  49. // // buyCourse 是否购买课程:1是 0否
  50. // let encode = encodeURIComponent(WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+'&channelId='
  51. // +item.channelId+'&gradeId='+0+'&courseId='+item.courseId+'&goodsId='+item.goodsId+'&orderGoodsId='+item.orderGoodsId+'&sectionId='+sectionId+'&chapterId='
  52. // +chapterId+'&moduleId='+moduleId+'&buyCourse='+item.buyCourse+'&ident='+uuid+'&sectionType='+this.sectionType+'&vid='+this.vid)
  53. // return {
  54. // title: '直播',
  55. // path: `/pages/webview/index?url=` + encode
  56. // };
  57. // },
  58. onLoad(option) {
  59. console.log('--option-', option)
  60. this.options = option
  61. console.log('userInfo:', this.userInfo)
  62. },
  63. onShow() {
  64. console.log('22222222222222')
  65. if (this.$method.isGoLogin()) { // 扫二维码进来的没登录需要跳到登录页,登录后返回
  66. return;
  67. }
  68. console.log('33333333333333')
  69. if (this.options.scene) {
  70. this.optObj = {}
  71. let arrs = decodeURIComponent(this.options.scene).split('&')
  72. for (let i = 0; i < arrs.length; i++) {
  73. this.optObj[arrs[i].split('=')[0]] = arrs[i].split('=')[1]
  74. }
  75. console.log('this.optObj', this.optObj)
  76. }
  77. // 有a字段是标识是扫二维码进来的
  78. if (this.optObj.a == 1) {
  79. if (!this.userInfo) {
  80. console.log('没有userInfo')
  81. this.getInfo()
  82. } else {
  83. console.log('有userInfo')
  84. this.getParam()
  85. }
  86. } else {
  87. this.url = decodeURIComponent(decodeURIComponent(this.options.url))
  88. console.log('小程序进来的url:', this.url)
  89. let index = this.url.indexOf('?')
  90. let paramArr = this.url.slice(index + 1).split('&')
  91. let paramObj = {}
  92. for (let i = 0; i < paramArr.length; i++) {
  93. paramObj[paramArr[i].split('=')[0]] = paramArr[i].split('=')[1]
  94. }
  95. this.paramObj = paramObj
  96. this.sectionType = this.paramObj.sectionType || 2 // 默认直播,回放的加了sectionType=3
  97. this.vid = this.paramObj.vid || ''
  98. console.log('paramObj', paramObj)
  99. this.studyLog(paramObj)
  100. }
  101. },
  102. computed: {
  103. ...mapGetters(['userInfo']),
  104. },
  105. methods: {
  106. getInfo() {
  107. // /app/user/getInfo 登录用户信息 // fromPlat来源平台 1小程序 2PC网站
  108. this.$api.getInfo({ fromPlat: 1 }).then(res => {
  109. if(res.data.code == 200){
  110. this.$store.state.userInfo = res.data.data
  111. console.log('this.userInfo', this.userInfo)
  112. this.getParam()
  113. }
  114. })
  115. },
  116. // 获取直播间跳转参数的接口
  117. getParam() {
  118. const { cid, gid, sid} = this.optObj
  119. this.$http({
  120. url: '/course/check/watch/per',
  121. method: 'get',
  122. data: {
  123. courseId: cid, //课程ID
  124. goodsId: gid, // 商品id
  125. sectionId: sid, // 节id
  126. },
  127. }).then((res) => {
  128. if (res.data.code == 200) {
  129. let item = res.data.data
  130. this.paramObj = item
  131. this.goodsId = item.goodsId
  132. this.goodsStatus = item.goodsStatus
  133. this.sectionType = item.sectionType
  134. this.vid = item.recordingUrl || ''
  135. if (item.checkStatus == 1) { // 有权限
  136. let moduleId = item.moduleId || 0
  137. let chapterId = item.chapterId || 0
  138. let sectionId = item.sectionId
  139. let uuid = new Date().valueOf() + ""
  140. // buyCourse 是否购买课程:1是 0否
  141. this.url = WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+'&channelId='
  142. +item.channelId+'&gradeId='+0+'&courseId='+item.courseId+'&goodsId='+item.goodsId+'&orderGoodsId='+item.orderGoodsId+'&sectionId='+sectionId
  143. +'&chapterId='+chapterId+'&moduleId='+moduleId+'&buyCourse='+item.buyCourse+'&ident='+uuid+'&sectionType='+ this.sectionType+'&vid='+this.vid
  144. console.log('url:', this.url)
  145. this.studyLog(item)
  146. } else {
  147. // 没有权限
  148. this.url = ''
  149. this.showAuth = true
  150. }
  151. } else {
  152. this.$u.toast(res.data.msg)
  153. uni.switchTab({
  154. url:'/pages/index/index'
  155. })
  156. }
  157. })
  158. },
  159. // 新增用户视频学习日志
  160. studyLog(item) {
  161. this.$http({
  162. url: '/user/study/log',
  163. method: 'post',
  164. data: {
  165. goodsId: item.goodsId,
  166. courseId: item.courseId,
  167. moduleId: item.moduleId || 0,
  168. chapterId: item.chapterId || 0,
  169. sectionId: item.sectionId || 0,
  170. fromPlat: 1, //来源平台 1小程序 2PC网站
  171. goodsType: 6, // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  172. orderGoodsId: item.orderGoodsId,
  173. }
  174. }).then((res) => {
  175. console.log('直播的用户学习日志:', res)
  176. })
  177. },
  178. toAuth() {
  179. if (this.goodsStatus == 1) { //已上架
  180. uni.navigateTo({
  181. url:'/pages3/course/detail?id='+this.goodsId + '&goodsType=6'
  182. })
  183. } else {
  184. uni.switchTab({
  185. url:'/pages/index/index'
  186. })
  187. }
  188. },
  189. },
  190. };
  191. </script>
  192. <style lang="scss" scoped>
  193. .popCentent {
  194. width: 600rpx;
  195. height: 300rpx;
  196. padding: 24rpx;
  197. text-align: center;
  198. display: flex;
  199. flex-direction: column;
  200. align-items: center;
  201. justify-content: space-between;
  202. .btns {
  203. width: 500rpx;
  204. height: 80rpx;
  205. line-height: 80rpx;
  206. text-align: center;
  207. background-color: #3577E8;
  208. color: #fff;
  209. font-size: 24rpx;
  210. border-radius: 20rpx;
  211. }
  212. }
  213. </style>