index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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="liveName">
  5. <el-input
  6. v-model="queryParams.liveName"
  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="primary" 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:live:add']"
  27. >新增</el-button>
  28. </el-col>
  29. <el-col :span="1.5">
  30. <el-button
  31. type="success"
  32. plain
  33. icon="el-icon-edit"
  34. size="mini"
  35. :disabled="single"
  36. @click="handleUpdate"
  37. v-hasPermi="['live:live:edit']"
  38. >修改</el-button>
  39. </el-col>
  40. <el-col :span="1.5">
  41. <el-button
  42. type="warning"
  43. plain
  44. icon="el-icon-download"
  45. size="mini"
  46. :loading="exportLoading"
  47. @click="handleExport"
  48. v-hasPermi="['live:live:export']"
  49. >导出</el-button>
  50. </el-col>
  51. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  52. </el-row>
  53. <el-table border v-loading="loading" :data="liveList">
  54. <el-table-column label="直播封面" align="center" prop="liveImgUrl" width="180">
  55. <template slot-scope="scope">
  56. <el-image style="width: 180px;" :src="scope.row.liveImgUrl" mode="aspectFill" :preview-src-list="[scope.row.liveImgUrl]" />
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="直播名称" align="center" prop="liveName" />
  60. <el-table-column label="显示类型" align="center" prop="showType">
  61. <template slot-scope="scope">
  62. <el-tag v-if="scope.row.showType == 1">横屏</el-tag>
  63. <el-tag v-if="scope.row.showType == 2">竖屏</el-tag>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="直播状态" align="center" prop="status">
  67. <template slot-scope="scope">
  68. <el-tag v-if="scope.row.status == 1">待直播</el-tag>
  69. <el-tag v-if="scope.row.status == 2">直播中</el-tag>
  70. <el-tag v-if="scope.row.status == 3">已结束</el-tag>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="主播ID" align="center" prop="anchorId" />
  74. <el-table-column label="直播类型" align="center" prop="liveType">
  75. <template slot-scope="scope">
  76. <el-tag v-if="scope.row.liveType == 1">直播</el-tag>
  77. <el-tag v-if="scope.row.liveType == 2">录播</el-tag>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="开始时间" align="center" prop="startTime" width="180" />
  81. <el-table-column label="结束时间" align="center" prop="finishTime" width="180" />
  82. <el-table-column label="上下架" align="center" prop="isShow">
  83. <template slot-scope="scope">
  84. <el-tag v-if="scope.row.isShow == 1">上架</el-tag>
  85. <el-tag v-if="scope.row.isShow == 2">下架</el-tag>
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  89. <template slot-scope="scope">
  90. <el-button
  91. size="mini"
  92. type="text"
  93. icon="el-icon-edit"
  94. @click="handleUpdate(scope.row)"
  95. v-hasPermi="['live:live:edit']"
  96. >修改</el-button>
  97. <el-button
  98. size="mini"
  99. type="text"
  100. icon="el-icon-delete"
  101. @click="handleDelete(scope.row)"
  102. v-hasPermi="['live:live:remove']"
  103. >删除</el-button>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <pagination
  108. v-show="total>0"
  109. :total="total"
  110. :page.sync="queryParams.pageNum"
  111. :limit.sync="queryParams.pageSize"
  112. @pagination="getList"
  113. />
  114. <!-- 添加或修改直播对话框 -->
  115. <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
  116. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  117. <el-form-item label="直播名称" prop="liveName">
  118. <el-input v-model="form.liveName" placeholder="请输入直播名称" />
  119. </el-form-item>
  120. <el-form-item label="显示类型" prop="showType">
  121. <el-radio-group v-model="form.showType">
  122. <el-radio :label="1">横屏</el-radio>
  123. <el-radio :label="2">竖屏</el-radio>
  124. </el-radio-group>
  125. </el-form-item>
  126. <el-form-item label="直播类型" prop="liveType">
  127. <el-radio-group disabled v-model="form.liveType">
  128. <el-radio :label="1">直播</el-radio>
  129. <el-radio :label="2">录播</el-radio>
  130. </el-radio-group>
  131. </el-form-item>
  132. <el-form-item label="直播描述" prop="liveDesc">
  133. <Editor ref="myeditor" :height="300" @on-text-change="updateText"/>
  134. <!-- <Editor v-model="form.liveDesc" :height="300" placeholder="直播描述" />-->
  135. </el-form-item>
  136. <el-form-item label="录播视屏" prop="videoUrl">
  137. <file-upload v-model="form.videoUrl" :limit="1" :file-size="3" :file-type="['mp4']" />
  138. <el-button @click="getVideoDuration" v-loading="timeLoading">读取视屏时长</el-button>
  139. <p style="margin: 0;padding: 0;" v-loading="timeLoading">视屏时长:<span style="color: #ff4949;">{{form.durationTime}}</span></p>
  140. </el-form-item>
  141. <el-form-item label="开始时间" prop="startTime">
  142. <el-date-picker size="small"
  143. v-model="form.startTime"
  144. @change="timeChange"
  145. type="datetime"
  146. value-format="yyyy-MM-dd HH:mm:ss"
  147. placeholder="选择开始时间">
  148. </el-date-picker>
  149. </el-form-item>
  150. <el-form-item label="结束时间" prop="finishTime" v-loading="timeLoading">
  151. <el-date-picker size="small"
  152. v-model="form.finishTime"
  153. type="datetime"
  154. disabled
  155. value-format="yyyy-MM-dd HH:mm:ss"
  156. placeholder="视屏播放结束">
  157. </el-date-picker>
  158. </el-form-item>
  159. <el-form-item label="直播封面" prop="liveImgUrl">
  160. <image-upload v-model="form.liveImgUrl" :limit="1" />
  161. </el-form-item>
  162. <el-form-item label="上下架" prop="isShow">
  163. <el-radio-group v-model="form.isShow">
  164. <el-radio :label="1">上架</el-radio>
  165. <el-radio :label="2">下架</el-radio>
  166. </el-radio-group>
  167. </el-form-item>
  168. </el-form>
  169. <div slot="footer" class="dialog-footer">
  170. <el-button type="primary" @click="submitForm">确 定</el-button>
  171. <el-button @click="cancel">取 消</el-button>
  172. </div>
  173. </el-dialog>
  174. </div>
  175. </template>
  176. <script>
  177. import { listLive, getLive, delLive, addLive, updateLive, exportLive } from "@/api/live/live";
  178. import Editor from '@/components/Editor/wang';
  179. import articleDetails from "@/views/components/his/doctorArticleDetails.vue";
  180. export default {
  181. name: "Live",
  182. components: { Editor },
  183. data() {
  184. return {
  185. baseUrl: process.env.VUE_APP_BASE_API,
  186. // 遮罩层
  187. loading: true,
  188. // 导出遮罩层
  189. exportLoading: false,
  190. // 选中数组
  191. ids: [],
  192. // 非单个禁用
  193. single: true,
  194. // 非多个禁用
  195. multiple: true,
  196. timeLoading: false,
  197. // 显示搜索条件
  198. showSearch: true,
  199. // 总条数
  200. total: 0,
  201. // 直播表格数据
  202. liveList: [],
  203. // 弹出层标题
  204. title: "",
  205. // 是否显示弹出层
  206. open: false,
  207. // 查询参数
  208. queryParams: {
  209. pageNum: 1,
  210. pageSize: 10,
  211. liveName: null,
  212. liveDesc: null,
  213. showType: null,
  214. status: null,
  215. anchorId: null,
  216. liveType: null,
  217. startTime: null,
  218. finishTime: null,
  219. liveImgUrl: null,
  220. liveConfig: null,
  221. isShow: null,
  222. isDel: null,
  223. qwQrCode: null,
  224. rtmpUrl: null,
  225. },
  226. // 表单参数
  227. form: {},
  228. // 表单校验
  229. rules: {
  230. liveName: [
  231. { required: true, message: "不能为空", trigger: "burl" }
  232. ],
  233. showType: [
  234. { required: true, message: "不能为空", trigger: "burl" }
  235. ],
  236. liveType: [
  237. { required: true, message: "不能为空", trigger: "burl" }
  238. ],
  239. videoUrl: [
  240. { required: true, message: "不能为空", trigger: "burl" }
  241. ],
  242. startTime: [
  243. { required: true, message: "不能为空", trigger: "burl" }
  244. ],
  245. liveImgUrl: [
  246. { required: true, message: "不能为空", trigger: "burl" }
  247. ],
  248. isShow: [
  249. { required: true, message: "不能为空", trigger: "change" }
  250. ],
  251. }
  252. };
  253. },
  254. created() {
  255. this.getList();
  256. },
  257. methods: {
  258. /** 查询直播列表 */
  259. getList() {
  260. this.loading = true;
  261. listLive(this.queryParams).then(response => {
  262. this.liveList = response.rows;
  263. this.total = response.total;
  264. this.loading = false;
  265. });
  266. },
  267. urlChange(url) {
  268. this.form.videoUrl = url;
  269. this.getVideoDuration();
  270. },
  271. getVideoDuration() {
  272. this.timeLoading = true;
  273. const videoElement = document.createElement('video');
  274. videoElement.src = this.form.videoUrl;
  275. videoElement.onloadedmetadata = () => {
  276. this.form.duration = Math.floor(videoElement.duration); // 秒
  277. this.form.durationTime = this.secondsToTime(this.form.duration);
  278. this.timeChange();
  279. this.timeLoading = false;
  280. };
  281. },
  282. changeDuration(e){
  283. this.form.duration = e.duration;
  284. this.form.durationTime = e.time;
  285. this.$forceUpdate();
  286. this.timeChange();
  287. },
  288. timeChange(){
  289. if(!this.form.startTime) return;
  290. if(!this.form.duration) return;
  291. console.info(this.form.startTime)
  292. const startDateTime = new Date(this.form.startTime);
  293. // 将视频时长(秒)加到开始时间
  294. const endDateTime = new Date(startDateTime.getTime() + this.form.duration * 1000); // 毫秒为单位
  295. // 格式化为年月日 时分秒
  296. this.form.finishTime = this.formatDate(endDateTime);
  297. this.$forceUpdate();
  298. },
  299. // 将秒数转换为时分秒
  300. secondsToTime(seconds) {
  301. const hours = Math.floor(seconds / 3600);
  302. const minutes = Math.floor((seconds % 3600) / 60);
  303. const secs = Math.floor(seconds % 60);
  304. return `${this.pad(hours)}:${this.pad(minutes)}:${this.pad(secs)}`;
  305. },
  306. // 补零处理
  307. pad(number) {
  308. return number < 10 ? `0${number}` : number;
  309. },
  310. // 格式化日期为 年月日 时分秒
  311. formatDate(date) {
  312. const year = date.getFullYear();
  313. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  314. const day = date.getDate().toString().padStart(2, '0');
  315. const hours = date.getHours().toString().padStart(2, '0');
  316. const minutes = date.getMinutes().toString().padStart(2, '0');
  317. const seconds = date.getSeconds().toString().padStart(2, '0');
  318. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  319. },
  320. // 取消按钮
  321. cancel() {
  322. this.open = false;
  323. this.reset();
  324. },
  325. // 表单重置
  326. reset() {
  327. this.form = {
  328. showType: 1,
  329. liveType: 2,
  330. isShow: 1,
  331. };
  332. this.resetForm("form");
  333. },
  334. /** 搜索按钮操作 */
  335. handleQuery() {
  336. this.queryParams.pageNum = 1;
  337. this.getList();
  338. },
  339. /** 重置按钮操作 */
  340. resetQuery() {
  341. this.resetForm("queryForm");
  342. this.handleQuery();
  343. },
  344. // 多选框选中数据
  345. handleSelectionChange(selection) {
  346. this.ids = selection.map(item => item.liveId)
  347. this.single = selection.length!==1
  348. this.multiple = !selection.length
  349. },
  350. /** 新增按钮操作 */
  351. handleAdd() {
  352. this.reset();
  353. this.open = true;
  354. setTimeout(() => {
  355. this.$refs.myeditor.setText("");
  356. }, 100);
  357. this.title = "添加直播";
  358. },
  359. updateText(text){
  360. this.form.liveDesc=text
  361. },
  362. /** 修改按钮操作 */
  363. handleUpdate(row) {
  364. this.reset();
  365. const liveId = row.liveId || this.ids
  366. getLive(liveId).then(response => {
  367. this.form = response.data;
  368. if(this.form.duration){
  369. this.form.durationTime = this.secondsToTime(this.form.duration)
  370. }
  371. setTimeout(() => {
  372. if(this.form.liveDesc==null){
  373. this.$refs.myeditor.setText("");
  374. }else{
  375. this.$refs.myeditor.setText(this.form.liveDesc);
  376. }
  377. }, 1);
  378. this.open = true;
  379. this.title = "修改直播";
  380. });
  381. },
  382. /** 提交按钮 */
  383. submitForm() {
  384. this.$refs["form"].validate(valid => {
  385. if (valid) {
  386. if (this.form.liveId != null) {
  387. updateLive(this.form).then(response => {
  388. this.msgSuccess("修改成功");
  389. this.open = false;
  390. this.getList();
  391. });
  392. } else {
  393. addLive(this.form).then(response => {
  394. this.msgSuccess("新增成功");
  395. this.open = false;
  396. this.getList();
  397. });
  398. }
  399. }
  400. });
  401. },
  402. /** 删除按钮操作 */
  403. handleDelete(row) {
  404. const liveIds = row.liveId || this.ids;
  405. this.$confirm('是否确认删除直播编号为"' + liveIds + '"的数据项?', "警告", {
  406. confirmButtonText: "确定",
  407. cancelButtonText: "取消",
  408. type: "warning"
  409. }).then(function() {
  410. return delLive(liveIds);
  411. }).then(() => {
  412. this.getList();
  413. this.msgSuccess("删除成功");
  414. }).catch(() => {});
  415. },
  416. /** 导出按钮操作 */
  417. handleExport() {
  418. const queryParams = this.queryParams;
  419. this.$confirm('是否确认导出所有直播数据项?', "警告", {
  420. confirmButtonText: "确定",
  421. cancelButtonText: "取消",
  422. type: "warning"
  423. }).then(() => {
  424. this.exportLoading = true;
  425. return exportLive(queryParams);
  426. }).then(response => {
  427. this.download(response.msg);
  428. this.exportLoading = false;
  429. }).catch(() => {});
  430. }
  431. }
  432. };
  433. </script>