video.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. {extend name="public/base"/}
  2. {block name="css"}
  3. <style>
  4. .series-title {font-size: 16px;}
  5. .series-time {font-size: 12px;color: #999;}
  6. .lw-list article{border-radius: 5px;width:100%;height:110px;display:flex;align-items:center;background:white;padding:5px 10px;}
  7. .lw-list article .s-left {height:90px;display:flex;flex-direction:column;width: 100%;margin-left:auto;}
  8. .lw-list article .s-left.image {width: calc(100% - 120px);}
  9. .lw-list article .s-left .s-title{font-size: 16px;text-overflow: ellipsis;display: -webkit-box;overflow: hidden;-webkit-box-orient: vertical;-webkit-line-clamp: 3;text-align:left;color:#323233;}
  10. .lw-list article .s-left .s-time{font-size: 12px;color:#999;margin-top:auto;text-align:right;}
  11. .lw-list article .s-left .s-color3{color:var(--blue);}
  12. .lw-list article .s-left .s-color2{color:var(--red);}
  13. .lw-list article .s-right {width:110px;}
  14. .s-status {font-size: 14px;color:#999;margin-top:auto;text-align:right;padding-right:20px;}
  15. .s-status.s-color3{color:var(--blue);}
  16. .s-status.s-color2{color:var(--red);}
  17. .lw-header {background:white;padding:5px 10px;}
  18. </style>
  19. {/block}
  20. {block name="body"}
  21. <van-nav-bar
  22. class="nav-theme"
  23. :placeholder="true"
  24. left-text="返回"
  25. left-arrow
  26. @click-left="onBack"
  27. >
  28. <template #title>
  29. <span class="text-white">学习视频</span>
  30. </template>
  31. </van-nav-bar>
  32. <h3 style="text-align:center;">{$video.title}</h3>
  33. <div class="s-status" :class="'s-color'+video.watch_status">{{video.watch_text}}</div>
  34. <video src="{$video.video}"
  35. style="width:100%;margin:20px auto;"
  36. id="myVideo"
  37. controls
  38. @timeupdate="timeUpdate"
  39. @ended="VideoEnded">
  40. </video>
  41. <div class="lw-header">相关视频</div>
  42. <div class="lw-list">
  43. <article v-for="video in list" @click="toVideo(video.id)">
  44. <section class="s-right">
  45. <van-image
  46. width="110"
  47. height="85"
  48. fit="cover"
  49. :src="video.main_image"
  50. ></van-image>
  51. </section>
  52. <section class="s-left image">
  53. <div class="s-title">{{video.title}}</div>
  54. <div class="s-time" :class="'s-color'+video.watch_status">{{video.watch_text}}</div>
  55. </section>
  56. </article>
  57. <div class="van-list__finished-text" v-if="list.length == 0">暂无更多视频</div>
  58. </div>
  59. {/block}
  60. {block name="script"}
  61. <script>
  62. function v_setup() {
  63. let base = {};
  64. base.video = Vue.reactive({$video});
  65. base.list = Vue.reactive({$video_list});
  66. base.toVideo = (id) => {
  67. location.href = "{:url('soldier/video')}?id=" + id;
  68. };
  69. //视频
  70. let time = localStorage.getItem('video_{$video.id}');
  71. base.currentTime = time ? time : 0; //上次观看时间
  72. base.newsschedule = base.currentTime; //当前观看时间
  73. base.timeUpdate = (e) => {
  74. if (e.target.currentTime - base.newsschedule > 1) {
  75. vant.showToast('不允许拖动进度条');
  76. let videoContext = document.getElementById("myVideo");
  77. videoContext.currentTime = base.newsschedule;
  78. } else {
  79. base.newsschedule = e.target.currentTime;
  80. localStorage.setItem('video_{$video.id}',base.newsschedule);
  81. }
  82. };
  83. base.VideoEnded = () => {
  84. postJson('/soldier/videoEnd', {id:base.video.id}).then(({data, code}) => {
  85. base.video.watch_status = 3;
  86. base.video.watch_text = '已完成';
  87. vant.showDialog({ message: '学习完毕' });
  88. })
  89. };
  90. base.onBack = () => {
  91. history.back();
  92. };
  93. Vue.onMounted(() => {
  94. let videoContext = document.getElementById("myVideo");
  95. if (videoContext) {
  96. if (base.currentTime > 0) {
  97. vant.showToast('上次已观看到'+ parseInt(base.currentTime)+'秒');
  98. }
  99. videoContext.currentTime = base.currentTime;
  100. }
  101. });
  102. return base;
  103. }
  104. </script>
  105. {/block}