index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class="webview">
  3. <web-view :webview-styles="webviewStyles" :src="url"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. import { WEBVIEW_URL } from '@/common/request.js'
  8. import { mapGetters } from 'vuex'
  9. export default {
  10. components: {},
  11. data() {
  12. return {
  13. url: "",
  14. webviewStyles: {
  15. progress: {
  16. color: "#007AFF",
  17. },
  18. },
  19. options: {},
  20. optObj: {},
  21. };
  22. },
  23. onLoad(option) {
  24. this.options = option
  25. },
  26. onShow() {
  27. if (this.$method.isGoLogin()) { // 扫二维码进来的没登录需要跳到登录页,登录后返回
  28. return;
  29. }
  30. this.optObj = {}
  31. let arrs = decodeURIComponent(this.options.scene).split('&')
  32. for (let i = 0; i < arrs.length; i++) {
  33. this.optObj[arrs[i].split('=')[0]] = arrs[i].split('=')[1]
  34. }
  35. console.log('this.optObj', this.optObj)
  36. // 有a字段是标识是扫二维码进来的
  37. if (this.optObj.a == 1) {
  38. this.getParam()
  39. } else {
  40. this.url = decodeURIComponent(this.options.url);
  41. }
  42. },
  43. computed: {
  44. ...mapGetters(['userInfo']),
  45. },
  46. methods: {
  47. // 获取直播间跳转参数的接口
  48. getParam() {
  49. const { cid, gid, sid} = this.optObj
  50. this.$http({
  51. url: '/course/check/watch/per',
  52. method: 'get',
  53. data: {
  54. courseId: cid, //课程ID
  55. goodsId: gid, // 商品id
  56. sectionId: sid, // 节id
  57. },
  58. }).then((res) => {
  59. if (res.data.code == 200) {
  60. let item = res.data.data
  61. let moduleId = item.moduleId || 0
  62. let chapterId = item.chapterId || 0
  63. let sectionId = item.sectionId || item.menuId
  64. let uuid = new Date().valueOf() + ""
  65. // buyCourse 是否购买课程:1是 0否
  66. this.url = WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+'&channelId='
  67. +item.channelId+'&gradeId='+0+'&courseId='+item.courseId+'&goodsId='+item.goodsId+'&orderGoodsId='+item.orderGoodsId+'&sectionId='+sectionId
  68. +'&chapterId='+chapterId+'&moduleId='+moduleId+'&buyCourse='+item.buyCourse+'&ident='+uuid
  69. console.log('url:', this.url)
  70. } else {
  71. this.$u.toast(res.data.msg)
  72. }
  73. })
  74. },
  75. },
  76. };
  77. </script>
  78. <style lang="scss" scoped>
  79. </style>