index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="10" class="mb8">
  4. <el-col :span="1.5">
  5. <el-button
  6. type="primary"
  7. plain
  8. icon="el-icon-plus"
  9. size="mini"
  10. @click="handleAdd"
  11. v-hasPermi="['live:liveVideo:add']"
  12. >新增</el-button>
  13. </el-col>
  14. <el-col :span="1.5">
  15. <el-button
  16. type="danger"
  17. plain
  18. icon="el-icon-delete"
  19. size="mini"
  20. :disabled="multiple"
  21. @click="handleDelete"
  22. v-hasPermi="['live:liveVideo:remove']"
  23. >删除</el-button>
  24. </el-col>
  25. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  26. </el-row>
  27. <el-table border v-loading="loading" :data="liveVideoList" @selection-change="handleSelectionChange">
  28. <el-table-column type="selection" width="55" align="center" />
  29. <el-table-column label="编号" align="center" prop="videoId" />
  30. <el-table-column label="视频名称" align="center" prop="remark" />
  31. <el-table-column label="视频地址" align="center" prop="videoUrl">
  32. <template slot-scope="scope">
  33. <video
  34. :src="scope.row.videoUrl"
  35. controls
  36. controlsList="nodownload"
  37. class="video-player"
  38. @contextmenu.prevent
  39. ></video>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="时长" align="center" prop="duration" :formatter="formatDuration"/>
  43. <el-table-column label="转码状态" align="center" prop="finishStatus">
  44. <template slot-scope="scope">
  45. <el-tag v-if="scope.row.finishStatus == 1">转码成功</el-tag>
  46. <el-tag v-else-if="scope.row.finishStatus == 0">转码中</el-tag>
  47. <el-tag v-else>---</el-tag>
  48. </template>
  49. </el-table-column>
  50. </el-table>
  51. <pagination
  52. v-show="total>0"
  53. :total="total"
  54. :page.sync="queryParams.pageNum"
  55. :limit.sync="queryParams.pageSize"
  56. @pagination="getList"
  57. />
  58. <!-- 添加或修改直播视频对话框 -->
  59. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  60. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  61. <live-video-upload
  62. :type = "1"
  63. :isPrivate = "isPrivate"
  64. :fileKey.sync = "form.fileKey"
  65. :fileSize.sync = "form.fileSize"
  66. :videoUrl.sync="form.videoUrl"
  67. :fileName.sync="form.fileName"
  68. :line_1.sync="form.lineOne"
  69. :thumbnail.sync="form.thumbnail"
  70. :uploadType.sync="form.uploadType"
  71. :isTranscode.sync="form.isTranscode"
  72. :transcodeFileKey.sync="form.transcodeFileKey"
  73. @video-duration="handleVideoDuration"
  74. @change="handleVideoChange"
  75. ref="videoUpload"
  76. append-to-body
  77. />
  78. </el-form>
  79. <div slot="footer" class="dialog-footer">
  80. <el-button type="primary" @click="submitForm">确 定</el-button>
  81. <el-button @click="cancel">取 消</el-button>
  82. </div>
  83. </el-dialog>
  84. </div>
  85. </template>
  86. <script>
  87. import { listLiveVideo, getLiveVideo, delLiveVideo, addLiveVideo, updateLiveVideo, exportLiveVideo } from "@/api/live/liveVideo";
  88. import LiveVideoUpload from "@/components/LiveVideoUpload/index.vue";
  89. export default {
  90. name: "LiveVideo",
  91. components: { LiveVideoUpload },
  92. data() {
  93. return {
  94. //字典
  95. videoTypeOptions: [],
  96. // 遮罩层
  97. loading: true,
  98. // 导出遮罩层
  99. exportLoading: false,
  100. // 选中数组
  101. ids: [],
  102. // 非单个禁用
  103. single: true,
  104. // 非多个禁用
  105. multiple: true,
  106. // 显示搜索条件
  107. showSearch: true,
  108. // 总条数
  109. total: 0,
  110. // 直播视频表格数据
  111. liveVideoList: [],
  112. // 弹出层标题
  113. title: "",
  114. // 是否显示弹出层
  115. open: false,
  116. // 查询参数
  117. queryParams: {
  118. pageNum: 1,
  119. pageSize: 10,
  120. liveId: -1,
  121. videoUrl: null,
  122. videoType: -1,
  123. sort: null,
  124. },
  125. // 表单参数
  126. form: {
  127. uploadType: 1,
  128. isTranscode:0,
  129. transcodeFileKey:null
  130. },
  131. // 表单校验
  132. rules: {
  133. },
  134. isPrivate:null,
  135. };
  136. },
  137. created() {
  138. this.getList();
  139. },
  140. methods: {
  141. handleVideoDuration(duration) {
  142. this.form.duration = duration;
  143. },
  144. handleVideoChange(videoUrl,lineOne){
  145. this.videoUrl = videoUrl;
  146. this.form.videoUrl = videoUrl;
  147. console.log(this.videoUrl)
  148. },
  149. // 操作日志类型字典翻译
  150. formatDuration(row, column) {
  151. if(row.duration == null) return "00:00"
  152. const h = Math.floor(row.duration / 3600);
  153. const m = Math.floor((row.duration % 3600) / 60);
  154. const s = Math.floor(row.duration % 60);
  155. // 补零处理
  156. const format = (num) => num.toString().padStart(2, '0');
  157. return h > 0
  158. ? `${h}:${format(m)}:${format(s)}`
  159. : `${format(m)}:${format(s)}`;
  160. },
  161. /** 查询直播视频列表 */
  162. getList() {
  163. this.loading = true;
  164. listLiveVideo(this.queryParams).then(response => {
  165. this.liveVideoList = response.rows;
  166. this.liveVideoList.forEach(item => {
  167. item.videoUrl = item.videoUrl.replace(".m3u8", ".mp4");
  168. });
  169. this.total = response.total;
  170. this.loading = false;
  171. });
  172. },
  173. videoTypeFormatter(row, column) {
  174. return this.selectDictLabel(this.videoTypeOptions, row.status);
  175. },
  176. // 取消按钮
  177. cancel() {
  178. this.open = false;
  179. this.reset();
  180. },
  181. // 表单重置
  182. reset() {
  183. this.form = {
  184. videoId: null,
  185. liveId: null,
  186. videoUrl: null,
  187. videoType: null,
  188. sort: null,
  189. createTime: null,
  190. createBy: null,
  191. updateBy: null,
  192. updateTime: null,
  193. remark: null
  194. };
  195. this.resetForm("form");
  196. },
  197. /** 搜索按钮操作 */
  198. handleQuery() {
  199. this.queryParams.pageNum = 1;
  200. this.getList();
  201. },
  202. /** 重置按钮操作 */
  203. resetQuery() {
  204. this.resetForm("queryForm");
  205. this.handleQuery();
  206. },
  207. // 多选框选中数据
  208. handleSelectionChange(selection) {
  209. this.ids = selection.map(item => item.videoId)
  210. this.single = selection.length!==1
  211. this.multiple = !selection.length
  212. },
  213. /** 新增按钮操作 */
  214. handleAdd() {
  215. this.reset();
  216. this.open = true;
  217. this.title = "添加直播视频";
  218. this.videoUrl = '';
  219. setTimeout(() => {
  220. this.$refs.videoUpload.reset();
  221. }, 500);
  222. },
  223. /** 修改按钮操作 */
  224. handleUpdate(row) {
  225. this.reset();
  226. const videoId = row.videoId || this.ids
  227. getLiveVideo(videoId).then(response => {
  228. this.form = response.data;
  229. this.open = true;
  230. this.title = "修改直播视频";
  231. });
  232. },
  233. /** 提交按钮 */
  234. submitForm() {
  235. this.$refs["form"].validate(valid => {
  236. if (valid) {
  237. this.form.videoType = -1;
  238. this.form.liveId = -1;
  239. this.form.remark = this.form.fileName;
  240. if(this.form.videoUrl == null || this.form.videoUrl == "") {
  241. this.msgError("请上传视频");
  242. return;
  243. }
  244. this.form.videoUrl = this.form.videoUrl.replace('.mp4', '.m3u8');
  245. addLiveVideo(this.form).then(response => {
  246. this.msgSuccess("新增成功");
  247. this.open = false;
  248. this.getList();
  249. this.reset();
  250. });
  251. }
  252. });
  253. },
  254. /** 删除按钮操作 */
  255. handleDelete(row) {
  256. const videoIds = row.videoId || this.ids;
  257. this.$confirm('是否确认删除直播视频编号为"' + videoIds + '"的数据项?', "警告", {
  258. confirmButtonText: "确定",
  259. cancelButtonText: "取消",
  260. type: "warning"
  261. }).then(function() {
  262. return delLiveVideo(videoIds);
  263. }).then(() => {
  264. this.getList();
  265. this.msgSuccess("删除成功");
  266. }).catch(() => {});
  267. },
  268. /** 导出按钮操作 */
  269. handleExport() {
  270. const queryParams = this.queryParams;
  271. this.$confirm('是否确认导出所有直播视频数据项?', "警告", {
  272. confirmButtonText: "确定",
  273. cancelButtonText: "取消",
  274. type: "warning"
  275. }).then(() => {
  276. this.exportLoading = true;
  277. return exportLiveVideo(queryParams);
  278. }).then(response => {
  279. this.download(response.msg);
  280. this.exportLoading = false;
  281. }).catch(() => {});
  282. }
  283. }
  284. };
  285. </script>
  286. <style scoped>
  287. .video-player {
  288. width: 100%;
  289. height: 100%;
  290. object-fit: cover;
  291. }
  292. </style>