index.vue 99 KB

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