index.vue 60 KB

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