index.vue 9.3 KB

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