index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. this.$store.state.userInfo = null;
  100. return Promise.resolve();
  101. } else {
  102. return Promise.reject("请求错误");
  103. }
  104. },
  105. getInfo() {
  106. // /app/user/getInfo 登录用户信息 // fromPlat来源平台 1小程序 2PC网站
  107. this.$api.getInfo({ fromPlat: 1 }).then((res) => {
  108. if (res.data.code == 200) {
  109. this.$store.state.userInfo = res.data.data;
  110. this.getParam();
  111. }
  112. });
  113. },
  114. // 获取直播间跳转参数的接口
  115. getParam() {
  116. const { cid, gid, sid } = this.optObj;
  117. this.$http({
  118. url: "/course/check/watch/per",
  119. method: "get",
  120. data: {
  121. courseId: cid, //课程ID
  122. goodsId: gid, // 商品id
  123. sectionId: sid, // 节id
  124. },
  125. }).then((res) => {
  126. if (res.data.code == 200) {
  127. let item = res.data.data;
  128. this.paramObj = item;
  129. this.goodsId = item.goodsId;
  130. this.goodsStatus = item.goodsStatus;
  131. this.sectionType = item.sectionType;
  132. this.vid = item.recordingUrl || "";
  133. if (item.checkStatus == 1) {
  134. // 有权限
  135. let moduleId = item.moduleId || 0;
  136. let chapterId = item.chapterId || 0;
  137. let sectionId = item.sectionId;
  138. let uuid = new Date().valueOf() + "";
  139. // buyCourse 是否购买课程:1是 0否
  140. this.url =
  141. this.config.hostLive +
  142. "/pages/live/index?token=" +
  143. uni.getStorageSync("token") +
  144. "&userInfo=" +
  145. JSON.stringify(this.userInfo) +
  146. "&channelId=" +
  147. item.channelId +
  148. "&gradeId=" +
  149. 0 +
  150. "&courseId=" +
  151. item.courseId +
  152. "&goodsId=" +
  153. item.goodsId +
  154. "&orderGoodsId=" +
  155. item.orderGoodsId +
  156. "&sectionId=" +
  157. sectionId +
  158. "&chapterId=" +
  159. chapterId +
  160. "&moduleId=" +
  161. moduleId +
  162. "&buyCourse=" +
  163. item.buyCourse +
  164. "&ident=" +
  165. uuid +
  166. "&sectionType=" +
  167. this.sectionType +
  168. "&vid=" +
  169. this.vid +
  170. "&tid=" +
  171. tenantId;
  172. this.studyLog(item);
  173. } else {
  174. // 没有权限
  175. this.url = "";
  176. this.showAuth = true;
  177. }
  178. } else {
  179. this.$u.toast(res.data.msg);
  180. uni.switchTab({
  181. url: "/pages/index/index",
  182. });
  183. }
  184. });
  185. },
  186. // 新增用户视频学习日志
  187. studyLog(item) {
  188. this.$http({
  189. url: "/user/study/log",
  190. method: "post",
  191. data: {
  192. goodsId: item.goodsId,
  193. courseId: item.courseId,
  194. moduleId: item.moduleId || 0,
  195. chapterId: item.chapterId || 0,
  196. sectionId: item.sectionId || 0,
  197. fromPlat: 1, //来源平台 1小程序 2PC网站
  198. goodsType: 6, // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  199. orderGoodsId: item.orderGoodsId,
  200. },
  201. }).then((res) => {
  202. console.log("直播的用户学习日志:", res);
  203. });
  204. },
  205. toAuth() {
  206. if (this.goodsStatus == 1) {
  207. //已上架
  208. uni.navigateTo({
  209. url: "/pages3/course/detail?id=" + this.goodsId + "&goodsType=6",
  210. });
  211. } else {
  212. uni.switchTab({
  213. url: "/pages/index/index",
  214. });
  215. }
  216. },
  217. },
  218. };
  219. </script>
  220. <style lang="scss" scoped>
  221. .popCentent {
  222. width: 600rpx;
  223. height: 300rpx;
  224. padding: 24rpx;
  225. text-align: center;
  226. display: flex;
  227. flex-direction: column;
  228. align-items: center;
  229. justify-content: space-between;
  230. .btns {
  231. width: 500rpx;
  232. height: 80rpx;
  233. line-height: 80rpx;
  234. text-align: center;
  235. background-color: #3577e8;
  236. color: #fff;
  237. font-size: 24rpx;
  238. border-radius: 20rpx;
  239. }
  240. }
  241. </style>