index.vue 6.8 KB

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