index.vue 6.3 KB

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