index.vue 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001
  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="primary"
  71. icon="el-icon-plus"
  72. size="mini"
  73. :disabled="multiple"
  74. @click="handleBatchUpdate"
  75. v-hasPermi="['course:videoResource:batchUpdateClass']"
  76. >批量修改分类</el-button>
  77. </el-col>
  78. <el-col :span="1.5">
  79. <el-button
  80. type="danger"
  81. icon="el-icon-delete"
  82. size="mini"
  83. :disabled="multiple"
  84. @click="handleDelete"
  85. v-hasPermi="['course:videoResource:remove']"
  86. >删除</el-button>
  87. </el-col>
  88. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  89. </el-row>
  90. <el-table v-loading="loading" :data="resourceList" @selection-change="handleSelectionChange" border>
  91. <el-table-column type="selection" width="55" align="center" />
  92. <el-table-column label="序号" width="55" align="center">
  93. <template slot-scope="scope">
  94. {{ scope.$index + 1 }}
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="素材名称" align="center" :show-overflow-tooltip="true" prop="resourceName"/>
  98. <el-table-column label="文件名称" align="center" :show-overflow-tooltip="true" prop="fileName"/>
  99. <el-table-column label="排序" align="center" prop="sort" />
  100. <el-table-column label="分类" align="center">
  101. <template slot-scope="scope">
  102. <span v-if="scope.row.typeId">{{ getTypeName(scope.row.typeId) }}</span>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="子分类" align="center">
  106. <template slot-scope="scope">
  107. <span v-if="scope.row.typeSubId">{{ getTypeName(scope.row.typeSubId) }}</span>
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="视频文件" align="center">
  111. <template slot-scope="scope">
  112. <a
  113. @click="handleVideoPreview(scope.row.videoUrl)"
  114. 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;">
  115. 查看文件
  116. </a>
  117. </template>
  118. </el-table-column>
  119. <el-table-column label="CDN" align="center">
  120. <template slot-scope="scope">
  121. <a
  122. @click="copy(scope.row.videoUrl)"
  123. style="color: #409EFF; border: none; border-radius: 4px; padding: 4px 12px; cursor: pointer; font-size: 12px; display: inline-block; text-decoration: none;">
  124. 复制链接
  125. </a>
  126. </template>
  127. </el-table-column>
  128. <el-table-column label="关联题目" align="center">
  129. <template slot-scope="scope">
  130. <a
  131. @click="handleViewProject(scope.row, 3)"
  132. :style="scope.row.projectIds ? {
  133. backgroundColor: '#409EFF',
  134. color: 'white',
  135. border: 'none',
  136. borderRadius: '4px',
  137. padding: '4px 12px',
  138. cursor: 'pointer',
  139. fontSize: '12px',
  140. display: 'inline-block',
  141. textDecoration: 'none'
  142. } : {
  143. backgroundColor: 'rgb(154 156 159)',
  144. color: 'white',
  145. border: 'none',
  146. cursor: 'pointer',
  147. borderRadius: '4px',
  148. padding: '4px 12px',
  149. fontSize: '12px',
  150. display: 'inline-block',
  151. textDecoration: 'none'
  152. }">
  153. {{ scope.row.projectIds ? '查看详情' : '未关联题目' }}
  154. </a>
  155. </template>
  156. </el-table-column>
  157. <el-table-column label="视频时长" align="center">
  158. <template slot-scope="scope">
  159. <div style="padding: 4px 12px;background: linear-gradient(to right, rgb(196 219 255), #409EFF)">{{ formatDuration(scope.row.duration) }}</div>
  160. </template>
  161. </el-table-column>
  162. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  163. <template slot-scope="scope">
  164. <el-button
  165. size="mini"
  166. type="text"
  167. icon="el-icon-edit"
  168. @click="handleUpdate(scope.row)"
  169. :disabled="hasMinimizableDialog"
  170. v-hasPermi="['course:videoResource:edit']"
  171. >修改</el-button>
  172. <el-button
  173. size="mini"
  174. type="text"
  175. icon="el-icon-delete"
  176. @click="handleDelete(scope.row)"
  177. v-hasPermi="['course:videoResource:remove']"
  178. >删除</el-button>
  179. </template>
  180. </el-table-column>
  181. </el-table>
  182. <pagination
  183. v-show="total>0"
  184. :total="total"
  185. :page.sync="queryParams.pageNum"
  186. :limit.sync="queryParams.pageSize"
  187. @pagination="getList"
  188. />
  189. <!-- 添加或修改视频素材库对话框 -->
  190. <minimizable-dialog :title="title" :visible.sync="open" width="700px" append-to-body :before-close="cancel"
  191. @minimize="hasMinimizableDialog = true" @restore="hasMinimizableDialog = false">
  192. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  193. <el-form-item label="素材名称" prop="resourceName" style="margin-top: 20px">
  194. <el-input v-model="form.resourceName" placeholder="请输入" />
  195. </el-form-item>
  196. <el-form-item label="文件名称" prop="fileName" style="margin-top: 20px;display: none">
  197. <el-input v-model="form.fileName" placeholder="请输入" />
  198. </el-form-item>
  199. <el-form-item label="分类" prop="typeId">
  200. <el-select v-model="form.typeId" placeholder="请选择分类" style="width: 100%" @change="val => changeCateType(val, 2)">
  201. <el-option
  202. v-for="item in rootTypeList"
  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="typeSubId">
  210. <el-select v-model="form.typeSubId" clearable placeholder="请选择子分类" style="width: 100%">
  211. <el-option
  212. v-for="item in subTypeList"
  213. :key="item.dictValue"
  214. :label="item.dictLabel"
  215. :value="item.dictValue">
  216. </el-option>
  217. </el-select>
  218. </el-form-item>
  219. <el-form-item label="排序" prop="sort">
  220. <el-input-number v-model="form.sort" :min="0" label="请输入排序"></el-input-number>
  221. </el-form-item>
  222. <el-form-item label="关联题目" prop="projectIds">
  223. <el-select
  224. ref="customSelect"
  225. class="custom-select-class"
  226. v-model="form.projectIds"
  227. multiple
  228. placeholder="请选择关联题目"
  229. @click.native.stop="openProjectDialog(form.projectIds, 0)"
  230. style="width: 100%;">
  231. <el-option
  232. v-for="item in projectShowList"
  233. :key="item.id"
  234. :label="item.title"
  235. :value="item.id">
  236. </el-option>
  237. </el-select>
  238. </el-form-item>
  239. <el-form-item label="上传视频" prop="videoUrl" required>
  240. <el-upload
  241. ref="videoUpload"
  242. action="#"
  243. list-type="picture-card"
  244. :http-request="videoUpload"
  245. :file-list="fileList"
  246. :on-change="handleFileChange"
  247. accept=".mp4">
  248. <i slot="default" class="el-icon-plus"></i>
  249. <div slot="file" slot-scope="{file}">
  250. <div
  251. class="el-upload-list__item-thumbnail"
  252. style="display: flex; justify-content: center; align-items: center; background-color: #f5f7fa; height: 146px;"
  253. >
  254. <i class="el-icon-video-camera" style="font-size: 48px;" />
  255. </div>
  256. <span v-if="file.status === 'success'" class="el-upload-list__item-status-label">
  257. <i class="el-icon-upload-success el-icon--check"></i>
  258. </span>
  259. <span v-if="file.status === 'fail'" class="el-upload-list__item-status-label">
  260. <i class="el-icon-circle-close"></i>
  261. </span>
  262. <span class="el-upload-list__item-actions">
  263. <span
  264. class="el-upload-list__item-preview"
  265. @click="handleVideoPreview(form.videoUrl)"
  266. >
  267. <i class="el-icon-zoom-in"></i>
  268. </span>
  269. <span
  270. class="el-upload-list__item-delete"
  271. @click="handleRemove(file)"
  272. >
  273. <i class="el-icon-delete"></i>
  274. </span>
  275. </span>
  276. <div v-if="file.status === 'uploading'" class="el-upload-list__item-progress">
  277. <div class="dual-upload-progress">
  278. <div class="total-progress">
  279. <el-progress
  280. :percentage="currentUploadProgress.total"
  281. :show-text="true"
  282. :width="52"
  283. :format="() => `${Math.round(currentUploadProgress.total)}%`"
  284. ></el-progress>
  285. </div>
  286. <div class="line-progress-container">
  287. <div class="line-progress-item">
  288. <span class="line-label">线路1:</span>
  289. <el-progress
  290. :percentage="currentUploadProgress.line1"
  291. :show-text="false"
  292. :width="30"
  293. :status="currentUploadProgress.line1Status === 'success' ? 'success' :
  294. currentUploadProgress.line1Status === 'failed' ? 'exception' : ''"
  295. ></el-progress>
  296. <span class="line-status-text">{{ Math.round(currentUploadProgress.line1) }}%</span>
  297. </div>
  298. <div class="line-progress-item">
  299. <span class="line-label">线路2:</span>
  300. <el-progress
  301. :percentage="currentUploadProgress.line2"
  302. :show-text="false"
  303. :width="30"
  304. :status="currentUploadProgress.line2Status === 'success' ? 'success' :
  305. currentUploadProgress.line2Status === 'failed' ? 'exception' : ''"
  306. ></el-progress>
  307. <span class="line-status-text">{{ Math.round(currentUploadProgress.line2) }}%</span>
  308. </div>
  309. </div>
  310. </div>
  311. </div>
  312. </div>
  313. </el-upload>
  314. </el-form-item>
  315. <el-form-item label="时长">
  316. <span>{{ formatDuration(form.duration) }}</span>
  317. </el-form-item>
  318. </el-form>
  319. <div slot="footer" class="dialog-footer">
  320. <el-button @click="cancel">取消</el-button>
  321. <el-button type="primary" @click="submitForm" :loading="add" :disabled="isUploading || add">
  322. {{ isUploading ? '上传中...' : '保存' }}
  323. </el-button>
  324. </div>
  325. </minimizable-dialog>
  326. <el-dialog
  327. title="视频预览"
  328. :visible.sync="videoPreviewVisible"
  329. append-to-body
  330. :close-on-click-modal="true"
  331. width="700px"
  332. class="video-preview-dialog"
  333. :modal-append-to-body="false"
  334. :before-close="handleCloseVideoPreview">
  335. <video ref="up-video" id="video" width="100%" height="400px" controls :src="videoPreviewUrl" />
  336. </el-dialog>
  337. <!--批量修改弹框-->
  338. <minimizable-dialog :title="'批量修改'" :visible.sync="batchUpdateVisible" width="700px" append-to-body :before-close="cancel"
  339. @minimize="hasMinimizableDialog = true" @restore="hasMinimizableDialog = false">
  340. <el-form ref="form" :model="batchUpdateForm" :rules="rules" label-width="80px">
  341. <el-form-item label="分类" prop="typeId">
  342. <el-select v-model="batchUpdateForm.typeId" placeholder="请选择分类" style="width: 100%" @change="val => changeCateType(val, 2)">
  343. <el-option
  344. v-for="item in rootTypeList"
  345. :key="item.dictValue"
  346. :label="item.dictLabel"
  347. :value="item.dictValue">
  348. </el-option>
  349. </el-select>
  350. </el-form-item>
  351. <el-form-item label="子分类" prop="typeSubId">
  352. <el-select v-model="batchUpdateForm.typeSubId" clearable placeholder="请选择子分类" style="width: 100%">
  353. <el-option
  354. v-for="item in subTypeList"
  355. :key="item.dictValue"
  356. :label="item.dictLabel"
  357. :value="item.dictValue">
  358. </el-option>
  359. </el-select>
  360. </el-form-item>
  361. </el-form>
  362. <div class="dialog-footer">
  363. <el-button @click="cancelBatch">取 消</el-button>
  364. <el-button type="primary" @click="submitBatchUpdate">保 存</el-button>
  365. </div>
  366. </minimizable-dialog>
  367. <!-- 批量选择视频弹窗 -->
  368. <minimizable-dialog :title="'选择视频'" :visible.sync="batchAddVisible" width="1200px" append-to-body class="batch-dialog"
  369. :close-on-click-modal="false" :before-close="cancelBeforeBatch" @minimize="hasMinimizableDialog = true"
  370. @restore="hasMinimizableDialog = false">
  371. <div class="filter-container">
  372. <el-button type="primary" icon="el-icon-plus" size="small" @click="showUploadPanel">上传视频</el-button>
  373. </div>
  374. <el-table
  375. v-loading="batchLoading"
  376. :data="videoList"
  377. height="350"
  378. border>
  379. <el-table-column label="序号" width="60" align="center">
  380. <template slot-scope="scope">
  381. {{ scope.$index + 1 }}
  382. </template>
  383. </el-table-column>
  384. <el-table-column label="素材名称" align="center" prop="resourceName" min-width="120" />
  385. <el-table-column label="文件名称" align="center" prop="fileName" min-width="120" />
  386. <el-table-column label="分类" align="center" min-width="100">
  387. <template slot-scope="scope">
  388. {{ getTypeName(scope.row.typeId) }}
  389. </template>
  390. </el-table-column>
  391. <el-table-column label="子分类" align="center" min-width="100">
  392. <template slot-scope="scope">
  393. {{ getTypeName(scope.row.typeSubId) }}
  394. </template>
  395. </el-table-column>
  396. <el-table-column label="关联项目" align="center" min-width="100">
  397. <template slot-scope="scope">
  398. <a
  399. @click="handleViewProject(scope.row, 4)"
  400. :style="scope.row.projectIds.length > 0 ? {
  401. backgroundColor: '#409EFF',
  402. color: 'white',
  403. border: 'none',
  404. borderRadius: '4px',
  405. padding: '4px 12px',
  406. cursor: 'pointer',
  407. fontSize: '12px',
  408. display: 'inline-block',
  409. textDecoration: 'none'
  410. } : {
  411. backgroundColor: 'rgb(154 156 159)',
  412. color: 'white',
  413. border: 'none',
  414. cursor: 'pointer',
  415. borderRadius: '4px',
  416. padding: '4px 12px',
  417. fontSize: '12px',
  418. display: 'inline-block',
  419. textDecoration: 'none'
  420. }">
  421. {{ scope.row.projectIds.length > 0 ? '查看详情' : '未关联题目' }}
  422. </a>
  423. </template>
  424. </el-table-column>
  425. <el-table-column label="视频文件" align="center" prop="fileName" min-width="120">
  426. <template slot-scope="scope">
  427. <a
  428. @click="handleVideoPreview(scope.row.videoUrl)"
  429. 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;">
  430. 查看文件
  431. </a>
  432. </template>
  433. </el-table-column>
  434. <el-table-column label="视频时长" align="center" width="80">
  435. <template slot-scope="scope">
  436. {{ formatDuration(scope.row.duration) }}
  437. </template>
  438. </el-table-column>
  439. <el-table-column label="上传进度" align="center" width="200">
  440. <template slot-scope="scope">
  441. <div class="batch-upload-progress">
  442. <div v-if="scope.row.uploadStatus === 'queued'" class="queue-status">
  443. <el-tag :color="getQueueStatusColor(scope.row.uploadStatus)" size="small">
  444. {{ getUploadStatusText(scope.row.uploadStatus, scope.row.queuePosition) }}
  445. </el-tag>
  446. </div>
  447. <div v-else class="total-progress-row">
  448. <span class="progress-label">总进度:</span>
  449. <el-progress
  450. :percentage="scope.row.progress || 0"
  451. :status="getProgressStatus(scope.row)"
  452. :show-text="true"
  453. :format="() => `${Math.round(scope.row.progress || 0)}%`"
  454. ></el-progress>
  455. </div>
  456. <div v-if="scope.row.uploadDetails && scope.row.uploadStatus !== 'queued'" class="line-progress-rows">
  457. <div class="line-progress-row">
  458. <span class="line-label">线路1:</span>
  459. <el-progress
  460. :percentage="scope.row.uploadDetails.line1 || 0"
  461. :status="scope.row.uploadDetails.line1Status === 'success' ? 'success' :
  462. scope.row.uploadDetails.line1Status === 'failed' ? 'exception' : 'warning'"
  463. :show-text="false"
  464. style="width: 60px;"
  465. ></el-progress>
  466. <span class="line-percentage">{{ Math.round(scope.row.uploadDetails.line1 || 0) }}%</span>
  467. </div>
  468. <div class="line-progress-row">
  469. <span class="line-label">线路2:</span>
  470. <el-progress
  471. :percentage="scope.row.uploadDetails.line2 || 0"
  472. :status="scope.row.uploadDetails.line2Status === 'success' ? 'success' :
  473. scope.row.uploadDetails.line2Status === 'failed' ? 'exception' : 'warning'"
  474. :show-text="false"
  475. style="width: 60px;"
  476. ></el-progress>
  477. <span class="line-percentage">{{ Math.round(scope.row.uploadDetails.line2 || 0) }}%</span>
  478. </div>
  479. </div>
  480. </div>
  481. </template>
  482. </el-table-column>
  483. <el-table-column label="操作" align="center" width="150">
  484. <template slot-scope="scope">
  485. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEditVideo(scope.row)">编辑</el-button>
  486. <el-button
  487. size="mini"
  488. type="text"
  489. icon="el-icon-delete"
  490. @click="handleDeleteVideo(scope.row)"
  491. :style="scope.row.uploadStatus === 'queued' ? 'color: #E6A23C;' : ''"
  492. >
  493. {{ scope.row.uploadStatus === 'queued' ? '取消' : '删除' }}
  494. </el-button>
  495. <el-button
  496. v-if="scope.row.progress < 100 && scope.row.uploadStatus === 'failed'"
  497. size="mini"
  498. type="text"
  499. icon="el-icon-refresh"
  500. @click="retryBatchUpload(scope.row)"
  501. style="color: #E6A23C;"
  502. >
  503. 重试
  504. </el-button>
  505. </template>
  506. </el-table-column>
  507. </el-table>
  508. <div class="dialog-footer">
  509. <el-button @click="cancelBatch">取 消</el-button>
  510. <el-button type="primary" :loading="add" :disabled="add || isUploading" @click="submitBatchAdd">保 存</el-button>
  511. </div>
  512. <!-- 批量上传视频弹窗 -->
  513. <el-dialog
  514. title="批量上传视频"
  515. :visible.sync="showUpload"
  516. width="500px"
  517. append-to-body
  518. :close-on-click-modal="false"
  519. class="upload-dialog">
  520. <el-form :model="batchUploadForm" ref="batchUploadForm" label-width="80px">
  521. <el-form-item style="margin-top: 20px" label="分类" prop="typeId" :rules="[{ required: true, message: '请选择分类', trigger: 'blur' }]">
  522. <el-select v-model="batchUploadForm.typeId" placeholder="请选择分类" style="width: 100%" @change="val => changeCateType(val, 3)">
  523. <el-option
  524. v-for="item in rootTypeList"
  525. :key="item.dictValue"
  526. :label="item.dictLabel"
  527. :value="item.dictValue">
  528. </el-option>
  529. </el-select>
  530. </el-form-item>
  531. <el-form-item label="子分类" prop="typeSubId" :rules="[{ required: true, message: '请选择子分类', trigger: 'blur' }]">
  532. <el-select v-model="batchUploadForm.typeSubId" clearable placeholder="请选择子分类" style="width: 100%">
  533. <el-option
  534. v-for="item in subTypeList"
  535. :key="item.dictValue"
  536. :label="item.dictLabel"
  537. :value="item.dictValue">
  538. </el-option>
  539. </el-select>
  540. </el-form-item>
  541. <el-form-item label="关联题目" prop="projectIds" style="display: none">
  542. <el-select
  543. ref="customSelect"
  544. class="custom-select-class"
  545. v-model="batchUploadForm.projectIds"
  546. multiple
  547. placeholder="请选择关联题目"
  548. @click.native.stop="openProjectDialog(batchUploadForm.projectIds, 1)"
  549. style="width: 100%;">
  550. <el-option
  551. v-for="item in projectShowList"
  552. :key="item.id"
  553. :label="item.title"
  554. :value="item.id">
  555. </el-option>
  556. </el-select>
  557. </el-form-item>
  558. <el-form-item label="上传视频" prop="files">
  559. <el-upload
  560. ref="batchVideoUpload"
  561. action="#"
  562. :http-request="batchVideoUpload"
  563. :file-list="batchFileList"
  564. :on-change="handleBatchFileChange"
  565. multiple
  566. accept=".mp4">
  567. <el-button type="primary" :disabled="batchUploadForm.typeSubId === null">选择文件</el-button>
  568. <div slot="tip" class="el-upload__tip">选择分类后才可以上传视频</div>
  569. </el-upload>
  570. </el-form-item>
  571. </el-form>
  572. </el-dialog>
  573. <!-- 添加或修改视频素材库对话框 -->
  574. <el-dialog :title="batchEditDialog.title" :visible.sync="batchEditDialog.open" width="600px" append-to-body :before-close="batchEditCancel">
  575. <el-form ref="batchEditDialogForm" :model="batchEditDialog.form" :rules="batchEditDialog.rules" label-width="80px">
  576. <el-form-item label="素材名称" prop="resourceName" style="margin-top: 20px">
  577. <el-input v-model="batchEditDialog.form.resourceName" placeholder="请输入" />
  578. </el-form-item>
  579. <el-form-item label="文件名称" prop="fileName" style="margin-top: 20px;display: none">
  580. <el-input v-model="batchEditDialog.form.fileName" placeholder="请输入" />
  581. </el-form-item>
  582. <el-form-item label="关联题目" prop="projectIds">
  583. <el-select
  584. ref="customSelect"
  585. class="custom-select-class"
  586. v-model="batchEditDialog.form.projectIds"
  587. multiple
  588. placeholder="请选择关联题目"
  589. @click.native.stop="openProjectDialog(batchEditDialog.form.projectIds, 2)"
  590. style="width: 100%;">
  591. <el-option
  592. v-for="item in projectShowList"
  593. :key="item.id"
  594. :label="item.title"
  595. :value="item.id">
  596. </el-option>
  597. </el-select>
  598. </el-form-item>
  599. </el-form>
  600. <div slot="footer" class="dialog-footer">
  601. <el-button @click="batchEditCancel">取消</el-button>
  602. <el-button type="primary" @click="batchEditSubmitForm">保存</el-button>
  603. </div>
  604. </el-dialog>
  605. </minimizable-dialog>
  606. <!-- 项目选择弹窗 -->
  607. <el-dialog
  608. title="选择题目"
  609. :visible.sync="projectDialogVisible"
  610. width="1000px"
  611. append-to-body
  612. @close="cancelSelectProject"
  613. :close-on-click-modal="false">
  614. <div class="project-container">
  615. <!-- 左侧分类树 -->
  616. <div class="category-tree">
  617. <div class="tree-fixed-header">
  618. <el-input
  619. placeholder="请输入分类名称"
  620. v-model="categoryFilterText"
  621. size="small"
  622. clearable
  623. prefix-icon="el-icon-search">
  624. </el-input>
  625. </div>
  626. <div class="tree-content">
  627. <el-tree
  628. ref="categoryTree"
  629. :data="categoryTreeData"
  630. node-key="cateId"
  631. highlight-current
  632. :filter-node-method="filterNode"
  633. :props="{ label: 'cateName', children: 'children' }"
  634. @node-click="handleCategoryClick"
  635. :expand-on-click-node="false"
  636. default-expand-all>
  637. <span class="custom-tree-node" slot-scope="{ node, data }">
  638. <span>{{ node.label }}</span>
  639. </span>
  640. </el-tree>
  641. </div>
  642. </div>
  643. <!-- 右侧题目列表 -->
  644. <div class="project-list">
  645. <div class="filter-container">
  646. <el-form :inline="true" :model="projectQueryParams" ref="projectForm">
  647. <el-form-item>
  648. <el-input prefix-icon="el-icon-search" @input="searchProjects" v-model="projectQueryParams.sort" placeholder="请输入题目序号" clearable size="small" />
  649. </el-form-item>
  650. <el-form-item>
  651. <el-input prefix-icon="el-icon-search" @input="searchProjects" v-model="projectQueryParams.title" placeholder="请输入题目标题" clearable size="small" />
  652. </el-form-item>
  653. </el-form>
  654. </div>
  655. <el-table
  656. ref="projectTable"
  657. height="350"
  658. :data="projectList"
  659. row-key="id"
  660. v-loading="projectLoading"
  661. border
  662. @select="handleProjectSelect"
  663. @select-all="handleProjectSelect">
  664. <el-table-column type="selection" reserve-selection width="55" align="center" />
  665. <el-table-column label="序号" width="60" align="center">
  666. <template slot-scope="scope">
  667. {{ scope.row.sort }}
  668. </template>
  669. </el-table-column>
  670. <el-table-column label="题目标题" align="center" prop="title" min-width="200" show-overflow-tooltip />
  671. </el-table>
  672. <div class="table-footer">
  673. <el-pagination style="text-align: right" v-show="projectListTotal>0" :pager-count="5" background
  674. @size-change="handleProjectPageSizeChange" @current-change="handleProjectPageChange" :current-page="projectQueryParams.pageNum"
  675. :page-sizes="[10, 20, 30, 50]" :page-size="projectQueryParams.pageSize" layout="total, sizes, prev, pager, next, jumper"
  676. :total="projectListTotal">
  677. </el-pagination>
  678. </div>
  679. </div>
  680. </div>
  681. <div slot="footer" class="dialog-footer">
  682. <span style="float: left; color: #606266; font-size: 13px;">
  683. 共选择 <span style="color: #409EFF; font-weight: bold;">{{ selectedProjectIds.length }}</span> 个题目
  684. </span>
  685. <el-button @click="projectDialogVisible = false">取消</el-button>
  686. <el-button type="primary" @click="confirmSelectProject">确定</el-button>
  687. </div>
  688. </el-dialog>
  689. <!-- 项目列表弹窗 -->
  690. <el-dialog
  691. title="题目列表"
  692. :visible.sync="projectListDialogVisible"
  693. width="600px"
  694. append-to-body
  695. :close-on-click-modal="false">
  696. <div class="project-list-container" style="max-height: 500px; overflow-y: auto; padding: 10px;">
  697. <!-- 题目列表 -->
  698. <div v-for="(item, index) in projectShowList" :key="index" class="question-card">
  699. <!-- 题目标题 -->
  700. <div class="question-header">
  701. <span class="question-index">{{ index + 1 }}</span>
  702. <span class="question-title">{{ item.title }}</span>
  703. </div>
  704. <!-- 题目类型 -->
  705. <div class="question-type">
  706. <el-tag size="small" type="primary">{{ item.type === 1 ? '单选' : '多选' }}</el-tag>
  707. </div>
  708. <!-- 题目内容 -->
  709. <div class="question-content" v-if="item.question && item.question.length > 0">
  710. <div class="content-title">题目内容:</div>
  711. <div v-for="(q, qIndex) in JSON.parse(item.question)" :key="qIndex" class="question-item"
  712. :style=" q.isAnswer === 1 ? 'background-color: rgb(234 245 251)' : ''">
  713. <div class="question-item-header">
  714. <span class="item-index">{{ convertToLetter(qIndex) }}</span>
  715. <span class="item-name">{{ q.name }}</span>
  716. </div>
  717. </div>
  718. </div>
  719. <!-- 答案 -->
  720. <div class="question-answer" v-if="item.answer">
  721. <span class="answer-label">答案:</span>
  722. <span class="answer-content">{{ item.answer }}</span>
  723. </div>
  724. </div>
  725. </div>
  726. </el-dialog>
  727. </div>
  728. </template>
  729. <script>
  730. import {
  731. addVideoResource,
  732. deleteVideoResource,
  733. getVideoResource,
  734. listVideoResource,
  735. updateVideoResource,
  736. batchAddVideoResource,
  737. batchUpdateVideoResource
  738. } from '@/api/course/videoResource'
  739. import {listUserCourseCategory,getCatePidList,getCateListByPid} from '@/api/course/userCourseCategory'
  740. import {getByIds, listCourseQuestionBank} from '@/api/course/courseQuestionBank'
  741. import {getThumbnail} from "@/api/course/userVideo";
  742. import {uploadObject} from "@/utils/cos.js";
  743. import {uploadToOBS} from "@/utils/obs.js";
  744. import MinimizableDialog from "@/components/MinimizableDialog"
  745. export default {
  746. name: 'VideoResource',
  747. components: {
  748. MinimizableDialog
  749. },
  750. data() {
  751. return {
  752. // 遮罩层
  753. loading: true,
  754. // 选中数组
  755. ids: [],
  756. // 非单个禁用
  757. single: true,
  758. // 非多个禁用
  759. multiple: true,
  760. // 显示搜索条件
  761. showSearch: true,
  762. // 总条数
  763. total: 0,
  764. // 视频素材库表格数据
  765. resourceList: [],
  766. // 弹出层标题
  767. title: "",
  768. // 是否显示弹出层
  769. open: false,
  770. // 查询参数
  771. queryParams: {
  772. pageNum: 1,
  773. pageSize: 10,
  774. resourceName: null,
  775. fileName: null,
  776. typeId: null,
  777. typeSubId: null
  778. },
  779. // 表单参数
  780. form: {
  781. id: null,
  782. resourceName: null,
  783. fileName: null,
  784. thumbnail: null,
  785. line1: null,
  786. line2: null,
  787. line3: null,
  788. duration: null,
  789. fileSize: null,
  790. fileKey: null,
  791. videoUrl: null,
  792. typeId: null,
  793. typeSubId: null,
  794. projectIds: [],
  795. sort: null,
  796. // 新增上传状态字段
  797. uploadStatus: 'pending', // pending, uploading, success, failed
  798. uploadProgress: {
  799. total: 0,
  800. line1: 0,
  801. line2: 0,
  802. line1Status: 'pending', // pending, uploading, success, failed
  803. line2Status: 'pending'
  804. }
  805. },
  806. // 表单校验
  807. rules: {
  808. resourceName: [
  809. { required: true, message: "素材名称不能为空", trigger: "blur" }
  810. ],
  811. fileName: [
  812. { required: true, message: "文件名称不能为空", trigger: "blur" }
  813. ],
  814. typeId: [
  815. { required: true, message: "请选择分类", trigger: "change" }
  816. ],
  817. typeSubId: [
  818. { required: true, message: "请选择子分类", trigger: "change" }
  819. ],
  820. sort: [
  821. { required: true, message: '排序不能为空', trigger: 'blur' }
  822. ],
  823. videoUrl: [
  824. { required: true, message: "请上传视频", trigger: "change" }
  825. ]
  826. },
  827. // 课程列表数据
  828. projectList: [],
  829. projectShowList: [],
  830. // 分类
  831. typeList: [],
  832. rootTypeList: [],
  833. subTypeList: [],
  834. // 视频上传
  835. videoDisabled: false,
  836. videoPreviewVisible: false,
  837. videoPreviewUrl: '',
  838. fileList: [],
  839. // 批量添加相关
  840. batchAddVisible: false,
  841. batchLoading: false,
  842. videoList: [],
  843. // 批量修改相关
  844. batchUpdateVisible: false,
  845. batchUpdateLoading: false,
  846. batchUpdateForm: {
  847. typeId: null,
  848. typeSubId: null,
  849. ids: [],
  850. },
  851. // 批量上传相关
  852. showUpload: false,
  853. batchUploadForm: {
  854. typeId: null,
  855. typeSubId: null,
  856. projectIds: [],
  857. files: []
  858. },
  859. batchFileList: [],
  860. // 弹窗选择项目相关
  861. projectDialogVisible: false,
  862. projectQueryParams: {
  863. pageNum: 1,
  864. pageSize: 10,
  865. questionType: null,
  866. questionSubType: null,
  867. title: null,
  868. sort: null
  869. },
  870. projectLoading: false,
  871. projectListTotal: 0,
  872. selectedProjectIds: [],
  873. selectedType: 0,
  874. currentRow: null,
  875. // 分类树相关数据
  876. categoryFilterText: '',
  877. categoryTreeData: [],
  878. add: false,
  879. // 题目列表
  880. projectListDialogVisible: false,
  881. // 修改视频记录
  882. batchEditDialog: {
  883. title: '修改视频',
  884. open: false,
  885. form: {},
  886. rules: {
  887. resourceName: [
  888. { required: true, message: "素材名称不能为空", trigger: "blur" }
  889. ],
  890. fileName: [
  891. { required: true, message: "文件名称不能为空", trigger: "blur" }
  892. ]
  893. },
  894. },
  895. // 是否存在最小化窗口
  896. hasMinimizableDialog: false,
  897. // 新增上传相关状态
  898. isUploading: false,
  899. currentUploadProgress: {
  900. total: 0,
  901. line1: 0,
  902. line2: 0,
  903. line1Status: 'pending',
  904. line2Status: 'pending'
  905. },
  906. // 上传任务队列
  907. uploadQueue: [], // 上传队列
  908. currentBatchSize: 2, // 每批上传数量
  909. isProcessingBatch: false, // 是否正在处理批次
  910. currentBatchIndex: 0, // 当前批次索引
  911. uploadCancellationTokens: new Map(), // Store cancellation functions by video ID
  912. }
  913. },
  914. watch: {
  915. categoryFilterText(val) {
  916. this.$refs.categoryTree.filter(val);
  917. }
  918. },
  919. created() {
  920. this.getTypeList();
  921. this.getRootTypeList()
  922. this.getList();
  923. },
  924. methods: {
  925. /** 将数字索引转换为字母序号 (0->A, 1->B, 等) */
  926. convertToLetter(index) {
  927. // 确保索引是数字
  928. let numIndex = parseInt(index, 10);
  929. // 如果无法转换成数字,返回原始值
  930. if (isNaN(numIndex)) {
  931. return index;
  932. }
  933. // 处理负数情况
  934. if (numIndex < 0) {
  935. return index;
  936. }
  937. // 直接使用索引计算ASCII码(0对应A,1对应B,以此类推)
  938. return String.fromCharCode(65 + numIndex); // 65 是大写字母 A 的ASCII码
  939. },
  940. /** 查询视频素材库列表 */
  941. getList() {
  942. this.loading = true;
  943. listVideoResource(this.queryParams).then(response => {
  944. this.resourceList = response.rows;
  945. this.total = response.total;
  946. this.loading = false;
  947. });
  948. },
  949. // 取消按钮
  950. cancel() {
  951. this.$refs.videoUpload.clearFiles()
  952. this.open = false;
  953. this.reset();
  954. this.changeCateType(this.queryParams.typeId)
  955. },
  956. // 表单重置
  957. reset() {
  958. // 初始化表单对象
  959. this.form = {
  960. id: null,
  961. resourceName: null,
  962. fileName: null,
  963. thumbnail: null,
  964. line1: null,
  965. line2: null,
  966. line3: null,
  967. duration: null,
  968. fileSize: null,
  969. fileKey: null,
  970. videoUrl: null,
  971. typeId: null,
  972. typeSubId: null,
  973. projectIds: []
  974. };
  975. // 重置表单验证状态
  976. this.resetForm("form");
  977. this.add = false
  978. },
  979. /** 搜索按钮操作 */
  980. handleQuery() {
  981. this.queryParams.pageNum = 1;
  982. this.getList();
  983. },
  984. /** 重置按钮操作 */
  985. resetQuery() {
  986. this.resetForm("queryForm");
  987. this.handleQuery();
  988. },
  989. // 多选框选中数据
  990. handleSelectionChange(selection) {
  991. this.ids = selection.map(item => item.id)
  992. this.single = selection.length!==1
  993. this.multiple = !selection.length
  994. },
  995. /** 新增按钮操作 */
  996. handleAdd() {
  997. // 先清空文件列表
  998. this.fileList = [];
  999. this.projectShowList = [];
  1000. // 先重置表单
  1001. this.reset();
  1002. this.subTypeList = []
  1003. // 重置上传组件
  1004. if (this.$refs.videoUpload) {
  1005. this.$refs.videoUpload.clearFiles();
  1006. }
  1007. // 所有重置完成后再打开弹窗
  1008. this.open = true;
  1009. this.title = "添加视频素材库";
  1010. },
  1011. /** 修改按钮操作 */
  1012. handleUpdate(row) {
  1013. // 先清空文件列表
  1014. this.fileList = [];
  1015. this.projectShowList = [];
  1016. // 先重置表单
  1017. this.reset();
  1018. this.subTypeList = []
  1019. const id = row.id
  1020. // 获取数据并设置表单
  1021. getVideoResource(id).then(async response => {
  1022. this.form = response.data;
  1023. await this.changeCateType(this.form.typeId)
  1024. // 处理projectIds,确保是数组格式
  1025. if (this.form.projectIds && typeof this.form.projectIds === 'string') {
  1026. this.form.projectIds = this.form.projectIds.split(',').map(id => parseInt(id));
  1027. } else if (!this.form.projectIds) {
  1028. this.form.projectIds = [];
  1029. }
  1030. // 如果存在关联项目,获取项目详情用于回显
  1031. if (this.form.projectIds && this.form.projectIds.length > 0) {
  1032. // 加载项目列表信息用于回显
  1033. await getByIds({ids: this.form.projectIds.join(',')}).then(reponse => {
  1034. this.projectShowList = reponse.data
  1035. });
  1036. }
  1037. // 如果存在视频URL,设置fileList
  1038. if (this.form.videoUrl) {
  1039. this.fileList = [{
  1040. name: this.form.fileName || '视频文件',
  1041. url: this.form.videoUrl,
  1042. thumbnail: this.form.thumbnail,
  1043. status: 'success' // 设置为成功状态
  1044. }];
  1045. }
  1046. // 所有设置完成后再打开弹窗
  1047. this.open = true;
  1048. this.title = "修改视频素材库";
  1049. });
  1050. },
  1051. /** 提交按钮 */
  1052. submitForm() {
  1053. this.$refs["form"].validate(valid => {
  1054. if (valid) {
  1055. if (this.add){
  1056. this.$message.warning("请勿重复提交")
  1057. return
  1058. }
  1059. this.add = true
  1060. const params = Object.assign({}, this.form);
  1061. params.projectIds = this.form.projectIds.join(',');
  1062. if (this.form.id != null) {
  1063. updateVideoResource(params).then(response => {
  1064. if (response.code === 200) {
  1065. this.msgSuccess("修改成功");
  1066. this.open = false;
  1067. this.getList();
  1068. }
  1069. })
  1070. } else {
  1071. addVideoResource(params).then(response => {
  1072. if (response.code === 200) {
  1073. this.msgSuccess("新增成功");
  1074. this.open = false;
  1075. this.getList();
  1076. }
  1077. })
  1078. }
  1079. }
  1080. });
  1081. },
  1082. /** 删除按钮操作 */
  1083. handleDelete(row) {
  1084. const ids = row.id || this.ids;
  1085. this.$confirm('是否确认删除视频素材库编号为"' + ids + '"的数据项?', "警告", {
  1086. confirmButtonText: "确定",
  1087. cancelButtonText: "取消",
  1088. type: "warning"
  1089. }).then(function() {
  1090. return deleteVideoResource(ids);
  1091. }).then(() => {
  1092. this.getList();
  1093. this.msgSuccess("删除成功");
  1094. }).catch(function() {});
  1095. },
  1096. /** 查询视频分类列表 */
  1097. getTypeList() {
  1098. listUserCourseCategory().then(response => {
  1099. this.typeList = response.data;
  1100. });
  1101. },
  1102. getRootTypeList() {
  1103. getCatePidList().then(response => {
  1104. this.rootTypeList = response.data
  1105. });
  1106. },
  1107. async changeCateType(val, type) {
  1108. if (type === 1) {
  1109. this.queryParams.typeSubId = null
  1110. }
  1111. if (type === 2) {
  1112. this.form.typeSubId = null
  1113. }
  1114. if (type === 3) {
  1115. this.batchUploadForm.typeSubId = null
  1116. }
  1117. this.subTypeList = []
  1118. if (!val) {
  1119. return
  1120. }
  1121. await getCateListByPid(val).then(response => {
  1122. this.subTypeList = response.data
  1123. })
  1124. },
  1125. /** 预览视频 */
  1126. handleVideoPreview(url) {
  1127. this.videoPreviewVisible = true;
  1128. this.videoPreviewUrl = url || this.form.videoUrl;
  1129. },
  1130. /** 格式化视频时长 */
  1131. formatDuration(seconds) {
  1132. if (!seconds) return '00:00';
  1133. const minutes = Math.floor(seconds / 60);
  1134. const remainingSeconds = seconds % 60;
  1135. return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
  1136. },
  1137. /** 移除视频 */
  1138. handleRemove(file) {
  1139. this.fileList.splice(this.fileList.indexOf(file), 1);
  1140. this.form.videoUrl = '';
  1141. this.form.thumbnail = '';
  1142. this.form.duration = 0;
  1143. this.form.fileSize = 0;
  1144. this.form.fileName = '';
  1145. this.form.line1 = '';
  1146. this.form.line_2 = '';
  1147. this.form.line_3 = '';
  1148. this.uploadType = null
  1149. this.fileSize = null
  1150. this.fileKey = null
  1151. },
  1152. //获取第一帧封面
  1153. async getFirstThumbnail(file, form){
  1154. try {
  1155. //截取小文件
  1156. // 打印原始文件名和大小
  1157. console.log("原始文件名:", file.name);
  1158. console.log("原始文件大小:", file.size, "bytes");
  1159. console.log("原始文件类型:", file.type);
  1160. // 截取小文件
  1161. const clippedBlob = await this.clipVideoFirstTwoSeconds(file);
  1162. console.log("clippedBlob:::::::::", clippedBlob);
  1163. console.log("截取后的Blob大小:", clippedBlob.size, "bytes");
  1164. console.log("截取后的Blob类型:", clippedBlob.type);
  1165. const clippedFile = new File([clippedBlob], 'clipped_video.mp4', {
  1166. type: 'video/mp4',
  1167. lastModified: Date.now()
  1168. });
  1169. // 3. 调用接口获取封面
  1170. const response = await getThumbnail(clippedFile);
  1171. console.log("获取封面请求---------------》",response)
  1172. form.thumbnail = response.url;
  1173. } catch (error) {
  1174. console.error('获取封面失败:', error);
  1175. }
  1176. },
  1177. //截取大文件视频
  1178. async clipVideoFirstTwoSeconds(file) {
  1179. return new Promise((resolve, reject) => {
  1180. const video = document.createElement('video');
  1181. video.src = URL.createObjectURL(file);
  1182. video.muted = true;
  1183. video.playsInline = true;
  1184. video.onloadedmetadata = () => {
  1185. video.currentTime = 0; // 定位到第一帧
  1186. video.onseeked = () => {
  1187. const canvas = document.createElement('canvas');
  1188. canvas.width = video.videoWidth;
  1189. canvas.height = video.videoHeight;
  1190. const ctx = canvas.getContext('2d');
  1191. ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
  1192. canvas.toBlob(
  1193. (blob) => {
  1194. URL.revokeObjectURL(video.src);
  1195. resolve(blob); // 返回 JPEG Blob
  1196. },
  1197. 'image/jpeg',
  1198. 0.8 // 质量
  1199. );
  1200. };
  1201. };
  1202. video.onerror = () => {
  1203. URL.revokeObjectURL(video.src);
  1204. reject(new Error('视频加载失败'));
  1205. };
  1206. });
  1207. },
  1208. //上传腾讯云Pcdn
  1209. async uploadVideoToTxPcdn(file, form, onProgress) {
  1210. try {
  1211. // 更新线路1状态为上传中
  1212. this.updateUploadProgress('line1Status', 'uploading');
  1213. const data = await uploadObject(file, (progress) => {
  1214. const progressPercent = Math.floor(progress.percent * 100);
  1215. this.updateUploadProgress('line1', progressPercent);
  1216. const progressEvent = { percent: progressPercent, loaded: progress.loaded, total: progress.total, lengthComputable: true };
  1217. onProgress(progressEvent);
  1218. }, 1, (uploadInfo) => {
  1219. if (form.tempId) {
  1220. const tokens = this.uploadCancellationTokens.get(form.tempId) || {};
  1221. tokens.cos = uploadInfo.cancel;
  1222. this.uploadCancellationTokens.set(form.tempId, tokens);
  1223. }
  1224. });
  1225. let line_1 = `${process.env.VUE_APP_VIDEO_LINE_1}${data.urlPath}`;
  1226. form.fileKey = data.urlPath.substring(1);
  1227. form.videoUrl = line_1;
  1228. form.line1 = line_1;
  1229. // 更新线路1状态为成功
  1230. this.updateUploadProgress('line1Status', 'success');
  1231. this.updateUploadProgress('line1', 100);
  1232. this.$message.success("线路一上传成功");
  1233. return { success: true, url: line_1 };
  1234. } catch (error) {
  1235. // 更新线路1状态为失败
  1236. this.updateUploadProgress('line1Status', 'failed');
  1237. this.$message.error("线路一上传失败");
  1238. return { success: false, error: error.message };
  1239. }
  1240. },
  1241. //上传华为云Obs
  1242. async uploadVideoToHwObs(file, form, onProgress) {
  1243. try {
  1244. // 更新线路2状态为上传中
  1245. this.updateUploadProgress('line2Status', 'uploading');
  1246. const data = await uploadToOBS(file, (progress) => {
  1247. const progressPercent = Math.floor(progress);
  1248. this.updateUploadProgress('line2', progressPercent);
  1249. const progressEvent = { percent: progressPercent, loaded: progress, total: progress, lengthComputable: true };
  1250. onProgress(progressEvent);
  1251. }, 1, (uploadInfo) => {
  1252. if (form.tempId) {
  1253. const tokens = this.uploadCancellationTokens.get(form.tempId) || {};
  1254. tokens.obs = uploadInfo.cancel;
  1255. this.uploadCancellationTokens.set(form.tempId, tokens);
  1256. }
  1257. });
  1258. form.line2 = `${process.env.VUE_APP_VIDEO_LINE_2}/${data.urlPath}`;
  1259. // 更新线路2状态为成功
  1260. this.updateUploadProgress('line2Status', 'success');
  1261. this.updateUploadProgress('line2', 100);
  1262. this.$message.success("线路二上传成功");
  1263. return { success: true, url: form.line2 };
  1264. } catch (error) {
  1265. // 更新线路2状态为失败
  1266. this.updateUploadProgress('line2Status', 'failed');
  1267. this.$message.error("线路二上传失败");
  1268. return { success: false, error: error.message };
  1269. }
  1270. },
  1271. // 更新上传进度的辅助方法
  1272. updateUploadProgress(key, value) {
  1273. this.currentUploadProgress[key] = value;
  1274. // 计算总进度:只有两个线路都成功才算100%
  1275. if (this.currentUploadProgress.line1Status === 'success' && this.currentUploadProgress.line2Status === 'success') {
  1276. this.currentUploadProgress.total = 100;
  1277. } else if (this.currentUploadProgress.line1Status === 'failed' || this.currentUploadProgress.line2Status === 'failed') {
  1278. // 如果任一线路失败,总进度保持当前状态
  1279. this.currentUploadProgress.total = Math.min(
  1280. (this.currentUploadProgress.line1 + this.currentUploadProgress.line2) / 2,
  1281. 99 // 失败时最多99%
  1282. );
  1283. } else {
  1284. // 正常上传中,计算平均进度
  1285. this.currentUploadProgress.total = Math.min(
  1286. (this.currentUploadProgress.line1 + this.currentUploadProgress.line2) / 2,
  1287. 99 // 上传中最多99%,只有都成功才100%
  1288. );
  1289. }
  1290. },
  1291. // 上传视频
  1292. async videoUpload(options) {
  1293. this.isUploading = true;
  1294. this.form.uploadStatus = 'uploading';
  1295. this.form.tempId = Math.random().toString(36).substring(2, 15);
  1296. const file = options.file;
  1297. this.getMediaDuration(file);
  1298. this.currentUploadProgress = { total: 0, line1: 0, line2: 0, line1Status: 'pending', line2Status: 'pending' };
  1299. try {
  1300. await this.getFirstThumbnail(file, this.form);
  1301. const [line1Result, line2Result] = await Promise.allSettled([
  1302. this.uploadVideoToTxPcdn(file, this.form, options.onProgress),
  1303. this.uploadVideoToHwObs(file, this.form, options.onProgress)
  1304. ]);
  1305. const line1Success = line1Result.status === 'fulfilled' && line1Result.value.success;
  1306. const line2Success = line2Result.status === 'fulfilled' && line2Result.value.success;
  1307. if (line1Success && line2Success) {
  1308. this.form.uploadStatus = 'success';
  1309. this.form.uploadProgress = { total: 100, line1: 100, line2: 100, line1Status: 'success', line2Status: 'success' };
  1310. this.currentUploadProgress.total = 100;
  1311. this.$message.success("视频上传完成!两个线路都上传成功");
  1312. } else {
  1313. this.form.uploadStatus = 'failed';
  1314. this.form.uploadProgress = {
  1315. total: this.currentUploadProgress.total,
  1316. line1: this.currentUploadProgress.line1,
  1317. line2: this.currentUploadProgress.line2,
  1318. line1Status: this.currentUploadProgress.line1Status,
  1319. line2Status: this.currentUploadProgress.line2Status
  1320. };
  1321. const failedLines = [];
  1322. if (!line1Success) failedLines.push('线路1');
  1323. if (!line2Success) failedLines.push('线路2');
  1324. this.$message.error(`视频上传失败!${failedLines.join('、')} 上传失败,请重试`);
  1325. }
  1326. this.form.fileName = file.name;
  1327. this.form.fileSize = file.size;
  1328. } catch (error) {
  1329. this.form.uploadStatus = 'failed';
  1330. this.$message.error("视频上传过程中发生错误,请重试");
  1331. } finally {
  1332. this.isUploading = false;
  1333. if (this.form.tempId) {
  1334. this.uploadCancellationTokens.delete(this.form.tempId);
  1335. }
  1336. }
  1337. },
  1338. // 获取媒体文件时长
  1339. getMediaDuration(file) {
  1340. // 处理视频
  1341. const video = document.createElement('video');
  1342. video.preload = 'metadata';
  1343. video.onloadedmetadata = () => {
  1344. this.form.duration = Math.round(video.duration);
  1345. };
  1346. video.src = URL.createObjectURL(file);
  1347. },
  1348. handleFileChange(file, files) {
  1349. // 保留最后一个文件
  1350. this.fileList = files.slice(-1);
  1351. },
  1352. /** 批量新增 */
  1353. handleBatchAdd() {
  1354. this.batchAddVisible = true;
  1355. this.add =false
  1356. this.videoList = []; // 清空之前的视频列表
  1357. },
  1358. /** 批量修改 */
  1359. handleBatchUpdate(){
  1360. if (this.ids.length === 0) {
  1361. this.$message.warning("请至少选择一条数据");
  1362. return;
  1363. }
  1364. this.batchUpdateForm.typeId = null;
  1365. this.batchUpdateForm.typeSubId = null;
  1366. this.batchUpdateForm.ids = this.ids; // 将选中的ID传递给批量修改表单
  1367. this.batchUpdateVisible = true;
  1368. },
  1369. cancelBeforeBatch(done, cancel) {
  1370. if (!this.videoList || this.videoList.length === 0) {
  1371. done()
  1372. return
  1373. }
  1374. this.$confirm('关闭窗口视频需要重新上传,确定关闭吗?', '提示', {
  1375. confirmButtonText: '确定',
  1376. cancelButtonText: '取消',
  1377. type: 'warning'
  1378. }).then(() => {
  1379. done()
  1380. }).catch(() => {
  1381. cancel()
  1382. });
  1383. },
  1384. /** 取消批量 */
  1385. cancelBatch() {
  1386. if (!this.videoList || this.videoList.length === 0) {
  1387. this.batchAddVisible = false
  1388. return
  1389. }
  1390. this.$confirm('关闭窗口视频需要重新上传,确定关闭吗?', '提示', {
  1391. confirmButtonText: '确定',
  1392. cancelButtonText: '取消',
  1393. type: 'warning'
  1394. }).then(() => {
  1395. this.batchAddVisible = false
  1396. this.changeCateType(this.queryParams.typeId)
  1397. }).catch(() => { });
  1398. },
  1399. /** 批量修改 */
  1400. submitBatchUpdate() {
  1401. this.$refs["form"].validate(valid => {
  1402. if (valid) {
  1403. if (this.batchUpdateForm.ids.length === 0) {
  1404. this.$message.warning("未选择任何数据");
  1405. return;
  1406. }
  1407. this.$confirm('是否确认修改视频素材库编号为"' + this.batchUpdateForm.ids.join(',') + '"的数据项?', "警告", {
  1408. confirmButtonText: "确定",
  1409. cancelButtonText: "取消",
  1410. type: "warning"
  1411. }).then(() => {
  1412. // 构造正确的参数格式
  1413. const params = new URLSearchParams();
  1414. params.append('typeId', this.batchUpdateForm.typeId || '');
  1415. params.append('typeSubId', this.batchUpdateForm.typeSubId || '');
  1416. params.append('ids', this.batchUpdateForm.ids.join(','));
  1417. return batchUpdateVideoResource(params);
  1418. }).then(() => {
  1419. this.getList();
  1420. this.batchUpdateVisible = false;
  1421. this.msgSuccess("修改成功");
  1422. }).catch(() => {});
  1423. }
  1424. });
  1425. },
  1426. /** 提交批量添加 */
  1427. submitBatchAdd() {
  1428. if (this.videoList.length === 0) {
  1429. this.$message.warning("请选择视频");
  1430. return;
  1431. }
  1432. // 检查是否所有选中的视频都已上传完成
  1433. const incompleteVideos = this.videoList.filter(item => (item.progress || 0) < 100);
  1434. if (incompleteVideos.length > 0) {
  1435. this.$message.warning('有未完成上传的视频,请先完成上传');
  1436. return;
  1437. }
  1438. if (this.add){
  1439. this.$message.warning("请勿重复提交")
  1440. return
  1441. }
  1442. this.add = true
  1443. // 调用批量添加API
  1444. const videoList = JSON.parse(JSON.stringify(this.videoList));
  1445. videoList.forEach(item => {
  1446. item.projectIds = item.projectIds.join(",");
  1447. });
  1448. batchAddVideoResource(videoList).then(response => {
  1449. if (response.code === 200) {
  1450. this.$message.success('批量添加成功');
  1451. this.batchAddVisible = false;
  1452. this.getList();
  1453. }
  1454. })
  1455. },
  1456. /** 获取分类名称 */
  1457. getTypeName(typeId) {
  1458. const type = this.typeList.find(item => item.cateId === typeId);
  1459. return type ? type.cateName : '';
  1460. },
  1461. /** 编辑视频信息 */
  1462. handleEditVideo(row) {
  1463. this.batchEditDialog.form = Object.assign({}, row)
  1464. this.changeCateType(row.typeId)
  1465. this.batchEditDialog.open = true
  1466. },
  1467. batchEditCancel() {
  1468. this.resetForm('batchEditDialogForm')
  1469. this.batchEditDialog.open = false
  1470. },
  1471. batchEditSubmitForm() {
  1472. let temp = this.videoList.find(item => item.tempId === this.batchEditDialog.form.tempId)
  1473. Object.assign(temp, this.batchEditDialog.form)
  1474. this.batchEditDialog.open = false
  1475. },
  1476. handleDeleteVideo(row) {
  1477. if (row.uploadStatus === 'uploading') {
  1478. this.$confirm('该视频正在上传中,确认要取消上传并删除吗?', '取消上传', {
  1479. confirmButtonText: '确定取消',
  1480. cancelButtonText: '继续上传',
  1481. type: 'warning'
  1482. }).then(() => {
  1483. // Cancel the upload and remove from list
  1484. this.cancelVideoUpload(row);
  1485. }).catch(() => {
  1486. // User chose to continue uploading
  1487. this.$message.info('继续上传该视频');
  1488. });
  1489. } else {
  1490. // Original confirmation for non-uploading videos
  1491. this.$confirm('确认要从列表中删除该视频吗?', '提示', {
  1492. confirmButtonText: '确定',
  1493. cancelButtonText: '取消',
  1494. type: 'warning'
  1495. }).then(() => {
  1496. this.removeVideoFromList(row);
  1497. }).catch(() => {
  1498. // 取消删除
  1499. });
  1500. }
  1501. },
  1502. cancelVideoUpload(row) {
  1503. const cancellationTokens = this.uploadCancellationTokens.get(row.tempId);
  1504. if (cancellationTokens) {
  1505. // Cancel COS upload if exists
  1506. if (cancellationTokens.cos) {
  1507. try {
  1508. cancellationTokens.cos();
  1509. console.log('COS upload cancelled for video:', row.tempId);
  1510. } catch (error) {
  1511. console.error('Error cancelling COS upload:', error);
  1512. }
  1513. }
  1514. // Cancel OBS upload if exists
  1515. if (cancellationTokens.obs) {
  1516. try {
  1517. cancellationTokens.obs();
  1518. console.log('OBS upload cancelled for video:', row.tempId);
  1519. } catch (error) {
  1520. console.error('Error cancelling OBS upload:', error);
  1521. }
  1522. }
  1523. // Remove cancellation tokens
  1524. this.uploadCancellationTokens.delete(row.tempId);
  1525. }
  1526. const videoIndex = this.videoList.findIndex(item => item.tempId === row.tempId);
  1527. if (videoIndex !== -1) {
  1528. this.videoList[videoIndex].uploadStatus = 'cancelled';
  1529. this.videoList.splice(videoIndex, 1);
  1530. }
  1531. const queueIndex = this.uploadQueue.findIndex(item => item.tempId === row.tempId);
  1532. if (queueIndex !== -1) {
  1533. this.uploadQueue.splice(queueIndex, 1);
  1534. this.updateQueuePositions();
  1535. }
  1536. this.$message.success('已取消视频上传并从列表中移除');
  1537. },
  1538. removeVideoFromList(row) {
  1539. const videoIndex = this.videoList.findIndex(item => item.tempId === row.tempId);
  1540. if (videoIndex !== -1) {
  1541. this.videoList.splice(videoIndex, 1);
  1542. }
  1543. // Remove from upload queue if it's still queued
  1544. const queueIndex = this.uploadQueue.findIndex(item => item.tempId === row.tempId);
  1545. if (queueIndex !== -1) {
  1546. this.uploadQueue.splice(queueIndex, 1);
  1547. this.updateQueuePositions();
  1548. this.$message.success('已从上传队列中移除该视频');
  1549. } else {
  1550. this.$message.success('已从列表中移除该视频');
  1551. }
  1552. },
  1553. /** 删除视频 */
  1554. // handleDeleteVideo(row) {
  1555. // this.$confirm('确认要从列表中删除该视频吗?', '提示', {
  1556. // confirmButtonText: '确定',
  1557. // cancelButtonText: '取消',
  1558. // type: 'warning'
  1559. // }).then(() => {
  1560. // const videoIndex = this.videoList.findIndex(item => item.tempId === row.tempId);
  1561. // if (videoIndex !== -1) {
  1562. // this.videoList.splice(videoIndex, 1);
  1563. // }
  1564. // // Remove from upload queue if it's still queued
  1565. // const queueIndex = this.uploadQueue.findIndex(item => item.tempId === row.tempId);
  1566. // if (queueIndex !== -1) {
  1567. // this.uploadQueue.splice(queueIndex, 1);
  1568. // this.updateQueuePositions();
  1569. // this.$message.success('已从上传队列中移除该视频');
  1570. // } else {
  1571. // this.$message.success('已从列表中移除该视频');
  1572. // }
  1573. // }).catch(() => {
  1574. // // 取消删除
  1575. // });
  1576. // },
  1577. /** 显示上传面板 */
  1578. showUploadPanel() {
  1579. this.showUpload = true;
  1580. this.batchUploadForm = {
  1581. typeId: null,
  1582. typeSubId: null,
  1583. projectIds: [],
  1584. files: []
  1585. };
  1586. this.batchFileList = [];
  1587. this.subTypeList = []
  1588. if (this.$refs.batchVideoUpload) {
  1589. this.$refs.batchVideoUpload.clearFiles();
  1590. }
  1591. },
  1592. /** 批量文件变更 */
  1593. handleBatchFileChange(file, fileList) {
  1594. this.batchFileList = fileList;
  1595. },
  1596. /** 批量上传视频 */
  1597. async batchVideoUpload(options) {
  1598. const file = options.file;
  1599. const tempVideo = {
  1600. tempId: Math.random().toString(36).substring(2, 15),
  1601. resourceName: file.name.substring(0, file.name.lastIndexOf('.')),
  1602. fileName: file.name,
  1603. thumbnail: null,
  1604. line1: null,
  1605. line2: null,
  1606. line3: null,
  1607. duration: 0,
  1608. fileSize: file.size,
  1609. fileKey: null,
  1610. videoUrl: null,
  1611. typeId: this.batchUploadForm.typeId,
  1612. typeSubId: this.batchUploadForm.typeSubId,
  1613. projectIds: this.batchUploadForm.projectIds,
  1614. progress: 0,
  1615. uploadStatus: 'queued', // Set initial status to queued
  1616. uploadDetails: {
  1617. line1: 0,
  1618. line2: 0,
  1619. line1Status: 'pending',
  1620. line2Status: 'pending'
  1621. },
  1622. file: file,
  1623. queuePosition: this.uploadQueue.length + 1 // Track queue position
  1624. };
  1625. this.uploadQueue.push(tempVideo);
  1626. this.videoList.unshift(tempVideo);
  1627. // 获取视频时长
  1628. const video = document.createElement('video');
  1629. video.preload = 'metadata';
  1630. video.onloadedmetadata = () => {
  1631. const index = this.videoList.findIndex(item => item.tempId === tempVideo.tempId);
  1632. if (index !== -1) {
  1633. tempVideo.duration = Math.round(video.duration);
  1634. }
  1635. };
  1636. video.src = URL.createObjectURL(file);
  1637. // 关闭上传弹窗
  1638. this.showUpload = false;
  1639. if (!this.isProcessingBatch) {
  1640. this.processUploadQueue();
  1641. }
  1642. if (this.$refs.batchVideoUpload) {
  1643. this.$refs.batchVideoUpload.clearFiles();
  1644. }
  1645. },
  1646. async processUploadQueue() {
  1647. if (this.isProcessingBatch || this.uploadQueue.length === 0) {
  1648. return;
  1649. }
  1650. this.isUploading = true;
  1651. this.isProcessingBatch = true;
  1652. while (this.uploadQueue.length > 0) {
  1653. // Get next batch (up to 5 videos)
  1654. const currentBatch = this.uploadQueue.splice(0, this.currentBatchSize);
  1655. // Update status for current batch
  1656. currentBatch.forEach(video => {
  1657. const index = this.videoList.findIndex(item => item.tempId === video.tempId);
  1658. if (index !== -1) {
  1659. this.videoList[index].uploadStatus = 'uploading';
  1660. }
  1661. });
  1662. // Process current batch in parallel
  1663. const batchPromises = currentBatch.map(video => this.uploadSingleVideo(video));
  1664. try {
  1665. await Promise.allSettled(batchPromises);
  1666. this.$message.success(`批次上传完成,已处理 ${currentBatch.length} 个视频`);
  1667. } catch (error) {
  1668. this.$message.error(`批次上传过程中发生错误: ${error.message}`);
  1669. }
  1670. // Update queue positions for remaining videos
  1671. this.updateQueuePositions();
  1672. // Small delay between batches
  1673. if (this.uploadQueue.length > 0) {
  1674. await new Promise(resolve => setTimeout(resolve, 1000));
  1675. }
  1676. }
  1677. this.isProcessingBatch = false;
  1678. this.isUploading = false;
  1679. this.$message.success('所有视频上传队列处理完成!');
  1680. },
  1681. async uploadSingleVideo(tempVideo) {
  1682. try {
  1683. // 获取封面
  1684. await this.getFirstThumbnail(tempVideo.file, tempVideo);
  1685. // 并行上传到两个服务器
  1686. const [line1Result, line2Result] = await Promise.allSettled([
  1687. this.uploadVideoToTxPcdnBatch(tempVideo.file, tempVideo),
  1688. this.uploadVideoToHwObsBatch(tempVideo.file, tempVideo)
  1689. ]);
  1690. // 检查上传结果
  1691. const line1Success = line1Result.status === 'fulfilled' && line1Result.value.success;
  1692. const line2Success = line1Result.status === 'fulfilled' && line1Result.value.success;
  1693. const index = this.videoList.findIndex(item => item.tempId === tempVideo.tempId);
  1694. if (index !== -1) {
  1695. if (line1Success && line2Success) {
  1696. this.videoList[index].progress = 100;
  1697. this.videoList[index].uploadStatus = 'success';
  1698. this.videoList[index].uploadDetails.line1Status = 'success';
  1699. this.videoList[index].uploadDetails.line2Status = 'success';
  1700. this.videoList[index].uploadDetails.line1 = 100;
  1701. this.videoList[index].uploadDetails.line2 = 100;
  1702. } else {
  1703. this.videoList[index].uploadStatus = 'failed';
  1704. this.videoList[index].uploadDetails.line1Status = line1Success ? 'success' : 'failed';
  1705. this.videoList[index].uploadDetails.line2Status = line2Success ? 'success' : 'failed';
  1706. this.updateBatchProgress(index);
  1707. }
  1708. }
  1709. return { success: line1Success && line2Success, tempVideo };
  1710. } catch (error) {
  1711. const index = this.videoList.findIndex(item => item.tempId === tempVideo.tempId);
  1712. if (index !== -1) {
  1713. this.videoList[index].uploadStatus = 'failed';
  1714. }
  1715. throw error;
  1716. }
  1717. },
  1718. /** 复制视频链接到剪贴板 */
  1719. copy(url) {
  1720. // 创建一个临时的input元素
  1721. const input = document.createElement('input');
  1722. // 设置input的值为要复制的视频链接
  1723. input.value = url;
  1724. // 将input添加到DOM中
  1725. document.body.appendChild(input);
  1726. // 选中input的值
  1727. input.select();
  1728. // 执行复制命令
  1729. document.execCommand('copy');
  1730. // 从DOM中移除input元素
  1731. document.body.removeChild(input);
  1732. // 提示用户复制成功
  1733. this.$message({
  1734. message: '已复制到剪贴板',
  1735. type: 'success',
  1736. duration: 1500
  1737. });
  1738. },
  1739. getProjectList() {
  1740. this.projectLoading = true
  1741. listCourseQuestionBank(this.projectQueryParams).then(response => {
  1742. this.projectList = response.rows;
  1743. this.projectListTotal = response.total;
  1744. // 如果存在已选择的项目,预选中表格中对应的行
  1745. this.$nextTick(() => {
  1746. // 获取表格组件实例
  1747. const projectTable = this.$refs.projectTable;
  1748. if (projectTable) {
  1749. if (this.selectedProjectIds.length > 0) {
  1750. // 遍历项目列表,找到匹配的ID并选中对应行
  1751. const selectedIds = this.selectedProjectIds;
  1752. this.projectList.forEach(row => {
  1753. if (selectedIds.includes(row.id)) {
  1754. projectTable.toggleRowSelection(row, true);
  1755. }
  1756. });
  1757. }
  1758. }
  1759. });
  1760. this.projectLoading = false
  1761. });
  1762. },
  1763. /** 打开项目选择弹窗 */
  1764. openProjectDialog(projectIds, type) {
  1765. this.$nextTick(() => {
  1766. if (this.$refs.customSelect) {
  1767. this.$refs.customSelect.blur();
  1768. }
  1769. });
  1770. // 重置查询参数
  1771. this.projectQueryParams = {
  1772. pageNum: 1,
  1773. pageSize: 10,
  1774. questionType: null,
  1775. title: null
  1776. };
  1777. this.selectedType = type
  1778. // 设置选中的项目IDs
  1779. if (projectIds) {
  1780. if (typeof projectIds === 'string') {
  1781. this.selectedProjectIds = projectIds.split(',').map(id => parseInt(id));
  1782. } else if (Array.isArray(projectIds)) {
  1783. this.selectedProjectIds = [...projectIds];
  1784. } else if (typeof projectIds === 'number') {
  1785. this.selectedProjectIds = [projectIds];
  1786. }
  1787. } else {
  1788. this.selectedProjectIds = [];
  1789. }
  1790. // 显示弹窗
  1791. this.projectDialogVisible = true;
  1792. // 加载分类树数据
  1793. this.initCategoryTree();
  1794. // 加载项目列表
  1795. this.getProjectList();
  1796. },
  1797. /** 确认选择项目 */
  1798. confirmSelectProject() {
  1799. // 更新表单中的项目ID
  1800. if (this.selectedType === 0) {
  1801. this.form.projectIds = this.selectedProjectIds;
  1802. }
  1803. else if (this.selectedType === 1) {
  1804. this.batchUploadForm.projectIds = this.selectedProjectIds;
  1805. }
  1806. else if (this.selectedType === 2) {
  1807. this.batchEditDialog.form.projectIds = this.selectedProjectIds;
  1808. }
  1809. else if (this.selectedType === 3) {
  1810. const params = {
  1811. id: this.currentRow.id,
  1812. projectIds: this.selectedProjectIds.join(",")
  1813. }
  1814. updateVideoResource(params).then(response => {
  1815. if (response.code === 200) {
  1816. this.msgSuccess("修改成功");
  1817. this.open = false;
  1818. this.getList();
  1819. }
  1820. });
  1821. }
  1822. else if (this.selectedType === 4) {
  1823. this.currentRow.projectIds = this.selectedProjectIds
  1824. }
  1825. this.projectDialogVisible = false;
  1826. },
  1827. /** 取消选择项目 */
  1828. cancelSelectProject() {
  1829. const projectTable = this.$refs.projectTable;
  1830. if (projectTable) {
  1831. // 清空表格数据
  1832. projectTable.clearSelection();
  1833. }
  1834. this.projectDialogVisible = false;
  1835. },
  1836. handleProjectSelect(selection) {
  1837. this.selectedProjectIds = selection.map(item => item.id);
  1838. selection.forEach(item => {
  1839. // 检查是否已存在该项目,不存在则添加
  1840. if (!this.projectShowList.some(p => p.id === item.id)) {
  1841. this.projectShowList.push(item);
  1842. }
  1843. });
  1844. },
  1845. /** 项目列表页码变更 */
  1846. handleProjectPageChange(page) {
  1847. this.projectQueryParams.pageNum = page;
  1848. this.getProjectList();
  1849. },
  1850. /** 项目列表每页条数变更 */
  1851. handleProjectPageSizeChange(size) {
  1852. this.projectQueryParams.pageNum = 1;
  1853. this.projectQueryParams.pageSize = size;
  1854. this.getProjectList();
  1855. },
  1856. /** 处理查看项目 */
  1857. handleViewProject(row, type) {
  1858. // 保存当前选择的行,以便后续操作
  1859. this.currentRow = row;
  1860. // 设置form对象的projectIds为当前行的项目IDs
  1861. this.projectShowList = [];
  1862. if (!row.projectIds || row.projectIds.length === 0) {
  1863. this.openProjectDialog(null, type)
  1864. return;
  1865. }
  1866. let projectIds = row.projectIds
  1867. if (Array.isArray(row.projectIds)) {
  1868. projectIds = projectIds.join(',');
  1869. }
  1870. getByIds({ids: projectIds}).then(response => {
  1871. this.projectShowList = response.data;
  1872. })
  1873. // 打开弹窗展示列表
  1874. this.projectListDialogVisible = true;
  1875. },
  1876. /** 初始化分类树 */
  1877. initCategoryTree() {
  1878. // 获取分类列表
  1879. listUserCourseCategory().then(response => {
  1880. const treeDate = this.handleTree(response.data, "cateId", "pid");
  1881. this.categoryTreeData = [{
  1882. cateId: 0,
  1883. cateName: '全部',
  1884. children: treeDate
  1885. }];
  1886. });
  1887. },
  1888. filterNode(value, data) {
  1889. if (!value) return true;
  1890. return data.cateName.indexOf(value) !== -1;
  1891. },
  1892. /** 处理分类点击 */
  1893. handleCategoryClick(data, node) {
  1894. // 更新查询参数
  1895. this.projectQueryParams.pageNum = 1;
  1896. // 如果是全部分类,则清空分类过滤
  1897. if (node.level === 1) {
  1898. this.projectQueryParams.questionType = null;
  1899. this.projectQueryParams.questionSubType = null;
  1900. }
  1901. else if (node.level === 2) {
  1902. this.projectQueryParams.questionType = data.cateId;
  1903. this.projectQueryParams.questionSubType = null;
  1904. }
  1905. else if (node.level === 3) {
  1906. this.projectQueryParams.questionType = null;
  1907. this.projectQueryParams.questionSubType = data.cateId;
  1908. }
  1909. // 重新加载项目列表
  1910. this.getProjectList();
  1911. },
  1912. /** 搜索项目 */
  1913. searchProjects() {
  1914. this.projectQueryParams.pageNum = 1;
  1915. this.getProjectList();
  1916. },
  1917. /** 视频预览弹窗关闭前的处理函数 */
  1918. handleCloseVideoPreview(done) {
  1919. // 停止视频播放
  1920. const video = document.getElementById('video');
  1921. if (video) {
  1922. video.pause();
  1923. video.currentTime = 0;
  1924. }
  1925. // 关闭弹窗
  1926. this.videoPreviewVisible = false;
  1927. done();
  1928. },
  1929. updateQueuePositions() {
  1930. this.uploadQueue.forEach((video, index) => {
  1931. video.queuePosition = index + 1;
  1932. const videoIndex = this.videoList.findIndex(item => item.tempId === video.tempId);
  1933. if (videoIndex !== -1) {
  1934. this.videoList[videoIndex].queuePosition = index + 1;
  1935. }
  1936. });
  1937. },
  1938. /** 删除视频 */
  1939. handleDeleteVideo(row) {
  1940. if (row.uploadStatus === 'uploading') {
  1941. this.$confirm('该视频正在上传中,确认要取消上传并删除吗?', '取消上传', {
  1942. confirmButtonText: '确定取消',
  1943. cancelButtonText: '继续上传',
  1944. type: 'warning'
  1945. }).then(() => {
  1946. // Cancel the upload and remove from list
  1947. this.cancelVideoUpload(row);
  1948. }).catch(() => {
  1949. // User chose to continue uploading
  1950. this.$message.info('继续上传该视频');
  1951. });
  1952. } else {
  1953. // Original confirmation for non-uploading videos
  1954. this.$confirm('确认要从列表中删除该视频吗?', '提示', {
  1955. confirmButtonText: '确定',
  1956. cancelButtonText: '取消',
  1957. type: 'warning'
  1958. }).then(() => {
  1959. this.removeVideoFromList(row);
  1960. }).catch(() => {
  1961. // 取消删除
  1962. });
  1963. }
  1964. },
  1965. cancelVideoUpload(row) {
  1966. const cancellationTokens = this.uploadCancellationTokens.get(row.tempId);
  1967. if (cancellationTokens) {
  1968. // Cancel COS upload if exists
  1969. if (cancellationTokens.cos) {
  1970. try {
  1971. cancellationTokens.cos();
  1972. console.log('COS upload cancelled for video:', row.tempId);
  1973. } catch (error) {
  1974. console.error('Error cancelling COS upload:', error);
  1975. }
  1976. }
  1977. // Cancel OBS upload if exists
  1978. if (cancellationTokens.obs) {
  1979. try {
  1980. cancellationTokens.obs();
  1981. console.log('OBS upload cancelled for video:', row.tempId);
  1982. } catch (error) {
  1983. console.error('Error cancelling OBS upload:', error);
  1984. }
  1985. }
  1986. // Remove cancellation tokens
  1987. this.uploadCancellationTokens.delete(row.tempId);
  1988. }
  1989. const videoIndex = this.videoList.findIndex(item => item.tempId === row.tempId);
  1990. if (videoIndex !== -1) {
  1991. this.videoList[videoIndex].uploadStatus = 'cancelled';
  1992. this.videoList.splice(videoIndex, 1);
  1993. }
  1994. const queueIndex = this.uploadQueue.findIndex(item => item.tempId === row.tempId);
  1995. if (queueIndex !== -1) {
  1996. this.uploadQueue.splice(queueIndex, 1);
  1997. this.updateQueuePositions();
  1998. }
  1999. this.$message.success('已取消视频上传并从列表中移除');
  2000. },
  2001. removeVideoFromList(row) {
  2002. const videoIndex = this.videoList.findIndex(item => item.tempId === row.tempId);
  2003. if (videoIndex !== -1) {
  2004. this.videoList.splice(videoIndex, 1);
  2005. }
  2006. // Remove from upload queue if it's still queued
  2007. const queueIndex = this.uploadQueue.findIndex(item => item.tempId === row.tempId);
  2008. if (queueIndex !== -1) {
  2009. this.uploadQueue.splice(queueIndex, 1);
  2010. this.updateQueuePositions();
  2011. this.$message.success('已从上传队列中移除该视频');
  2012. } else {
  2013. this.$message.success('已从列表中移除该视频');
  2014. }
  2015. },
  2016. getUploadStatusText(status, queuePosition) {
  2017. switch (status) {
  2018. case 'success':
  2019. return '上传成功';
  2020. case 'failed':
  2021. return '上传失败';
  2022. case 'uploading':
  2023. return '上传中';
  2024. case 'queued':
  2025. return `队列中 (第${queuePosition}位)`;
  2026. default:
  2027. return '待上传';
  2028. }
  2029. },
  2030. getQueueStatusColor(status) {
  2031. switch (status) {
  2032. case 'success':
  2033. return '#67C23A';
  2034. case 'failed':
  2035. return '#F56C6C';
  2036. case 'uploading':
  2037. return '#409EFF';
  2038. case 'queued':
  2039. return '#E6A23C';
  2040. default:
  2041. return '#909399';
  2042. }
  2043. },
  2044. // 批量上传 - 腾讯云
  2045. async uploadVideoToTxPcdnBatch(file, tempVideo) {
  2046. console.log("--------------",JSON.stringify(tempVideo))
  2047. try {
  2048. const data = await uploadObject(file, (progress) => {
  2049. const progressPercent = Math.floor(progress.percent * 100);
  2050. const index = this.videoList.findIndex(item => item.tempId === tempVideo.tempId);
  2051. if (index !== -1) {
  2052. this.videoList[index].uploadDetails.line1 = progressPercent;
  2053. this.videoList[index].uploadDetails.line1Status = 'uploading';
  2054. this.updateBatchProgress(index);
  2055. }
  2056. }, 1, (uploadInfo) => {
  2057. const tokens = this.uploadCancellationTokens.get(tempVideo.tempId) || {};
  2058. tokens.cos = uploadInfo.cancel;
  2059. this.uploadCancellationTokens.set(tempVideo.tempId, tokens);
  2060. });
  2061. let line_1 = `${process.env.VUE_APP_VIDEO_LINE_1}${data.urlPath}`;
  2062. tempVideo.fileKey = data.urlPath.substring(1);
  2063. tempVideo.videoUrl = line_1;
  2064. tempVideo.line1 = line_1;
  2065. return { success: true, url: line_1 };
  2066. } catch (error) {
  2067. return { success: false, error: error.message };
  2068. }
  2069. },
  2070. // 批量上传 - 华为云
  2071. async uploadVideoToHwObsBatch(file, tempVideo) {
  2072. try {
  2073. const data = await uploadToOBS(file, (progress) => {
  2074. const progressPercent = Math.floor(progress);
  2075. const index = this.videoList.findIndex(item => item.tempId === tempVideo.tempId);
  2076. if (index !== -1) {
  2077. this.videoList[index].uploadDetails.line2 = progressPercent;
  2078. this.videoList[index].uploadDetails.line2Status = 'uploading';
  2079. this.updateBatchProgress(index);
  2080. }
  2081. }, 1, (uploadInfo) => {
  2082. const tokens = this.uploadCancellationTokens.get(tempVideo.tempId) || {};
  2083. tokens.obs = uploadInfo.cancel;
  2084. this.uploadCancellationTokens.set(tempVideo.tempId, tokens);
  2085. });
  2086. tempVideo.line2 = `${process.env.VUE_APP_VIDEO_LINE_2}/${data.urlPath}`;
  2087. return { success: true, url: tempVideo.line2 };
  2088. } catch (error) {
  2089. return { success: false, error: error.message };
  2090. }
  2091. },
  2092. // 更新批量上传的总进度
  2093. updateBatchProgress(index) {
  2094. if (index >= 0 && index < this.videoList.length) {
  2095. const item = this.videoList[index];
  2096. const line1Progress = item.uploadDetails.line1 || 0;
  2097. const line2Progress = item.uploadDetails.line2 || 0;
  2098. // 只有两个线路都成功才算100%
  2099. if (item.uploadDetails.line1Status === 'success' && item.uploadDetails.line2Status === 'success') {
  2100. item.progress = 100;
  2101. } else if (item.uploadDetails.line1Status === 'failed' || item.uploadDetails.line2Status === 'failed') {
  2102. // 如果任一线路失败,总进度保持当前状态,不超过99%
  2103. item.progress = Math.min((line1Progress + line2Progress) / 2, 99);
  2104. } else {
  2105. // 正常上传中,计算平均进度,不超过99%
  2106. item.progress = Math.min((line1Progress + line2Progress) / 2, 99);
  2107. }
  2108. }
  2109. },
  2110. // 重试批量上传
  2111. async retryBatchUpload(row) {
  2112. // const index = this.videoList.findIndex(item => item.tempId === row.tempId);
  2113. // if (index === -1) return;
  2114. // const {line1, line2,line1Status,line2Status} = this.videoList[index].uploadDetails
  2115. // // 重置状态
  2116. // this.videoList[index].uploadStatus = 'uploading';
  2117. // // this.videoList[index].progress = 0;
  2118. // this.videoList[index].uploadDetails = {
  2119. // line1: line1 == 100?line1:0,
  2120. // line2: line2 == 100?line2:0,
  2121. // line1Status: line1Status =='success'?line1Status:'pending',
  2122. // line2Status: line2Status =='success'?line2Status:'pending'
  2123. // };
  2124. // const tempVideo = this.videoList[index];
  2125. // try {
  2126. // // 重新上传
  2127. // // const [line1Result, line2Result] = await Promise.allSettled([
  2128. // // this.uploadVideoToTxPcdnBatch(tempVideo.file, tempVideo),
  2129. // // // this.uploadVideoToHwObsBatch(tempVideo.file, tempVideo)
  2130. // // ]);
  2131. // if (line1 !== 100) {
  2132. // const line1Result = await this.uploadVideoToTxPcdnBatch(tempVideo.file, tempVideo)
  2133. // }
  2134. // if (line2 !== 100) {
  2135. // const line2Result = await this.uploadVideoToHwObsBatch(tempVideo.file, tempVideo)
  2136. // }
  2137. // const line1Success = line1Result.status === 'fulfilled' && line1Result.value.success;
  2138. // const line2Success = line2Result.status === 'fulfilled' && line2Result.value.success;
  2139. // if ( line1 == 100 || line1Success) {
  2140. // this.videoList[index].uploadDetails.line1Status = 'success';
  2141. // this.videoList[index].uploadDetails.line1 = 100;
  2142. // this.$message.success(`文件 ${tempVideo.fileName} 重试上传成功`);
  2143. // } else {
  2144. // this.videoList[index].uploadDetails.line1Status = line1Success ? 'success' : 'failed';
  2145. // this.$message.error(`文件 ${tempVideo.fileName} 重试上传失败`);
  2146. // }
  2147. // if (line2 == 100 || line2Success) {
  2148. // this.videoList[index].uploadDetails.line2Status = 'success';
  2149. // this.videoList[index].uploadDetails.line2 = 100;
  2150. // this.$message.success(`文件 ${tempVideo.fileName} 重试上传成功`);
  2151. // } else {
  2152. // this.videoList[index].uploadDetails.line2Status = line2Success ? 'success' : 'failed';
  2153. // this.$message.error(`文件 ${tempVideo.fileName} 重试上传失败`);
  2154. // }
  2155. // // if (line1Success && line2Success) {
  2156. // // this.videoList[index].progress = 100;
  2157. // // this.videoList[index].uploadStatus = 'success';
  2158. // // this.videoList[index].uploadDetails.line1Status = 'success';
  2159. // // this.videoList[index].uploadDetails.line2Status = 'success';
  2160. // // this.videoList[index].uploadDetails.line1 = 100;
  2161. // // this.videoList[index].uploadDetails.line2 = 100;
  2162. // // this.$message.success(`文件 ${tempVideo.fileName} 重试上传成功`);
  2163. // // } else {
  2164. // // this.videoList[index].uploadStatus = 'failed';
  2165. // // this.videoList[index].uploadDetails.line1Status = line1Success ? 'success' : 'failed';
  2166. // // this.videoList[index].uploadDetails.line2Status = line2Success ? 'success' : 'failed';
  2167. // // this.$message.error(`文件 ${tempVideo.fileName} 重试上传失败`);
  2168. // // }
  2169. // } catch (error) {
  2170. // this.videoList[index].uploadStatus = 'failed';
  2171. // this.$message.error(`文件 ${tempVideo.fileName} 重试上传失败`);
  2172. // }
  2173. const index = this.videoList.findIndex(item => item.tempId === row.tempId);
  2174. if (index === -1) return;
  2175. const tempVideo = this.videoList[index];
  2176. const uploadDetails = tempVideo.uploadDetails || {};
  2177. // 检查哪些线路需要重试
  2178. const needRetryLine1 = uploadDetails.line1Status === 'failed' || uploadDetails.line1Status === 'pending';
  2179. const needRetryLine2 = uploadDetails.line2Status === 'failed' || uploadDetails.line2Status === 'pending';
  2180. if (!needRetryLine1 && !needRetryLine2) {
  2181. this.$message.info('所有线路都已上传成功,无需重试');
  2182. return;
  2183. }
  2184. // 更新整体状态为上传中
  2185. this.videoList[index].uploadStatus = 'uploading';
  2186. // 只重置需要重试的线路状态
  2187. if (needRetryLine1) {
  2188. this.videoList[index].uploadDetails.line1 = 0;
  2189. this.videoList[index].uploadDetails.line1Status = 'pending';
  2190. }
  2191. if (needRetryLine2) {
  2192. this.videoList[index].uploadDetails.line2 = 0;
  2193. this.videoList[index].uploadDetails.line2Status = 'pending';
  2194. }
  2195. try {
  2196. const uploadPromises = [];
  2197. // 根据需要重试的线路创建上传任务
  2198. if (needRetryLine1) {
  2199. uploadPromises.push(
  2200. this.uploadVideoToTxPcdnBatch(tempVideo.file, tempVideo)
  2201. .then(result => ({ line: 'line1', result }))
  2202. .catch(error => ({ line: 'line1', result: { success: false, error: error.message } }))
  2203. );
  2204. } else {
  2205. // 如果线路1不需要重试,创建一个已成功的Promise
  2206. uploadPromises.push(Promise.resolve({ line: 'line1', result: { success: true } }));
  2207. }
  2208. if (needRetryLine2) {
  2209. uploadPromises.push(
  2210. this.uploadVideoToHwObsBatch(tempVideo.file, tempVideo)
  2211. .then(result => ({ line: 'line2', result }))
  2212. .catch(error => ({ line: 'line2', result: { success: false, error: error.message } }))
  2213. );
  2214. } else {
  2215. // 如果线路2不需要重试,创建一个已成功的Promise
  2216. uploadPromises.push(Promise.resolve({ line: 'line2', result: { success: true } }));
  2217. }
  2218. // 等待所有上传任务完成
  2219. const results = await Promise.all(uploadPromises);
  2220. // 处理结果
  2221. let line1Success = true;
  2222. let line2Success = true;
  2223. let retryMessages = [];
  2224. results.forEach(({ line, result }) => {
  2225. if (line === 'line1') {
  2226. line1Success = result.success;
  2227. if (needRetryLine1) {
  2228. if (result.success) {
  2229. this.videoList[index].uploadDetails.line1Status = 'success';
  2230. this.videoList[index].uploadDetails.line1 = 100;
  2231. retryMessages.push('线路1重试成功');
  2232. } else {
  2233. this.videoList[index].uploadDetails.line1Status = 'failed';
  2234. retryMessages.push('线路1重试失败');
  2235. }
  2236. }
  2237. } else if (line === 'line2') {
  2238. line2Success = result.success;
  2239. if (needRetryLine2) {
  2240. if (result.success) {
  2241. this.videoList[index].uploadDetails.line2Status = 'success';
  2242. this.videoList[index].uploadDetails.line2 = 100;
  2243. retryMessages.push('线路2重试成功');
  2244. } else {
  2245. this.videoList[index].uploadDetails.line2Status = 'failed';
  2246. retryMessages.push('线路2重试失败');
  2247. }
  2248. }
  2249. }
  2250. });
  2251. // 更新总体状态和进度
  2252. if (line1Success && line2Success) {
  2253. this.videoList[index].progress = 100;
  2254. this.videoList[index].uploadStatus = 'success';
  2255. this.$message.success(`文件 ${tempVideo.fileName} 重试完成:${retryMessages.join(',')}`);
  2256. } else {
  2257. this.videoList[index].uploadStatus = 'failed';
  2258. // 重新计算进度
  2259. this.updateBatchProgress(index);
  2260. this.$message.error(`文件 ${tempVideo.fileName} 重试完成:${retryMessages.join(',')}`);
  2261. }
  2262. } catch (error) {
  2263. this.videoList[index].uploadStatus = 'failed';
  2264. this.$message.error(`文件 ${tempVideo.fileName} 重试过程中发生错误:${error.message || '未知错误'}`);
  2265. }
  2266. },
  2267. // 重试单个上传
  2268. async retryUpload(row) {
  2269. this.$confirm('确认要重新上传该视频吗?', '提示', {
  2270. confirmButtonText: '确定',
  2271. cancelButtonText: '取消',
  2272. type: 'warning'
  2273. }).then(async () => {
  2274. // 这里需要重新触发上传,但由于原始文件可能已经不存在
  2275. // 建议用户重新选择文件上传
  2276. this.$message.info('请重新选择文件进行上传');
  2277. this.handleUpdate(row);
  2278. }).catch(() => {});
  2279. },
  2280. // 获取上传状态图标
  2281. getUploadStatusIcon(status) {
  2282. switch (status) {
  2283. case 'success': return 'el-icon-success';
  2284. case 'failed': return 'el-icon-error';
  2285. case 'uploading': return 'el-icon-loading';
  2286. default: return 'el-icon-time';
  2287. }
  2288. },
  2289. // 获取上传状态颜色
  2290. getUploadStatusColor(status) {
  2291. switch (status) {
  2292. case 'success': return '#67C23A';
  2293. case 'failed': return '#F56C6C';
  2294. case 'uploading': return '#409EFF';
  2295. default: return '#909399';
  2296. }
  2297. },
  2298. // 获取上传状态文本
  2299. getUploadStatusText(status, queuePosition) {
  2300. switch (status) {
  2301. case 'success':
  2302. return '上传成功';
  2303. case 'failed':
  2304. return '上传失败';
  2305. case 'uploading':
  2306. return '上传中';
  2307. case 'queued':
  2308. return `队列中 (第${queuePosition}位)`;
  2309. default:
  2310. return '待上传';
  2311. }
  2312. },
  2313. // 获取线路状态图标
  2314. getLineStatusIcon(status) {
  2315. switch (status) {
  2316. case 'success': return 'el-icon-check';
  2317. case 'failed': return 'el-icon-close';
  2318. case 'uploading': return 'el-icon-loading';
  2319. default: return 'el-icon-minus';
  2320. }
  2321. },
  2322. // 获取线路状态颜色
  2323. getLineStatusColor(status) {
  2324. switch (status) {
  2325. case 'success': return '#67C23A';
  2326. case 'failed': return '#F56C6C';
  2327. case 'uploading': return '#409EFF';
  2328. default: return '#C0C4CC';
  2329. }
  2330. },
  2331. // 获取进度条状态
  2332. getProgressStatus(row) {
  2333. if (row.progress === 100 && row.uploadStatus === 'success') {
  2334. return 'success';
  2335. } else if (row.uploadStatus === 'failed') {
  2336. return 'exception';
  2337. }
  2338. return '';
  2339. },
  2340. }
  2341. }
  2342. </script>
  2343. <style scoped>
  2344. /* 自定义表格样式 */
  2345. .el-table .video-cell {
  2346. padding: 5px;
  2347. }
  2348. /* 设置删除和修改按钮的间距 */
  2349. .el-button + .el-button {
  2350. margin-left: 5px;
  2351. }
  2352. /* 上传状态样式 */
  2353. .upload-status-container {
  2354. display: flex;
  2355. flex-direction: column;
  2356. align-items: center;
  2357. gap: 4px;
  2358. }
  2359. .status-indicator {
  2360. display: flex;
  2361. align-items: center;
  2362. gap: 4px;
  2363. }
  2364. .status-text {
  2365. font-size: 12px;
  2366. }
  2367. .upload-details {
  2368. display: flex;
  2369. flex-direction: column;
  2370. gap: 2px;
  2371. font-size: 11px;
  2372. }
  2373. .line-status {
  2374. display: flex;
  2375. align-items: center;
  2376. gap: 4px;
  2377. }
  2378. .line-label {
  2379. min-width: 35px;
  2380. color: #606266;
  2381. }
  2382. .line-progress {
  2383. color: #909399;
  2384. }
  2385. /* 双线上传进度样式 */
  2386. .dual-upload-progress {
  2387. display: flex;
  2388. flex-direction: column;
  2389. align-items: center;
  2390. gap: 4px;
  2391. }
  2392. .total-progress {
  2393. margin-bottom: 4px;
  2394. }
  2395. .line-progress-container {
  2396. display: flex;
  2397. flex-direction: column;
  2398. gap: 2px;
  2399. width: 100%;
  2400. }
  2401. .line-progress-item {
  2402. display: flex;
  2403. align-items: center;
  2404. gap: 4px;
  2405. font-size: 10px;
  2406. }
  2407. .line-label {
  2408. min-width: 30px;
  2409. color: #606266;
  2410. }
  2411. .line-status-text {
  2412. min-width: 25px;
  2413. color: #909399;
  2414. font-size: 10px;
  2415. }
  2416. /* 批量上传进度样式 */
  2417. .batch-upload-progress {
  2418. display: flex;
  2419. flex-direction: column;
  2420. gap: 4px;
  2421. }
  2422. .total-progress-row {
  2423. display: flex;
  2424. align-items: center;
  2425. gap: 8px;
  2426. white-space: nowrap;
  2427. /* 防止换行 */
  2428. min-width: 0;
  2429. /* 允许flex项目收缩 */
  2430. }
  2431. .progress-label {
  2432. font-size: 12px;
  2433. color: #606266;
  2434. min-width: 40px;
  2435. }
  2436. .line-progress-rows {
  2437. display: flex;
  2438. flex-direction: column;
  2439. gap: 2px;
  2440. }
  2441. .line-progress-row {
  2442. display: flex;
  2443. align-items: center;
  2444. gap: 4px;
  2445. font-size: 11px;
  2446. }
  2447. .line-percentage {
  2448. min-width: 30px;
  2449. color: #909399;
  2450. font-size: 11px;
  2451. }
  2452. ::v-deep .upload-icon {
  2453. font-size: 28px;
  2454. color: #8c939d;
  2455. }
  2456. ::v-deep .upload-text {
  2457. font-size: 12px;
  2458. color: #606266;
  2459. margin-top: 10px;
  2460. }
  2461. /* 表单样式 */
  2462. ::v-deep .el-form-item {
  2463. margin-bottom: 22px;
  2464. }
  2465. /* 批量选择弹窗样式 */
  2466. ::v-deep .batch-dialog .el-dialog__body {
  2467. padding: 0 20px 20px;
  2468. max-height: 70vh;
  2469. overflow-y: auto;
  2470. }
  2471. ::v-deep .el-dialog .el-dialog__body {
  2472. padding: 0 20px 20px;
  2473. max-height: 70vh;
  2474. overflow-y: auto;
  2475. }
  2476. .filter-container {
  2477. padding: 15px 0;
  2478. background-color: #fff;
  2479. border-bottom: 1px solid #ebeef5;
  2480. position: relative;
  2481. text-align: right;
  2482. }
  2483. .dialog-footer {
  2484. text-align: right;
  2485. margin-top: 20px;
  2486. padding-right: 20px;
  2487. }
  2488. ::v-deep .batch-dialog .el-table {
  2489. margin-top: 10px;
  2490. }
  2491. ::v-deep .el-table__header-wrapper th {
  2492. background-color: #f5f7fa;
  2493. color: #606266;
  2494. font-weight: 500;
  2495. padding: 8px 0;
  2496. }
  2497. ::v-deep .el-table__header-wrapper th {
  2498. background-color: #f5f7fa;
  2499. color: #606266;
  2500. font-weight: 500;
  2501. padding: 8px 0;
  2502. }
  2503. /* 确保弹窗中表格内容垂直居中 */
  2504. ::v-deep .batch-dialog .el-table .cell {
  2505. line-height: 23px;
  2506. }
  2507. ::v-deep .el-table .cell {
  2508. line-height: 23px;
  2509. }
  2510. /* 自定义滚动条样式 */
  2511. ::v-deep .batch-dialog .el-dialog__body::-webkit-scrollbar {
  2512. width: 6px;
  2513. height: 6px;
  2514. }
  2515. ::v-deep .el-dialog .el-dialog__body::-webkit-scrollbar {
  2516. width: 6px;
  2517. height: 6px;
  2518. }
  2519. ::v-deep .batch-dialog .el-dialog__body::-webkit-scrollbar-thumb {
  2520. background: #c0c4cc;
  2521. border-radius: 3px;
  2522. }
  2523. ::v-deep .el-dialog .el-dialog__body::-webkit-scrollbar-thumb {
  2524. background: #c0c4cc;
  2525. border-radius: 3px;
  2526. }
  2527. ::v-deep .batch-dialog .el-dialog__body::-webkit-scrollbar-track {
  2528. background: #f5f7fa;
  2529. }
  2530. ::v-deep .el-dialog .el-dialog__body::-webkit-scrollbar-track {
  2531. background: #f5f7fa;
  2532. }
  2533. /* 批量上传视频弹窗样式 */
  2534. .upload-dialog .el-dialog__body {
  2535. padding: 20px;
  2536. }
  2537. ::v-deep .upload-dialog .el-dialog__header {
  2538. padding: 15px 20px;
  2539. background-color: #f9f9f9;
  2540. border-bottom: 1px solid #ebeef5;
  2541. }
  2542. ::v-deep .upload-dialog .el-dialog__title {
  2543. font-size: 16px;
  2544. font-weight: 500;
  2545. color: #303133;
  2546. }
  2547. /* 项目选择弹窗样式 */
  2548. ::v-deep .el-dialog__wrapper {
  2549. z-index: 2001 !important;
  2550. }
  2551. ::v-deep .el-dialog__header {
  2552. padding: 15px 20px;
  2553. background-color: #f9f9f9;
  2554. border-bottom: 1px solid #ebeef5;
  2555. }
  2556. ::v-deep .el-dialog__title {
  2557. font-size: 16px;
  2558. font-weight: 500;
  2559. color: #303133;
  2560. }
  2561. ::v-deep .el-pagination {
  2562. text-align: center;
  2563. margin-top: 10px;
  2564. }
  2565. /* 项目选择弹窗的样式 */
  2566. .project-container {
  2567. display: flex;
  2568. height: 500px;
  2569. }
  2570. .category-tree {
  2571. width: 250px;
  2572. height: 100%;
  2573. border-right: 1px solid #ebeef5;
  2574. padding: 0;
  2575. display: flex;
  2576. flex-direction: column;
  2577. overflow: hidden;
  2578. flex-shrink: 0;
  2579. }
  2580. .tree-fixed-header {
  2581. padding: 10px;
  2582. background-color: #fff;
  2583. border-bottom: 1px solid #ebeef5;
  2584. z-index: 10;
  2585. box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  2586. }
  2587. .tree-content {
  2588. flex: 1;
  2589. overflow-y: auto;
  2590. padding: 10px 10px 10px 10px;
  2591. }
  2592. .project-list {
  2593. flex: 1;
  2594. padding: 10px;
  2595. height: 100%;
  2596. display: flex;
  2597. flex-direction: column;
  2598. width: calc(100% - 250px);
  2599. /* 固定宽度为剩余空间 */
  2600. }
  2601. .project-list .filter-container {
  2602. padding: 0 0 15px 0;
  2603. text-align: left;
  2604. }
  2605. .project-list .table-footer {
  2606. margin-top: 15px;
  2607. }
  2608. ::v-deep .el-tree-node__content {
  2609. height: 36px;
  2610. border-radius: 4px;
  2611. margin-bottom: 2px;
  2612. }
  2613. ::v-deep .el-tree-node:focus > .el-tree-node__content {
  2614. background-color: #e6f7ff;
  2615. }
  2616. ::v-deep .el-tree-node__content:hover {
  2617. background-color: #f0f7ff;
  2618. }
  2619. ::v-deep .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  2620. background-color: #e6f7ff;
  2621. color: #1890ff;
  2622. }
  2623. ::v-deep .custom-tree-node {
  2624. flex: 1;
  2625. display: flex;
  2626. align-items: center;
  2627. justify-content: space-between;
  2628. font-size: 14px;
  2629. padding: 0 8px;
  2630. }
  2631. /* 视频预览弹窗样式 */
  2632. ::v-deep .video-preview-dialog {
  2633. z-index: 3000 !important;
  2634. }
  2635. ::v-deep .video-preview-dialog .el-dialog {
  2636. margin-top: 10vh !important;
  2637. }
  2638. ::v-deep .video-preview-dialog .el-dialog__header {
  2639. padding: 15px 20px;
  2640. background-color: #f9f9f9;
  2641. border-bottom: 1px solid #ebeef5;
  2642. }
  2643. ::v-deep .video-preview-dialog .el-dialog__body {
  2644. padding: 15px;
  2645. background-color: #000;
  2646. display: flex;
  2647. justify-content: center;
  2648. align-items: center;
  2649. }
  2650. ::v-deep .video-preview-dialog video {
  2651. max-width: 100%;
  2652. max-height: 70vh;
  2653. }
  2654. /* 题目列表样式 */
  2655. .project-list-container {
  2656. background-color: #f5f7fa;
  2657. border-radius: 4px;
  2658. }
  2659. .question-card {
  2660. background-color: #ffffff;
  2661. border-radius: 4px;
  2662. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  2663. padding: 15px;
  2664. margin-bottom: 15px;
  2665. position: relative;
  2666. }
  2667. .question-header {
  2668. display: flex;
  2669. align-items: flex-start;
  2670. margin-bottom: 10px;
  2671. border-bottom: 1px solid #ebeef5;
  2672. padding-bottom: 10px;
  2673. }
  2674. .question-index {
  2675. display: flex;
  2676. justify-content: center;
  2677. align-items: center;
  2678. width: 24px;
  2679. height: 24px;
  2680. background-color: #409EFF;
  2681. color: white;
  2682. border-radius: 50%;
  2683. font-size: 14px;
  2684. margin-right: 10px;
  2685. flex-shrink: 0;
  2686. }
  2687. .question-title {
  2688. font-size: 16px;
  2689. font-weight: 500;
  2690. color: #303133;
  2691. line-height: 1.5;
  2692. word-break: break-all;
  2693. }
  2694. .question-type {
  2695. margin-bottom: 15px;
  2696. }
  2697. .content-title {
  2698. font-weight: 500;
  2699. color: #606266;
  2700. margin-bottom: 10px;
  2701. }
  2702. .question-content {
  2703. margin-bottom: 15px;
  2704. }
  2705. .question-item {
  2706. background-color: #f8f8f8;
  2707. border-left: 3px solid #409EFF;
  2708. padding: 10px;
  2709. margin-bottom: 10px;
  2710. border-radius: 0 4px 4px 0;
  2711. }
  2712. .question-item-header {
  2713. display: flex;
  2714. align-items: center;
  2715. margin-bottom: 5px;
  2716. }
  2717. .item-index {
  2718. display: inline-block;
  2719. margin-right: 10px;
  2720. font-weight: 500;
  2721. color: #409EFF;
  2722. }
  2723. .item-name {
  2724. color: #303133;
  2725. }
  2726. .question-answer {
  2727. background-color: #f0f9eb;
  2728. padding: 10px;
  2729. border-radius: 4px;
  2730. border-left: 3px solid #67c23a;
  2731. }
  2732. .answer-label {
  2733. font-weight: 500;
  2734. color: #67c23a;
  2735. margin-right: 10px;
  2736. }
  2737. .answer-content {
  2738. color: #606266;
  2739. }
  2740. ::v-deep .custom-select-class .el-select__tags {
  2741. display: flex;
  2742. flex-direction: column;
  2743. align-items: flex-start;
  2744. flex-wrap: nowrap;
  2745. max-height: 200px;
  2746. overflow-y: auto;
  2747. }
  2748. ::v-deep .custom-select-class .el-tag {
  2749. margin-bottom: 4px;
  2750. margin-right: 0;
  2751. }
  2752. /* Added queue status styles */
  2753. .queue-status {
  2754. display: flex;
  2755. justify-content: center;
  2756. align-items: center;
  2757. padding: 8px;
  2758. }
  2759. .queue-status .el-tag {
  2760. font-size: 12px;
  2761. padding: 4px 8px;
  2762. }
  2763. </style>