task_info.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <!-- +---------------------------------------------------------------------- -->
  2. <!-- | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -->
  3. <!-- +---------------------------------------------------------------------- -->
  4. <!-- | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -->
  5. <!-- +---------------------------------------------------------------------- -->
  6. <!-- | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -->
  7. <!-- +---------------------------------------------------------------------- -->
  8. <!-- | Author: CRMEB Team <admin@crmeb.com> -->
  9. <!-- +---------------------------------------------------------------------- -->
  10. {extend name="public/container"}
  11. {block name="title"}课程详情{/block}
  12. {block name="head_top"}
  13. <style>
  14. .prism-player .prism-info-display {
  15. box-sizing: border-box;
  16. }
  17. .prism-player .prism-big-play-btn {
  18. bottom: 50% !important;
  19. left: 50% !important;
  20. z-index: 54 !important;
  21. transform: translate(-50%, 50%);
  22. }
  23. </style>
  24. {/block}
  25. {block name="content"}
  26. <div v-cloak id="app">
  27. <div class="taskinfo">
  28. <!-- 视频窗口 -->
  29. <div :style="{ height: playerHeight + 'px' }" class="player">
  30. <div :hidden="taskInfo.type == 2" id="J_prismPlayer"></div>
  31. <img v-if="taskInfo.type == 2 || (!taskInfo.videoId && !taskInfo.link)" :src="taskInfo.image">
  32. </div>
  33. <div class="title">
  34. <div>{{ taskInfo.title }}</div>
  35. <div>已播放{{ taskInfo.play_count }}次</div>
  36. </div>
  37. <!-- 音频播放 -->
  38. <div v-if="taskInfo.type == 2 && !(!taskInfo.videoId && !taskInfo.link)" class="audio">
  39. <div class="progress">
  40. <div class="time">{{ currentTime | format(duration) }}</div>
  41. <div class="bar" @click="audioSeek">
  42. <div :style="{ width: audioRange + '%' }" class="range">
  43. <div class="dot" @touchmove="audioMove" @touchend="audioMoveEnd"></div>
  44. </div>
  45. </div>
  46. <div class="time">{{ duration | format }}</div>
  47. </div>
  48. <div class="control">
  49. <button class="iconfont iconleft" type="button" @click="audioTab(0)"></button>
  50. <button type="button" @click="audioPlay">
  51. <svg class="icon" aria-hidden="true">
  52. <use :xlink:href="audioPaused ? '#iconbofang1' : '#iconzanting'"></use>
  53. </svg>
  54. </button>
  55. <button class="iconfont iconright" type="button" @click="audioTab(1)"></button>
  56. </div>
  57. </div>
  58. <!-- 目录、详情 -->
  59. <div class="tabbar">
  60. <div :class="{ on: tabIndex == 0 }" @click="tabIndex = 0">目录</div>
  61. <div :class="{ on: tabIndex == 1 }" @click="tabIndex = 1">详情</div>
  62. </div>
  63. <div v-show="tabIndex == 0">
  64. <ul class="catalogue">
  65. <li v-for="(item, index) in taskList" :key="item.id" :class="{ on: item.id == taskId }" @click="playTask(item)">
  66. <div>
  67. <img v-if="item.type == 1" class="img" src="{__WAP_PATH}zsff/images/media1.png">
  68. <img v-else-if="item.type == 2" class="img" src="{__WAP_PATH}zsff/images/media2.png">
  69. <img v-else-if="item.type == 3" class="img" src="{__WAP_PATH}zsff/images/media3.png">
  70. </div>
  71. <div class="text">
  72. <div class="title">{{ index >= 9 ? index + 1 : '0' + (index + 1) }} | {{ item.title }}</div>
  73. <div class="try-progress">
  74. <div v-if="item.watch && item.watch.percentage" class="progress">已学习{{ item.watch.percentage }}%</div>
  75. <div v-else class="progress no">未学习</div>
  76. </div>
  77. </div>
  78. <div class="status">
  79. <i v-if="item.is_free" :class="[item.pay_status ? 'iconsuozi' : 'iconziyuan2', 'iconfont']"></i>
  80. <span v-else class="free">免费</span>
  81. </div>
  82. </li>
  83. </ul>
  84. </div>
  85. <div v-show="tabIndex == 1" class="content" v-html="taskInfo.content"></div>
  86. </div>
  87. <pay-dialog :open.sync="payDialogOpen" :money="isMember ? specialInfo.member_money : specialInfo.money" :now_money="now_money" :special_id="specialId" :pay_type_num="2"
  88. :is-wechat="isWechat" :is-alipay="is_alipay" :is-balance="is_yue" :template-id="templateIds" :wxpay-h5="wxpayH5" :is-member="isMember"
  89. :member-money="specialInfo.member_money" :member-link="memberLink" @change="changeVal"></pay-dialog>
  90. </div>
  91. {/block}
  92. {block name="foot"}
  93. <script>
  94. window.overallShare = false;
  95. require([
  96. 'vue',
  97. 'helper',
  98. 'store',
  99. 'moment',
  100. 'components/pay-dialog/index',
  101. 'layer',
  102. 'aliplayer'
  103. ], function (Vue, $h, store, moment, PayDialog) {
  104. var specialId = {$specialId};
  105. var taskId = {$task_id};
  106. var now_money = {$now_money};
  107. var isWechat = {$isWechat? 'true': 'false'};
  108. var is_alipay = {$is_alipay? 'true': 'false'};
  109. var is_yue = {$is_yue? 'true': 'false'};
  110. var wxpayH5 = {$is_h5_wechat_payment_switch? 'true': 'false'};
  111. var memberLink = "{:url('special/member_recharge')}";
  112. new Vue({
  113. el: '#app',
  114. filters: {
  115. format: function (time, sibling) {
  116. var duration = moment.duration(time * 1000);
  117. var hours = duration.hours();
  118. var siblingHours = sibling ? moment.duration(sibling * 1000).hours() : 0;
  119. return moment({
  120. h: hours,
  121. m: duration.minutes(),
  122. s: duration.seconds()
  123. }).format((hours || siblingHours ? 'HH:' : '') + 'mm:ss');
  124. }
  125. },
  126. components: {
  127. 'pay-dialog': PayDialog
  128. },
  129. data: {
  130. specialId: specialId,
  131. taskId: taskId,
  132. now_money: now_money,
  133. isWechat: isWechat,
  134. is_alipay: is_alipay,
  135. is_yue: is_yue,
  136. templateIds: '',
  137. wxpayH5: wxpayH5,
  138. memberLink: memberLink,
  139. playerHeight: 0,
  140. isPay: false,
  141. isSourcePay: false,
  142. isMember: 0,
  143. linkUrl: '',
  144. specialInfo: {},
  145. taskInfo: {
  146. play_count: 0
  147. },
  148. taskList: [],
  149. tabIndex: 0,
  150. duration: 0,
  151. currentTime: 0,
  152. audioRange: 0,
  153. audioPaused: true,
  154. page: 1,
  155. limit: 10,
  156. loading: false,
  157. finished: false,
  158. player: null,
  159. viewing_time: 0,
  160. player: null,
  161. payDialogOpen: false
  162. },
  163. computed: {
  164. },
  165. created: function () {
  166. this.viewing_time = $h.getParmas('viewing_time') / 1e3;
  167. this.currentTime = Math.floor(this.viewing_time);
  168. this.playerHeight = Math.floor(window.innerWidth * 9 / 16);
  169. this.getTaskList();
  170. },
  171. mounted: function () {
  172. this.$nextTick(function () {
  173. var vm = this;
  174. this.getTaskInfo();
  175. $h.EventUtil.listenTouchDirection(document, function () {
  176. vm.getTaskList();
  177. });
  178. });
  179. },
  180. methods: {
  181. // 获取播放信息
  182. getTaskInfo: function () {
  183. var vm = this;
  184. store.basePost($h.U({
  185. c: 'special',
  186. a: 'getTaskInfo'
  187. }), {
  188. special_id: specialId,
  189. task_id: this.taskId
  190. }, function (res) {
  191. var data = res.data.data;
  192. vm.isPay = data.isPay;
  193. vm.isSourcePay = data.isSourcePay;
  194. vm.isSourcePay = data.isSourcePay;
  195. vm.isMember = data.is_member;
  196. vm.linkUrl = data.link_url;
  197. vm.specialInfo = data.specialInfo;
  198. vm.taskInfo = data.taskInfo;
  199. if (vm.taskInfo.videoId) {
  200. vm.getPlayAuth();
  201. } else if (vm.taskInfo.link) {
  202. vm.createPlayer();
  203. }
  204. if (isWechat) {
  205. mapleWx($jssdk(), function () {
  206. this.onMenuShareAll({
  207. title: vm.taskInfo.title,
  208. desc: vm.taskInfo.title,
  209. imgUrl: vm.taskInfo.image,
  210. link: data.link_url
  211. });
  212. });
  213. }
  214. });
  215. },
  216. // 获取palyauth
  217. getPlayAuth: function () {
  218. var vm = this;
  219. store.baseGet($h.U({
  220. c: 'special',
  221. a: 'get_video_playback_credentials',
  222. q: {
  223. videoId: vm.taskInfo.videoId,
  224. type: 2
  225. }
  226. }), function (res) {
  227. var request = new XMLHttpRequest();
  228. request.onreadystatechange = function () {
  229. if (request.readyState === 4) {
  230. try {
  231. var data = JSON.parse(request.responseText);
  232. if (request.status === 200) {
  233. vm.duration = data.VideoMeta.Duration;
  234. vm.createPlayer(data.PlayAuth);
  235. } else {
  236. layer.msg(data.Message);
  237. }
  238. } catch (error) {
  239. layer.msg(error);
  240. }
  241. }
  242. };
  243. request.open('GET', res.data.msg);
  244. request.send();
  245. }, undefined);
  246. },
  247. // 创建播放器
  248. createPlayer: function (playauth) {
  249. var vm = this;
  250. if (this.player) {
  251. this.player.dispose();
  252. this.player = null;
  253. this.audioPaused = true;
  254. }
  255. this.player = new Aliplayer({
  256. id: 'J_prismPlayer',
  257. height: '100%',
  258. source: vm.taskInfo.link,
  259. vid: vm.taskInfo.videoId,
  260. playauth: playauth || '',
  261. cover: vm.taskInfo.type == 3 ? vm.taskInfo.image : '',
  262. autoplay: true,
  263. // isLive:true,
  264. format: vm.taskInfo.type == 2 ? 'mp3' : '',
  265. controlBarVisibility: 'click', //never
  266. showBarTime: 3e3
  267. });
  268. vm.player.on('ready', vm.handleReady);
  269. vm.player.on('canplaythrough', vm.onPlayerCanplaythrough);
  270. vm.player.on('ended', vm.handleEnded);
  271. vm.player.on('timeupdate', vm.handleTimeupdate);
  272. document.addEventListener('WeixinJSBridgeReady',() => {
  273. if (vm.player.tag) vm.player.tag.play();
  274. })
  275. // 进度条拖拽开始,不可以前进,可以后退
  276. let start = true;
  277. let startProgress = 0;
  278. let endProgress = 0;
  279. vm.player.on('startSeek', (e) => {
  280. if(start){
  281. start = false;
  282. startProgress = vm.player.getCurrentTime();
  283. //console.log('startSeek', startProgress);
  284. }
  285. vm.player.pause();
  286. });
  287. //阿里播放器拖动【结束】拖动时,不可以前进,可以后退
  288. vm.player.on('completeSeek', (e) => {
  289. start = true;
  290. endProgress = vm.player.getCurrentTime();
  291. //console.log('endProgress', endProgress);
  292. if (endProgress < startProgress) {
  293. //console.log('endProgress1', endProgress);
  294. vm.player.seek(endProgress);
  295. } else {
  296. //console.log('endProgress2', endProgress);
  297. vm.player.seek(startProgress);
  298. }
  299. vm.player.play();
  300. });
  301. },
  302. handleReady: function () {
  303. var vm = this;
  304. if (this.taskInfo.link) {
  305. this.duration = this.player.getDuration();
  306. }
  307. if (!this.isPay && !this.isSourcePay) {
  308. this.player.setPreviewTime(this.taskInfo.try_time * 60);
  309. }
  310. },
  311. // 初始播放位置
  312. onPlayerCanplaythrough: function () {
  313. var vm = this;
  314. if (!this.isPay && !this.isSourcePay) {
  315. return;
  316. }
  317. if (!vm.seeked) {
  318. vm.seeked = true;
  319. vm.player.seek(vm.viewing_time);
  320. }
  321. },
  322. handleTimeupdate: function () {
  323. this.currentTime = this.player.getCurrentTime();
  324. if (this.taskInfo.type === 2) {
  325. this.setAudioRange();
  326. }
  327. if (!this.isPay && !this.isSourcePay) {
  328. return;
  329. }
  330. var floorTime = Math.floor(this.currentTime);
  331. if (floorTime && floorTime !== this.floorTime && !(floorTime % 10)) {
  332. this.floorTime = floorTime;
  333. this.setViewing();
  334. }
  335. },
  336. // 播放结束
  337. handleEnded: function () {
  338. var vm = this;
  339. if (vm.taskInfo.type == 2) {
  340. vm.audioPaused = !vm.audioPaused;
  341. }
  342. if (!this.isPay && !this.isSourcePay) {
  343. layer.confirm('购买后可' + (this.taskInfo.type === 2 ? '听' : '看') + '全部内容,是否购买?', {
  344. title: false,
  345. closeBtn: false,
  346. btn: ['购买', '取消']
  347. }, function (index) {
  348. vm.payDialogOpen = true;
  349. layer.close(index);
  350. });
  351. }
  352. },
  353. // 获取专栏列表
  354. getTaskList: function () {
  355. var vm = this;
  356. if (vm.finished) {
  357. return;
  358. }
  359. store.baseGet($h.U({
  360. c: 'special',
  361. a: 'get_course_list',
  362. q: {
  363. special_id: specialId,
  364. page: vm.page,
  365. limit: vm.limit
  366. }
  367. }), function (res) {
  368. var data = res.data.data;
  369. var list = Array.isArray(data) ? [] : data.list;
  370. vm.taskList = vm.taskList.concat(list);
  371. vm.finished = vm.limit > list.length;
  372. if (!vm.finished) {
  373. vm.page++;
  374. }
  375. }, function () {
  376. });
  377. },
  378. // 点击目录
  379. playTask: function (item) {
  380. var vm = this;
  381. if (item.id == vm.taskId) {
  382. return;
  383. }
  384. if (!this.isPay && item.pay_status && !item.is_try) {
  385. layer.confirm('购买后可' + (item.type === 2 ? '听' : '看') + '全部内容,是否购买?', {
  386. title: false,
  387. closeBtn: false,
  388. btn: ['购买', '取消']
  389. }, function (index) {
  390. vm.payDialogOpen = true;
  391. layer.close(index);
  392. });
  393. return;
  394. }
  395. vm.taskId = item.id;
  396. vm.viewing_time = item.watch && item.watch.viewing_time / 1e3 || 0;
  397. vm.currentTime = Math.floor(vm.viewing_time);
  398. vm.seeked = false;
  399. vm.getTaskInfo();
  400. },
  401. // 更新播放进度
  402. setViewing: function () {
  403. store.basePost($h.U({
  404. c: 'special',
  405. a: 'viewing'
  406. }), {
  407. special_id: specialId,
  408. task_id: this.taskId,
  409. total: this.duration * 1000,
  410. viewing_time: this.currentTime * 1000,
  411. percentage: Math.floor(this.currentTime / this.duration * 100)
  412. }, false, false, true);
  413. },
  414. // 播放/暂停音频
  415. audioPlay: function () {
  416. this.audioPaused = !this.audioPaused;
  417. this.audioPaused ? this.player.pause() : this.player.play();
  418. },
  419. // 设置音频进度
  420. setAudioRange: function () {
  421. this.audioRange = Math.floor(this.currentTime / this.duration * 100);
  422. },
  423. // 跳到音频的新位置
  424. audioSeek: function (event) {
  425. var target = event.target;
  426. var classList = target.classList;
  427. var range;
  428. if (classList.contains('dot')) {
  429. return;
  430. } else if (classList.contains('range')) {
  431. range = event.offsetX / target.parentNode.clientWidth;
  432. } else {
  433. range = event.offsetX / target.clientWidth;
  434. }
  435. this.audioRange = range * 100;
  436. this.currentTime = this.duration * range;
  437. this.player.seek(this.currentTime);
  438. },
  439. // 上一个音频/下一个音频
  440. audioTab: function (state) {
  441. if (this.player.getStatus() === 'playing') {
  442. this.audioPaused = true;
  443. this.player.pause();
  444. }
  445. var index = 0;
  446. for (var i = this.taskList.length; i--;) {
  447. if (this.taskList[i].id === this.taskId) {
  448. index = i;
  449. break;
  450. }
  451. }
  452. if (index === this.taskList.length - 1 && state) {
  453. return $h.pushMsg('已经是最后一个');
  454. }
  455. if (!index && !state) {
  456. return $h.pushMsg('已经是第一个');
  457. }
  458. var task = state ? this.taskList[index + 1] : this.taskList[index - 1];
  459. if (task.pay_status) {
  460. return $h.pushMsg('请先去购买');
  461. }
  462. this.playTask(task);
  463. },
  464. // 滑动音频
  465. audioMove: function (event) {
  466. if (this.player.getStatus() === 'playing') {
  467. this.audioPaused = true;
  468. this.player.pause();
  469. }
  470. var parentNode = event.target.parentNode.parentNode;
  471. var range = Math.floor((event.touches[0].pageX - parentNode.offsetLeft) / parentNode.clientWidth * 100);
  472. if (range > 100) {
  473. range = 100;
  474. }
  475. this.audioRange = range;
  476. },
  477. // 滑动音频停止
  478. audioMoveEnd: function () {
  479. this.player.seek(this.duration * this.audioRange / 100);
  480. if (this.player.getStatus() === 'pause') {
  481. this.audioPaused = false;
  482. this.player.play();
  483. }
  484. },
  485. changeVal: function (opt) {
  486. if (typeof opt !== 'object') {
  487. opt = {};
  488. }
  489. var action = opt.action || '';
  490. var value = opt.value || '';
  491. this[action] && this[action](value);
  492. },
  493. // 支付方式回调
  494. pay_order: function (data) {
  495. this.orderId = data.data.result.orderId || '';
  496. switch (data.data.status) {
  497. case "PAY_ERROR":
  498. case 'ORDER_EXIST':
  499. case 'ORDER_ERROR':
  500. this.extendOrder(data.msg);
  501. break;
  502. case 'WECHAT_PAY':
  503. this.wechatPay(data.data.result.jsConfig);
  504. break;
  505. case 'WECHAT_H5_PAY':
  506. this.payDialogOpen = false;
  507. var callbackUrl = callback_url + '?type=7&id=' + this.special.id;
  508. var mwebUrl = data.data.result.jsConfig.mweb_url + '&redirect_url=' + encodeURIComponent(callbackUrl);
  509. window.location.assign(mwebUrl);
  510. break;
  511. case 'SUCCESS':
  512. this.successOrder(data.msg);
  513. break;
  514. case 'ZHIFUBAO_PAY':
  515. window.location.assign($h.U({
  516. c: 'alipay',
  517. a: 'index',
  518. q: {
  519. info: data.data.result,
  520. params: 'special'
  521. }
  522. }));
  523. break;
  524. }
  525. },
  526. // 微信支付
  527. wechatPay: function (config) {
  528. var vm = this;
  529. mapleWx($jssdk(), function () {
  530. this.chooseWXPay(config, function () {
  531. vm.successOrder();
  532. }, {
  533. fail: vm.extendOrder,
  534. cancel: vm.extendOrder
  535. });
  536. });
  537. },
  538. // 支付成功
  539. successOrder: function (msg) {
  540. var that = this;
  541. $h.showMsg({
  542. title: msg || '支付成功',
  543. icon: 'success',
  544. success: function () {
  545. window.location.reload();
  546. that.payDialogOpen = false;
  547. that.getTaskInfo();
  548. that.finished = false;
  549. that.page = 1;
  550. that.taskList = [];
  551. that.getTaskList();
  552. }
  553. });
  554. },
  555. // 支付未完成
  556. extendOrder: function (msg) {
  557. var that = this;
  558. if (typeof msg === 'object') {
  559. if (msg.errMsg === 'chooseWXPay:cancel') {
  560. msg = '微信支付取消';
  561. } else {
  562. msg = '支付失败';
  563. }
  564. } else {
  565. msg = '支付失败';
  566. }
  567. $h.pushMsg(msg, function () {
  568. that.payDialogOpen = false;
  569. if (that.orderId) {
  570. store.baseGet($h.U({
  571. c: 'special',
  572. a: 'del_order',
  573. q: {
  574. orderId: that.orderId
  575. }
  576. }));
  577. }
  578. });
  579. },
  580. }
  581. });
  582. });
  583. </script>
  584. {/block}