index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. goodsId: 0,
  22. chapterId: 0,
  23. moduleId: 0,
  24. courseId: 0,
  25. sectionId: 0,
  26. orderGoodsId: 0,
  27. };
  28. },
  29. onLoad(option) {
  30. console.log('--option-', option)
  31. this.options = option
  32. },
  33. onShow() {
  34. if (this.$method.isGoLogin()) { // 扫二维码进来的没登录需要跳到登录页,登录后返回
  35. return;
  36. }
  37. this.optObj = {}
  38. let arrs = decodeURIComponent(this.options.scene).split('&')
  39. for (let i = 0; i < arrs.length; i++) {
  40. this.optObj[arrs[i].split('=')[0]] = arrs[i].split('=')[1]
  41. }
  42. console.log('this.optObj', this.optObj)
  43. // 有a字段是标识是扫二维码进来的
  44. if (this.optObj.a == 1) {
  45. this.getParam()
  46. } else {
  47. this.url = decodeURIComponent(this.options.url);
  48. console.log('小程序进来的url:', this.url)
  49. let index = this.options.url.indexOf('?')
  50. let paramArr = this.options.url.slice(index + 1).split('&')
  51. let paramObj = {}
  52. for (let i = 0; i < paramArr.length; i++) {
  53. paramObj[paramArr[i].split('=')[0]] = paramArr[i].split('=')[1]
  54. }
  55. console.log('paramObj', paramObj)
  56. this.studyLog(paramObj)
  57. }
  58. },
  59. computed: {
  60. ...mapGetters(['userInfo']),
  61. },
  62. methods: {
  63. // 获取直播间跳转参数的接口
  64. getParam() {
  65. const { cid, gid, sid} = this.optObj
  66. this.$http({
  67. url: '/course/check/watch/per',
  68. method: 'get',
  69. data: {
  70. courseId: cid, //课程ID
  71. goodsId: gid, // 商品id
  72. sectionId: sid, // 节id
  73. },
  74. }).then((res) => {
  75. if (res.data.code == 200) {
  76. let item = res.data.data
  77. let moduleId = item.moduleId || 0
  78. let chapterId = item.chapterId || 0
  79. let sectionId = item.sectionId
  80. let uuid = new Date().valueOf() + ""
  81. // buyCourse 是否购买课程:1是 0否
  82. this.url = WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+'&channelId='
  83. +item.channelId+'&gradeId='+0+'&courseId='+item.courseId+'&goodsId='+item.goodsId+'&orderGoodsId='+item.orderGoodsId+'&sectionId='+sectionId
  84. +'&chapterId='+chapterId+'&moduleId='+moduleId+'&buyCourse='+item.buyCourse+'&ident='+uuid
  85. console.log('url:', this.url)
  86. this.studyLog(item)
  87. } else {
  88. this.$u.toast(res.data.msg)
  89. }
  90. })
  91. },
  92. // 新增用户视频学习日志
  93. studyLog(item) {
  94. this.$http({
  95. url: '/user/study/log',
  96. method: 'post',
  97. data: {
  98. goodsId: item.goodsId,
  99. courseId: item.courseId,
  100. moduleId: item.moduleId || 0,
  101. chapterId: item.chapterId || 0,
  102. sectionId: item.sectionId || 0,
  103. fromPlat: 1, //来源平台 1小程序 2PC网站
  104. goodsType: 6, // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  105. orderGoodsId: item.orderGoodsId,
  106. }
  107. }).then((res) => {
  108. console.log('直播的用户学习日志:', res)
  109. })
  110. },
  111. },
  112. };
  113. </script>
  114. <style lang="scss" scoped>
  115. </style>