liveReplay.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <div class="app-container" v-loading.fullscreen.lock="loading">
  3. <!-- 直播回放开关区域 -->
  4. <div class="switch-area">
  5. <span class="switch-label">直播回放:</span>
  6. <el-switch
  7. v-model="replayForm.isPlaybackOpen"
  8. @change="handlePlaybackSwitch"
  9. />
  10. <span class="switch-desc" style="color: #9c9c9c;margin-left: 10px">开启回放,直播结束后学员可查看回放视频</span>
  11. </div>
  12. <!-- 回放模式区域 -->
  13. <div class="playback-mode" v-if="replayForm.isPlaybackOpen">
  14. <div class="mode-title">回放模式:</div>
  15. <div class="mode-option">
  16. <el-radio v-model="replayForm.playbackMode" label="1">模式一:以直播间全部直播视频作为回看</el-radio>
  17. </div>
  18. <!-- <div class="mode-option">-->
  19. <!-- <el-radio v-model="playbackMode" label="2">模式二:以直播间最后一次直播视频作为回看</el-radio>-->
  20. <!-- </div>-->
  21. <!-- <div class="mode-option">-->
  22. <!-- <el-radio v-model="playbackMode" label="3">模式三:自主选择本直播间或素材库任一视频作为回看</el-radio>-->
  23. <!-- </div>-->
  24. </div>
  25. <!-- 回放有效期区域 -->
  26. <div class="validity-period" v-if="replayForm.isPlaybackOpen">
  27. <div class="period-title">回放有效期:</div>
  28. <div class="period-option">
  29. <el-radio @change="updateForm" v-model="replayForm.validityType" label="permanent">永久有效</el-radio>
  30. </div>
  31. <div class="period-option">
  32. <el-radio v-model="replayForm.validityType" label="days">
  33. 直播结束后
  34. <el-input
  35. v-model.number="replayForm.validDays"
  36. type="number"
  37. @change="updateForm"
  38. :min="1"
  39. placeholder="天数"
  40. />
  41. 天有效
  42. <el-tooltip
  43. content="以直播实际结束时间为准"
  44. placement="top"
  45. effect="light"
  46. >
  47. <i class="el-icon-question" style="color: #999; margin-left: 5px" />
  48. </el-tooltip> </el-radio>
  49. </div>
  50. <div class="period-desc">
  51. 到期后,学员无法观看回放内容
  52. </div>
  53. <!-- 倍速播放区域 -->
  54. <div class="speed-play">
  55. <div class="speed-label">倍速播放/快进:</div>
  56. <el-radio @change="updateForm" v-model="replayForm.isSpeedAllowed" label="1">允许</el-radio>
  57. <el-radio @change="updateForm" v-model="replayForm.isSpeedAllowed" label="0">禁止</el-radio>
  58. <span class="speed-desc">禁止时,课程未学完学员不可倍速播放、拖动进度条</span>
  59. <span class="pro-tag">专业版</span>
  60. </div>
  61. </div>
  62. <!-- 回放内容区域 -->
  63. <div class="playback-content">
  64. <div>
  65. <span>回放内容:</span>
  66. <!-- <el-button-->
  67. <!-- class="upload-btn"-->
  68. <!-- type="text"-->
  69. <!-- icon="el-icon-plus"-->
  70. <!-- @click="handleUploadVideo"-->
  71. <!-- >上传视频</el-button>-->
  72. <!-- <span class="upload-tip">上传视频大小不可超过5GB</span>-->
  73. </div>
  74. <!-- 视频列表 -->
  75. <el-table
  76. :data="videoList"
  77. border
  78. style="width: 100%; margin-top: 10px"
  79. >
  80. <el-table-column prop="videoName" label="视频名称">
  81. <template slot-scope="scope">
  82. <div class="video-item">
  83. <div class="video-info">
  84. <div class="video-name">{{ scope.row.videoName }}</div>
  85. </div>
  86. </div>
  87. </template>
  88. </el-table-column>
  89. <el-table-column prop="duration" label="时长" />
  90. <el-table-column prop="status" label="状态">
  91. <template slot-scope="scope">
  92. <span v-if="scope.row.status === '回放中'">
  93. <span class="status-dot" />{{ scope.row.status }}
  94. </span>
  95. <span v-else>{{ scope.row.status }}</span>
  96. </template>
  97. </el-table-column>
  98. <el-table-column prop="updateTime" label="更新时间" />
  99. <el-table-column label="视频地址" prop="videoUrl" >
  100. <template slot-scope="scope">
  101. <el-tooltip
  102. :content="scope.row.videoUrl"
  103. placement="top"
  104. effect="dark"
  105. >
  106. <a
  107. :href="scope.row.videoUrl"
  108. target="_blank"
  109. class="video-url-container"
  110. rel="noopener noreferrer"
  111. >
  112. {{
  113. scope.row.videoUrl.length > 32
  114. ? scope.row.videoUrl.substring(0, 32) + '...'
  115. : scope.row.videoUrl
  116. }}
  117. <i class="el-icon-external-link video-url-icon"></i>
  118. </a>
  119. </el-tooltip>
  120. </template>
  121. </el-table-column>
  122. <!-- <el-table-column label="操作">-->
  123. <!-- <template slot-scope="scope">-->
  124. <!--&lt;!&ndash; <el-button&ndash;&gt;-->
  125. <!--&lt;!&ndash; type="text"&ndash;&gt;-->
  126. <!--&lt;!&ndash; size="small"&ndash;&gt;-->
  127. <!--&lt;!&ndash; @click="handleCut(scope.row)"&ndash;&gt;-->
  128. <!--&lt;!&ndash; >剪切</el-button>&ndash;&gt;-->
  129. <!--&lt;!&ndash; <el-button&ndash;&gt;-->
  130. <!--&lt;!&ndash; type="text"&ndash;&gt;-->
  131. <!--&lt;!&ndash; size="small"&ndash;&gt;-->
  132. <!--&lt;!&ndash; @click="handleGenerateAiSummary(scope.row)"&ndash;&gt;-->
  133. <!--&lt;!&ndash; >生成AI速览</el-button>&ndash;&gt;-->
  134. <!--&lt;!&ndash; <el-button&ndash;&gt;-->
  135. <!--&lt;!&ndash; type="text"&ndash;&gt;-->
  136. <!--&lt;!&ndash; size="small"&ndash;&gt;-->
  137. <!--&lt;!&ndash; @click="handleGenerateSubtitle(scope.row)"&ndash;&gt;-->
  138. <!--&lt;!&ndash; >生成字幕</el-button>&ndash;&gt;-->
  139. <!--&lt;!&ndash; <el-button&ndash;&gt;-->
  140. <!--&lt;!&ndash; type="text"&ndash;&gt;-->
  141. <!--&lt;!&ndash; size="small"&ndash;&gt;-->
  142. <!--&lt;!&ndash; @click="handlePlaybackSegment(scope.row)"&ndash;&gt;-->
  143. <!--&lt;!&ndash; >回放片段</el-button>&ndash;&gt;-->
  144. <!-- </template>-->
  145. <!-- </el-table-column>-->
  146. </el-table>
  147. </div>
  148. </div>
  149. </template>
  150. <script>
  151. import {getLive, updateLive,} from '@/api/live/live'
  152. import {getLiveVideoByLiveId,} from '@/api/live/liveVideo'
  153. export default {
  154. name: "LiveReplay",
  155. data() {
  156. return {
  157. loading: true,
  158. replayForm:{
  159. isPlaybackOpen: false, // 直播回放开关状态
  160. playbackMode: "1", // 回放模式,默认模式一
  161. validityType: "days", // 回放有效期类型,默认天数
  162. validDays: 7, // 有效天数
  163. isSpeedAllowed: "1", // 是否允许倍速播放,默认允许
  164. },
  165. videoList: [
  166. {
  167. },
  168. ], // 视频列表数据,实际需从接口获取
  169. liveId: null,
  170. liveInfo: null,
  171. };
  172. },
  173. watch: {
  174. // 监听路由的 query 参数变化
  175. '$route.query': {
  176. handler(newQuery) {
  177. if (this.$route.params.liveId) {
  178. this.liveId = this.$route.params.liveId;
  179. }else {
  180. this.liveId = this.$route.query.liveId;
  181. }
  182. if(this.liveId == null) {
  183. return;
  184. }
  185. this.getLive();
  186. },
  187. // 初始化时立即执行一次
  188. immediate: true
  189. }
  190. },
  191. created() {
  192. // if (this.$route.params.liveId) {
  193. // this.liveId = this.$route.params.liveId;
  194. // }else {
  195. // this.liveId = this.$route.query.liveId;
  196. // }
  197. // if(this.liveId == null) {
  198. // this.$message.error("页面错误,请联系管理员");
  199. // return;
  200. // }
  201. // this.getLive();
  202. },
  203. methods: {
  204. getLiveVideo() {
  205. getLiveVideoByLiveId(this.liveId).then(res => {
  206. let dataEntity =
  207. {
  208. duration: "00:00",
  209. status: "回放中",
  210. updateTime: "2025-09-08 14:28:24",
  211. };
  212. //将秒数转为时分秒
  213. dataEntity.duration = this.convertSeconds(res.data.duration);
  214. dataEntity.updateTime = res.data.updateTime;
  215. dataEntity.videoUrl = res.data.videoUrl;
  216. dataEntity.videoName = this.extractFileName(dataEntity.videoUrl)
  217. this.videoList.push(dataEntity);
  218. });
  219. },
  220. /**
  221. * 提取文件名称核心方法
  222. * 逻辑:通过split('/')分割路径,取最后一个非空元素作为文件名称
  223. */
  224. extractFileName(data) {
  225. try {
  226. this.errorMsg = '';
  227. const trimmedUrl = data.trim();
  228. // 用'/'分割路径,过滤空字符串(避免路径末尾有'/'导致的空元素)
  229. const pathSegments = trimmedUrl.split('/').filter(segment => segment);
  230. if (pathSegments.length === 0) {
  231. throw new Error('输入的路径格式无效,请检查后重新输入');
  232. }
  233. // 最后一个分段即为文件名称
  234. const fileName = pathSegments[pathSegments.length - 1];
  235. // 简单校验是否为常见视频文件格式(可选,根据需求调整)
  236. const videoExtensions = ['mp4', 'mov', 'avi', 'flv', 'mkv'];
  237. const fileExtension = fileName.split('.').pop()?.toLowerCase();
  238. if (!fileExtension || !videoExtensions.includes(fileExtension)) {
  239. this.errorMsg = '提示:提取到的文件可能不是常见视频格式,请注意校验';
  240. }
  241. return fileName;
  242. } catch (err) {
  243. this.errorMsg = err.message;
  244. return '';
  245. }
  246. },
  247. convertSeconds(data) {
  248. // 确保输入是有效的数字
  249. const totalSeconds = Math.max(0, parseInt(data) || 0);
  250. // 计算时、分、秒
  251. const hours = Math.floor(totalSeconds / 3600);
  252. const minutes = Math.floor((totalSeconds % 3600) / 60);
  253. const seconds = totalSeconds % 60;
  254. // 格式化每个部分为两位数
  255. return `${this.padWithZero(hours)}:${this.padWithZero(minutes)}:${this.padWithZero(seconds)}`;
  256. },
  257. padWithZero(num) {
  258. // 将数字转换为两位数格式
  259. return num.toString().padStart(2, '0');
  260. },
  261. getLive() {
  262. getLive(this.liveId).then(res => {
  263. this.liveInfo = res.data;
  264. if(res.data.liveConfig){
  265. this.replayForm = JSON.parse(res.data.liveConfig);
  266. this.getLiveVideo();
  267. }else{
  268. this.resetForm();
  269. }
  270. this.loading = false;
  271. });
  272. },
  273. resetForm() {
  274. this.replayForm={
  275. isPlaybackOpen: false, // 直播回放开关状态
  276. playbackMode: "1", // 回放模式,默认模式一
  277. validityType: "days", // 回放有效期类型,默认天数
  278. validDays: 7, // 有效天数
  279. isSpeedAllowed: "1", // 是否允许倍速播放,默认允许
  280. }
  281. },
  282. // 直播回放开关变更处理
  283. handlePlaybackSwitch(val) {
  284. if (this.liveInfo.liveType != 1 && this.liveInfo.liveType != 3) {
  285. this.replayForm.isPlaybackOpen = !val;
  286. this.$message.error("直播回放开关仅支持直播");
  287. return;
  288. }
  289. if (!this.liveInfo.finishTime) {
  290. this.replayForm.isPlaybackOpen = !val;
  291. this.$message.error("直播未结束");
  292. return;
  293. }
  294. this.replayForm.isPlaybackOpen = val;
  295. this.updateForm()
  296. },
  297. updateForm(){
  298. let param = {
  299. liveId: this.liveId,
  300. startTime:this.liveInfo.startTime,
  301. finishTime:this.liveInfo.finishTime,
  302. status: 4,
  303. liveConfig: JSON.stringify(this.replayForm)
  304. };
  305. updateLive(param).then(res => {
  306. if (res.code != 200) {
  307. this.$message.error(res.msg);
  308. }
  309. });
  310. },
  311. // 上传视频处理
  312. handleUploadVideo() {
  313. // 模拟上传视频逻辑,实际需调用上传组件或接口
  314. this.$message.info("点击了上传视频按钮,实际需对接上传逻辑");
  315. },
  316. // 剪切视频处理
  317. handleCut(video) {
  318. this.$message.info(`点击了剪切视频,视频名称:${video.videoName}`);
  319. // 实际剪切逻辑
  320. },
  321. // 生成AI速览处理
  322. handleGenerateAiSummary(video) {
  323. this.$message.info(`点击了生成AI速览,视频名称:${video.videoName}`);
  324. // 实际生成AI速览逻辑
  325. },
  326. // 生成字幕处理
  327. handleGenerateSubtitle(video) {
  328. this.$message.info(`点击了生成字幕,视频名称:${video.videoName}`);
  329. // 实际生成字幕逻辑
  330. },
  331. // 回放片段处理
  332. handlePlaybackSegment(video) {
  333. this.$message.info(`点击了回放片段,视频名称:${video.videoName}`);
  334. // 实际回放片段逻辑
  335. },
  336. },
  337. };
  338. </script>
  339. <style scoped>
  340. .live-playback-setting {
  341. font-family: "Microsoft Yahei", sans-serif;
  342. color: #333;
  343. background-color: #fff;
  344. padding: 20px;
  345. border-radius: 4px;
  346. box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
  347. }
  348. .switch-area {
  349. display: flex;
  350. align-items: center;
  351. margin-bottom: 20px;
  352. }
  353. .switch-area .switch-label {
  354. margin-right: 10px;
  355. font-size: 14px;
  356. }
  357. .switch-area .switch-desc {
  358. color: #999;
  359. font-size: 12px;
  360. }
  361. .playback-mode {
  362. background-color: #f9fafc;
  363. padding: 15px;
  364. border-radius: 4px;
  365. margin-bottom: 20px;
  366. }
  367. .playback-mode .mode-title {
  368. font-size: 14px;
  369. margin-bottom: 10px;
  370. }
  371. .playback-mode .mode-option {
  372. display: flex;
  373. align-items: center;
  374. margin-bottom: 8px;
  375. }
  376. .playback-mode .mode-option .el-radio {
  377. margin-left: 2%;
  378. }
  379. .playback-mode .mode-option label {
  380. font-size: 13px;
  381. }
  382. .validity-period {
  383. background-color: #f9fafc;
  384. padding: 15px;
  385. border-radius: 4px;
  386. margin-bottom: 20px;
  387. }
  388. .validity-period .period-title {
  389. font-size: 14px;
  390. margin-bottom: 10px;
  391. }
  392. .validity-period .period-option {
  393. display: flex;
  394. align-items: center;
  395. margin-bottom: 8px;
  396. }
  397. .validity-period .period-option .el-radio {
  398. margin-left: 2%;
  399. }
  400. .validity-period .period-option label {
  401. font-size: 13px;
  402. }
  403. .validity-period .period-desc {
  404. color: #999;
  405. font-size: 12px;
  406. margin-top: 5px;
  407. margin-left: 2%;
  408. }
  409. .validity-period .day-input {
  410. width: 60px;
  411. height: 28px;
  412. border: 1px solid #ddd;
  413. border-radius: 4px;
  414. padding: 0 8px;
  415. margin: 0 5px;
  416. }
  417. .speed-play {
  418. display: flex;
  419. align-items: center;
  420. margin-top: 15px;
  421. }
  422. .speed-play .speed-label {
  423. font-size: 13px;
  424. margin-right: 10px;
  425. }
  426. .speed-play .el-radio {
  427. margin-right: 5px;
  428. }
  429. .speed-play .speed-desc {
  430. color: #999;
  431. font-size: 12px;
  432. margin-left: 10px;
  433. }
  434. .pro-tag {
  435. display: inline-block;
  436. background-color: #007bff;
  437. color: #fff;
  438. font-size: 10px;
  439. padding: 2px 5px;
  440. border-radius: 3px;
  441. margin-left: 5px;
  442. vertical-align: middle;
  443. }
  444. .playback-content {
  445. margin-top: 20px;
  446. }
  447. .playback-content .upload-btn {
  448. display: inline-block;
  449. background-color: #fff;
  450. border: 1px dashed #ddd;
  451. color: #007bff;
  452. padding: 8px 15px;
  453. border-radius: 4px;
  454. cursor: pointer;
  455. font-size: 13px;
  456. margin-bottom: 15px;
  457. }
  458. .playback-content .upload-btn:hover {
  459. border-color: #007bff;
  460. }
  461. .playback-content .upload-tip {
  462. font-size: 12px;
  463. color: #999;
  464. margin-left: 10px;
  465. }
  466. .video-item {
  467. display: flex;
  468. align-items: center;
  469. }
  470. .video-cover {
  471. width: 80px;
  472. height: 45px;
  473. border-radius: 4px;
  474. margin-right: 10px;
  475. }
  476. .video-info .video-name {
  477. font-size: 13px;
  478. margin-bottom: 3px;
  479. }
  480. .video-info .video-desc {
  481. font-size: 12px;
  482. color: #999;
  483. }
  484. .video-duration,
  485. .video-source,
  486. .video-status,
  487. .video-update-time {
  488. color: #666;
  489. }
  490. .video-status .status-dot {
  491. display: inline-block;
  492. width: 8px;
  493. height: 8px;
  494. background-color: #007bff;
  495. border-radius: 50%;
  496. margin-right: 5px;
  497. vertical-align: middle;
  498. }
  499. .video-operation .el-button {
  500. color: #007bff;
  501. font-size: 12px;
  502. margin-right: 10px;
  503. }
  504. </style>