courseVideo.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view class="column">
  3. <view class="video-box" >
  4. <video id="myVideo" :src='listdetail.videoUrl' show-mute-btn='false'
  5. vslide-gesture-in-fullscreen='true' loop='true' enable-progress-gesture='true'
  6. enable-danmu controls='true' autoplay="true" object-fit='contain' show-center-play-btn='true'
  7. class="videotop" :playback-rate="playbackRate"></video>
  8. </view>
  9. <view class="speed-controls">
  10. <view @click="changeSpeed(item.value,index)" v-for="(item,index) in speadvideo"
  11. :key="index" :class="actTime==index?'actstyle':''">{{item.name}}</view>
  12. </view>
  13. <view class="title-content" id="title-content">
  14. <!-- 课程标题 -->
  15. <view >
  16. {{listdetail.title}}
  17. </view>
  18. <view class="fs24" style="color: #666;font-weight: normal;">
  19. {{listdetail.description?listdetail.description:""}}
  20. </view>
  21. <view class="fs24" style="color: #999;font-weight: normal;">课程视频时长:{{formatSeconds(listdetail.duration)}}</view>
  22. </view>
  23. <!-- 问题 -->
  24. <view class="ques-content ">
  25. <view class="ques-content-tit">问答题</view>
  26. <view class="center fs32" v-if="listdetail.questionBankList.length<1" style="color: #666;">暂无问答题</view>
  27. <view v-for="(item,index) in listdetail.questionBankList" :key="index">
  28. <view class="ques-title">
  29. <text>{{index + 1}}.</text>
  30. <view class="ques-type" v-show="item.type == 1 || item.type == 2">
  31. {{item.type == 1 ? '单选' : item.type == 2 ? '多选' : ''}}
  32. </view>
  33. <text >{{item.title}}</text>
  34. </view>
  35. <view :class="option.isAnswer== 1 ?'ques-option ques-option-active':'ques-option'"
  36. v-for="(option,idx) in item.question" :key="idx">
  37. <view>
  38. {{numberToLetter(idx)}}.
  39. </view>
  40. <view>{{option.name}}</view>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="footer" v-if="!viewload">
  45. <view class="justify-between" >
  46. <!--#ifdef MP-WEIXIN-->
  47. <button open-type="share" class="copybtn flex-1">分享课程</button>
  48. <!-- <view class="copybtn flex-1" @click="showShare=!showShare">分享卡片</view> -->
  49. <!--#endif-->
  50. <!--#ifdef H5-->
  51. <view class="copybtn flex-1" @click="copyshareLink()">复制分享链接</view>
  52. <!--#endif-->
  53. </view>
  54. </view>
  55. <u-loading-page :loading="viewload" iconSize="32" loadingColor="#3c9cff" fontSize="20"
  56. :loading-text="loadingtext" ></u-loading-page>
  57. </view>
  58. </template>
  59. <script>
  60. import {
  61. getcourseDetail,
  62. sharecourselink
  63. } from '@/api/courseManage'
  64. import {
  65. numberToLetter
  66. } from "@/utils/tools.js"
  67. export default {
  68. data() {
  69. return {
  70. viewload:true,
  71. loadingtext:"数据加载中...",
  72. videoId:'',
  73. listdetail:[],
  74. user:{},
  75. copylink:'',
  76. id:'',
  77. periodId:'',
  78. imgs:this.$store.state.imgpath+'/app/image/logo.png',
  79. playbackRate: 1.0, // 默认1倍速
  80. videoContext: null,
  81. actTime:0,
  82. speadvideo:[
  83. {
  84. name:'1.0倍速',
  85. value:1
  86. },
  87. {
  88. name:'1.5倍速',
  89. value:1.5
  90. },
  91. {
  92. name:'2.0倍速',
  93. value:2
  94. }
  95. ]
  96. }
  97. },
  98. mounted() {
  99. // 创建视频上下文
  100. this.videoContext = uni.createVideoContext('myVideo', this);
  101. },
  102. onLoad(option) {
  103. this.videoId=option.videoId
  104. this.id=option.id
  105. this.periodId=option.periodId
  106. },
  107. onShow() {
  108. this.getdetail()
  109. this.user = uni.getStorageSync("companyUserInfo") ? JSON.parse(uni.getStorageSync("companyUserInfo")) : {}
  110. },
  111. computed: {
  112. imgPath() {
  113. // 处理空值,返回默认路径或空字符串
  114. // if (!this.$store.state.imgpath) {
  115. // return '' // 本地默认图
  116. // }
  117. return this.$store.state.imgpath
  118. }
  119. },
  120. onShareAppMessage() {
  121. const course={
  122. companyId:this.user.companyId,
  123. companyUserId:this.user.userId,
  124. id:this.id,
  125. courseId:this.listdetail.courseId,
  126. videoId:this.videoId,
  127. periodId:this.periodId
  128. }
  129. console.log(course)
  130. return {
  131. title: this.listdetail.title, // 分享卡片标题
  132. path: 'pages_course/videovip' + "?course=" +JSON.stringify(course) , // 目标页面路径
  133. // 携带参数:将当前页面的数据拼接到路径中
  134. imageUrl: this.listdetail.thumbnail||this.imgs, // 分享卡片封面图(可选)
  135. success: (res) => {
  136. console.log("分享成功", res);
  137. },
  138. fail: (err) => {
  139. console.log("分享失败", err);
  140. },
  141. }
  142. },
  143. methods: {
  144. changeSpeed(rate,index) {
  145. console.log(rate,index)
  146. this.actTime=index
  147. this.playbackRate = rate;
  148. // 更新播放速率
  149. if (this.videoContext) {
  150. this.videoContext.playbackRate(rate);
  151. }
  152. },
  153. numberToLetter(num) {
  154. // 将数字转换为字母的 ASCII 码
  155. let letterCode = num + 65;
  156. // 将 ASCII 码转换为大写字母
  157. let letter = String.fromCharCode(letterCode);
  158. return letter;
  159. },
  160. //转化时间格式
  161. formatSeconds(seconds) {
  162. const hours = Math.floor(seconds / 3600);
  163. const minutes = Math.floor((seconds % 3600) / 60);
  164. const remainingSeconds = seconds % 60;
  165. // 补零函数:确保两位数显示
  166. const pad = (num) => num.toString().padStart(2, '0');
  167. return `${pad(hours)}:${pad(minutes)}:${pad(remainingSeconds)}`;
  168. },
  169. // 获取视频详情
  170. getdetail() {
  171. const param = {
  172. videoId:this.videoId
  173. }
  174. getcourseDetail(param).then(res => {
  175. if(res.code==200){
  176. this.viewload=false
  177. this.listdetail=res.data
  178. this.listdetail.questionBankList= this.listdetail.questionBankList.map(item => ({
  179. ...item,
  180. question: JSON.parse(item.question),
  181. answer: '',
  182. }))
  183. }else{
  184. uni.showToast({
  185. title: res.msg,
  186. icon: 'none',
  187. });
  188. }
  189. })
  190. },
  191. copyshareLink(){
  192. const params = {
  193. companyId: this.user.companyId,
  194. companyUserId: this.user.userId,
  195. courseId: this.listdetail.courseId,
  196. time: this.time,
  197. videoId: this.listdetail.videoId,
  198. id: Number(this.id),
  199. }
  200. sharecourselink(params).then(res => {
  201. if (res.code == 200) {
  202. this.copylink = res.url
  203. // if (this.copylink.startsWith('http://')) {
  204. // this.copylink = this.copylink.replace('http://', 'https://');
  205. // }
  206. // console.log(this.copylink)
  207. setTimeout(() => {
  208. uni.setClipboardData({
  209. data: this.copylink,
  210. success: () => {
  211. uni.showToast({
  212. title: '链接已复制',
  213. icon: 'none',
  214. duration: 2000
  215. });
  216. },
  217. fail: () => {
  218. uni.showToast({
  219. title: '复制失败',
  220. icon: 'none'
  221. });
  222. }
  223. });
  224. }, 100)
  225. console.log(this.copylink)
  226. } else {
  227. uni.showToast({
  228. icon: 'none',
  229. title: res.msg
  230. })
  231. }
  232. })
  233. console.log(123)
  234. }
  235. }
  236. }
  237. </script>
  238. <style scoped lang="scss">
  239. .actstyle{
  240. background-color: #FF5C03;
  241. color: #fff;
  242. border: 2rpx solid #FF5C03 !important;
  243. }
  244. .speed-controls {
  245. margin-top: 20rpx;
  246. display: flex;
  247. justify-content: space-around;
  248. margin-bottom: 16rpx;
  249. view{
  250. height: 50rpx;
  251. line-height: 46rpx;
  252. width: 120rpx;
  253. font-size: 24rpx;
  254. border-radius: 30rpx;
  255. text-align: center;
  256. border: 2rpx solid #a5a5a5;
  257. }
  258. }
  259. .video-box {
  260. width: 100%;
  261. height: 420rpx;
  262. overflow: hidden;
  263. position: relative;
  264. #myVideo {
  265. width: 100%;
  266. height: 100%;
  267. }
  268. }
  269. .title-content {
  270. padding: 20rpx 32rpx;
  271. background-color: #fff;
  272. font-size: 28rpx;
  273. font-weight: bold;
  274. line-height: 1.6;
  275. }
  276. .ques-content-tit {
  277. font-family: PingFang SC, PingFang SC;
  278. font-weight: 600;
  279. font-size: 36rpx;
  280. color: #222222;
  281. }
  282. .ques-content {
  283. background-color: #fff;
  284. margin-top: 20rpx;
  285. padding: 32rpx 32rpx;
  286. padding-bottom: 140rpx;
  287. box-sizing: border-box;
  288. ont-family: PingFang SC, PingFang SC;
  289. font-weight: 400;
  290. font-size: 28rpx;
  291. color: #222222;
  292. }
  293. .ques-title {
  294. margin: 32rpx 0 34rpx 0;
  295. font-weight: 500;
  296. font-size: 32rpx;
  297. white-space: normal;
  298. }
  299. .ques-type {
  300. flex-shrink: 0;
  301. min-width: 72rpx;
  302. height: 40rpx;
  303. padding: 0 12rpx;
  304. margin: 0 12rpx;
  305. box-sizing: border-box;
  306. background: #ff8901;
  307. border-radius: 8rpx 8rpx 8rpx 8rpx;
  308. line-height: 40rpx;
  309. text-align: center;
  310. font-family: PingFang SC, PingFang SC;
  311. font-weight: 400;
  312. font-size: 24rpx;
  313. color: #FFFFFF;
  314. display: inline-block;
  315. }
  316. .ques-option {
  317. min-height: 88rpx;
  318. padding: 24rpx 32rpx;
  319. box-sizing: border-box;
  320. margin-bottom: 24rpx;
  321. background: #F5F7FA;
  322. border-radius: 16rpx 16rpx 16rpx 16rpx;
  323. display: flex;
  324. align-items: center;
  325. &-active {
  326. color: #1db131 !important;
  327. background: #e8fcee !important;
  328. }
  329. }
  330. .footer {
  331. border-top: 1rpx solid #ededef;
  332. background: #fff;
  333. width: 100%;
  334. position: fixed;
  335. bottom: 0;
  336. padding: 24rpx 32rpx;
  337. box-sizing: border-box;
  338. z-index: 9;
  339. .copybtn {
  340. background: #FF5C03;
  341. color: #fff;
  342. text-align: center;
  343. font-size: 28rpx;
  344. border-radius: 80rpx;
  345. padding: 20rpx 0;
  346. }
  347. }
  348. </style>