task_info.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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. format: vm.taskInfo.type == 2 ? 'mp3' : '',
  264. controlBarVisibility: 'click',
  265. showBarTime: 3e3
  266. });
  267. vm.player.on('ready', vm.handleReady);
  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. },
  273. handleReady: function () {
  274. var vm = this;
  275. if (this.taskInfo.link) {
  276. this.duration = this.player.getDuration();
  277. }
  278. if (!this.isPay && !this.isSourcePay) {
  279. this.player.setPreviewTime(this.taskInfo.try_time * 60);
  280. }
  281. },
  282. // 初始播放位置
  283. onPlayerCanplaythrough: function () {
  284. var vm = this;
  285. if (!this.isPay && !this.isSourcePay) {
  286. return;
  287. }
  288. if (!vm.seeked) {
  289. vm.seeked = true;
  290. vm.player.seek(vm.viewing_time);
  291. }
  292. },
  293. handleTimeupdate: function () {
  294. this.currentTime = this.player.getCurrentTime();
  295. if (this.taskInfo.type === 2) {
  296. this.setAudioRange();
  297. }
  298. if (!this.isPay && !this.isSourcePay) {
  299. return;
  300. }
  301. var floorTime = Math.floor(this.currentTime);
  302. if (floorTime && floorTime !== this.floorTime && !(floorTime % 10)) {
  303. this.floorTime = floorTime;
  304. this.setViewing();
  305. }
  306. },
  307. // 播放结束
  308. handleEnded: function () {
  309. var vm = this;
  310. if (vm.taskInfo.type == 2) {
  311. vm.audioPaused = !vm.audioPaused;
  312. }
  313. if (!this.isPay && !this.isSourcePay) {
  314. layer.confirm('购买后可' + (this.taskInfo.type === 2 ? '听' : '看') + '全部内容,是否购买?', {
  315. title: false,
  316. closeBtn: false,
  317. btn: ['购买', '取消']
  318. }, function (index) {
  319. vm.payDialogOpen = true;
  320. layer.close(index);
  321. });
  322. }
  323. },
  324. // 获取专栏列表
  325. getTaskList: function () {
  326. var vm = this;
  327. if (vm.finished) {
  328. return;
  329. }
  330. store.baseGet($h.U({
  331. c: 'special',
  332. a: 'get_course_list',
  333. q: {
  334. special_id: specialId,
  335. page: vm.page,
  336. limit: vm.limit
  337. }
  338. }), function (res) {
  339. var data = res.data.data;
  340. var list = Array.isArray(data) ? [] : data.list;
  341. vm.taskList = vm.taskList.concat(list);
  342. vm.finished = vm.limit > list.length;
  343. if (!vm.finished) {
  344. vm.page++;
  345. }
  346. }, function () {
  347. });
  348. },
  349. // 点击目录
  350. playTask: function (item) {
  351. var vm = this;
  352. if (item.id == vm.taskId) {
  353. return;
  354. }
  355. if (!this.isPay && item.pay_status && !item.is_try) {
  356. layer.confirm('购买后可' + (item.type === 2 ? '听' : '看') + '全部内容,是否购买?', {
  357. title: false,
  358. closeBtn: false,
  359. btn: ['购买', '取消']
  360. }, function (index) {
  361. vm.payDialogOpen = true;
  362. layer.close(index);
  363. });
  364. return;
  365. }
  366. vm.taskId = item.id;
  367. vm.viewing_time = item.watch && item.watch.viewing_time / 1e3 || 0;
  368. vm.currentTime = Math.floor(vm.viewing_time);
  369. vm.seeked = false;
  370. vm.getTaskInfo();
  371. },
  372. // 更新播放进度
  373. setViewing: function () {
  374. store.basePost($h.U({
  375. c: 'special',
  376. a: 'viewing'
  377. }), {
  378. special_id: specialId,
  379. task_id: this.taskId,
  380. total: this.duration * 1000,
  381. viewing_time: this.currentTime * 1000,
  382. percentage: Math.floor(this.currentTime / this.duration * 100)
  383. }, false, false, true);
  384. },
  385. // 播放/暂停音频
  386. audioPlay: function () {
  387. this.audioPaused = !this.audioPaused;
  388. this.audioPaused ? this.player.pause() : this.player.play();
  389. },
  390. // 设置音频进度
  391. setAudioRange: function () {
  392. this.audioRange = Math.floor(this.currentTime / this.duration * 100);
  393. },
  394. // 跳到音频的新位置
  395. audioSeek: function (event) {
  396. var target = event.target;
  397. var classList = target.classList;
  398. var range;
  399. if (classList.contains('dot')) {
  400. return;
  401. } else if (classList.contains('range')) {
  402. range = event.offsetX / target.parentNode.clientWidth;
  403. } else {
  404. range = event.offsetX / target.clientWidth;
  405. }
  406. this.audioRange = range * 100;
  407. this.currentTime = this.duration * range;
  408. this.player.seek(this.currentTime);
  409. },
  410. // 上一个音频/下一个音频
  411. audioTab: function (state) {
  412. if (this.player.getStatus() === 'playing') {
  413. this.audioPaused = true;
  414. this.player.pause();
  415. }
  416. var index = 0;
  417. for (var i = this.taskList.length; i--;) {
  418. if (this.taskList[i].id === this.taskId) {
  419. index = i;
  420. break;
  421. }
  422. }
  423. if (index === this.taskList.length - 1 && state) {
  424. return $h.pushMsg('已经是最后一个');
  425. }
  426. if (!index && !state) {
  427. return $h.pushMsg('已经是第一个');
  428. }
  429. var task = state ? this.taskList[index + 1] : this.taskList[index - 1];
  430. if (task.pay_status) {
  431. return $h.pushMsg('请先去购买');
  432. }
  433. this.playTask(task);
  434. },
  435. // 滑动音频
  436. audioMove: function (event) {
  437. if (this.player.getStatus() === 'playing') {
  438. this.audioPaused = true;
  439. this.player.pause();
  440. }
  441. var parentNode = event.target.parentNode.parentNode;
  442. var range = Math.floor((event.touches[0].pageX - parentNode.offsetLeft) / parentNode.clientWidth * 100);
  443. if (range > 100) {
  444. range = 100;
  445. }
  446. this.audioRange = range;
  447. },
  448. // 滑动音频停止
  449. audioMoveEnd: function () {
  450. this.player.seek(this.duration * this.audioRange / 100);
  451. if (this.player.getStatus() === 'pause') {
  452. this.audioPaused = false;
  453. this.player.play();
  454. }
  455. },
  456. changeVal: function (opt) {
  457. if (typeof opt !== 'object') {
  458. opt = {};
  459. }
  460. var action = opt.action || '';
  461. var value = opt.value || '';
  462. this[action] && this[action](value);
  463. },
  464. // 支付方式回调
  465. pay_order: function (data) {
  466. this.orderId = data.data.result.orderId || '';
  467. switch (data.data.status) {
  468. case "PAY_ERROR":
  469. case 'ORDER_EXIST':
  470. case 'ORDER_ERROR':
  471. this.extendOrder(data.msg);
  472. break;
  473. case 'WECHAT_PAY':
  474. this.wechatPay(data.data.result.jsConfig);
  475. break;
  476. case 'WECHAT_H5_PAY':
  477. this.payDialogOpen = false;
  478. var callbackUrl = callback_url + '?type=7&id=' + this.special.id;
  479. var mwebUrl = data.data.result.jsConfig.mweb_url + '&redirect_url=' + encodeURIComponent(callbackUrl);
  480. window.location.assign(mwebUrl);
  481. break;
  482. case 'SUCCESS':
  483. this.successOrder(data.msg);
  484. break;
  485. case 'ZHIFUBAO_PAY':
  486. window.location.assign($h.U({
  487. c: 'alipay',
  488. a: 'index',
  489. q: {
  490. info: data.data.result,
  491. params: 'special'
  492. }
  493. }));
  494. break;
  495. }
  496. },
  497. // 微信支付
  498. wechatPay: function (config) {
  499. var vm = this;
  500. mapleWx($jssdk(), function () {
  501. this.chooseWXPay(config, function () {
  502. vm.successOrder();
  503. }, {
  504. fail: vm.extendOrder,
  505. cancel: vm.extendOrder
  506. });
  507. });
  508. },
  509. // 支付成功
  510. successOrder: function (msg) {
  511. var that = this;
  512. $h.showMsg({
  513. title: msg || '支付成功',
  514. icon: 'success',
  515. success: function () {
  516. window.location.reload();
  517. that.payDialogOpen = false;
  518. that.getTaskInfo();
  519. that.finished = false;
  520. that.page = 1;
  521. that.taskList = [];
  522. that.getTaskList();
  523. }
  524. });
  525. },
  526. // 支付未完成
  527. extendOrder: function (msg) {
  528. var that = this;
  529. if (typeof msg === 'object') {
  530. if (msg.errMsg === 'chooseWXPay:cancel') {
  531. msg = '微信支付取消';
  532. } else {
  533. msg = '支付失败';
  534. }
  535. } else {
  536. msg = '支付失败';
  537. }
  538. $h.pushMsg(msg, function () {
  539. that.payDialogOpen = false;
  540. if (that.orderId) {
  541. store.baseGet($h.U({
  542. c: 'special',
  543. a: 'del_order',
  544. q: {
  545. orderId: that.orderId
  546. }
  547. }));
  548. }
  549. });
  550. },
  551. }
  552. });
  553. });
  554. </script>
  555. {/block}