index.vue 98 KB

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