index.vue 7.3 KB

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