index.vue 8.0 KB

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