single.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div>
  3. <el-form-item label="">
  4. <div class="upload_video" id="upload_video">
  5. <!-- <el-upload-->
  6. <!-- class="upload-demo"-->
  7. <!-- ref="upload"-->
  8. <!-- action="#"-->
  9. <!-- :http-request="uploadVideoToTxPcdn"-->
  10. <!-- accept=".mp4"-->
  11. <!-- :limit="1"-->
  12. <!-- :on-remove="handleRemove"-->
  13. <!-- :on-change="handleChange"-->
  14. <!-- :auto-upload="false"-->
  15. <!-- :key="uploadKey"-->
  16. <!-- >-->
  17. <!-- <el-button slot="trigger" size="small" type="primary" >选取视频</el-button>-->
  18. <!-- <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">点击上传</el-button>-->
  19. <!-- 仅当showControl为true时显示视频库选取按钮 -->
  20. <el-button v-if="showControl" style="margin-left: 10px;" size="small" type="success" @click="openVideoLibrary">视频库选取</el-button>
  21. <!-- 线路一 -->
  22. <div class="progress-container">
  23. <span class="progress-label">线路一</span>
  24. <el-progress
  25. style="margin-top: 5px;"
  26. class="progress"
  27. :text-inside="true"
  28. :stroke-width="18"
  29. :percentage="txProgress"
  30. status="success">
  31. </el-progress>
  32. </div>
  33. <!-- 线路二 -->
  34. <!-- <div class="progress-container">-->
  35. <!-- <span class="progress-label">线路二</span>-->
  36. <!-- <el-progress-->
  37. <!-- style="margin-top: 5px;"-->
  38. <!-- class="progress"-->
  39. <!-- :text-inside="true"-->
  40. <!-- :stroke-width="18"-->
  41. <!-- :percentage="hwProgress"-->
  42. <!-- status="success">-->
  43. <!-- </el-progress>-->
  44. <!-- </div>-->
  45. <div slot="tip" class="el-upload__tip">只能上传mp4文件,且不超过500M</div>
  46. </el-upload>
  47. </div>
  48. </el-form-item>
  49. <el-form-item label="视频播放">
  50. <video v-if="videoUrl" ref="myvideo" :src="videoUrl" id="video" width="100%" height="300px" controls></video>
  51. <div v-if="fileName">视频文件名: {{ fileName }}</div>
  52. <div v-if="fileKey">文件Key: {{ fileKey }}</div>
  53. <div v-if="fileSize">文件大小(MB): {{ (fileSize / (1024 * 1024)).toFixed(2) }} MB</div>
  54. </el-form-item>
  55. <!-- 仅当showControl为true时显示播放线路选择器 -->
  56. <!-- <el-form-item v-if="showControl" label="播放线路">-->
  57. <!-- <el-radio-group v-model="localUploadType">-->
  58. <!-- <el-radio :label="1" >线路一</el-radio>-->
  59. <!--&lt;!&ndash; <el-radio :label="2" >线路二</el-radio>&ndash;&gt;-->
  60. <!-- &lt;!&ndash; <el-radio :label="3" >线路三</el-radio>&ndash;&gt;-->
  61. <!-- </el-radio-group>-->
  62. <!-- </el-form-item>-->
  63. <!-- 视频库选择对话框 -->
  64. <el-dialog title="视频库选择" :visible.sync="libraryOpen" width="900px" append-to-body>
  65. <!-- 搜索条件 -->
  66. <el-form :inline="true" :model="libraryQueryParams" class="library-search">
  67. <el-form-item label="素材名称">
  68. <el-input
  69. v-model="libraryQueryParams.remark"
  70. placeholder="请输入素材名称"
  71. clearable
  72. size="small"
  73. @keyup.enter.native="handleLibraryQuery"
  74. />
  75. </el-form-item>
  76. <el-form-item>
  77. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleLibraryQuery">搜索</el-button>
  78. <el-button icon="el-icon-refresh" size="mini" @click="resetLibraryQuery">重置</el-button>
  79. </el-form-item>
  80. </el-form>
  81. <!-- 视频列表 -->
  82. <el-table v-loading="libraryLoading" :data="libraryList" @row-click="handleLibrarySelect" highlight-current-row>
  83. <el-table-column label="素材名称" align="center" prop="remark" />
  84. <!-- <el-table-column label="缩略图" align="center">-->
  85. <!-- <template slot-scope="scope">-->
  86. <!-- <video-->
  87. <!-- :src="scope.row.videoUrl"-->
  88. <!-- controls-->
  89. <!-- controlsList="nodownload"-->
  90. <!-- class="video-player"-->
  91. <!-- @contextmenu.prevent-->
  92. <!-- ></video>-->
  93. <!-- </template>-->
  94. <!-- </el-table-column>-->
  95. <el-table-column label="视频时长" align="center">
  96. <template slot-scope="scope">
  97. <span>{{ formatDuration(scope.row.duration) }}</span>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. <!-- 分页 -->
  102. <pagination
  103. v-show="libraryTotal>0"
  104. :total="libraryTotal"
  105. :page.sync="libraryQueryParams.pageNum"
  106. :limit.sync="libraryQueryParams.pageSize"
  107. @pagination="getList"
  108. />
  109. <div slot="footer" class="dialog-footer">
  110. <el-button type="primary" @click="confirmVideoSelection">确 定</el-button>
  111. <el-button @click="cancelVideoSelection">取 消</el-button>
  112. </div>
  113. </el-dialog>
  114. </div>
  115. </template>
  116. <script>
  117. import { uploadObject } from "@/utils/cos.js";
  118. import Pagination from "@/components/Pagination";
  119. // import { listVideoResource } from '@/api/course/videoResource';
  120. import { listLiveVideo, getLiveVideo, delLiveVideo, addLiveVideo, updateLiveVideo, exportLiveVideo } from "@/api/live/liveVideo";
  121. export default {
  122. components: {
  123. Pagination
  124. },
  125. props: {
  126. videoUrl: {
  127. type: String,
  128. default: "",
  129. },
  130. fileKey: {
  131. type: String,
  132. default: "",
  133. },
  134. fileSize: {
  135. type: Number,
  136. default: null,
  137. },
  138. fileName: {
  139. type: String,
  140. default: "",
  141. },
  142. line_1: {
  143. type: String,
  144. default: "",
  145. },
  146. line_2: {
  147. type: String,
  148. default: "",
  149. },
  150. line_3: {
  151. type: String,
  152. default: "",
  153. },
  154. thumbnail: {
  155. type: String,
  156. default: "",
  157. },
  158. uploadType: {
  159. type: Number,
  160. default: null,
  161. },
  162. type: {
  163. type: Number,
  164. default: null,
  165. },
  166. isPrivate: {
  167. type: Number,
  168. default: 0,
  169. },
  170. // 使用一个变量控制显示,默认为true显示所有控制项
  171. showControl: {
  172. type: Boolean,
  173. default: true,
  174. }
  175. },
  176. data() {
  177. return {
  178. videoName:'',
  179. isHidden : false,
  180. localUploadType: this.uploadType,
  181. duration: 0,
  182. fileId: "",
  183. uploadTypeOptions: [
  184. { dictLabel: "线路一", dictValue: 1 }, // 腾讯pcdn
  185. { dictLabel: "线路二", dictValue: 2 }, // 华为云obs
  186. // { dictLabel: "华为云VOD", dictValue: 4 },
  187. // { dictLabel: "腾讯云VOD", dictValue: 5 },
  188. ],
  189. fileList: [],
  190. txProgress: 0,
  191. hwProgress: 0,
  192. uploadLoading: false,
  193. uploadKey: 0,
  194. // 视频库选择相关数据
  195. libraryOpen: false,
  196. libraryLoading: false,
  197. libraryTotal: 0,
  198. libraryList: [],
  199. selectedVideo: null,
  200. libraryQueryParams: {
  201. pageNum: 1,
  202. pageSize: 10,
  203. resourceName: null,
  204. liveId: -1,
  205. videoUrl: null,
  206. videoType: -1,
  207. sort: null,
  208. remark: null,
  209. finishStatus:1
  210. },
  211. liveQueryParams: {
  212. pageNum: 1,
  213. pageSize: 10,
  214. liveId: -1,
  215. videoUrl: null,
  216. videoType: -1,
  217. sort: null,
  218. remark: null,
  219. },
  220. };
  221. },
  222. mounted() {
  223. this.reset();
  224. },
  225. watch: {
  226. uploadType(newType) {
  227. this.localUploadType = newType;
  228. },
  229. },
  230. methods: {
  231. /** 查询直播视频列表 */
  232. getList() {
  233. this.libraryLoading = true;
  234. listLiveVideo(this.libraryQueryParams).then(response => {
  235. this.libraryList = response.rows;
  236. this.libraryTotal = response.total;
  237. this.libraryLoading = false;
  238. });
  239. },
  240. // 打开视频库对话框
  241. openVideoLibrary() {
  242. this.libraryOpen = true;
  243. this.selectedVideo = null;
  244. this.getList();
  245. },
  246. handleChange(file, fileList) {
  247. this.fileList = fileList;
  248. this.getVideoDuration(file.raw);
  249. },
  250. getVideoDuration(file) {
  251. const video = document.createElement("video");
  252. video.preload = "metadata";
  253. video.onloadedmetadata = () => {
  254. window.URL.revokeObjectURL(video.src);
  255. this.duration = parseInt(video.duration.toFixed(2));
  256. console.log("视频时长=========>",this.duration);
  257. this.$emit("video-duration", this.duration);
  258. console.log("文件大小=====>",file.size);
  259. this.$emit("update:fileSize", file.size);
  260. };
  261. video.src = URL.createObjectURL(file);
  262. },
  263. async submitUpload() {
  264. if (this.fileList.length < 1) {
  265. return this.$message.error("请先选取视频,再进行上传");
  266. }
  267. //同时上传个线路
  268. await this.uploadVideoToTxPcdn();
  269. this.$emit("update:fileName", this.fileList[0].name);
  270. },
  271. //获取第一帧封面
  272. async getFirstThumbnail(){
  273. const file = this.fileList[0].raw;
  274. getThumbnail(file).then(response => {
  275. console.log("获取到第一帧为封面======>",response.url)
  276. this.$emit("update:thumbnail", response.url);
  277. })
  278. },
  279. //更新华为线路进度条
  280. // updateHwProgress(progress) {
  281. // this.hwProgress = progress;
  282. // },
  283. //更新腾讯线路进度条
  284. updateTxProgress(progressData) {
  285. this.txProgress = Math.round(progressData.percent * 100);
  286. },
  287. //上传腾讯云Pcdn
  288. async uploadVideoToTxPcdn() {
  289. try {
  290. const file = this.fileList[0].raw;
  291. const data = await uploadObject(file, this.updateTxProgress,this.type);
  292. console.log("腾讯COS返回========>",data);
  293. console.log("isPrivate=======>",this.isPrivate)
  294. let line_1='' ;
  295. if (this.isPrivate===0){
  296. line_1 = `${process.env.VUE_APP_VIDEO_LINE_1}${data.urlPath}`;
  297. }else {
  298. line_1 = `${process.env.VUE_APP_VIDEO_LINE_1}${data.urlPath}`;
  299. }
  300. line_1 = line_1.replace(/\.mp4$/, '.m3u8');
  301. let urlPathWithoutFirstSlash = data.urlPath.substring(1);
  302. this.$emit("update:fileKey", urlPathWithoutFirstSlash);
  303. console.log("文件key",urlPathWithoutFirstSlash);
  304. console.log("组装URL========>",line_1);
  305. this.$emit("update:videoUrl", line_1);
  306. this.$emit("update:line_1", line_1);
  307. this.$emit("change", line_1,line_1);
  308. // this.$emit("update:line_2", line_2);
  309. this.$message.success("线路一上传成功");
  310. } catch (error) {
  311. this.$message.error("线路一上传失败");
  312. }
  313. },
  314. //上传华为云Obs
  315. async uploadVideoToHwObs() {
  316. try {
  317. const file = this.fileList[0].raw;
  318. const data = await uploadToOBS(file, this.updateHwProgress,this.type);
  319. console.log("华为OBS返回========>",data);
  320. let line_2='' ;
  321. if (this.isPrivate===0){
  322. line_2 = `${process.env.VUE_APP_VIDEO_LINE_2}/${data.urlPath}`;
  323. }else {
  324. line_2 = `${process.env.VUE_APP_VIDEO_LINE_2}/${data.urlPath}`;
  325. }
  326. // this.$emit("update:videoUrl", data);
  327. this.$emit("update:line_2", line_2);
  328. this.$message.success("线路二上传成功");
  329. } catch (error) {
  330. this.$message.error("线路二上传失败");
  331. }
  332. },
  333. handleRemove(file, fileList) {
  334. console.log(file, fileList.length);
  335. },
  336. reset() {
  337. // 重置内部状态
  338. this.txProgress = 0;
  339. this.fileList = [];
  340. this.$refs.upload.clearFiles();
  341. this.uploadKey++;
  342. },
  343. /** 查询视频库列表 */
  344. getLibraryList() {
  345. this.libraryLoading = true;
  346. // listVideoResource(this.libraryQueryParams).then(response => {
  347. // this.libraryList = response.rows;
  348. // this.libraryTotal = response.total;
  349. // this.libraryLoading = false;
  350. // });
  351. },
  352. /** 搜索视频库按钮操作 */
  353. handleLibraryQuery() {
  354. this.libraryQueryParams.pageNum = 1;
  355. this.getList();
  356. },
  357. /** 重置视频库查询按钮操作 */
  358. resetLibraryQuery() {
  359. this.libraryQueryParams = {
  360. pageNum: 1,
  361. pageSize: 10,
  362. resourceName: null,
  363. liveId: -1,
  364. videoUrl: null,
  365. videoType: -1,
  366. sort: null,
  367. remark: null,
  368. finishStatus:1
  369. };
  370. this.handleLibraryQuery();
  371. },
  372. /** 视频库选择行点击 */
  373. handleLibrarySelect(row) {
  374. this.selectedVideo = row;
  375. },
  376. /** 格式化视频时长 */
  377. formatDuration(seconds) {
  378. if (!seconds) return '00:00';
  379. const minutes = Math.floor(seconds / 60);
  380. const remainingSeconds = seconds % 60;
  381. return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
  382. },
  383. /** 确认选择视频 */
  384. confirmVideoSelection() {
  385. if (!this.selectedVideo) {
  386. this.$message.warning("请选择一个视频");
  387. return;
  388. }
  389. // 更新组件内部数据
  390. this.$emit("update:fileName", this.selectedVideo.fileName);
  391. this.$emit("update:thumbnail", this.selectedVideo.thumbnail);
  392. this.$emit("update:line_1", this.selectedVideo.lineOne);
  393. this.$emit("update:fileSize", this.selectedVideo.fileSize);
  394. this.$emit("update:fileKey", this.selectedVideo.fileKey);
  395. this.$emit("update:uploadType", this.selectedVideo.uploadType);
  396. this.$emit("video-duration", this.selectedVideo.duration);
  397. // 设置预览URL
  398. this.$emit("update:videoUrl", this.selectedVideo.videoUrl);
  399. this.$emit("change", this.selectedVideo.videoUrl,this.selectedVideo.lineOne);
  400. this.libraryOpen = false;
  401. },
  402. /** 取消视频选择 */
  403. cancelVideoSelection() {
  404. this.libraryOpen = false;
  405. this.selectedVideo = null;
  406. }
  407. }
  408. };
  409. </script>
  410. <style>
  411. .progress-container {
  412. margin-bottom: 5px; /* 进度条之间的间距 */
  413. }
  414. .progress-label {
  415. display: block;
  416. font-weight: bold;
  417. font-size: 13px;
  418. color: #303331; /* 标签颜色,可以根据需要调整 */
  419. }
  420. /* 视频库选择对话框样式 */
  421. .library-search {
  422. margin-bottom: 15px;
  423. }
  424. .el-table .el-table__row:hover {
  425. cursor: pointer;
  426. }
  427. </style>