index.vue 97 KB

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