index.vue 97 KB

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