index.vue 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933
  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="resourceName">
  5. <el-input
  6. v-model="queryParams.resourceName"
  7. placeholder="请输入素材名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="文件名称" prop="fileName">
  14. <el-input
  15. v-model="queryParams.fileName"
  16. placeholder="请输入素材名称"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="分类" prop="typeId">
  23. <el-select v-model="queryParams.typeId" clearable placeholder="请选择分类" @change="val => changeCateType(val, 1)">
  24. <el-option
  25. v-for="item in rootTypeList"
  26. :key="item.dictValue"
  27. :label="item.dictLabel"
  28. :value="item.dictValue">
  29. </el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="子分类" prop="typeSubId">
  33. <el-select v-model="queryParams.typeSubId" clearable placeholder="请选择子分类">
  34. <el-option
  35. v-for="item in subTypeList"
  36. :key="item.dictValue"
  37. :label="item.dictLabel"
  38. :value="item.dictValue">
  39. </el-option>
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  44. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  45. </el-form-item>
  46. </el-form>
  47. <el-row :gutter="10" class="mb8">
  48. <el-col :span="1.5">
  49. <el-button
  50. type="primary"
  51. icon="el-icon-plus"
  52. size="mini"
  53. @click="handleAdd"
  54. :disabled="hasMinimizableDialog"
  55. v-hasPermi="['course:videoResource:add']"
  56. >新增</el-button>
  57. </el-col>
  58. <el-col :span="1.5">
  59. <el-button
  60. type="primary"
  61. icon="el-icon-plus"
  62. size="mini"
  63. @click="handleBatchAdd"
  64. :disabled="hasMinimizableDialog"
  65. v-hasPermi="['course:videoResource:batchAdd']"
  66. >批量新增</el-button>
  67. </el-col>
  68. <el-col :span="1.5">
  69. <el-button
  70. type="danger"
  71. icon="el-icon-delete"
  72. size="mini"
  73. :disabled="multiple"
  74. @click="handleDelete"
  75. v-hasPermi="['course:videoResource:remove']"
  76. >删除</el-button>
  77. </el-col>
  78. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  79. </el-row>
  80. <el-table v-loading="loading" :data="resourceList" @selection-change="handleSelectionChange" border>
  81. <el-table-column type="selection" width="55" align="center" />
  82. <el-table-column label="序号" width="55" align="center">
  83. <template slot-scope="scope">
  84. {{ scope.$index + 1 }}
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="素材名称" align="center" :show-overflow-tooltip="true" prop="resourceName"/>
  88. <el-table-column label="文件名称" align="center" :show-overflow-tooltip="true" prop="fileName"/>
  89. <el-table-column label="分类" align="center">
  90. <template slot-scope="scope">
  91. <span v-if="scope.row.typeId">{{ getTypeName(scope.row.typeId) }}</span>
  92. </template>
  93. </el-table-column>
  94. <el-table-column label="子分类" align="center">
  95. <template slot-scope="scope">
  96. <span v-if="scope.row.typeSubId">{{ getTypeName(scope.row.typeSubId) }}</span>
  97. </template>
  98. </el-table-column>
  99. <el-table-column label="视频文件" align="center">
  100. <template slot-scope="scope">
  101. <a
  102. @click="handleVideoPreview(scope.row.videoUrl)"
  103. style="background-color: #409EFF; color: white; border: none; border-radius: 4px; padding: 4px 12px; cursor: pointer; font-size: 12px; display: inline-block; text-decoration: none;">
  104. 查看文件
  105. </a>
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="CDN" align="center">
  109. <template slot-scope="scope">
  110. <a
  111. @click="copy(scope.row.videoUrl)"
  112. style="color: #409EFF; border: none; border-radius: 4px; padding: 4px 12px; cursor: pointer; font-size: 12px; display: inline-block; text-decoration: none;">
  113. 复制链接
  114. </a>
  115. </template>
  116. </el-table-column>
  117. <el-table-column label="关联题目" align="center">
  118. <template slot-scope="scope">
  119. <a
  120. @click="handleViewProject(scope.row, 3)"
  121. :style="scope.row.projectIds ? {
  122. backgroundColor: '#409EFF',
  123. color: 'white',
  124. border: 'none',
  125. borderRadius: '4px',
  126. padding: '4px 12px',
  127. cursor: 'pointer',
  128. fontSize: '12px',
  129. display: 'inline-block',
  130. textDecoration: 'none'
  131. } : {
  132. backgroundColor: 'rgb(154 156 159)',
  133. color: 'white',
  134. border: 'none',
  135. cursor: 'pointer',
  136. borderRadius: '4px',
  137. padding: '4px 12px',
  138. fontSize: '12px',
  139. display: 'inline-block',
  140. textDecoration: 'none'
  141. }">
  142. {{ scope.row.projectIds ? '查看详情' : '未关联题目' }}
  143. </a>
  144. </template>
  145. </el-table-column>
  146. <el-table-column label="视频时长" align="center">
  147. <template slot-scope="scope">
  148. <div style="padding: 4px 12px;background: linear-gradient(to right, rgb(196 219 255), #409EFF)">{{ formatDuration(scope.row.duration) }}</div>
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  152. <template slot-scope="scope">
  153. <el-button
  154. size="mini"
  155. type="text"
  156. icon="el-icon-edit"
  157. @click="handleUpdate(scope.row)"
  158. :disabled="hasMinimizableDialog"
  159. v-hasPermi="['course:videoResource:edit']"
  160. >修改</el-button>
  161. <el-button
  162. size="mini"
  163. type="text"
  164. icon="el-icon-delete"
  165. @click="handleDelete(scope.row)"
  166. v-hasPermi="['course:videoResource:remove']"
  167. >删除</el-button>
  168. </template>
  169. </el-table-column>
  170. </el-table>
  171. <pagination
  172. v-show="total>0"
  173. :total="total"
  174. :page.sync="queryParams.pageNum"
  175. :limit.sync="queryParams.pageSize"
  176. @pagination="getList"
  177. />
  178. <!-- 添加或修改视频素材库对话框 -->
  179. <minimizable-dialog :title="title" :visible.sync="open" width="700px" append-to-body :before-close="cancel"
  180. @minimize="hasMinimizableDialog = true" @restore="hasMinimizableDialog = false">
  181. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  182. <el-form-item label="素材名称" prop="resourceName" style="margin-top: 20px">
  183. <el-input v-model="form.resourceName" placeholder="请输入" />
  184. </el-form-item>
  185. <el-form-item label="文件名称" prop="fileName" style="margin-top: 20px;display: none">
  186. <el-input v-model="form.fileName" placeholder="请输入" />
  187. </el-form-item>
  188. <el-form-item label="分类" prop="typeId">
  189. <el-select v-model="form.typeId" placeholder="请选择分类" style="width: 100%" @change="val => changeCateType(val, 2)">
  190. <el-option
  191. v-for="item in rootTypeList"
  192. :key="item.dictValue"
  193. :label="item.dictLabel"
  194. :value="item.dictValue">
  195. </el-option>
  196. </el-select>
  197. </el-form-item>
  198. <el-form-item label="子分类" prop="typeSubId">
  199. <el-select v-model="form.typeSubId" clearable placeholder="请选择子分类" style="width: 100%">
  200. <el-option
  201. v-for="item in subTypeList"
  202. :key="item.dictValue"
  203. :label="item.dictLabel"
  204. :value="item.dictValue">
  205. </el-option>
  206. </el-select>
  207. </el-form-item>
  208. <el-form-item label="关联题目" prop="projectIds">
  209. <el-select
  210. ref="customSelect"
  211. class="custom-select-class"
  212. v-model="form.projectIds"
  213. multiple
  214. placeholder="请选择关联题目"
  215. @click.native.stop="openProjectDialog(form.projectIds, 0)"
  216. style="width: 100%;">
  217. <el-option
  218. v-for="item in projectShowList"
  219. :key="item.id"
  220. :label="item.title"
  221. :value="item.id">
  222. </el-option>
  223. </el-select>
  224. </el-form-item>
  225. <el-form-item label="上传视频" prop="videoUrl" required>
  226. <el-upload
  227. ref="videoUpload"
  228. action="#"
  229. list-type="picture-card"
  230. :http-request="videoUpload"
  231. :file-list="fileList"
  232. :on-change="handleFileChange"
  233. accept=".mp4">
  234. <i slot="default" class="el-icon-plus"></i>
  235. <div slot="file" slot-scope="{file}">
  236. <div
  237. class="el-upload-list__item-thumbnail"
  238. style="display: flex; justify-content: center; align-items: center; background-color: #f5f7fa; height: 146px;"
  239. >
  240. <i class="el-icon-video-camera" style="font-size: 48px;" />
  241. </div>
  242. <span v-if="file.status === 'success'" class="el-upload-list__item-status-label">
  243. <i class="el-icon-upload-success el-icon--check"></i>
  244. </span>
  245. <span v-if="file.status === 'fail'" class="el-upload-list__item-status-label">
  246. <i class="el-icon-circle-close"></i>
  247. </span>
  248. <span class="el-upload-list__item-actions">
  249. <span
  250. class="el-upload-list__item-preview"
  251. @click="handleVideoPreview(form.videoUrl)"
  252. >
  253. <i class="el-icon-zoom-in"></i>
  254. </span>
  255. <span
  256. class="el-upload-list__item-delete"
  257. @click="handleRemove(file)"
  258. >
  259. <i class="el-icon-delete"></i>
  260. </span>
  261. </span>
  262. <div v-if="file.status === 'uploading'" class="el-upload-list__item-progress">
  263. <el-progress
  264. :percentage="file.percentage"
  265. :show-text="false"
  266. :width="52"
  267. ></el-progress>
  268. </div>
  269. </div>
  270. </el-upload>
  271. </el-form-item>
  272. <el-form-item label="时长">
  273. <span>{{ formatDuration(form.duration) }}</span>
  274. </el-form-item>
  275. </el-form>
  276. <div slot="footer" class="dialog-footer">
  277. <el-button @click="cancel">取消</el-button>
  278. <el-button type="primary" @click="submitForm">保存</el-button>
  279. </div>
  280. </minimizable-dialog>
  281. <el-dialog
  282. title="视频预览"
  283. :visible.sync="videoPreviewVisible"
  284. append-to-body
  285. :close-on-click-modal="true"
  286. width="700px"
  287. class="video-preview-dialog"
  288. :modal-append-to-body="false"
  289. :before-close="handleCloseVideoPreview">
  290. <video ref="up-video" id="video" width="100%" height="400px" controls :src="videoPreviewUrl" />
  291. </el-dialog>
  292. <!-- 批量选择视频弹窗 -->
  293. <minimizable-dialog :title="'选择视频'" :visible.sync="batchAddVisible" width="1200px" append-to-body class="batch-dialog" :close-on-click-modal="false" :before-close="cancelBeforeBatch"
  294. @minimize="hasMinimizableDialog = true" @restore="hasMinimizableDialog = false">
  295. <div class="filter-container">
  296. <el-button type="primary" icon="el-icon-plus" size="small" @click="showUploadPanel">上传视频</el-button>
  297. </div>
  298. <el-table
  299. v-loading="batchLoading"
  300. :data="videoList"
  301. height="350"
  302. border>
  303. <el-table-column label="序号" width="60" align="center">
  304. <template slot-scope="scope">
  305. {{ scope.$index + 1 }}
  306. </template>
  307. </el-table-column>
  308. <el-table-column label="素材名称" align="center" prop="resourceName" min-width="120" />
  309. <el-table-column label="文件名称" align="center" prop="fileName" min-width="120" />
  310. <el-table-column label="分类" align="center" min-width="100">
  311. <template slot-scope="scope">
  312. {{ getTypeName(scope.row.typeId) }}
  313. </template>
  314. </el-table-column>
  315. <el-table-column label="关联项目" align="center" min-width="100">
  316. <template slot-scope="scope">
  317. <a
  318. @click="handleViewProject(scope.row, 4)"
  319. :style="scope.row.projectIds.length > 0 ? {
  320. backgroundColor: '#409EFF',
  321. color: 'white',
  322. border: 'none',
  323. borderRadius: '4px',
  324. padding: '4px 12px',
  325. cursor: 'pointer',
  326. fontSize: '12px',
  327. display: 'inline-block',
  328. textDecoration: 'none'
  329. } : {
  330. backgroundColor: 'rgb(154 156 159)',
  331. color: 'white',
  332. border: 'none',
  333. cursor: 'pointer',
  334. borderRadius: '4px',
  335. padding: '4px 12px',
  336. fontSize: '12px',
  337. display: 'inline-block',
  338. textDecoration: 'none'
  339. }">
  340. {{ scope.row.projectIds.length > 0 ? '查看详情' : '未关联题目' }}
  341. </a>
  342. </template>
  343. </el-table-column>
  344. <el-table-column label="视频文件" align="center" prop="fileName" min-width="120">
  345. <template slot-scope="scope">
  346. <a
  347. @click="handleVideoPreview(scope.row.videoUrl)"
  348. style="background-color: #409EFF; color: white; border: none; border-radius: 4px; padding: 4px 12px; cursor: pointer; font-size: 12px; display: inline-block; text-decoration: none;">
  349. 查看文件
  350. </a>
  351. </template>
  352. </el-table-column>
  353. <el-table-column label="视频时长" align="center" width="80">
  354. <template slot-scope="scope">
  355. {{ formatDuration(scope.row.duration) }}
  356. </template>
  357. </el-table-column>
  358. <el-table-column label="上传进度" align="center" width="120">
  359. <template slot-scope="scope">
  360. <el-progress :percentage="scope.row.progress" :status="scope.row.progress === 100 ? 'success' : undefined"></el-progress>
  361. </template>
  362. </el-table-column>
  363. <el-table-column label="操作" align="center" width="150">
  364. <template slot-scope="scope">
  365. <el-button
  366. size="mini"
  367. type="text"
  368. icon="el-icon-edit"
  369. @click="handleEditVideo(scope.row)">编辑</el-button>
  370. <el-button
  371. size="mini"
  372. type="text"
  373. icon="el-icon-delete"
  374. @click="handleDeleteVideo(scope.row)">删除</el-button>
  375. </template>
  376. </el-table-column>
  377. </el-table>
  378. <div class="dialog-footer">
  379. <el-button @click="cancelBatch">取 消</el-button>
  380. <el-button type="primary" @click="submitBatchAdd">保 存</el-button>
  381. </div>
  382. <!-- 批量上传视频弹窗 -->
  383. <el-dialog
  384. title="批量上传视频"
  385. :visible.sync="showUpload"
  386. width="500px"
  387. append-to-body
  388. :close-on-click-modal="false"
  389. class="upload-dialog">
  390. <el-form :model="batchUploadForm" ref="batchUploadForm" label-width="80px">
  391. <el-form-item style="margin-top: 20px" label="分类" prop="typeId" :rules="[{ required: true, message: '请选择分类', trigger: 'blur' }]">
  392. <el-select v-model="batchUploadForm.typeId" placeholder="请选择分类" style="width: 100%" @change="val => changeCateType(val, 3)">
  393. <el-option
  394. v-for="item in rootTypeList"
  395. :key="item.dictValue"
  396. :label="item.dictLabel"
  397. :value="item.dictValue">
  398. </el-option>
  399. </el-select>
  400. </el-form-item>
  401. <el-form-item label="子分类" prop="typeSubId" :rules="[{ required: true, message: '请选择子分类', trigger: 'blur' }]">
  402. <el-select v-model="batchUploadForm.typeSubId" clearable placeholder="请选择子分类" style="width: 100%">
  403. <el-option
  404. v-for="item in subTypeList"
  405. :key="item.dictValue"
  406. :label="item.dictLabel"
  407. :value="item.dictValue">
  408. </el-option>
  409. </el-select>
  410. </el-form-item>
  411. <el-form-item label="关联题目" prop="projectIds" style="display: none">
  412. <el-select
  413. ref="customSelect"
  414. class="custom-select-class"
  415. v-model="batchUploadForm.projectIds"
  416. multiple
  417. placeholder="请选择关联题目"
  418. @click.native.stop="openProjectDialog(batchUploadForm.projectIds, 1)"
  419. style="width: 100%;">
  420. <el-option
  421. v-for="item in projectShowList"
  422. :key="item.id"
  423. :label="item.title"
  424. :value="item.id">
  425. </el-option>
  426. </el-select>
  427. </el-form-item>
  428. <el-form-item label="上传视频" prop="files">
  429. <el-upload
  430. ref="batchVideoUpload"
  431. action="#"
  432. :http-request="batchVideoUpload"
  433. :file-list="batchFileList"
  434. :on-change="handleBatchFileChange"
  435. multiple
  436. accept=".mp4">
  437. <el-button type="primary" :disabled="batchUploadForm.typeSubId === null">选择文件</el-button>
  438. <div slot="tip" class="el-upload__tip">选择分类后才可以上传视频</div>
  439. </el-upload>
  440. </el-form-item>
  441. </el-form>
  442. </el-dialog>
  443. <!-- 添加或修改视频素材库对话框 -->
  444. <el-dialog :title="batchEditDialog.title" :visible.sync="batchEditDialog.open" width="600px" append-to-body :before-close="batchEditCancel">
  445. <el-form ref="batchEditDialogForm" :model="batchEditDialog.form" :rules="batchEditDialog.rules" label-width="80px">
  446. <el-form-item label="素材名称" prop="resourceName" style="margin-top: 20px">
  447. <el-input v-model="batchEditDialog.form.resourceName" placeholder="请输入" />
  448. </el-form-item>
  449. <el-form-item label="文件名称" prop="fileName" style="margin-top: 20px;display: none">
  450. <el-input v-model="batchEditDialog.form.fileName" placeholder="请输入" />
  451. </el-form-item>
  452. <el-form-item label="关联题目" prop="projectIds">
  453. <el-select
  454. ref="customSelect"
  455. class="custom-select-class"
  456. v-model="batchEditDialog.form.projectIds"
  457. multiple
  458. placeholder="请选择关联题目"
  459. @click.native.stop="openProjectDialog(batchEditDialog.form.projectIds, 2)"
  460. style="width: 100%;">
  461. <el-option
  462. v-for="item in projectShowList"
  463. :key="item.id"
  464. :label="item.title"
  465. :value="item.id">
  466. </el-option>
  467. </el-select>
  468. </el-form-item>
  469. </el-form>
  470. <div slot="footer" class="dialog-footer">
  471. <el-button @click="batchEditCancel">取消</el-button>
  472. <el-button type="primary" @click="batchEditSubmitForm">保存</el-button>
  473. </div>
  474. </el-dialog>
  475. </minimizable-dialog>
  476. <!-- 项目选择弹窗 -->
  477. <el-dialog
  478. title="选择题目"
  479. :visible.sync="projectDialogVisible"
  480. width="1000px"
  481. append-to-body
  482. @close="cancelSelectProject"
  483. :close-on-click-modal="false">
  484. <div class="project-container">
  485. <!-- 左侧分类树 -->
  486. <div class="category-tree">
  487. <div class="tree-fixed-header">
  488. <el-input
  489. placeholder="请输入分类名称"
  490. v-model="categoryFilterText"
  491. size="small"
  492. clearable
  493. prefix-icon="el-icon-search">
  494. </el-input>
  495. </div>
  496. <div class="tree-content">
  497. <el-tree
  498. ref="categoryTree"
  499. :data="categoryTreeData"
  500. node-key="cateId"
  501. highlight-current
  502. :filter-node-method="filterNode"
  503. :props="{ label: 'cateName', children: 'children' }"
  504. @node-click="handleCategoryClick"
  505. :expand-on-click-node="false"
  506. default-expand-all>
  507. <span class="custom-tree-node" slot-scope="{ node, data }">
  508. <span>{{ node.label }}</span>
  509. </span>
  510. </el-tree>
  511. </div>
  512. </div>
  513. <!-- 右侧题目列表 -->
  514. <div class="project-list">
  515. <div class="filter-container">
  516. <el-form :inline="true" :model="projectQueryParams" ref="projectForm">
  517. <el-form-item>
  518. <el-input prefix-icon="el-icon-search" @input="searchProjects" v-model="projectQueryParams.title" placeholder="请输入题目标题" clearable size="small" />
  519. </el-form-item>
  520. </el-form>
  521. </div>
  522. <el-table
  523. ref="projectTable"
  524. height="350"
  525. :data="projectList"
  526. row-key="id"
  527. v-loading="projectLoading"
  528. border
  529. @select="handleProjectSelect"
  530. @select-all="handleProjectSelect">
  531. <el-table-column type="selection" reserve-selection width="55" align="center" />
  532. <el-table-column label="序号" width="60" align="center">
  533. <template slot-scope="scope">
  534. {{ scope.row.sort }}
  535. </template>
  536. </el-table-column>
  537. <el-table-column label="题目标题" align="center" prop="title" min-width="200" show-overflow-tooltip />
  538. </el-table>
  539. <div class="table-footer">
  540. <el-pagination
  541. style="text-align: right"
  542. v-show="projectListTotal>0"
  543. :pager-count="5"
  544. background
  545. @size-change="handleProjectPageSizeChange"
  546. @current-change="handleProjectPageChange"
  547. :current-page="projectQueryParams.pageNum"
  548. :page-sizes="[10, 20, 30, 50]"
  549. :page-size="projectQueryParams.pageSize"
  550. layout="total, sizes, prev, pager, next, jumper"
  551. :total="projectListTotal">
  552. </el-pagination>
  553. </div>
  554. </div>
  555. </div>
  556. <div slot="footer" class="dialog-footer">
  557. <span style="float: left; color: #606266; font-size: 13px;">
  558. 共选择 <span style="color: #409EFF; font-weight: bold;">{{ selectedProjectIds.length }}</span> 个题目
  559. </span>
  560. <el-button @click="projectDialogVisible = false">取消</el-button>
  561. <el-button type="primary" @click="confirmSelectProject">确定</el-button>
  562. </div>
  563. </el-dialog>
  564. <!-- 项目列表弹窗 -->
  565. <el-dialog
  566. title="题目列表"
  567. :visible.sync="projectListDialogVisible"
  568. width="600px"
  569. append-to-body
  570. :close-on-click-modal="false">
  571. <div class="project-list-container" style="max-height: 500px; overflow-y: auto; padding: 10px;">
  572. <!-- 题目列表 -->
  573. <div v-for="(item, index) in projectShowList" :key="index" class="question-card">
  574. <!-- 题目标题 -->
  575. <div class="question-header">
  576. <span class="question-index">{{ index + 1 }}</span>
  577. <span class="question-title">{{ item.title }}</span>
  578. </div>
  579. <!-- 题目类型 -->
  580. <div class="question-type">
  581. <el-tag size="small" type="primary">{{ item.type === 1 ? '单选' : '多选' }}</el-tag>
  582. </div>
  583. <!-- 题目内容 -->
  584. <div class="question-content" v-if="item.question && item.question.length > 0">
  585. <div class="content-title">题目内容:</div>
  586. <div v-for="(q, qIndex) in JSON.parse(item.question)" :key="qIndex" class="question-item"
  587. :style=" q.isAnswer === 1 ? 'background-color: rgb(234 245 251)' : ''">
  588. <div class="question-item-header">
  589. <span class="item-index">{{ convertToLetter(qIndex) }}</span>
  590. <span class="item-name">{{ q.name }}</span>
  591. </div>
  592. </div>
  593. </div>
  594. <!-- 答案 -->
  595. <div class="question-answer" v-if="item.answer">
  596. <span class="answer-label">答案:</span>
  597. <span class="answer-content">{{ item.answer }}</span>
  598. </div>
  599. </div>
  600. </div>
  601. </el-dialog>
  602. </div>
  603. </template>
  604. <script>
  605. import {
  606. addVideoResource,
  607. deleteVideoResource,
  608. getVideoResource,
  609. listVideoResource,
  610. updateVideoResource,
  611. batchAddVideoResource
  612. } from '@/api/course/videoResource'
  613. import {listUserCourseCategory,getCatePidList,getCateListByPid} from '@/api/course/userCourseCategory'
  614. import {getByIds, listCourseQuestionBank} from '@/api/course/courseQuestionBank'
  615. import {getThumbnail} from "@/api/course/userVideo";
  616. import {uploadObject} from "@/utils/cos.js";
  617. import {uploadToOBS} from "@/utils/obs.js";
  618. import MinimizableDialog from "@/components/MinimizableDialog"
  619. export default {
  620. name: 'VideoResource',
  621. components: {
  622. MinimizableDialog
  623. },
  624. data() {
  625. return {
  626. // 遮罩层
  627. loading: true,
  628. // 选中数组
  629. ids: [],
  630. // 非单个禁用
  631. single: true,
  632. // 非多个禁用
  633. multiple: true,
  634. // 显示搜索条件
  635. showSearch: true,
  636. // 总条数
  637. total: 0,
  638. // 视频素材库表格数据
  639. resourceList: [],
  640. // 弹出层标题
  641. title: "",
  642. // 是否显示弹出层
  643. open: false,
  644. // 查询参数
  645. queryParams: {
  646. pageNum: 1,
  647. pageSize: 10,
  648. resourceName: null,
  649. fileName: null,
  650. typeId: null,
  651. typeSubId: null
  652. },
  653. // 表单参数
  654. form: {
  655. id: null,
  656. resourceName: null,
  657. fileName: null,
  658. thumbnail: null,
  659. line1: null,
  660. line2: null,
  661. line3: null,
  662. duration: null,
  663. fileSize: null,
  664. fileKey: null,
  665. videoUrl: null,
  666. typeId: null,
  667. typeSubId: null,
  668. projectIds: []
  669. },
  670. // 表单校验
  671. rules: {
  672. resourceName: [
  673. { required: true, message: "素材名称不能为空", trigger: "blur" }
  674. ],
  675. fileName: [
  676. { required: true, message: "文件名称不能为空", trigger: "blur" }
  677. ],
  678. typeId: [
  679. { required: true, message: "请选择分类", trigger: "change" }
  680. ],
  681. typeSubId: [
  682. { required: true, message: "请选择子分类", trigger: "change" }
  683. ],
  684. videoUrl: [
  685. { required: true, message: "请上传视频", trigger: "change" }
  686. ]
  687. },
  688. // 课程列表数据
  689. projectList: [],
  690. projectShowList: [],
  691. // 分类
  692. typeList: [],
  693. rootTypeList: [],
  694. subTypeList: [],
  695. // 视频上传
  696. videoDisabled: false,
  697. videoPreviewVisible: false,
  698. videoPreviewUrl: '',
  699. fileList: [],
  700. // 批量添加相关
  701. batchAddVisible: false,
  702. batchLoading: false,
  703. videoList: [],
  704. // 批量上传相关
  705. showUpload: false,
  706. batchUploadForm: {
  707. typeId: null,
  708. typeSubId: null,
  709. projectIds: [],
  710. files: []
  711. },
  712. batchFileList: [],
  713. // 弹窗选择项目相关
  714. projectDialogVisible: false,
  715. projectQueryParams: {
  716. pageNum: 1,
  717. pageSize: 10,
  718. questionType: null,
  719. questionSubType: null,
  720. title: null
  721. },
  722. projectLoading: false,
  723. projectListTotal: 0,
  724. selectedProjectIds: [],
  725. selectedType: 0,
  726. currentRow: null,
  727. // 分类树相关数据
  728. categoryFilterText: '',
  729. categoryTreeData: [],
  730. add: false,
  731. // 题目列表
  732. projectListDialogVisible: false,
  733. // 修改视频记录
  734. batchEditDialog: {
  735. title: '修改视频',
  736. open: false,
  737. form: {},
  738. rules: {
  739. resourceName: [
  740. { required: true, message: "素材名称不能为空", trigger: "blur" }
  741. ],
  742. fileName: [
  743. { required: true, message: "文件名称不能为空", trigger: "blur" }
  744. ]
  745. },
  746. },
  747. // 是否存在最小化窗口
  748. hasMinimizableDialog: false,
  749. }
  750. },
  751. watch: {
  752. categoryFilterText(val) {
  753. this.$refs.categoryTree.filter(val);
  754. }
  755. },
  756. created() {
  757. this.getTypeList();
  758. this.getRootTypeList()
  759. this.getList();
  760. },
  761. methods: {
  762. /** 将数字索引转换为字母序号 (0->A, 1->B, 等) */
  763. convertToLetter(index) {
  764. // 确保索引是数字
  765. let numIndex = parseInt(index, 10);
  766. // 如果无法转换成数字,返回原始值
  767. if (isNaN(numIndex)) {
  768. return index;
  769. }
  770. // 处理负数情况
  771. if (numIndex < 0) {
  772. return index;
  773. }
  774. // 直接使用索引计算ASCII码(0对应A,1对应B,以此类推)
  775. return String.fromCharCode(65 + numIndex); // 65 是大写字母 A 的ASCII码
  776. },
  777. /** 查询视频素材库列表 */
  778. getList() {
  779. this.loading = true;
  780. listVideoResource(this.queryParams).then(response => {
  781. this.resourceList = response.rows;
  782. this.total = response.total;
  783. this.loading = false;
  784. });
  785. },
  786. // 取消按钮
  787. cancel() {
  788. this.$refs.videoUpload.clearFiles()
  789. this.open = false;
  790. this.reset();
  791. this.changeCateType(this.queryParams.typeId)
  792. },
  793. // 表单重置
  794. reset() {
  795. // 初始化表单对象
  796. this.form = {
  797. id: null,
  798. resourceName: null,
  799. fileName: null,
  800. thumbnail: null,
  801. line1: null,
  802. line2: null,
  803. line3: null,
  804. duration: null,
  805. fileSize: null,
  806. fileKey: null,
  807. videoUrl: null,
  808. typeId: null,
  809. typeSubId: null,
  810. projectIds: []
  811. };
  812. // 重置表单验证状态
  813. this.resetForm("form");
  814. this.add = false
  815. },
  816. /** 搜索按钮操作 */
  817. handleQuery() {
  818. this.queryParams.pageNum = 1;
  819. this.getList();
  820. },
  821. /** 重置按钮操作 */
  822. resetQuery() {
  823. this.resetForm("queryForm");
  824. this.handleQuery();
  825. },
  826. // 多选框选中数据
  827. handleSelectionChange(selection) {
  828. this.ids = selection.map(item => item.id)
  829. this.single = selection.length!==1
  830. this.multiple = !selection.length
  831. },
  832. /** 新增按钮操作 */
  833. handleAdd() {
  834. // 先清空文件列表
  835. this.fileList = [];
  836. this.projectShowList = [];
  837. // 先重置表单
  838. this.reset();
  839. this.subTypeList = []
  840. // 重置上传组件
  841. if (this.$refs.videoUpload) {
  842. this.$refs.videoUpload.clearFiles();
  843. }
  844. // 所有重置完成后再打开弹窗
  845. this.open = true;
  846. this.title = "添加视频素材库";
  847. },
  848. /** 修改按钮操作 */
  849. handleUpdate(row) {
  850. // 先清空文件列表
  851. this.fileList = [];
  852. this.projectShowList = [];
  853. // 先重置表单
  854. this.reset();
  855. this.subTypeList = []
  856. const id = row.id
  857. // 获取数据并设置表单
  858. getVideoResource(id).then(async response => {
  859. this.form = response.data;
  860. await this.changeCateType(this.form.typeId)
  861. // 处理projectIds,确保是数组格式
  862. if (this.form.projectIds && typeof this.form.projectIds === 'string') {
  863. this.form.projectIds = this.form.projectIds.split(',').map(id => parseInt(id));
  864. } else if (!this.form.projectIds) {
  865. this.form.projectIds = [];
  866. }
  867. // 如果存在关联项目,获取项目详情用于回显
  868. if (this.form.projectIds && this.form.projectIds.length > 0) {
  869. // 加载项目列表信息用于回显
  870. await getByIds({ids: this.form.projectIds.join(',')}).then(reponse => {
  871. this.projectShowList = reponse.data
  872. });
  873. }
  874. // 如果存在视频URL,设置fileList
  875. if (this.form.videoUrl) {
  876. this.fileList = [{
  877. name: this.form.fileName || '视频文件',
  878. url: this.form.videoUrl,
  879. thumbnail: this.form.thumbnail,
  880. status: 'success' // 设置为成功状态
  881. }];
  882. }
  883. // 所有设置完成后再打开弹窗
  884. this.open = true;
  885. this.title = "修改视频素材库";
  886. });
  887. },
  888. /** 提交按钮 */
  889. submitForm() {
  890. this.$refs["form"].validate(valid => {
  891. if (valid) {
  892. if (this.add){
  893. this.$message.warning("文件上传中,请稍后再试")
  894. return
  895. }
  896. const params = Object.assign({}, this.form);
  897. params.projectIds = this.form.projectIds.join(',');
  898. if (this.form.id != null) {
  899. updateVideoResource(params).then(response => {
  900. if (response.code === 200) {
  901. this.msgSuccess("修改成功");
  902. this.open = false;
  903. this.getList();
  904. }
  905. });
  906. } else {
  907. addVideoResource(params).then(response => {
  908. if (response.code === 200) {
  909. this.msgSuccess("新增成功");
  910. this.open = false;
  911. this.getList();
  912. }
  913. });
  914. }
  915. }
  916. });
  917. },
  918. /** 删除按钮操作 */
  919. handleDelete(row) {
  920. const ids = row.id || this.ids;
  921. this.$confirm('是否确认删除视频素材库编号为"' + ids + '"的数据项?', "警告", {
  922. confirmButtonText: "确定",
  923. cancelButtonText: "取消",
  924. type: "warning"
  925. }).then(function() {
  926. return deleteVideoResource(ids);
  927. }).then(() => {
  928. this.getList();
  929. this.msgSuccess("删除成功");
  930. }).catch(function() {});
  931. },
  932. /** 查询视频分类列表 */
  933. getTypeList() {
  934. listUserCourseCategory().then(response => {
  935. this.typeList = response.data;
  936. });
  937. },
  938. getRootTypeList() {
  939. getCatePidList().then(response => {
  940. this.rootTypeList = response.data
  941. });
  942. },
  943. async changeCateType(val, type) {
  944. if (type === 1) {
  945. this.queryParams.typeSubId = null
  946. }
  947. if (type === 2) {
  948. this.form.typeSubId = null
  949. }
  950. if (type === 3) {
  951. this.batchUploadForm.typeSubId = null
  952. }
  953. this.subTypeList = []
  954. if (!val) {
  955. return
  956. }
  957. await getCateListByPid(val).then(response => {
  958. this.subTypeList = response.data
  959. })
  960. },
  961. /** 预览视频 */
  962. handleVideoPreview(url) {
  963. this.videoPreviewVisible = true;
  964. this.videoPreviewUrl = url || this.form.videoUrl;
  965. },
  966. /** 格式化视频时长 */
  967. formatDuration(seconds) {
  968. if (!seconds) return '00:00';
  969. const minutes = Math.floor(seconds / 60);
  970. const remainingSeconds = seconds % 60;
  971. return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
  972. },
  973. /** 移除视频 */
  974. handleRemove(file) {
  975. this.fileList.splice(this.fileList.indexOf(file), 1);
  976. this.form.videoUrl = '';
  977. this.form.thumbnail = '';
  978. this.form.duration = 0;
  979. this.form.fileSize = 0;
  980. this.form.fileName = '';
  981. this.form.line1 = '';
  982. this.form.line_2 = '';
  983. this.form.line_3 = '';
  984. this.uploadType = null
  985. this.fileSize = null
  986. this.fileKey = null
  987. },
  988. //获取第一帧封面
  989. async getFirstThumbnail(file, form){
  990. getThumbnail(file).then(response => {
  991. form.thumbnail = response.url;
  992. })
  993. },
  994. //上传腾讯云Pcdn
  995. async uploadVideoToTxPcdn(file, form, onProgress) {
  996. try {
  997. const data = await uploadObject(file, (progress) => {
  998. const progressEvent = {
  999. percent: Math.floor(progress.percent * 100 / 2), // COS SDK 百分比是 0-1,el-upload 需要 0-100
  1000. loaded: progress.loaded,
  1001. total: progress.total,
  1002. lengthComputable: true // 文件上传通常总大小可知
  1003. };
  1004. onProgress(progressEvent);
  1005. }, 1);
  1006. let line_1 = `${process.env.VUE_APP_VIDEO_LINE_1}${data.urlPath}`;
  1007. form.fileKey = data.urlPath.substring(1);
  1008. form.videoUrl = line_1;
  1009. form.line1 = line_1;
  1010. this.$message.success("线路一上传成功");
  1011. } catch (error) {
  1012. this.$message.error("线路一上传失败");
  1013. }
  1014. },
  1015. //上传华为云Obs
  1016. async uploadVideoToHwObs(file, form, onProgress) {
  1017. try {
  1018. const data = await uploadToOBS(file, (progress) => {
  1019. const progressEvent = {
  1020. percent: Math.floor(progress / 2) + 50,
  1021. loaded: progress,
  1022. total: progress,
  1023. lengthComputable: true // 文件上传通常总大小可知
  1024. };
  1025. onProgress(progressEvent);
  1026. }, 1);
  1027. form.line2 = `${process.env.VUE_APP_VIDEO_LINE_2}/${data.urlPath}`;
  1028. this.$message.success("线路二上传成功");
  1029. } catch (error) {
  1030. this.$message.error("线路二上传失败");
  1031. }
  1032. },
  1033. // 上传视频
  1034. async videoUpload(options) {
  1035. this.add = true
  1036. const file = options.file;
  1037. this.getMediaDuration(file)
  1038. // 获取第一帧图片
  1039. await this.getFirstThumbnail(file, this.form);
  1040. // 上传腾讯云pcdn
  1041. await this.uploadVideoToTxPcdn(file, this.form, options.onProgress);
  1042. // 上传华为obs
  1043. await this.uploadVideoToHwObs(file, this.form, options.onProgress);
  1044. this.form.fileName = file.name;
  1045. this.form.fileSize = file.size;
  1046. this.add = false
  1047. },
  1048. // 获取媒体文件时长
  1049. getMediaDuration(file) {
  1050. // 处理视频
  1051. const video = document.createElement('video');
  1052. video.preload = 'metadata';
  1053. video.onloadedmetadata = () => {
  1054. this.form.duration = Math.round(video.duration);
  1055. };
  1056. video.src = URL.createObjectURL(file);
  1057. },
  1058. handleFileChange(file, files) {
  1059. // 保留最后一个文件
  1060. this.fileList = files.slice(-1);
  1061. },
  1062. /** 批量新增 */
  1063. handleBatchAdd() {
  1064. this.batchAddVisible = true;
  1065. this.videoList = []; // 清空之前的视频列表
  1066. },
  1067. cancelBeforeBatch(done, cancel) {
  1068. if (!this.videoList || this.videoList.length === 0) {
  1069. done()
  1070. return
  1071. }
  1072. this.$confirm('关闭窗口视频需要重新上传,确定关闭吗?', '提示', {
  1073. confirmButtonText: '确定',
  1074. cancelButtonText: '取消',
  1075. type: 'warning'
  1076. }).then(() => {
  1077. done()
  1078. }).catch(() => {
  1079. cancel()
  1080. });
  1081. },
  1082. /** 取消批量 */
  1083. cancelBatch() {
  1084. if (!this.videoList || this.videoList.length === 0) {
  1085. this.batchAddVisible = false
  1086. return
  1087. }
  1088. this.$confirm('关闭窗口视频需要重新上传,确定关闭吗?', '提示', {
  1089. confirmButtonText: '确定',
  1090. cancelButtonText: '取消',
  1091. type: 'warning'
  1092. }).then(() => {
  1093. this.batchAddVisible = false
  1094. this.changeCateType(this.queryParams.typeId)
  1095. }).catch(() => {
  1096. });
  1097. },
  1098. /** 提交批量添加 */
  1099. submitBatchAdd() {
  1100. // 检查是否所有选中的视频都已上传完成
  1101. const incompleteVideos = this.videoList.filter(item => (item.progress || 0) < 100);
  1102. if (incompleteVideos.length > 0) {
  1103. this.$message.warning('有未完成上传的视频,请先完成上传');
  1104. return;
  1105. }
  1106. // 调用批量添加API
  1107. const videoList = JSON.parse(JSON.stringify(this.videoList));
  1108. videoList.forEach(item => {
  1109. item.projectIds = item.projectIds.join(",");
  1110. });
  1111. batchAddVideoResource(videoList).then(response => {
  1112. if (response.code === 200) {
  1113. this.$message.success('批量添加成功');
  1114. this.batchAddVisible = false;
  1115. this.getList();
  1116. }
  1117. });
  1118. },
  1119. /** 获取分类名称 */
  1120. getTypeName(typeId) {
  1121. const type = this.typeList.find(item => item.cateId === typeId);
  1122. return type ? type.cateName : '';
  1123. },
  1124. /** 编辑视频信息 */
  1125. handleEditVideo(row) {
  1126. this.batchEditDialog.form = Object.assign({}, row)
  1127. this.changeCateType(row.typeId)
  1128. this.batchEditDialog.open = true
  1129. },
  1130. batchEditCancel() {
  1131. this.resetForm('batchEditDialogForm')
  1132. this.batchEditDialog.open = false
  1133. },
  1134. batchEditSubmitForm() {
  1135. let temp = this.videoList.find(item => item.tempId === this.batchEditDialog.form.tempId)
  1136. Object.assign(temp, this.batchEditDialog.form)
  1137. this.batchEditDialog.open = false
  1138. },
  1139. /** 删除视频 */
  1140. handleDeleteVideo(row) {
  1141. this.$confirm('确认要从列表中删除该视频吗?', '提示', {
  1142. confirmButtonText: '确定',
  1143. cancelButtonText: '取消',
  1144. type: 'warning'
  1145. }).then(() => {
  1146. // 从视频列表中删除该项
  1147. const index = this.videoList.findIndex(item => {
  1148. // 通过文件名和大小确定唯一性,因为临时视频可能没有id
  1149. return item.tempId === row.tempId
  1150. });
  1151. if (index !== -1) {
  1152. this.videoList.splice(index, 1);
  1153. this.$message({
  1154. type: 'success',
  1155. message: '已从列表中移除该视频'
  1156. });
  1157. }
  1158. }).catch(() => {
  1159. // 取消删除
  1160. });
  1161. },
  1162. /** 显示上传面板 */
  1163. showUploadPanel() {
  1164. this.showUpload = true;
  1165. this.batchUploadForm = {
  1166. typeId: null,
  1167. typeSubId: null,
  1168. projectIds: [],
  1169. files: []
  1170. };
  1171. this.batchFileList = [];
  1172. this.subTypeList = []
  1173. if (this.$refs.batchVideoUpload) {
  1174. this.$refs.batchVideoUpload.clearFiles();
  1175. }
  1176. },
  1177. /** 批量文件变更 */
  1178. handleBatchFileChange(file, fileList) {
  1179. this.batchFileList = fileList;
  1180. },
  1181. /** 批量上传视频 */
  1182. async batchVideoUpload(options) {
  1183. const file = options.file;
  1184. // 创建临时视频对象添加到列表中
  1185. const tempVideo = {
  1186. tempId: Math.random().toString(36).substring(2, 15),
  1187. resourceName: file.name.split('.')[0], // 使用文件名作为视频名称
  1188. fileName: file.name,
  1189. thumbnail: null,
  1190. line1: null,
  1191. line2: null,
  1192. line3: null,
  1193. duration: 0, // 先默认为0,后续获取真实时长
  1194. fileSize: file.size,
  1195. fileKey: null,
  1196. videoUrl: null,
  1197. typeId: this.batchUploadForm.typeId, // 使用选择的分类
  1198. typeSubId: this.batchUploadForm.typeSubId, // 使用选择的子分类
  1199. projectIds: this.batchUploadForm.projectIds, // 使用选择的项目
  1200. progress: 0, // 上传进度
  1201. file: file // 保存文件引用
  1202. };
  1203. // 添加到视频列表
  1204. this.videoList.unshift(tempVideo);
  1205. // 获取视频时长
  1206. const video = document.createElement('video');
  1207. video.preload = 'metadata';
  1208. video.onloadedmetadata = () => {
  1209. const index = this.videoList.findIndex(item => item.tempId === tempVideo.tempId);
  1210. if (index !== -1) {
  1211. tempVideo.duration = Math.round(video.duration);
  1212. }
  1213. };
  1214. video.src = URL.createObjectURL(file);
  1215. // 关闭上传弹窗,返回批量选择视频弹窗
  1216. this.showUpload = false;
  1217. try {
  1218. // 获取封面
  1219. await this.getFirstThumbnail(file, tempVideo);
  1220. // 上传到第一个服务器
  1221. await this.uploadVideoToTxPcdn(file, tempVideo, (event) => {
  1222. tempVideo.progress = event.percent
  1223. });
  1224. // 上传到第二个服务器
  1225. await this.uploadVideoToHwObs(file, tempVideo, (event) => {
  1226. tempVideo.progress = event.percent
  1227. });
  1228. } catch (error) {
  1229. this.$message.error(`文件 ${file.name} 上传失败: ${error.message || '未知错误'}`);
  1230. }
  1231. if (this.$refs.batchVideoUpload) {
  1232. this.$refs.batchVideoUpload.clearFiles();
  1233. }
  1234. },
  1235. /** 复制视频链接到剪贴板 */
  1236. copy(url) {
  1237. // 创建一个临时的input元素
  1238. const input = document.createElement('input');
  1239. // 设置input的值为要复制的视频链接
  1240. input.value = url;
  1241. // 将input添加到DOM中
  1242. document.body.appendChild(input);
  1243. // 选中input的值
  1244. input.select();
  1245. // 执行复制命令
  1246. document.execCommand('copy');
  1247. // 从DOM中移除input元素
  1248. document.body.removeChild(input);
  1249. // 提示用户复制成功
  1250. this.$message({
  1251. message: '已复制到剪贴板',
  1252. type: 'success',
  1253. duration: 1500
  1254. });
  1255. },
  1256. getProjectList() {
  1257. this.projectLoading = true
  1258. listCourseQuestionBank(this.projectQueryParams).then(response => {
  1259. this.projectList = response.rows;
  1260. this.projectListTotal = response.total;
  1261. // 如果存在已选择的项目,预选中表格中对应的行
  1262. this.$nextTick(() => {
  1263. // 获取表格组件实例
  1264. const projectTable = this.$refs.projectTable;
  1265. if (projectTable) {
  1266. if (this.selectedProjectIds.length > 0) {
  1267. // 遍历项目列表,找到匹配的ID并选中对应行
  1268. const selectedIds = this.selectedProjectIds;
  1269. this.projectList.forEach(row => {
  1270. if (selectedIds.includes(row.id)) {
  1271. projectTable.toggleRowSelection(row, true);
  1272. }
  1273. });
  1274. }
  1275. }
  1276. });
  1277. this.projectLoading = false
  1278. });
  1279. },
  1280. /** 打开项目选择弹窗 */
  1281. openProjectDialog(projectIds, type) {
  1282. this.$nextTick(() => {
  1283. if (this.$refs.customSelect) {
  1284. this.$refs.customSelect.blur();
  1285. }
  1286. });
  1287. // 重置查询参数
  1288. this.projectQueryParams = {
  1289. pageNum: 1,
  1290. pageSize: 10,
  1291. questionType: null,
  1292. title: null
  1293. };
  1294. this.selectedType = type
  1295. // 设置选中的项目IDs
  1296. if (projectIds) {
  1297. if (typeof projectIds === 'string') {
  1298. this.selectedProjectIds = projectIds.split(',').map(id => parseInt(id));
  1299. } else if (Array.isArray(projectIds)) {
  1300. this.selectedProjectIds = [...projectIds];
  1301. } else if (typeof projectIds === 'number') {
  1302. this.selectedProjectIds = [projectIds];
  1303. }
  1304. } else {
  1305. this.selectedProjectIds = [];
  1306. }
  1307. // 显示弹窗
  1308. this.projectDialogVisible = true;
  1309. // 加载分类树数据
  1310. this.initCategoryTree();
  1311. // 加载项目列表
  1312. this.getProjectList();
  1313. },
  1314. /** 确认选择项目 */
  1315. confirmSelectProject() {
  1316. // 更新表单中的项目ID
  1317. if (this.selectedType === 0) {
  1318. this.form.projectIds = this.selectedProjectIds;
  1319. }
  1320. else if (this.selectedType === 1) {
  1321. this.batchUploadForm.projectIds = this.selectedProjectIds;
  1322. }
  1323. else if (this.selectedType === 2) {
  1324. this.batchEditDialog.form.projectIds = this.selectedProjectIds;
  1325. }
  1326. else if (this.selectedType === 3) {
  1327. const params = {
  1328. id: this.currentRow.id,
  1329. projectIds: this.selectedProjectIds.join(",")
  1330. }
  1331. updateVideoResource(params).then(response => {
  1332. if (response.code === 200) {
  1333. this.msgSuccess("修改成功");
  1334. this.open = false;
  1335. this.getList();
  1336. }
  1337. });
  1338. }
  1339. else if (this.selectedType === 4) {
  1340. this.currentRow.projectIds = this.selectedProjectIds
  1341. }
  1342. this.projectDialogVisible = false;
  1343. },
  1344. /** 取消选择项目 */
  1345. cancelSelectProject() {
  1346. const projectTable = this.$refs.projectTable;
  1347. if (projectTable) {
  1348. // 清空表格数据
  1349. projectTable.clearSelection();
  1350. }
  1351. this.projectDialogVisible = false;
  1352. },
  1353. handleProjectSelect(selection) {
  1354. this.selectedProjectIds = selection.map(item => item.id);
  1355. selection.forEach(item => {
  1356. // 检查是否已存在该项目,不存在则添加
  1357. if (!this.projectShowList.some(p => p.id === item.id)) {
  1358. this.projectShowList.push(item);
  1359. }
  1360. });
  1361. },
  1362. /** 项目列表页码变更 */
  1363. handleProjectPageChange(page) {
  1364. this.projectQueryParams.pageNum = page;
  1365. this.getProjectList();
  1366. },
  1367. /** 项目列表每页条数变更 */
  1368. handleProjectPageSizeChange(size) {
  1369. this.projectQueryParams.pageNum = 1;
  1370. this.projectQueryParams.pageSize = size;
  1371. this.getProjectList();
  1372. },
  1373. /** 处理查看项目 */
  1374. handleViewProject(row, type) {
  1375. // 保存当前选择的行,以便后续操作
  1376. this.currentRow = row;
  1377. // 设置form对象的projectIds为当前行的项目IDs
  1378. this.projectShowList = [];
  1379. if (!row.projectIds || row.projectIds.length === 0) {
  1380. this.openProjectDialog(null, type)
  1381. return;
  1382. }
  1383. let projectIds = row.projectIds
  1384. if (Array.isArray(row.projectIds)) {
  1385. projectIds = projectIds.join(',');
  1386. }
  1387. getByIds({ids: projectIds}).then(response => {
  1388. this.projectShowList = response.data;
  1389. })
  1390. // 打开弹窗展示列表
  1391. this.projectListDialogVisible = true;
  1392. },
  1393. /** 初始化分类树 */
  1394. initCategoryTree() {
  1395. // 获取分类列表
  1396. listUserCourseCategory().then(response => {
  1397. const treeDate = this.handleTree(response.data, "cateId", "pid");
  1398. this.categoryTreeData = [{
  1399. cateId: 0,
  1400. cateName: '全部',
  1401. children: treeDate
  1402. }];
  1403. });
  1404. },
  1405. filterNode(value, data) {
  1406. if (!value) return true;
  1407. return data.cateName.indexOf(value) !== -1;
  1408. },
  1409. /** 处理分类点击 */
  1410. handleCategoryClick(data, node) {
  1411. // 更新查询参数
  1412. this.projectQueryParams.pageNum = 1;
  1413. // 如果是全部分类,则清空分类过滤
  1414. if (node.level === 1) {
  1415. this.projectQueryParams.questionType = null;
  1416. this.projectQueryParams.questionSubType = null;
  1417. }
  1418. else if (node.level === 2) {
  1419. this.projectQueryParams.questionType = data.cateId;
  1420. this.projectQueryParams.questionSubType = null;
  1421. }
  1422. else if (node.level === 3) {
  1423. this.projectQueryParams.questionType = null;
  1424. this.projectQueryParams.questionSubType = data.cateId;
  1425. }
  1426. // 重新加载项目列表
  1427. this.getProjectList();
  1428. },
  1429. /** 搜索项目 */
  1430. searchProjects() {
  1431. this.projectQueryParams.pageNum = 1;
  1432. this.getProjectList();
  1433. },
  1434. /** 视频预览弹窗关闭前的处理函数 */
  1435. handleCloseVideoPreview(done) {
  1436. // 停止视频播放
  1437. const video = document.getElementById('video');
  1438. if (video) {
  1439. video.pause();
  1440. video.currentTime = 0;
  1441. }
  1442. // 关闭弹窗
  1443. this.videoPreviewVisible = false;
  1444. done();
  1445. },
  1446. }
  1447. }
  1448. </script>
  1449. <style scoped>
  1450. /* 自定义表格样式 */
  1451. .el-table .video-cell {
  1452. padding: 5px;
  1453. }
  1454. /* 设置删除和修改按钮的间距 */
  1455. .el-button + .el-button {
  1456. margin-left: 5px;
  1457. }
  1458. ::v-deep .upload-icon {
  1459. font-size: 28px;
  1460. color: #8c939d;
  1461. }
  1462. ::v-deep .upload-text {
  1463. font-size: 12px;
  1464. color: #606266;
  1465. margin-top: 10px;
  1466. }
  1467. /* 表单样式 */
  1468. ::v-deep .el-form-item {
  1469. margin-bottom: 22px;
  1470. }
  1471. /* 批量选择弹窗样式 */
  1472. ::v-deep .batch-dialog .el-dialog__body {
  1473. padding: 0 20px 20px;
  1474. max-height: 70vh;
  1475. overflow-y: auto;
  1476. }
  1477. ::v-deep .el-dialog .el-dialog__body {
  1478. padding: 0 20px 20px;
  1479. max-height: 70vh;
  1480. overflow-y: auto;
  1481. }
  1482. .filter-container {
  1483. padding: 15px 0;
  1484. background-color: #fff;
  1485. border-bottom: 1px solid #ebeef5;
  1486. position: relative;
  1487. text-align: right;
  1488. }
  1489. .dialog-footer {
  1490. text-align: right;
  1491. margin-top: 20px;
  1492. padding-right: 20px;
  1493. }
  1494. ::v-deep .batch-dialog .el-table {
  1495. margin-top: 10px;
  1496. }
  1497. /* 按钮样式 */
  1498. ::v-deep .el-button--primary {
  1499. background-color: #1890ff;
  1500. border-color: #1890ff;
  1501. }
  1502. ::v-deep .el-button--primary:hover {
  1503. background-color: #40a9ff;
  1504. border-color: #40a9ff;
  1505. }
  1506. ::v-deep .el-button--primary:focus {
  1507. background-color: #40a9ff;
  1508. border-color: #40a9ff;
  1509. }
  1510. /* 表格头部样式 */
  1511. ::v-deep .batch-dialog .el-table__header-wrapper th {
  1512. background-color: #f5f7fa;
  1513. color: #606266;
  1514. font-weight: 500;
  1515. padding: 8px 0;
  1516. }
  1517. ::v-deep .el-table__header-wrapper th {
  1518. background-color: #f5f7fa;
  1519. color: #606266;
  1520. font-weight: 500;
  1521. padding: 8px 0;
  1522. }
  1523. /* 确保弹窗中表格内容垂直居中 */
  1524. ::v-deep .batch-dialog .el-table .cell {
  1525. line-height: 23px;
  1526. }
  1527. ::v-deep .el-table .cell {
  1528. line-height: 23px;
  1529. }
  1530. /* 自定义滚动条样式 */
  1531. ::v-deep .batch-dialog .el-dialog__body::-webkit-scrollbar {
  1532. width: 6px;
  1533. height: 6px;
  1534. }
  1535. ::v-deep .el-dialog .el-dialog__body::-webkit-scrollbar {
  1536. width: 6px;
  1537. height: 6px;
  1538. }
  1539. ::v-deep .batch-dialog .el-dialog__body::-webkit-scrollbar-thumb {
  1540. background: #c0c4cc;
  1541. border-radius: 3px;
  1542. }
  1543. ::v-deep .el-dialog .el-dialog__body::-webkit-scrollbar-thumb {
  1544. background: #c0c4cc;
  1545. border-radius: 3px;
  1546. }
  1547. ::v-deep .batch-dialog .el-dialog__body::-webkit-scrollbar-track {
  1548. background: #f5f7fa;
  1549. }
  1550. ::v-deep .el-dialog .el-dialog__body::-webkit-scrollbar-track {
  1551. background: #f5f7fa;
  1552. }
  1553. /* 批量上传视频弹窗样式 */
  1554. .upload-dialog .el-dialog__body {
  1555. padding: 20px;
  1556. }
  1557. ::v-deep .upload-dialog .el-dialog__header {
  1558. padding: 15px 20px;
  1559. background-color: #f9f9f9;
  1560. border-bottom: 1px solid #ebeef5;
  1561. }
  1562. ::v-deep .upload-dialog .el-dialog__title {
  1563. font-size: 16px;
  1564. font-weight: 500;
  1565. color: #303133;
  1566. }
  1567. /* 项目选择弹窗样式 */
  1568. ::v-deep .el-dialog__wrapper {
  1569. z-index: 2001 !important;
  1570. }
  1571. ::v-deep .el-dialog__header {
  1572. padding: 15px 20px;
  1573. background-color: #f9f9f9;
  1574. border-bottom: 1px solid #ebeef5;
  1575. }
  1576. ::v-deep .el-dialog__title {
  1577. font-size: 16px;
  1578. font-weight: 500;
  1579. color: #303133;
  1580. }
  1581. ::v-deep .el-pagination {
  1582. text-align: center;
  1583. margin-top: 10px;
  1584. }
  1585. /* 项目选择弹窗的样式 */
  1586. .project-container {
  1587. display: flex;
  1588. height: 500px;
  1589. }
  1590. .category-tree {
  1591. width: 250px;
  1592. height: 100%;
  1593. border-right: 1px solid #ebeef5;
  1594. padding: 0;
  1595. display: flex;
  1596. flex-direction: column;
  1597. overflow: hidden;
  1598. flex-shrink: 0;
  1599. }
  1600. .tree-fixed-header {
  1601. padding: 10px;
  1602. background-color: #fff;
  1603. border-bottom: 1px solid #ebeef5;
  1604. z-index: 10;
  1605. box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  1606. }
  1607. .tree-content {
  1608. flex: 1;
  1609. overflow-y: auto;
  1610. padding: 10px 10px 10px 10px;
  1611. }
  1612. .project-list {
  1613. flex: 1;
  1614. padding: 10px;
  1615. height: 100%;
  1616. display: flex;
  1617. flex-direction: column;
  1618. width: calc(100% - 250px); /* 固定宽度为剩余空间 */
  1619. }
  1620. .project-list .filter-container {
  1621. padding: 0 0 15px 0;
  1622. text-align: left;
  1623. }
  1624. .project-list .table-footer {
  1625. margin-top: 15px;
  1626. }
  1627. ::v-deep .el-tree-node__content {
  1628. height: 36px;
  1629. border-radius: 4px;
  1630. margin-bottom: 2px;
  1631. }
  1632. ::v-deep .el-tree-node:focus > .el-tree-node__content {
  1633. background-color: #e6f7ff;
  1634. }
  1635. ::v-deep .el-tree-node__content:hover {
  1636. background-color: #f0f7ff;
  1637. }
  1638. ::v-deep .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  1639. background-color: #e6f7ff;
  1640. color: #1890ff;
  1641. }
  1642. ::v-deep .custom-tree-node {
  1643. flex: 1;
  1644. display: flex;
  1645. align-items: center;
  1646. justify-content: space-between;
  1647. font-size: 14px;
  1648. padding: 0 8px;
  1649. }
  1650. /* 视频预览弹窗样式 */
  1651. ::v-deep .video-preview-dialog {
  1652. z-index: 3000 !important;
  1653. }
  1654. ::v-deep .video-preview-dialog .el-dialog {
  1655. margin-top: 10vh !important;
  1656. }
  1657. ::v-deep .video-preview-dialog .el-dialog__header {
  1658. padding: 15px 20px;
  1659. background-color: #f9f9f9;
  1660. border-bottom: 1px solid #ebeef5;
  1661. }
  1662. ::v-deep .video-preview-dialog .el-dialog__body {
  1663. padding: 15px;
  1664. background-color: #000;
  1665. display: flex;
  1666. justify-content: center;
  1667. align-items: center;
  1668. }
  1669. ::v-deep .video-preview-dialog video {
  1670. max-width: 100%;
  1671. max-height: 70vh;
  1672. }
  1673. /* 题目列表样式 */
  1674. .project-list-container {
  1675. background-color: #f5f7fa;
  1676. border-radius: 4px;
  1677. }
  1678. .question-card {
  1679. background-color: #ffffff;
  1680. border-radius: 4px;
  1681. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  1682. padding: 15px;
  1683. margin-bottom: 15px;
  1684. position: relative;
  1685. }
  1686. .question-header {
  1687. display: flex;
  1688. align-items: flex-start;
  1689. margin-bottom: 10px;
  1690. border-bottom: 1px solid #ebeef5;
  1691. padding-bottom: 10px;
  1692. }
  1693. .question-index {
  1694. display: flex;
  1695. justify-content: center;
  1696. align-items: center;
  1697. width: 24px;
  1698. height: 24px;
  1699. background-color: #409EFF;
  1700. color: white;
  1701. border-radius: 50%;
  1702. font-size: 14px;
  1703. margin-right: 10px;
  1704. flex-shrink: 0;
  1705. }
  1706. .question-title {
  1707. font-size: 16px;
  1708. font-weight: 500;
  1709. color: #303133;
  1710. line-height: 1.5;
  1711. word-break: break-all;
  1712. }
  1713. .question-type {
  1714. margin-bottom: 15px;
  1715. }
  1716. .content-title {
  1717. font-weight: 500;
  1718. color: #606266;
  1719. margin-bottom: 10px;
  1720. }
  1721. .question-content {
  1722. margin-bottom: 15px;
  1723. }
  1724. .question-item {
  1725. background-color: #f8f8f8;
  1726. border-left: 3px solid #409EFF;
  1727. padding: 10px;
  1728. margin-bottom: 10px;
  1729. border-radius: 0 4px 4px 0;
  1730. }
  1731. .question-item-header {
  1732. display: flex;
  1733. align-items: center;
  1734. margin-bottom: 5px;
  1735. }
  1736. .item-index {
  1737. display: inline-block;
  1738. margin-right: 10px;
  1739. font-weight: 500;
  1740. color: #409EFF;
  1741. }
  1742. .item-name {
  1743. color: #303133;
  1744. }
  1745. .question-answer {
  1746. background-color: #f0f9eb;
  1747. padding: 10px;
  1748. border-radius: 4px;
  1749. border-left: 3px solid #67c23a;
  1750. }
  1751. .answer-label {
  1752. font-weight: 500;
  1753. color: #67c23a;
  1754. margin-right: 10px;
  1755. }
  1756. .answer-content {
  1757. color: #606266;
  1758. }
  1759. ::v-deep .custom-select-class .el-select__tags {
  1760. display: flex;
  1761. flex-direction: column;
  1762. align-items: flex-start;
  1763. flex-wrap: nowrap;
  1764. max-height: 200px;
  1765. overflow-y: auto;
  1766. }
  1767. ::v-deep .custom-select-class .el-tag {
  1768. margin-bottom: 4px;
  1769. margin-right: 0;
  1770. }
  1771. </style>