index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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="50">
  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: true,
  37. checkStatus: 0, // 0没有权限,1有权限
  38. checkMsg: '',
  39. goodsStatus: 0, // 0未上架,1上架
  40. };
  41. },
  42. onShareAppMessage() {
  43. let item = this.paramObj
  44. let moduleId = item.moduleId || 0
  45. let chapterId = item.chapterId || 0
  46. let sectionId = item.sectionId
  47. let uuid = new Date().valueOf() + ""
  48. // buyCourse 是否购买课程:1是 0否
  49. let encode = encodeURIComponent(WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+'&channelId='
  50. +item.liveUrl+'&gradeId='+0+'&courseId='+item.courseId+'&goodsId='+item.goodsId+'&orderGoodsId='+item.orderGoodsId+'&sectionId='+sectionId+'&chapterId='
  51. +chapterId+'&moduleId='+moduleId+'&buyCourse='+item.buyCourse+'&ident='+uuid)
  52. return {
  53. title: '直播',
  54. path: `/pages/webview/index?url=` + encode
  55. };
  56. },
  57. onLoad(option) {
  58. console.log('--option-', option)
  59. this.options = option
  60. },
  61. onShow() {
  62. if (this.$method.isGoLogin()) { // 扫二维码进来的没登录需要跳到登录页,登录后返回
  63. return;
  64. }
  65. this.optObj = {}
  66. let arrs = decodeURIComponent(this.options.scene).split('&')
  67. for (let i = 0; i < arrs.length; i++) {
  68. this.optObj[arrs[i].split('=')[0]] = arrs[i].split('=')[1]
  69. }
  70. console.log('this.optObj', this.optObj)
  71. // 有a字段是标识是扫二维码进来的
  72. if (this.optObj.a == 1) {
  73. this.getParam()
  74. } else {
  75. this.url = decodeURIComponent(decodeURIComponent(this.options.url))
  76. console.log('小程序进来的url:', this.url)
  77. let index = this.url.indexOf('?')
  78. let paramArr = this.url.slice(index + 1).split('&')
  79. let paramObj = {}
  80. for (let i = 0; i < paramArr.length; i++) {
  81. paramObj[paramArr[i].split('=')[0]] = paramArr[i].split('=')[1]
  82. }
  83. this.paramObj = paramObj
  84. console.log('paramObj', paramObj)
  85. this.studyLog(paramObj)
  86. }
  87. },
  88. computed: {
  89. ...mapGetters(['userInfo']),
  90. },
  91. methods: {
  92. // 获取直播间跳转参数的接口
  93. getParam() {
  94. const { cid, gid, sid} = this.optObj
  95. this.$http({
  96. url: '/course/check/watch/per',
  97. method: 'get',
  98. data: {
  99. courseId: cid, //课程ID
  100. goodsId: gid, // 商品id
  101. sectionId: sid, // 节id
  102. },
  103. }).then((res) => {
  104. if (res.data.code == 200) {
  105. let item = res.data.data
  106. this.paramObj = item
  107. this.goodsId = item.goodsId
  108. this.goodsStatus = item.goodsStatus
  109. if (item.checkStatus == 1) { // 有权限
  110. let moduleId = item.moduleId || 0
  111. let chapterId = item.chapterId || 0
  112. let sectionId = item.sectionId
  113. let uuid = new Date().valueOf() + ""
  114. // buyCourse 是否购买课程:1是 0否
  115. this.url = WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+'&channelId='
  116. +item.channelId+'&gradeId='+0+'&courseId='+item.courseId+'&goodsId='+item.goodsId+'&orderGoodsId='+item.orderGoodsId+'&sectionId='+sectionId
  117. +'&chapterId='+chapterId+'&moduleId='+moduleId+'&buyCourse='+item.buyCourse+'&ident='+uuid
  118. console.log('url:', this.url)
  119. this.studyLog(item)
  120. } else {
  121. this.url = ''
  122. }
  123. } else {
  124. this.$u.toast(res.data.msg)
  125. }
  126. })
  127. },
  128. // 新增用户视频学习日志
  129. studyLog(item) {
  130. this.$http({
  131. url: '/user/study/log',
  132. method: 'post',
  133. data: {
  134. goodsId: item.goodsId,
  135. courseId: item.courseId,
  136. moduleId: item.moduleId || 0,
  137. chapterId: item.chapterId || 0,
  138. sectionId: item.sectionId || 0,
  139. fromPlat: 1, //来源平台 1小程序 2PC网站
  140. goodsType: 6, // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  141. orderGoodsId: item.orderGoodsId,
  142. }
  143. }).then((res) => {
  144. console.log('直播的用户学习日志:', res)
  145. })
  146. },
  147. toAuth() {
  148. if (this.goodsStatus == 1) { //已上架
  149. uni.navigateTo({
  150. url:'/pages3/course/detail?id='+this.goodsId
  151. })
  152. } else {
  153. uni.switchTab({
  154. url:'/pages/index/index'
  155. })
  156. }
  157. },
  158. },
  159. };
  160. </script>
  161. <style lang="scss" scoped>
  162. .popCentent {
  163. width: 600rpx;
  164. height: 300rpx;
  165. padding: 24rpx;
  166. text-align: center;
  167. display: flex;
  168. flex-direction: column;
  169. align-items: center;
  170. justify-content: space-between;
  171. .btns {
  172. width: 500rpx;
  173. height: 80rpx;
  174. line-height: 80rpx;
  175. text-align: center;
  176. background-color: #3577E8;
  177. color: #fff;
  178. font-size: 24rpx;
  179. border-radius: 20rpx;
  180. }
  181. }
  182. </style>