index.vue 101 KB

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