index.vue 6.3 KB

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