index.vue 7.2 KB

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