index.vue 3.4 KB

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