index.vue 101 KB

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