index.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="视频名称" prop="videoName">
  5. <el-input
  6. v-model="queryParams.videoName"
  7. placeholder="请输入视频名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="分类" prop="category">
  13. <el-select
  14. v-model="queryParams.category"
  15. placeholder="请选择分类"
  16. clearable
  17. filterable
  18. style="width: 200px"
  19. >
  20. <el-option
  21. v-for="item in categoryOptions"
  22. :key="item.dictValue"
  23. :label="item.dictLabel"
  24. :value="item.dictValue"
  25. />
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item label="备注" prop="remark">
  29. <el-input
  30. v-model="queryParams.remark"
  31. placeholder="请输入备注"
  32. clearable
  33. @keyup.enter.native="handleQuery"
  34. />
  35. </el-form-item>
  36. <el-form-item label="可见公司" prop="companyId">
  37. <el-select
  38. v-model="queryParams.companyId"
  39. placeholder="请选择可见公司"
  40. clearable
  41. filterable
  42. style="width: 200px"
  43. >
  44. <el-option
  45. v-for="company in allCompanyOptions"
  46. :key="company.companyId"
  47. :label="company.companyName"
  48. :value="company.companyId"
  49. />
  50. </el-select>
  51. </el-form-item>
  52. <el-form-item>
  53. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  54. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  55. </el-form-item>
  56. </el-form>
  57. <el-row :gutter="10" class="mb8">
  58. <el-col :span="1.5">
  59. <el-button
  60. type="primary"
  61. plain
  62. icon="el-icon-plus"
  63. size="mini"
  64. @click="handleAdd"
  65. v-hasPermi="['live:liveVideo:add']"
  66. >新增</el-button>
  67. </el-col>
  68. <el-col :span="1.5">
  69. <el-button
  70. type="danger"
  71. plain
  72. icon="el-icon-delete"
  73. size="mini"
  74. :disabled="multiple"
  75. @click="handleDelete"
  76. v-hasPermi="['live:liveVideo:remove']"
  77. >删除</el-button>
  78. </el-col>
  79. <el-col :span="1.5">
  80. <el-button
  81. type="warning"
  82. plain
  83. icon="el-icon-edit"
  84. size="mini"
  85. :disabled="multiple"
  86. @click="handleBatchUpdateCategory"
  87. >批量修改分类</el-button>
  88. </el-col>
  89. <el-col :span="1.5">
  90. <el-button
  91. type="primary"
  92. plain
  93. icon="el-icon-upload"
  94. size="mini"
  95. @click="handleBatchUpload"
  96. >批量上传视频</el-button>
  97. </el-col>
  98. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  99. </el-row>
  100. <el-table border v-loading="loading" :data="liveVideoList" @selection-change="handleSelectionChange">
  101. <el-table-column type="selection" width="55" align="center" />
  102. <el-table-column label="编号" align="center" prop="videoId" />
  103. <el-table-column label="视频名称" align="center" prop="videoName" />
  104. <el-table-column label="分类" align="center" prop="category" :formatter="categoryFormatter" />
  105. <el-table-column label="排序" align="center" prop="sort" />
  106. <el-table-column label="备注" align="center" prop="remark" />
  107. <el-table-column label="视频地址" align="center" prop="videoUrl">
  108. <template slot-scope="scope">
  109. <video
  110. :src="scope.row.videoUrl"
  111. controls
  112. controlsList="nodownload"
  113. class="video-player"
  114. @contextmenu.prevent
  115. ></video>
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="文件大小" align="center">
  119. <template slot-scope="scope">
  120. <span>{{ formatFileSize(scope.row.fileSize) }}</span>
  121. </template>
  122. </el-table-column>
  123. <el-table-column label="时长" align="center" prop="duration" :formatter="formatDuration"/>
  124. <el-table-column label="转码状态" align="center" prop="finishStatus">
  125. <template slot-scope="scope">
  126. <el-tag v-if="scope.row.finishStatus == 1">转码成功</el-tag>
  127. <el-tag v-else-if="scope.row.finishStatus == 0">转码中</el-tag>
  128. <el-tag v-else>---</el-tag>
  129. </template>
  130. </el-table-column>
  131. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250">
  132. <template slot-scope="scope">
  133. <el-button
  134. size="mini"
  135. type="text"
  136. icon="el-icon-edit"
  137. @click="handleUpdateVideoInfo(scope.row)"
  138. >修改</el-button>
  139. <el-button
  140. size="mini"
  141. type="text"
  142. icon="el-icon-edit"
  143. @click="handleUpdateCompanyIds(scope.row)"
  144. >修改公司范围</el-button>
  145. <el-button
  146. size="mini"
  147. type="text"
  148. icon="el-icon-upload"
  149. @click="handleReuploadVideo(scope.row)"
  150. >再次上传视频</el-button>
  151. </template>
  152. </el-table-column>
  153. </el-table>
  154. <pagination
  155. v-show="total>0"
  156. :total="total"
  157. :page.sync="queryParams.pageNum"
  158. :limit.sync="queryParams.pageSize"
  159. @pagination="getList"
  160. />
  161. <!-- 添加或修改直播视频对话框 -->
  162. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  163. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  164. <live-video-upload
  165. :type = "1"
  166. :isPrivate = "isPrivate"
  167. :fileKey.sync = "form.fileKey"
  168. :fileSize.sync = "form.fileSize"
  169. :videoUrl.sync="form.videoUrl"
  170. :fileName.sync="form.fileName"
  171. :line_1.sync="form.lineOne"
  172. :thumbnail.sync="form.thumbnail"
  173. :uploadType.sync="form.uploadType"
  174. :isTranscode.sync="form.isTranscode"
  175. :transcodeFileKey.sync="form.transcodeFileKey"
  176. @video-duration="handleVideoDuration"
  177. @change="handleVideoChange"
  178. ref="videoUpload"
  179. append-to-body
  180. />
  181. <el-form-item label="视频名称" prop="videoName">
  182. <el-input v-model="form.videoName" placeholder="请输入视频名称" />
  183. </el-form-item>
  184. <el-form-item label="分类" prop="category">
  185. <el-select
  186. v-model="form.category"
  187. placeholder="请选择分类"
  188. filterable
  189. style="width: 100%"
  190. >
  191. <el-option
  192. v-for="item in categoryOptions"
  193. :key="item.dictValue"
  194. :label="item.dictLabel"
  195. :value="item.dictValue"
  196. />
  197. </el-select>
  198. </el-form-item>
  199. <el-form-item label="排序" prop="sort">
  200. <el-input-number v-model="form.sort" :min="0" placeholder="请输入排序号" />
  201. </el-form-item>
  202. <el-form-item label="备注" prop="remark">
  203. <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
  204. </el-form-item>
  205. <el-form-item label="公司列表" prop="companyIds">
  206. <div style="margin-bottom: 10px;">
  207. <el-button size="mini" type="text" @click="selectAllCompanies">全选</el-button>
  208. <el-button size="mini" type="text" @click="unselectAllCompanies">全不选</el-button>
  209. <el-button size="mini" type="text" @click="reverseSelectCompanies">反选</el-button>
  210. <span style="margin-left: 20px; color: #909399; font-size: 12px;">
  211. 已选择 {{ form.companyIds ? form.companyIds.length : 0 }} 个公司
  212. </span>
  213. </div>
  214. <el-select
  215. v-model="form.companyIds"
  216. multiple
  217. filterable
  218. placeholder="请选择公司"
  219. style="width: 100%"
  220. collapse-tags
  221. :loading="companyOptionsLoading"
  222. >
  223. <el-option
  224. v-for="company in allCompanyOptions"
  225. :key="company.companyId"
  226. :label="company.companyName"
  227. :value="company.companyId"
  228. />
  229. </el-select>
  230. </el-form-item>
  231. </el-form>
  232. <div slot="footer" class="dialog-footer">
  233. <el-button type="primary" @click="submitForm">确 定</el-button>
  234. <el-button @click="cancel">取 消</el-button>
  235. </div>
  236. </el-dialog>
  237. <!-- 修改视频信息对话框 -->
  238. <el-dialog title="修改视频信息" :visible.sync="editVideoInfoDialog" width="800px" append-to-body>
  239. <el-form ref="editVideoInfoForm" :model="editVideoInfoForm" label-width="120px">
  240. <el-form-item label="视频名称" prop="videoName">
  241. <el-input v-model="editVideoInfoForm.videoName" placeholder="请输入视频名称" />
  242. </el-form-item>
  243. <el-form-item label="分类" prop="category">
  244. <el-select
  245. v-model="editVideoInfoForm.category"
  246. placeholder="请选择分类"
  247. filterable
  248. style="width: 100%"
  249. >
  250. <el-option
  251. v-for="item in categoryOptions"
  252. :key="item.dictValue"
  253. :label="item.dictLabel"
  254. :value="item.dictValue"
  255. />
  256. </el-select>
  257. </el-form-item>
  258. <el-form-item label="排序" prop="sort">
  259. <el-input-number v-model="editVideoInfoForm.sort" :min="0" placeholder="请输入排序号" />
  260. </el-form-item>
  261. <el-form-item label="备注" prop="remark">
  262. <el-input v-model="editVideoInfoForm.remark" type="textarea" placeholder="请输入备注" />
  263. </el-form-item>
  264. </el-form>
  265. <div slot="footer" class="dialog-footer">
  266. <el-button type="primary" @click="submitEditVideoInfo">确 定</el-button>
  267. <el-button @click="cancelEditVideoInfo">取 消</el-button>
  268. </div>
  269. </el-dialog>
  270. <!-- 修改公司范围对话框 -->
  271. <el-dialog title="修改公司范围" :visible.sync="editCompanyIdsDialog" width="800px" append-to-body>
  272. <el-form ref="editCompanyIdsForm" :model="editCompanyIdsForm" label-width="120px">
  273. <el-form-item label="视频名称">
  274. <el-input v-model="editCompanyIdsForm.videoName" :disabled="true" />
  275. </el-form-item>
  276. <el-form-item label="公司列表" prop="companyIds">
  277. <div style="margin-bottom: 10px;">
  278. <el-button size="mini" type="text" @click="selectAllCompaniesForEdit">全选</el-button>
  279. <el-button size="mini" type="text" @click="unselectAllCompaniesForEdit">全不选</el-button>
  280. <el-button size="mini" type="text" @click="reverseSelectCompaniesForEdit">反选</el-button>
  281. <span style="margin-left: 20px; color: #909399; font-size: 12px;">
  282. 已选择 {{ editCompanyIdsForm.companyIds ? editCompanyIdsForm.companyIds.length : 0 }} 个公司
  283. </span>
  284. </div>
  285. <el-select
  286. v-model="editCompanyIdsForm.companyIds"
  287. multiple
  288. filterable
  289. placeholder="请选择公司"
  290. style="width: 100%"
  291. collapse-tags
  292. :loading="companyOptionsLoading"
  293. >
  294. <el-option
  295. v-for="company in allCompanyOptions"
  296. :key="company.companyId"
  297. :label="company.companyName"
  298. :value="company.companyId"
  299. />
  300. </el-select>
  301. </el-form-item>
  302. </el-form>
  303. <div slot="footer" class="dialog-footer">
  304. <el-button type="primary" @click="submitEditCompanyIds">确 定</el-button>
  305. <el-button @click="cancelEditCompanyIds">取 消</el-button>
  306. </div>
  307. </el-dialog>
  308. <!-- 批量修改分类对话框 -->
  309. <el-dialog title="批量修改分类" :visible.sync="batchUpdateCategoryDialog" width="500px" append-to-body>
  310. <el-form ref="batchUpdateCategoryForm" :model="batchUpdateCategoryForm" label-width="100px">
  311. <el-form-item label="分类" prop="category">
  312. <el-select
  313. v-model="batchUpdateCategoryForm.category"
  314. placeholder="请选择分类"
  315. filterable
  316. style="width: 100%"
  317. >
  318. <el-option
  319. v-for="item in categoryOptions"
  320. :key="item.dictValue"
  321. :label="item.dictLabel"
  322. :value="item.dictValue"
  323. />
  324. </el-select>
  325. </el-form-item>
  326. </el-form>
  327. <div slot="footer" class="dialog-footer">
  328. <el-button type="primary" @click="submitBatchUpdateCategory">确 定</el-button>
  329. <el-button @click="cancelBatchUpdateCategory">取 消</el-button>
  330. </div>
  331. </el-dialog>
  332. <!-- 批量上传视频对话框 -->
  333. <el-dialog title="批量上传视频" :visible.sync="batchUploadDialog" width="900px" append-to-body>
  334. <div style="margin-bottom: 15px;">
  335. <el-upload
  336. ref="batchUpload"
  337. action="#"
  338. :http-request="handleBatchUploadRequest"
  339. accept=".mp4"
  340. :multiple="true"
  341. :auto-upload="false"
  342. :on-change="handleBatchFileChange"
  343. :on-remove="handleBatchFileRemove"
  344. :file-list="batchUploadFileList"
  345. >
  346. <el-button slot="trigger" size="small" type="primary">选择视频文件</el-button>
  347. <el-button style="margin-left: 10px;" size="small" type="success" @click="submitBatchUpload">开始上传</el-button>
  348. <div slot="tip" class="el-upload__tip">只能上传mp4文件,且每个文件不超过1G,可同时选择多个文件</div>
  349. </el-upload>
  350. </div>
  351. <div v-if="batchUploadVideos.length > 0" style="margin-top: 20px;">
  352. <div v-for="(video, index) in batchUploadVideos" :key="index" style="margin-bottom: 20px; border: 1px solid #e4e7ed; padding: 15px; border-radius: 4px;">
  353. <div style="margin-bottom: 10px; font-weight: bold;">{{ video.fileName }}</div>
  354. <div class="progress-container" style="width:100% !important;">
  355. <span class="progress-label">上传进度</span>
  356. <el-progress
  357. style="margin-top: 5px;"
  358. class="progress"
  359. :text-inside="true"
  360. :stroke-width="18"
  361. :percentage="video.progress"
  362. :status="video.status"
  363. ></el-progress>
  364. </div>
  365. <div v-if="video.status === 'success'" style="margin-top: 10px; color: #67c23a; font-size: 12px;">
  366. 上传成功
  367. </div>
  368. <div v-else-if="video.status === 'exception'" style="margin-top: 10px; color: #f56c6c; font-size: 12px;">
  369. 上传失败: {{ video.errorMsg || '未知错误' }}
  370. </div>
  371. </div>
  372. </div>
  373. <div slot="footer" class="dialog-footer">
  374. <el-button type="primary" @click="saveBatchUploadVideos" :disabled="!canSaveBatchUpload">保 存</el-button>
  375. <el-button @click="cancelBatchUpload">取 消</el-button>
  376. </div>
  377. </el-dialog>
  378. <!-- 重新上传视频对话框 -->
  379. <el-dialog title="重新上传视频" :visible.sync="reuploadVideoDialog" width="800px" append-to-body>
  380. <el-form ref="reuploadVideoForm" :model="reuploadVideoForm" label-width="120px">
  381. <el-form-item label="视频名称">
  382. <el-input v-model="reuploadVideoForm.videoName" :disabled="true" />
  383. </el-form-item>
  384. <live-video-upload
  385. :type="1"
  386. :isPrivate="isPrivate"
  387. :fileKey.sync="reuploadVideoForm.fileKey"
  388. :fileSize.sync="reuploadVideoForm.fileSize"
  389. :videoUrl.sync="reuploadVideoForm.videoUrl"
  390. :fileName.sync="reuploadVideoForm.fileName"
  391. :line_1.sync="reuploadVideoForm.lineOne"
  392. :thumbnail.sync="reuploadVideoForm.thumbnail"
  393. :uploadType.sync="reuploadVideoForm.uploadType"
  394. :isTranscode.sync="reuploadVideoForm.isTranscode"
  395. :transcodeFileKey.sync="reuploadVideoForm.transcodeFileKey"
  396. @video-duration="handleReuploadVideoDuration"
  397. @change="handleReuploadVideoChange"
  398. ref="reuploadVideoUpload"
  399. append-to-body
  400. />
  401. </el-form>
  402. <div slot="footer" class="dialog-footer">
  403. <el-button type="primary" @click="submitReuploadVideo">确 定</el-button>
  404. <el-button @click="cancelReuploadVideo">取 消</el-button>
  405. </div>
  406. </el-dialog>
  407. </div>
  408. </template>
  409. <script>
  410. import { listLiveVideo, getLiveVideo, delLiveVideo, addLiveVideo, updateLiveVideo, exportLiveVideo, batchUpdateCategory, updateVideoUrl, batchAddLiveVideo } from "@/api/live/liveVideo";
  411. import { getCompanyList } from "@/api/company/company";
  412. import LiveVideoUpload from "@/components/LiveVideoUpload/index.vue";
  413. import { uploadObject } from "@/utils/cos.js";
  414. export default {
  415. name: "LiveVideo",
  416. components: { LiveVideoUpload },
  417. data() {
  418. return {
  419. //字典
  420. videoTypeOptions: [],
  421. categoryOptions: [],
  422. // 遮罩层
  423. loading: true,
  424. // 导出遮罩层
  425. exportLoading: false,
  426. // 选中数组
  427. ids: [],
  428. // 非单个禁用
  429. single: true,
  430. // 非多个禁用
  431. multiple: true,
  432. // 显示搜索条件
  433. showSearch: true,
  434. // 总条数
  435. total: 0,
  436. // 直播视频表格数据
  437. liveVideoList: [],
  438. // 弹出层标题
  439. title: "",
  440. // 是否显示弹出层
  441. open: false,
  442. // 查询参数
  443. queryParams: {
  444. pageNum: 1,
  445. pageSize: 10,
  446. liveId: -1,
  447. videoUrl: null,
  448. videoType: -1,
  449. sort: null,
  450. videoName: null,
  451. remark: null,
  452. category: null,
  453. companyId: null,
  454. },
  455. // 表单参数
  456. form: {
  457. uploadType: 1,
  458. isTranscode:0,
  459. transcodeFileKey:null,
  460. companyIds: [],
  461. fileSize: null
  462. },
  463. // 表单校验
  464. rules: {
  465. category: [
  466. { required: true, message: "分类不能为空", trigger: "change" }
  467. ]
  468. },
  469. isPrivate:null,
  470. // 是否显示修改视频信息对话框
  471. editVideoInfoDialog: false,
  472. // 修改视频信息表单
  473. editVideoInfoForm: {
  474. videoId: null,
  475. videoName: '',
  476. category: '',
  477. sort: null,
  478. remark: ''
  479. },
  480. // 是否显示修改公司范围对话框
  481. editCompanyIdsDialog: false,
  482. // 修改公司范围表单
  483. editCompanyIdsForm: {
  484. videoId: null,
  485. videoName: '',
  486. companyIds: []
  487. },
  488. // 是否显示批量修改分类对话框
  489. batchUpdateCategoryDialog: false,
  490. // 批量修改分类表单
  491. batchUpdateCategoryForm: {
  492. category: ''
  493. },
  494. // 所有公司选项(用于下拉选择)
  495. allCompanyOptions: [],
  496. // 公司选项加载状态
  497. companyOptionsLoading: false,
  498. // 是否显示批量上传对话框
  499. batchUploadDialog: false,
  500. // 批量上传视频数据
  501. batchUploadVideos: [],
  502. // 批量上传文件列表
  503. batchUploadFileList: [],
  504. // 是否显示重新上传视频对话框
  505. reuploadVideoDialog: false,
  506. // 重新上传视频表单
  507. reuploadVideoForm: {
  508. videoId: null,
  509. videoName: '',
  510. videoUrl: '',
  511. fileKey: '',
  512. fileSize: null,
  513. fileName: '',
  514. lineOne: '',
  515. thumbnail: '',
  516. uploadType: 1,
  517. isTranscode: 0,
  518. transcodeFileKey: null
  519. }
  520. };
  521. },
  522. created() {
  523. this.getList();
  524. this.getAllCompanyOptions();
  525. this.getDicts("sys_live_video_category").then(response => {
  526. this.categoryOptions = response.data;
  527. });
  528. },
  529. mounted() {
  530. this.getAllCompanyOptions();
  531. },
  532. methods: {
  533. categoryFormatter(row, column) {
  534. return this.selectDictLabel(this.categoryOptions, row.category);
  535. },
  536. handleVideoDuration(duration) {
  537. this.form.duration = duration;
  538. },
  539. handleVideoChange(videoUrl,lineOne){
  540. this.videoUrl = videoUrl;
  541. this.form.videoUrl = videoUrl;
  542. console.log(this.videoUrl)
  543. },
  544. // 操作日志类型字典翻译
  545. formatDuration(row, column) {
  546. if(row.duration == null) return "00:00"
  547. const h = Math.floor(row.duration / 3600);
  548. const m = Math.floor((row.duration % 3600) / 60);
  549. const s = Math.floor(row.duration % 60);
  550. // 补零处理
  551. const format = (num) => num.toString().padStart(2, '0');
  552. return h > 0
  553. ? `${h}:${format(m)}:${format(s)}`
  554. : `${format(m)}:${format(s)}`;
  555. },
  556. formatFileSize(size) {
  557. if (!size) return "--";
  558. const mb = size / (1024 * 1024);
  559. return `${mb.toFixed(2)} MB`;
  560. },
  561. /** 查询直播视频列表 */
  562. getList() {
  563. this.loading = true;
  564. listLiveVideo(this.queryParams).then(response => {
  565. this.liveVideoList = response.rows;
  566. this.liveVideoList.forEach(item => {
  567. item.videoUrl = item.videoUrl.replace(".m3u8", ".mp4");
  568. });
  569. this.total = response.total;
  570. this.loading = false;
  571. });
  572. },
  573. videoTypeFormatter(row, column) {
  574. return this.selectDictLabel(this.videoTypeOptions, row.status);
  575. },
  576. categoryFormatter(row, column) {
  577. return this.selectDictLabel(this.categoryOptions, row.category);
  578. },
  579. // 取消按钮
  580. cancel() {
  581. this.open = false;
  582. this.reset();
  583. },
  584. // 表单重置
  585. reset() {
  586. this.form = {
  587. videoId: null,
  588. liveId: null,
  589. videoUrl: null,
  590. videoType: null,
  591. videoName: null,
  592. category: null,
  593. sort: null,
  594. createTime: null,
  595. createBy: null,
  596. updateBy: null,
  597. updateTime: null,
  598. remark: null,
  599. uploadType: 1,
  600. isTranscode: 0,
  601. transcodeFileKey: null,
  602. companyIds: [],
  603. fileSize: null
  604. };
  605. this.resetForm("form");
  606. },
  607. /** 搜索按钮操作 */
  608. handleQuery() {
  609. this.queryParams.pageNum = 1;
  610. this.getList();
  611. },
  612. /** 重置按钮操作 */
  613. resetQuery() {
  614. this.queryParams = {
  615. pageNum: 1,
  616. pageSize: 10,
  617. liveId: -1,
  618. videoUrl: null,
  619. videoType: -1,
  620. sort: null,
  621. videoName: null,
  622. remark: null,
  623. category: null,
  624. companyId: null,
  625. };
  626. this.handleQuery();
  627. },
  628. // 多选框选中数据
  629. handleSelectionChange(selection) {
  630. this.ids = selection.map(item => item.videoId)
  631. this.single = selection.length!==1
  632. this.multiple = !selection.length
  633. },
  634. /** 新增按钮操作 */
  635. handleAdd() {
  636. this.reset();
  637. this.open = true;
  638. this.title = "添加直播视频";
  639. this.videoUrl = '';
  640. setTimeout(() => {
  641. this.$refs.videoUpload.reset();
  642. }, 500);
  643. },
  644. /** 修改按钮操作 */
  645. handleUpdate(row) {
  646. this.reset();
  647. const videoId = row.videoId || this.ids
  648. getLiveVideo(videoId).then(response => {
  649. this.form = response.data;
  650. // 处理companyIds,可能是字符串或数组
  651. if (response.data.companyIds) {
  652. if (typeof response.data.companyIds === 'string') {
  653. this.form.companyIds = response.data.companyIds
  654. ? response.data.companyIds.split(',').map(Number)
  655. : [];
  656. } else if (Array.isArray(response.data.companyIds)) {
  657. this.form.companyIds = response.data.companyIds.map(Number);
  658. }
  659. } else {
  660. this.form.companyIds = [];
  661. }
  662. this.open = true;
  663. this.title = "修改直播视频";
  664. });
  665. },
  666. /** 获取所有公司选项 */
  667. getAllCompanyOptions() {
  668. this.companyOptionsLoading = true;
  669. getCompanyList().then(response => {
  670. if (response.code === 200 && response.data) {
  671. this.allCompanyOptions = response.data || [];
  672. } else {
  673. this.allCompanyOptions = [];
  674. }
  675. this.companyOptionsLoading = false;
  676. }).catch(() => {
  677. this.allCompanyOptions = [];
  678. this.companyOptionsLoading = false;
  679. });
  680. },
  681. /** 全选公司 */
  682. selectAllCompanies() {
  683. this.form.companyIds = this.allCompanyOptions.map(item => item.companyId);
  684. },
  685. /** 全不选公司 */
  686. unselectAllCompanies() {
  687. this.form.companyIds = [];
  688. },
  689. /** 反选公司 */
  690. reverseSelectCompanies() {
  691. const allIds = this.allCompanyOptions.map(item => item.companyId);
  692. const selectedIds = this.form.companyIds || [];
  693. this.form.companyIds = allIds.filter(id => !selectedIds.includes(id));
  694. },
  695. /** 全选公司(修改公司范围) */
  696. selectAllCompaniesForEdit() {
  697. this.editCompanyIdsForm.companyIds = this.allCompanyOptions.map(item => item.companyId);
  698. },
  699. /** 全不选公司(修改公司范围) */
  700. unselectAllCompaniesForEdit() {
  701. this.editCompanyIdsForm.companyIds = [];
  702. },
  703. /** 反选公司(修改公司范围) */
  704. reverseSelectCompaniesForEdit() {
  705. const allIds = this.allCompanyOptions.map(item => item.companyId);
  706. const selectedIds = this.editCompanyIdsForm.companyIds || [];
  707. this.editCompanyIdsForm.companyIds = allIds.filter(id => !selectedIds.includes(id));
  708. },
  709. /** 打开修改视频信息对话框 */
  710. handleUpdateVideoInfo(row) {
  711. const videoId = row.videoId;
  712. getLiveVideo(videoId).then(response => {
  713. if (response.code === 200) {
  714. this.editVideoInfoForm = {
  715. videoId: response.data.videoId,
  716. videoName: response.data.videoName || '',
  717. category: response.data.category || '',
  718. sort: response.data.sort || null,
  719. remark: response.data.remark || ''
  720. };
  721. this.editVideoInfoDialog = true;
  722. }
  723. }).catch(() => {
  724. this.msgError("获取数据失败");
  725. });
  726. },
  727. /** 取消修改视频信息 */
  728. cancelEditVideoInfo() {
  729. this.editVideoInfoDialog = false;
  730. this.editVideoInfoForm = {
  731. videoId: null,
  732. videoName: '',
  733. category: '',
  734. sort: null,
  735. remark: ''
  736. };
  737. },
  738. /** 提交修改视频信息 */
  739. submitEditVideoInfo() {
  740. const data = {
  741. videoId: this.editVideoInfoForm.videoId,
  742. videoName: this.editVideoInfoForm.videoName,
  743. category: this.editVideoInfoForm.category,
  744. sort: this.editVideoInfoForm.sort,
  745. remark: this.editVideoInfoForm.remark
  746. };
  747. updateLiveVideo(data).then(response => {
  748. if (response.code === 200) {
  749. this.msgSuccess("修改成功");
  750. this.editVideoInfoDialog = false;
  751. this.getList();
  752. } else {
  753. this.msgError(response.msg || "修改失败");
  754. }
  755. }).catch(() => {
  756. this.msgError("修改失败");
  757. });
  758. },
  759. /** 打开修改公司范围对话框 */
  760. handleUpdateCompanyIds(row) {
  761. const videoId = row.videoId;
  762. getLiveVideo(videoId).then(response => {
  763. if (response.code === 200) {
  764. this.editCompanyIdsForm = {
  765. videoId: response.data.videoId,
  766. videoName: response.data.videoName || '',
  767. companyIds: []
  768. };
  769. // 处理companyIds,可能是字符串或数组
  770. if (response.data.companyIds) {
  771. if (typeof response.data.companyIds === 'string') {
  772. this.editCompanyIdsForm.companyIds = response.data.companyIds
  773. ? response.data.companyIds.split(',').map(Number)
  774. : [];
  775. } else if (Array.isArray(response.data.companyIds)) {
  776. this.editCompanyIdsForm.companyIds = response.data.companyIds.map(Number);
  777. }
  778. }
  779. this.editCompanyIdsDialog = true;
  780. }
  781. }).catch(() => {
  782. this.msgError("获取数据失败");
  783. });
  784. },
  785. /** 取消修改公司范围 */
  786. cancelEditCompanyIds() {
  787. this.editCompanyIdsDialog = false;
  788. this.editCompanyIdsForm = {
  789. videoId: null,
  790. videoName: '',
  791. companyIds: []
  792. };
  793. },
  794. /** 提交修改公司范围 */
  795. submitEditCompanyIds() {
  796. const data = {
  797. videoId: this.editCompanyIdsForm.videoId,
  798. companyIds: Array.isArray(this.editCompanyIdsForm.companyIds)
  799. ? this.editCompanyIdsForm.companyIds
  800. : []
  801. };
  802. updateLiveVideo(data).then(response => {
  803. if (response.code === 200) {
  804. this.msgSuccess("修改成功");
  805. this.editCompanyIdsDialog = false;
  806. this.getList();
  807. } else {
  808. this.msgError(response.msg || "修改失败");
  809. }
  810. }).catch(() => {
  811. this.msgError("修改失败");
  812. });
  813. },
  814. /** 提交按钮 */
  815. submitForm() {
  816. this.$refs["form"].validate(valid => {
  817. if (valid) {
  818. this.form.videoType = -1;
  819. this.form.liveId = -1;
  820. if (!this.form.videoName) {
  821. this.form.videoName = this.form.fileName;
  822. }
  823. if (!this.form.remark) {
  824. this.form.remark = this.form.fileName;
  825. }
  826. if(this.form.videoUrl == null || this.form.videoUrl == "") {
  827. this.msgError("请上传视频");
  828. return;
  829. }
  830. this.form.videoUrl = this.form.videoUrl.replace('.mp4', '.m3u8');
  831. // 确保companyIds是数组
  832. const submitData = {
  833. ...this.form,
  834. companyIds: Array.isArray(this.form.companyIds) ? this.form.companyIds : []
  835. };
  836. if (this.form.videoId != null) {
  837. // 修改
  838. updateLiveVideo(submitData).then(response => {
  839. this.msgSuccess("修改成功");
  840. this.open = false;
  841. this.getList();
  842. this.reset();
  843. });
  844. } else {
  845. // 新增
  846. addLiveVideo(submitData).then(response => {
  847. this.msgSuccess("新增成功");
  848. this.open = false;
  849. this.getList();
  850. this.reset();
  851. });
  852. }
  853. }
  854. });
  855. },
  856. /** 删除按钮操作 */
  857. handleDelete(row) {
  858. const videoIds = row.videoId || this.ids;
  859. this.$confirm('是否确认删除直播视频编号为"' + videoIds + '"的数据项?', "警告", {
  860. confirmButtonText: "确定",
  861. cancelButtonText: "取消",
  862. type: "warning"
  863. }).then(function() {
  864. return delLiveVideo(videoIds);
  865. }).then(() => {
  866. this.getList();
  867. this.msgSuccess("删除成功");
  868. }).catch(() => {});
  869. },
  870. /** 导出按钮操作 */
  871. handleExport() {
  872. const queryParams = this.queryParams;
  873. this.$confirm('是否确认导出所有直播视频数据项?', "警告", {
  874. confirmButtonText: "确定",
  875. cancelButtonText: "取消",
  876. type: "warning"
  877. }).then(() => {
  878. this.exportLoading = true;
  879. return exportLiveVideo(queryParams);
  880. }).then(response => {
  881. this.download(response.msg);
  882. this.exportLoading = false;
  883. }).catch(() => {});
  884. },
  885. /** 批量修改分类 */
  886. handleBatchUpdateCategory() {
  887. if (this.ids.length === 0) {
  888. this.msgWarning("请选择要修改的视频");
  889. return;
  890. }
  891. this.batchUpdateCategoryForm.category = '';
  892. this.batchUpdateCategoryDialog = true;
  893. },
  894. /** 取消批量修改分类 */
  895. cancelBatchUpdateCategory() {
  896. this.batchUpdateCategoryDialog = false;
  897. this.batchUpdateCategoryForm.category = '';
  898. },
  899. /** 提交批量修改分类 */
  900. submitBatchUpdateCategory() {
  901. const data = {
  902. videoIds: this.ids,
  903. category: this.batchUpdateCategoryForm.category
  904. };
  905. batchUpdateCategory(data).then(response => {
  906. if (response.code === 200) {
  907. this.msgSuccess("批量修改成功");
  908. this.batchUpdateCategoryDialog = false;
  909. this.getList();
  910. } else {
  911. this.msgError(response.msg || "批量修改失败");
  912. }
  913. }).catch(() => {
  914. this.msgError("批量修改失败");
  915. });
  916. },
  917. /** 打开批量上传视频对话框 */
  918. handleBatchUpload() {
  919. this.batchUploadFileList = [];
  920. this.batchUploadVideos = [];
  921. this.batchUploadDialog = true;
  922. },
  923. /** 取消批量上传 */
  924. cancelBatchUpload() {
  925. this.batchUploadDialog = false;
  926. this.batchUploadFileList = [];
  927. this.batchUploadVideos = [];
  928. if (this.$refs.batchUpload) {
  929. this.$refs.batchUpload.clearFiles();
  930. }
  931. },
  932. /** 批量文件变化 */
  933. handleBatchFileChange(file, fileList) {
  934. const MAX_SIZE = 1024 * 1024 * 1024;
  935. if (file.raw && file.raw.size > MAX_SIZE) {
  936. this.$message.error(`${file.name} 文件大小不能超过1G`);
  937. // 从文件列表中移除
  938. const index = fileList.findIndex(f => f.uid === file.uid);
  939. if (index > -1) {
  940. fileList.splice(index, 1);
  941. }
  942. return;
  943. }
  944. this.batchUploadFileList = fileList;
  945. // 初始化上传数据
  946. const index = this.batchUploadVideos.length;
  947. this.batchUploadVideos.push({
  948. file: file.raw,
  949. fileName: file.name,
  950. fileSize: file.size,
  951. videoUrl: '',
  952. fileKey: '',
  953. duration: 0,
  954. progress: 0,
  955. status: '',
  956. errorMsg: ''
  957. });
  958. // 获取视频时长
  959. this.getBatchVideoDuration(file.raw, index);
  960. },
  961. /** 批量文件移除 */
  962. handleBatchFileRemove(file, fileList) {
  963. this.batchUploadFileList = fileList;
  964. const index = this.batchUploadVideos.findIndex(v => v.fileName === file.name);
  965. if (index > -1) {
  966. this.batchUploadVideos.splice(index, 1);
  967. }
  968. },
  969. /** 获取批量视频时长 */
  970. getBatchVideoDuration(file, index) {
  971. const video = document.createElement("video");
  972. video.preload = "metadata";
  973. video.onloadedmetadata = () => {
  974. window.URL.revokeObjectURL(video.src);
  975. const duration = parseInt(video.duration.toFixed(2));
  976. if (this.batchUploadVideos[index]) {
  977. this.batchUploadVideos[index].duration = duration;
  978. }
  979. };
  980. video.src = URL.createObjectURL(file);
  981. },
  982. /** 批量上传请求处理 */
  983. handleBatchUploadRequest(options) {
  984. // 这个方法不会被调用,因为我们使用auto-upload=false
  985. },
  986. /** 开始批量上传 */
  987. async submitBatchUpload() {
  988. if (this.batchUploadVideos.length === 0) {
  989. this.msgWarning("请先选择视频文件");
  990. return;
  991. }
  992. // 重置所有视频状态
  993. this.batchUploadVideos.forEach(video => {
  994. video.progress = 0;
  995. video.status = '';
  996. video.errorMsg = '';
  997. });
  998. // 逐个上传视频
  999. for (let i = 0; i < this.batchUploadVideos.length; i++) {
  1000. const video = this.batchUploadVideos[i];
  1001. try {
  1002. video.status = '';
  1003. video.progress = 0;
  1004. // 上传到COS
  1005. const updateProgress = (progressData) => {
  1006. video.progress = Math.round(progressData.percent * 100);
  1007. };
  1008. const data = await uploadObject(video.file, updateProgress, 1);
  1009. // 构建视频URL
  1010. let line_1 = `${process.env.VUE_APP_VIDEO_LINE_1}${data.urlPath}`;
  1011. line_1 = line_1.replace(/\.mp4$/, '.m3u8');
  1012. video.videoUrl = line_1;
  1013. video.fileKey = data.urlPath.substring(1);
  1014. video.progress = 100;
  1015. video.status = 'success';
  1016. } catch (error) {
  1017. console.error(`视频 ${video.fileName} 上传失败:`, error);
  1018. video.status = 'exception';
  1019. video.errorMsg = error.message || '上传失败';
  1020. }
  1021. }
  1022. },
  1023. /** 计算是否可以保存 */
  1024. canSaveBatchUpload() {
  1025. if (this.batchUploadVideos.length === 0) {
  1026. return false;
  1027. }
  1028. // 检查是否所有视频都已上传成功
  1029. return this.batchUploadVideos.every(video => video.status === 'success' && video.videoUrl);
  1030. },
  1031. /** 保存批量上传的视频 */
  1032. saveBatchUploadVideos() {
  1033. if (!this.canSaveBatchUpload) {
  1034. this.msgWarning("请等待所有视频上传完成");
  1035. return;
  1036. }
  1037. // 构建保存数据
  1038. const videoList = this.batchUploadVideos.map(video => {
  1039. return {
  1040. videoUrl: video.videoUrl,
  1041. videoName: video.fileName.replace(/\.[^/.]+$/, ""), // 去掉扩展名
  1042. videoType: -1, // 视频库
  1043. liveId: -1,
  1044. fileSize: video.fileSize,
  1045. duration: video.duration,
  1046. finishStatus: 0
  1047. };
  1048. });
  1049. // 调用批量新增接口
  1050. batchAddLiveVideo(videoList).then(response => {
  1051. if (response.code === 200) {
  1052. this.msgSuccess("批量保存成功");
  1053. this.batchUploadDialog = false;
  1054. this.batchUploadFileList = [];
  1055. this.batchUploadVideos = [];
  1056. this.getList();
  1057. } else {
  1058. this.msgError(response.msg || "批量保存失败");
  1059. }
  1060. }).catch(() => {
  1061. this.msgError("批量保存失败");
  1062. });
  1063. },
  1064. /** 打开重新上传视频对话框 */
  1065. handleReuploadVideo(row) {
  1066. this.reuploadVideoForm = {
  1067. videoId: row.videoId,
  1068. videoName: row.videoName || '',
  1069. videoUrl: '',
  1070. fileKey: '',
  1071. fileSize: null,
  1072. fileName: '',
  1073. lineOne: '',
  1074. thumbnail: '',
  1075. uploadType: 1,
  1076. isTranscode: 0,
  1077. transcodeFileKey: null,
  1078. duration: 0
  1079. };
  1080. this.reuploadVideoDialog = true;
  1081. // 重置上传组件
  1082. this.$nextTick(() => {
  1083. if (this.$refs.reuploadVideoUpload) {
  1084. this.$refs.reuploadVideoUpload.reset();
  1085. }
  1086. });
  1087. },
  1088. /** 取消重新上传视频 */
  1089. cancelReuploadVideo() {
  1090. this.reuploadVideoDialog = false;
  1091. this.reuploadVideoForm = {
  1092. videoId: null,
  1093. videoName: '',
  1094. videoUrl: '',
  1095. fileKey: '',
  1096. fileSize: null,
  1097. fileName: '',
  1098. lineOne: '',
  1099. thumbnail: '',
  1100. uploadType: 1,
  1101. isTranscode: 0,
  1102. transcodeFileKey: null,
  1103. duration: 0
  1104. };
  1105. },
  1106. /** 重新上传视频时长回调 */
  1107. handleReuploadVideoDuration(duration) {
  1108. this.reuploadVideoForm.duration = duration;
  1109. },
  1110. /** 重新上传视频URL变化回调 */
  1111. handleReuploadVideoChange(videoUrl) {
  1112. this.reuploadVideoForm.videoUrl = videoUrl;
  1113. },
  1114. /** 提交重新上传视频 */
  1115. submitReuploadVideo() {
  1116. if (!this.reuploadVideoForm.videoUrl) {
  1117. this.msgError("请上传视频");
  1118. return;
  1119. }
  1120. const videoUrl = this.reuploadVideoForm.videoUrl.replace('.mp4', '.m3u8');
  1121. updateVideoUrl({
  1122. videoId: this.reuploadVideoForm.videoId,
  1123. videoUrl: videoUrl
  1124. }).then(response => {
  1125. if (response.code === 200) {
  1126. this.msgSuccess("上传成功");
  1127. this.reuploadVideoDialog = false;
  1128. this.getList();
  1129. this.cancelReuploadVideo();
  1130. } else {
  1131. this.msgError(response.msg || "上传失败");
  1132. }
  1133. }).catch(() => {
  1134. this.msgError("上传失败");
  1135. });
  1136. }
  1137. }
  1138. };
  1139. </script>
  1140. <style scoped>
  1141. .video-player {
  1142. width: 100%;
  1143. height: 100%;
  1144. object-fit: cover;
  1145. }
  1146. .progress-container {
  1147. margin-bottom: 5px;
  1148. }
  1149. .progress-label {
  1150. display: block;
  1151. font-weight: bold;
  1152. font-size: 13px;
  1153. color: #303331;
  1154. }
  1155. </style>