coursedetail.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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/manageCompany'
  64. import {
  65. numberToLetter
  66. } from "@/utils/tools.js"
  67. import { mapGetters } from 'vuex';
  68. export default {
  69. data() {
  70. return {
  71. viewload:true,
  72. loadingtext:"数据加载中...",
  73. videoId:'',
  74. listdetail:[],
  75. user:{},
  76. copylink:'',
  77. id:'',
  78. periodId:'',
  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. ...mapGetters(['logoimg']),
  120. },
  121. watch: {
  122. logoimg: {
  123. immediate: true, // 页面一进入就检查一次
  124. handler(val) {
  125. return val
  126. }
  127. },
  128. },
  129. onShareAppMessage() {
  130. const course={
  131. companyId:this.user.companyId,
  132. companyUserId:this.user.userId,
  133. id:this.id,
  134. courseId:this.listdetail.courseId,
  135. videoId:this.videoId,
  136. periodId:this.periodId
  137. }
  138. console.log(course)
  139. return {
  140. title: this.listdetail.title, // 分享卡片标题
  141. path: 'pages_course/videovip' + "?course=" +JSON.stringify(course) , // 目标页面路径
  142. // 携带参数:将当前页面的数据拼接到路径中
  143. imageUrl: this.listdetail.thumbnail||this.logoimg, // 分享卡片封面图(可选)
  144. success: (res) => {
  145. console.log("分享成功", res);
  146. },
  147. fail: (err) => {
  148. console.log("分享失败", err);
  149. },
  150. }
  151. },
  152. methods: {
  153. changeSpeed(rate,index) {
  154. console.log(rate,index)
  155. this.actTime=index
  156. this.playbackRate = rate;
  157. // 更新播放速率
  158. if (this.videoContext) {
  159. this.videoContext.playbackRate(rate);
  160. }
  161. },
  162. numberToLetter(num) {
  163. // 将数字转换为字母的 ASCII 码
  164. let letterCode = num + 65;
  165. // 将 ASCII 码转换为大写字母
  166. let letter = String.fromCharCode(letterCode);
  167. return letter;
  168. },
  169. //转化时间格式
  170. formatSeconds(seconds) {
  171. const hours = Math.floor(seconds / 3600);
  172. const minutes = Math.floor((seconds % 3600) / 60);
  173. const remainingSeconds = seconds % 60;
  174. // 补零函数:确保两位数显示
  175. const pad = (num) => num.toString().padStart(2, '0');
  176. return `${pad(hours)}:${pad(minutes)}:${pad(remainingSeconds)}`;
  177. },
  178. // 获取视频详情
  179. getdetail() {
  180. const param = {
  181. videoId:this.videoId
  182. }
  183. getcourseDetail(param).then(res => {
  184. if(res.code==200){
  185. this.viewload=false
  186. this.listdetail=res.data
  187. this.listdetail.questionBankList= this.listdetail.questionBankList.map(item => ({
  188. ...item,
  189. question: JSON.parse(item.question),
  190. answer: '',
  191. }))
  192. }else{
  193. uni.showToast({
  194. title: res.msg,
  195. icon: 'none',
  196. });
  197. }
  198. })
  199. },
  200. copyshareLink(){
  201. const params = {
  202. companyId: this.user.companyId,
  203. companyUserId: this.user.userId,
  204. courseId: this.listdetail.courseId,
  205. time: this.time,
  206. videoId: this.listdetail.videoId,
  207. id: Number(this.id),
  208. }
  209. sharecourselink(params).then(res => {
  210. if (res.code == 200) {
  211. this.copylink = res.url
  212. // if (this.copylink.startsWith('http://')) {
  213. // this.copylink = this.copylink.replace('http://', 'https://');
  214. // }
  215. // console.log(this.copylink)
  216. setTimeout(() => {
  217. uni.setClipboardData({
  218. data: this.copylink,
  219. success: () => {
  220. uni.showToast({
  221. title: '链接已复制',
  222. icon: 'none',
  223. duration: 2000
  224. });
  225. },
  226. fail: () => {
  227. uni.showToast({
  228. title: '复制失败',
  229. icon: 'none'
  230. });
  231. }
  232. });
  233. }, 100)
  234. console.log(this.copylink)
  235. } else {
  236. uni.showToast({
  237. icon: 'none',
  238. title: res.msg
  239. })
  240. }
  241. })
  242. console.log(123)
  243. }
  244. }
  245. }
  246. </script>
  247. <style scoped lang="scss">
  248. .actstyle{
  249. background-color: #FF5C03;
  250. color: #fff;
  251. border: 2rpx solid #FF5C03 !important;
  252. }
  253. .speed-controls {
  254. margin-top: 20rpx;
  255. display: flex;
  256. justify-content: space-around;
  257. margin-bottom: 16rpx;
  258. view{
  259. height: 50rpx;
  260. line-height: 46rpx;
  261. width: 120rpx;
  262. font-size: 24rpx;
  263. border-radius: 30rpx;
  264. text-align: center;
  265. border: 2rpx solid #a5a5a5;
  266. }
  267. }
  268. .video-box {
  269. width: 100%;
  270. height: 420rpx;
  271. overflow: hidden;
  272. position: relative;
  273. #myVideo {
  274. width: 100%;
  275. height: 100%;
  276. }
  277. }
  278. .title-content {
  279. padding: 20rpx 32rpx;
  280. background-color: #fff;
  281. font-size: 28rpx;
  282. font-weight: bold;
  283. line-height: 1.6;
  284. }
  285. .ques-content-tit {
  286. font-family: PingFang SC, PingFang SC;
  287. font-weight: 600;
  288. font-size: 36rpx;
  289. color: #222222;
  290. }
  291. .ques-content {
  292. background-color: #fff;
  293. margin-top: 20rpx;
  294. padding: 32rpx 32rpx;
  295. padding-bottom: 140rpx;
  296. box-sizing: border-box;
  297. ont-family: PingFang SC, PingFang SC;
  298. font-weight: 400;
  299. font-size: 28rpx;
  300. color: #222222;
  301. }
  302. .ques-title {
  303. margin: 32rpx 0 34rpx 0;
  304. font-weight: 500;
  305. font-size: 32rpx;
  306. white-space: normal;
  307. }
  308. .ques-type {
  309. flex-shrink: 0;
  310. min-width: 72rpx;
  311. height: 40rpx;
  312. padding: 0 12rpx;
  313. margin: 0 12rpx;
  314. box-sizing: border-box;
  315. background: #ff8901;
  316. border-radius: 8rpx 8rpx 8rpx 8rpx;
  317. line-height: 40rpx;
  318. text-align: center;
  319. font-family: PingFang SC, PingFang SC;
  320. font-weight: 400;
  321. font-size: 24rpx;
  322. color: #FFFFFF;
  323. display: inline-block;
  324. }
  325. .ques-option {
  326. min-height: 88rpx;
  327. padding: 24rpx 32rpx;
  328. box-sizing: border-box;
  329. margin-bottom: 24rpx;
  330. background: #F5F7FA;
  331. border-radius: 16rpx 16rpx 16rpx 16rpx;
  332. display: flex;
  333. align-items: center;
  334. &-active {
  335. color: #1db131 !important;
  336. background: #e8fcee !important;
  337. }
  338. }
  339. .footer {
  340. border-top: 1rpx solid #ededef;
  341. background: #fff;
  342. width: 100%;
  343. position: fixed;
  344. bottom: 0;
  345. padding: 24rpx 32rpx;
  346. box-sizing: border-box;
  347. z-index: 9;
  348. .copybtn {
  349. background: #FF5C03;
  350. color: #fff;
  351. text-align: center;
  352. font-size: 28rpx;
  353. border-radius: 80rpx;
  354. padding: 20rpx 0;
  355. }
  356. }
  357. </style>