index.vue 7.0 KB

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