video.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {extend name="public/base_soldier"/}
  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;margin-top:auto;text-align:right;padding:0 20px;display:flex;justify-content:space-between;color:#666;}
  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">
  34. <span>{{video.is_must_text}}</span>
  35. <span :class="'s-color'+video.watch_status">{{video.watch_text}}</span>
  36. </div>
  37. <video src="{$video.video}"
  38. style="width:100%;margin:20px auto;"
  39. id="myVideo"
  40. controls
  41. @timeupdate="timeUpdate"
  42. @ended="VideoEnded">
  43. </video>
  44. <div class="lw-header">相关视频</div>
  45. <div class="lw-list">
  46. <article v-for="video in list" @click="toVideo(video.id)">
  47. <section class="s-right">
  48. <van-image
  49. width="110"
  50. height="85"
  51. fit="cover"
  52. :src="video.main_image"
  53. ></van-image>
  54. </section>
  55. <section class="s-left image">
  56. <div class="s-title">{{video.title}}【{{video.is_must_text}}】</div>
  57. <div class="s-time" :class="'s-color'+video.watch_status">{{video.watch_text}}</div>
  58. </section>
  59. </article>
  60. <div class="van-list__finished-text" v-if="list.length == 0">暂无更多视频</div>
  61. </div>
  62. {/block}
  63. {block name="script"}
  64. <script>
  65. function v_setup() {
  66. let base = {};
  67. base.video = Vue.reactive({$video});
  68. base.list = Vue.reactive({$video_list});
  69. base.toVideo = (id) => {
  70. location.href = "{:url('soldier/video')}?id=" + id;
  71. };
  72. //视频
  73. let time = localStorage.getItem('video_{$video.id}');
  74. base.currentTime = time ? time : 0; //上次观看时间
  75. base.newsschedule = base.currentTime; //当前观看时间
  76. base.timeUpdate = (e) => {
  77. if (e.target.currentTime - base.newsschedule > 1) {
  78. vant.showToast('不允许拖动进度条');
  79. let videoContext = document.getElementById("myVideo");
  80. videoContext.currentTime = base.newsschedule;
  81. } else {
  82. base.newsschedule = e.target.currentTime;
  83. localStorage.setItem('video_{$video.id}',base.newsschedule);
  84. }
  85. };
  86. base.VideoEnded = () => {
  87. postJson('/soldier/videoEnd', {id:base.video.id}).then(({data, code}) => {
  88. base.video.watch_status = 3;
  89. base.video.watch_text = '已完成';
  90. vant.showDialog({ message: '学习完毕' });
  91. })
  92. };
  93. base.onBack = () => {
  94. location.href = "{:url('soldier/series')}?id={$video.series_id}";
  95. };
  96. Vue.onMounted(() => {
  97. let videoContext = document.getElementById("myVideo");
  98. if (videoContext) {
  99. if (base.currentTime > 0) {
  100. vant.showToast('上次已观看到'+ parseInt(base.currentTime)+'秒');
  101. }
  102. videoContext.currentTime = base.currentTime;
  103. }
  104. });
  105. return base;
  106. }
  107. </script>
  108. {/block}