aiGengrate.vue 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990
  1. <template>
  2. <Dialog
  3. :title="'AI生成课程'"
  4. v-model="dialogVisible"
  5. width="90%"
  6. :fullscreen="true"
  7. @update:fullscreen="(value) => (fullscreen = value)"
  8. >
  9. <div class="course-script-editor">
  10. <!-- 全屏遮挡层 -->
  11. <div v-if="isGenerating" class="loading-overlay">
  12. <div class="loading-content">
  13. <div class="loading-spinner"></div>
  14. <div class="loading-text">生成中...</div>
  15. </div>
  16. </div>
  17. <div class="main-container">
  18. <!-- 左侧步骤指示器 -->
  19. <div class="steps-sidebar">
  20. <div class="steps-container">
  21. <template v-for="(step, index) in steps" :key="step.id">
  22. <div
  23. :class="[
  24. 'step-item',
  25. {
  26. process: currentStep === step.id,
  27. finish: step.id < currentStep,
  28. wait: step.id > currentStep
  29. }
  30. ]"
  31. >
  32. <div class="step-circle">{{ step.id }}</div>
  33. <div class="step-title">{{ step.label }}</div>
  34. </div>
  35. <div
  36. v-if="index < steps.length - 1"
  37. class="step-line"
  38. :class="{ active: currentStep > step.id }"
  39. ></div>
  40. </template>
  41. </div>
  42. </div>
  43. <!-- 右侧内容区域 -->
  44. <div class="content-area">
  45. <!-- 步骤1:AI一句话生成 -->
  46. <div v-if="currentStep === 1" class="step-content">
  47. <div class="ai-input-container">
  48. <div class="ai-input-wrapper">
  49. <div class="ai-icon">🤖</div>
  50. <textarea
  51. v-model="scriptPrompt"
  52. placeholder="AI一句话生成课程脚本,例如:生成一节关于牛顿万有引力的小学科学课脚本..."
  53. class="ai-textarea"
  54. ></textarea>
  55. </div>
  56. <div class="selection-group">
  57. <div class="selection-item">
  58. <label>主讲老师</label>
  59. <el-select
  60. v-model="selectedMainTeacher"
  61. filterable
  62. size="large"
  63. placeholder="请选择主讲老师"
  64. style="width: 300px"
  65. clearable
  66. >
  67. <el-option
  68. v-for="teacher in digitalHumans"
  69. :key="teacher.name"
  70. :label="teacher.name"
  71. :value="teacher.name"
  72. />
  73. </el-select>
  74. </div>
  75. <div class="selection-item">
  76. <label>助讲老师</label>
  77. <el-select
  78. v-model="selectedAssistants"
  79. filterable
  80. size="large"
  81. placeholder="请选择助讲老师"
  82. style="width: 300px"
  83. clearable
  84. multiple
  85. >
  86. <el-option
  87. v-for="teacher in digitalHumans"
  88. :key="teacher.name"
  89. :label="teacher.name"
  90. :value="teacher.name"
  91. />
  92. </el-select>
  93. </div>
  94. <div class="selection-item">
  95. <label>主题类型</label>
  96. <el-select
  97. v-model="selectedThemeType"
  98. size="large"
  99. placeholder="请选择主题类型"
  100. style="width: 300px"
  101. >
  102. <el-option label="课程通用" value="13" />
  103. <el-option label="诗词课" value="256" />
  104. </el-select>
  105. </div>
  106. </div>
  107. <div class="button-group">
  108. <button
  109. class="generate-btn primary"
  110. :disabled="
  111. !scriptPrompt || !selectedMainTeacher || !selectedThemeType || isGenerating
  112. "
  113. @click="generateScript"
  114. >
  115. {{ isGenerating ? '生成中...' : '生成课程脚本' }}
  116. </button>
  117. <button
  118. v-if="hasDraftCache"
  119. class="generate-btn secondary"
  120. @click="loadDraftAndGotoStep2"
  121. >
  122. 查看草稿
  123. </button>
  124. </div>
  125. </div>
  126. </div>
  127. <!-- 步骤2:脚本编辑(含背景图/音生成) -->
  128. <div v-else-if="currentStep === 2" class="step-content">
  129. <!-- 固定顶部的一键操作栏 -->
  130. <div class="editor-toolbar sticky-top">
  131. <button
  132. class="toolbar-btn"
  133. @click="generateAllImages"
  134. :disabled="isGeneratingImages || isAnyImageGenerating"
  135. >
  136. {{ isGeneratingImages ? '生成中...' : '一键生成所有背景图' }}
  137. </button>
  138. <button
  139. class="toolbar-btn"
  140. @click="generateAllVideos"
  141. :disabled="isGeneratingVideos || isAnyVideoGenerating"
  142. >
  143. {{ isGeneratingVideos ? '生成中...' : '一键生成所有视频' }}
  144. </button>
  145. <button
  146. class="toolbar-btn"
  147. @click="generateAllVoiceovers"
  148. :disabled="isGeneratingVoiceovers || isAnyVoiceoverGenerating"
  149. >
  150. {{ isGeneratingVoiceovers ? '生成中...' : '一键配音' }}
  151. </button>
  152. </div>
  153. <!-- 可滚动的内容区域 -->
  154. <div class="script-editor">
  155. <div
  156. v-for="(section, sectionIndex) in scriptData.sections"
  157. :key="sectionIndex"
  158. class="script-section"
  159. >
  160. <div class="section-header">
  161. <div class="section-name-container">
  162. <label class="section-name-label">环节 {{ sectionIndex + 1 }}</label>
  163. <input
  164. v-model="section.name"
  165. class="section-title"
  166. placeholder="如:环节一(引入)"
  167. />
  168. </div>
  169. <button class="remove-section-btn" @click="removeSection(sectionIndex)">×</button>
  170. </div>
  171. <div class="media-controls">
  172. <!-- 背景类型切换 -->
  173. <el-radio-group v-model="section.backgroundType" class="background-type-switch">
  174. <el-radio-button label="imageAudio">图音背景</el-radio-button>
  175. <el-radio-button label="video">视频背景</el-radio-button>
  176. </el-radio-group>
  177. <!-- 图音背景 -->
  178. <template v-if="section.backgroundType === 'imageAudio'">
  179. <div class="media-item">
  180. <div class="media-input-group">
  181. <span class="media-label">背景图</span>
  182. <el-input
  183. v-model="section.backgroundImage.prompt"
  184. type="textarea"
  185. :autosize="{ minRows: 2, maxRows: 4 }"
  186. placeholder="描述词"
  187. class="media-prompt"
  188. />
  189. <el-button
  190. type="primary"
  191. size="small"
  192. :loading="section.backgroundImage.generating"
  193. :disabled="
  194. !section.backgroundImage.prompt || section.backgroundImage.generating
  195. "
  196. @click="generateMedia(sectionIndex)"
  197. class="generate-btn"
  198. >
  199. {{
  200. section.backgroundImage.generating
  201. ? '生成中...'
  202. : section.backgroundImage.url
  203. ? '重新生成'
  204. : '生成'
  205. }}
  206. </el-button>
  207. </div>
  208. <div class="upload-container">
  209. <UploadImg v-model="section.backgroundImage.url" />
  210. </div>
  211. </div>
  212. <div class="media-item">
  213. <div class="media-input-group">
  214. <span class="media-label">背景音</span>
  215. <el-select
  216. v-model="section.backgroundAudio.type"
  217. placeholder="选择背景音"
  218. :style="{ width: fullscreen ? '240px' : '130px' }"
  219. clearable
  220. size="large"
  221. @change="(value) => handleBackgroundAudioChange(value, section)"
  222. >
  223. <el-option
  224. v-for="musicType in backgroundMusicTypes"
  225. :key="musicType.id"
  226. :label="musicType.name"
  227. :value="musicType.id"
  228. />
  229. </el-select>
  230. <button
  231. v-if="section.backgroundAudio.type"
  232. class="play-btn small"
  233. @click="playBackgroundAudio(section.backgroundAudio.type)"
  234. >
  235. <span class="play-icon">{{
  236. audioState.isPlaying &&
  237. audioState.currentType === 'background' &&
  238. audioState.currentUrl === section.backgroundAudio.url
  239. ? '⏸'
  240. : '▶'
  241. }}</span>
  242. </button>
  243. </div>
  244. </div>
  245. </template>
  246. <!-- 视频背景 -->
  247. <template v-else-if="section.backgroundType === 'video'">
  248. <div class="media-item">
  249. <div class="media-input-group">
  250. <span class="media-label">视频提示词</span>
  251. <el-input
  252. v-model="section.backgroundVideo.prompt"
  253. type="textarea"
  254. :autosize="{ minRows: 2, maxRows: 4 }"
  255. placeholder="描述词"
  256. class="media-prompt-video"
  257. />
  258. <el-button
  259. type="primary"
  260. size="small"
  261. :loading="section.backgroundVideo.generating"
  262. :disabled="
  263. !section.backgroundVideo.prompt || section.backgroundVideo.generating
  264. "
  265. @click="generateVideo(sectionIndex)"
  266. class="generate-btn"
  267. >
  268. {{
  269. section.backgroundVideo.generating
  270. ? '生成中...'
  271. : section.backgroundVideo.url
  272. ? '重新生成'
  273. : '生成'
  274. }}
  275. </el-button>
  276. </div>
  277. <div class="upload-container">
  278. <UploadVideo2 v-model="section.backgroundVideo.url" />
  279. </div>
  280. </div>
  281. </template>
  282. </div>
  283. <div class="dialogues-container">
  284. <div
  285. v-for="(dialogue, dialogueIndex) in section.dialogues"
  286. :key="dialogueIndex"
  287. class="dialogue-item"
  288. :class="[dialogue.type, { hidden: dialogue.type === 'user' }]"
  289. >
  290. <div class="dialogue-header">
  291. <div class="dialogue-type-tag" :class="dialogue.type">
  292. {{
  293. dialogue.type === 'digital'
  294. ? '数字人'
  295. : dialogue.type === 'user'
  296. ? '用户'
  297. : dialogue.type === 'quest'
  298. ? '提问'
  299. : dialogue.type === 'poem'
  300. ? '诗词'
  301. : '视频'
  302. }}
  303. </div>
  304. </div>
  305. <div class="dialogue-row">
  306. <!-- 数字人对话 -->
  307. <template v-if="dialogue.type === 'digital'">
  308. <div class="dialogue-role-select">
  309. <el-select
  310. v-model="dialogue.roleName"
  311. placeholder="选择角色"
  312. style="width: 140px"
  313. clearable
  314. >
  315. <el-option
  316. v-for="role in digitalHumans"
  317. :key="role.id"
  318. :label="role.name"
  319. :value="role.name"
  320. />
  321. </el-select>
  322. </div>
  323. <div class="dialogue-content-container">
  324. <el-input
  325. v-model="dialogue.content"
  326. type="textarea"
  327. class="dialogue-content"
  328. placeholder="对话内容..."
  329. :autosize="{ minRows: 2, maxRows: 4 }"
  330. />
  331. </div>
  332. <div class="action-buttons">
  333. <div class="action-buttons-row">
  334. <button
  335. v-if="dialogue.voiceoverUrl"
  336. class="play-btn"
  337. @click="playVoiceover(dialogue.voiceoverUrl)"
  338. >
  339. <span class="play-icon">{{
  340. audioState.isPlaying &&
  341. audioState.currentType === 'voice' &&
  342. audioState.currentUrl === dialogue.voiceoverUrl
  343. ? '⏸'
  344. : '▶'
  345. }}</span>
  346. </button>
  347. <button
  348. class="remove-btn"
  349. @click="removeDialogue(sectionIndex, dialogueIndex)"
  350. >×</button
  351. >
  352. </div>
  353. <div class="action-buttons-row">
  354. <button
  355. v-if="!dialogue.voiceoverUrl"
  356. class="generate-btn small"
  357. :disabled="
  358. !dialogue.content ||
  359. !dialogue.roleName ||
  360. dialogue.generatingVoiceover
  361. "
  362. @click="generateVoiceover(sectionIndex, dialogueIndex)"
  363. >
  364. <span class="voice-icon">{{
  365. dialogue.generatingVoiceover ? '生成中...' : '生成语音'
  366. }}</span>
  367. </button>
  368. <button
  369. v-if="dialogue.voiceoverUrl"
  370. class="generate-btn small"
  371. :disabled="
  372. !dialogue.content ||
  373. !dialogue.roleName ||
  374. dialogue.generatingVoiceover
  375. "
  376. @click="generateVoiceover(sectionIndex, dialogueIndex)"
  377. >
  378. <span class="voice-icon">{{
  379. dialogue.generatingVoiceover ? '生成中...' : '重新生成'
  380. }}</span>
  381. </button>
  382. </div>
  383. </div>
  384. </template>
  385. <!-- 用户 -->
  386. <template v-else-if="dialogue.type === 'user'">
  387. <div class="dialogue-content-container full-width">
  388. <el-input
  389. v-model="dialogue.content"
  390. type="textarea"
  391. class="dialogue-content"
  392. placeholder="用户回复内容参考语..."
  393. :autosize="{ minRows: 2, maxRows: 4 }"
  394. />
  395. </div>
  396. <div class="dialogue-reply-select">
  397. <el-select
  398. v-model="dialogue.roleName"
  399. placeholder="选择数字人回复"
  400. style="width: 140px"
  401. clearable
  402. >
  403. <el-option
  404. v-for="role in digitalHumans"
  405. :key="role.id"
  406. :label="role.name"
  407. :value="role.name"
  408. />
  409. </el-select>
  410. </div>
  411. <div class="action-buttons">
  412. <div class="action-buttons-row">
  413. <button
  414. class="remove-btn"
  415. @click="removeDialogue(sectionIndex, dialogueIndex)"
  416. >×</button
  417. >
  418. </div>
  419. </div>
  420. </template>
  421. <!-- 提问 -->
  422. <template v-else-if="dialogue.type === 'quest'">
  423. <div class="dialogue-role-select">
  424. <el-select
  425. v-model="dialogue.roleName"
  426. placeholder="选择角色"
  427. style="width: 140px"
  428. clearable
  429. >
  430. <el-option
  431. v-for="role in digitalHumans"
  432. :key="role.id"
  433. :label="role.name"
  434. :value="role.name"
  435. />
  436. </el-select>
  437. </div>
  438. <div class="dialogue-content-container">
  439. <div class="question-type-select">
  440. <span class="question-type-label">提问类型:</span>
  441. <el-select
  442. v-model="dialogue.questionType"
  443. placeholder="请选择提问类型"
  444. style="width: 140px"
  445. >
  446. <el-option label="AI问答" value="AI Q&A" />
  447. <el-option label="单选题" value="singleChoice" />
  448. </el-select>
  449. </div>
  450. <el-input
  451. v-model="dialogue.content"
  452. type="textarea"
  453. class="dialogue-content"
  454. placeholder="提问内容..."
  455. :autosize="{ minRows: 2, maxRows: 4 }"
  456. />
  457. <!-- 单选题选项 -->
  458. <div v-if="dialogue.questionType === 'singleChoice'" class="single-choice-options">
  459. <div class="options-header">
  460. <span class="options-label">选项列表:</span>
  461. <button class="add-option-btn" @click="addOption(sectionIndex, dialogueIndex)">+ 添加选项</button>
  462. </div>
  463. <div
  464. v-for="(option, optionIndex) in (dialogue.options || [])"
  465. :key="optionIndex"
  466. class="option-item"
  467. >
  468. <span class="option-label">{{ String.fromCharCode(65 + optionIndex) }}.</span>
  469. <el-input
  470. v-model="option.content"
  471. placeholder="选项内容"
  472. style="flex: 1; margin-right: 10px;"
  473. />
  474. <div class="answer-radio-wrapper">
  475. <el-radio
  476. v-model="dialogue.answer"
  477. :label="String.fromCharCode(65 + optionIndex)"
  478. />
  479. <span v-if="dialogue.answer === String.fromCharCode(65 + optionIndex)" class="correct-mark">✓</span>
  480. </div>
  481. <button
  482. v-if="(dialogue.options || []).length > 2"
  483. class="remove-option-btn"
  484. @click="removeOption(sectionIndex, dialogueIndex, optionIndex)"
  485. >×</button>
  486. </div>
  487. </div>
  488. </div>
  489. <div class="action-buttons">
  490. <div class="action-buttons-row">
  491. <button
  492. v-if="dialogue.voiceoverUrl"
  493. class="play-btn"
  494. @click="playVoiceover(dialogue.voiceoverUrl)"
  495. >
  496. <span class="play-icon">{{
  497. audioState.isPlaying &&
  498. audioState.currentType === 'voice' &&
  499. audioState.currentUrl === dialogue.voiceoverUrl
  500. ? '⏸'
  501. : '▶'
  502. }}</span>
  503. </button>
  504. <button
  505. class="remove-btn"
  506. @click="removeDialogue(sectionIndex, dialogueIndex)"
  507. >×</button
  508. >
  509. </div>
  510. <div class="action-buttons-row">
  511. <button
  512. v-if="!dialogue.voiceoverUrl"
  513. class="generate-btn small"
  514. :disabled="
  515. !dialogue.content ||
  516. !dialogue.roleName ||
  517. dialogue.generatingVoiceover
  518. "
  519. @click="generateVoiceover(sectionIndex, dialogueIndex)"
  520. >
  521. <span class="voice-icon">{{
  522. dialogue.generatingVoiceover ? '生成中...' : '生成语音'
  523. }}</span>
  524. </button>
  525. <button
  526. v-if="dialogue.voiceoverUrl"
  527. class="generate-btn small"
  528. :disabled="
  529. !dialogue.content ||
  530. !dialogue.roleName ||
  531. dialogue.generatingVoiceover
  532. "
  533. @click="generateVoiceover(sectionIndex, dialogueIndex)"
  534. >
  535. <span class="voice-icon">{{
  536. dialogue.generatingVoiceover ? '生成中...' : '重新生成'
  537. }}</span>
  538. </button>
  539. </div>
  540. </div>
  541. </template>
  542. <!-- 诗词 -->
  543. <template v-else-if="dialogue.type === 'poem'">
  544. <div class="dialogue-role-select">
  545. <el-select
  546. v-model="dialogue.roleName"
  547. placeholder="选择角色"
  548. style="width: 140px"
  549. clearable
  550. >
  551. <el-option
  552. v-for="role in digitalHumans"
  553. :key="role.id"
  554. :label="role.name"
  555. :value="role.name"
  556. />
  557. </el-select>
  558. </div>
  559. <div class="dialogue-content-container">
  560. <el-input
  561. v-model="dialogue.content"
  562. type="textarea"
  563. class="dialogue-content"
  564. placeholder="诗词内容..."
  565. :autosize="{ minRows: 2, maxRows: 4 }"
  566. />
  567. </div>
  568. <div class="action-buttons">
  569. <div class="action-buttons-row">
  570. <button
  571. v-if="dialogue.voiceoverUrl"
  572. class="play-btn"
  573. @click="playVoiceover(dialogue.voiceoverUrl)"
  574. >
  575. <span class="play-icon">{{
  576. audioState.isPlaying &&
  577. audioState.currentType === 'voice' &&
  578. audioState.currentUrl === dialogue.voiceoverUrl
  579. ? '⏸'
  580. : '▶'
  581. }}</span>
  582. </button>
  583. <button
  584. class="remove-btn"
  585. @click="removeDialogue(sectionIndex, dialogueIndex)"
  586. >×</button
  587. >
  588. </div>
  589. <div class="action-buttons-row">
  590. <button
  591. v-if="!dialogue.voiceoverUrl"
  592. class="generate-btn small"
  593. :disabled="
  594. !dialogue.content ||
  595. !dialogue.roleName ||
  596. dialogue.generatingVoiceover
  597. "
  598. @click="generateVoiceover(sectionIndex, dialogueIndex)"
  599. >
  600. <span class="voice-icon">{{
  601. dialogue.generatingVoiceover ? '生成中...' : '生成语音'
  602. }}</span>
  603. </button>
  604. <button
  605. v-if="dialogue.voiceoverUrl"
  606. class="generate-btn small"
  607. :disabled="
  608. !dialogue.content ||
  609. !dialogue.roleName ||
  610. dialogue.generatingVoiceover
  611. "
  612. @click="generateVoiceover(sectionIndex, dialogueIndex)"
  613. >
  614. <span class="voice-icon">{{
  615. dialogue.generatingVoiceover ? '生成中...' : '重新生成'
  616. }}</span>
  617. </button>
  618. </div>
  619. </div>
  620. </template>
  621. <!-- 视频 -->
  622. <template v-else-if="dialogue.type === 'video'">
  623. <div class="media-input-group" style="display: flex; align-items: center; justify-content: center;">
  624. <span class="media-label" style="margin-right: 10px;">视频提示词</span>
  625. <el-input
  626. v-model="dialogue.videoPrompt"
  627. type="textarea"
  628. :autosize="{ minRows: 2, maxRows: 4 }"
  629. placeholder="描述词"
  630. class="media-prompt-video"
  631. style="flex: 1; margin-right: 10px;"
  632. />
  633. <el-button
  634. type="primary"
  635. size="small"
  636. :loading="dialogue.generatingVideo"
  637. :disabled="
  638. !dialogue.videoPrompt || dialogue.generatingVideo
  639. "
  640. @click="generateDialogueVideo(sectionIndex, dialogueIndex)"
  641. class="generate-btn"
  642. style="margin-right: 10px;"
  643. >
  644. {{
  645. dialogue.generatingVideo
  646. ? '生成中...'
  647. : dialogue.videoUrl
  648. ? '重新生成'
  649. : '生成'
  650. }}
  651. </el-button>
  652. <div class="upload-container" style="margin: 0 10px;">
  653. <UploadVideo2 v-model="dialogue.videoUrl" />
  654. </div>
  655. <button
  656. class="remove-btn"
  657. @click="removeDialogue(sectionIndex, dialogueIndex)"
  658. >×</button>
  659. </div>
  660. </template>
  661. </div>
  662. </div>
  663. <div class="add-dialogue-buttons">
  664. <button class="add-dialogue-btn digital" @click="addDialogue(sectionIndex)"
  665. >+ 添加对话</button
  666. >
  667. <button
  668. class="add-dialogue-btn quest-user"
  669. @click="addQuestWithUserReply(sectionIndex)"
  670. >+ 添加提问与回复</button
  671. >
  672. <button class="add-dialogue-btn poem" @click="addPoemDialogue(sectionIndex)"
  673. >+ 添加诗词</button
  674. >
  675. <button class="add-dialogue-btn video" @click="addVideoDialogue(sectionIndex)"
  676. >+ 添加视频</button
  677. >
  678. </div>
  679. </div>
  680. </div>
  681. <button class="add-section-btn" @click="addSection">+ 添加环节</button>
  682. </div>
  683. <div class="preview-actions">
  684. <button v-if="currentStep > 1" class="secondary-btn" @click="currentStep--">
  685. 重新生成
  686. </button>
  687. <button class="primary-btn" @click="nextStep"> 预览完整脚本 </button>
  688. </div>
  689. </div>
  690. <!-- 步骤3:预览与保存 -->
  691. <div v-else-if="currentStep === 3" class="step-content">
  692. <div class="preview-container">
  693. <h3>课程脚本预览</h3>
  694. <div class="scrollable-content">
  695. <br />
  696. <div v-if="isValidationPassed" class="validation-result valid">
  697. {{ validationMessage }}
  698. </div>
  699. <div v-else>
  700. <div
  701. v-for="(error, index) in errorMessages"
  702. :key="index"
  703. class="validation-result invalid"
  704. >
  705. {{ error }}
  706. </div>
  707. </div>
  708. <div class="preview-content">
  709. <div
  710. v-for="(section, sectionIndex) in scriptData.sections"
  711. :key="sectionIndex"
  712. class="preview-section"
  713. :style="{
  714. backgroundImage: section.backgroundType === 'imageAudio' && section.backgroundImage.url
  715. ? `url(${section.backgroundImage.url})`
  716. : 'none',
  717. backgroundSize: 'cover',
  718. backgroundPosition: 'center',
  719. backgroundRepeat: 'no-repeat'
  720. }"
  721. >
  722. <div v-if="section.backgroundType === 'video' && section.backgroundVideo.url" class="preview-video">
  723. <video :src="section.backgroundVideo.url" alt="视频背景" autoplay loop muted ></video>
  724. </div>
  725. <div class="preview-section-content">
  726. <div class="preview-media">
  727. <div class="preview-media-left">
  728. <label class="section-name-label">环节 {{ sectionIndex + 1 }}</label>
  729. <strong>{{ section.name }}</strong>
  730. </div>
  731. <div class="preview-media-right">
  732. <span v-if="section.backgroundType === 'imageAudio' && section.backgroundAudio.type" class="preview-audio">
  733. 背景音:{{ section.backgroundAudio.type }}
  734. <button
  735. class="play-btn small"
  736. @click="playBackgroundAudio(section.backgroundAudio.type)"
  737. >
  738. <span class="play-icon">{{
  739. audioState.isPlaying &&
  740. audioState.currentType === 'background' &&
  741. audioState.currentUrl === section.backgroundAudio.url
  742. ? '⏸'
  743. : '▶'
  744. }}</span>
  745. </button>
  746. </span>
  747. </div>
  748. </div>
  749. <div class="preview-dialogues">
  750. <div
  751. v-for="(dialogue, dialogueIndex) in section.dialogues.filter(
  752. (d) => d.type !== 'user'
  753. )"
  754. :key="dialogueIndex"
  755. class="preview-dialogue"
  756. :class="dialogue.type"
  757. >
  758. <div class="dialogue-header">
  759. <div class="dialogue-header-left">
  760. <div class="dialogue-type-tag" :class="dialogue.type">
  761. {{
  762. dialogue.type === 'digital'
  763. ? '数字人'
  764. : dialogue.type === 'user'
  765. ? '用户'
  766. : dialogue.type === 'quest'
  767. ? '提问'
  768. : dialogue.type === 'poem'
  769. ? '诗词'
  770. : '视频'
  771. }}
  772. </div>
  773. <div class="dialogue-role">
  774. {{
  775. dialogue.type !== 'user' && dialogue.type !== 'video'
  776. ? getRoleName(dialogue.roleName)
  777. : dialogue.type === 'video' ? '视频' : '用户'
  778. }}:
  779. </div>
  780. </div>
  781. <button
  782. v-if="dialogue.voiceoverUrl"
  783. class="play-btn small"
  784. @click="playVoiceover(dialogue.voiceoverUrl)"
  785. >
  786. <span class="play-icon">{{
  787. audioState.isPlaying &&
  788. audioState.currentType === 'voice' &&
  789. audioState.currentUrl === dialogue.voiceoverUrl
  790. ? '⏸'
  791. : '▶'
  792. }}</span>
  793. </button>
  794. </div>
  795. <template v-if="dialogue.type === 'video'">
  796. <div class="dialogue-text">{{ dialogue.videoPrompt }}</div>
  797. <div v-if="dialogue.videoUrl" class="media-preview">
  798. <video :src="dialogue.videoUrl" alt="视频预览" controls></video>
  799. </div>
  800. </template>
  801. <template v-else>
  802. <div class="dialogue-text" v-html="parseMarkdown(dialogue.content)"></div>
  803. </template>
  804. <div
  805. v-if="dialogue.type === 'user' && dialogue.roleName"
  806. class="reply-info"
  807. >
  808. 回复角色:{{ getRoleName(dialogue.roleName) }}
  809. </div>
  810. </div>
  811. </div>
  812. </div>
  813. </div>
  814. </div>
  815. </div>
  816. <div class="preview-actions">
  817. <button class="secondary-btn" @click="currentStep = 2">返回修改</button>
  818. <!-- <button
  819. class="primary-btn"
  820. :disabled="!isValidationPassed"
  821. @click="showVideoPreview"
  822. >
  823. 预览视频
  824. </button>-->
  825. <button class="primary-btn" :disabled="!isValidationPassed" @click="saveScript">
  826. 保存课程脚本
  827. </button>
  828. </div>
  829. </div>
  830. </div>
  831. </div>
  832. </div>
  833. <!-- 视频预览模态框 -->
  834. <VideoPreview
  835. :visible="showVideoPreviewModal"
  836. :script-data="scriptData"
  837. :script-roles="digitalHumans"
  838. @close="closeVideoPreview"
  839. />
  840. </div>
  841. </Dialog>
  842. </template>
  843. <script setup>
  844. import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
  845. import { Dialog } from '@/components/Dialog'
  846. import { ElMessage } from 'element-plus'
  847. import UploadImg from '@/components/UploadFile/src/UploadImg.vue'
  848. import UploadVideo2 from '@/components/UploadFile/src/UploadVideo2.vue'
  849. import { ChatMessageApi } from '@/api/ai/chat/message'
  850. import { ChatConversationApi } from '@/api/ai/chat/conversation'
  851. import { ChatRoleApi } from '@/api/ai/model/chatRole'
  852. import { ImageApi } from '@/api/ai/image'
  853. import { TtsApi } from '@/api/ai/tts'
  854. import { VideoApi} from '@/api/ai/video'
  855. import VideoPreview from '@/views/bjdx/course/aiGenerate/VideoPreview.vue'
  856. import { AiImageStatusEnum, AiPlatformEnum, AiVideoStatusEnum } from '@/views/ai/utils/constants'
  857. import { marked } from 'marked'
  858. import { useUserStore } from '@/store/modules/user'
  859. // 步骤配置
  860. const steps = [
  861. { id: 1, label: 'AI生成脚本' },
  862. { id: 2, label: '编辑脚本与媒体' },
  863. { id: 3, label: '预览与保存' }
  864. ]
  865. // 当前步骤
  866. const currentStep = ref(1)
  867. // 步骤1数据
  868. const scriptPrompt = ref('')
  869. const selectedMainTeacher = ref('')
  870. const selectedAssistants = ref([])
  871. const selectedThemeType = ref()
  872. const isGenerating = ref(false)
  873. // 对话框可见性
  874. const props = defineProps({
  875. visible: {
  876. type: Boolean,
  877. default: false
  878. },
  879. initialStep: {
  880. type: Number,
  881. default: 1
  882. },
  883. initialScriptData: {
  884. type: String,
  885. default: ''
  886. }
  887. })
  888. const dialogVisible = computed({
  889. get: () => props.visible,
  890. set: (value) => emit('update:visible', value)
  891. })
  892. // 获取用户信息
  893. const userStore = useUserStore()
  894. const userId = computed(() => userStore.getUser.id)
  895. // 检查是否存在草稿缓存
  896. const hasDraftCache = ref(false)
  897. // 步骤2生成状态
  898. const isGeneratingImages = ref(false)
  899. const isGeneratingVoiceovers = ref(false)
  900. const isGeneratingVideos = ref(false)
  901. // 数字人列表
  902. const digitalHumans = ref([])
  903. // 背景音类型
  904. const backgroundMusicTypes = ref([
  905. {
  906. id: '轻松欢快',
  907. name: '轻松欢快',
  908. url: 'https://learn-ai.com.cn/admin-api/infra/file/29/get/20260310/AI_1773106630966.MP3'
  909. }
  910. ])
  911. // 从localStorage加载脚本数据
  912. const loadScriptDataFromCache = () => {
  913. try {
  914. const key = `courseScriptData_${userId.value}`
  915. const cachedData = localStorage.getItem(key)
  916. if (cachedData) {
  917. try {
  918. return JSON.parse(cachedData)
  919. } catch (error) {
  920. console.error('解析缓存数据失败:', error)
  921. }
  922. }
  923. } catch (error) {
  924. console.error('获取用户信息失败:', error)
  925. }
  926. return null
  927. }
  928. // 是否为编辑模式
  929. const isEditMode = ref(false)
  930. // 脚本数据结构
  931. const scriptData = reactive(
  932. loadScriptDataFromCache() || {
  933. title: '',
  934. sections: [
  935. {
  936. name: '环节一',
  937. backgroundType: 'imageAudio', // imageAudio: 图音背景, video: 视频背景
  938. backgroundImage: {
  939. prompt: '',
  940. url: '',
  941. generating: false
  942. },
  943. backgroundAudio: {
  944. type: '',
  945. url: ''
  946. },
  947. backgroundVideo: {
  948. prompt: '',
  949. url: '',
  950. generating: false
  951. },
  952. dialogues: [
  953. {
  954. type: 'digital',
  955. roleName: '',
  956. content: '',
  957. voiceoverUrl: '',
  958. generatingVoiceover: false
  959. },
  960. {
  961. type: 'user',
  962. roleName: '',
  963. content: ''
  964. }
  965. ]
  966. }
  967. ]
  968. }
  969. )
  970. // 兼容旧数据,为旧数据添加背景类型字段和提问类型字段
  971. if (scriptData.sections) {
  972. scriptData.sections.forEach(section => {
  973. if (!section.backgroundType) {
  974. section.backgroundType = 'imageAudio';
  975. }
  976. if (!section.backgroundVideo) {
  977. section.backgroundVideo = {
  978. prompt: '',
  979. url: '',
  980. generating: false
  981. };
  982. }
  983. // 为旧数据的提问类型对话添加默认的questionType
  984. if (section.dialogues) {
  985. section.dialogues.forEach(dialogue => {
  986. if (dialogue.type === 'quest' && !dialogue.questionType) {
  987. dialogue.questionType = 'AI Q&A';
  988. dialogue.options = [{ content: '' }, { content: '' }];
  989. dialogue.answer = '';
  990. }
  991. });
  992. }
  993. });
  994. }
  995. // 保存脚本数据到localStorage
  996. const saveScriptDataToCache = () => {
  997. try {
  998. const key = `courseScriptData_${userId.value}`
  999. localStorage.setItem(key, JSON.stringify(scriptData))
  1000. hasDraftCache.value = true
  1001. console.log('保存脚本数据到缓存', key)
  1002. } catch (error) {
  1003. console.error('保存缓存数据失败:', error)
  1004. }
  1005. }
  1006. // 清空脚本数据缓存
  1007. const clearScriptDataCache = () => {
  1008. const key = `courseScriptData_${userId.value}`
  1009. localStorage.removeItem(key)
  1010. hasDraftCache.value = false
  1011. console.log('清除脚本数据缓存', key)
  1012. }
  1013. // 加载草稿并跳转到步骤2
  1014. const loadDraftAndGotoStep2 = () => {
  1015. const cachedData = loadScriptDataFromCache()
  1016. if (cachedData) {
  1017. Object.assign(scriptData, cachedData)
  1018. // 为加载的草稿数据添加背景类型和视频背景字段
  1019. if (scriptData.sections) {
  1020. scriptData.sections.forEach(section => {
  1021. if (!section.backgroundType) {
  1022. section.backgroundType = 'imageAudio';
  1023. }
  1024. if (!section.backgroundVideo) {
  1025. section.backgroundVideo = {
  1026. prompt: '',
  1027. url: '',
  1028. generating: false
  1029. };
  1030. }
  1031. // 为旧数据的提问类型对话添加默认的questionType
  1032. if (section.dialogues) {
  1033. section.dialogues.forEach(dialogue => {
  1034. if (dialogue.type === 'quest' && !dialogue.questionType) {
  1035. dialogue.questionType = 'AI Q&A';
  1036. dialogue.options = [{ content: '' }, { content: '' }];
  1037. dialogue.answer = '';
  1038. }
  1039. });
  1040. }
  1041. });
  1042. }
  1043. currentStep.value = 2
  1044. }
  1045. }
  1046. // 监听脚本数据变化,自动保存到缓存
  1047. watch(
  1048. () => scriptData,
  1049. () => {
  1050. saveScriptDataToCache()
  1051. },
  1052. { deep: true }
  1053. )
  1054. // 监听对话框可见性变化
  1055. watch(
  1056. () => props.visible,
  1057. (newVisible, oldVisible) => {
  1058. if (newVisible) {
  1059. // 对话框打开时,设置初始步骤
  1060. currentStep.value = props.initialStep
  1061. // 清空被替换的URL集合
  1062. replacedUrls.value.clear()
  1063. // 处理脚本数据
  1064. if (props.initialScriptData) {
  1065. // 标记为编辑模式
  1066. isEditMode.value = true
  1067. try {
  1068. const parsedData = JSON.parse(props.initialScriptData)
  1069. Object.assign(scriptData, parsedData)
  1070. // 为加载的脚本数据添加背景类型和视频背景字段
  1071. if (scriptData.sections) {
  1072. scriptData.sections.forEach(section => {
  1073. if (!section.backgroundType) {
  1074. section.backgroundType = 'imageAudio';
  1075. }
  1076. if (!section.backgroundVideo) {
  1077. section.backgroundVideo = {
  1078. prompt: '',
  1079. url: '',
  1080. generating: false
  1081. };
  1082. }
  1083. // 为旧数据的提问类型对话添加默认的questionType
  1084. if (section.dialogues) {
  1085. section.dialogues.forEach(dialogue => {
  1086. if (dialogue.type === 'quest' && !dialogue.questionType) {
  1087. dialogue.questionType = 'AI Q&A';
  1088. dialogue.options = [{ content: '' }, { content: '' }];
  1089. dialogue.answer = '';
  1090. }
  1091. });
  1092. }
  1093. });
  1094. }
  1095. } catch (error) {
  1096. console.error('解析脚本数据失败:', error)
  1097. // 解析失败,尝试加载草稿
  1098. const cachedData = loadScriptDataFromCache()
  1099. if (cachedData) {
  1100. Object.assign(scriptData, cachedData)
  1101. // 为加载的草稿数据添加背景类型和视频背景字段
  1102. if (scriptData.sections) {
  1103. scriptData.sections.forEach(section => {
  1104. if (!section.backgroundType) {
  1105. section.backgroundType = 'imageAudio';
  1106. }
  1107. if (!section.backgroundVideo) {
  1108. section.backgroundVideo = {
  1109. prompt: '',
  1110. url: '',
  1111. generating: false
  1112. };
  1113. }
  1114. // 为旧数据的提问类型对话添加默认的questionType
  1115. if (section.dialogues) {
  1116. section.dialogues.forEach(dialogue => {
  1117. if (dialogue.type === 'quest' && !dialogue.questionType) {
  1118. dialogue.questionType = 'AI Q&A';
  1119. dialogue.options = [{ content: '' }, { content: '' }];
  1120. dialogue.answer = '';
  1121. }
  1122. });
  1123. }
  1124. });
  1125. }
  1126. }
  1127. }
  1128. } else {
  1129. // 标记为新建模式
  1130. isEditMode.value = false
  1131. // 没有脚本数据,尝试加载草稿
  1132. const cachedData = loadScriptDataFromCache()
  1133. if (cachedData) {
  1134. Object.assign(scriptData, cachedData)
  1135. // 为加载的草稿数据添加背景类型和视频背景字段
  1136. if (scriptData.sections) {
  1137. scriptData.sections.forEach(section => {
  1138. if (!section.backgroundType) {
  1139. section.backgroundType = 'imageAudio';
  1140. }
  1141. if (!section.backgroundVideo) {
  1142. section.backgroundVideo = {
  1143. prompt: '',
  1144. url: '',
  1145. generating: false
  1146. };
  1147. }
  1148. // 为旧数据的提问类型对话添加默认的questionType
  1149. if (section.dialogues) {
  1150. section.dialogues.forEach(dialogue => {
  1151. if (dialogue.type === 'quest' && !dialogue.questionType) {
  1152. dialogue.questionType = 'AI Q&A';
  1153. dialogue.options = [{ content: '' }, { content: '' }];
  1154. dialogue.answer = '';
  1155. }
  1156. });
  1157. }
  1158. });
  1159. }
  1160. }
  1161. }
  1162. } else if (oldVisible) {
  1163. // 对话框关闭时
  1164. if (props.initialScriptData) {
  1165. // 编辑进来的,清空缓存
  1166. clearScriptDataCache()
  1167. }
  1168. // 重置编辑模式标记
  1169. isEditMode.value = false
  1170. // 新增进来的,保留缓存
  1171. }
  1172. }
  1173. )
  1174. // 音频播放状态
  1175. const audioState = reactive({
  1176. currentAudio: null,
  1177. isPlaying: false,
  1178. currentType: '',
  1179. currentUrl: ''
  1180. })
  1181. // 存储所有音频实例
  1182. const audioInstances = new Map()
  1183. // 计算属性:判断是否可以进入下一步
  1184. const canProceed = computed(() => {
  1185. switch (currentStep.value) {
  1186. case 1:
  1187. return !!scriptPrompt.value && !!selectedMainTeacher.value && !!selectedThemeType.value
  1188. case 2:
  1189. case 3:
  1190. return scriptData.sections.every(
  1191. (section) =>
  1192. section.backgroundImage.url &&
  1193. section.dialogues.every(
  1194. (dialogue) =>
  1195. (dialogue.type === 'digital' ||
  1196. dialogue.type === 'quest' ||
  1197. dialogue.type === 'poem') &&
  1198. dialogue.roleName &&
  1199. dialogue.content.trim() &&
  1200. dialogue.voiceoverUrl
  1201. )
  1202. )
  1203. default:
  1204. return false
  1205. }
  1206. })
  1207. // 计算属性:检查是否有任何背景图正在生成
  1208. const isAnyImageGenerating = computed(() => {
  1209. return scriptData.sections.some((section) => section.backgroundImage.generating)
  1210. })
  1211. // 计算属性:检查是否有任何配音正在生成
  1212. const isAnyVoiceoverGenerating = computed(() => {
  1213. return scriptData.sections.some((section) =>
  1214. section.dialogues.some((dialogue) => dialogue.generatingVoiceover)
  1215. )
  1216. })
  1217. // 计算属性:检查是否有任何视频正在生成
  1218. const isAnyVideoGenerating = computed(() => {
  1219. return scriptData.sections.some((section) => {
  1220. // 检查背景视频是否正在生成
  1221. if (section.backgroundVideo.generating) {
  1222. return true
  1223. }
  1224. // 检查对话视频是否正在生成
  1225. return section.dialogues.some((dialogue) => dialogue.generatingVideo)
  1226. })
  1227. })
  1228. // 校验结果
  1229. const isValidationPassed = ref(false)
  1230. const validationMessage = ref('')
  1231. const errorMessages = ref([])
  1232. // 视频预览状态
  1233. const showVideoPreviewModal = ref(false)
  1234. // 全屏状态
  1235. const fullscreen = ref(false)
  1236. // 存储被替换的URL链接集合
  1237. const replacedUrls = ref(new Set())
  1238. const activeConversationId = ref(null) // 选中的对话编号
  1239. const conversationInAbortController = ref() // 对话进行中 abort 控制器(控制 stream 对话)
  1240. const conversationInProgress = ref(false) // 对话是否正在进行中。目前只有【发送】消息时,会更新为 true,避免切换对话、删除对话等操作
  1241. const enableContext = ref(false) // 是否开启上下文
  1242. // 接收 Stream 消息
  1243. const receiveMessageFullText = ref('')
  1244. const scriptDataTemp = ref(null)
  1245. // 步骤1:生成脚本
  1246. const generateScript = async () => {
  1247. isGenerating.value = true
  1248. try {
  1249. clearScriptDataCache()
  1250. scriptData.title = ''
  1251. scriptData.sections = []
  1252. receiveMessageFullText.value = ''
  1253. scriptDataTemp.value = null
  1254. const role = digitalHumans.value.find((r) => r.name === selectedMainTeacher.value)
  1255. let content =
  1256. scriptPrompt.value +
  1257. '(主讲人:' +
  1258. role.name +
  1259. ',主讲人角色定位:' +
  1260. role.description +
  1261. ';助讲有:'
  1262. let zhujiang = []
  1263. selectedAssistants.value.forEach((rName) => {
  1264. const role = digitalHumans.value.find((r) => r.name === rName)
  1265. zhujiang.push(role.name + '[' + role.description + ']')
  1266. })
  1267. content += zhujiang.join(',') + ')'
  1268. await createAiRoleIdConversation(Number(selectedThemeType.value))
  1269. currentStep.value = 2
  1270. await doSendMessageStream(activeConversationId.value, content)
  1271. } catch (error) {
  1272. console.error('生成脚本失败:', error)
  1273. } finally {
  1274. isGenerating.value = false
  1275. }
  1276. }
  1277. /** 选择 card 角色:新建聊天对话 */
  1278. const createAiRoleIdConversation = async (roleId) => {
  1279. activeConversationId.value = await ChatConversationApi.createChatConversationMy({
  1280. roleId: roleId
  1281. })
  1282. }
  1283. /** 真正执行【发送】消息操作 */
  1284. const doSendMessageStream = async (conversationId, content) => {
  1285. conversationInAbortController.value = new AbortController()
  1286. conversationInProgress.value = true
  1287. scriptPrompt.value = ''
  1288. try {
  1289. let isFirstChunk = true
  1290. await ChatMessageApi.sendChatMessageStream(
  1291. conversationId,
  1292. content,
  1293. conversationInAbortController.value,
  1294. enableContext.value,
  1295. async (res) => {
  1296. const { code, data, msg } = JSON.parse(res.data)
  1297. if (code !== 0) {
  1298. console.error(`对话异常! ${msg}`)
  1299. return
  1300. }
  1301. if (data.eventType === 'TEXT') {
  1302. if (data.receive?.content === '') {
  1303. return
  1304. }
  1305. if (isFirstChunk) {
  1306. isFirstChunk = false
  1307. }
  1308. receiveMessageFullText.value += data.receive.content
  1309. console.log('数据加载中..')
  1310. try {
  1311. const parsedData = JSON.parse(receiveMessageFullText.value)
  1312. scriptDataTemp.value = parsedData
  1313. Object.assign(scriptData, parsedData)
  1314. // 为新生成的脚本数据添加背景类型和视频背景字段
  1315. if (scriptData.sections) {
  1316. scriptData.sections.forEach(section => {
  1317. if (!section.backgroundType) {
  1318. section.backgroundType = 'imageAudio';
  1319. }
  1320. if (!section.backgroundVideo) {
  1321. section.backgroundVideo = {
  1322. prompt: '',
  1323. url: '',
  1324. generating: false
  1325. };
  1326. }
  1327. // 为新生成的提问类型对话添加默认的questionType
  1328. if (section.dialogues) {
  1329. section.dialogues.forEach(dialogue => {
  1330. if (dialogue.type === 'quest' && !dialogue.questionType) {
  1331. dialogue.questionType = 'AI Q&A';
  1332. dialogue.options = [{ content: '' }, { content: '' }];
  1333. dialogue.answer = '';
  1334. }
  1335. });
  1336. }
  1337. });
  1338. }
  1339. } catch (e) {
  1340. // 解析失败,说明数据还不完整,继续等待
  1341. }
  1342. }
  1343. },
  1344. (error) => {
  1345. console.error(`对话异常! ${error}`)
  1346. throw error
  1347. },
  1348. () => {
  1349. try {
  1350. if (receiveMessageFullText.value) {
  1351. console.log('最终数据:', receiveMessageFullText.value)
  1352. const parsedData = JSON.parse(receiveMessageFullText.value)
  1353. console.log('最终数据json:', parsedData)
  1354. scriptDataTemp.value = parsedData
  1355. Object.assign(scriptData, parsedData)
  1356. // 为新生成的脚本数据添加背景类型和视频背景字段
  1357. if (scriptData.sections) {
  1358. scriptData.sections.forEach(section => {
  1359. if (!section.backgroundType) {
  1360. section.backgroundType = 'imageAudio';
  1361. }
  1362. if (!section.backgroundVideo) {
  1363. section.backgroundVideo = {
  1364. prompt: '',
  1365. url: '',
  1366. generating: false
  1367. };
  1368. }
  1369. // 为新生成的提问类型对话添加默认的questionType
  1370. if (section.dialogues) {
  1371. section.dialogues.forEach(dialogue => {
  1372. if (dialogue.type === 'quest' && !dialogue.questionType) {
  1373. dialogue.questionType = 'AI Q&A';
  1374. dialogue.options = [{ content: '' }, { content: '' }];
  1375. dialogue.answer = '';
  1376. }
  1377. });
  1378. }
  1379. });
  1380. }
  1381. }
  1382. } catch (e) {
  1383. console.error('最终数据解析失败:', e)
  1384. // 清洗规则:移除```json、```、** 等非JSON标记,只保留中间的JSON内容
  1385. try {
  1386. let cleanJsonStr = receiveMessageFullText.value
  1387. const parsedData = JSON.parse(
  1388. cleanJsonStr
  1389. .replace(/^```json\s*/, '')
  1390. .replace(/\s*```$/, '')
  1391. .replace(/\*\*/g, '')
  1392. .trim()
  1393. )
  1394. console.log('最终清洗后数据json:', parsedData)
  1395. scriptDataTemp.value = parsedData
  1396. Object.assign(scriptData, parsedData)
  1397. // 为新生成的脚本数据添加背景类型和视频背景字段
  1398. if (scriptData.sections) {
  1399. scriptData.sections.forEach(section => {
  1400. if (!section.backgroundType) {
  1401. section.backgroundType = 'imageAudio';
  1402. }
  1403. if (!section.backgroundVideo) {
  1404. section.backgroundVideo = {
  1405. prompt: '',
  1406. url: '',
  1407. generating: false
  1408. };
  1409. }
  1410. // 为新生成的提问类型对话添加默认的questionType
  1411. if (section.dialogues) {
  1412. section.dialogues.forEach(dialogue => {
  1413. if (dialogue.type === 'quest' && !dialogue.questionType) {
  1414. dialogue.questionType = 'AI Q&A';
  1415. dialogue.options = [{ content: '' }, { content: '' }];
  1416. dialogue.answer = '';
  1417. }
  1418. });
  1419. }
  1420. });
  1421. }
  1422. } catch (cleanError) {
  1423. console.error('清洗后数据解析失败:', cleanError)
  1424. }
  1425. }
  1426. }
  1427. )
  1428. } catch (error) {
  1429. console.error('发送消息流失败:', error)
  1430. } finally {
  1431. conversationInProgress.value = false
  1432. }
  1433. }
  1434. // 步骤2:添加环节
  1435. const addSection = () => {
  1436. scriptData.sections.push({
  1437. name: `环节${scriptData.sections.length + 1}`,
  1438. backgroundType: 'imageAudio', // imageAudio: 图音背景, video: 视频背景
  1439. backgroundImage: { prompt: '', url: '', generating: false },
  1440. backgroundAudio: { type: '', url: '' },
  1441. backgroundVideo: { prompt: '', url: '', generating: false },
  1442. dialogues: []
  1443. })
  1444. }
  1445. // 步骤2:添加对话(数字人)
  1446. const addDialogue = (sectionIndex) => {
  1447. scriptData.sections[sectionIndex].dialogues.push({
  1448. type: 'digital',
  1449. roleName: '',
  1450. content: '',
  1451. voiceoverUrl: '',
  1452. generatingVoiceover: false
  1453. })
  1454. }
  1455. // 步骤2:添加视频对话
  1456. const addVideoDialogue = (sectionIndex) => {
  1457. scriptData.sections[sectionIndex].dialogues.push({
  1458. type: 'video',
  1459. videoUrl: '',
  1460. videoPrompt: '',
  1461. generatingVideo: false
  1462. })
  1463. }
  1464. // 步骤2:添加用户回复
  1465. const addUserReply = (sectionIndex) => {
  1466. scriptData.sections[sectionIndex].dialogues.push({
  1467. type: 'user',
  1468. content: '',
  1469. roleName: '',
  1470. voiceoverUrl: '',
  1471. generatingVoiceover: false
  1472. })
  1473. }
  1474. // 步骤2:添加提问
  1475. const addQuestDialogue = (sectionIndex) => {
  1476. scriptData.sections[sectionIndex].dialogues.push({
  1477. type: 'quest',
  1478. content: '',
  1479. roleName: '',
  1480. voiceoverUrl: '',
  1481. generatingVoiceover: false,
  1482. questionType: 'AI Q&A',
  1483. options: [{ content: '' }, { content: '' }],
  1484. answer: ''
  1485. })
  1486. }
  1487. // 步骤2:添加诗词
  1488. const addPoemDialogue = (sectionIndex) => {
  1489. scriptData.sections[sectionIndex].dialogues.push({
  1490. type: 'poem',
  1491. content: '',
  1492. roleName: '',
  1493. voiceoverUrl: '',
  1494. generatingVoiceover: false
  1495. })
  1496. }
  1497. // 步骤2:添加提问与用户回复
  1498. const addQuestWithUserReply = (sectionIndex) => {
  1499. // 添加提问类型对话
  1500. scriptData.sections[sectionIndex].dialogues.push({
  1501. type: 'quest',
  1502. content: '',
  1503. roleName: '',
  1504. voiceoverUrl: '',
  1505. generatingVoiceover: false,
  1506. questionType: 'AI Q&A',
  1507. options: [{ content: '' }, { content: '' }],
  1508. answer: ''
  1509. })
  1510. // 添加用户回复类型对话
  1511. scriptData.sections[sectionIndex].dialogues.push({
  1512. type: 'user',
  1513. content: '',
  1514. roleName: '',
  1515. voiceoverUrl: '',
  1516. generatingVoiceover: false
  1517. })
  1518. }
  1519. // 步骤2:添加单选题选项
  1520. const addOption = (sectionIndex, dialogueIndex) => {
  1521. const dialogue = scriptData.sections[sectionIndex].dialogues[dialogueIndex]
  1522. if (!dialogue.options) {
  1523. dialogue.options = []
  1524. }
  1525. if (dialogue.options.length < 6) {
  1526. dialogue.options.push({ content: '' })
  1527. }
  1528. }
  1529. // 步骤2:删除单选题选项
  1530. const removeOption = (sectionIndex, dialogueIndex, optionIndex) => {
  1531. const dialogue = scriptData.sections[sectionIndex].dialogues[dialogueIndex]
  1532. if (dialogue.options && dialogue.options.length > 2) {
  1533. dialogue.options.splice(optionIndex, 1)
  1534. // 如果删除的是当前选中的答案,需要重新设置答案
  1535. if (dialogue.answer && dialogue.answer.charCodeAt(0) - 65 >= dialogue.options.length) {
  1536. dialogue.answer = ''
  1537. }
  1538. }
  1539. }
  1540. // 步骤2:删除对话
  1541. const removeDialogue = (sectionIndex, dialogueIndex) => {
  1542. const dialogues = scriptData.sections[sectionIndex].dialogues
  1543. const dialogue = dialogues[dialogueIndex]
  1544. // 如果是提问类型,同时删除后面的用户回复
  1545. if (
  1546. dialogue.type === 'quest' &&
  1547. dialogueIndex < dialogues.length - 1 &&
  1548. dialogues[dialogueIndex + 1].type === 'user'
  1549. ) {
  1550. dialogues.splice(dialogueIndex, 2)
  1551. } else {
  1552. dialogues.splice(dialogueIndex, 1)
  1553. }
  1554. }
  1555. // 步骤2:删除环节
  1556. const removeSection = (sectionIndex) => {
  1557. if (scriptData.sections.length > 1) {
  1558. scriptData.sections.splice(sectionIndex, 1)
  1559. } else {
  1560. alert('至少需要保留一个环节')
  1561. }
  1562. }
  1563. // 图片生成相关状态
  1564. const inProgressImageMap = ref({}) // 监听的图片映射,key 为 image 编号,value 为 { sectionIndex, type: 'image'|'audio' }
  1565. const inProgressTimer = ref(null) // 生成中的图片定时器,轮询生成进展
  1566. // 视频生成相关状态
  1567. const inProgressVideoMap = ref({}) // 监听的视频映射,key 为 video 编号,value 为 { sectionIndex, dialogueIndex, type: 'background'|'dialogue' }
  1568. const inProgressVideoTimer = ref(null) // 生成中的视频定时器,轮询生成进展
  1569. // 步骤2:生成单个媒体(仅背景图)
  1570. const generateMedia = async (sectionIndex) => {
  1571. const section = scriptData.sections[sectionIndex]
  1572. const media = section.backgroundImage
  1573. // 记录旧的URL
  1574. let oldUrl = null
  1575. if (media.url) {
  1576. oldUrl = media.url
  1577. replacedUrls.value.add(oldUrl)
  1578. }
  1579. media.generating = true
  1580. try {
  1581. const form = {
  1582. platform: AiPlatformEnum.DOU_BAO,
  1583. modelId: 56,
  1584. prompt: media.prompt,
  1585. width: 1024,
  1586. height: 768
  1587. }
  1588. const response = await ImageApi.drawImage(form)
  1589. inProgressImageMap.value[response] = {
  1590. sectionIndex
  1591. }
  1592. } catch (error) {
  1593. console.error(`生成图片失败:`, error)
  1594. media.generating = false
  1595. // 生成失败,从replacedUrls中移除旧URL
  1596. if (oldUrl) {
  1597. replacedUrls.value.delete(oldUrl)
  1598. }
  1599. }
  1600. }
  1601. // 步骤2:生成视频背景
  1602. const generateVideo = async (sectionIndex) => {
  1603. const section = scriptData.sections[sectionIndex]
  1604. const media = section.backgroundVideo
  1605. // 记录旧的URL
  1606. let oldUrl = null
  1607. if (media.url) {
  1608. oldUrl = media.url
  1609. replacedUrls.value.add(oldUrl)
  1610. }
  1611. media.generating = true
  1612. try {
  1613. const form = {
  1614. platform: AiPlatformEnum.DOU_BAO,
  1615. modelId: 60,
  1616. prompt: media.prompt,
  1617. width: 1024,
  1618. height: 768,
  1619. resolution: '1080P',
  1620. duration: 4,
  1621. options: {}
  1622. }
  1623. const response = await VideoApi.drawVideo(form)
  1624. inProgressVideoMap.value[response] = {
  1625. sectionIndex,
  1626. type: 'background'
  1627. }
  1628. } catch (error) {
  1629. console.error(`生成视频失败:`, error)
  1630. media.generating = false
  1631. // 生成失败,从replacedUrls中移除旧URL
  1632. if (oldUrl) {
  1633. replacedUrls.value.delete(oldUrl)
  1634. }
  1635. }
  1636. }
  1637. // 步骤2:生成对话视频
  1638. const generateDialogueVideo = async (sectionIndex, dialogueIndex) => {
  1639. const dialogue = scriptData.sections[sectionIndex].dialogues[dialogueIndex]
  1640. // 记录旧的URL
  1641. let oldUrl = null
  1642. if (dialogue.videoUrl) {
  1643. oldUrl = dialogue.videoUrl
  1644. replacedUrls.value.add(oldUrl)
  1645. }
  1646. dialogue.generatingVideo = true
  1647. try {
  1648. const form = {
  1649. platform: AiPlatformEnum.DOU_BAO,
  1650. modelId: 64,
  1651. prompt: dialogue.videoPrompt,
  1652. width: 1024,
  1653. height: 768,
  1654. resolution: '1080P',
  1655. duration: 4,
  1656. options: {}
  1657. }
  1658. const response = await VideoApi.drawVideo(form)
  1659. inProgressVideoMap.value[response] = {
  1660. sectionIndex,
  1661. dialogueIndex,
  1662. type: 'dialogue'
  1663. }
  1664. } catch (error) {
  1665. console.error(`生成对话视频失败:`, error)
  1666. dialogue.generatingVideo = false
  1667. // 生成失败,从replacedUrls中移除旧URL
  1668. if (oldUrl) {
  1669. replacedUrls.value.delete(oldUrl)
  1670. }
  1671. }
  1672. }
  1673. // 步骤2:一键生成所有背景图
  1674. const generateAllImages = async () => {
  1675. isGeneratingImages.value = true
  1676. try {
  1677. for (let i = 0; i < scriptData.sections.length; i++) {
  1678. const section = scriptData.sections[i]
  1679. // 只处理没有背景图URL的环节
  1680. if (!section.backgroundImage.url) {
  1681. await generateMedia(i)
  1682. }
  1683. }
  1684. // 检查是否有图片正在生成
  1685. const checkImagesComplete = setInterval(() => {
  1686. if (Object.keys(inProgressImageMap.value).length === 0) {
  1687. isGeneratingImages.value = false
  1688. clearInterval(checkImagesComplete)
  1689. }
  1690. }, 1000)
  1691. } catch (error) {
  1692. console.error('生成所有背景图失败:', error)
  1693. isGeneratingImages.value = false
  1694. }
  1695. }
  1696. // 步骤2:一键生成所有视频
  1697. const generateAllVideos = async () => {
  1698. isGeneratingVideos.value = true
  1699. try {
  1700. for (let i = 0; i < scriptData.sections.length; i++) {
  1701. const section = scriptData.sections[i]
  1702. // 处理视频背景
  1703. if (section.backgroundType === 'video' && !section.backgroundVideo.url) {
  1704. await generateVideo(i)
  1705. }
  1706. // 处理对话视频
  1707. for (let j = 0; j < section.dialogues.length; j++) {
  1708. const dialogue = section.dialogues[j]
  1709. if (dialogue.type === 'video' && !dialogue.videoUrl) {
  1710. await generateDialogueVideo(i, j)
  1711. }
  1712. }
  1713. }
  1714. // 检查是否有视频正在生成
  1715. const checkVideosComplete = setInterval(() => {
  1716. if (Object.keys(inProgressVideoMap.value).length === 0) {
  1717. isGeneratingVideos.value = false
  1718. clearInterval(checkVideosComplete)
  1719. }
  1720. }, 1000)
  1721. } catch (error) {
  1722. console.error('生成所有视频失败:', error)
  1723. isGeneratingVideos.value = false
  1724. }
  1725. }
  1726. // 轮询生成中的图片列表
  1727. const refreshWatchImages = async () => {
  1728. const imageIds = Object.keys(inProgressImageMap.value).map(Number)
  1729. if (imageIds.length === 0) {
  1730. return
  1731. }
  1732. try {
  1733. const list = await ImageApi.getImageListMyByIds(imageIds)
  1734. const newWatchImages = {}
  1735. list.forEach((image) => {
  1736. const info = inProgressImageMap.value[image.id]
  1737. if (info) {
  1738. if (image.status === AiImageStatusEnum.IN_PROGRESS) {
  1739. newWatchImages[image.id] = info
  1740. } else if (image.status === AiImageStatusEnum.SUCCESS && image.picUrl) {
  1741. const section = scriptData.sections[info.sectionIndex]
  1742. section.backgroundImage.url = image.picUrl
  1743. section.backgroundImage.generating = false
  1744. } else if (image.status === AiImageStatusEnum.FAIL) {
  1745. const section = scriptData.sections[info.sectionIndex]
  1746. section.backgroundImage.generating = false
  1747. // 生成失败,从replacedUrls中移除旧URL
  1748. if (section.backgroundImage.url) {
  1749. replacedUrls.value.delete(section.backgroundImage.url)
  1750. }
  1751. }
  1752. }
  1753. })
  1754. inProgressImageMap.value = newWatchImages
  1755. } catch (error) {
  1756. console.error('轮询图片状态失败:', error)
  1757. }
  1758. }
  1759. // 轮询生成中的视频列表
  1760. const refreshWatchVideos = async () => {
  1761. const videoIds = Object.keys(inProgressVideoMap.value).map(Number)
  1762. if (videoIds.length === 0) {
  1763. return
  1764. }
  1765. try {
  1766. const list = await VideoApi.getVideoListMyByIds(videoIds)
  1767. const newWatchVideos = {}
  1768. list.forEach((video) => {
  1769. const info = inProgressVideoMap.value[video.id]
  1770. if (info) {
  1771. if (video.status === AiVideoStatusEnum.IN_PROGRESS) {
  1772. newWatchVideos[video.id] = info
  1773. } else if (video.status === AiVideoStatusEnum.SUCCESS && video.videoUrl) {
  1774. if (info.type === 'background') {
  1775. const section = scriptData.sections[info.sectionIndex]
  1776. section.backgroundVideo.url = video.videoUrl
  1777. section.backgroundVideo.generating = false
  1778. } else if (info.type === 'dialogue') {
  1779. const dialogue = scriptData.sections[info.sectionIndex].dialogues[info.dialogueIndex]
  1780. dialogue.videoUrl = video.videoUrl
  1781. dialogue.generatingVideo = false
  1782. }
  1783. } else if (video.status === AiVideoStatusEnum.FAIL) {
  1784. if (info.type === 'background') {
  1785. const section = scriptData.sections[info.sectionIndex]
  1786. section.backgroundVideo.generating = false
  1787. // 生成失败,从replacedUrls中移除旧URL
  1788. if (section.backgroundVideo.url) {
  1789. replacedUrls.value.delete(section.backgroundVideo.url)
  1790. }
  1791. } else if (info.type === 'dialogue') {
  1792. const dialogue = scriptData.sections[info.sectionIndex].dialogues[info.dialogueIndex]
  1793. dialogue.generatingVideo = false
  1794. // 生成失败,从replacedUrls中移除旧URL
  1795. if (dialogue.videoUrl) {
  1796. replacedUrls.value.delete(dialogue.videoUrl)
  1797. }
  1798. }
  1799. }
  1800. }
  1801. })
  1802. inProgressVideoMap.value = newWatchVideos
  1803. } catch (error) {
  1804. console.error('轮询视频状态失败:', error)
  1805. }
  1806. }
  1807. // 播放音频通用函数
  1808. const playAudio = (url, type) => {
  1809. if (audioState.currentAudio) {
  1810. audioState.currentAudio.pause()
  1811. audioState.currentAudio.currentTime = 0
  1812. }
  1813. if (audioState.isPlaying && audioState.currentUrl === url && audioState.currentType === type) {
  1814. if (audioState.currentAudio) {
  1815. audioState.currentAudio.pause()
  1816. }
  1817. audioState.isPlaying = false
  1818. return
  1819. }
  1820. let audio = audioInstances.get(`${type}_${url}`)
  1821. if (!audio) {
  1822. audio = new Audio(url)
  1823. audio.autoplay = false
  1824. audioInstances.set(`${type}_${url}`, audio)
  1825. audio.onended = () => {
  1826. audioState.isPlaying = false
  1827. audioState.currentAudio = null
  1828. audioState.currentUrl = ''
  1829. audioState.currentType = ''
  1830. }
  1831. }
  1832. audio.play().catch((error) => {
  1833. console.error('播放失败:', error)
  1834. audioState.isPlaying = false
  1835. })
  1836. audioState.currentAudio = audio
  1837. audioState.isPlaying = true
  1838. audioState.currentUrl = url
  1839. audioState.currentType = type
  1840. }
  1841. // 播放语音
  1842. const playVoiceover = (voiceoverUrl) => {
  1843. playAudio(voiceoverUrl, 'voice')
  1844. }
  1845. // 处理背景音选择变化
  1846. const handleBackgroundAudioChange = (value, section) => {
  1847. if (value) {
  1848. const selectedMusic = backgroundMusicTypes.value.find((music) => music.id === value)
  1849. if (selectedMusic) {
  1850. section.backgroundAudio.url = selectedMusic.url
  1851. }
  1852. } else {
  1853. section.backgroundAudio.url = ''
  1854. }
  1855. }
  1856. // 播放背景音
  1857. const playBackgroundAudio = (musicType) => {
  1858. const selectedMusic = backgroundMusicTypes.value.find((music) => music.id === musicType)
  1859. const audioUrl = selectedMusic ? selectedMusic.url : `https://example.com/${musicType}.mp3`
  1860. playAudio(audioUrl, 'background')
  1861. }
  1862. // 生成单个语音
  1863. const generateVoiceover = async (sectionIndex, dialogueIndex) => {
  1864. const dialogue = scriptData.sections[sectionIndex].dialogues[dialogueIndex]
  1865. // 只处理数字人、提问和诗词类型的对话
  1866. if (dialogue.type !== 'digital' && dialogue.type !== 'quest' && dialogue.type !== 'poem') {
  1867. return
  1868. }
  1869. // 记录旧的URL
  1870. let oldUrl = null
  1871. if (dialogue.voiceoverUrl) {
  1872. oldUrl = dialogue.voiceoverUrl
  1873. replacedUrls.value.add(oldUrl)
  1874. }
  1875. dialogue.generatingVoiceover = true
  1876. let role = digitalHumans.value.find((r) => r.name === dialogue.roleName)
  1877. try {
  1878. // 根据对话类型设置不同的command
  1879. const command =
  1880. dialogue.type === 'poem' ? '要有感情的朗读诗词语句,要符合诗词的节奏和韵律。' : null
  1881. // 调用后端API将文本转成语音
  1882. // 将返回的URL赋值给对话
  1883. dialogue.voiceoverUrl = await TtsApi.convert({
  1884. roleId: Number(role.id),
  1885. content: dialogue.content,
  1886. command: command
  1887. })
  1888. } catch (error) {
  1889. console.error('生成语音失败:', error)
  1890. // 生成失败,从replacedUrls中移除旧URL
  1891. if (oldUrl) {
  1892. replacedUrls.value.delete(oldUrl)
  1893. }
  1894. } finally {
  1895. dialogue.generatingVoiceover = false
  1896. }
  1897. }
  1898. // 步骤3:一键生成所有语音
  1899. const generateAllVoiceovers = async () => {
  1900. isGeneratingVoiceovers.value = true
  1901. try {
  1902. for (let i = 0; i < scriptData.sections.length; i++) {
  1903. for (let j = 0; j < scriptData.sections[i].dialogues.length; j++) {
  1904. const dialogue = scriptData.sections[i].dialogues[j]
  1905. // 只处理没有语音URL的对话
  1906. if (!dialogue.voiceoverUrl) {
  1907. await generateVoiceover(i, j)
  1908. }
  1909. }
  1910. }
  1911. } catch (error) {
  1912. console.error('生成所有语音失败:', error)
  1913. } finally {
  1914. isGeneratingVoiceovers.value = false
  1915. }
  1916. }
  1917. // 获取角色名称
  1918. const getRoleName = (roleName) => {
  1919. const role = digitalHumans.value.find((r) => r.name === roleName)
  1920. return role ? role.name : '未知角色'
  1921. }
  1922. // 解析 Markdown 文本
  1923. const parseMarkdown = (text) => {
  1924. if (!text) return ''
  1925. return marked(text)
  1926. }
  1927. // 步骤4:校验脚本
  1928. const validateScript = () => {
  1929. let isValid = true
  1930. errorMessages.value = []
  1931. // 检查环节名称、背景图或视频
  1932. scriptData.sections.forEach((section, sectionIndex) => {
  1933. if (!section.name.trim()) {
  1934. errorMessages.value.push(`环节${sectionIndex + 1}:名称未配置!`)
  1935. isValid = false
  1936. }
  1937. // 根据背景类型检查对应的媒体URL
  1938. if (section.backgroundType === 'video') {
  1939. // 视频背景需要检查视频URL
  1940. if (!section.backgroundVideo.url) {
  1941. errorMessages.value.push(`环节${sectionIndex + 1}:视频背景URL未配置!`)
  1942. isValid = false
  1943. }
  1944. } else if (section.backgroundType === 'imageAudio') {
  1945. // 图音背景需要检查背景图URL
  1946. if (!section.backgroundImage.url) {
  1947. errorMessages.value.push(`环节${sectionIndex + 1}:背景图URL未配置!`)
  1948. isValid = false
  1949. }
  1950. }
  1951. // 检查对话
  1952. section.dialogues.forEach((dialogue, dialogueIndex) => {
  1953. // 检查数字人、提问和诗词类型的对话
  1954. if (dialogue.type === 'digital' || dialogue.type === 'quest' || dialogue.type === 'poem') {
  1955. if (
  1956. !dialogue.roleName ||
  1957. !dialogue.content.trim() ||
  1958. (dialogue.type !== 'poem' && !dialogue.voiceoverUrl)
  1959. ) {
  1960. errorMessages.value.push(
  1961. `环节${sectionIndex + 1}:对话${dialogueIndex + 1}:存在完成内容!`
  1962. )
  1963. isValid = false
  1964. }
  1965. } else if (dialogue.type === 'video') {
  1966. // 检查视频类型的对话
  1967. if (
  1968. !dialogue.videoUrl
  1969. ) {
  1970. errorMessages.value.push(
  1971. `环节${sectionIndex + 1}:对话${dialogueIndex + 1}:视频内容未配置完整!`
  1972. )
  1973. isValid = false
  1974. }
  1975. }
  1976. })
  1977. })
  1978. isValidationPassed.value = isValid
  1979. validationMessage.value = errorMessages.value.length > 0 ? '校验失败' : '校验通过'
  1980. }
  1981. // 图片上传前验证
  1982. const beforeImageUpload = (file) => {
  1983. const isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif' || file.type === 'image/webp'
  1984. const isLt2M = file.size / 1024 / 1024 < 2
  1985. if (!isJPG) {
  1986. ElMessage.error('只能上传 JPG、PNG、GIF、WebP 格式的图片!')
  1987. return false
  1988. }
  1989. if (!isLt2M) {
  1990. ElMessage.error('图片大小不能超过 2MB!')
  1991. return false
  1992. }
  1993. return true
  1994. }
  1995. // 处理图片上传成功
  1996. const handleImageUpload = (response, file, sectionIndex) => {
  1997. // 这里假设上传成功后返回的response包含图片的URL
  1998. // 实际项目中需要根据后端API的返回格式进行调整
  1999. const imageUrl = response.url || URL.createObjectURL(file)
  2000. scriptData.sections[sectionIndex].backgroundImage.url = imageUrl
  2001. scriptData.sections[sectionIndex].backgroundImage.generating = false
  2002. ElMessage.success('图片上传成功!')
  2003. }
  2004. // 编辑图片
  2005. const editImage = (sectionIndex) => {
  2006. // 这里可以添加编辑图片的逻辑,比如打开图片编辑器
  2007. ElMessage.info('编辑图片功能待实现')
  2008. }
  2009. // 删除图片
  2010. const deleteImage = (sectionIndex) => {
  2011. scriptData.sections[sectionIndex].backgroundImage.url = ''
  2012. ElMessage.success('图片删除成功!')
  2013. }
  2014. // 步骤4:保存脚本
  2015. const saveScript = async () => {
  2016. validateScript()
  2017. if (!isValidationPassed.value) {
  2018. return
  2019. }
  2020. // 保存脚本后清除缓存
  2021. clearScriptDataCache()
  2022. emit('save', scriptData, [...replacedUrls.value])
  2023. emit('update:visible', false)
  2024. }
  2025. // 下一步操作
  2026. const nextStep = () => {
  2027. if (currentStep.value === 2) {
  2028. validateScript()
  2029. }
  2030. currentStep.value++
  2031. }
  2032. // 显示视频预览
  2033. const showVideoPreview = () => {
  2034. showVideoPreviewModal.value = true
  2035. }
  2036. // 关闭视频预览
  2037. const closeVideoPreview = () => {
  2038. showVideoPreviewModal.value = false
  2039. }
  2040. // 组件挂载时
  2041. onMounted(async () => {
  2042. // 设置初始步骤
  2043. currentStep.value = props.initialStep
  2044. try {
  2045. const params = {
  2046. pageOn: 1,
  2047. pageSize: 100,
  2048. category: '小学低年级',
  2049. publicStatus: true
  2050. }
  2051. const { list } = await ChatRoleApi.getMyPage(params)
  2052. params.category += 'AI'
  2053. const { list: listAi } = await ChatRoleApi.getMyPage(params)
  2054. params.category = '全部'
  2055. const { list: listAll } = await ChatRoleApi.getMyPage(params)
  2056. params.category = '全部-Poet'
  2057. const { list: listAllPoet } = await ChatRoleApi.getMyPage(params)
  2058. listAi.push(...list)
  2059. listAi.push(...listAll)
  2060. listAi.push(...listAllPoet)
  2061. digitalHumans.value = listAi
  2062. } catch (error) {
  2063. console.error('获取角色数据失败:', error)
  2064. }
  2065. inProgressTimer.value = setInterval(async () => {
  2066. await refreshWatchImages()
  2067. }, 3000)
  2068. inProgressVideoTimer.value = setInterval(async () => {
  2069. await refreshWatchVideos()
  2070. }, 3000)
  2071. })
  2072. // 关闭事件
  2073. const emit = defineEmits(['update:visible', 'save'])
  2074. const handleClose = () => {
  2075. emit('update:visible', false)
  2076. }
  2077. // 组件卸载时
  2078. onUnmounted(() => {
  2079. if (inProgressTimer.value) {
  2080. clearInterval(inProgressTimer.value)
  2081. }
  2082. if (inProgressVideoTimer.value) {
  2083. clearInterval(inProgressVideoTimer.value)
  2084. }
  2085. })
  2086. </script>
  2087. <style scoped>
  2088. .course-script-editor {
  2089. width: 100%;
  2090. height: 90vh;
  2091. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  2092. display: flex;
  2093. flex-direction: column;
  2094. overflow: hidden;
  2095. background-color: #f8f9fa;
  2096. }
  2097. /* 主容器样式 */
  2098. .main-container {
  2099. flex: 1;
  2100. display: flex;
  2101. overflow: hidden;
  2102. }
  2103. /* 左侧步骤指示器样式 */
  2104. .steps-sidebar {
  2105. width: 200px;
  2106. background-color: #f5f7fa;
  2107. border-right: 1px solid #ebeef5;
  2108. padding: 30px 0;
  2109. display: flex;
  2110. align-items: center;
  2111. }
  2112. /* 右侧内容区域样式 */
  2113. .content-area {
  2114. flex: 1;
  2115. display: flex;
  2116. flex-direction: column;
  2117. overflow: hidden;
  2118. }
  2119. /* 步骤内容样式 */
  2120. .step-content {
  2121. flex: 1;
  2122. padding: 20px;
  2123. overflow: hidden;
  2124. display: flex;
  2125. flex-direction: column;
  2126. background-color: white;
  2127. border-radius: 0;
  2128. box-shadow: none;
  2129. }
  2130. /* 步骤1垂直居中 */
  2131. .step-content:has(.ai-input-container) {
  2132. justify-content: center;
  2133. align-items: center;
  2134. }
  2135. /* 编辑器工具栏样式 - 固定顶部 */
  2136. .editor-toolbar.sticky-top {
  2137. position: sticky;
  2138. top: 0;
  2139. z-index: 100;
  2140. margin-top: -20px;
  2141. margin-left: -20px;
  2142. margin-right: -20px;
  2143. border-radius: 0;
  2144. border-bottom: 1px solid #ebeef5;
  2145. background: rgba(250, 250, 250, 0.95);
  2146. backdrop-filter: blur(10px);
  2147. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  2148. }
  2149. /* 脚本编辑器样式 - 可滚动 */
  2150. .script-editor {
  2151. flex: 1;
  2152. overflow-y: auto;
  2153. margin-top: 20px;
  2154. padding-right: 10px;
  2155. background-color: white;
  2156. border-radius: 8px;
  2157. padding: 20px;
  2158. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  2159. }
  2160. .script-editor::-webkit-scrollbar {
  2161. width: 6px;
  2162. }
  2163. .script-editor::-webkit-scrollbar-track {
  2164. background: #f1f1f1;
  2165. border-radius: 3px;
  2166. }
  2167. .script-editor::-webkit-scrollbar-thumb {
  2168. background: #c1c1c1;
  2169. border-radius: 3px;
  2170. }
  2171. /* 背景类型切换样式 */
  2172. .background-type-switch {
  2173. position: absolute;
  2174. top: -15px;
  2175. left: 10px;
  2176. z-index: 10;
  2177. }
  2178. /* 媒体控制区域样式调整 */
  2179. .media-controls {
  2180. position: relative;
  2181. margin-top: 30px;
  2182. padding-top: 40px; /* 为背景类型切换留出空间 */
  2183. height: 165px;
  2184. }
  2185. /* 视频预览样式 */
  2186. .media-preview video {
  2187. width: 100%;
  2188. max-height: 300px;
  2189. object-fit: cover;
  2190. border-radius: 4px;
  2191. }
  2192. /* 预览视频背景样式 */
  2193. .preview-section {
  2194. position: relative;
  2195. min-height: 400px;
  2196. margin-bottom: 20px;
  2197. border-radius: 8px;
  2198. overflow: hidden;
  2199. }
  2200. .preview-video {
  2201. position: absolute;
  2202. top: 0;
  2203. left: 0;
  2204. width: 100%;
  2205. height: 100%;
  2206. z-index: 0;
  2207. }
  2208. .preview-video video {
  2209. width: 100%;
  2210. height: 100%;
  2211. object-fit: cover;
  2212. }
  2213. .preview-section-content {
  2214. position: relative;
  2215. z-index: 1;
  2216. padding: 20px;
  2217. background: rgba(255, 255, 255, 0.8);
  2218. height: 100%;
  2219. display: flex;
  2220. flex-direction: column;
  2221. }
  2222. .script-editor::-webkit-scrollbar-thumb:hover {
  2223. background: #a1a1a1;
  2224. }
  2225. /* 步骤导航 */
  2226. .steps-container {
  2227. display: flex;
  2228. flex-direction: column;
  2229. align-items: center;
  2230. gap: 20px;
  2231. width: 100%;
  2232. .step-item {
  2233. display: flex;
  2234. flex-direction: column;
  2235. align-items: center;
  2236. width: 100%;
  2237. .step-circle {
  2238. width: 32px;
  2239. height: 32px;
  2240. border-radius: 50%;
  2241. display: flex;
  2242. align-items: center;
  2243. justify-content: center;
  2244. font-weight: bold;
  2245. margin-bottom: 8px;
  2246. }
  2247. .step-title {
  2248. font-size: 14px;
  2249. text-align: center;
  2250. padding: 0 20px;
  2251. }
  2252. &.process {
  2253. .step-circle {
  2254. background-color: #409eff;
  2255. color: white;
  2256. }
  2257. .step-title {
  2258. color: #409eff;
  2259. }
  2260. }
  2261. &.wait {
  2262. .step-circle {
  2263. background-color: #e4e7ed;
  2264. color: #c0c4cc;
  2265. }
  2266. .step-title {
  2267. color: #c0c4cc;
  2268. }
  2269. }
  2270. &.finish {
  2271. .step-circle {
  2272. background-color: #67c23a;
  2273. color: white;
  2274. }
  2275. .step-title {
  2276. color: #67c23a;
  2277. }
  2278. }
  2279. }
  2280. .step-line {
  2281. width: 2px;
  2282. height: 40px;
  2283. background-color: #e4e7ed;
  2284. &.active {
  2285. background-color: #409eff;
  2286. }
  2287. }
  2288. }
  2289. /* 步骤内容 */
  2290. .step-content {
  2291. background-color: white;
  2292. border-radius: 8px;
  2293. padding: 20px;
  2294. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  2295. }
  2296. /* 按钮组样式 */
  2297. .button-group {
  2298. display: flex;
  2299. gap: 10px;
  2300. margin-top: 20px;
  2301. justify-content: center;
  2302. }
  2303. /* 次要按钮样式 */
  2304. .generate-btn.secondary {
  2305. background-color: #606266;
  2306. color: white;
  2307. }
  2308. .generate-btn.secondary:hover {
  2309. background-color: #ffaa72;
  2310. color: white;
  2311. }
  2312. /* 对话类型标签 */
  2313. .dialogue-type-tag {
  2314. position: absolute;
  2315. top: -10px;
  2316. left: 10px;
  2317. padding: 2px 8px;
  2318. border-radius: 10px;
  2319. font-size: 12px;
  2320. font-weight: 500;
  2321. color: white;
  2322. }
  2323. /* 隐藏用户回复卡片 */
  2324. .dialogue-item.hidden {
  2325. display: none;
  2326. }
  2327. /* 错误信息项样式 */
  2328. .error-item {
  2329. margin-bottom: 8px;
  2330. line-height: 1.4;
  2331. }
  2332. .dialogue-type-tag.digital {
  2333. background-color: #409eff;
  2334. }
  2335. .dialogue-type-tag.user {
  2336. background-color: #67c23a;
  2337. }
  2338. .dialogue-type-tag.quest {
  2339. background-color: #e6a23c;
  2340. }
  2341. .dialogue-type-tag.poem {
  2342. background-color: #909399;
  2343. }
  2344. .dialogue-type-tag.video {
  2345. background-color: #8b4513;
  2346. }
  2347. /* 对话项样式 */
  2348. .dialogue-item {
  2349. position: relative;
  2350. background-color: #f9f9f9;
  2351. border-radius: 8px;
  2352. padding: 20px;
  2353. margin-bottom: 15px;
  2354. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  2355. transition: all 0.3s ease;
  2356. }
  2357. .dialogue-item:hover {
  2358. box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  2359. }
  2360. .dialogue-item.digital {
  2361. border-left: 4px solid #409eff;
  2362. }
  2363. .dialogue-item.user {
  2364. border-left: 4px solid #67c23a;
  2365. }
  2366. .dialogue-item.quest {
  2367. border-left: 4px solid #e6a23c;
  2368. }
  2369. .dialogue-item.video {
  2370. border-left: 4px solid #8b4513;
  2371. }
  2372. /* 对话头部 */
  2373. .dialogue-header {
  2374. margin-bottom: 10px;
  2375. }
  2376. /* 对话行 */
  2377. .dialogue-row {
  2378. display: flex;
  2379. gap: 15px;
  2380. align-items: flex-start;
  2381. }
  2382. /* 角色选择 */
  2383. .dialogue-role-select {
  2384. flex-shrink: 0;
  2385. }
  2386. /* 回复角色选择 */
  2387. .dialogue-reply-select {
  2388. flex-shrink: 0;
  2389. }
  2390. /* 内容容器 */
  2391. .dialogue-content-container {
  2392. flex: 1;
  2393. min-width: 0;
  2394. }
  2395. /* 添加对话按钮容器 */
  2396. .add-dialogue-buttons {
  2397. display: flex;
  2398. gap: 10px;
  2399. margin-top: 15px;
  2400. }
  2401. /* 添加对话按钮 */
  2402. .add-dialogue-btn {
  2403. padding: 8px 16px;
  2404. border: none;
  2405. border-radius: 4px;
  2406. font-size: 14px;
  2407. font-weight: 500;
  2408. cursor: pointer;
  2409. transition: all 0.3s ease;
  2410. display: flex;
  2411. align-items: center;
  2412. justify-content: center;
  2413. gap: 5px;
  2414. min-width: 120px;
  2415. }
  2416. .add-dialogue-btn.digital {
  2417. background-color: #83c2ff;
  2418. color: white;
  2419. }
  2420. .add-dialogue-btn.digital:hover {
  2421. background-color: #409eff;
  2422. border-color: #4aa2fd;
  2423. color: white;
  2424. }
  2425. .add-dialogue-btn.user {
  2426. background-color: #85ce61;
  2427. color: white;
  2428. }
  2429. .add-dialogue-btn.quest {
  2430. background-color: #e6a23c;
  2431. color: white;
  2432. }
  2433. .add-dialogue-btn.poem {
  2434. background-color: #909399;
  2435. color: white;
  2436. }
  2437. .add-dialogue-btn.quest-user {
  2438. background-color: #e6a23c;
  2439. color: white;
  2440. }
  2441. .add-dialogue-btn.user:hover {
  2442. background-color: #67c23a;
  2443. border-color: #67c23a;
  2444. color: white;
  2445. }
  2446. .add-dialogue-btn.quest:hover {
  2447. background-color: #cf9236;
  2448. border-color: #cf9236;
  2449. color: white;
  2450. }
  2451. .add-dialogue-btn.quest-user:hover {
  2452. background-color: #cf9236;
  2453. border-color: #cf9236;
  2454. color: white;
  2455. }
  2456. .add-dialogue-btn.poem:hover {
  2457. background-color: #73767a;
  2458. border-color: #73767a;
  2459. }
  2460. /* 上传相关样式 */
  2461. .upload-container {
  2462. margin-top: 10px;
  2463. display: inline-block;
  2464. }
  2465. .media-upload-placeholder {
  2466. display: flex;
  2467. flex-direction: column;
  2468. align-items: center;
  2469. justify-content: center;
  2470. padding: 40px 20px;
  2471. border: 2px dashed #d9d9d9;
  2472. border-radius: 8px;
  2473. margin-top: 10px;
  2474. background-color: #fafafa;
  2475. }
  2476. .upload-icon {
  2477. font-size: 48px;
  2478. margin-bottom: 16px;
  2479. }
  2480. .upload-text {
  2481. margin-bottom: 16px;
  2482. color: #999;
  2483. }
  2484. .upload-btn {
  2485. margin-left: 10px;
  2486. }
  2487. .upload-btn-full {
  2488. width: 100%;
  2489. }
  2490. .media-preview {
  2491. position: relative;
  2492. margin-top: 10px;
  2493. border-radius: 8px;
  2494. overflow: hidden;
  2495. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  2496. }
  2497. .media-preview img,
  2498. .media-preview video {
  2499. width: 100%;
  2500. max-height: 300px;
  2501. object-fit: cover;
  2502. }
  2503. .media-preview .preview-actions {
  2504. position: absolute;
  2505. bottom: 0;
  2506. left: 0;
  2507. right: 0;
  2508. background: rgba(0, 0, 0, 0.6);
  2509. padding: 10px;
  2510. display: flex;
  2511. justify-content: flex-end;
  2512. margin-top: 0;
  2513. }
  2514. .media-preview .preview-actions button {
  2515. color: white;
  2516. margin-left: 10px;
  2517. }
  2518. .media-preview .preview-actions button:hover {
  2519. color: #409eff;
  2520. }
  2521. .add-dialogue-btn.video {
  2522. background-color: #8b4513;
  2523. color: white;
  2524. }
  2525. .add-dialogue-btn.video:hover {
  2526. background-color: #a0522d;
  2527. border-color: #a0522d;
  2528. color: white;
  2529. }
  2530. /* 预览对话样式 */
  2531. .preview-dialogue {
  2532. position: relative;
  2533. margin-bottom: 20px;
  2534. padding: 15px;
  2535. border-radius: 8px;
  2536. background-color: #f9f9f9;
  2537. }
  2538. .preview-dialogue.digital {
  2539. border-left: 4px solid #409eff;
  2540. }
  2541. .preview-dialogue.user {
  2542. border-left: 4px solid #67c23a;
  2543. }
  2544. .preview-dialogue.quest {
  2545. border-left: 4px solid #e6a23c;
  2546. }
  2547. .preview-dialogue.poem {
  2548. border-left: 4px solid #909399;
  2549. }
  2550. .preview-dialogue.video {
  2551. border-left: 4px solid #8b4513;
  2552. }
  2553. .preview-dialogue .dialogue-header {
  2554. display: flex;
  2555. align-items: center;
  2556. justify-content: space-between;
  2557. gap: 0;
  2558. margin-bottom: 10px;
  2559. }
  2560. .preview-dialogue .dialogue-header-left {
  2561. display: flex;
  2562. align-items: center;
  2563. gap: 2px;
  2564. }
  2565. .preview-dialogue .dialogue-type-tag {
  2566. position: static;
  2567. margin-right: 2px;
  2568. }
  2569. /* 回复信息 */
  2570. .reply-info {
  2571. margin-top: 10px;
  2572. padding-top: 10px;
  2573. border-top: 1px solid #e8e8e8;
  2574. font-size: 14px;
  2575. color: #666;
  2576. font-style: italic;
  2577. }
  2578. /* AI输入容器 */
  2579. .ai-input-container {
  2580. max-width: 800px;
  2581. margin: 0 auto;
  2582. padding: 30px;
  2583. background: white;
  2584. border-radius: 16px;
  2585. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  2586. display: flex;
  2587. flex-direction: column;
  2588. min-height: 500px;
  2589. }
  2590. .selection-group {
  2591. margin-bottom: 30px;
  2592. }
  2593. .ai-input-wrapper {
  2594. margin-bottom: 30px;
  2595. }
  2596. .ai-input-container .button-group {
  2597. display: flex;
  2598. gap: 10px;
  2599. margin-top: 30px;
  2600. justify-content: center;
  2601. }
  2602. .ai-input-container .button-group button {
  2603. flex: 1;
  2604. min-width: 200px;
  2605. text-align: center;
  2606. }
  2607. .ai-input-wrapper {
  2608. position: relative;
  2609. margin-bottom: 30px;
  2610. }
  2611. .ai-icon {
  2612. position: absolute;
  2613. top: 20px;
  2614. left: 20px;
  2615. font-size: 28px;
  2616. color: #409eff;
  2617. background: rgba(64, 158, 255, 0.1);
  2618. width: 48px;
  2619. height: 48px;
  2620. border-radius: 12px;
  2621. display: flex;
  2622. align-items: center;
  2623. justify-content: center;
  2624. animation: pulse 2s infinite;
  2625. }
  2626. @keyframes pulse {
  2627. 0% {
  2628. box-shadow: 0 0 0 0 rgba(64, 158, 255, 0.4);
  2629. }
  2630. 70% {
  2631. box-shadow: 0 0 0 10px rgba(64, 158, 255, 0);
  2632. }
  2633. 100% {
  2634. box-shadow: 0 0 0 0 rgba(64, 158, 255, 0);
  2635. }
  2636. }
  2637. .ai-textarea {
  2638. width: 100%;
  2639. min-height: 140px;
  2640. padding: 24px 24px 24px 84px;
  2641. border: 2px solid #e8e8e8;
  2642. border-radius: 16px;
  2643. font-size: 16px;
  2644. resize: vertical;
  2645. transition: all 0.3s ease;
  2646. background: #fafafa;
  2647. line-height: 1.6;
  2648. }
  2649. .ai-textarea:focus {
  2650. outline: none;
  2651. border-color: #409eff;
  2652. background: white;
  2653. box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
  2654. }
  2655. .selection-group {
  2656. display: grid;
  2657. grid-template-columns: 1fr 1fr;
  2658. gap: 24px;
  2659. margin-bottom: 30px;
  2660. }
  2661. .selection-item {
  2662. display: flex;
  2663. flex-direction: column;
  2664. gap: 10px;
  2665. }
  2666. .selection-item label {
  2667. font-weight: 600;
  2668. color: #333;
  2669. font-size: 14px;
  2670. text-transform: uppercase;
  2671. letter-spacing: 0.5px;
  2672. color: #666;
  2673. }
  2674. .selection-item select {
  2675. padding: 14px 16px;
  2676. border: 2px solid #e8e8e8;
  2677. border-radius: 10px;
  2678. font-size: 14px;
  2679. transition: all 0.3s ease;
  2680. background: white;
  2681. }
  2682. .selection-item select:focus {
  2683. outline: none;
  2684. border-color: #409eff;
  2685. box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
  2686. }
  2687. .multi-select {
  2688. display: flex;
  2689. flex-wrap: wrap;
  2690. gap: 10px;
  2691. padding: 12px;
  2692. border: 2px solid #e8e8e8;
  2693. border-radius: 10px;
  2694. background: white;
  2695. transition: all 0.3s ease;
  2696. }
  2697. .multi-select:focus-within {
  2698. border-color: #409eff;
  2699. box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
  2700. }
  2701. .select-option {
  2702. padding: 8px 16px;
  2703. background: #f5f5f5;
  2704. border-radius: 20px;
  2705. cursor: pointer;
  2706. transition: all 0.2s ease;
  2707. font-size: 14px;
  2708. font-weight: 500;
  2709. border: 1px solid transparent;
  2710. }
  2711. .select-option:hover {
  2712. background: #e6f7ff;
  2713. border-color: #91d5ff;
  2714. }
  2715. .select-option.selected {
  2716. background: #409eff;
  2717. color: white;
  2718. border-color: #409eff;
  2719. box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
  2720. }
  2721. /* 加载遮挡层样式 */
  2722. .loading-overlay {
  2723. position: fixed;
  2724. top: 0;
  2725. left: 0;
  2726. width: 100%;
  2727. height: 100%;
  2728. background-color: rgba(0, 0, 0, 0.1);
  2729. display: flex;
  2730. align-items: center;
  2731. justify-content: center;
  2732. z-index: 9999;
  2733. pointer-events: auto;
  2734. }
  2735. .loading-content {
  2736. display: flex;
  2737. flex-direction: column;
  2738. align-items: center;
  2739. gap: 16px;
  2740. background: white;
  2741. padding: 32px;
  2742. border-radius: 12px;
  2743. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  2744. pointer-events: auto;
  2745. }
  2746. .loading-spinner {
  2747. width: 48px;
  2748. height: 48px;
  2749. border: 4px solid #f3f3f3;
  2750. border-top: 4px solid #409eff;
  2751. border-radius: 50%;
  2752. animation: spin 1s linear infinite;
  2753. }
  2754. @keyframes spin {
  2755. 0% {
  2756. transform: rotate(0deg);
  2757. }
  2758. 100% {
  2759. transform: rotate(360deg);
  2760. }
  2761. }
  2762. .loading-text {
  2763. font-size: 16px;
  2764. font-weight: 500;
  2765. color: #333;
  2766. }
  2767. /* 按钮样式 */
  2768. .generate-btn {
  2769. padding: 14px 8px;
  2770. border: none;
  2771. border-radius: 8px;
  2772. font-size: 14px;
  2773. font-weight: 400;
  2774. cursor: pointer;
  2775. transition: all 0.3s ease;
  2776. position: relative;
  2777. overflow: hidden;
  2778. }
  2779. .generate-btn.primary {
  2780. background: linear-gradient(135deg, #409eff, #1890ff);
  2781. color: white;
  2782. box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
  2783. }
  2784. .generate-btn.primary:hover {
  2785. transform: translateY(-2px);
  2786. box-shadow: 0 6px 16px rgba(64, 158, 255, 0.4);
  2787. }
  2788. .generate-btn.primary:disabled {
  2789. background: #91c5f7;
  2790. cursor: not-allowed;
  2791. transform: none;
  2792. box-shadow: none;
  2793. }
  2794. .generate-btn.small {
  2795. padding: 8px 16px;
  2796. font-size: 14px;
  2797. border-radius: 8px;
  2798. }
  2799. .generate-btn.small:hover {
  2800. transform: translateY(-1px);
  2801. box-shadow: 0 3px 8px rgba(64, 158, 255, 0.3);
  2802. }
  2803. .generate-btn.small:disabled {
  2804. background: #91c5f7;
  2805. color: white;
  2806. cursor: not-allowed;
  2807. transform: none;
  2808. box-shadow: none;
  2809. }
  2810. .toolbar-btn:disabled {
  2811. background: #f0f0f0;
  2812. color: #c0c0c0;
  2813. border-color: #e0e0e0;
  2814. cursor: not-allowed;
  2815. transform: none;
  2816. box-shadow: none;
  2817. }
  2818. .toolbar-btn:disabled:hover {
  2819. background: #f0f0f0;
  2820. color: #c0c0c0;
  2821. border-color: #e0e0e0;
  2822. transform: none;
  2823. box-shadow: none;
  2824. }
  2825. /* 编辑器工具栏 */
  2826. .editor-toolbar {
  2827. position: sticky;
  2828. top: 20px;
  2829. z-index: 100;
  2830. margin-bottom: 30px;
  2831. padding: 16px 20px;
  2832. background: rgba(250, 250, 250, 0.95);
  2833. backdrop-filter: blur(10px);
  2834. border-radius: 12px;
  2835. border: 1px solid #e8e8e8;
  2836. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  2837. overflow-x: auto;
  2838. overflow-y: hidden;
  2839. white-space: nowrap;
  2840. }
  2841. .editor-toolbar::-webkit-scrollbar {
  2842. height: 4px;
  2843. }
  2844. .editor-toolbar::-webkit-scrollbar-track {
  2845. background: #f1f1f1;
  2846. border-radius: 2px;
  2847. }
  2848. .editor-toolbar::-webkit-scrollbar-thumb {
  2849. background: #c1c1c1;
  2850. border-radius: 2px;
  2851. }
  2852. .editor-toolbar::-webkit-scrollbar-thumb:hover {
  2853. background: #a1a1a1;
  2854. }
  2855. .toolbar-btn {
  2856. padding: 12px 24px;
  2857. margin: 0 12px;
  2858. background: white;
  2859. border: 2px solid #e8e8e8;
  2860. border-radius: 10px;
  2861. cursor: pointer;
  2862. transition: all 0.3s ease;
  2863. font-weight: 500;
  2864. color: #333;
  2865. }
  2866. .toolbar-btn:hover {
  2867. background: #409eff;
  2868. color: white;
  2869. border-color: #409eff;
  2870. transform: translateY(-1px);
  2871. box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
  2872. }
  2873. /* 脚本编辑器 */
  2874. .script-section {
  2875. margin-top: 40px;
  2876. margin-bottom: 40px;
  2877. padding: 5px 24px 24px;
  2878. background: white;
  2879. border-radius: 16px;
  2880. position: relative;
  2881. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  2882. border: 1px solid #f0f0f0;
  2883. }
  2884. .section-header {
  2885. margin-bottom: 24px;
  2886. display: flex;
  2887. align-items: center;
  2888. gap: 16px;
  2889. }
  2890. .section-name-container {
  2891. display: flex;
  2892. align-items: center;
  2893. flex: 1;
  2894. gap: 12px;
  2895. margin-top: 16px;
  2896. }
  2897. .remove-section-btn {
  2898. background: #ff4d4f;
  2899. border: none;
  2900. color: white;
  2901. font-size: 16px;
  2902. cursor: pointer;
  2903. padding: 0;
  2904. width: 28px;
  2905. height: 28px;
  2906. display: flex;
  2907. align-items: center;
  2908. justify-content: center;
  2909. border-radius: 6px;
  2910. transition: all 0.3s ease;
  2911. flex-shrink: 0;
  2912. }
  2913. .remove-section-btn:hover {
  2914. background: #ff7875;
  2915. transform: scale(1.1);
  2916. box-shadow: 0 2px 8px rgba(255, 77, 79, 0.3);
  2917. }
  2918. .section-name-label {
  2919. padding: 2px 15px;
  2920. border-radius: 10px;
  2921. font-size: 18px;
  2922. font-weight: 500;
  2923. color: white;
  2924. background-color: #c18484;
  2925. white-space: nowrap;
  2926. display: flex;
  2927. align-items: center;
  2928. height: 44px;
  2929. box-sizing: border-box;
  2930. }
  2931. .section-title {
  2932. flex: 1;
  2933. padding: 14px 16px;
  2934. border: 2px solid #e8e8e8;
  2935. border-radius: 10px;
  2936. font-size: 16px;
  2937. font-weight: 500;
  2938. transition: all 0.3s ease;
  2939. }
  2940. .section-title:focus {
  2941. outline: none;
  2942. border-color: #409eff;
  2943. box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
  2944. }
  2945. .media-controls {
  2946. display: flex;
  2947. background: linear-gradient(135deg, #f8f9fa, #ffffff);
  2948. padding: 16px 20px;
  2949. border-radius: 10px;
  2950. border: 1px solid #e8e8e8;
  2951. align-items: center;
  2952. justify-content: space-between;
  2953. }
  2954. .media-item {
  2955. display: flex;
  2956. align-items: center;
  2957. gap: 10px;
  2958. min-height: 50px;
  2959. }
  2960. .media-input-group {
  2961. display: flex;
  2962. align-items: center;
  2963. gap: 10px;
  2964. }
  2965. .media-label {
  2966. font-size: 14px;
  2967. font-weight: 600;
  2968. white-space: nowrap;
  2969. color: #666;
  2970. }
  2971. .media-prompt {
  2972. font-size: 14px;
  2973. transition: all 0.3s ease;
  2974. width: 300px;
  2975. }
  2976. .media-prompt-video{
  2977. font-size: 14px;
  2978. transition: all 0.3s ease;
  2979. width: 500px;
  2980. }
  2981. /* 视频对话样式 */
  2982. .dialogue-item.video .dialogue-row {
  2983. justify-content: center;
  2984. }
  2985. .dialogue-item.video .media-item {
  2986. display: flex;
  2987. flex-direction: column;
  2988. align-items: center;
  2989. width: 100%;
  2990. max-width: 900px;
  2991. }
  2992. .dialogue-item.video .media-input-group {
  2993. display: flex;
  2994. align-items: center;
  2995. justify-content: center;
  2996. width: 100%;
  2997. gap: 15px;
  2998. }
  2999. .dialogue-item.video .media-label {
  3000. white-space: nowrap;
  3001. margin-bottom: 0;
  3002. }
  3003. .dialogue-item.video .media-prompt-video {
  3004. flex: 1;
  3005. min-width: 300px;
  3006. max-width: 600px;
  3007. }
  3008. .dialogue-item.video .media-prompt-video .el-textarea {
  3009. min-height: 40px;
  3010. }
  3011. .dialogue-item.video .media-prompt-video .el-textarea__inner {
  3012. min-height: 40px;
  3013. padding: 6px 12px;
  3014. }
  3015. .dialogue-item.video .media-preview {
  3016. flex: 0 0 200px;
  3017. margin: 5px 0;
  3018. }
  3019. .dialogue-item.video .media-preview video {
  3020. width: 100%;
  3021. max-height: 120px;
  3022. object-fit: cover;
  3023. border-radius: 4px;
  3024. }
  3025. .dialogue-item.video .generate-btn {
  3026. min-width: 80px;
  3027. white-space: nowrap;
  3028. }
  3029. .dialogue-item.video .remove-btn {
  3030. margin-left: 10px;
  3031. }
  3032. .media-prompt .el-textarea {
  3033. width: 100%;
  3034. min-height: 60px;
  3035. }
  3036. .media-prompt .el-textarea__inner {
  3037. padding: 8px 12px;
  3038. border: 2px solid #e8e8e8;
  3039. border-radius: 8px;
  3040. font-size: 14px;
  3041. transition: all 0.3s ease;
  3042. min-height: 60px;
  3043. resize: none;
  3044. }
  3045. .media-prompt .el-textarea__inner:focus {
  3046. outline: none;
  3047. border-color: #409eff;
  3048. box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
  3049. }
  3050. .media-preview {
  3051. margin-left: 20px;
  3052. }
  3053. .media-preview img {
  3054. max-width: 180px;
  3055. border-radius: 8px;
  3056. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  3057. transition: transform 0.3s ease;
  3058. }
  3059. .media-preview img:hover {
  3060. transform: scale(1.05);
  3061. }
  3062. .dialogues-container {
  3063. margin-top: 48px;
  3064. }
  3065. .dialogue-item {
  3066. margin-bottom: 20px;
  3067. padding: 20px;
  3068. background: #fafafa;
  3069. border-radius: 12px;
  3070. border: 1px solid #e8e8e8;
  3071. transition: all 0.3s ease;
  3072. }
  3073. .dialogue-item:hover {
  3074. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  3075. transform: translateY(-2px);
  3076. }
  3077. .dialogue-row {
  3078. display: flex;
  3079. align-items: flex-start;
  3080. gap: 16px;
  3081. }
  3082. .dialogue-role-select {
  3083. min-width: 140px;
  3084. }
  3085. .dialogue-role-select select {
  3086. width: 100%;
  3087. padding: 10px 12px;
  3088. border: 2px solid #e8e8e8;
  3089. border-radius: 8px;
  3090. font-size: 14px;
  3091. transition: all 0.3s ease;
  3092. }
  3093. .dialogue-role-select select:focus {
  3094. outline: none;
  3095. border-color: #409eff;
  3096. box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
  3097. }
  3098. .dialogue-content-container {
  3099. flex: 1;
  3100. }
  3101. .dialogue-content:focus {
  3102. outline: none;
  3103. border-color: #409eff;
  3104. box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
  3105. }
  3106. /* 提问类型选择 */
  3107. .question-type-select {
  3108. display: flex;
  3109. align-items: center;
  3110. gap: 10px;
  3111. margin-bottom: 12px;
  3112. }
  3113. .question-type-label {
  3114. font-size: 14px;
  3115. font-weight: 600;
  3116. color: #666;
  3117. }
  3118. /* 单选题选项 */
  3119. .single-choice-options {
  3120. margin-top: 16px;
  3121. padding: 16px;
  3122. background: #f8f9fa;
  3123. border-radius: 8px;
  3124. border: 1px solid #e8e8e8;
  3125. }
  3126. .options-header {
  3127. display: flex;
  3128. align-items: center;
  3129. justify-content: space-between;
  3130. margin-bottom: 12px;
  3131. }
  3132. .options-label {
  3133. font-size: 14px;
  3134. font-weight: 600;
  3135. color: #666;
  3136. }
  3137. .add-option-btn {
  3138. padding: 6px 12px;
  3139. background: #409eff;
  3140. color: white;
  3141. border: none;
  3142. border-radius: 4px;
  3143. font-size: 12px;
  3144. cursor: pointer;
  3145. transition: all 0.2s ease;
  3146. }
  3147. .add-option-btn:hover {
  3148. background: #66b1ff;
  3149. }
  3150. .option-item {
  3151. display: flex;
  3152. align-items: center;
  3153. gap: 10px;
  3154. margin-bottom: 10px;
  3155. }
  3156. .option-item:last-child {
  3157. margin-bottom: 0;
  3158. }
  3159. .option-label {
  3160. font-weight: 600;
  3161. color: #409eff;
  3162. width: 20px;
  3163. text-align: center;
  3164. flex-shrink: 0;
  3165. }
  3166. .answer-radio-wrapper {
  3167. width: 60px;
  3168. flex-shrink: 0;
  3169. display: flex;
  3170. align-items: center;
  3171. gap: 4px;
  3172. }
  3173. .remove-option-btn {
  3174. flex-shrink: 0;
  3175. background: #ff4d4f;
  3176. border: none;
  3177. color: white;
  3178. font-size: 14px;
  3179. cursor: pointer;
  3180. padding: 0;
  3181. width: 24px;
  3182. height: 24px;
  3183. display: flex;
  3184. align-items: center;
  3185. justify-content: center;
  3186. border-radius: 4px;
  3187. transition: all 0.2s ease;
  3188. }
  3189. .remove-option-btn:hover {
  3190. background: #ff7875;
  3191. }
  3192. /* 答案单选框包装器 */
  3193. .answer-radio-wrapper {
  3194. display: flex;
  3195. align-items: center;
  3196. gap: 4px;
  3197. }
  3198. /* 正确答案标记 */
  3199. .correct-mark {
  3200. color: #52c41a;
  3201. font-size: 18px;
  3202. font-weight: bold;
  3203. animation: fadeIn 0.2s ease;
  3204. }
  3205. /* 调整单选框右外边距 */
  3206. :deep(.el-radio) {
  3207. margin-right: 10px;
  3208. }
  3209. @keyframes fadeIn {
  3210. from {
  3211. opacity: 0;
  3212. transform: scale(0.5);
  3213. }
  3214. to {
  3215. opacity: 1;
  3216. transform: scale(1);
  3217. }
  3218. }
  3219. .remove-btn {
  3220. background: #ff4d4f;
  3221. border: none;
  3222. color: white;
  3223. font-size: 16px;
  3224. cursor: pointer;
  3225. padding: 0;
  3226. width: 28px;
  3227. height: 28px;
  3228. display: flex;
  3229. align-items: center;
  3230. justify-content: center;
  3231. border-radius: 6px;
  3232. transition: all 0.3s ease;
  3233. flex-shrink: 0;
  3234. }
  3235. .remove-btn:hover {
  3236. background: #ff7875;
  3237. transform: scale(1.1);
  3238. box-shadow: 0 2px 8px rgba(255, 77, 79, 0.3);
  3239. }
  3240. .dialogue-header {
  3241. display: flex;
  3242. justify-content: space-between;
  3243. align-items: center;
  3244. margin-bottom: 8px;
  3245. }
  3246. .dialogue-text {
  3247. flex: 1;
  3248. width: 100%;
  3249. font-size: 16px;
  3250. line-height: 1.6;
  3251. }
  3252. .generate-btn.small {
  3253. padding: 8px;
  3254. background: linear-gradient(135deg, #409eff, #1890ff);
  3255. color: white;
  3256. border: none;
  3257. border-radius: 6px;
  3258. cursor: pointer;
  3259. transition: all 0.3s ease;
  3260. display: flex;
  3261. align-items: center;
  3262. justify-content: center;
  3263. height: 28px;
  3264. font-size: 14px;
  3265. }
  3266. .generate-btn.small:hover {
  3267. transform: scale(1.1);
  3268. box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
  3269. }
  3270. .play-btn {
  3271. padding: 8px;
  3272. background: #52c41a;
  3273. color: white;
  3274. border: none;
  3275. border-radius: 6px;
  3276. cursor: pointer;
  3277. transition: all 0.3s ease;
  3278. display: flex;
  3279. align-items: center;
  3280. justify-content: center;
  3281. width: 28px;
  3282. height: 28px;
  3283. font-size: 14px;
  3284. }
  3285. .play-btn:hover {
  3286. background: #73d13d;
  3287. transform: scale(1.1);
  3288. box-shadow: 0 2px 8px rgba(82, 196, 26, 0.3);
  3289. }
  3290. .play-btn.small {
  3291. padding: 8px;
  3292. width: 28px;
  3293. height: 28px;
  3294. font-size: 14px;
  3295. }
  3296. .voice-icon {
  3297. font-size: 14px;
  3298. line-height: 1;
  3299. }
  3300. .play-icon {
  3301. font-size: 14px;
  3302. line-height: 1;
  3303. }
  3304. .action-buttons {
  3305. display: flex;
  3306. flex-direction: column;
  3307. gap: 8px;
  3308. margin-left: 8px;
  3309. }
  3310. .action-buttons-row {
  3311. display: flex;
  3312. gap: 8px;
  3313. align-items: center;
  3314. justify-content: flex-end;
  3315. }
  3316. .add-dialogue-btn,
  3317. .add-section-btn {
  3318. padding: 12px 24px;
  3319. background: white;
  3320. border: 2px dashed #d9d9d9;
  3321. border-radius: 10px;
  3322. cursor: pointer;
  3323. transition: all 0.3s ease;
  3324. font-weight: 500;
  3325. color: #666;
  3326. margin-top: 16px;
  3327. width: 100%;
  3328. text-align: center;
  3329. }
  3330. .add-dialogue-btn:hover,
  3331. .add-section-btn:hover {
  3332. border-color: #c18484;
  3333. color: white;
  3334. background: rgba(193, 132, 132, 0.6);
  3335. transform: translateY(-1px);
  3336. box-shadow: 0 4px 12px rgba(64, 158, 255, 0.15);
  3337. }
  3338. /* 预览页面 */
  3339. .preview-container {
  3340. width: 100%;
  3341. height: 100%;
  3342. background: white;
  3343. border-radius: 16px;
  3344. padding: 30px;
  3345. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  3346. display: flex;
  3347. flex-direction: column;
  3348. }
  3349. .scrollable-content {
  3350. flex: 1;
  3351. overflow-y: auto;
  3352. margin-bottom: 20px;
  3353. padding-right: 10px;
  3354. }
  3355. .scrollable-content::-webkit-scrollbar {
  3356. width: 6px;
  3357. }
  3358. .scrollable-content::-webkit-scrollbar-track {
  3359. background: #f1f1f1;
  3360. border-radius: 3px;
  3361. }
  3362. .scrollable-content::-webkit-scrollbar-thumb {
  3363. background: #c1c1c1;
  3364. border-radius: 3px;
  3365. }
  3366. .scrollable-content::-webkit-scrollbar-thumb:hover {
  3367. background: #a1a1a1;
  3368. }
  3369. .preview-content {
  3370. margin-top: 20px;
  3371. margin-bottom: 30px;
  3372. }
  3373. .preview-actions {
  3374. margin-top: auto;
  3375. display: flex;
  3376. justify-content: flex-end;
  3377. gap: 12px;
  3378. }
  3379. .validation-result {
  3380. padding: 16px 20px;
  3381. border-radius: 10px;
  3382. font-weight: 500;
  3383. font-size: 14px;
  3384. }
  3385. .validation-result.valid {
  3386. background: #f6ffed;
  3387. border: 2px solid #b7eb8f;
  3388. color: #52c41a;
  3389. box-shadow: 0 2px 8px rgba(82, 196, 26, 0.1);
  3390. }
  3391. .validation-result.invalid {
  3392. background: #fff2f0;
  3393. border: 2px solid #ffccc7;
  3394. color: #ff4d4f;
  3395. box-shadow: 0 2px 8px rgba(255, 77, 79, 0.1);
  3396. }
  3397. .preview-section {
  3398. margin-bottom: 40px;
  3399. padding: 40px;
  3400. border-radius: 12px;
  3401. border: 1px solid #e8e8e8;
  3402. min-height: 300px;
  3403. display: flex;
  3404. align-items: center;
  3405. justify-content: center;
  3406. }
  3407. .preview-section h4 {
  3408. margin-top: 0;
  3409. color: #333;
  3410. font-size: 18px;
  3411. font-weight: 600;
  3412. margin-bottom: 20px;
  3413. }
  3414. .preview-section-content {
  3415. background: rgba(255, 255, 255, 0.2);
  3416. padding: 20px;
  3417. border-radius: 12px;
  3418. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  3419. backdrop-filter: blur(5px);
  3420. width: 80%;
  3421. }
  3422. .preview-media {
  3423. margin: 20px 0;
  3424. padding: 16px;
  3425. background: rgba(255, 255, 255, 0.8);
  3426. border-radius: 10px;
  3427. border: 1px solid #e8e8e8;
  3428. display: flex;
  3429. align-items: center;
  3430. justify-content: space-between;
  3431. flex-wrap: wrap;
  3432. }
  3433. .preview-media-left {
  3434. display: flex;
  3435. align-items: center;
  3436. gap: 12px;
  3437. }
  3438. .preview-media-right {
  3439. display: flex;
  3440. align-items: center;
  3441. gap: 12px;
  3442. }
  3443. .preview-image img {
  3444. max-width: 250px;
  3445. border-radius: 8px;
  3446. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  3447. transition: transform 0.3s ease;
  3448. }
  3449. .preview-image img:hover {
  3450. transform: scale(1.05);
  3451. }
  3452. .preview-audio {
  3453. float: right;
  3454. margin-right: 20px;
  3455. display: flex;
  3456. align-items: center;
  3457. gap: 8px;
  3458. }
  3459. .preview-dialogue {
  3460. margin-bottom: 20px;
  3461. padding: 16px;
  3462. background: white;
  3463. border-radius: 10px;
  3464. border: 1px solid #e8e8e8;
  3465. transition: all 0.3s ease;
  3466. }
  3467. .dialogue-header {
  3468. display: flex;
  3469. justify-content: space-between;
  3470. align-items: center;
  3471. margin-bottom: 8px;
  3472. }
  3473. .preview-dialogue:hover {
  3474. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  3475. }
  3476. .dialogue-role {
  3477. font-weight: 600;
  3478. color: #409eff;
  3479. font-size: 14px;
  3480. }
  3481. .dialogue-text {
  3482. line-height: 1.6;
  3483. font-size: 14px;
  3484. color: #333;
  3485. }
  3486. /* Markdown 样式 */
  3487. .dialogue-text h1,
  3488. .dialogue-text h2,
  3489. .dialogue-text h3,
  3490. .dialogue-text h4,
  3491. .dialogue-text h5,
  3492. .dialogue-text h6 {
  3493. margin: 16px 0 8px 0;
  3494. font-weight: 600;
  3495. line-height: 1.2;
  3496. }
  3497. .dialogue-text h1 {
  3498. font-size: 24px;
  3499. }
  3500. .dialogue-text h2 {
  3501. font-size: 20px;
  3502. }
  3503. .dialogue-text h3 {
  3504. font-size: 18px;
  3505. }
  3506. .dialogue-text h4 {
  3507. font-size: 16px;
  3508. }
  3509. .dialogue-text h5 {
  3510. font-size: 14px;
  3511. }
  3512. .dialogue-text h6 {
  3513. font-size: 12px;
  3514. }
  3515. .dialogue-text p {
  3516. margin: 8px 0;
  3517. }
  3518. .dialogue-text ul,
  3519. .dialogue-text ol {
  3520. margin: 8px 0;
  3521. padding-left: 24px;
  3522. }
  3523. .dialogue-text li {
  3524. margin: 4px 0;
  3525. }
  3526. .dialogue-text strong {
  3527. font-weight: 600;
  3528. }
  3529. .dialogue-text em {
  3530. font-style: italic;
  3531. }
  3532. .dialogue-text a {
  3533. color: #409eff;
  3534. text-decoration: none;
  3535. }
  3536. .dialogue-text a:hover {
  3537. text-decoration: underline;
  3538. }
  3539. .dialogue-text code {
  3540. background: #f5f5f5;
  3541. padding: 2px 4px;
  3542. border-radius: 4px;
  3543. font-family: 'Courier New', Courier, monospace;
  3544. font-size: 14px;
  3545. }
  3546. .dialogue-text pre {
  3547. background: #f5f5f5;
  3548. padding: 12px;
  3549. border-radius: 8px;
  3550. overflow-x: auto;
  3551. margin: 12px 0;
  3552. }
  3553. .dialogue-text pre code {
  3554. background: none;
  3555. padding: 0;
  3556. }
  3557. .voiceover-preview {
  3558. margin-top: 12px;
  3559. padding-top: 12px;
  3560. border-top: 1px solid #f0f0f0;
  3561. }
  3562. .preview-actions {
  3563. display: flex;
  3564. justify-content: center;
  3565. gap: 20px;
  3566. padding-top: 24px;
  3567. border-top: 1px solid #e8e8e8;
  3568. }
  3569. .primary-btn,
  3570. .secondary-btn {
  3571. padding: 14px 32px;
  3572. border: none;
  3573. border-radius: 12px;
  3574. font-size: 16px;
  3575. font-weight: 600;
  3576. cursor: pointer;
  3577. transition: all 0.3s ease;
  3578. position: relative;
  3579. overflow: hidden;
  3580. }
  3581. .primary-btn {
  3582. background: linear-gradient(135deg, #409eff, #1890ff);
  3583. color: white;
  3584. box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
  3585. }
  3586. .primary-btn:hover {
  3587. transform: translateY(-2px);
  3588. box-shadow: 0 6px 16px rgba(64, 158, 255, 0.4);
  3589. }
  3590. .primary-btn:disabled {
  3591. background: #91c5f7;
  3592. cursor: not-allowed;
  3593. transform: none;
  3594. box-shadow: none;
  3595. }
  3596. .secondary-btn {
  3597. background: white;
  3598. color: #333;
  3599. border: 2px solid #e8e8e8;
  3600. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  3601. }
  3602. .secondary-btn:hover {
  3603. background: #fafafa;
  3604. border-color: #409eff;
  3605. color: #409eff;
  3606. transform: translateY(-2px);
  3607. box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
  3608. }
  3609. </style>