index.vue 184 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649
  1. <template>
  2. <div class="pptist-student-viewer" :class="{ 'fullscreen': isFullscreen }">
  3. <!-- Loading状态显示 -->
  4. <div v-if="isLoading" class="loading-overlay">
  5. <div class="loading-content">
  6. <div class="loading-spinner"></div>
  7. <div class="loading-text">{{ lang.ssCourseLoading }}</div>
  8. </div>
  9. </div>
  10. <!-- 左侧导航栏 -->
  11. <div class="layout-content-left" v-show="type == '1' || (type == '2' && !isFollowModeActive)" :class="{ collapsed: slidePanelCollapsed }">
  12. <div class="thumbnails">
  13. <div class="viewer-header slide-header">
  14. <h3 v-show="!slidePanelCollapsed">{{ lang.ssCourseOutline }}</h3>
  15. <button class="collapse-btn" @click="slidePanelCollapsed = !slidePanelCollapsed" :title="slidePanelCollapsed ? lang.ssExpand : lang.ssCollapse" style="right: 8px;">
  16. <span v-if="slidePanelCollapsed">
  17. <img src="@/assets/img/arrow.svg">
  18. </span>
  19. <span v-else>
  20. <img src="@/assets/img/arrow.svg" style="transform: rotate(180deg);">
  21. </span>
  22. </button>
  23. </div>
  24. <div v-if="!slidePanelCollapsed" class="panel-content">
  25. <div class="thumbnail-list">
  26. <div v-for="(slide, index) in slides" :key="slide.id" class="thumbnail-item"
  27. :class="{ 'active': slideIndex === index }" @click="goToSlide(index)">
  28. <div class="label">{{ fillDigit(index + 1, 2) }}</div>
  29. <ThumbnailSlide class="thumbnail" :slide="slide" :size="168" :visible="true" @click="goToSlide(index)" />
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <!-- 中间放映区域 -->
  36. <div class="layout-content-center">
  37. <div class="viewer-header" :class="{ 'hidden': isFullscreen }" style="display: none;">
  38. <div class="slide-title">{{ lang.ssSlidePage }} {{ slideIndex + 1 }}</div>
  39. <div class="viewer-controls">
  40. <button @click="previousSlide" :disabled="slideIndex === 0" :title="lang.ssPrevPage" v-if="!isFollowModeActive || props.type == '1'">
  41. <IconLeftTwo class="control-icon" />
  42. </button>
  43. <button @click="nextSlide" :disabled="slideIndex === slides.length - 1" :title="lang.ssNextPage" v-if="!isFollowModeActive || props.type == '1'">
  44. <IconRightTwo class="control-icon" />
  45. </button>
  46. <!-- <button @click="resetZoom" title="重置缩放">
  47. <IconUndo class="control-icon" />
  48. </button> -->
  49. <button @click="enterFullscreen" :title="lang.ssFullscreen">
  50. <IconFullScreenOne class="control-icon" />
  51. </button>
  52. <!-- 只有创建人才显示跟随模式按钮 -->
  53. <button
  54. v-if="isCreator"
  55. @click="toggleFollowMode"
  56. :class="{ 'follow-active': isFollowModeActive }"
  57. >
  58. {{ isFollowModeActive ? lang.ssFollowOff : lang.ssFollowOn }}
  59. </button>
  60. <!-- <button @click="backToEditor" class="back-btn" title="返回编辑">
  61. <IconEdit class="control-icon" />
  62. </button> -->
  63. </div>
  64. </div>
  65. <div class="viewer-canvas" ref="viewerCanvasRef">
  66. <!-- 全屏时:使用放映功能 -->
  67. <!-- <ScreenSlideList :slideWidth="slideWidth"
  68. :slideHeight="slideHeight" :animationIndex="0" :turnSlideToId="() => { }"
  69. :manualExitFullscreen="() => { }" /> -->
  70. <!-- 不全屏时:使用编辑模式的显示比例和居中逻辑 -->
  71. <div class="slide-list-wrap" ref="slideListWrapRef" :class="{'slide-list-wrap-n': !isFullscreen, 'laser-pen': laserPen }" :style="{
  72. width: isFullscreen ? '100%' : (slideWidth * canvasScale) + 'px',
  73. height: isFullscreen ? '100%' : (slideHeight * canvasScale) + 'px',
  74. left: isFullscreen ? '0' : `${(containerWidth - slideWidth * canvasScale) / 2}px`,
  75. top: isFullscreen ? '0' : `${(containerHeight - slideHeight * canvasScale) / 2}px`
  76. }" @mousemove="handleLaserMove">
  77. <div class="homework-check-box" v-if="currentSlideHasIframe && !currentSlideHasBilibiliVideo && props.type == '1'" v-show="currentSlideHasIframe" :style="{
  78. top: isFullscreen ? '0' : `0`
  79. }">
  80. <div class="homework-check-box-item" @click="openChoiceQuestionDetail2(slideIndex)" :class="{'active': !choiceQuestionDetailDialogOpenList.includes(slideIndex)}">
  81. <div class="homework-check-box-item-title">{{ lang.ssQuestion }}</div>
  82. </div>
  83. <div class="homework-check-box-item" @click="openChoiceQuestionDetail3(slideIndex)" :class="{'active': choiceQuestionDetailDialogOpenList.includes(slideIndex)}">
  84. <div class="homework-check-box-item-title">{{ lang.ssResult }}</div>
  85. </div>
  86. </div>
  87. <div class="aiBtn" ref="aiBtnRef" v-if="isQuestionFrame && hasWork && props.type == '2' && aiAssistant"
  88. :style="{ right: aiBtnPosition.x + 'px', bottom: aiBtnPosition.y + 'px' }" @click="openAiChat">
  89. <IconComment class="aiBtn-icon" />
  90. <span>AI对话</span>
  91. </div>
  92. <aiChat v-show="visibleAIChat" :position="aiBtnPosition" @close="visibleAIChat = false" :userid="props.userid" :workJson="myWork" :visible="visibleAIChat" :cid="props.cid"/>
  93. <!-- -->
  94. <div class="viewport" v-if="false">
  95. <div class="background" :style="backgroundStyle"></div>
  96. <ScreenElement v-for="(element, index) in elementList" :key="element.id" :elementInfo="element"
  97. :elementIndex="index + 1" :animationIndex="0" :turnSlideToId="() => { }"
  98. :manualExitFullscreen="() => { }" :is-visible="slideIndex === index" />
  99. </div>
  100. <ScreenSlideList :style="{ width: isFullscreen ? '100%' : slideWidth2 * canvasScale + 'px', height: isFullscreen ? '100%' : slideHeight2 * canvasScale + 'px', margin: '0 auto' }" :slideWidth="isFullscreen ? slideWidth * canvasScale : slideWidth2 * canvasScale" :slideHeight="isFullscreen ? slideHeight * canvasScale : slideHeight2 * canvasScale"
  101. :animationIndex="0" :turnSlideToId="() => { }" :manualExitFullscreen="() => { }" :slideIndex="slideIndex" v-show="!choiceQuestionDetailDialogOpenList.includes(slideIndex)"/>
  102. <choiceQuestionDetailDialog v-if="choiceQuestionDetailDialogOpenList.includes(slideIndex) && currentSlideToolType !== 77" :cid="props.cid" :workId="workId" :workUrl="workUrl" :userId="props.userid" :courseDetail="courseDetail" :workArray="workArray" @changeWorkIndex="changeWorkIndex" v-model:visible="choiceQuestionDetailDialogOpenList" :showData="answerTheResultRef" :slideIndex="slideIndex" :workIndex="0" :style="{ width: isFullscreen ? '100%' : slideWidth2 * canvasScale + 'px', height: isFullscreen ? '100%' : slideHeight2 * canvasScale + 'px', margin: '0 auto' }" :slideWidth="isFullscreen ? slideWidth * canvasScale : slideWidth2 * canvasScale" :slideHeight="isFullscreen ? slideHeight * canvasScale : slideHeight2 * canvasScale"/>
  103. <SpeakingClassPanel
  104. v-else-if="choiceQuestionDetailDialogOpenList.includes(slideIndex) && currentSlideToolType === 77"
  105. ref="speakingPanelRef"
  106. :configId="currentSlideConfigId"
  107. :slideIndex="slideIndex"
  108. :studentArray="studentArray"
  109. :courseId="props.courseid"
  110. :slideWidth="isFullscreen ? slideWidth * canvasScale : slideWidth2 * canvasScale"
  111. :slideHeight="isFullscreen ? slideHeight * canvasScale : slideHeight2 * canvasScale"
  112. :style="{ margin: '0 auto' }"
  113. />
  114. <div class="slide-bottom" v-if="!isFullscreen">
  115. <div class="slide-bottom-center" v-if="!isFullscreen && (!isFollowModeActive || props.type == '1')">
  116. <div class="slide-bottom-center-item">
  117. <img src="@/assets/img/left-a.svg" alt="" @click="previousSlide">
  118. <div class="slide-bottom-center-item-page">
  119. <span>{{ slideIndex + 1 }}</span>
  120. <span>/</span>
  121. <span>{{ slides.length }}</span>
  122. </div>
  123. <img src="@/assets/img/right-a.svg" alt="" @click="nextSlide">
  124. </div>
  125. </div>
  126. <div class="slide-bottom-right" v-if="!isFullscreen">
  127. <Refresh class="tool-btn" v-tooltip="lang.ssRefresh" @click="handleRefreshPage" v-if="currentSlideHasIframe && !currentSlideHasEnglishSpeaking"/>
  128. <!-- <UpTwo @click="handleHomeworkSubmit" v-if="currentSlideHasIframe && !currentSlideHasBilibiliVideo && !isSubmitting" class="tool-btn upBtn" v-tooltip="lang.ssSubmitHW"/> -->
  129. <svg @click="handleHomeworkSubmit" v-if="currentSlideHasIframe && !currentSlideHasBilibiliVideo && !isSubmitting && !currentSlideHasEnglishSpeaking" class="tool-btn upBtn" v-tooltip="lang.ssSubmitHW" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
  130. <!-- Document body -->
  131. <path d="M15 10 L15 90 Q15 95 20 95 L80 95 Q85 95 85 90 L85 35 L60 10 Z"
  132. fill="none" stroke="currentColor" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"/>
  133. <!-- Folded corner -->
  134. <path d="M60 10 L60 35 L85 35"
  135. fill="none" stroke="currentColor" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"/>
  136. <!-- Upload arrow shaft -->
  137. <line x1="50" y1="72" x2="50" y2="45"
  138. stroke="currentColor" stroke-width="6" stroke-linecap="round"/>
  139. <!-- Arrow head -->
  140. <polyline points="37,57 50,43 63,57"
  141. fill="none" stroke="currentColor" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"/>
  142. <!-- Bottom lines -->
  143. <line x1="36" y1="80" x2="64" y2="80"
  144. stroke="currentColor" stroke-width="6" stroke-linecap="round"/>
  145. <line x1="36" y1="88" x2="64" y2="88"
  146. stroke="currentColor" stroke-width="6" stroke-linecap="round"/>
  147. </svg>
  148. <IconLoading v-else-if="currentSlideHasIframe && !currentSlideHasBilibiliVideo && !currentSlideHasEnglishSpeaking" class="tool-btn loading" v-tooltip="lang.ssSubmitting"></IconLoading>
  149. <IconStopwatchStart v-if="props.type == '1' && courseDetail.userid == props.userid && isFollowModeActive" class="tool-btn" v-tooltip="lang.ssTimer" @click="timerlVisible = !timerlVisible" />
  150. <IconWrite v-if="isFollowModeActive && props.type == '1' && courseDetail.userid == props.userid" class="tool-btn" v-tooltip="lang.ssPenTool" @click="writingBoardToolVisible = true" />
  151. <!-- <IconMagic v-if="isFollowModeActive && props.type == '1' && courseDetail.userid == props.userid" class="tool-btn" v-tooltip="lang.ssLaserPen" :class="{ 'active': laserPen }" @click="toggleLaserPen" /> -->
  152. <IconTips v-if="props.type == '1'" class="tool-btn" v-tooltip="lang.ssAiHelper" :class="{ 'active': !workPanelCollapsed }" @click="workPanelCollapsed = !workPanelCollapsed" />
  153. <IconFullScreenOne class="tool-btn" v-tooltip="lang.ssOpenFull" @click="enterFullscreen" />
  154. </div>
  155. </div>
  156. </div>
  157. <!-- 全屏时的左右下角工具按钮 -->
  158. <div v-if="isFullscreen && (!isFollowModeActive || props.type == '1')" class="tools-left">
  159. <IconLeftTwo class="tool-btn" theme="two-tone" :fill="['#111', '#fff']" @click="previousSlide" />
  160. <IconRightTwo class="tool-btn" theme="two-tone" :fill="['#111', '#fff']" @click="nextSlide" />
  161. </div>
  162. <!-- 作业提交按钮 - 当当前幻灯片包含iframe时显示(排除B站视频) -->
  163. <div v-if="currentSlideHasIframe && !currentSlideHasBilibiliVideo && isFullscreen && !currentSlideHasEnglishSpeaking" class="homework-submit-btn" :class="{ 'submitting': isSubmitting }"
  164. :style="{ right: getHomeworkButtonRight() + 'px' }" @click="handleHomeworkSubmit"
  165. v-tooltip="isSubmitting ? lang.ssHwSubmitting : lang.ssHwSubmit">
  166. <!-- <IconEdit v-if="!isSubmitting" class="tool-btn" />
  167. <div v-else class="loading-spinner"></div> -->
  168. <span class="btn-text">{{ isSubmitting ? lang.ssSubmittingEll : lang.ssSubmit }}</span>
  169. </div>
  170. <!-- 刷新iframe按钮 -->
  171. <div class="refresh-page-btn"
  172. v-if="currentSlideHasIframe && isFullscreen && !currentSlideHasEnglishSpeaking"
  173. :style="{ right: getRefreshButtonRight() + 'px' }"
  174. @click="handleRefreshPage"
  175. v-tooltip="lang.ssRefreshIframe">
  176. <Refresh class="tool-btn" />
  177. <span class="btn-text">{{ lang.ssRefresh }}</span>
  178. </div>
  179. <!-- 功能组件 -->
  180. <SlideThumbnails v-if="slideThumbnailModelVisible" :turnSlideToIndex="goToSlide"
  181. @close="slideThumbnailModelVisible = false" />
  182. <WritingBoardTool
  183. :slideWidth="slideWidth"
  184. :slideHeight="slideHeight"
  185. v-if="writingBoardToolVisible || (props.type == '2' && isFollowModeActive && writingBoardSyncDataURL && writingBoardSyncDataURL.trim() !== '')"
  186. :readonly="props.type == '2'"
  187. :syncDataURL="props.type == '2' ? writingBoardSyncDataURL : null"
  188. :syncBlackboard="props.type == '2' ? writingBoardSyncBlackboard : null"
  189. @close="handleWritingBoardClose"
  190. @drawing-end="handleDrawingEnd"
  191. @blackboard-change="handleBlackboardChange"
  192. />
  193. <CountdownTimer
  194. v-if="timerlVisible"
  195. @close="timerlVisible = false"
  196. @timer-start="onTimerStart"
  197. @timer-pause="onTimerPause"
  198. @timer-reset="onTimerReset"
  199. @timer-stop="onTimerStop"
  200. @timer-finish="onTimerFinish"
  201. @timer-update="onTimerUpdate"
  202. />
  203. <div v-if="isFullscreen && (!isFollowModeActive || props.type == '1')" class="tools-right" :class="{ 'visible': rightToolsVisible }"
  204. @mouseleave="rightToolsVisible = false" @mouseenter="rightToolsVisible = true">
  205. <div class="content">
  206. <div class="tool-btn page-number" @click="slideThumbnailModelVisible = true">
  207. {{ lang.ssSlidePage }} {{slideIndex + 1}} / {{slides.length}}
  208. </div>
  209. <IconWrite class="tool-btn" v-if="isFollowModeActive && props.type == '1' && courseDetail.userid == props.userid" v-tooltip="lang.ssPenTool" @click="writingBoardToolVisible = true" />
  210. <IconMagic class="tool-btn" v-if="isFollowModeActive && props.type == '1' && courseDetail.userid == props.userid" v-tooltip="lang.ssLaserPen" :class="{ 'active': laserPen }" @click="toggleLaserPen" />
  211. <IconStopwatchStart v-if="(props.type == '1' && courseDetail.userid == props.userid && isFollowModeActive)" class="tool-btn" v-tooltip="lang.ssTimer" @click="timerlVisible = !timerlVisible" />
  212. <IconOffScreenOne class="tool-btn" v-tooltip="lang.ssExitFull" @click="enterFullscreen" />
  213. </div>
  214. </div>
  215. </div>
  216. </div>
  217. <div class="layout-content-right" v-show="type == '1'" :class="{ collapsed: workPanelCollapsed }">
  218. <div class="thumbnails">
  219. <div class="viewer-header right-panel-header">
  220. <button class="collapse-btn" @click="workPanelCollapsed = !workPanelCollapsed" :title="workPanelCollapsed ? lang.ssExpand : lang.ssCollapse" v-if="rightPanelMode != ''" style="left: 8px;">
  221. <span v-if="workPanelCollapsed">
  222. <img src="@/assets/img/arrow.svg" style="transform: rotate(180deg);">
  223. </span>
  224. <span v-else>
  225. <img src="@/assets/img/arrow.svg">
  226. </span>
  227. </button>
  228. <!-- 标签页切换按钮 -->
  229. <div v-show="!workPanelCollapsed" class="tab-switcher">
  230. <!-- <button
  231. v-if="currentSlideHasIframe && !currentSlideHasBilibiliVideo"
  232. v-show="currentSlideHasIframe"
  233. class="tab-btn"
  234. :class="{ active: rightPanelMode === 'homework' }"
  235. @click="switchToHomework"
  236. :title="lang.ssAnswerRes"
  237. >
  238. {{ lang.ssAnswerRes }}
  239. </button> -->
  240. <button
  241. class="tab-btn"
  242. :class="{ active: rightPanelMode === 'dialogue' }"
  243. @click="switchToDialogue"
  244. :title="lang.ssDialogArea"
  245. >
  246. {{ lang.ssDialogArea }}
  247. </button>
  248. <!-- <button
  249. v-if="isChoiceQuestion"
  250. class="tab-btn"
  251. :class="{ active: rightPanelMode === 'choice' }"
  252. @click="switchToChoice"
  253. title="统计"
  254. >
  255. 统计
  256. </button> -->
  257. </div>
  258. </div>
  259. <!-- 侧边导航标签 - 无论展开还是收缩都显示在左侧 -->
  260. <!-- <div class="side-nav-tabs">
  261. <button
  262. v-if="currentSlideHasIframe"
  263. class="side-nav-btn"
  264. :class="{ active: rightPanelMode === 'homework' }"
  265. @click="switchToHomework"
  266. title="作业"
  267. >
  268. <img :src="rightPanelMode === 'homework' ? homeworkActiveIcon : homeworkIcon" alt="作业">
  269. </button>
  270. <button
  271. v-if="isChoiceQuestion"
  272. class="side-nav-btn"
  273. :class="{ active: rightPanelMode === 'choice' }"
  274. @click="switchToChoice"
  275. title="统计"
  276. >
  277. <img :src="rightPanelMode === 'choice' ? choiceActiveIcon : choiceIcon" alt="统计">
  278. </button>
  279. <button
  280. class="side-nav-btn"
  281. :class="{ active: rightPanelMode === 'dialogue' }"
  282. @click="switchToDialogue"
  283. title="对话"
  284. >
  285. <img :src="rightPanelMode === 'dialogue' ? dialogueActiveIcon : dialogueIcon" alt="对话">
  286. </button>
  287. </div> -->
  288. <!-- 回答结果内容 -->
  289. <div v-show="!workPanelCollapsed && rightPanelMode === 'homework'" class="panel-content">
  290. <div v-if="workLoading" class="homework-loading">{{ lang.ssHwLoading }}</div>
  291. <answerTheResult :toolType="toolType" :workId="workId" :workArray="workArray" :unsubmittedStudents="unsubmittedStudents" :slideIndex="slideIndex" v-else ref="answerTheResultRef" @openChoiceQuestionDetail="openChoiceQuestionDetail" @openWorkModal="openWorkModal"/>
  292. <!--<div class="homework-title">已提交</div>
  293. <div v-if="workLoading" class="homework-loading">正在加载作业...</div>
  294. <div v-else>
  295. <div v-if="workArray && workArray.length" class="homework-grid">
  296. <button class="homework-btn" v-for="(work, idx) in workArray" :key="work.id ?? idx" :title="work.name" @click="openWorkModal(work)">
  297. <span class="homework-btn__text">{{ work.name }}</span>
  298. </button>
  299. </div>
  300. <div class="homework-empty" v-else>
  301. 暂无作业提交
  302. </div>
  303. </div>-->
  304. <!--<div v-if="unsubmittedStudents && unsubmittedStudents.length > 0" class="homework-title" style="margin-top: 20px;">未提交</div>
  305. <div v-if="unsubmittedStudents && unsubmittedStudents.length > 0">
  306. <div v-if="studentLoading" class="homework-loading">正在加载学生信息...</div>
  307. <div v-else>
  308. <div class="homework-grid">
  309. <button class="homework-btn unsubmitted" v-for="(student, idx) in unsubmittedStudents" :key="student.id ?? idx" :title="student.name" disabled>
  310. <span class="homework-btn__text">{{ student.name }}</span>
  311. </button>
  312. </div>
  313. </div>
  314. </div>-->
  315. </div>
  316. <!-- 对话区内容 -->
  317. <div v-show="!workPanelCollapsed && rightPanelMode === 'dialogue'" class="panel-content">
  318. <DialoguePanel :userid="props.userid" :courseid="props.courseid"/>
  319. </div>
  320. <!-- 选择题统计内容 -->
  321. <div v-show="!workPanelCollapsed && rightPanelMode === 'choice'" class="panel-content">
  322. <ChoiceStatistics :workArray="workArray" :elementList="elementList" />
  323. </div>
  324. </div>
  325. </div>
  326. <!-- 右上角计时状态指示器(块状样式) -->
  327. <div
  328. v-if="timerIndicator.visible"
  329. class="timer-indicator"
  330. :class="{ 'countdown': timerIndicator.isCountdown, 'timeout': timerIndicator.isCountdown && timerIndicator.remainingSec !== null && timerIndicator.remainingSec <= 0 }"
  331. :style="{ right: getTimerIndicatorRight() + 'px', top: isFullscreen ? '16px' : '12px' }"
  332. >
  333. <div class="blocks">
  334. <template v-if="timerBlocksVisibility().showH">
  335. <span class="block">{{ timerBlocks().h }}</span>
  336. <span class="colon"></span>
  337. </template>
  338. <template v-if="timerBlocksVisibility().showM">
  339. <span class="block">{{ timerBlocks().m }}</span>
  340. <span class="colon"></span>
  341. </template>
  342. <span class="block">{{ timerBlocks().s }}</span>
  343. </div>
  344. </div>
  345. </div>
  346. <ShotWorkModal v-model:visible="visibleShot" :work="selectedWork" />
  347. <QAWorkModal v-model:visible="visibleQA" :work="selectedWork" />
  348. <ChoiceWorkModal v-model:visible="visibleChoice" :work="selectedWork" />
  349. <AIWorkModal v-model:visible="visibleAI" :work="selectedWork" />
  350. <!-- 学生端激光笔覆盖层(拦截点击) -->
  351. <div
  352. v-if="props.type == '2' && laserPenOverlay.visible"
  353. class="laser-pointer-overlay"
  354. :style="laserOverlayStyle"
  355. >
  356. <div class="laser-pointer-dot" ref="laserDotRef"></div>
  357. </div>
  358. <!-- 在适当位置添加连接状态指示器 -->
  359. <div class="connection-status" v-if="connectionStatus !== 'connected'">
  360. <div class="status-indicator" :class="connectionStatus">
  361. <span v-if="connectionStatus === 'connecting'">{{ lang.ssConnecting }}</span>
  362. <span v-else-if="connectionStatus === 'disconnected'">{{ lang.ssConnLost }}</span>
  363. </div>
  364. <button v-if="connectionStatus === 'disconnected'" @click="manualReconnect" class="reconnect-btn">
  365. {{ lang.ssReconnect }}
  366. </button>
  367. </div>
  368. <div class="connection-status" v-if="false">
  369. <div class="status-indicator" :class="'disconnected'">
  370. <span>{{ lang.ssConnLost }}</span>
  371. </div>
  372. <button @click="manualReconnect" class="reconnect-btn">
  373. {{ lang.ssReconnect }}
  374. </button>
  375. </div>
  376. <messageInstruction ref="messageInstructionRef" />
  377. </template>
  378. <script lang="ts" setup>
  379. import { computed, ref, onMounted, onUnmounted, nextTick, inject, watch, provide } from 'vue'
  380. import { storeToRefs } from 'pinia'
  381. import { useSlidesStore } from '@/store'
  382. import { ElementTypes } from '@/types/slides'
  383. import { fillDigit } from '@/utils/common'
  384. import ThumbnailSlide from '@/views/components/ThumbnailSlide/index.vue'
  385. import ScreenSlideList from '@/views/Screen/ScreenSlideList.vue'
  386. import ScreenElement from '@/views/Screen/ScreenElement.vue'
  387. import SlideThumbnails from '@/views/Screen/SlideThumbnails.vue'
  388. import WritingBoardTool from '@/views/Screen/WritingBoardTool.vue'
  389. import CountdownTimer from '@/views/Screen/CountdownTimer.vue'
  390. import useSlideBackgroundStyle from '@/hooks/useSlideBackgroundStyle'
  391. import useImport from '@/hooks/useImport'
  392. import message from '@/utils/message'
  393. import api, { API_URL } from '@/services/course'
  394. import axios from '@/services/config'
  395. import {currentVersion, lang} from '@/main'
  396. import ShotWorkModal from './components/ShotWorkModal.vue'
  397. import QAWorkModal from './components/QAWorkModal.vue'
  398. import ChoiceWorkModal from './components/ChoiceWorkModal.vue'
  399. import AIWorkModal from './components/AIWorkModal.vue'
  400. import DialoguePanel from './components/DialoguePanel.vue'
  401. import ChoiceStatistics from './components/ChoiceStatistics.vue'
  402. import * as Y from 'yjs'
  403. import { WebsocketProvider } from 'y-websocket'
  404. import { Refresh } from '@icon-park/vue-next'
  405. import answerTheResult from './components/answerTheResult.vue'
  406. import choiceQuestionDetailDialog from './components/choiceQuestionDetailDialog.vue'
  407. import SpeakingClassPanel from './components/SpeakingClassPanel/index.vue'
  408. import aiChat from './components/aiChat.vue'
  409. import messageInstruction from '@/utils/components/messageInstruction.vue'
  410. const messageInstructionRef = ref(null)
  411. // 生成标准 UUID v4 格式(36位,符合 [0-9a-fA-F-] 格式)
  412. const generateUUID = (): string => {
  413. // 优先使用浏览器原生 API
  414. if (typeof crypto !== 'undefined' && crypto.randomUUID) {
  415. return crypto.randomUUID()
  416. }
  417. // 降级方案:手动生成 UUID v4
  418. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
  419. const r = (Math.random() * 16) | 0
  420. const v = c === 'x' ? r : (r & 0x3) | 0x8
  421. return v.toString(16)
  422. })
  423. }
  424. // 导入图片资源
  425. import homeworkIcon from '@/assets/img/homework.png'
  426. import homeworkActiveIcon from '@/assets/img/homework-active.png'
  427. import dialogueIcon from '@/assets/img/dialogue.png'
  428. import dialogueActiveIcon from '@/assets/img/dialogue-active.png'
  429. import choiceIcon from '@/assets/img/choice.png'
  430. import choiceActiveIcon from '@/assets/img/choice-active.png'
  431. // 定义组件props
  432. interface Props {
  433. courseid?: string | null
  434. userid?: string | null
  435. oid?: string | null
  436. org?: string | null
  437. cid?: string | null
  438. type?: string | null
  439. }
  440. const props = withDefaults(defineProps<Props>(), {
  441. courseid: null,
  442. userid: null,
  443. oid: null,
  444. org: null,
  445. cid: null,
  446. type: null,
  447. })
  448. // 图标组件通过全局注册,无需导入
  449. const slidesStore = useSlidesStore()
  450. const { slides, slideIndex, currentSlide, viewportSize, viewportRatio } = storeToRefs(slidesStore)
  451. // 添加容器引用,用于计算幻灯片尺寸
  452. const viewerCanvasRef = ref<HTMLElement>()
  453. // 放映相关的状态
  454. const canvasScale = ref(1) // 画布缩放比例
  455. const isFullscreen = ref(false) // 是否全屏
  456. const containerWidth = ref(0) // 容器宽度
  457. const containerHeight = ref(0) // 容器高度
  458. // 全屏工具相关状态
  459. const rightToolsVisible = ref(false)
  460. const writingBoardToolVisible = ref(false)
  461. const timerlVisible = ref(false)
  462. const slideThumbnailModelVisible = ref(false)
  463. const laserPen = ref(false)
  464. // 学生端激光笔覆盖层与位置(百分比)
  465. const laserPenOverlay = ref<{ visible: boolean; xPct: number; yPct: number }>({ visible: false, xPct: 0, yPct: 0 })
  466. const laserDotRef = ref<HTMLElement | null>(null)
  467. let laserMoveRafId: number | null = null
  468. let lastLayout: { w: number; h: number } | null = null
  469. // 学生端覆盖层矩形(固定定位)
  470. const laserOverlayRect = ref<{ left: number; top: number; width: number; height: number }>({ left: 0, top: 0, width: 0, height: 0 })
  471. const laserOverlayStyle = computed(() => ({
  472. position: 'fixed' as const,
  473. left: laserOverlayRect.value.left + 'px',
  474. top: laserOverlayRect.value.top + 'px',
  475. width: laserOverlayRect.value.width + 'px',
  476. height: laserOverlayRect.value.height + 'px',
  477. pointerEvents: 'auto' as const,
  478. zIndex: 1000
  479. }))
  480. const refreshLaserOverlayRect = () => {
  481. const wrap = (viewerCanvasRef.value?.querySelector('.slide-list-wrap') as HTMLElement) || null
  482. if (!wrap) return
  483. const rect = wrap.getBoundingClientRect()
  484. laserOverlayRect.value = { left: rect.left, top: rect.top, width: rect.width, height: rect.height }
  485. }
  486. const updateLaserDotPosition = () => {
  487. if (!laserDotRef.value || !viewerCanvasRef.value) return
  488. const wrap = (viewerCanvasRef.value.querySelector('.slide-list-wrap') as HTMLElement) || viewerCanvasRef.value
  489. const w = wrap.clientWidth
  490. const h = wrap.clientHeight
  491. lastLayout = { w, h }
  492. const left = (laserPenOverlay.value.xPct / 100) * w
  493. const top = (laserPenOverlay.value.yPct / 100) * h
  494. // 减去半径使光点中心对齐
  495. laserDotRef.value.style.transform = `translate3d(${left - 12}px, ${top - 12}px, 0)`
  496. }
  497. const answerTheResultRef = ref(null)
  498. // 计时状态指示器
  499. const timerIndicator = ref<{ visible: boolean; isCountdown: boolean; startAt: string | null; durationSec: number | null; elapsedSec: number | null; remainingSec: number | null; finished: boolean }>({
  500. visible: false,
  501. isCountdown: false,
  502. startAt: null,
  503. durationSec: null,
  504. elapsedSec: null,
  505. remainingSec: null,
  506. finished: false,
  507. })
  508. const timerInterval = ref<number | null>(null)
  509. // 作业提交状态
  510. const isSubmitting = ref(false)
  511. // 控制组件显示的开关
  512. const showSlideList = ref(true)
  513. const slideWidth = ref(0)
  514. const slideHeight = ref(0)
  515. const slideWidth2 = ref(0)
  516. const slideHeight2 = ref(0)
  517. // 添加loading状态
  518. const isLoading = ref(false)
  519. const workLoading = ref(false)
  520. const studentLoading = ref(false)
  521. // 作业数组
  522. type WorkItem = {
  523. id?: string | number
  524. name: string
  525. type: number | string
  526. [key: string]: any
  527. }
  528. const workArray = ref<WorkItem[]>([])
  529. // 作业弹窗相关
  530. const selectedWork = ref<any>(null)
  531. const visibleShot = ref(false)
  532. const visibleQA = ref(false)
  533. const visibleChoice = ref(false)
  534. const visibleAI = ref(false)
  535. const choiceQuestionDetailDialogOpenList = ref<number[]>([])
  536. const speakingPanelRef = ref<InstanceType<typeof SpeakingClassPanel> | null>(null)
  537. provide('notifySpeakingProgress', (status: 'active' | 'completed', payload: { configId: string; sessionId: string }) => {
  538. if (props.type !== '2') return // 只有学生客户端发广播
  539. sendMessage({
  540. type: 'speaking_session_updated',
  541. courseid: props.courseid,
  542. slideIndex: slideIndex.value,
  543. userid: props.userid,
  544. status,
  545. ...payload,
  546. })
  547. })
  548. provide('recordSpeakingStart', async (sessionId: string) => {
  549. // 老师端 (type=1) 与学生端 (type=2) 都允许写作业记录,方便老师自测/学生提交
  550. if (!sessionId || !props.courseid || !props.userid) return
  551. try {
  552. await api.submitWork({
  553. uid: props.userid as string,
  554. cid: props.courseid as string,
  555. stage: '0',
  556. task: String(slideIndex.value),
  557. tool: '0',
  558. atool: '77',
  559. content: sessionId,
  560. type: '21',
  561. })
  562. }
  563. catch (err) {
  564. console.error('[speaking] recordSpeakingStart failed:', err)
  565. }
  566. })
  567. // 提供给子组件使用
  568. provide('choiceQuestionDetailDialogOpenList', choiceQuestionDetailDialogOpenList)
  569. // 当前作业选择/问答题的ID
  570. const workId = ref<string>('')
  571. // 当前作业的url
  572. const workUrl = ref<string>('')
  573. // 当前作业的type
  574. const toolType = ref<string>('')
  575. // 回答结果收缩状态
  576. const workPanelCollapsed = ref(true)
  577. // 幻灯片导航收缩状态
  578. const slidePanelCollapsed = ref(true)
  579. // 右侧面板当前显示的内容:'homework' | 'dialogue' | 'choice'
  580. const rightPanelMode = ref<'homework' | 'dialogue' | 'choice' | ''>('homework')
  581. // 移除定时器相关代码,改用socket监听
  582. const courseDetail = ref<any>({})
  583. const aiAssistant = ref<boolean>(false)
  584. const studentArray = ref<any>([])
  585. // 跟随模式相关状态
  586. const isCreator = ref(false) // 是否为创建人
  587. const isFollowModeActive = ref(false) // 跟随模式是否开启
  588. const isFirstEnter = ref(true) // 是否首次进入
  589. // 用户信息
  590. const userJson = ref<any>(null)
  591. // 计算未提交作业的学生
  592. const unsubmittedStudents = computed(() => {
  593. if (!studentArray.value || !workArray.value) return []
  594. // 获取已提交作业的学生姓名
  595. const submittedNames = workArray.value.map(work => work.name)
  596. // 过滤出未提交作业的学生
  597. return studentArray.value.filter((student: any) => !submittedNames.includes(student.name))
  598. })
  599. const docSocket = ref<Y.Doc | null>(null)
  600. const yMessage = ref<any | null>(null)
  601. const yTimerState = ref<any | null>(null)
  602. const yLaserState = ref<any | null>(null)
  603. const yWritingBoardState = ref<any | null>(null)
  604. // 独立的数组存储特殊类型的消息
  605. const yTimerMessages = ref<any | null>(null)
  606. const yLaserMessages = ref<any | null>(null)
  607. const yWritingBoardMessages = ref<any | null>(null)
  608. const providerSocket = ref<WebsocketProvider | null>(null)
  609. // 学生端画图同步数据
  610. const writingBoardSyncDataURL = ref<string | null>(null)
  611. const writingBoardSyncBlackboard = ref<boolean | null>(null)
  612. const mId = ref<string | null>(null)
  613. // 画图延迟发送定时器
  614. const drawingDelayTimer = ref<NodeJS.Timeout | null>(null)
  615. // WebSocket重连相关变量
  616. const reconnectAttempts = ref(0)
  617. const maxReconnectAttempts = ref(5) // 最大重连次数
  618. const reconnectInterval = ref(5000) // 重连间隔(毫秒)
  619. const reconnectTimer = ref<NodeJS.Timeout | null>(null)
  620. const isConnecting = ref(false)
  621. const connectionStatus = ref<'disconnected' | 'connecting' | 'connected'>('disconnected')
  622. // 认证 token 相关变量
  623. const authToken = ref<string | null>(null)
  624. const authTokenUpdateTimer = ref<NodeJS.Timeout | null>(null)
  625. const socketCheckTimer = ref<NodeJS.Timeout | null>(null)
  626. // 同步数据最大保留时间(40分钟)
  627. const SYNC_DATA_MAX_AGE = 40 * 60 * 1000 // 40分钟 = 40 * 60 * 1000毫秒
  628. // 切换选择题题目
  629. const changeWorkIndex = (type:number) => {
  630. if (answerTheResultRef.value && answerTheResultRef.value.changeWorkIndex) {
  631. answerTheResultRef.value.changeWorkIndex(type)
  632. }
  633. }
  634. // 切换到回答结果
  635. const switchToHomework = () => {
  636. rightPanelMode.value = 'homework'
  637. if (workPanelCollapsed.value) {
  638. workPanelCollapsed.value = false
  639. }
  640. }
  641. // 切换到对话区
  642. const switchToDialogue = () => {
  643. rightPanelMode.value = 'dialogue'
  644. if (workPanelCollapsed.value) {
  645. workPanelCollapsed.value = false
  646. }
  647. }
  648. // 切换到选择题统计
  649. const switchToChoice = () => {
  650. rightPanelMode.value = 'choice'
  651. if (workPanelCollapsed.value) {
  652. workPanelCollapsed.value = false
  653. }
  654. }
  655. // 自动切换到可用的面板
  656. const autoSwitchToAvailablePanel = () => {
  657. // 如果当前在回答结果但没有iframe,自动切换到其他可用面板
  658. if (rightPanelMode.value === 'homework' && !currentSlideHasIframe.value && !currentSlideHasBilibiliVideo.value) {
  659. if (isChoiceQuestion.value) {
  660. rightPanelMode.value = 'choice'
  661. console.log('自动切换到统计面板')
  662. }
  663. else {
  664. rightPanelMode.value = 'dialogue'
  665. console.log('自动切换到对话面板')
  666. }
  667. }
  668. // 如果当前在统计面板但不是选择题,自动切换到对话面板
  669. else if (rightPanelMode.value === 'choice' && !isChoiceQuestion.value) {
  670. rightPanelMode.value = 'dialogue'
  671. console.log('自动切换到对话面板')
  672. }
  673. // else if (currentSlideHasIframe.value && rightPanelMode.value !== 'homework' && !currentSlideHasBilibiliVideo.value) {
  674. // rightPanelMode.value = 'homework'
  675. // }
  676. }
  677. // 移除定时器相关函数,改用socket监听
  678. // 收缩/展开后重新计算中间画布尺寸(在 DOM 更新并完成过渡后)
  679. watch([() => workPanelCollapsed.value, () => slidePanelCollapsed.value], async () => {
  680. // 等待本次 DOM 更新
  681. await nextTick()
  682. // 先在下一帧计算一次,确保初步布局就绪
  683. requestAnimationFrame(() => {
  684. calculateScale()
  685. })
  686. // 再在过渡结束后(与左右栏 width .2s 过渡一致)复算一次,确保最终尺寸
  687. setTimeout(() => {
  688. calculateScale()
  689. }, 220)
  690. }, { flush: 'post' })
  691. const openWorkModal = (work: WorkItem) => {
  692. selectedWork.value = work
  693. const t = Number(work?.type)
  694. // if (t !== 1) {
  695. // message.warning('暂未开发完成')
  696. // return
  697. // }
  698. visibleShot.value = false
  699. visibleQA.value = false
  700. visibleChoice.value = false
  701. visibleAI.value = false
  702. if (t === 1) {
  703. visibleShot.value = true
  704. }
  705. else if (t === 3) {
  706. visibleQA.value = true
  707. }
  708. else if (t === 8) {
  709. visibleChoice.value = true
  710. }
  711. else if (t === 20) {
  712. visibleAI.value = true
  713. }
  714. else {
  715. message.info(lang.ssHwTypeUnsup)
  716. }
  717. }
  718. // 计算幻灯片尺寸的函数
  719. const calculateSlideSize = () => {
  720. const slideWrapRef = isFullscreen.value ? document.body : viewerCanvasRef.value
  721. const winWidth = slideWrapRef?.clientWidth || 0
  722. const winHeight = slideWrapRef?.clientHeight || 0
  723. const winWidth2 = slideWrapRef && typeof slideWrapRef.clientWidth === 'number' ? slideWrapRef.clientWidth - 40 : 0
  724. const winHeight2 = slideWrapRef && typeof slideWrapRef.clientHeight === 'number' ? slideWrapRef.clientHeight - 60 - 65 - 10 : 0 // 底部栏 顶部高度 底部高度的
  725. // 根据视口比例计算最佳尺寸
  726. if (winHeight / winWidth === viewportRatio.value) {
  727. slideWidth.value = winWidth
  728. slideHeight.value = winHeight
  729. }
  730. else if (winHeight / winWidth > viewportRatio.value) {
  731. slideWidth.value = winWidth
  732. slideHeight.value = winWidth * viewportRatio.value
  733. }
  734. else {
  735. slideWidth.value = winHeight / viewportRatio.value
  736. slideHeight.value = winHeight
  737. }
  738. // 这里的逻辑存在一些问题和可以优化的地方:
  739. // 1. winWidth2 或 winHeight2 可能为0,导致后续计算为NaN。
  740. // 2. slideHeight.value - slideHeight2.value < 85 这个判断,slideHeight2.value 可能还未被合理赋值,导致判断不准确。
  741. // 3. 反复赋值 slideHeight2/slideWidth2,可能导致宽高比被破坏。
  742. // 4. 代码重复,可合并优化。
  743. // 先按比例计算
  744. let tempWidth = 0
  745. let tempHeight = 0
  746. if (winHeight2 / winWidth2 === viewportRatio.value) {
  747. tempWidth = winWidth2
  748. tempHeight = winHeight2
  749. }
  750. else if (winHeight2 / winWidth2 > viewportRatio.value) {
  751. tempWidth = winWidth2
  752. tempHeight = winWidth2 * viewportRatio.value
  753. }
  754. else {
  755. tempHeight = winHeight2
  756. tempWidth = winHeight2 / viewportRatio.value
  757. }
  758. // 检查底部空间
  759. if (slideHeight.value - tempHeight < (60 + 65 + 10)) {
  760. tempHeight = Math.max(slideHeight.value - (60 + 65 + 10), 0)
  761. tempWidth = tempHeight > 0 ? tempHeight / viewportRatio.value : 0
  762. }
  763. slideWidth2.value = tempWidth
  764. slideHeight2.value = tempHeight
  765. console.log('calculateSlideSize', slideWidth.value, slideHeight.value, viewportRatio.value, canvasScale.value)
  766. console.log('calculateSlideSize', slideWidth2.value, slideHeight2.value, viewportRatio.value, canvasScale.value)
  767. }
  768. // 使用编辑模式的缩放逻辑
  769. const calculateScale = () => {
  770. console.log('calculateScale 开始执行')
  771. // 获取容器尺寸
  772. const container = viewerCanvasRef.value || document.querySelector('.viewer-canvas')
  773. if (container) {
  774. containerWidth.value = container.clientWidth
  775. containerHeight.value = container.clientHeight
  776. console.log('容器尺寸:', {
  777. width: containerWidth.value,
  778. height: containerHeight.value
  779. })
  780. // 计算基础尺寸
  781. const baseWidth = viewportSize.value
  782. const baseHeight = viewportSize.value * viewportRatio.value
  783. console.log('基础尺寸:', {
  784. baseWidth,
  785. baseHeight,
  786. viewportSize: viewportSize.value,
  787. viewportRatio: viewportRatio.value
  788. })
  789. // 计算缩放比例,让幻灯片能够合理利用空间
  790. const scaleX = containerWidth.value / baseWidth
  791. const scaleY = containerHeight.value / baseHeight
  792. console.log('原始缩放比例:', { scaleX, scaleY })
  793. // 选择较小的缩放比例,确保幻灯片完全显示且居中,留10%边距
  794. const scale = Math.min(scaleX, scaleY) * 0.9
  795. console.log('最终缩放比例:', scale)
  796. canvasScale.value = isFullscreen.value ? 1 : props.type == '1' ? 1 : 1
  797. // canvasScale.value = 1
  798. }
  799. else {
  800. console.error('找不到容器元素')
  801. }
  802. // 计算幻灯片尺寸
  803. nextTick(() => {
  804. setTimeout(() => {
  805. calculateSlideSize()
  806. if (laserPenOverlay.value.visible) {
  807. refreshLaserOverlayRect()
  808. requestAnimationFrame(updateLaserDotPosition)
  809. }
  810. }, 500)
  811. })
  812. }
  813. // 简化:直接使用放映功能的缩放逻辑
  814. const resetZoom = () => {
  815. calculateScale()
  816. }
  817. // 背景样式
  818. const background = computed(() => currentSlide.value?.background)
  819. const { backgroundStyle } = useSlideBackgroundStyle(background)
  820. // 计算当前幻灯片的元素列表
  821. const elementList = computed(() => {
  822. return currentSlide.value?.elements || []
  823. })
  824. // 检查当前是否为选择题(toolType为45)
  825. const isChoiceQuestion = computed(() => {
  826. const frame = elementList.value.find(element => element.type === ElementTypes.FRAME)
  827. return frame?.toolType === 45
  828. })
  829. const isQuestionFrame = computed(() => {
  830. const frame = elementList.value.find(element => element.type === ElementTypes.FRAME)
  831. return frame?.toolType === 45 || frame?.toolType === 15
  832. })
  833. const hasWork = computed(() => {
  834. return workArray.value.find(work => work.userid === props.userid) !== undefined
  835. })
  836. const myWork = computed(() => {
  837. return workArray.value.find(work => work.userid === props.userid)
  838. })
  839. // AI按钮拖动相关状态
  840. const aiBtnPosition = ref({ x: 80, y: 70 }) // 初始位置(从右下角计算)
  841. const isDragging = ref(false)
  842. const dragStart = ref({ x: 0, y: 0 })
  843. const slideListWrapRef = ref<HTMLElement | null>(null)
  844. const aiBtnRef = ref<HTMLElement | null>(null)
  845. // 处理AI按钮开始拖动
  846. const handleAiBtnPointerDown = (e: PointerEvent) => {
  847. isDragging.value = true
  848. const aiBtn = aiBtnRef.value
  849. if (aiBtn) {
  850. // 设置指针捕获,确保即使鼠标移出元素也能继续接收事件
  851. aiBtn.setPointerCapture(e.pointerId)
  852. }
  853. // 获取slide-list-wrap元素的位置和尺寸
  854. const slideListWrap = slideListWrapRef.value
  855. if (slideListWrap) {
  856. const rect = slideListWrap.getBoundingClientRect()
  857. dragStart.value = {
  858. x: e.clientX - (rect.right - aiBtnPosition.value.x),
  859. y: e.clientY - (rect.bottom - aiBtnPosition.value.y)
  860. }
  861. }
  862. e.preventDefault()
  863. }
  864. // 处理拖动中
  865. const handleAiBtnPointerMove = (e: PointerEvent) => {
  866. if (isDragging.value) {
  867. const slideListWrap = slideListWrapRef.value
  868. if (slideListWrap) {
  869. const rect = slideListWrap.getBoundingClientRect()
  870. // 计算新位置(从slide-list-wrap右下角计算)
  871. const newX = rect.right - (e.clientX - dragStart.value.x)
  872. const newY = rect.bottom - (e.clientY - dragStart.value.y)
  873. // 限制在slide-list-wrap范围内
  874. const aiBtnWidth = 120 // 估计AI按钮宽度
  875. const aiBtnHeight = 40 // 估计AI按钮高度
  876. aiBtnPosition.value = {
  877. x: Math.max(20, Math.min(newX, rect.width - aiBtnWidth)),
  878. y: Math.max(20, Math.min(newY, rect.height - aiBtnHeight))
  879. }
  880. }
  881. }
  882. }
  883. // 处理拖动结束
  884. const handleAiBtnPointerUp = (e: PointerEvent) => {
  885. isDragging.value = false
  886. const aiBtn = aiBtnRef.value
  887. if (aiBtn) {
  888. // 释放指针捕获
  889. aiBtn.releasePointerCapture(e.pointerId)
  890. }
  891. }
  892. // 处理指针取消(如浏览器标签页切换)
  893. const handleAiBtnPointerCancel = (e: PointerEvent) => {
  894. isDragging.value = false
  895. const aiBtn = aiBtnRef.value
  896. if (aiBtn) {
  897. // 释放指针捕获
  898. aiBtn.releasePointerCapture(e.pointerId)
  899. }
  900. }
  901. // 监听isQuestionFrame和hasWork的变化,当按钮显示时添加事件监听器
  902. watch([isQuestionFrame, hasWork], ([newIsQuestionFrame, newHasWork]) => {
  903. if (newIsQuestionFrame && newHasWork) {
  904. // 按钮显示了,添加事件监听器
  905. nextTick(() => {
  906. const aiBtn = aiBtnRef.value
  907. if (aiBtn) {
  908. aiBtn.addEventListener('pointerdown', handleAiBtnPointerDown)
  909. aiBtn.addEventListener('pointermove', handleAiBtnPointerMove)
  910. aiBtn.addEventListener('pointerup', handleAiBtnPointerUp)
  911. aiBtn.addEventListener('pointercancel', handleAiBtnPointerCancel)
  912. }
  913. })
  914. }
  915. else {
  916. // 按钮隐藏了,移除事件监听器
  917. const aiBtn = aiBtnRef.value
  918. if (aiBtn) {
  919. aiBtn.removeEventListener('pointerdown', handleAiBtnPointerDown)
  920. aiBtn.removeEventListener('pointermove', handleAiBtnPointerMove)
  921. aiBtn.removeEventListener('pointerup', handleAiBtnPointerUp)
  922. aiBtn.removeEventListener('pointercancel', handleAiBtnPointerCancel)
  923. }
  924. }
  925. })
  926. onUnmounted(() => {
  927. // 移除事件监听器
  928. const aiBtn = aiBtnRef.value
  929. if (aiBtn) {
  930. aiBtn.removeEventListener('pointerdown', handleAiBtnPointerDown)
  931. aiBtn.removeEventListener('pointermove', handleAiBtnPointerMove)
  932. aiBtn.removeEventListener('pointerup', handleAiBtnPointerUp)
  933. aiBtn.removeEventListener('pointercancel', handleAiBtnPointerCancel)
  934. }
  935. })
  936. const visibleAIChat = ref(false)
  937. // 打开AI对话框
  938. const openAiChat = () => {
  939. visibleAIChat.value = !visibleAIChat.value
  940. }
  941. // 检测当前幻灯片是否包含iframe元素
  942. const currentSlideHasIframe = computed(() => {
  943. console.log('elementList.value', elementList.value)
  944. return elementList.value.some(element => element.type === ElementTypes.FRAME)
  945. })
  946. const currentSlideToolType = computed(() => {
  947. const frame = elementList.value.find(element => element.type === ElementTypes.FRAME)
  948. return Number((frame as any)?.toolType) || 0
  949. })
  950. const currentSlideConfigId = computed(() => {
  951. if (currentSlideToolType.value !== 77) return ''
  952. const frame = elementList.value.find(element => element.type === ElementTypes.FRAME)
  953. return (frame as any)?.url || ''
  954. })
  955. // 检测当前幻灯片是否包含B站视频
  956. const currentSlideHasBilibiliVideo = computed(() => {
  957. return elementList.value.some(element =>
  958. element.type === ElementTypes.FRAME && (element.toolType === 75 || element.toolType === 74 || element.toolType === 76)
  959. )
  960. })
  961. // 检测当前幻灯片是否是英语口语
  962. const currentSlideHasEnglishSpeaking = computed(() => {
  963. return elementList.value.some(element =>
  964. element.type === ElementTypes.FRAME && (element.toolType === 77)
  965. )
  966. })
  967. // 跳转到指定幻灯片
  968. const goToSlide = (index: number) => {
  969. console.log('goToSlide 被调用,目标索引:', index)
  970. console.log('当前索引:', slideIndex.value)
  971. if (index >= 0 && index < slides.value.length) {
  972. slidesStore.updateSlideIndex(index)
  973. console.log('更新后的索引:', slideIndex.value)
  974. }
  975. else {
  976. console.warn('goToSlide: 无效的索引:', index)
  977. }
  978. }
  979. // 上一页
  980. const previousSlide = () => {
  981. if (slideIndex.value > 0) {
  982. const newIndex = slideIndex.value - 1
  983. console.log('上一页,从', slideIndex.value, '到', newIndex)
  984. slidesStore.updateSlideIndex(newIndex)
  985. }
  986. }
  987. // 下一页
  988. const nextSlide = () => {
  989. if (slideIndex.value < slides.value.length - 1) {
  990. const newIndex = slideIndex.value + 1
  991. console.log('下一页,从', slideIndex.value, '到', newIndex)
  992. slidesStore.updateSlideIndex(newIndex)
  993. }
  994. }
  995. // 监听幻灯片切换,清除不匹配的画图数据
  996. watch(() => slideIndex.value, () => {
  997. if (props.type == '2' && yWritingBoardState.value && currentSlide.value) {
  998. const snap = yWritingBoardState.value.toJSON()
  999. console.log('📝 幻灯片切换,检查画图数据:', { snap, currentSlideId: currentSlide.value.id })
  1000. if (snap && snap.slideId === currentSlide.value.id && snap.dataURL) {
  1001. // 当前幻灯片有画图数据,显示
  1002. writingBoardSyncDataURL.value = snap.dataURL
  1003. writingBoardSyncBlackboard.value = snap.blackboard !== undefined ? snap.blackboard : null
  1004. console.log('📝 当前幻灯片有画图数据,显示画图工具,小黑板状态:', writingBoardSyncBlackboard.value)
  1005. }
  1006. else {
  1007. // 当前幻灯片没有画图数据,隐藏
  1008. writingBoardSyncDataURL.value = null
  1009. writingBoardSyncBlackboard.value = null
  1010. console.log('📝 当前幻灯片没有画图数据,隐藏画图工具')
  1011. }
  1012. if (visibleAIChat.value) {
  1013. visibleAIChat.value = false
  1014. }
  1015. }
  1016. })
  1017. // 监听 currentSlide 变化,确保刷新后能获取到画图状态
  1018. watch(() => currentSlide.value?.id, (newSlideId, oldSlideId) => {
  1019. // 只在学生端且跟随模式下检查
  1020. if (props.type == '2' && isFollowModeActive.value && yWritingBoardState.value && newSlideId) {
  1021. const snap = yWritingBoardState.value.toJSON()
  1022. console.log('📝 currentSlide变化,检查画图数据:', { snap, newSlideId, oldSlideId })
  1023. if (snap && snap.slideId === newSlideId && snap.dataURL) {
  1024. // 当前幻灯片有画图数据,显示
  1025. writingBoardSyncDataURL.value = snap.dataURL
  1026. writingBoardSyncBlackboard.value = snap.blackboard !== undefined ? snap.blackboard : null
  1027. console.log('📝 currentSlide变化后找到画图数据,显示画图工具,小黑板状态:', writingBoardSyncBlackboard.value)
  1028. }
  1029. else if (snap && snap.slideId !== newSlideId) {
  1030. // 当前幻灯片没有画图数据,隐藏
  1031. writingBoardSyncDataURL.value = null
  1032. writingBoardSyncBlackboard.value = null
  1033. console.log('📝 currentSlide变化后没有匹配的画图数据,隐藏画图工具')
  1034. }
  1035. }
  1036. }, { immediate: true })
  1037. // 监听slideIndex变化,调用getWork
  1038. watch(() => slideIndex.value, (newIndex, oldIndex) => {
  1039. console.log('slideIndex变化,调用getWork', { newIndex, oldIndex })
  1040. if (newIndex !== oldIndex && typeof newIndex === 'number') {
  1041. // 检查新页面是否有iframe
  1042. const hasIframe = currentSlideHasIframe.value
  1043. if (hasIframe) {
  1044. console.log('当前页面有iframe,获取作业数据')
  1045. console.log('触发getWork,当前幻灯片索引:', newIndex)
  1046. getWork()
  1047. }
  1048. if (props.type == '1' && isFollowModeActive.value && isCreator.value) {
  1049. api.updateCourseFollowC(newIndex, props.courseid as string)
  1050. sendMessage({slideIndex: newIndex, courseid: props.courseid, type: 'slideIndex'})
  1051. }
  1052. // 自动切换到可用的面板
  1053. autoSwitchToAvailablePanel()
  1054. if (isSubmitting.value) {
  1055. isSubmitting.value = false
  1056. }
  1057. if (timerlVisible.value) {
  1058. timerlVisible.value = false
  1059. }
  1060. }
  1061. getWorkId()
  1062. }, { immediate: false, deep: false })
  1063. // 监听iframe状态变化,自动切换面板
  1064. watch(() => currentSlideHasIframe.value, (hasIframe) => {
  1065. if (!hasIframe) {
  1066. autoSwitchToAvailablePanel()
  1067. }
  1068. }, { immediate: false })
  1069. // 全屏
  1070. const enterFullscreen = () => {
  1071. if (document.fullscreenElement) {
  1072. document.exitFullscreen()
  1073. }
  1074. else {
  1075. document.documentElement.requestFullscreen()
  1076. }
  1077. }
  1078. // 监听全屏状态变化
  1079. const handleFullscreenChange = () => {
  1080. isFullscreen.value = !!document.fullscreenElement
  1081. if (isFullscreen.value) {
  1082. // 全屏时不需要计算缩放,直接使用放映功能
  1083. console.log('进入全屏模式')
  1084. }
  1085. else {
  1086. // 退出全屏时重置所有工具状态并重新计算缩放比例
  1087. console.log('退出全屏模式,重置工具状态')
  1088. // 重置所有工具状态
  1089. rightToolsVisible.value = false
  1090. writingBoardToolVisible.value = false
  1091. slideThumbnailModelVisible.value = false
  1092. laserPen.value = false
  1093. // 重新计算缩放比例
  1094. nextTick(() => {
  1095. setTimeout(() => {
  1096. calculateScale()
  1097. }, 1000)
  1098. })
  1099. }
  1100. }
  1101. const getWorkId = () => {
  1102. // 修复类型报错:elementList 可能没有 toolType 和 url 字段,需先判断类型
  1103. const element = elementList.value.find((i:any) => i.type === 'frame')
  1104. console.log(element)
  1105. if (
  1106. element &&
  1107. typeof element === 'object' &&
  1108. ('toolType' in element) &&
  1109. (element as any).toolType !== undefined &&
  1110. ((element as any).toolType === 45 || (element as any).toolType === 15 || (element as any).toolType === 73 || (element as any).toolType === 72 || (element as any).toolType === 78 || (element as any).toolType === 79)
  1111. ) {
  1112. // 提取链接中的id参数
  1113. const url = (element as any).url
  1114. let id = ''
  1115. toolType.value = (element as any).toolType
  1116. if (typeof url === 'string') {
  1117. const match = url.match(/[?&]id=([^&]+)/)
  1118. if (match) {
  1119. id = match[1]
  1120. }
  1121. workUrl.value = url
  1122. workId.value = id
  1123. if ((element as any).toolType === 72) {
  1124. workId.value = (element as any).id
  1125. }
  1126. }
  1127. else {
  1128. workId.value = ''
  1129. workUrl.value = ''
  1130. }
  1131. }
  1132. else {
  1133. workId.value = ''
  1134. workUrl.value = ''
  1135. }
  1136. }
  1137. // 处理画图关闭事件
  1138. const handleWritingBoardClose = () => {
  1139. // 学生端只读模式下,不应该响应关闭事件(因为关闭按钮已隐藏)
  1140. // 只有老师端可以关闭
  1141. if (props.type == '2') {
  1142. console.log('📝 学生端收到关闭事件,但只读模式下不应该关闭,忽略')
  1143. return
  1144. }
  1145. writingBoardToolVisible.value = false
  1146. // 老师端关闭时,清空共享状态并通知学生端
  1147. if (props.type == '1' && isFollowModeActive.value && isCreator.value) {
  1148. clearWritingBoardState()
  1149. }
  1150. }
  1151. // 清空画图共享状态(仅创建人)
  1152. const clearWritingBoardState = () => {
  1153. try {
  1154. if (props.type == '1' && isCreator.value && yWritingBoardState.value) {
  1155. docSocket.value?.transact(() => {
  1156. yWritingBoardState.value.clear()
  1157. })
  1158. sendMessage({
  1159. type: 'writing_board_close',
  1160. courseid: props.courseid
  1161. })
  1162. }
  1163. }
  1164. catch (e) {
  1165. console.warn('清空画图状态失败', e)
  1166. }
  1167. }
  1168. // 处理小黑板状态变化(老师端)
  1169. const handleBlackboardChange = (blackboard: boolean) => {
  1170. if (props.type == '1' && isFollowModeActive.value && isCreator.value) {
  1171. // 同步到共享 Map
  1172. if (yWritingBoardState.value) {
  1173. docSocket.value?.transact(() => {
  1174. yWritingBoardState.value.set('blackboard', blackboard)
  1175. })
  1176. }
  1177. // 广播消息
  1178. sendMessage({
  1179. type: 'writing_board_blackboard',
  1180. blackboard: blackboard,
  1181. courseid: props.courseid
  1182. })
  1183. }
  1184. }
  1185. // 处理画图结束事件(老师端)
  1186. const handleDrawingEnd = (dataURL: string) => {
  1187. if (props.type == '1' && isFollowModeActive.value && isCreator.value) {
  1188. // 同步到共享 Map
  1189. if (yWritingBoardState.value) {
  1190. docSocket.value?.transact(() => {
  1191. yWritingBoardState.value.set('slideId', currentSlide.value.id)
  1192. yWritingBoardState.value.set('dataURL', dataURL)
  1193. // 保持小黑板状态
  1194. const currentBlackboard = yWritingBoardState.value.get('blackboard')
  1195. if (currentBlackboard !== undefined) {
  1196. yWritingBoardState.value.set('blackboard', currentBlackboard)
  1197. }
  1198. })
  1199. }
  1200. // 延迟5秒后广播消息,避免频繁发送
  1201. if (drawingDelayTimer.value) {
  1202. clearTimeout(drawingDelayTimer.value)
  1203. }
  1204. drawingDelayTimer.value = setTimeout(() => {
  1205. const currentBlackboard = yWritingBoardState.value?.get('blackboard') || false
  1206. sendMessage({
  1207. type: 'writing_board_update',
  1208. slideId: currentSlide.value.id,
  1209. dataURL: dataURL,
  1210. blackboard: currentBlackboard,
  1211. courseid: props.courseid
  1212. })
  1213. drawingDelayTimer.value = null
  1214. }, 5000) // 延迟5秒发送
  1215. }
  1216. }
  1217. // 应用画图共享状态(任意端)
  1218. const applyWritingBoardStateSnapshot = (snap: any) => {
  1219. console.log('📝 应用画图状态快照:', snap, '当前幻灯片ID:', currentSlide.value?.id, '跟随模式:', isFollowModeActive.value, '用户类型:', props.type)
  1220. if (!snap || !snap.dataURL || typeof snap.dataURL !== 'string' || snap.dataURL.trim() === '') {
  1221. writingBoardSyncDataURL.value = null
  1222. writingBoardSyncBlackboard.value = null
  1223. console.log('📝 画图状态为空,隐藏画图工具')
  1224. return
  1225. }
  1226. const slideId = snap.slideId
  1227. const dataURL = snap.dataURL
  1228. const blackboardState = snap.blackboard !== undefined ? snap.blackboard : null
  1229. // 只有当前幻灯片匹配时才显示
  1230. if (slideId && currentSlide.value && slideId === currentSlide.value.id) {
  1231. writingBoardSyncDataURL.value = dataURL
  1232. writingBoardSyncBlackboard.value = blackboardState
  1233. console.log('📝 画图数据匹配,显示画图工具,数据长度:', dataURL.length, '小黑板状态:', blackboardState, '显示条件:', {
  1234. type: props.type,
  1235. isFollowModeActive: isFollowModeActive.value,
  1236. hasData: !!writingBoardSyncDataURL.value
  1237. })
  1238. }
  1239. else {
  1240. writingBoardSyncDataURL.value = null
  1241. writingBoardSyncBlackboard.value = null
  1242. console.log('📝 画图数据不匹配,隐藏画图工具', { slideId, currentSlideId: currentSlide.value?.id })
  1243. }
  1244. }
  1245. // 切换激光笔模式
  1246. const toggleLaserPen = () => {
  1247. laserPen.value = !laserPen.value
  1248. console.log('激光笔状态:', laserPen.value ? '开启' : '关闭')
  1249. // 老师端广播激光笔开关
  1250. if (props.type == '1') {
  1251. sendMessage({ type: 'laser_toggle', enabled: laserPen.value, courseid: props.courseid })
  1252. // 同步到共享 Map,方便后来者拿到状态
  1253. if (yLaserState.value) {
  1254. if (laserPen.value) {
  1255. const state: any = { enabled: true }
  1256. if (lastSent.x >= 0 && lastSent.y >= 0) {
  1257. state.x = lastSent.x; state.y = lastSent.y
  1258. }
  1259. docSocket.value?.transact(() => {
  1260. Object.entries(state).forEach(([k, v]) => yLaserState.value.set(k, v as any))
  1261. })
  1262. }
  1263. else {
  1264. // 关闭时清空共享状态
  1265. docSocket.value?.transact(() => {
  1266. yLaserState.value.clear()
  1267. })
  1268. }
  1269. }
  1270. }
  1271. }
  1272. // 老师端移动时广播激光笔位置(百分比坐标)
  1273. let sendRafPending = false
  1274. let lastSent = { x: -1, y: -1 }
  1275. const handleLaserMove = (e: MouseEvent) => {
  1276. if (!(props.type == '1' && laserPen.value)) return
  1277. // 始终以中间画布 .slide-list-wrap 为基准,避免外层左右留白导致的偏差
  1278. const wrap = (viewerCanvasRef.value?.querySelector('.slide-list-wrap') as HTMLElement) || (e.currentTarget as HTMLElement)
  1279. const rect = wrap.getBoundingClientRect()
  1280. const x = Math.min(Math.max(e.clientX - rect.left, 0), rect.width)
  1281. const y = Math.min(Math.max(e.clientY - rect.top, 0), rect.height)
  1282. const xPct = (x / rect.width) * 100
  1283. const yPct = (y / rect.height) * 100
  1284. // 小幅度移动忽略(阈值 0.4%)
  1285. if (Math.abs(xPct - lastSent.x) < 0.4 && Math.abs(yPct - lastSent.y) < 0.4) return
  1286. lastSent = { x: xPct, y: yPct }
  1287. if (sendRafPending) return
  1288. sendRafPending = true
  1289. requestAnimationFrame(() => {
  1290. sendRafPending = false
  1291. // sendMessage 中已经直接更新 Map,不需要重复更新
  1292. sendMessage({ type: 'laser_move', x: lastSent.x, y: lastSent.y, courseid: props.courseid })
  1293. })
  1294. }
  1295. // 清空激光笔共享状态(仅创建人)
  1296. const clearLaserState = () => {
  1297. try {
  1298. if (props.type == '1' && isCreator.value && yLaserState.value) {
  1299. docSocket.value?.transact(() => {
  1300. yLaserState.value.clear()
  1301. })
  1302. sendMessage({ type: 'laser_toggle', enabled: false, courseid: props.courseid })
  1303. }
  1304. }
  1305. catch (e) {
  1306. console.warn('清空激光笔状态失败', e)
  1307. }
  1308. }
  1309. // 清空所有同步状态(仅创建人)
  1310. const clearAllSyncStates = () => {
  1311. try {
  1312. if (props.type == '1' && isCreator.value && docSocket.value) {
  1313. console.log('🧹 创建老师退出,清空所有同步状态')
  1314. docSocket.value.transact(() => {
  1315. // 清空普通消息
  1316. const messageArray = docSocket.value?.getArray?.('message')
  1317. if (messageArray) {
  1318. messageArray.delete(0, messageArray.length)
  1319. }
  1320. // 清空计时器消息数组
  1321. const timerMessagesArray = docSocket.value?.getArray?.('timerMessages')
  1322. if (timerMessagesArray) {
  1323. timerMessagesArray.delete(0, timerMessagesArray.length)
  1324. }
  1325. // 清空激光笔消息数组
  1326. const laserMessagesArray = docSocket.value?.getArray?.('laserMessages')
  1327. if (laserMessagesArray) {
  1328. laserMessagesArray.delete(0, laserMessagesArray.length)
  1329. }
  1330. // 清空画图消息数组
  1331. const writingBoardMessagesArray = docSocket.value?.getArray?.('writingBoardMessages')
  1332. if (writingBoardMessagesArray) {
  1333. writingBoardMessagesArray.delete(0, writingBoardMessagesArray.length)
  1334. }
  1335. // 清空计时器状态
  1336. const timerStateMap = docSocket.value?.getMap?.('timerState')
  1337. if (timerStateMap) {
  1338. timerStateMap.clear()
  1339. }
  1340. // 清空激光笔状态
  1341. const laserStateMap = docSocket.value?.getMap?.('laserState')
  1342. if (laserStateMap) {
  1343. laserStateMap.clear()
  1344. }
  1345. // 清空画图状态
  1346. const writingBoardStateMap = docSocket.value?.getMap?.('writingBoardState')
  1347. if (writingBoardStateMap) {
  1348. writingBoardStateMap.clear()
  1349. }
  1350. })
  1351. }
  1352. }
  1353. catch (e) {
  1354. console.warn('清空所有同步状态失败', e)
  1355. }
  1356. }
  1357. // 获取导入导出功能
  1358. const { readJSON, exportJSON2, getFile, getFile2 } = useImport()
  1359. // 根据iframe的URL查找对应的幻灯片索引
  1360. const findSlideIndexByIframeUrl = (iframeUrl: string): number => {
  1361. try {
  1362. console.log('查找iframe对应的幻灯片索引,iframe URL:', iframeUrl)
  1363. // 遍历所有幻灯片,查找包含该iframe URL的幻灯片
  1364. for (let i = 0; i < slides.value.length; i++) {
  1365. const slide = slides.value[i]
  1366. // 检查幻灯片的元素中是否有iframe
  1367. if (slide.elements && slide.elements.length > 0) {
  1368. for (const element of slide.elements) {
  1369. // 检查是否是iframe元素
  1370. if (element.type === ElementTypes.FRAME) {
  1371. // 检查iframe的src是否匹配
  1372. if (element.url === iframeUrl) {
  1373. console.log(`找到匹配的幻灯片,索引: ${i}, 幻灯片ID: ${slide.id}`)
  1374. return i
  1375. }
  1376. }
  1377. }
  1378. }
  1379. }
  1380. // 如果没有找到匹配的幻灯片,返回当前幻灯片索引
  1381. console.log('未找到匹配的幻灯片,使用当前幻灯片索引:', slideIndex.value)
  1382. return slideIndex.value
  1383. }
  1384. catch (error) {
  1385. console.error('查找幻灯片索引时出错:', error)
  1386. return slideIndex.value
  1387. }
  1388. }
  1389. // 处理iframe链接,为包含workPage的iframe添加必要参数
  1390. // 处理iframe链接,为包含workPage的iframe添加必要参数
  1391. const processIframeLinks = async () => {
  1392. try {
  1393. console.log('开始处理iframe链接')
  1394. console.log('当前props:', { courseid: props.courseid, userid: props.userid })
  1395. // 从slides数据中查找包含iframe的元素
  1396. let hasIframe = false
  1397. // 由于有异步操作,需整体用Promise.all处理
  1398. const updatedSlides = await Promise.all(
  1399. slides.value.map(async (slide, slideIndex) => {
  1400. if (slide.elements && slide.elements.length > 0) {
  1401. // 这里不能直接用async map,否则会导致类型不对
  1402. const updatedElements = await Promise.all(
  1403. slide.elements.map(async (element) => {
  1404. // 检查是否是iframe元素
  1405. if (element.type === ElementTypes.FRAME && element.url) {
  1406. const { element: updatedElement, hasIframe: updatedHasIframe } = await elementDone(element, slideIndex)
  1407. // hasIframe = updatedHasIframe
  1408. hasIframe = true
  1409. console.log('更新后的iframe元素:', updatedElement)
  1410. return {
  1411. ...updatedElement,
  1412. isDone: true
  1413. }
  1414. }
  1415. // 不是iframe元素或不需要处理,直接返回
  1416. return element
  1417. })
  1418. )
  1419. // 返回更新后的幻灯片
  1420. return {
  1421. ...slide,
  1422. elements: updatedElements
  1423. }
  1424. }
  1425. // 没有元素的幻灯片直接返回
  1426. return slide
  1427. })
  1428. )
  1429. if (hasIframe) {
  1430. console.log('找到iframe元素,更新slides数据')
  1431. // 更新store中的slides数据
  1432. slidesStore.setSlides(updatedSlides)
  1433. console.log('slides数据更新完成')
  1434. }
  1435. else {
  1436. console.log('未找到包含workPage的iframe元素')
  1437. }
  1438. console.log('iframe链接处理完成')
  1439. }
  1440. catch (error) {
  1441. console.error('处理iframe链接时出错:', error)
  1442. }
  1443. }
  1444. const elementDone = async (element: any, slideIndex: number) => {
  1445. let hasIframe = false
  1446. let _element = {...element}
  1447. let iframeSrc = element.url
  1448. const toolType = element.toolType
  1449. console.log('当前版本:', currentVersion)
  1450. // 替换beta环境域名
  1451. iframeSrc = iframeSrc.replace(/https?:\/\/beta\.pbl\.cocorobo\.cn/g, 'https://pbl.cocorobo.cn')
  1452. // 根据当前版本统一域名
  1453. const versionMap = {
  1454. cn: /cocorobo\.(hk|com)/g,
  1455. hk: /cocorobo\.(cn|com)/g,
  1456. com: /cocorobo\.(cn|hk)/g
  1457. }
  1458. const targetDomain = `cocorobo.${currentVersion}`
  1459. iframeSrc = iframeSrc.replace(versionMap[currentVersion], targetDomain)
  1460. if (iframeSrc.includes('setWorkPage')) {
  1461. iframeSrc = iframeSrc.replace(/setWorkPage/g, 'workPageNew')
  1462. }
  1463. if (iframeSrc.includes('workPage')) {
  1464. hasIframe = true
  1465. console.log(`处理幻灯片 ${slideIndex + 1} 中的iframe链接:`, iframeSrc)
  1466. try {
  1467. // 解析URL,处理hash部分
  1468. let baseUrl = iframeSrc
  1469. let hashPart = ''
  1470. // 分离base URL和hash部分
  1471. if (iframeSrc.includes('#')) {
  1472. const parts = iframeSrc.split('#')
  1473. baseUrl = parts[0]
  1474. hashPart = parts[1]
  1475. }
  1476. // 构建新的hash部分,添加参数
  1477. // 使用当前幻灯片索引作为task参数
  1478. let newHash = hashPart
  1479. if (newHash.includes('?')) {
  1480. // 如果hash中已经有查询参数,添加&
  1481. newHash += `&courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=${slideIndex}&tool=0`
  1482. }
  1483. else {
  1484. // 如果hash中没有查询参数,添加?
  1485. newHash += `?courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=${slideIndex}&tool=0`
  1486. }
  1487. // 构建新的URL
  1488. let newUrl = `${baseUrl}#${newHash}`
  1489. console.log(`幻灯片 ${slideIndex + 1} 的iframe链接已更新:`, newUrl)
  1490. if (window.location.href.includes('beta') && !newUrl.includes('beta')) {
  1491. newUrl = newUrl.replace('pbl.cocorobo.cn', 'beta.pbl.cocorobo.cn')
  1492. }
  1493. else if (newUrl.includes('beta') && !window.location.href.includes('beta')) {
  1494. newUrl = newUrl.replace('beta.pbl.cocorobo.cn', 'pbl.cocorobo.cn')
  1495. }
  1496. // 返回更新后的元素
  1497. _element = {
  1498. ...element,
  1499. url: newUrl
  1500. }
  1501. }
  1502. catch (error) {
  1503. console.error(`处理幻灯片 ${slideIndex + 1} 的iframe链接时出错:`, error)
  1504. return {
  1505. element: _element,
  1506. hasIframe
  1507. }
  1508. }
  1509. }
  1510. else if (iframeSrc.includes('aichat.cocorobo') || iframeSrc.includes('knowledge.cocorobo')) {
  1511. hasIframe = true
  1512. try {
  1513. // 解析URL,处理hash部分
  1514. let baseUrl = iframeSrc
  1515. let hashPart = ''
  1516. let isHashPart = false
  1517. // 分离base URL和hash部分
  1518. if (iframeSrc.includes('#')) {
  1519. const parts = iframeSrc.split('#')
  1520. baseUrl = parts[0]
  1521. hashPart = parts[1]
  1522. isHashPart = true
  1523. }
  1524. // 构建新的hash部分,添加参数
  1525. // 使用当前幻灯片索引作为task参数
  1526. let newHash = hashPart
  1527. if (newHash.includes('?')) {
  1528. // 如果hash中已经有查询参数,添加&
  1529. newHash += `&courseid=${props.courseid || ''}&layout=laptop`
  1530. }
  1531. else {
  1532. // 如果hash中没有查询参数,添加?
  1533. newHash += `?courseid=${props.courseid || ''}&layout=laptop`
  1534. }
  1535. // 构建新的URL
  1536. let newUrl = `${baseUrl}#${newHash}`
  1537. if (!isHashPart) {
  1538. newUrl = `${baseUrl}${newHash}`
  1539. }
  1540. console.log(`幻灯片 ${slideIndex + 1} 的iframe链接已更新:`, newUrl)
  1541. // 返回更新后的元素
  1542. _element = {
  1543. ...element,
  1544. url: newUrl
  1545. }
  1546. }
  1547. catch (error) {
  1548. console.error(`处理幻灯片 ${slideIndex + 1} 的iframe链接时出错:`, error)
  1549. return {
  1550. element: _element,
  1551. hasIframe
  1552. }
  1553. }
  1554. }
  1555. else if (toolType === 76) {
  1556. hasIframe = true
  1557. try {
  1558. // 解析URL,处理hash部分
  1559. let baseUrl = iframeSrc
  1560. let hashPart = ''
  1561. // 分离base URL和hash部分
  1562. if (iframeSrc.includes('#')) {
  1563. const parts = iframeSrc.split('#')
  1564. baseUrl = parts[0]
  1565. hashPart = parts[1]
  1566. }
  1567. // 构建新的hash部分,添加参数
  1568. // 使用当前幻灯片索引作为task参数
  1569. let newHash = hashPart
  1570. if (newHash.includes('?')) {
  1571. // 如果hash中已经有查询参数,添加&
  1572. newHash += `&mode=pptMode`
  1573. }
  1574. else {
  1575. // 如果hash中没有查询参数,添加?
  1576. newHash += `?mode=pptMode`
  1577. }
  1578. // 构建新的URL
  1579. const newUrl = `${baseUrl}#${newHash}`
  1580. console.log(`幻灯片 ${slideIndex + 1} 的iframe链接已更新:`, newUrl)
  1581. // 返回更新后的元素
  1582. _element = {
  1583. ...element,
  1584. url: newUrl
  1585. }
  1586. }
  1587. catch (error) {
  1588. console.error(`处理幻灯片 ${slideIndex + 1} 的iframe链接时出错:`, error)
  1589. return {
  1590. element: _element,
  1591. hasIframe
  1592. }
  1593. }
  1594. }
  1595. else if (toolType === 73) {
  1596. hasIframe = true
  1597. // 先尝试获取iframe的contentWindow,如果获取不到再使用HTML方式
  1598. try {
  1599. // 创建一个临时的iframe来测试是否能获取contentWindow
  1600. const tempIframe = document.createElement('iframe')
  1601. tempIframe.style.display = 'none'
  1602. tempIframe.src = iframeSrc
  1603. // 先将临时iframe添加到body,否则onload事件不会触发
  1604. document.body.appendChild(tempIframe)
  1605. // 等待iframe加载完成
  1606. await new Promise((resolve, reject) => {
  1607. tempIframe.onload = resolve
  1608. tempIframe.onerror = reject
  1609. // 可选:设置超时时间,避免长时间无响应
  1610. setTimeout(() => reject(new Error('Timeout')), 5000)
  1611. })
  1612. // 尝试获取contentWindow
  1613. if (tempIframe.contentWindow && tempIframe.contentWindow.document) {
  1614. console.log(`iframe ${iframeSrc} 可以获取contentWindow,使用直接加载方式`)
  1615. // 移除临时iframe
  1616. document.body.removeChild(tempIframe)
  1617. _element = {
  1618. ...element,
  1619. isHTML: false,
  1620. url: iframeSrc
  1621. }
  1622. }
  1623. else {
  1624. // 加载完成但无法获取contentWindow,也要移除iframe
  1625. document.body.removeChild(tempIframe)
  1626. }
  1627. }
  1628. catch (error) {
  1629. console.log(`iframe ${iframeSrc} 无法获取contentWindow,使用HTML方式:`, error)
  1630. // 如果无法获取contentWindow,使用HTML方式
  1631. let html = null
  1632. try {
  1633. html = await api.getHTML(iframeSrc)
  1634. console.log('getHTML 成功获取内容:', html)
  1635. }
  1636. catch (error) {
  1637. console.log(`getHTML 失败,尝试使用 getFile:`, error)
  1638. try {
  1639. const fileData = await getFile(iframeSrc)
  1640. if (fileData && fileData.data) {
  1641. const uint8Array = new Uint8Array(fileData.data)
  1642. html = new TextDecoder('utf-8').decode(uint8Array)
  1643. console.log('getFile 成功获取内容:', html)
  1644. }
  1645. }
  1646. catch (error2) {
  1647. console.log(`getFile 失败,尝试使用 getHTML:`, error2)
  1648. try {
  1649. const fileData2 = await getFile2(iframeSrc)
  1650. if (fileData2 && fileData2.data) {
  1651. const uint8Array = new Uint8Array(fileData2.data)
  1652. html = new TextDecoder('utf-8').decode(uint8Array)
  1653. console.log('getFile2 成功获取内容:', html)
  1654. }
  1655. }
  1656. catch (error3) {
  1657. console.error('getFile2 也失败:', error3)
  1658. console.error('无法获取内容: getFile、getFile2 和 getHTML 都失败了')
  1659. }
  1660. }
  1661. }
  1662. console.log(`处理幻灯片 ${slideIndex + 1} 中的iframe链接:`, iframeSrc)
  1663. _element = {
  1664. ...element,
  1665. isHTML: true,
  1666. url: html
  1667. }
  1668. }
  1669. }
  1670. return {
  1671. element: _element,
  1672. hasIframe
  1673. }
  1674. }
  1675. // 导入JSON功能
  1676. const importJSON = (jsonData: any) => {
  1677. try {
  1678. console.log('Student importJSON 开始执行')
  1679. const result = readJSON(jsonData, true)
  1680. if (result.success) {
  1681. console.log('Student importJSON 成功,开始重新渲染')
  1682. // 强制重新渲染:先隐藏组件
  1683. showSlideList.value = false
  1684. // 重新计算画布尺寸和缩放比例
  1685. nextTick(() => {
  1686. calculateScale()
  1687. // 延迟500ms后重新显示组件,确保重新渲染完成
  1688. setTimeout(() => {
  1689. showSlideList.value = true
  1690. // 只有当当前页面存在iframe时才获取作业数据
  1691. if (currentSlideHasIframe.value) { // && props.type == '1'
  1692. getWork()
  1693. }
  1694. selectCourseSLook(1)
  1695. console.log('组件重新渲染完成')
  1696. }, 500)
  1697. })
  1698. return true
  1699. }
  1700. console.error('Student importJSON 失败:', result.error)
  1701. return false
  1702. }
  1703. catch (error) {
  1704. console.error('Student importJSON 执行失败:', error)
  1705. return false
  1706. }
  1707. }
  1708. // 导出JSON功能
  1709. const exportJSON = () => {
  1710. try {
  1711. console.log('Student exportJSON 开始执行,调用 useImport.exportJSON2')
  1712. // 直接调用 useImport 中的 exportJSON2 函数
  1713. const exportData = exportJSON2()
  1714. if (exportData) {
  1715. return exportData
  1716. }
  1717. console.error('Student exportJSON 失败: exportJSON2 返回空数据')
  1718. return false
  1719. }
  1720. catch (error) {
  1721. console.error('Student exportJSON 执行失败:', error)
  1722. return false
  1723. }
  1724. }
  1725. // 返回编辑器
  1726. const backToEditor = () => {
  1727. // 通过路由跳转到编辑模式
  1728. window.location.href = '/'
  1729. }
  1730. const submitWork = async (slideIndex: number, atool: string, content: string, type: string) => {
  1731. const res = await api.submitWork({
  1732. uid: props.userid as string,
  1733. cid: props.courseid as string,
  1734. stage: '0',
  1735. task: String(slideIndex), // 转为字符串
  1736. tool: '0',
  1737. atool: atool,
  1738. content: content,
  1739. type: type
  1740. })
  1741. getWork()
  1742. console.log(res)
  1743. }
  1744. // 文件上传到AWS S3的函数
  1745. const uploadFile = (file: File): Promise<string> => {
  1746. return new Promise((resolve, reject) => {
  1747. try {
  1748. // 检查AWS SDK是否可用
  1749. if (!(window as any).AWS) {
  1750. reject(new Error('AWS SDK not loaded'))
  1751. return
  1752. }
  1753. const credentials = {
  1754. accessKeyId: 'AKIATLPEDU37QV5CHLMH',
  1755. secretAccessKey: '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'
  1756. }
  1757. // 配置AWS
  1758. ;(window as any).AWS.config.update(credentials)
  1759. ;(window as any).AWS.config.region = 'cn-northwest-1'
  1760. // 创建S3实例
  1761. const bucket = new (window as any).AWS.S3({ params: { Bucket: 'ccrb' } })
  1762. if (file) {
  1763. // 生成唯一的文件名
  1764. const fileExtension = file.name.split('.').pop()
  1765. const fileName = `${file.name.split('.')[0]}_${Date.now()}.${fileExtension}`
  1766. const params = {
  1767. Key: fileName,
  1768. ContentType: file.type,
  1769. Body: file,
  1770. ACL: 'public-read'
  1771. }
  1772. const options = {
  1773. partSize: 5 * 1024 * 1024, // 2GB分片
  1774. queueSize: 2,
  1775. leavePartsOnError: true
  1776. }
  1777. bucket
  1778. .upload(params, options)
  1779. .on('httpUploadProgress', (evt: any) => {
  1780. // 这里可以添加进度条逻辑
  1781. const progress = Math.round((evt.loaded * 100) / evt.total)
  1782. console.log(`Uploaded: ${progress}%`)
  1783. })
  1784. .send((err: any, data: any) => {
  1785. if (err) {
  1786. console.error('Upload failed:', err)
  1787. message.error(lang.ssFileUploadFail)
  1788. reject(err)
  1789. }
  1790. else {
  1791. console.log('Upload successful:', data.Location)
  1792. resolve(data.Location)
  1793. }
  1794. })
  1795. }
  1796. else {
  1797. reject(new Error('No file provided'))
  1798. }
  1799. }
  1800. catch (error) {
  1801. console.error('Upload error:', error)
  1802. reject(error)
  1803. }
  1804. })
  1805. }
  1806. // 作业提交功能(优化版)
  1807. const handleHomeworkSubmit = async () => {
  1808. console.log('作业提交按钮被点击')
  1809. // 防抖:如果正在提交中,直接返回
  1810. if (isSubmitting.value) {
  1811. console.log('作业正在提交中,忽略重复点击')
  1812. return
  1813. }
  1814. isSubmitting.value = true
  1815. let homeworkContent: string = lang.ssHwSubmit // 默认作业内容
  1816. let hasSubmitWork = false // 标记是否成功提交作业
  1817. try {
  1818. // 获取所有iframe元素
  1819. const iframes = document.querySelectorAll('.viewer-canvas .screen-slide')[slideIndex.value].querySelectorAll('iframe')
  1820. console.log('找到iframe元素数量:', iframes.length)
  1821. if (iframes.length === 0) {
  1822. message.warning('当前页面没有找到iframe元素')
  1823. return
  1824. }
  1825. for (let i = 0; i < iframes.length; i++) {
  1826. const iframe = iframes[i] as HTMLIFrameElement
  1827. const iframeSrc = iframe.src
  1828. console.log(`iframe ${i + 1} 链接:`, iframeSrc)
  1829. // 检查iframe链接是否包含workPage
  1830. if (iframeSrc && iframeSrc.includes('workPage')) {
  1831. console.log('找到包含workPage的iframe,尝试执行submitWork')
  1832. try {
  1833. const iframeWindow = iframe.contentWindow as Window & { submitWork?: (...args: any[]) => unknown }
  1834. if (iframeWindow && typeof iframeWindow.submitWork === 'function') {
  1835. console.log('执行iframe中的submitWork方法,参数可变')
  1836. const iframeSlideIndex = slideIndex.value
  1837. const submitArgs = [iframeSlideIndex]
  1838. // 支持同步和异步submitWork
  1839. const result = await iframeWindow.submitWork(...submitArgs)
  1840. console.log('submitWork同步执行完成')
  1841. // 尝试从结果中获取作业内容
  1842. if (result && typeof result === 'object') {
  1843. homeworkContent = JSON.stringify(result)
  1844. }
  1845. else if (result) {
  1846. homeworkContent = String(result)
  1847. }
  1848. else {
  1849. homeworkContent = lang.ssHwSubmitWp
  1850. }
  1851. messageInstructionRef.value.success(lang.ssHwSubmitSucc)
  1852. hasSubmitWork = true
  1853. // 发送作业提交成功的socket消息
  1854. sendMessage({
  1855. type: 'homework_submitted',
  1856. courseid: props.courseid,
  1857. slideIndex: slideIndex.value,
  1858. userid: props.userid
  1859. })
  1860. break
  1861. }
  1862. else {
  1863. console.log('iframe中没有找到submitWork方法')
  1864. isSubmitting.value = false
  1865. }
  1866. }
  1867. catch (error) {
  1868. console.error('访问iframe内容时出错:', error)
  1869. isSubmitting.value = false
  1870. }
  1871. }
  1872. else if (iframeSrc && (iframeSrc.includes('aichat.cocorobo') || iframeSrc.includes('knowledge.cocorobo'))) {
  1873. console.log('找到包含aichat.cocorobo或knowledge.cocorobo的iframe,尝试执行submitWork')
  1874. // 由于TS类型检查,需通过 any 绕过类型限制
  1875. const iframeWindow = iframe.contentWindow as any
  1876. if (iframeWindow && iframeWindow.exposed_outputs) {
  1877. if (iframeWindow.exposed_outputs.length === 0) {
  1878. message.warning('没有找到作业内容')
  1879. hasSubmitWork = true
  1880. continue
  1881. }
  1882. console.log('执行iframe中的submitWork方法,参数可变')
  1883. const iframeSlideIndex = slideIndex.value
  1884. const jsonString = JSON.stringify(iframeWindow.exposed_outputs)
  1885. // 将 JSON 字符串转成文件并上传
  1886. try {
  1887. const blob = new Blob([jsonString], { type: 'application/json' })
  1888. const file = new File([blob], `ai_work_${Date.now()}.json`, { type: 'application/json' })
  1889. const fileUrl = await uploadFile(file)
  1890. console.log('文件上传成功,链接:', fileUrl)
  1891. homeworkContent = fileUrl // 保存AI作业内容
  1892. // 使用上传后的链接提交作业
  1893. await submitWork(iframeSlideIndex, '72', fileUrl, '20')
  1894. messageInstructionRef.value.success(lang.ssHwSubmitSucc)
  1895. hasSubmitWork = true
  1896. // 发送作业提交成功的socket消息
  1897. sendMessage({
  1898. type: 'homework_submitted',
  1899. courseid: props.courseid,
  1900. slideIndex: slideIndex.value,
  1901. userid: props.userid
  1902. })
  1903. }
  1904. catch (error) {
  1905. console.error('文件上传失败:', error)
  1906. isSubmitting.value = false
  1907. message.error(lang.ssHwSubmitRetry)
  1908. }
  1909. }
  1910. }
  1911. else if (slides.value[slideIndex.value].elements.some((element: any) => element.isHTML)) {
  1912. message.info(lang.ssTryingScreenshot)
  1913. console.log('尝试截图当前页面并提交ISHTML')
  1914. // return
  1915. try {
  1916. // 尝试使用html2canvas,对iframe支持更好
  1917. let imageData: string
  1918. const screenSlides = document.querySelectorAll('.viewer-canvas .screen-slide')
  1919. let iframeElement: HTMLIFrameElement | null = null
  1920. let iframeBody: HTMLElement | null = null
  1921. let iframehtml: HTMLElement | null = null
  1922. // 获取iframe元素
  1923. if (
  1924. screenSlides &&
  1925. screenSlides[slideIndex.value] &&
  1926. screenSlides[slideIndex.value].querySelector('iframe')
  1927. ) {
  1928. iframeElement = screenSlides[slideIndex.value].querySelector('iframe') as HTMLIFrameElement
  1929. }
  1930. else {
  1931. message.error(lang.ssFailedGetIframe)
  1932. throw new Error('未能获取到iframe元素,无法截图')
  1933. }
  1934. // 获取iframe内部的body元素(同源)
  1935. if (
  1936. iframeElement.contentWindow &&
  1937. iframeElement.contentWindow.document &&
  1938. iframeElement.contentWindow.document.body
  1939. ) {
  1940. // 获取页面的所有注释节点
  1941. const comments = []
  1942. const childNodes = iframeElement.contentWindow.document.createTreeWalker(iframeElement.contentWindow.document.body, NodeFilter.SHOW_COMMENT, null)
  1943. while (childNodes.nextNode()) {
  1944. comments.push(childNodes.currentNode)
  1945. }
  1946. // 移除所有注释节点
  1947. comments.forEach(comment => {
  1948. comment?.parentNode?.removeChild(comment)
  1949. })
  1950. iframeBody = iframeElement.contentWindow.document.body as HTMLElement
  1951. iframehtml = iframeElement.contentWindow.document.getElementsByTagName('html')[0] as HTMLElement
  1952. }
  1953. else {
  1954. message.error(lang.ssFailedGetIframeBody)
  1955. throw new Error('未能获取到iframe的body元素,无法截图')
  1956. }
  1957. try {
  1958. const a = iframeBody.getElementsByTagName('img')
  1959. const b = iframeBody.getElementsByTagName('video')
  1960. // const c = iframeBody.getElementsByTagName('canvas')
  1961. iframeBody.style.cssText += 'width:100%;height:100%;position:absolute;top:0;left:0;'
  1962. iframehtml.style.cssText += 'width:100%;height:100%;position:absolute;top:0;left:0;'
  1963. for (let i = 0;i < a.length;i++) {
  1964. a[i].crossOrigin = 'anonymous'
  1965. }
  1966. for (let i = 0;i < b.length;i++) {
  1967. b[i].crossOrigin = 'anonymous'
  1968. }
  1969. // 直接对iframe内部的body进行截图
  1970. const html2canvas = await import('html2canvas')
  1971. const canvas = await html2canvas.default(iframeBody, {
  1972. // useCORS: true,
  1973. // allowTaint: true,
  1974. // scale: 1,
  1975. // backgroundColor: '#ffffff',
  1976. // logging: false,
  1977. // foreignObjectRendering: true,
  1978. // removeContainer: true
  1979. scale: 2, // 提高清晰度
  1980. allowTaint: false, // 是否允许跨域污染画布
  1981. useCORS: true, // 尝试跨域加载图片
  1982. logging: true,
  1983. })
  1984. imageData = canvas.toDataURL('image/png', 0.95)
  1985. console.log('成功截图iframe内部内容')
  1986. }
  1987. catch (html2canvasError) {
  1988. console.log('html2canvas失败,尝试html-to-image:', html2canvasError)
  1989. message.error(lang.ssHtml2canvasFailed + html2canvasError)
  1990. try {
  1991. // 回退到html-to-image
  1992. const { toPng } = await import('html-to-image')
  1993. imageData = await toPng(iframeBody, {
  1994. quality: 0.95,
  1995. backgroundColor: '#ffffff',
  1996. filter: (node) => {
  1997. if (node.tagName === 'SCRIPT' || node.tagName === 'STYLE') {
  1998. return false
  1999. }
  2000. return true
  2001. }
  2002. })
  2003. console.log('使用html-to-image截图成功')
  2004. }
  2005. catch (htmlToImageError) {
  2006. console.log('html-to-image也失败了,使用canvas绘制方案:', htmlToImageError)
  2007. message.error(lang.ssHtmlToImageFailed + htmlToImageError)
  2008. message.error(lang.ssShotFail)
  2009. return
  2010. /*
  2011. // 最后的备用方案:使用canvas绘制
  2012. const canvas = document.createElement('canvas')
  2013. const ctx = canvas.getContext('2d')
  2014. if (ctx) {
  2015. canvas.width = iframeElement.offsetWidth || 800
  2016. canvas.height = iframeElement.offsetHeight || 600
  2017. // 绘制背景
  2018. const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height)
  2019. gradient.addColorStop(0, '#f8f9fa')
  2020. gradient.addColorStop(1, '#e9ecef')
  2021. ctx.fillStyle = gradient
  2022. ctx.fillRect(0, 0, canvas.width, canvas.height)
  2023. // 绘制边框
  2024. ctx.strokeStyle = '#dee2e6'
  2025. ctx.lineWidth = 3
  2026. ctx.strokeRect(2, 2, canvas.width - 4, canvas.height - 4)
  2027. // 绘制内边框
  2028. ctx.strokeStyle = '#ffffff'
  2029. ctx.lineWidth = 1
  2030. ctx.strokeRect(5, 5, canvas.width - 10, canvas.height - 10)
  2031. // 绘制iframe图标
  2032. ctx.fillStyle = '#6c757d'
  2033. ctx.font = 'bold 48px Arial'
  2034. ctx.textAlign = 'center'
  2035. ctx.fillText('', canvas.width / 2, canvas.height / 2 - 40)
  2036. // 绘制标题
  2037. ctx.font = 'bold 20px Arial'
  2038. ctx.fillStyle = '#495057'
  2039. ctx.fillText('iframe内容', canvas.width / 2, canvas.height / 2 + 20)
  2040. // 绘制URL
  2041. const src = iframeElement.srcf
  2042. if (src) {
  2043. ctx.font = '14px Arial'
  2044. ctx.fillStyle = '#6c757d'
  2045. const url = src.length > 80 ? src.substring(0, 80) + '...' : src
  2046. ctx.fillText(url, canvas.width / 2, canvas.height / 2 + 50)
  2047. }
  2048. // 绘制提示信息
  2049. ctx.font = '12px Arial'
  2050. ctx.fillStyle = '#adb5bd'
  2051. ctx.fillText('(截图失败)', canvas.width / 2, canvas.height / 2 + 80)
  2052. // 绘制装饰性元素
  2053. ctx.strokeStyle = '#dee2e6'
  2054. ctx.lineWidth = 1
  2055. ctx.setLineDash([5, 5])
  2056. ctx.strokeRect(20, 20, canvas.width - 40, canvas.height - 40)
  2057. ctx.setLineDash([])
  2058. imageData = canvas.toDataURL('image/png', 0.95)
  2059. console.log('使用canvas绘制方案截图成功')
  2060. }
  2061. else {
  2062. throw new Error('无法创建canvas上下文')
  2063. }*/
  2064. }
  2065. }
  2066. const _a = iframeBody.getElementsByTagName('img')
  2067. const _b = iframeBody.getElementsByTagName('video')
  2068. for (let i = 0; i < _a.length; i++) {
  2069. _a[i].removeAttribute('crossorigin')
  2070. }
  2071. for (let i = 0; i < _b.length; i++) {
  2072. _b[i].removeAttribute('crossorigin')
  2073. }
  2074. // 将base64字符串转换为File对象
  2075. const base64ToFile = (base64String: string, filename: string): File => {
  2076. const arr = base64String.split(',')
  2077. const mime = arr[0].match(/:(.*?);/)?.[1] || 'image/png'
  2078. const bstr = atob(arr[1])
  2079. let n = bstr.length
  2080. const u8arr = new Uint8Array(n)
  2081. while (n--) {
  2082. u8arr[n] = bstr.charCodeAt(n)
  2083. }
  2084. return new File([u8arr], filename, { type: mime })
  2085. }
  2086. const imageFile = base64ToFile(imageData, `screenshot_${Date.now()}.png`)
  2087. const imageUrl = await uploadFile(imageFile)
  2088. homeworkContent = imageUrl // 保存截图URL作为作业内容
  2089. // 提交截图
  2090. await submitWork(slideIndex.value, '73', imageUrl, '1') // 73表示截图工具,21表示图片类型
  2091. console.log('messageInstructionRef', messageInstructionRef.value)
  2092. messageInstructionRef.value.success(lang.ssShotSucc)
  2093. hasSubmitWork = true
  2094. // 发送作业提交成功的socket消息
  2095. sendMessage({
  2096. type: 'homework_submitted',
  2097. courseid: props.courseid,
  2098. slideIndex: slideIndex.value,
  2099. userid: props.userid
  2100. })
  2101. }
  2102. catch (error) {
  2103. message.error(lang.ssScreenshotSubmitFailed + error)
  2104. console.error('截图提交失败:', error)
  2105. isSubmitting.value = false
  2106. message.error(lang.ssShotFail)
  2107. }
  2108. }
  2109. else {
  2110. // message.info('尝试截图当前页面并提交')
  2111. const screenSlides = document.querySelectorAll('.viewer-canvas .screen-slide')
  2112. let iframeElement: HTMLIFrameElement | null = null
  2113. // 获取iframe元素
  2114. if (
  2115. screenSlides &&
  2116. screenSlides[slideIndex.value] &&
  2117. screenSlides[slideIndex.value].querySelector('iframe')
  2118. ) {
  2119. iframeElement = screenSlides[slideIndex.value].querySelector('iframe') as HTMLIFrameElement
  2120. }
  2121. else {
  2122. message.error(lang.ssFailedGetIframe)
  2123. throw new Error('未能获取到iframe元素,无法截图')
  2124. }
  2125. // 获取iframe内部的body元素(同源)
  2126. if (
  2127. iframeElement.contentWindow &&
  2128. iframeElement.contentWindow.document &&
  2129. iframeElement.contentWindow.document.body
  2130. ) {
  2131. iframeElement.contentWindow.document.body.style.cssText += 'width:100%;height:100%;position:absolute;top:0;left:0;'
  2132. iframeElement.contentWindow.document.getElementsByTagName('html')[0].style.cssText += 'width:100%;height:100%;position:absolute;top:0;left:0;'
  2133. try {
  2134. isSubmitting.value = true
  2135. const _ajs = iframeElement.contentWindow.document.createElement('script')
  2136. _ajs.type = 'text/javascript'
  2137. _ajs.innerHTML =
  2138. 'var _js = document.createElement("script");\n' +
  2139. '_js.type="text/javascript";\n' +
  2140. '_js.src="https://beta.cloud.cocorobo.cn/js/Common/html2canvas-pro.min.js";\n' +
  2141. '_js.onload = function(){\n' +
  2142. ' var a = document.getElementsByTagName("img")\n' +
  2143. ' for(var i = 0;i<a.length;i++){a[i].crossOrigin="anonymous"}\n' +
  2144. ' html2canvas(document.body, {scale: 2,allowTaint: false,useCORS: true,logging: true,}).then(canvas => {\n' +
  2145. ' var base64Url = canvas.toDataURL("image/png");\n' +
  2146. 'var base64 = "<img src=" + base64Url + " />"\n' +
  2147. 'var file = dataURLtoFile_shishi(base64Url, "截图")\n' +
  2148. 'beforeUpload_shishi(file,' +
  2149. "'" +
  2150. props.userid +
  2151. "'" +
  2152. ', ' +
  2153. "'" +
  2154. props.courseid +
  2155. "'" +
  2156. ', ' +
  2157. "'" +
  2158. slideIndex.value +
  2159. "'" +
  2160. ', ' +
  2161. "'0'" +
  2162. ', ' +
  2163. "'73'" +
  2164. ', ' +
  2165. "'1'" +
  2166. ')\n' +
  2167. ' });\n' +
  2168. '}\n' +
  2169. 'document.head.appendChild(_js);\n'
  2170. iframeElement.contentWindow.document.head.appendChild(_ajs)
  2171. return
  2172. }
  2173. catch (error) {
  2174. message.error(lang.ssFailedGetIframeBodyElement)
  2175. throw new Error('获取iframe内部body元素失败,无法截图')
  2176. }
  2177. }
  2178. }
  2179. }
  2180. if (!hasSubmitWork) {
  2181. message.info(lang.ssHwNoFunc)
  2182. }
  2183. isSubmitting.value = false
  2184. }
  2185. catch (error) {
  2186. console.error('作业提交过程中出错:', error)
  2187. message.error('作业提交过程中出错:' + error)
  2188. message.error(lang.ssHwSubmitFail)
  2189. isSubmitting.value = false
  2190. addOp3(1, new Date().getTime(), { courseid: props.courseid, homeworkContent }, 'error')
  2191. }
  2192. finally {
  2193. // isSubmitting.value = false
  2194. getWork(true)
  2195. if (hasSubmitWork) {
  2196. addOp3(1, new Date().getTime(), { courseid: props.courseid, homeworkContent }, 'success')
  2197. }
  2198. else {
  2199. addOp3(1, new Date().getTime(), { courseid: props.courseid, homeworkContent: '未找到可用的作业提交功能' }, 'error')
  2200. }
  2201. }
  2202. }
  2203. const successSubmit = () => {
  2204. messageInstructionRef.value.success(lang.ssHwSubmitSucc)
  2205. sendMessage({
  2206. type: 'homework_submitted',
  2207. courseid: props.courseid,
  2208. slideIndex: slideIndex.value,
  2209. userid: props.userid
  2210. })
  2211. isSubmitting.value = false
  2212. getWork(true)
  2213. }
  2214. // 刷新iframe功能
  2215. const handleRefreshPage = () => {
  2216. console.log('刷新iframe按钮被点击')
  2217. try {
  2218. // 获取当前幻灯片中的所有iframe元素
  2219. const iframes = document.querySelectorAll('.viewer-canvas .screen-slide')[slideIndex.value].querySelectorAll('iframe')
  2220. console.log('找到iframe元素数量:', iframes.length)
  2221. if (iframes.length === 0) {
  2222. message.warning(lang.ssNoIframe)
  2223. return
  2224. }
  2225. let refreshedCount = 0
  2226. // 遍历所有iframe并刷新
  2227. for (let i = 0; i < iframes.length; i++) {
  2228. const iframe = iframes[i] as HTMLIFrameElement
  2229. // 优化刷新方式,避免闪烁和兼容 srcdoc 场景
  2230. if (iframe.src) {
  2231. // 仅当有src属性时刷新
  2232. const originalSrc = iframe.src
  2233. // 通过重新赋值src实现刷新,避免先清空再赋值导致的闪烁
  2234. iframe.src = ''
  2235. setTimeout(() => {
  2236. iframe.src = originalSrc
  2237. console.log(`刷新iframe ${i + 1}:`, originalSrc)
  2238. }, 50)
  2239. refreshedCount++
  2240. }
  2241. else if (iframe.srcdoc) {
  2242. // srcdoc场景下,重新赋值srcdoc内容
  2243. const originalSrcdoc = iframe.srcdoc
  2244. iframe.srcdoc = ''
  2245. setTimeout(() => {
  2246. iframe.srcdoc = originalSrcdoc
  2247. console.log(`iframe ${i + 1} (srcdoc) 刷新完成`)
  2248. }, 50)
  2249. refreshedCount++
  2250. }
  2251. }
  2252. if (refreshedCount > 0) {
  2253. message.success(lang.ssRefreshDone)
  2254. // 如果当前页面有iframe,重新获取作业数据
  2255. if (currentSlideHasIframe.value && props.type == '1') {
  2256. setTimeout(() => {
  2257. getWork()
  2258. }, 500) // 延迟500ms等待iframe加载完成
  2259. }
  2260. isSubmitting.value = false
  2261. }
  2262. else {
  2263. message.info(lang.ssNoIframeRef)
  2264. }
  2265. }
  2266. catch (error) {
  2267. console.error('刷新iframe时出错:', error)
  2268. message.error(lang.ssRefreshFail)
  2269. }
  2270. }
  2271. // 获取作业提交按钮的右侧位置
  2272. const getHomeworkButtonRight = () => {
  2273. if (isFullscreen.value) {
  2274. return 70 // 全屏时按钮在右侧30px
  2275. }
  2276. if (props.type === '1') {
  2277. // 展开回答结果:按钮更靠左;收起时:按钮更靠右侧
  2278. return workPanelCollapsed.value ? 100 : 430
  2279. }
  2280. return 30 // type=2时按钮在右侧30px
  2281. }
  2282. // 获取刷新按钮的右侧位置
  2283. const getRefreshButtonRight = () => {
  2284. if (isFullscreen.value) {
  2285. return 160 // 全屏时按钮在右侧150px
  2286. }
  2287. if (props.type === '1') {
  2288. // 展开回答结果:按钮更靠左;收起时:按钮更靠右侧
  2289. return workPanelCollapsed.value ? 190 : 560
  2290. }
  2291. return 160 // type=2时按钮在右侧150px
  2292. }
  2293. // 键盘快捷键
  2294. const handleKeydown = (e: KeyboardEvent) => {
  2295. // 如果事件发生在输入框中,不处理快捷键
  2296. const target = e.target as HTMLElement
  2297. if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {
  2298. return
  2299. }
  2300. console.log('键盘事件:', e.key)
  2301. switch (e.key) {
  2302. case 'ArrowLeft':
  2303. e.preventDefault()
  2304. if (!isFollowModeActive.value || props.type == '1') {
  2305. previousSlide()
  2306. }
  2307. break
  2308. case 'PageUp':
  2309. case 'ArrowUp':
  2310. e.preventDefault()
  2311. if (!isFollowModeActive.value || props.type == '1') {
  2312. previousSlide()
  2313. }
  2314. break
  2315. case 'ArrowRight':
  2316. e.preventDefault()
  2317. if (!isFollowModeActive.value || props.type == '1') {
  2318. nextSlide()
  2319. }
  2320. break
  2321. case 'PageDown':
  2322. case 'ArrowDown':
  2323. case ' ':
  2324. e.preventDefault()
  2325. if (!isFollowModeActive.value || props.type == '1') {
  2326. nextSlide()
  2327. }
  2328. break
  2329. case 'F11':
  2330. e.preventDefault()
  2331. enterFullscreen()
  2332. break
  2333. case 'Escape':
  2334. if (document.fullscreenElement) {
  2335. document.exitFullscreen()
  2336. }
  2337. break
  2338. default:
  2339. break
  2340. }
  2341. }
  2342. // 事件处理函数
  2343. const handleSlidesDataUpdated = () => {
  2344. console.log('收到 slidesDataUpdated 事件')
  2345. // 强制重新渲染:先隐藏组件
  2346. showSlideList.value = false
  2347. nextTick(() => {
  2348. calculateScale()
  2349. // 延迟500ms后重新显示组件,确保重新渲染完成
  2350. setTimeout(() => {
  2351. showSlideList.value = true
  2352. console.log('组件重新渲染完成')
  2353. // 重新处理iframe链接
  2354. processIframeLinks()
  2355. }, 500)
  2356. console.log('slidesDataUpdated 事件处理完成')
  2357. })
  2358. }
  2359. const handleViewportSizeUpdated = (event: any) => {
  2360. console.log('收到 viewportSizeUpdated 事件:', event.detail)
  2361. // 重新计算缩放比例
  2362. nextTick(() => {
  2363. calculateScale()
  2364. console.log('viewportSizeUpdated 事件处理完成')
  2365. })
  2366. }
  2367. const pptJsonFileid = ref<string>('')
  2368. // 上传文件
  2369. const uploadFile2 = async (file: File, pptid: string): Promise<void> => {
  2370. try {
  2371. const uuid = generateUUID()
  2372. const formData = new FormData()
  2373. const timestamp = Date.now()
  2374. const finalExtension = file.name.split('.').pop()?.toLowerCase() || ''
  2375. const baseName = file.name.slice(0, -(finalExtension.length + 1))
  2376. formData.append(
  2377. 'file',
  2378. new File([file], `${baseName}${timestamp}.${finalExtension}`)
  2379. )
  2380. formData.append('collection_ids', JSON.stringify([]))
  2381. formData.append('id', uuid)
  2382. formData.append('metadata', JSON.stringify({ title: file.name }))
  2383. formData.append('ingestion_mode', 'fast')
  2384. formData.append('run_with_orchestration', 'true')
  2385. // 同步知识库
  2386. await axios.post(
  2387. 'https://r2rserver.cocorobo.cn/v3/documents',
  2388. formData,
  2389. {
  2390. headers: {
  2391. 'Content-Type': 'multipart/form-data',
  2392. },
  2393. }
  2394. )
  2395. const ptype = '1' // 根据实际业务定义类型
  2396. const fileid = uuid // 如果需要唯一fileid可以和pptid保持一致或按需更改
  2397. await axios.post(`${API_URL}addPPTFile`, [{
  2398. pptid: pptid,
  2399. ptype: ptype,
  2400. fileid: fileid,
  2401. classid: '',
  2402. task: '',
  2403. tool: ''
  2404. }])
  2405. }
  2406. catch (err) {
  2407. console.error(err)
  2408. throw err
  2409. }
  2410. }
  2411. const checkPPTFile = async (jsonObj: any) => {
  2412. const res = await api.getPPTFile(props.courseid as string, props.cid as string)
  2413. console.log(res)
  2414. const data1 = res[0]
  2415. const data2 = res[1]
  2416. const data3 = res[2]
  2417. console.log(data1, data2, data3)
  2418. if (res[0].length) {
  2419. pptJsonFileid.value = data1[0].fileid
  2420. }
  2421. else {
  2422. const pptJsonFile = new File([jsonObj], courseDetail.value.title + '.txt', { type: 'text/plain' })
  2423. uploadFile2(pptJsonFile, props.courseid as string)
  2424. }
  2425. }
  2426. const getCourseDetail = async () => {
  2427. isLoading.value = true
  2428. try {
  2429. const res = await api.getCourseDetail(props.courseid as string)
  2430. console.log(res)
  2431. const courseData = res[0][0]
  2432. courseDetail.value = courseData
  2433. selectWorksStudent()
  2434. checkIsCreator()
  2435. const pptJSONUrl = JSON.parse(courseData.chapters).pptData ? JSON.parse(courseData.chapters).pptData : ''
  2436. aiAssistant.value = JSON.parse(courseData.chapters).aiAssistant ? JSON.parse(courseData.chapters).aiAssistant : false
  2437. console.log(pptJSONUrl)
  2438. if (pptJSONUrl) {
  2439. const pptdata = await getFile(pptJSONUrl)
  2440. // pptdata.data 是 ArrayBuffer,需要先转成字符串再解析为 JSON
  2441. let jsonStr = ''
  2442. if (pptdata && pptdata.data) {
  2443. // 先将 ArrayBuffer 转为字符串
  2444. const uint8Array = new Uint8Array(pptdata.data)
  2445. jsonStr = new TextDecoder('utf-8').decode(uint8Array)
  2446. try {
  2447. const jsonObj = JSON.parse(jsonStr)
  2448. // 生成每页幻灯片的内容描述
  2449. const pptContent = []
  2450. if (jsonObj.slides) {
  2451. jsonObj.slides.forEach((slide: any, index: number) => {
  2452. let slideContent = ''
  2453. if (slide.elements) {
  2454. // 提取文本内容(包括普通文本和形状文本)
  2455. const allTextElements = slide.elements.filter((element: any) =>
  2456. element.type === 'text' || (element.type === 'shape' && element.text?.content)
  2457. )
  2458. if (allTextElements.length > 0) {
  2459. slideContent = allTextElements
  2460. .map((element: any) => {
  2461. const content = element.type === 'text' ? element.content : element.text.content
  2462. return content.replace(/<[^>]*>/g, '')
  2463. })
  2464. .join(' ')
  2465. }
  2466. }
  2467. pptContent.push(`第${index + 1}页: ${slideContent || '内容为空'}`)
  2468. })
  2469. }
  2470. const contentDescription = pptContent.join('\n')
  2471. checkPPTFile(contentDescription)
  2472. importJSON(jsonObj)
  2473. }
  2474. catch (e) {
  2475. console.error('解析pptdata.data失败:', e)
  2476. }
  2477. }
  2478. }
  2479. getWorkId()
  2480. autoSwitchToAvailablePanel()
  2481. }
  2482. catch (error) {
  2483. console.error('获取课程详情失败:', error)
  2484. message.error(lang.ssFetchCourseFail)
  2485. isLoading.value = false
  2486. }
  2487. finally {
  2488. isLoading.value = false
  2489. // if (props.type == '2') {
  2490. // console.log('判断是否是学生进入全屏')
  2491. // function panFull() {
  2492. // console.log('判断是否是学生进入全屏111')
  2493. // if (!document.fullscreenElement) {
  2494. // setTimeout(() => {
  2495. // if (!document.fullscreenElement) {
  2496. // if (document.documentElement.requestFullscreen) {
  2497. // document.documentElement.requestFullscreen()
  2498. // }
  2499. // else if (document.documentElement.mozRequestFullScreen) { // Firefox
  2500. // document.documentElement.mozRequestFullScreen()
  2501. // }
  2502. // else if (document.documentElement.webkitRequestFullscreen) { // Chrome, Safari and Opera
  2503. // document.documentElement.webkitRequestFullscreen()
  2504. // }
  2505. // else if (document.documentElement.msRequestFullscreen) { // IE/Edge
  2506. // document.documentElement.msRequestFullscreen()
  2507. // }
  2508. // panFull()
  2509. // }
  2510. // }, 50)
  2511. // }
  2512. // }
  2513. // nextTick(() => {
  2514. // setTimeout(() => {
  2515. // // enterFullscreen();
  2516. // panFull()
  2517. // }, 50)
  2518. // })
  2519. // }
  2520. }
  2521. }
  2522. const getWorkLoading = ref<any>(false)
  2523. const getWork = async (isUpdate = false) => {
  2524. try {
  2525. if (getWorkLoading.value) {
  2526. return
  2527. }
  2528. if (!isUpdate) {
  2529. workLoading.value = true
  2530. }
  2531. getWorkLoading.value = true
  2532. console.log('getWork 开始执行,参数:', {
  2533. courseid: props.courseid,
  2534. slideIndex: slideIndex.value,
  2535. type: props.type,
  2536. isUpdate
  2537. })
  2538. if (!props.courseid) {
  2539. console.warn('getWork: courseid 未提供,跳过执行')
  2540. if (!isUpdate) workLoading.value = false
  2541. return
  2542. }
  2543. const res = await api.selectSWorks(props.courseid, '0', slideIndex.value.toString())
  2544. console.log('getWork 执行成功,结果:', res)
  2545. const frame = elementList.value.find(element => element.type === ElementTypes.FRAME)
  2546. console.log('frame:', frame)
  2547. const toolType = frame?.toolType ?? ''
  2548. const newWorkArray = props.cid
  2549. ? res[0].filter((work: any) => {
  2550. // console.log(work.ttype == '1' || (work.ttype == '2' && work.classid.includes(props.cid)) && (work.atool === toolType.value || !toolType.value))
  2551. return work.ttype == '1' || (work.ttype == '2' && work.classid.includes(props.cid)) && (work.atool == toolType.value || !toolType.value)
  2552. })
  2553. : res[0]
  2554. // 如果是更新模式,只有当数据真正变化时才更新
  2555. if (isUpdate) {
  2556. const hasChanged = checkWorkArrayChanged(workArray.value, newWorkArray)
  2557. if (hasChanged) {
  2558. console.log('检测到作业数据变化,更新显示')
  2559. workArray.value = newWorkArray
  2560. }
  2561. else {
  2562. console.log('作业数据无变化,跳过更新')
  2563. }
  2564. }
  2565. else {
  2566. workArray.value = newWorkArray
  2567. }
  2568. console.log('getWork 执行成功,结果:', workArray.value)
  2569. getWorkLoading.value = false
  2570. }
  2571. catch (error) {
  2572. console.error('getWork 执行失败:', error)
  2573. if (!isUpdate) {
  2574. message.error(lang.ssWorkInfoFail)
  2575. }
  2576. getWorkLoading.value = false
  2577. }
  2578. finally {
  2579. if (!isUpdate) {
  2580. workLoading.value = false
  2581. }
  2582. getWorkLoading.value = false
  2583. }
  2584. }
  2585. const selectWorksStudent = async () => {
  2586. studentLoading.value = true
  2587. try {
  2588. const res = await api.selectWorksStudent(props.oid as string, courseDetail.value.juri as string)
  2589. console.log('selectWorksStudent', res)
  2590. const students = res[0]
  2591. console.log('students', students)
  2592. if (props.cid) {
  2593. studentArray.value = students.filter((student: any) => student.classid.includes(props.cid))
  2594. }
  2595. else {
  2596. studentArray.value = students
  2597. }
  2598. }
  2599. catch (error) {
  2600. console.error('获取学生信息失败:', error)
  2601. message.error(lang.ssStuInfoFail)
  2602. }
  2603. finally {
  2604. studentLoading.value = false
  2605. }
  2606. }
  2607. // 检查作业数组是否发生变化
  2608. const checkWorkArrayChanged = (oldArray: WorkItem[], newArray: WorkItem[]): boolean => {
  2609. if (oldArray.length !== newArray.length) return true
  2610. // 检查每个作业的 id 和 name 是否一致
  2611. for (let i = 0; i < oldArray.length; i++) {
  2612. const oldWork = oldArray[i]
  2613. const newWork = newArray[i]
  2614. if (oldWork.id !== newWork.id || oldWork.name !== newWork.name || oldWork.content !== newWork.content) {
  2615. return true
  2616. }
  2617. }
  2618. return false
  2619. }
  2620. // 查询课程跟随状态
  2621. const selectCourseSLook = async (type = 2) => {
  2622. const res = await api.selectCourseSLook(props.courseid as string)
  2623. console.log('selectCourseSLook', res)
  2624. if (res[0][0].follow == 2) {
  2625. if (props.type == '2') {
  2626. goToSlide(Number(res[0][0].followC))
  2627. }
  2628. isFollowModeActive.value = true
  2629. if (props.userid == courseDetail.value.userid && props.type == '1') {
  2630. api.updateCourseFollowC(slideIndex.value, props.courseid as string)
  2631. sendMessage({slideIndex: slideIndex.value, courseid: props.courseid, type: 'slideIndex'})
  2632. console.log('设置当前幻灯片为跟随目标:', slideIndex.value)
  2633. }
  2634. if (props.type == '2' && slidePanelCollapsed.value) {
  2635. slidePanelCollapsed.value = false
  2636. }
  2637. }
  2638. else {
  2639. isFollowModeActive.value = false
  2640. if (type === 1 && props.userid == courseDetail.value.userid && props.type == '1') {
  2641. toggleFollowMode()
  2642. }
  2643. }
  2644. if (props.type == '2') {
  2645. message.success(isFollowModeActive.value ? lang.ssFollowOnTip : lang.ssFreeOnTip)
  2646. }
  2647. checkParentMode()
  2648. }
  2649. // 切换跟随模式
  2650. const toggleFollowMode = async () => {
  2651. try {
  2652. const newFollowState = !isFollowModeActive.value
  2653. const sopen = newFollowState ? 2 : 1
  2654. // 调用API更新跟随状态
  2655. const res = await api.updateCourseFollow(sopen, props.courseid as string)
  2656. console.log('更新跟随模式状态:', res)
  2657. sendMessage({sopen: newFollowState, courseid: props.courseid, type: 'sopen'})
  2658. if (res) {
  2659. isFollowModeActive.value = newFollowState
  2660. message.success(newFollowState ? lang.ssFollowOnTip : lang.ssFreeOnTip)
  2661. // 如果开启跟随模式,设置当前幻灯片为跟随目标
  2662. if (newFollowState) {
  2663. await api.updateCourseFollowC(slideIndex.value, props.courseid as string)
  2664. console.log('设置当前幻灯片为跟随目标:', slideIndex.value)
  2665. }
  2666. if (timerlVisible.value) {
  2667. timerlVisible.value = false
  2668. }
  2669. handleWritingBoardClose()
  2670. }
  2671. else {
  2672. message.error(lang.ssOpFailRetry)
  2673. }
  2674. checkParentMode()
  2675. }
  2676. catch (error) {
  2677. console.error('切换跟随模式失败:', error)
  2678. message.error(lang.ssOpFailRetry)
  2679. }
  2680. }
  2681. const checkParentMode = () => {
  2682. // @ts-ignore
  2683. if (window.parent && typeof window.parent.onFreeBrowseChange === 'function') {
  2684. // @ts-ignore
  2685. window.parent.onFreeBrowseChange(!isFollowModeActive.value)
  2686. }
  2687. }
  2688. const forceLogout = () => {
  2689. sendMessage({ type: 'logout' })
  2690. }
  2691. const logout = () => {
  2692. // @ts-ignore
  2693. if (window.parent && typeof window.parent.topU.U.MD.U.LO.logoutSystemQ === 'function') {
  2694. // @ts-ignore
  2695. window.parent.topU.U.MD.U.LO.logoutSystemQ()
  2696. }
  2697. }
  2698. // 检查是否为创建人
  2699. const checkIsCreator = () => {
  2700. // 这里可以根据实际业务逻辑判断是否为创建人
  2701. // 比如通过props中的userid与课程创建者ID比较
  2702. if (courseDetail.value && props.userid) {
  2703. isCreator.value = courseDetail.value.userid === props.userid
  2704. }
  2705. }
  2706. /**
  2707. * 初始化消息监听
  2708. */
  2709. const messageInit = () => {
  2710. if (!docSocket.value) return
  2711. // 初始化普通消息数组(只保留最后一条)
  2712. if (!yMessage.value) {
  2713. console.log('初始化普通消息数组')
  2714. yMessage.value = docSocket.value.getArray('message')
  2715. yMessage.value.observe((e: any) => {
  2716. e.changes.added.forEach((i: any) => {
  2717. console.log('yMessage', yMessage.value.length)
  2718. console.log('yMessage', yMessage.value)
  2719. const message = i.content.getContent()[0]
  2720. console.log('yMessage', message)
  2721. if (message.mId !== mId.value) {
  2722. getMessages(message)
  2723. }
  2724. })
  2725. })
  2726. }
  2727. // 初始化计时器消息数组
  2728. if (!yTimerMessages.value) {
  2729. console.log('初始化计时器消息数组')
  2730. yTimerMessages.value = docSocket.value.getArray('timerMessages')
  2731. // 初始化时检查一次是否需要清理
  2732. if (yTimerMessages.value && yTimerMessages.value.length > 500 && isCreator.value && docSocket.value) {
  2733. smartCleanupMessages(yTimerMessages.value, 500, 'timer', docSocket.value)
  2734. }
  2735. yTimerMessages.value.observe((e: any) => {
  2736. console.log('yTimerMessages', yTimerMessages.value.length)
  2737. console.log('yTimerMessages', yTimerMessages.value)
  2738. // 每次有新消息添加后,检查是否需要清理
  2739. if (yTimerMessages.value && yTimerMessages.value.length > 500 && isCreator.value && docSocket.value) {
  2740. // 使用 setTimeout 确保在 observe 回调执行完成后再清理
  2741. setTimeout(() => {
  2742. if (docSocket.value && yTimerMessages.value && yTimerMessages.value.length > 500) {
  2743. smartCleanupMessages(yTimerMessages.value, 500, 'timer', docSocket.value)
  2744. }
  2745. }, 0)
  2746. }
  2747. e.changes.added.forEach((i: any) => {
  2748. const message = i.content.getContent()[0]
  2749. if (message.mId !== mId.value) {
  2750. getMessages(message)
  2751. }
  2752. })
  2753. })
  2754. }
  2755. // 初始化激光笔消息数组
  2756. if (!yLaserMessages.value) {
  2757. console.log('初始化激光笔消息数组')
  2758. yLaserMessages.value = docSocket.value.getArray('laserMessages')
  2759. // 初始化时检查一次是否需要清理
  2760. if (yLaserMessages.value && yLaserMessages.value.length > 500 && isCreator.value && docSocket.value) {
  2761. smartCleanupMessages(yLaserMessages.value, 500, 'laser', docSocket.value)
  2762. }
  2763. yLaserMessages.value.observe((e: any) => {
  2764. console.log('yLaserMessages', yLaserMessages.value.length)
  2765. console.log('yLaserMessages', yLaserMessages.value)
  2766. // 每次有新消息添加后,检查是否需要清理
  2767. if (yLaserMessages.value && yLaserMessages.value.length > 500 && isCreator.value && docSocket.value) {
  2768. // 使用 setTimeout 确保在 observe 回调执行完成后再清理
  2769. setTimeout(() => {
  2770. if (docSocket.value && yLaserMessages.value && yLaserMessages.value.length > 500) {
  2771. smartCleanupMessages(yLaserMessages.value, 500, 'laser', docSocket.value)
  2772. }
  2773. }, 0)
  2774. }
  2775. e.changes.added.forEach((i: any) => {
  2776. const message = i.content.getContent()[0]
  2777. // 只处理开关消息,位置消息直接通过 Map 同步
  2778. if (message.type === 'laser_toggle' && message.mId !== mId.value) {
  2779. getMessages(message)
  2780. }
  2781. })
  2782. })
  2783. }
  2784. // 初始化画图消息数组
  2785. if (!yWritingBoardMessages.value) {
  2786. console.log('初始化画图消息数组')
  2787. yWritingBoardMessages.value = docSocket.value.getArray('writingBoardMessages')
  2788. // 初始化时检查一次是否需要清理
  2789. if (yWritingBoardMessages.value && yWritingBoardMessages.value.length > 500 && isCreator.value && docSocket.value) {
  2790. smartCleanupMessages(yWritingBoardMessages.value, 500, 'writingBoard', docSocket.value)
  2791. }
  2792. yWritingBoardMessages.value.observe((e: any) => {
  2793. console.log('yWritingBoardMessages', yWritingBoardMessages.value.length)
  2794. console.log('yWritingBoardMessages', yWritingBoardMessages.value)
  2795. // 每次有新消息添加后,检查是否需要清理
  2796. if (yWritingBoardMessages.value && yWritingBoardMessages.value.length > 500 && isCreator.value && docSocket.value) {
  2797. // 使用 setTimeout 确保在 observe 回调执行完成后再清理
  2798. setTimeout(() => {
  2799. if (docSocket.value && yWritingBoardMessages.value && yWritingBoardMessages.value.length > 500) {
  2800. smartCleanupMessages(yWritingBoardMessages.value, 500, 'writingBoard', docSocket.value)
  2801. }
  2802. }, 0)
  2803. }
  2804. e.changes.added.forEach((i: any) => {
  2805. const message = i.content.getContent()[0]
  2806. if (message.mId !== mId.value) {
  2807. getMessages(message)
  2808. }
  2809. })
  2810. })
  2811. }
  2812. // 如果是首次进入且是创建者,清空所有同步状态
  2813. if (isFirstEnter.value && isCreator.value && docSocket.value) {
  2814. console.log('🧹 首次进入且为创建者,清空所有同步状态')
  2815. docSocket.value.transact(() => {
  2816. // 清空普通消息(只保留最后一条的逻辑在 sendMessage 中处理)
  2817. const messageArray = docSocket.value?.getArray?.('message')
  2818. if (messageArray) {
  2819. messageArray.delete(0, messageArray.length)
  2820. }
  2821. // 清空计时器消息数组
  2822. const timerMessagesArray = docSocket.value?.getArray?.('timerMessages')
  2823. if (timerMessagesArray) {
  2824. timerMessagesArray.delete(0, timerMessagesArray.length)
  2825. }
  2826. // 清空激光笔消息数组
  2827. const laserMessagesArray = docSocket.value?.getArray?.('laserMessages')
  2828. if (laserMessagesArray) {
  2829. laserMessagesArray.delete(0, laserMessagesArray.length)
  2830. }
  2831. // 清空画图消息数组
  2832. const writingBoardMessagesArray = docSocket.value?.getArray?.('writingBoardMessages')
  2833. if (writingBoardMessagesArray) {
  2834. writingBoardMessagesArray.delete(0, writingBoardMessagesArray.length)
  2835. }
  2836. // 清空计时器状态
  2837. const timerStateMap = docSocket.value?.getMap?.('timerState')
  2838. if (timerStateMap) {
  2839. timerStateMap.clear()
  2840. }
  2841. // 清空激光笔状态
  2842. const laserStateMap = docSocket.value?.getMap?.('laserState')
  2843. if (laserStateMap) {
  2844. laserStateMap.clear()
  2845. }
  2846. // 清空画图状态
  2847. const writingBoardStateMap = docSocket.value?.getMap?.('writingBoardState')
  2848. if (writingBoardStateMap) {
  2849. writingBoardStateMap.clear()
  2850. }
  2851. })
  2852. // 标记已不再是首次进入
  2853. isFirstEnter.value = false
  2854. }
  2855. // 初始化计时器状态 Map 并监听
  2856. if (docSocket.value && !yTimerState.value) {
  2857. yTimerState.value = docSocket.value.getMap('timerState')
  2858. // 初始状态同步(后加入用户会立即拿到当前 map 值)
  2859. const snapshot = yTimerState.value.toJSON()
  2860. applyTimerStateSnapshot(snapshot)
  2861. // 监听变化
  2862. yTimerState.value.observe((event: any) => {
  2863. const snap = yTimerState.value.toJSON()
  2864. applyTimerStateSnapshot(snap)
  2865. })
  2866. }
  2867. // 初始化激光笔状态 Map 并监听
  2868. if (docSocket.value && !yLaserState.value) {
  2869. yLaserState.value = docSocket.value.getMap('laserState')
  2870. const lsnap = yLaserState.value.toJSON()
  2871. applyLaserStateSnapshot(lsnap)
  2872. yLaserState.value.observe(() => {
  2873. const s = yLaserState.value.toJSON()
  2874. applyLaserStateSnapshot(s)
  2875. })
  2876. }
  2877. // 初始化画图状态 Map 并监听
  2878. if (docSocket.value && !yWritingBoardState.value) {
  2879. yWritingBoardState.value = docSocket.value.getMap('writingBoardState')
  2880. const wsnap = yWritingBoardState.value.toJSON()
  2881. console.log('📝 初始化画图状态Map,快照:', wsnap, '当前幻灯片:', currentSlide.value?.id)
  2882. // 延迟应用,确保 currentSlide 已初始化
  2883. nextTick(() => {
  2884. // 如果 currentSlide 还没准备好,再等一帧
  2885. if (currentSlide.value && currentSlide.value.id) {
  2886. applyWritingBoardStateSnapshot(wsnap)
  2887. }
  2888. else {
  2889. // 如果还没准备好,等待 currentSlide 变化(最多等待3秒)
  2890. let timeoutId: any = null
  2891. const unwatch = watch(() => currentSlide.value?.id, (slideId) => {
  2892. if (slideId) {
  2893. applyWritingBoardStateSnapshot(wsnap)
  2894. unwatch()
  2895. if (timeoutId) clearTimeout(timeoutId)
  2896. }
  2897. }, { immediate: true })
  2898. // 3秒后如果还没准备好,强制应用一次
  2899. timeoutId = setTimeout(() => {
  2900. if (currentSlide.value && currentSlide.value.id) {
  2901. applyWritingBoardStateSnapshot(wsnap)
  2902. }
  2903. unwatch()
  2904. }, 3000)
  2905. }
  2906. })
  2907. yWritingBoardState.value.observe(() => {
  2908. const s = yWritingBoardState.value.toJSON()
  2909. if (currentSlide.value && currentSlide.value.id) {
  2910. applyWritingBoardStateSnapshot(s)
  2911. }
  2912. })
  2913. }
  2914. }
  2915. /**
  2916. * 判断是否为特殊类型的消息(计时器、激光笔、画图)
  2917. * 注意:laser_move 不通过消息数组,直接通过 Map 同步,所以不包含在这里
  2918. */
  2919. const isSpecialMessageType = (type: string): boolean => {
  2920. const timerTypes = ['timer_start', 'timer_pause', 'timer_reset', 'timer_stop', 'timer_finish', 'timer_update']
  2921. const laserTypes = ['laser_toggle'] // laser_move 直接通过 Map,不通过消息数组
  2922. const writingBoardTypes = ['writing_board_update', 'writing_board_close', 'writing_board_blackboard']
  2923. return timerTypes.includes(type) || laserTypes.includes(type) || writingBoardTypes.includes(type)
  2924. }
  2925. /**
  2926. * 判断是否为开关类型的消息(需要保留的状态消息)
  2927. */
  2928. const isToggleMessageType = (type: string, category: 'timer' | 'laser' | 'writingBoard'): boolean => {
  2929. if (category === 'laser') {
  2930. return type === 'laser_toggle'
  2931. }
  2932. if (category === 'writingBoard') {
  2933. return type === 'writing_board_close'
  2934. }
  2935. if (category === 'timer') {
  2936. return ['timer_start', 'timer_stop', 'timer_reset'].includes(type)
  2937. }
  2938. return false
  2939. }
  2940. /**
  2941. * 智能清理消息数组,保留最新的开关消息
  2942. */
  2943. const smartCleanupMessages = (messageArray: any, maxLength: number, category: 'timer' | 'laser' | 'writingBoard', docSocket: Y.Doc) => {
  2944. if (!messageArray || messageArray.length <= maxLength) return
  2945. const allMessages = messageArray.toArray()
  2946. // 找到所有开关类型的消息及其索引
  2947. const toggleMessages: Array<{ index: number; message: any }> = []
  2948. for (let i = 0; i < allMessages.length; i++) {
  2949. const msg = allMessages[i]
  2950. if (msg && typeof msg === 'object' && msg.type && isToggleMessageType(msg.type, category)) {
  2951. toggleMessages.push({ index: i, message: msg })
  2952. }
  2953. }
  2954. // 如果有关键的开关消息,需要确保它们被保留
  2955. if (toggleMessages.length > 0) {
  2956. // 找到最新的开关消息索引
  2957. const latestToggleIndex = toggleMessages[toggleMessages.length - 1].index
  2958. // 如果最新的开关消息在最后500条内,直接保留最后500条
  2959. if (latestToggleIndex >= allMessages.length - maxLength) {
  2960. const excessCount = allMessages.length - maxLength
  2961. docSocket.transact(() => {
  2962. messageArray.delete(0, excessCount)
  2963. })
  2964. console.log(`🧹 清理了 ${excessCount} 条${category}消息,保留最新${maxLength}条(包含最新开关状态)`)
  2965. }
  2966. else {
  2967. // 如果最新的开关消息不在最后500条内,需要特殊处理
  2968. // 保留从最新开关消息开始到末尾的所有消息
  2969. const keepFromIndex = Math.max(0, latestToggleIndex)
  2970. const excessCount = keepFromIndex
  2971. docSocket.transact(() => {
  2972. messageArray.delete(0, excessCount)
  2973. })
  2974. console.log(`🧹 清理了 ${excessCount} 条${category}消息,保留从最新开关状态开始的所有消息`)
  2975. }
  2976. }
  2977. else {
  2978. // 没有开关消息,直接保留最后500条
  2979. const excessCount = allMessages.length - maxLength
  2980. docSocket.transact(() => {
  2981. messageArray.delete(0, excessCount)
  2982. })
  2983. console.log(`🧹 清理了 ${excessCount} 条${category}消息,保留最新${maxLength}条`)
  2984. }
  2985. }
  2986. /**
  2987. * 获取消息类型对应的数组
  2988. * 注意:laser_move 不通过消息数组,直接通过 Map 同步
  2989. */
  2990. const getMessageArrayByType = (type: string): any | null => {
  2991. const timerTypes = ['timer_start', 'timer_pause', 'timer_reset', 'timer_stop', 'timer_finish', 'timer_update']
  2992. const laserTypes = ['laser_toggle'] // laser_move 直接通过 Map,不通过消息数组
  2993. const writingBoardTypes = ['writing_board_update', 'writing_board_close', 'writing_board_blackboard']
  2994. if (timerTypes.includes(type)) {
  2995. return yTimerMessages.value
  2996. }
  2997. if (laserTypes.includes(type)) {
  2998. return yLaserMessages.value
  2999. }
  3000. if (writingBoardTypes.includes(type)) {
  3001. return yWritingBoardMessages.value
  3002. }
  3003. return null
  3004. }
  3005. /**
  3006. * 发送消息
  3007. */
  3008. const sendMessage = (obj: any) => {
  3009. if (!docSocket.value) return
  3010. const message = obj
  3011. message.timestamp = new Date().toISOString()
  3012. message.mId = mId.value
  3013. const messageType = message.type
  3014. // laser_move 消息直接通过 Map 同步,不通过消息数组(减少延迟)
  3015. if (messageType === 'laser_move') {
  3016. if (yLaserState.value) {
  3017. docSocket.value.transact(() => {
  3018. yLaserState.value.set('x', message.x)
  3019. yLaserState.value.set('y', message.y)
  3020. })
  3021. }
  3022. return // 不存储到消息数组
  3023. }
  3024. const isSpecial = isSpecialMessageType(messageType)
  3025. docSocket.value.transact(() => {
  3026. if (isSpecial) {
  3027. // 特殊类型消息:存储到对应的独立数组
  3028. const targetArray = getMessageArrayByType(messageType)
  3029. if (targetArray) {
  3030. targetArray.push([message])
  3031. }
  3032. }
  3033. else {
  3034. // 普通消息:只保留最后一条
  3035. if (yMessage.value) {
  3036. // 清空数组,只保留新消息
  3037. yMessage.value.delete(0, yMessage.value.length)
  3038. yMessage.value.push([message])
  3039. }
  3040. }
  3041. })
  3042. }
  3043. /**
  3044. * 处理收到的消息
  3045. */
  3046. const getMessages = (msgObj: any) => {
  3047. console.log('message', msgObj)
  3048. // 处理幻灯片切换消息
  3049. if (props.type == '2' && msgObj.type === 'slideIndex') {
  3050. goToSlide(msgObj.slideIndex)
  3051. }
  3052. // 处理跟随模式状态变化
  3053. if (props.type == '2' && msgObj.type === 'sopen') {
  3054. selectCourseSLook()
  3055. }
  3056. if (props.type == '2' && msgObj.type === 'logout') {
  3057. logout()
  3058. }
  3059. // 处理作业提交消息 - 当有人提交作业时,重新获取作业数据
  3060. if (props.type == '1' && msgObj.type === 'homework_submitted' && msgObj.courseid === props.courseid) {
  3061. console.log('收到作业提交消息,重新获取作业数据')
  3062. // 延迟一点时间,确保后端数据已更新
  3063. setTimeout(() => {
  3064. if (currentSlideHasIframe.value) {
  3065. getWork(true) // 传入true表示是更新模式
  3066. }
  3067. }, 1000)
  3068. }
  3069. // 处理英语口语状态更新 - 学生开始/完成对话时,刷新班级答题面板
  3070. if (props.type == '1' && msgObj.type === 'speaking_session_updated' && msgObj.courseid === props.courseid) {
  3071. console.log('收到英语口语状态更新,触发面板刷新')
  3072. speakingPanelRef.value?.scheduleRefetch?.()
  3073. }
  3074. // 计时器消息 - 学生与老师端实时显示
  3075. if (msgObj.type === 'timer_start' && msgObj.courseid === props.courseid) {
  3076. applyTimerStart(msgObj.payload)
  3077. }
  3078. if (msgObj.type === 'timer_pause' && msgObj.courseid === props.courseid) {
  3079. applyTimerPause()
  3080. }
  3081. if (msgObj.type === 'timer_reset' && msgObj.courseid === props.courseid) {
  3082. applyTimerReset()
  3083. }
  3084. if (msgObj.type === 'timer_stop' && msgObj.courseid === props.courseid) {
  3085. applyTimerStop()
  3086. }
  3087. if (msgObj.type === 'timer_finish' && msgObj.courseid === props.courseid) {
  3088. applyTimerFinish()
  3089. }
  3090. if (msgObj.type === 'timer_update' && msgObj.courseid === props.courseid) {
  3091. applyTimerUpdate(msgObj.payload)
  3092. }
  3093. // 激光笔:老师广播的开关
  3094. if (props.type == '2' && msgObj.type === 'laser_toggle' && msgObj.courseid === props.courseid) {
  3095. laserPenOverlay.value.visible = !!msgObj.enabled
  3096. // 开关时立即刷新一次位置
  3097. if (laserPenOverlay.value.visible) {
  3098. refreshLaserOverlayRect()
  3099. if (laserMoveRafId) cancelAnimationFrame(laserMoveRafId)
  3100. laserMoveRafId = requestAnimationFrame(updateLaserDotPosition)
  3101. }
  3102. }
  3103. // 注意:laser_move 现在直接通过 Map 同步,不通过消息数组,所以这里不需要处理
  3104. // 画图:老师广播的画图数据
  3105. if (props.type == '2' && msgObj.type === 'writing_board_update' && msgObj.courseid === props.courseid) {
  3106. console.log('📝 学生端收到画图更新消息:', { slideId: msgObj.slideId, currentSlideId: currentSlide.value?.id, hasData: !!msgObj.dataURL })
  3107. if (currentSlide.value && msgObj.slideId === currentSlide.value.id) {
  3108. writingBoardSyncDataURL.value = msgObj.dataURL || null
  3109. // 如果消息中包含小黑板状态,也更新
  3110. if (msgObj.blackboard !== undefined) {
  3111. writingBoardSyncBlackboard.value = msgObj.blackboard
  3112. }
  3113. console.log('📝 画图数据匹配当前幻灯片,显示画图工具')
  3114. // 同步到共享 Map
  3115. if (yWritingBoardState.value) {
  3116. docSocket.value?.transact(() => {
  3117. yWritingBoardState.value.set('slideId', msgObj.slideId)
  3118. yWritingBoardState.value.set('dataURL', msgObj.dataURL)
  3119. if (msgObj.blackboard !== undefined) {
  3120. yWritingBoardState.value.set('blackboard', msgObj.blackboard)
  3121. }
  3122. })
  3123. }
  3124. }
  3125. else {
  3126. // 不是当前幻灯片,但也要更新到 Map(供后续切换时使用)
  3127. if (yWritingBoardState.value) {
  3128. docSocket.value?.transact(() => {
  3129. yWritingBoardState.value.set('slideId', msgObj.slideId)
  3130. yWritingBoardState.value.set('dataURL', msgObj.dataURL)
  3131. if (msgObj.blackboard !== undefined) {
  3132. yWritingBoardState.value.set('blackboard', msgObj.blackboard)
  3133. }
  3134. })
  3135. }
  3136. console.log('📝 画图数据不匹配当前幻灯片,已保存到Map供后续使用')
  3137. }
  3138. }
  3139. // 画图:老师关闭画图工具
  3140. if (props.type == '2' && msgObj.type === 'writing_board_close' && msgObj.courseid === props.courseid) {
  3141. writingBoardSyncDataURL.value = null
  3142. writingBoardSyncBlackboard.value = null
  3143. // 清空共享 Map
  3144. if (yWritingBoardState.value) {
  3145. docSocket.value?.transact(() => {
  3146. yWritingBoardState.value.clear()
  3147. })
  3148. }
  3149. }
  3150. // 画图:老师切换小黑板状态
  3151. if (props.type == '2' && msgObj.type === 'writing_board_blackboard' && msgObj.courseid === props.courseid) {
  3152. writingBoardSyncBlackboard.value = msgObj.blackboard || false
  3153. // 同步到共享 Map
  3154. if (yWritingBoardState.value) {
  3155. docSocket.value?.transact(() => {
  3156. yWritingBoardState.value.set('blackboard', msgObj.blackboard)
  3157. })
  3158. }
  3159. }
  3160. }
  3161. // 打开作业查看详细
  3162. const openChoiceQuestionDetail = (index:number) => {
  3163. if (!choiceQuestionDetailDialogOpenList.value.includes(index)) {
  3164. choiceQuestionDetailDialogOpenList.value.push(index)
  3165. }
  3166. else {
  3167. choiceQuestionDetailDialogOpenList.value = choiceQuestionDetailDialogOpenList.value.filter(i => i !== index)
  3168. }
  3169. }
  3170. // 打开作业查看详细
  3171. const openChoiceQuestionDetail2 = (index:number) => {
  3172. if (!choiceQuestionDetailDialogOpenList.value.includes(index)) {
  3173. }
  3174. else {
  3175. choiceQuestionDetailDialogOpenList.value = choiceQuestionDetailDialogOpenList.value.filter(i => i !== index)
  3176. }
  3177. }
  3178. // 打开作业查看详细
  3179. const openChoiceQuestionDetail3 = (index:number) => {
  3180. if (!choiceQuestionDetailDialogOpenList.value.includes(index)) {
  3181. choiceQuestionDetailDialogOpenList.value.push(index)
  3182. }
  3183. }
  3184. const handlePageUnload = () => {
  3185. if (isCreator.value && timerIndicator.value.visible && props.type === '1') {
  3186. sendMessage({ type: 'timer_stop', courseid: props.courseid })
  3187. }
  3188. // 创建老师刷新/关闭页面时,清空所有同步状态
  3189. if (isCreator.value && props.type === '1') {
  3190. clearAllSyncStates()
  3191. }
  3192. // 清理画图延迟发送定时器
  3193. if (drawingDelayTimer.value) {
  3194. clearTimeout(drawingDelayTimer.value)
  3195. drawingDelayTimer.value = null
  3196. }
  3197. }
  3198. // 检测浏览器类型
  3199. const detectBrowser = () => {
  3200. const ua = navigator.userAgent
  3201. // 按优先级顺序检测
  3202. if (ua.includes('Edg/') || ua.includes('Edge/')) {
  3203. return 'Microsoft Edge'
  3204. }
  3205. if (ua.includes('Firefox')) {
  3206. return 'Mozilla Firefox'
  3207. }
  3208. if (ua.includes('Trident') || ua.includes('MSIE')) {
  3209. return 'Internet Explorer'
  3210. }
  3211. if (ua.includes('360EE')) {
  3212. return '360 Browser (极速模式)'
  3213. }
  3214. if (ua.includes('360SE')) {
  3215. return '360 Browser (安全模式)'
  3216. }
  3217. if (ua.includes('SLBrowser')) {
  3218. return 'QQ Browser'
  3219. }
  3220. if (ua.includes('UCBrowser')) {
  3221. return 'UC Browser'
  3222. }
  3223. if (ua.includes('Opera') || ua.includes('OPR/')) {
  3224. return 'Opera'
  3225. }
  3226. if (ua.includes('Chrome') && !ua.includes('Edg/')) {
  3227. return 'Google Chrome'
  3228. }
  3229. if (ua.includes('Safari/') && !ua.includes('Chrome')) {
  3230. return 'Safari'
  3231. }
  3232. return 'Other Browser'
  3233. }
  3234. // 用户数据上报功能
  3235. const addOp3 = async (userTime: any, loadTime: any, object: any, status: any) => {
  3236. if (!props.userid) return
  3237. try {
  3238. if (!userJson.value || !userJson.value.accountNumber) {
  3239. const res = await axios.get('https://pbl.cocorobo.cn/api/pbl/selectUser', {
  3240. params: { userid: props.userid }
  3241. })
  3242. userJson.value = res[0][0]
  3243. console.log(userJson.value)
  3244. console.log(res[0][0])
  3245. }
  3246. }
  3247. catch (e) {
  3248. console.log(e)
  3249. return addOp3(userTime, loadTime, object, status)
  3250. }
  3251. const _time = new Date()
  3252. .toLocaleString('zh-CN', { hour12: false, timeZone: 'Asia/Shanghai' })
  3253. .replace(/\//g, '-')
  3254. const browser = detectBrowser()
  3255. const params = {
  3256. userid: props.userid,
  3257. username: userJson.value.username,
  3258. accountNumber: userJson.value.accountNumber,
  3259. org: userJson.value.orgName,
  3260. school: userJson.value.schoolName,
  3261. role: userJson.value.type === '1' ? '老师' : '学生',
  3262. browser,
  3263. userTime: userTime === '1' ? _time : userTime, // 使用时间 1次的就1 其次传秒
  3264. loadTime, // load的时间没有就''
  3265. object: JSON.stringify(object), // 执行信息传json
  3266. status // 成功返回success。失败返回error的信息
  3267. }
  3268. console.log('params', params)
  3269. axios
  3270. .post('https://pbl.cocorobo.cn/api/mongo/updateUserData2', [params])
  3271. .then(res => {
  3272. if (res.status === 1) {
  3273. console.log('保存成功')
  3274. }
  3275. else {
  3276. console.log('保存失败')
  3277. }
  3278. })
  3279. .catch(e => {
  3280. console.log('保存失败')
  3281. console.log(e)
  3282. })
  3283. }
  3284. onMounted(() => {
  3285. document.addEventListener('keydown', handleKeydown)
  3286. // 处理URL参数
  3287. if (props.courseid || props.type) {
  3288. console.log('收到URL参数:', { courseid: props.courseid, type: props.type })
  3289. // 这里可以根据courseid和type进行相应的处理
  3290. // 比如加载特定的课程数据、设置特定的显示模式等
  3291. if (props.courseid) {
  3292. console.log('课程ID:', props.courseid)
  3293. // TODO: 根据courseid加载对应的课程数据
  3294. }
  3295. if (props.type) {
  3296. console.log('类型:', props.type)
  3297. // TODO: 根据type设置特定的显示模式或功能
  3298. }
  3299. }
  3300. getCourseDetail()
  3301. // 计算初始缩放比例
  3302. nextTick(() => {
  3303. calculateScale()
  3304. // 处理iframe链接
  3305. processIframeLinks()
  3306. // 初始化时检查并自动切换到可用面板
  3307. autoSwitchToAvailablePanel()
  3308. })
  3309. // 监听窗口大小变化
  3310. window.addEventListener('resize', calculateScale)
  3311. // 监听全屏状态变化
  3312. document.addEventListener('fullscreenchange', handleFullscreenChange)
  3313. // 监听幻灯片数据更新事件(来自useImport的readJSON)
  3314. window.addEventListener('slidesDataUpdated', handleSlidesDataUpdated)
  3315. // 监听视口尺寸更新事件
  3316. window.addEventListener('viewportSizeUpdated', handleViewportSizeUpdated)
  3317. // 将导入导出功能暴露到window上,方便调试和外部调用
  3318. ; (window as any).PPTistStudent = {
  3319. importJSON,
  3320. exportJSON,
  3321. slides: slidesStore.slides,
  3322. currentSlide: computed(() => slidesStore.currentSlide),
  3323. slideIndex: computed(() => slidesStore.slideIndex),
  3324. goToSlide,
  3325. previousSlide,
  3326. nextSlide,
  3327. enterFullscreen,
  3328. toggleLaserPen,
  3329. // 添加URL参数到全局对象中
  3330. courseid: props.courseid,
  3331. type: props.type,
  3332. successSubmit,
  3333. toggleFollowMode,
  3334. // 添加重连功能
  3335. manualReconnect,
  3336. connectionStatus: computed(() => connectionStatus.value),
  3337. forceLogout,
  3338. }
  3339. console.log('PPTist Student View 已加载,可通过 window.PPTistStudent 访问功能')
  3340. console.log('URL参数:', { courseid: props.courseid, type: props.type })
  3341. // 初始化WebSocket连接
  3342. if (api.yweb_socket) {
  3343. createWebSocketConnection()
  3344. }
  3345. // 创建人离开页面时,广播停止计时
  3346. // beforeunload 事件(页面刷新或关闭)
  3347. window.addEventListener('beforeunload', handlePageUnload)
  3348. // visibilitychange 事件(适用于 iframe 嵌套场景,当外层页面返回时触发)
  3349. const handleVisibilityChange = () => {
  3350. if (document.hidden && isCreator.value) {
  3351. // 页面被隐藏时,清空所有同步状态
  3352. clearAllSyncStates()
  3353. if (timerIndicator.value.visible) {
  3354. sendMessage({ type: 'timer_stop', courseid: props.courseid })
  3355. }
  3356. }
  3357. }
  3358. document.addEventListener('visibilitychange', handleVisibilityChange)
  3359. // pagehide 事件(作为补充,某些浏览器中比 beforeunload 更可靠)
  3360. window.addEventListener('pagehide', handlePageUnload)
  3361. // 存储清理函数,方便在 onUnmounted 中移除
  3362. ;(window as any).__pptistStudentUnloadHandlers = {
  3363. beforeunload: handlePageUnload,
  3364. visibilitychange: handleVisibilityChange,
  3365. pagehide: handlePageUnload
  3366. }
  3367. })
  3368. onUnmounted(() => {
  3369. document.removeEventListener('keydown', handleKeydown)
  3370. window.removeEventListener('resize', calculateScale)
  3371. document.removeEventListener('fullscreenchange', handleFullscreenChange)
  3372. // 移除幻灯片数据更新事件监听器
  3373. window.removeEventListener('slidesDataUpdated', handleSlidesDataUpdated)
  3374. // 移除视口尺寸更新事件监听器
  3375. window.removeEventListener('viewportSizeUpdated', handleViewportSizeUpdated)
  3376. // 清理WebSocket连接
  3377. if (reconnectTimer.value) {
  3378. clearTimeout(reconnectTimer.value)
  3379. reconnectTimer.value = null
  3380. }
  3381. // 清理认证 token 更新定时器
  3382. if (authTokenUpdateTimer.value) {
  3383. clearTimeout(authTokenUpdateTimer.value)
  3384. authTokenUpdateTimer.value = null
  3385. }
  3386. // 清理 socket 连接检查定时器
  3387. if (socketCheckTimer.value) {
  3388. clearInterval(socketCheckTimer.value)
  3389. socketCheckTimer.value = null
  3390. }
  3391. // if (providerSocket.value) {
  3392. // providerSocket.value.destroy()
  3393. // providerSocket.value = null
  3394. // }
  3395. // 清理画图延迟发送定时器
  3396. if (drawingDelayTimer.value) {
  3397. clearTimeout(drawingDelayTimer.value)
  3398. drawingDelayTimer.value = null
  3399. }
  3400. // 清理页面卸载相关的事件监听器
  3401. if ((window as any).__pptistStudentUnloadHandlers) {
  3402. const handlers = (window as any).__pptistStudentUnloadHandlers
  3403. window.removeEventListener('beforeunload', handlers.beforeunload)
  3404. document.removeEventListener('visibilitychange', handlers.visibilitychange)
  3405. window.removeEventListener('pagehide', handlers.pagehide)
  3406. delete (window as any).__pptistStudentUnloadHandlers
  3407. }
  3408. // 清理window上的引用
  3409. if ((window as any).PPTistStudent) {
  3410. delete (window as any).PPTistStudent
  3411. console.log('PPTist Student View 已卸载,window.PPTistStudent 已清理')
  3412. }
  3413. if (timerInterval.value) {
  3414. clearInterval(timerInterval.value)
  3415. timerInterval.value = null
  3416. }
  3417. handlePageUnload()
  3418. })
  3419. // 获取认证 token
  3420. const getAuthToken = async (): Promise<string> => {
  3421. try {
  3422. // 使用代理路径避免跨域问题
  3423. // 开发环境:通过 vite 代理 /yjs-auth/auth/token -> https://yjsredis.cocorobo.cn/auth/token
  3424. // 生产环境:需要配置服务器代理或使用后端 API
  3425. // 兼容性修复:不直接使用 import.meta.env.DEV
  3426. let isDev = false
  3427. // 判断如果有 window 对象且以 localhost/127.0.0.1 开头,则认为是开发环境
  3428. if (typeof window !== 'undefined') {
  3429. const hostname = window.location.hostname
  3430. if (
  3431. hostname === 'localhost' ||
  3432. hostname === '127.0.0.1' ||
  3433. hostname === '::1' ||
  3434. /^192\.168\.\d+\.\d+$/.test(hostname)
  3435. ) {
  3436. isDev = true
  3437. }
  3438. }
  3439. let authUrl = ''
  3440. if (isDev) {
  3441. // 开发环境使用 vite 代理
  3442. authUrl = '/yjs-auth/auth/token'
  3443. }
  3444. else {
  3445. // 生产环境:如果服务器有代理则使用代理,否则直接访问(需要服务器配置 CORS)
  3446. // 或者通过后端 API 获取 token
  3447. let baseUrl = 'https://yjsredis.cocorobo.cn/'
  3448. baseUrl = baseUrl.replace(/\/+$/, '')
  3449. authUrl = `${baseUrl}/auth/token`
  3450. }
  3451. console.log('🔐 获取认证 token,URL:', authUrl)
  3452. const response = await axios.get(authUrl)
  3453. console.log('🔐 获取认证 token 成功', response)
  3454. return response
  3455. }
  3456. catch (error) {
  3457. console.error('🔐 获取认证 token 失败:', error)
  3458. throw error
  3459. }
  3460. }
  3461. // 定期更新认证 token
  3462. const updateAuthToken = async () => {
  3463. try {
  3464. if (!providerSocket.value) return
  3465. const newToken = await getAuthToken()
  3466. authToken.value = newToken
  3467. // 更新 provider 的 auth 参数
  3468. if (providerSocket.value.params) {
  3469. providerSocket.value.params.yauth = newToken
  3470. }
  3471. console.log('🔐 认证 token 已更新')
  3472. // 30分钟后再次更新
  3473. if (authTokenUpdateTimer.value) {
  3474. clearTimeout(authTokenUpdateTimer.value)
  3475. }
  3476. authTokenUpdateTimer.value = setTimeout(updateAuthToken, 30 * 60 * 1000) as unknown as NodeJS.Timeout
  3477. }
  3478. catch (error) {
  3479. console.error('🔐 更新认证 token 失败:', error)
  3480. // 失败后1秒重试
  3481. if (authTokenUpdateTimer.value) {
  3482. clearTimeout(authTokenUpdateTimer.value)
  3483. }
  3484. authTokenUpdateTimer.value = setTimeout(updateAuthToken, 1000) as unknown as NodeJS.Timeout
  3485. }
  3486. }
  3487. // 手动重连
  3488. const manualReconnect = () => {
  3489. if (isConnecting.value) return
  3490. reconnectAttempts.value = 0 // 重置重连次数
  3491. createWebSocketConnection()
  3492. }
  3493. // 创建WebSocket连接
  3494. const createWebSocketConnection = async (type = 1) => {
  3495. if (!api.yweb_socket || isConnecting.value) return
  3496. isConnecting.value = true
  3497. connectionStatus.value = 'connecting'
  3498. try {
  3499. // 清理之前的连接
  3500. // if (providerSocket.value && type == 1) {
  3501. // providerSocket.value.destroy()
  3502. // providerSocket.value = null
  3503. // }
  3504. // 清理之前的 token 更新定时器
  3505. if (authTokenUpdateTimer.value) {
  3506. clearTimeout(authTokenUpdateTimer.value)
  3507. authTokenUpdateTimer.value = null
  3508. }
  3509. // 获取认证 token
  3510. // try {
  3511. // authToken.value = await getAuthToken()
  3512. // console.log('🔐 认证 token 获取成功,准备连接 WebSocket')
  3513. // }
  3514. // catch (error) {
  3515. // console.error('🔐 获取认证 token 失败,连接可能失败:', error)
  3516. // connectionStatus.value = 'disconnected'
  3517. // isConnecting.value = false
  3518. // handleDisconnection()
  3519. // return
  3520. // }
  3521. docSocket.value = new Y.Doc()
  3522. docSocket.value.gc = true
  3523. providerSocket.value = new WebsocketProvider(
  3524. api.yweb_socket,
  3525. 'PPT' + props.courseid,
  3526. docSocket.value,
  3527. // { params: { yauth: authToken.value } }
  3528. )
  3529. // 启动定期更新 token
  3530. // updateAuthToken()
  3531. providerSocket.value.on('status', (event: any) => {
  3532. console.log('👉 WebSocket状态:', event.status)
  3533. if (event.status === 'connected') {
  3534. console.log('👉连接成功websocket(teachingMode)')
  3535. connectionStatus.value = 'connected'
  3536. isConnecting.value = false
  3537. reconnectAttempts.value = 0 // 重置重连次数
  3538. // 清理重连定时器
  3539. if (reconnectTimer.value) {
  3540. clearTimeout(reconnectTimer.value)
  3541. reconnectTimer.value = null
  3542. }
  3543. mId.value = Math.random().toString(36).substr(2, 9)
  3544. messageInit()
  3545. // 连接成功后,读取当前计时器状态(Map)
  3546. if (docSocket.value) {
  3547. yTimerState.value = docSocket.value.getMap('timerState')
  3548. const snapshot = yTimerState.value.toJSON()
  3549. applyTimerStateSnapshot(snapshot)
  3550. // 激光笔 map
  3551. yLaserState.value = docSocket.value.getMap('laserState')
  3552. const ls = yLaserState.value.toJSON()
  3553. applyLaserStateSnapshot(ls)
  3554. yLaserState.value.observe(() => {
  3555. const s = yLaserState.value.toJSON()
  3556. applyLaserStateSnapshot(s)
  3557. })
  3558. // 画图 map
  3559. yWritingBoardState.value = docSocket.value.getMap('writingBoardState')
  3560. const ws = yWritingBoardState.value.toJSON()
  3561. console.log('📝 WebSocket连接成功,读取画图状态:', ws, '当前幻灯片:', currentSlide.value?.id)
  3562. // 延迟应用,确保 currentSlide 已初始化
  3563. nextTick(() => {
  3564. // 如果 currentSlide 还没准备好,再等一帧
  3565. if (currentSlide.value && currentSlide.value.id) {
  3566. applyWritingBoardStateSnapshot(ws)
  3567. }
  3568. else {
  3569. // 如果还没准备好,等待 currentSlide 变化(最多等待3秒)
  3570. let timeoutId: any = null
  3571. const unwatch = watch(() => currentSlide.value?.id, (slideId) => {
  3572. if (slideId) {
  3573. applyWritingBoardStateSnapshot(ws)
  3574. unwatch()
  3575. if (timeoutId) clearTimeout(timeoutId)
  3576. }
  3577. }, { immediate: true })
  3578. // 3秒后如果还没准备好,强制应用一次
  3579. timeoutId = setTimeout(() => {
  3580. if (currentSlide.value && currentSlide.value.id) {
  3581. applyWritingBoardStateSnapshot(ws)
  3582. }
  3583. unwatch()
  3584. }, 3000)
  3585. }
  3586. })
  3587. yWritingBoardState.value.observe(() => {
  3588. const s = yWritingBoardState.value.toJSON()
  3589. if (currentSlide.value && currentSlide.value.id) {
  3590. applyWritingBoardStateSnapshot(s)
  3591. }
  3592. })
  3593. }
  3594. }
  3595. else if (event.status === 'disconnected') {
  3596. console.log('👉 WebSocket连接断开')
  3597. connectionStatus.value = 'disconnected'
  3598. isConnecting.value = false
  3599. createWebSocketConnection(2)
  3600. }
  3601. })
  3602. // 监听连接错误
  3603. providerSocket.value.on('connection-error', (error: any) => {
  3604. console.error('👉 WebSocket连接错误:', error)
  3605. connectionStatus.value = 'disconnected'
  3606. isConnecting.value = false
  3607. createWebSocketConnection(2)
  3608. })
  3609. }
  3610. catch (error) {
  3611. console.error('👉 创建WebSocket连接失败:', error)
  3612. connectionStatus.value = 'disconnected'
  3613. isConnecting.value = false
  3614. createWebSocketConnection(2)
  3615. }
  3616. // 启动 socket 连接检查定时器
  3617. // startSocketCheckTimer()
  3618. }
  3619. // 处理连接断开
  3620. const handleDisconnection = () => {
  3621. if (reconnectAttempts.value < maxReconnectAttempts.value) {
  3622. reconnectAttempts.value++
  3623. console.log(`👉 尝试重连 (${reconnectAttempts.value}/${maxReconnectAttempts.value})`)
  3624. reconnectTimer.value = setTimeout(() => {
  3625. createWebSocketConnection()
  3626. }, reconnectInterval.value) as unknown as NodeJS.Timeout
  3627. }
  3628. else {
  3629. console.error('👉 WebSocket重连次数已达上限,停止重连')
  3630. // 可以在这里显示用户提示
  3631. message.error( lang.ssNetError )
  3632. }
  3633. }
  3634. // 启动 socket 连接检查定时器
  3635. const startSocketCheckTimer = () => {
  3636. // 清理之前的定时器
  3637. if (socketCheckTimer.value) {
  3638. clearInterval(socketCheckTimer.value)
  3639. socketCheckTimer.value = null
  3640. }
  3641. // 每10秒检查一次 socket 连接状态
  3642. socketCheckTimer.value = setInterval(() => {
  3643. if (providerSocket.value) {
  3644. // 直接检查 providerSocket 的连接状态
  3645. // WebsocketProvider 有一个 connected 属性来表示连接状态
  3646. const isConnected = (providerSocket.value as any).ws.readyState
  3647. console.log('🔍 定时器检查 socket 连接状态:', isConnected)
  3648. if (isConnected !== 1) {
  3649. console.log('🔍 定时器检查发现 socket 未连接,执行重连')
  3650. createWebSocketConnection(2)
  3651. }
  3652. }
  3653. }, 10000) as unknown as NodeJS.Timeout
  3654. }
  3655. // 工具函数:格式化时间
  3656. const formatTime = (totalSec: number) => {
  3657. const m = Math.floor(totalSec / 60)
  3658. const s = Math.floor(totalSec % 60)
  3659. return `${fillDigit(m, 2)}:${fillDigit(s, 2)}`
  3660. }
  3661. // 块状时间显示
  3662. const timerBlocks = () => {
  3663. const total = timerIndicator.value.isCountdown
  3664. ? Math.max(timerIndicator.value.remainingSec || 0, 0)
  3665. : Math.max(timerIndicator.value.elapsedSec || 0, 0)
  3666. const h = Math.floor(total / 3600)
  3667. const m = Math.floor((total % 3600) / 60)
  3668. const s = Math.floor(total % 60)
  3669. return {
  3670. h: fillDigit(h, 2),
  3671. m: fillDigit(m, 2),
  3672. s: fillDigit(s, 2),
  3673. }
  3674. }
  3675. // 块可见性:始终显示时分秒
  3676. const timerBlocksVisibility = () => {
  3677. return {
  3678. showH: true,
  3679. showM: true,
  3680. }
  3681. }
  3682. // 根据布局避免遮挡右侧面板
  3683. const getTimerIndicatorRight = () => {
  3684. if (isFullscreen.value) {
  3685. return 16
  3686. }
  3687. if (props.type === '1') {
  3688. // 右侧面板展开时向左让位
  3689. return workPanelCollapsed.value ? 65 : 420
  3690. }
  3691. return 65
  3692. }
  3693. // 计时器本地更新
  3694. const startLocalTick = (isCountdown: boolean) => {
  3695. if (timerInterval.value) {
  3696. clearInterval(timerInterval.value)
  3697. timerInterval.value = null
  3698. }
  3699. timerInterval.value = setInterval(() => {
  3700. if (isCountdown) {
  3701. if (timerIndicator.value.remainingSec !== null) {
  3702. const newRemaining = (timerIndicator.value.remainingSec as number) - 1
  3703. timerIndicator.value.remainingSec = Math.max(newRemaining, 0)
  3704. // 时间到了,标记为完成但保持显示
  3705. if (newRemaining <= 0) {
  3706. timerIndicator.value.finished = true
  3707. timerIndicator.value.remainingSec = 0
  3708. // 保持 visible 为 true,不隐藏
  3709. timerIndicator.value.visible = true
  3710. }
  3711. }
  3712. }
  3713. else {
  3714. if (timerIndicator.value.elapsedSec !== null) {
  3715. timerIndicator.value.elapsedSec = (timerIndicator.value.elapsedSec as number) + 1
  3716. }
  3717. }
  3718. }, 1000) as unknown as number
  3719. }
  3720. // CountdownTimer 事件(仅创建人触发发送)
  3721. const onTimerStart = (payload: { isCountdown: boolean; startAt: string; durationSec?: number }) => {
  3722. timerIndicator.value.visible = true
  3723. timerIndicator.value.isCountdown = payload.isCountdown
  3724. timerIndicator.value.startAt = payload.startAt
  3725. timerIndicator.value.durationSec = payload.isCountdown ? (payload.durationSec || 0) : null
  3726. timerIndicator.value.elapsedSec = payload.isCountdown ? null : 0
  3727. timerIndicator.value.remainingSec = payload.isCountdown ? (payload.durationSec || 0) : null
  3728. timerIndicator.value.finished = false
  3729. startLocalTick(payload.isCountdown)
  3730. if (isCreator.value) {
  3731. sendMessage({ type: 'timer_start', courseid: props.courseid, payload })
  3732. // 持久化状态到 YMap(带运行状态与基线)
  3733. const isCd = payload.isCountdown
  3734. const state: any = {
  3735. visible: true,
  3736. isCountdown: isCd,
  3737. status: 'running',
  3738. startAt: payload.startAt,
  3739. durationSec: isCd ? (payload.durationSec || 0) : null,
  3740. finished: false,
  3741. stopped: false,
  3742. }
  3743. if (isCd) {
  3744. state.remainingBaseSec = payload.durationSec || 0
  3745. state.elapsedBaseSec = null
  3746. }
  3747. else {
  3748. state.elapsedBaseSec = 0
  3749. state.remainingBaseSec = null
  3750. }
  3751. setTimerState(state)
  3752. }
  3753. }
  3754. const onTimerPause = () => {
  3755. if (timerInterval.value) {
  3756. clearInterval(timerInterval.value)
  3757. timerInterval.value = null
  3758. }
  3759. if (isCreator.value) {
  3760. sendMessage({ type: 'timer_pause', courseid: props.courseid })
  3761. // 将当前显示值作为基线写入,并标记暂停
  3762. const isCd = !!timerIndicator.value.isCountdown
  3763. const payload: any = {
  3764. ...getTimerState(),
  3765. status: 'paused',
  3766. pausedAt: new Date().toISOString(),
  3767. finished: !!timerIndicator.value.finished,
  3768. stopped: false,
  3769. }
  3770. if (isCd) {
  3771. payload.remainingBaseSec = Math.max(Number(timerIndicator.value.remainingSec || 0), 0)
  3772. payload.elapsedBaseSec = null
  3773. }
  3774. else {
  3775. payload.elapsedBaseSec = Math.max(Number(timerIndicator.value.elapsedSec || 0), 0)
  3776. payload.remainingBaseSec = null
  3777. }
  3778. setTimerState(payload)
  3779. }
  3780. }
  3781. const onTimerReset = () => {
  3782. if (timerInterval.value) {
  3783. clearInterval(timerInterval.value)
  3784. timerInterval.value = null
  3785. }
  3786. timerIndicator.value = { visible: false, isCountdown: false, startAt: null, durationSec: null, elapsedSec: null, remainingSec: null, finished: false }
  3787. if (isCreator.value) {
  3788. sendMessage({ type: 'timer_reset', courseid: props.courseid })
  3789. clearTimerState()
  3790. }
  3791. }
  3792. const onTimerStop = () => {
  3793. if (timerInterval.value) {
  3794. clearInterval(timerInterval.value)
  3795. timerInterval.value = null
  3796. }
  3797. timerIndicator.value = { visible: false, isCountdown: false, startAt: null, durationSec: null, elapsedSec: null, remainingSec: null, finished: false }
  3798. if (isCreator.value) {
  3799. sendMessage({ type: 'timer_stop', courseid: props.courseid })
  3800. clearTimerState()
  3801. }
  3802. }
  3803. const onTimerFinish = () => {
  3804. timerIndicator.value.finished = true
  3805. // 保持 visible 为 true,时间到了也不消失
  3806. timerIndicator.value.visible = true
  3807. if (timerIndicator.value.isCountdown) {
  3808. timerIndicator.value.remainingSec = 0
  3809. }
  3810. if (timerInterval.value) {
  3811. clearInterval(timerInterval.value)
  3812. timerInterval.value = null
  3813. }
  3814. if (isCreator.value) {
  3815. sendMessage({ type: 'timer_finish', courseid: props.courseid })
  3816. const snap = getTimerState()
  3817. setTimerState({ ...snap, status: 'finished', finished: true, stopped: true, remainingBaseSec: 0 })
  3818. }
  3819. }
  3820. const onTimerUpdate = (payload: { durationSec: number }) => {
  3821. if (isCreator.value && timerIndicator.value.visible && timerIndicator.value.isCountdown) {
  3822. // 重新设置开始时间,重置整个计时
  3823. const newStartAt = new Date().toISOString()
  3824. // 更新本地状态
  3825. timerIndicator.value.startAt = newStartAt
  3826. timerIndicator.value.durationSec = payload.durationSec
  3827. timerIndicator.value.remainingSec = payload.durationSec
  3828. timerIndicator.value.finished = false
  3829. // 重新开始本地计时
  3830. startLocalTick(true)
  3831. // 更新 YMap 状态
  3832. const snap = getTimerState()
  3833. setTimerState({
  3834. ...snap,
  3835. status: 'running',
  3836. startAt: newStartAt,
  3837. durationSec: payload.durationSec,
  3838. remainingBaseSec: payload.durationSec,
  3839. finished: false,
  3840. })
  3841. // 发送消息通知其他用户(使用 timer_start 消息重新开始计时)
  3842. sendMessage({
  3843. type: 'timer_start',
  3844. courseid: props.courseid,
  3845. payload: {
  3846. isCountdown: true,
  3847. startAt: newStartAt,
  3848. durationSec: payload.durationSec
  3849. }
  3850. })
  3851. }
  3852. }
  3853. // 消息应用(任意端)
  3854. const applyTimerStart = (payload: { isCountdown: boolean; startAt: string; durationSec?: number }) => {
  3855. timerIndicator.value.visible = true
  3856. timerIndicator.value.isCountdown = payload.isCountdown
  3857. timerIndicator.value.startAt = payload.startAt
  3858. timerIndicator.value.durationSec = payload.isCountdown ? (payload.durationSec || 0) : null
  3859. // 以消息时间为基准纠正进度
  3860. const startTs = new Date(payload.startAt).getTime()
  3861. const nowTs = Date.now()
  3862. if (payload.isCountdown) {
  3863. const elapsed = Math.floor((nowTs - startTs) / 1000)
  3864. timerIndicator.value.remainingSec = Math.max((payload.durationSec || 0) - elapsed, 0)
  3865. timerIndicator.value.elapsedSec = null
  3866. }
  3867. else {
  3868. timerIndicator.value.elapsedSec = Math.floor((nowTs - startTs) / 1000)
  3869. timerIndicator.value.remainingSec = null
  3870. }
  3871. timerIndicator.value.finished = false
  3872. startLocalTick(payload.isCountdown)
  3873. }
  3874. const applyTimerPause = () => {
  3875. if (timerInterval.value) {
  3876. clearInterval(timerInterval.value)
  3877. timerInterval.value = null
  3878. }
  3879. }
  3880. const applyTimerReset = () => {
  3881. if (timerInterval.value) {
  3882. clearInterval(timerInterval.value)
  3883. timerInterval.value = null
  3884. }
  3885. timerIndicator.value = { visible: false, isCountdown: false, startAt: null, durationSec: null, elapsedSec: null, remainingSec: null, finished: false }
  3886. }
  3887. const applyTimerStop = () => {
  3888. if (timerInterval.value) {
  3889. clearInterval(timerInterval.value)
  3890. timerInterval.value = null
  3891. }
  3892. timerIndicator.value = { visible: false, isCountdown: false, startAt: null, durationSec: null, elapsedSec: null, remainingSec: null, finished: false }
  3893. }
  3894. const applyTimerFinish = () => {
  3895. timerIndicator.value.finished = true
  3896. // 保持 visible 为 true,时间到了也不消失
  3897. timerIndicator.value.visible = true
  3898. if (timerIndicator.value.isCountdown) {
  3899. timerIndicator.value.remainingSec = 0
  3900. }
  3901. if (timerInterval.value) {
  3902. clearInterval(timerInterval.value)
  3903. timerInterval.value = null
  3904. }
  3905. }
  3906. const applyTimerUpdate = (payload: { durationSec: number; startAt?: string }) => {
  3907. if (timerIndicator.value.visible && timerIndicator.value.isCountdown) {
  3908. const newStartAt = payload.startAt || new Date().toISOString()
  3909. // 更新状态
  3910. timerIndicator.value.startAt = newStartAt
  3911. timerIndicator.value.durationSec = payload.durationSec
  3912. timerIndicator.value.remainingSec = payload.durationSec
  3913. timerIndicator.value.finished = false
  3914. // 重新开始本地计时
  3915. startLocalTick(true)
  3916. }
  3917. }
  3918. // 应用激光笔共享状态(任意端)
  3919. const applyLaserStateSnapshot = (snap: any) => {
  3920. if (!snap) return
  3921. const enabled = snap.enabled !== undefined ? !!snap.enabled : laserPenOverlay.value.visible
  3922. const x = typeof snap.x === 'number' ? snap.x : null
  3923. const y = typeof snap.y === 'number' ? snap.y : null
  3924. if (props.type == '2') {
  3925. // 更新开关状态
  3926. if (snap.enabled !== undefined) {
  3927. laserPenOverlay.value.visible = enabled
  3928. }
  3929. // 如果激光笔是开启状态,更新位置
  3930. if (laserPenOverlay.value.visible && x != null && y != null) {
  3931. laserPenOverlay.value.xPct = x
  3932. laserPenOverlay.value.yPct = y
  3933. refreshLaserOverlayRect()
  3934. if (laserMoveRafId) cancelAnimationFrame(laserMoveRafId)
  3935. laserMoveRafId = requestAnimationFrame(updateLaserDotPosition)
  3936. }
  3937. }
  3938. }
  3939. // YMap 状态应用
  3940. const applyTimerStateSnapshot = (snap: any) => {
  3941. if (!snap || !snap.visible) {
  3942. return
  3943. }
  3944. const isCountdown = !!snap.isCountdown
  3945. const status = snap.status as string | undefined
  3946. const startAt = snap.startAt as string
  3947. const durationSec = isCountdown ? Number(snap.durationSec || 0) : null
  3948. const finished = !!snap.finished
  3949. const elapsedBaseSec = snap.elapsedBaseSec != null ? Number(snap.elapsedBaseSec) : null
  3950. const remainingBaseSec = snap.remainingBaseSec != null ? Number(snap.remainingBaseSec) : null
  3951. timerIndicator.value.visible = true
  3952. timerIndicator.value.isCountdown = isCountdown
  3953. timerIndicator.value.startAt = startAt
  3954. timerIndicator.value.durationSec = durationSec
  3955. const startTs = new Date(startAt).getTime()
  3956. const nowTs = Date.now()
  3957. if (isCountdown) {
  3958. if (status === 'paused') {
  3959. timerIndicator.value.remainingSec = Math.max(remainingBaseSec || 0, 0)
  3960. timerIndicator.value.elapsedSec = null
  3961. timerIndicator.value.finished = !!finished || (timerIndicator.value.remainingSec as number) <= 0
  3962. if (timerInterval.value) {
  3963. clearInterval(timerInterval.value); timerInterval.value = null
  3964. }
  3965. return
  3966. }
  3967. const base = remainingBaseSec != null ? remainingBaseSec : (durationSec || 0)
  3968. const elapsed = Math.floor((nowTs - startTs) / 1000)
  3969. timerIndicator.value.remainingSec = Math.max(base - elapsed, 0)
  3970. timerIndicator.value.elapsedSec = null
  3971. if (finished || (timerIndicator.value.remainingSec as number) <= 0) {
  3972. timerIndicator.value.finished = true
  3973. timerIndicator.value.remainingSec = 0
  3974. // 保持 visible 为 true,时间到了也不消失
  3975. timerIndicator.value.visible = true
  3976. if (timerInterval.value) {
  3977. clearInterval(timerInterval.value); timerInterval.value = null
  3978. }
  3979. }
  3980. else {
  3981. timerIndicator.value.finished = false
  3982. startLocalTick(true)
  3983. }
  3984. }
  3985. else {
  3986. if (status === 'paused') {
  3987. timerIndicator.value.elapsedSec = Math.max(elapsedBaseSec || 0, 0)
  3988. timerIndicator.value.remainingSec = null
  3989. timerIndicator.value.finished = !!finished
  3990. if (timerInterval.value) {
  3991. clearInterval(timerInterval.value); timerInterval.value = null
  3992. }
  3993. return
  3994. }
  3995. const base = elapsedBaseSec != null ? elapsedBaseSec : 0
  3996. const elapsed = Math.floor((nowTs - startTs) / 1000)
  3997. timerIndicator.value.elapsedSec = base + elapsed
  3998. timerIndicator.value.remainingSec = null
  3999. if (finished) {
  4000. if (timerInterval.value) {
  4001. clearInterval(timerInterval.value); timerInterval.value = null
  4002. }
  4003. timerIndicator.value.finished = true
  4004. }
  4005. else {
  4006. timerIndicator.value.finished = false
  4007. startLocalTick(false)
  4008. }
  4009. }
  4010. }
  4011. // 读写 YMap 工具
  4012. const getTimerState = () => {
  4013. if (!yTimerState.value) return {}
  4014. return yTimerState.value.toJSON()
  4015. }
  4016. const setTimerState = (state: any) => {
  4017. if (!yTimerState.value) return
  4018. docSocket.value?.transact(() => {
  4019. Object.entries(state).forEach(([k, v]) => yTimerState.value.set(k, v as any))
  4020. yTimerState.value.set('visible', true)
  4021. })
  4022. }
  4023. const clearTimerState = () => {
  4024. if (!yTimerState.value) return
  4025. docSocket.value?.transact(() => {
  4026. yTimerState.value.clear()
  4027. })
  4028. }
  4029. </script>
  4030. <style lang="scss" scoped>
  4031. .pptist-student-viewer {
  4032. height: 100vh;
  4033. display: flex;
  4034. background-color: #f4f4f4;
  4035. padding: 15px 0;
  4036. box-sizing: border-box;
  4037. // 全屏模式样式
  4038. &.fullscreen {
  4039. padding: 0;
  4040. .layout-content-left {
  4041. display: none; // 全屏时隐藏左侧导航栏
  4042. }
  4043. .layout-content-right {
  4044. display: none; // 全屏时隐藏左侧导航栏
  4045. }
  4046. .viewer-header {
  4047. display: none; // 全屏时隐藏顶部标题栏
  4048. }
  4049. }
  4050. // 激光笔模式样式
  4051. }
  4052. .layout-content-left {
  4053. width: 200px;
  4054. height: 100%;
  4055. background-color: #fff;
  4056. border-radius: 0 5px 0 5px;
  4057. overflow: hidden;
  4058. transition: width .2s ease;
  4059. margin: 10px;
  4060. }
  4061. .layout-content-left.collapsed {
  4062. width: 48px;
  4063. margin-left: 0;
  4064. }
  4065. .slide-header {
  4066. display: flex;
  4067. align-items: center;
  4068. justify-content: space-between;
  4069. }
  4070. /* 收缩时头部仅显示按钮,并保持按钮在可用宽度内水平居中 */
  4071. .layout-content-left.collapsed .slide-header {
  4072. justify-content: center;
  4073. padding: 8px;
  4074. }
  4075. .layout-content-right {
  4076. width: 350px;
  4077. height: 100%;
  4078. background-color: #fff;
  4079. border-radius: 5px 0 5px 0;
  4080. overflow: hidden;
  4081. transition: width .2s ease;
  4082. position: relative;
  4083. margin: 10px;
  4084. }
  4085. .panel-content {
  4086. margin-right: 0;
  4087. // padding: 0 8px;
  4088. height: calc(100% - 65px);
  4089. overflow: auto;
  4090. }
  4091. .layout-content-right.collapsed {
  4092. width: 52px;
  4093. margin-right: 0px;
  4094. }
  4095. .right-panel-header {
  4096. display: flex;
  4097. align-items: center;
  4098. justify-content: space-between;
  4099. }
  4100. /* 侧边导航标签样式 */
  4101. .side-nav-tabs {
  4102. position: absolute;
  4103. right: 0;
  4104. top: 60px;
  4105. bottom: 0;
  4106. width: 52px;
  4107. display: flex;
  4108. flex-direction: column;
  4109. gap: 8px;
  4110. padding: 8px 0;
  4111. align-items: center;
  4112. background: #fff;
  4113. border-left: 1px solid #e0e0e0;
  4114. z-index: 10;
  4115. }
  4116. .side-nav-btn {
  4117. width: 45px;
  4118. height: 45px;
  4119. min-height: 45px;
  4120. border: 1px solid #d9d9d9;
  4121. background: #fff;
  4122. border-radius: 6px;
  4123. cursor: pointer;
  4124. transition: all 0.2s;
  4125. display: flex;
  4126. align-items: center;
  4127. justify-content: center;
  4128. padding: 8px;
  4129. gap: 8px;
  4130. overflow: hidden;
  4131. &:hover {
  4132. border-color: #1890ff;
  4133. transform: scale(1.02);
  4134. }
  4135. &.active {
  4136. border-color: #3681fc;
  4137. background: #3681fc;
  4138. box-shadow: 0 0 0 2px rgba(54, 129, 252, 0.2);
  4139. }
  4140. img {
  4141. width: 25px;
  4142. height: 25px;
  4143. object-fit: contain;
  4144. flex-shrink: 0;
  4145. }
  4146. span {
  4147. font-size: 12px;
  4148. font-weight: 500;
  4149. color: #333;
  4150. white-space: nowrap;
  4151. overflow: hidden;
  4152. text-overflow: ellipsis;
  4153. }
  4154. &.active span {
  4155. color: #fff;
  4156. }
  4157. }
  4158. /* 收缩时头部仅显示按钮,并保持按钮在可用宽度内水平居中 */
  4159. .layout-content-right.collapsed .right-panel-header {
  4160. justify-content: center;
  4161. padding: 8px;
  4162. }
  4163. /* 收缩状态下的切换按钮 */
  4164. .collapsed-tabs {
  4165. display: flex;
  4166. flex-direction: column;
  4167. gap: 8px;
  4168. // padding: 8px;
  4169. align-items: center;
  4170. }
  4171. .collapsed-tab-btn {
  4172. width: 32px;
  4173. height: 32px;
  4174. border: 1px solid #d9d9d9;
  4175. background: #fff;
  4176. border-radius: 6px;
  4177. cursor: pointer;
  4178. transition: all 0.2s;
  4179. display: flex;
  4180. align-items: center;
  4181. justify-content: center;
  4182. padding: 0;
  4183. overflow: hidden;
  4184. &:hover {
  4185. border-color: #1890ff;
  4186. transform: scale(1.05);
  4187. }
  4188. &.active {
  4189. border-color: #3681fc;
  4190. background: #3681fc;
  4191. box-shadow: 0 0 0 2px rgba(54, 129, 252, 0.2);
  4192. }
  4193. img {
  4194. width: 20px;
  4195. height: 20px;
  4196. object-fit: contain;
  4197. transition: transform 0.2s;
  4198. }
  4199. &:hover img {
  4200. transform: scale(1.1);
  4201. }
  4202. }
  4203. .collapse-btn {
  4204. display: inline-flex;
  4205. align-items: center;
  4206. justify-content: center;
  4207. width: 32px;
  4208. height: 32px;
  4209. // border: 1px solid #d9d9d9;
  4210. border: none;
  4211. border-radius: 8px;
  4212. background: #fff;
  4213. color: #333;
  4214. cursor: pointer;
  4215. line-height: 1;
  4216. font-weight: 700;
  4217. position: absolute;
  4218. }
  4219. .collapse-btn:hover {
  4220. // border-color: #1890ff;
  4221. // color: #1890ff;
  4222. }
  4223. .homework-title {
  4224. padding: 12px 12px 0 12px;
  4225. color: #333;
  4226. font-size: 14px;
  4227. font-weight: 600;
  4228. }
  4229. .homework-grid {
  4230. display: grid;
  4231. grid-template-columns: repeat(4, 1fr);
  4232. gap: 16px;
  4233. padding: 12px;
  4234. }
  4235. .homework-btn {
  4236. display: inline-flex;
  4237. align-items: center;
  4238. justify-content: center;
  4239. width: 100%;
  4240. min-width: 0;
  4241. height: 35px;
  4242. border: 1px solid #2f80ed;
  4243. color: #2f80ed;
  4244. background: #fff;
  4245. border-radius: 8px;
  4246. cursor: pointer;
  4247. font-weight: 600;
  4248. overflow: hidden;
  4249. padding: 0 10px;
  4250. text-align: center;
  4251. }
  4252. .homework-btn__text {
  4253. display: block;
  4254. max-width: 100%;
  4255. overflow: hidden;
  4256. white-space: nowrap;
  4257. text-overflow: ellipsis;
  4258. }
  4259. .homework-btn:hover {
  4260. box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  4261. }
  4262. .homework-btn.unsubmitted {
  4263. border-color: #d9d9d9;
  4264. color: #999;
  4265. background: #f5f5f5;
  4266. cursor: not-allowed;
  4267. }
  4268. .homework-btn.unsubmitted:hover {
  4269. box-shadow: none;
  4270. transform: none;
  4271. }
  4272. .homework-loading {
  4273. padding: 12px;
  4274. color: #666;
  4275. font-size: 13px;
  4276. }
  4277. .homework-empty {
  4278. padding: 12px;
  4279. color: #999;
  4280. font-size: 13px;
  4281. }
  4282. .thumbnails {
  4283. padding: 0;
  4284. height: 100%;
  4285. .viewer-header {
  4286. margin-bottom: 16px;
  4287. h3 {
  4288. margin: 0;
  4289. font-size: 16px;
  4290. font-weight: 600;
  4291. color: #333;
  4292. text-align: center;
  4293. width: 100%;
  4294. }
  4295. }
  4296. .thumbnail-list {
  4297. width: 100%;
  4298. padding: 0 16px;
  4299. box-sizing: border-box;
  4300. .thumbnail-item {
  4301. position: relative;
  4302. margin-bottom: 12px;
  4303. cursor: pointer;
  4304. border-radius: 8px;
  4305. overflow: hidden;
  4306. transition: all 0.2s ease;
  4307. border: 2px solid rgba(24, 144, 255, 0.2);
  4308. &:hover {
  4309. transform: translateY(-2px);
  4310. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  4311. border-color: rgba(24, 144, 255, 0.4);
  4312. }
  4313. &.active {
  4314. border: 2px solid #1890ff;
  4315. box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
  4316. }
  4317. .label {
  4318. position: absolute;
  4319. top: 8px;
  4320. left: 8px;
  4321. background-color: rgba(0, 0, 0, 0.6);
  4322. color: #fff;
  4323. padding: 2px 6px;
  4324. border-radius: 4px;
  4325. font-size: 12px;
  4326. font-weight: 600;
  4327. z-index: 1;
  4328. }
  4329. .thumbnail {
  4330. width: 100%;
  4331. height: auto;
  4332. }
  4333. }
  4334. }
  4335. .page-number {
  4336. text-align: center;
  4337. margin-top: 16px;
  4338. padding: 8px;
  4339. background-color: #f0f0f0;
  4340. border-radius: 4px;
  4341. font-size: 14px;
  4342. color: #666;
  4343. }
  4344. .progress-bar {
  4345. margin-top: 12px;
  4346. height: 6px;
  4347. background-color: #f0f0f0;
  4348. border-radius: 3px;
  4349. overflow: hidden;
  4350. .progress-fill {
  4351. height: 100%;
  4352. background: linear-gradient(90deg, #1890ff, #40a9ff);
  4353. border-radius: 3px;
  4354. transition: width 0.3s ease;
  4355. }
  4356. }
  4357. }
  4358. .layout-content-center {
  4359. flex: 1;
  4360. display: flex;
  4361. flex-direction: column;
  4362. background-color: #000;
  4363. }
  4364. .viewer-header {
  4365. height: 45px;
  4366. background-color: #fff;
  4367. border-bottom: 1px solid #e0e0e0;
  4368. display: flex;
  4369. align-items: center;
  4370. justify-content: space-between;
  4371. padding: 0 8px;
  4372. transition: transform 0.3s ease;
  4373. position: relative;
  4374. &.hidden {
  4375. transform: translateY(-100%);
  4376. }
  4377. .slide-title {
  4378. font-size: 18px;
  4379. font-weight: 600;
  4380. color: #333;
  4381. }
  4382. .viewer-controls {
  4383. display: flex;
  4384. gap: 12px;
  4385. button {
  4386. padding: 8px 12px;
  4387. border: 1px solid #d9d9d9;
  4388. border-radius: 6px;
  4389. background-color: #fff;
  4390. color: #333;
  4391. cursor: pointer;
  4392. transition: all 0.2s ease;
  4393. display: flex;
  4394. align-items: center;
  4395. justify-content: center;
  4396. min-width: 40px;
  4397. height: 36px;
  4398. &:hover:not(:disabled) {
  4399. border-color: #1890ff;
  4400. color: #1890ff;
  4401. }
  4402. &:disabled {
  4403. opacity: 0.5;
  4404. cursor: not-allowed;
  4405. }
  4406. &.back-btn {
  4407. background-color: #1890ff;
  4408. color: #fff;
  4409. border-color: #1890ff;
  4410. &:hover {
  4411. background-color: #40a9ff;
  4412. border-color: #40a9ff;
  4413. }
  4414. }
  4415. &.follow-active {
  4416. background-color: #3681fc;
  4417. color: #fff !important;
  4418. border-color: #3681fc;
  4419. &:hover {
  4420. background-color: #2d6fd9;
  4421. border-color: #2d6fd9;
  4422. color: #fff !important;
  4423. }
  4424. }
  4425. .control-icon {
  4426. font-size: 16px;
  4427. }
  4428. }
  4429. }
  4430. }
  4431. .viewer-canvas {
  4432. flex: 1;
  4433. position: relative;
  4434. background-color: rgb(244, 244, 244);
  4435. overflow: hidden;
  4436. // 全屏时隐藏滚动条和边框
  4437. &.fullscreen-mode {
  4438. overflow: hidden !important;
  4439. background-color: transparent !important;
  4440. }
  4441. }
  4442. .slide-list-wrap {
  4443. position: absolute;
  4444. overflow: hidden;
  4445. background-color: #fff;
  4446. box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.01), 0 0 12px 0 rgba(0, 0, 0, 0.1);
  4447. border-radius: 8px;
  4448. /* 全屏时去掉圆角 */
  4449. .pptist-student-viewer.fullscreen & {
  4450. border-radius: 0;
  4451. }
  4452. }
  4453. .slide-list-wrap-n{
  4454. border: 5px solid #595959;
  4455. background: #000;
  4456. padding: 65px 0 0 0;
  4457. box-sizing: border-box;
  4458. }
  4459. /* 学生端激光笔覆盖层与小圆点样式(拦截点击) */
  4460. .laser-pointer-overlay {
  4461. position: fixed;
  4462. inset: 0;
  4463. z-index: 1000;
  4464. pointer-events: auto;
  4465. }
  4466. .laser-pointer-dot {
  4467. position: absolute;
  4468. width: 24px;
  4469. height: 24px;
  4470. pointer-events: none;
  4471. /* 复用 .laser-pen 的光点视觉(使用与 cursor 相同的图) */
  4472. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABHNCSVQICAgIfAhkiAAACCJJREFUWIXtmLuO3MYShv/qZl9IzqwXo2BkSAtsIK+z8wwOBcOJ9C56Cr2LlThQcgBnfofVBnswXlgTaLHaIdk3dtcJOKOzd8n2MeDABRDDgKz/m+pudv0N/BN/Luj/kYSZJQBxJR8DKESU/2zuPwTIzAKnpxqHhxUuLir0vYSUAkS0ewA5F7Rtxv7+iNPTEYeHkYjKXwrIzHK9XtultRohaKSkkFIVhqGCEAIxTvm0ZpRSTNOMUGqEUgnGxLX3cblc+t9T2S8GXK1W9dP53OLiwoLZhMtLQ4CiGBVKkchZIOcpn5QMKQuEyKx1YiCZvb0AooD9ff/rZuMPDg7cl+hWn3uAmQWABut1g/PzOnZdTd5bMY6aQtAIQQGQGEd5bYirKgPIZExiY2IKIbK1XpeinzaN2s7b4XPD/iAgM0ucn7fYbNrQ963Juaauq8k5i3E01PcG46iQs0TO1wGlzJAyo6oS2jagqgLGUQNQwTllvJeYzwUz9w8N+b2AzCxwft6i72fBuZkYhnbcbBqKsSbvazhnEIJBzqrEqGQpAlO1AaKShShC6wQpE4UQUNcBKenReyXm8yoIIYwQtNXq7qvkQxVssNm0wbmZuLiYUQgtnGtps2ngfQ3vLaVkEKOmGKcqMtMWkEnKTFonaB3Z+4AQPFmreD6vSAghxpECAFMKY7EoALovBlytVjXW6yb0fSuGoaUQWrq8nKHvW/R9S943xbmavJ+qmNIO8FMFIWXert7A1gYxjprHsSLmaTHt7UF0HYdSilmv82q1ynctnFuAzCzx8aPF+Xltcq7HzaaBcy36vsUwzKjrZhiGRgxDA+8tUjIUgkbOEqVMgEIUkjLDmAjvgwjBI6WKxlHybp5KyVRKMcaMGIb0dLFIzBxvzsdbgOv12i69t7HrpgURY02bTYO+b6nrZui6qZLONdz3jTg5ORDHx0f48OExQpgBAIzp8OjRez46Oi7Pnq1ot5BKETQVgYmosJRj6rrEQNJCxLX3EUB/LyAzC3z8qOGcIe8tOWdpmm81ed9gGJpdJdF1rXz79jucnX1za454P8fZ2ZzOzr6Rx8fvyvPnP38afiEKVVXmqhrJ+wSlIqoqYj73S2s1M7urC0ZcS3x6qhGCDpeXBuOoMY4Gzhl4b4tzNYahgXMNuq4Vb978cCfczTg7+0a8efMDuq6Fcw2GoSnO1fDewjmDcTQYx0kzBI3TU3319euAh4cVUlIEKApBU98bhGAoJSO8N/Dect834u3b73B+/vVn4XZxfv61ePv2O+77Bt5b4b2hlKbcfW8oBE2AQkoKh4fXRvU64MVFhZQqilEhBLX9CCvEqLer1YiTk4MvqtxdlTw5OcAWDDFq5DxphDBtmSlNzcddgMws0fcyDEOFUiQAiZxliVGVGFVJSXEImo6Pj3433Dbo+PiIQ9AlJbXLi5wnrVIm7b6X223wOiAAASkFhBDIWWAcJXKWshQhcpYiZ0k5S3z48PhO9ZcvgV9+ma6XL+8m/PDhMW1ziW1u5Cy3WpO2lOIq11VAAhEhRkLO0z0RgVmAefotRXz6lNyMV6+AxWK6Xr26GzCEGXZb4i7nTifnSXv6Tn7qssTdmf4+cRWQwczQmiHldM/MICogmn6FKDDmzj0Tr18D5+fT9fr13WrGdBCiXMu505Fy0mZmTJYBwPUPdUHOBaUUSFlQVRlS5rzbtqTMJGXGo0fvcXY2vyX+44/T9VA8evSepcy8zcdCFDG1ZBlSTto5FwC3P9RElNG22TTNCCEygAwps9A6Ca2TUCqRMZGPjo4fprg/+OjomIyJQqm0ywspJy0hJu22zVf34+tzcH9/hFIja51gTEJVJUiZoHWEMQFKhfLs2QpPnrz73XRPnrwrz56toFSAMQFaR0g5aRiTWOsEpUbs749XX7u51Y1QKjGQ2JjIbRtgTGClQrE2wFpPbTuU589/xmLx2xfDLRa/lefPf6a2HWCtL9YG3oJy2wY2JjKQoFTC6ekDgIeHEcZEs7cXUFURVTV1wtZ6UdcOTTOgrgfMZn158eKnL6rkkyfvyosXP2E261HXA5pmEHXtYK1HXU9WoKomTWMiDg/j1devbStEVN6/fx+XRIGt9RhHjZQ0Wat4HCsax//1fEQlf//9v8XJyTF9rt1q2+mPtW2PphnY2gHWOrbWcV17ttaDKKy9j4/398u9gACwXC49Pn7UuhQNQI3eT206s2DadptCFEiZqaoS/+tfvnz77X/oRsPKUmYyJpJSAdZ6NM2Aphl4Pu/QND3P5wO0dmo2c5jNHPb3/fKrr/xNnluARJRXq5V/2jQqOKfE1kPsPC8zM1VVLkqNwpiAEAxbq+hGy89SZtq2/MXaIOrasbUDmqZH2/Zo257bdghSOtM07tfNxh/s799yd3d6koODA8fM0ngvw9bgYG9vatOJClfVSFUVYe3UldxhmiBlxtY0kVLTlLHW8Xw+oG17NqYvs1lv6rrHcjkcEN1p5B9ydQPmc2GEoABAdB1TKYWlnDph5wJvbSdPpwvXbCcLUXhrO2FMQF0HttZBa8dtO5TZrDdt26FtewDDfRD3AhJRYeYemKxh2Bqc1HVTm17Xn4y7yFnyDeMurhh33hp3rmuvZjMXpHSmrqehXiz6h04XHjxZIKLMzB0Wi2LW64xhSAwkVFXEOGpo/dmjD2yPPlBVka31mM2caRqH5XLAnz362FUSQLdarfLTxSJpISLmcx8uLw217R8/PLpnzt3S/5KHdvG3Pn67Afr3PMB8APgvOwL+J/5s/BeEBm1u1Gu4+QAAAABJRU5ErkJggg==);
  4473. background-repeat: no-repeat;
  4474. background-position: center center;
  4475. background-size: contain;
  4476. /* 居中到指针 */
  4477. transform: translate3d(-12px, -12px, 0);
  4478. will-change: transform;
  4479. }
  4480. .laser-pen {
  4481. cursor: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABHNCSVQICAgIfAhkiAAACCJJREFUWIXtmLuO3MYShv/qZl9IzqwXo2BkSAtsIK+z8wwOBcOJ9C56Cr2LlThQcgBnfofVBnswXlgTaLHaIdk3dtcJOKOzd8n2MeDABRDDgKz/m+pudv0N/BN/Luj/kYSZJQBxJR8DKESU/2zuPwTIzAKnpxqHhxUuLir0vYSUAkS0ewA5F7Rtxv7+iNPTEYeHkYjKXwrIzHK9XtultRohaKSkkFIVhqGCEAIxTvm0ZpRSTNOMUGqEUgnGxLX3cblc+t9T2S8GXK1W9dP53OLiwoLZhMtLQ4CiGBVKkchZIOcpn5QMKQuEyKx1YiCZvb0AooD9ff/rZuMPDg7cl+hWn3uAmQWABut1g/PzOnZdTd5bMY6aQtAIQQGQGEd5bYirKgPIZExiY2IKIbK1XpeinzaN2s7b4XPD/iAgM0ucn7fYbNrQ963Juaauq8k5i3E01PcG46iQs0TO1wGlzJAyo6oS2jagqgLGUQNQwTllvJeYzwUz9w8N+b2AzCxwft6i72fBuZkYhnbcbBqKsSbvazhnEIJBzqrEqGQpAlO1AaKShShC6wQpE4UQUNcBKenReyXm8yoIIYwQtNXq7qvkQxVssNm0wbmZuLiYUQgtnGtps2ngfQ3vLaVkEKOmGKcqMtMWkEnKTFonaB3Z+4AQPFmreD6vSAghxpECAFMKY7EoALovBlytVjXW6yb0fSuGoaUQWrq8nKHvW/R9S943xbmavJ+qmNIO8FMFIWXert7A1gYxjprHsSLmaTHt7UF0HYdSilmv82q1ynctnFuAzCzx8aPF+Xltcq7HzaaBcy36vsUwzKjrZhiGRgxDA+8tUjIUgkbOEqVMgEIUkjLDmAjvgwjBI6WKxlHybp5KyVRKMcaMGIb0dLFIzBxvzsdbgOv12i69t7HrpgURY02bTYO+b6nrZui6qZLONdz3jTg5ORDHx0f48OExQpgBAIzp8OjRez46Oi7Pnq1ot5BKETQVgYmosJRj6rrEQNJCxLX3EUB/LyAzC3z8qOGcIe8tOWdpmm81ed9gGJpdJdF1rXz79jucnX1za454P8fZ2ZzOzr6Rx8fvyvPnP38afiEKVVXmqhrJ+wSlIqoqYj73S2s1M7urC0ZcS3x6qhGCDpeXBuOoMY4Gzhl4b4tzNYahgXMNuq4Vb978cCfczTg7+0a8efMDuq6Fcw2GoSnO1fDewjmDcTQYx0kzBI3TU3319euAh4cVUlIEKApBU98bhGAoJSO8N/Dect834u3b73B+/vVn4XZxfv61ePv2O+77Bt5b4b2hlKbcfW8oBE2AQkoKh4fXRvU64MVFhZQqilEhBLX9CCvEqLer1YiTk4MvqtxdlTw5OcAWDDFq5DxphDBtmSlNzcddgMws0fcyDEOFUiQAiZxliVGVGFVJSXEImo6Pj3433Dbo+PiIQ9AlJbXLi5wnrVIm7b6X223wOiAAASkFhBDIWWAcJXKWshQhcpYiZ0k5S3z48PhO9ZcvgV9+ma6XL+8m/PDhMW1ziW1u5Cy3WpO2lOIq11VAAhEhRkLO0z0RgVmAefotRXz6lNyMV6+AxWK6Xr26GzCEGXZb4i7nTifnSXv6Tn7qssTdmf4+cRWQwczQmiHldM/MICogmn6FKDDmzj0Tr18D5+fT9fr13WrGdBCiXMu505Fy0mZmTJYBwPUPdUHOBaUUSFlQVRlS5rzbtqTMJGXGo0fvcXY2vyX+44/T9VA8evSepcy8zcdCFDG1ZBlSTto5FwC3P9RElNG22TTNCCEygAwps9A6Ca2TUCqRMZGPjo4fprg/+OjomIyJQqm0ywspJy0hJu22zVf34+tzcH9/hFIja51gTEJVJUiZoHWEMQFKhfLs2QpPnrz73XRPnrwrz56toFSAMQFaR0g5aRiTWOsEpUbs749XX7u51Y1QKjGQ2JjIbRtgTGClQrE2wFpPbTuU589/xmLx2xfDLRa/lefPf6a2HWCtL9YG3oJy2wY2JjKQoFTC6ekDgIeHEcZEs7cXUFURVTV1wtZ6UdcOTTOgrgfMZn158eKnL6rkkyfvyosXP2E261HXA5pmEHXtYK1HXU9WoKomTWMiDg/j1devbStEVN6/fx+XRIGt9RhHjZQ0Wat4HCsax//1fEQlf//9v8XJyTF9rt1q2+mPtW2PphnY2gHWOrbWcV17ttaDKKy9j4/398u9gACwXC49Pn7UuhQNQI3eT206s2DadptCFEiZqaoS/+tfvnz77X/oRsPKUmYyJpJSAdZ6NM2Aphl4Pu/QND3P5wO0dmo2c5jNHPb3/fKrr/xNnluARJRXq5V/2jQqOKfE1kPsPC8zM1VVLkqNwpiAEAxbq+hGy89SZtq2/MXaIOrasbUDmqZH2/Zo257bdghSOtM07tfNxh/s799yd3d6koODA8fM0ngvw9bgYG9vatOJClfVSFUVYe3UldxhmiBlxtY0kVLTlLHW8Xw+oG17NqYvs1lv6rrHcjkcEN1p5B9ydQPmc2GEoABAdB1TKYWlnDph5wJvbSdPpwvXbCcLUXhrO2FMQF0HttZBa8dtO5TZrDdt26FtewDDfRD3AhJRYeYemKxh2Bqc1HVTm17Xn4y7yFnyDeMurhh33hp3rmuvZjMXpHSmrqehXiz6h04XHjxZIKLMzB0Wi2LW64xhSAwkVFXEOGpo/dmjD2yPPlBVka31mM2caRqH5XLAnz362FUSQLdarfLTxSJpISLmcx8uLw217R8/PLpnzt3S/5KHdvG3Pn67Afr3PMB8APgvOwL+J/5s/BeEBm1u1Gu4+QAAAABJRU5ErkJggg==) 20 20, default !important;
  4482. }
  4483. .slide-bottom{
  4484. height: 60px;
  4485. background: #000;
  4486. position: relative;
  4487. z-index: 10;
  4488. posttion: relative;
  4489. }
  4490. .slide-bottom-center{
  4491. position: absolute;
  4492. left: 50%;
  4493. top: 50%;
  4494. transform: translate(-50%, -50%);
  4495. }
  4496. .slide-bottom-center-item{
  4497. display: flex;
  4498. align-items: center;
  4499. justify-content: center;
  4500. gap: 15px;
  4501. img{
  4502. width: 24px;
  4503. height: 24px;
  4504. cursor: pointer;
  4505. }
  4506. .slide-bottom-center-item-page{
  4507. color: #fff;
  4508. font-size: 16px;
  4509. font-weight: 600;
  4510. display: flex;
  4511. gap: 5px;
  4512. }
  4513. }
  4514. .slide-bottom-right{
  4515. position: absolute;
  4516. right: 20px;
  4517. top: 50%;
  4518. transform: translateY(-50%);
  4519. display: flex;
  4520. align-items: center;
  4521. justify-content: center;
  4522. gap: 15px;
  4523. font-size: 24px;
  4524. color: #fff;
  4525. .tool-btn {
  4526. cursor: pointer;
  4527. &:hover,
  4528. &.active {
  4529. color: #1890ff;
  4530. }
  4531. &+.tool-btn {
  4532. margin-left: 15px;
  4533. }
  4534. }
  4535. .upBtn{
  4536. // border-bottom: 3px solid #fff;
  4537. // padding-bottom: 3px;
  4538. width: 24px;
  4539. height: 24px;
  4540. &:hover,
  4541. &.active {
  4542. border-color: #1890ff;
  4543. }
  4544. }
  4545. .tool-btn.loading {
  4546. animation: icon-rotate 1s linear infinite;
  4547. }
  4548. @keyframes icon-rotate {
  4549. 100% { transform: rotate(360deg); }
  4550. }
  4551. }
  4552. .upBtn :deep(svg) {
  4553. width: calc(1em - 3px) !important;
  4554. height: calc(1em - 3px) !important;
  4555. }
  4556. .loading-indicator {
  4557. position: absolute;
  4558. top: 50%;
  4559. left: 50%;
  4560. transform: translate(-50%, -50%);
  4561. display: flex;
  4562. align-items: center;
  4563. justify-content: center;
  4564. z-index: 10;
  4565. .loading-text {
  4566. color: #666;
  4567. font-size: 14px;
  4568. background-color: rgba(255, 255, 255, 0.9);
  4569. padding: 12px 20px;
  4570. border-radius: 6px;
  4571. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  4572. }
  4573. }
  4574. // 全屏模式样式
  4575. .fullscreen-slide {
  4576. // 使用放映功能的默认样式
  4577. }
  4578. // 全屏工具按钮样式,直接复制放映功能的样式
  4579. .tools-left {
  4580. position: fixed;
  4581. bottom: 8px;
  4582. left: 8px;
  4583. font-size: 25px;
  4584. color: #666;
  4585. z-index: 10;
  4586. .tool-btn {
  4587. opacity: .3;
  4588. cursor: pointer;
  4589. transition: opacity 0.3s;
  4590. &:hover {
  4591. opacity: .95;
  4592. }
  4593. &+.tool-btn {
  4594. margin-left: 8px;
  4595. }
  4596. }
  4597. }
  4598. .tools-right {
  4599. height: 66px;
  4600. position: fixed;
  4601. bottom: -66px;
  4602. right: 0;
  4603. z-index: 5;
  4604. padding: 8px;
  4605. transition: bottom 0.3s;
  4606. &.visible {
  4607. bottom: 0;
  4608. }
  4609. &::after {
  4610. content: '';
  4611. width: 100%;
  4612. height: 66px;
  4613. position: absolute;
  4614. left: 0;
  4615. top: -66px;
  4616. }
  4617. .content {
  4618. width: 100%;
  4619. height: 100%;
  4620. display: flex;
  4621. justify-content: center;
  4622. align-items: center;
  4623. border-radius: 4px;
  4624. font-size: 25px;
  4625. background-color: #fff;
  4626. color: #333;
  4627. padding: 8px 10px;
  4628. box-shadow: 0 2px 12px 0 rgb(56, 56, 56, .2);
  4629. border: 1px solid #e2e6ed;
  4630. }
  4631. .tool-btn {
  4632. cursor: pointer;
  4633. &:hover,
  4634. &.active {
  4635. color: #1890ff;
  4636. }
  4637. &+.tool-btn {
  4638. margin-left: 15px;
  4639. }
  4640. }
  4641. .page-number {
  4642. font-size: 12px;
  4643. padding: 0 12px;
  4644. cursor: pointer;
  4645. }
  4646. }
  4647. // 右上角计时状态指示器样式
  4648. .timer-indicator {
  4649. position: fixed;
  4650. z-index: 1000;
  4651. // background: rgba(0, 0, 0, 0.75);
  4652. color: #fff;
  4653. border-radius: 8px;
  4654. padding: 8px 10px;
  4655. display: flex;
  4656. align-items: center;
  4657. gap: 10px;
  4658. // border: 1px solid rgba(255, 255, 255, 0.15);
  4659. .label {
  4660. font-size: 12px;
  4661. opacity: .9;
  4662. margin-right: 2px;
  4663. white-space: nowrap;
  4664. }
  4665. .blocks {
  4666. display: flex;
  4667. align-items: center;
  4668. gap: 8px;
  4669. }
  4670. .block {
  4671. min-width: 45px;
  4672. height: 35px;
  4673. padding: 0 8px;
  4674. border-radius: 6px;
  4675. background: #111;
  4676. display: inline-flex;
  4677. align-items: center;
  4678. justify-content: center;
  4679. font-weight: 700;
  4680. font-size: 22px;
  4681. letter-spacing: 1px;
  4682. }
  4683. .colon {
  4684. position: relative;
  4685. width: 6px;
  4686. display: inline-flex;
  4687. align-items: center;
  4688. justify-content: center;
  4689. }
  4690. .colon::before,
  4691. .colon::after {
  4692. content: '';
  4693. width: 4px;
  4694. height: 4px;
  4695. border-radius: 50%;
  4696. background: #000;
  4697. display: block;
  4698. opacity: .9;
  4699. position: absolute;
  4700. left: 0;
  4701. }
  4702. .colon::before { top: 4px; }
  4703. .colon::after { bottom: 4px; }
  4704. // 全屏尺寸略大
  4705. .pptist-student-viewer.fullscreen & .block {
  4706. min-width: 40px;
  4707. height: 30px;
  4708. font-size: 18px;
  4709. }
  4710. &.countdown .block {
  4711. background: #222;
  4712. }
  4713. &.timeout .block,
  4714. &.timeout .colon {
  4715. background: #ff4d4f;
  4716. color: #fff;
  4717. }
  4718. }
  4719. .viewport {
  4720. position: relative;
  4721. width: 100%;
  4722. height: 100%;
  4723. background-color: #fff;
  4724. }
  4725. .background {
  4726. width: 100%;
  4727. height: 100%;
  4728. background-position: center;
  4729. position: absolute;
  4730. }
  4731. // 响应式设计
  4732. @media (max-width: 768px) {
  4733. .layout-content-left {
  4734. width: 160px;
  4735. }
  4736. .layout-content-right {
  4737. width: 160px;
  4738. }
  4739. .viewer-header {
  4740. padding: 0 16px;
  4741. .slide-title {
  4742. font-size: 16px;
  4743. }
  4744. .viewer-controls button {
  4745. padding: 6px 12px;
  4746. font-size: 14px;
  4747. }
  4748. }
  4749. }
  4750. /* 作业提交按钮样式 */
  4751. .homework-submit-btn {
  4752. position: fixed;
  4753. bottom: 160px;
  4754. z-index: 100;
  4755. background: #191a19;
  4756. color: white;
  4757. padding: 5px 20px;
  4758. border-radius: 5px;
  4759. cursor: pointer;
  4760. display: flex;
  4761. align-items: center;
  4762. gap: 8px;
  4763. border: 2px solid #191a19;
  4764. transition: all 0.3s ease;
  4765. font-size: 16px;
  4766. font-weight: 500;
  4767. &:hover:not(.submitting) {
  4768. transform: translateY(-2px);
  4769. box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  4770. }
  4771. &:active:not(.submitting) {
  4772. transform: translateY(0);
  4773. }
  4774. &.submitting {
  4775. cursor: not-allowed;
  4776. opacity: 0.8;
  4777. background: linear-gradient(135deg, #999 0%, #666 100%);
  4778. }
  4779. .btn-text {
  4780. white-space: nowrap;
  4781. }
  4782. .tool-btn {
  4783. background: transparent;
  4784. color: white;
  4785. width: 20px;
  4786. height: 20px;
  4787. font-size: 16px;
  4788. &:hover {
  4789. background: transparent;
  4790. transform: none;
  4791. }
  4792. }
  4793. .loading-spinner {
  4794. width: 20px;
  4795. height: 20px;
  4796. border: 2px solid rgba(255, 255, 255, 0.3);
  4797. border-top: 2px solid white;
  4798. border-radius: 50%;
  4799. animation: spin 1s linear infinite;
  4800. }
  4801. }
  4802. /* 刷新网页按钮样式 */
  4803. .refresh-page-btn {
  4804. position: fixed;
  4805. bottom: 160px;
  4806. z-index: 100;
  4807. color: #000;
  4808. padding: 5px 20px;
  4809. border-radius: 5px;
  4810. background: #fff;
  4811. cursor: pointer;
  4812. display: flex;
  4813. align-items: center;
  4814. gap: 8px;
  4815. border: 2px solid #e9e9e9;
  4816. transition: all 0.3s ease;
  4817. font-size: 16px;
  4818. font-weight: 500;
  4819. &:hover {
  4820. transform: translateY(-2px);
  4821. box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  4822. }
  4823. &:active {
  4824. transform: translateY(0);
  4825. }
  4826. .btn-text {
  4827. white-space: nowrap;
  4828. }
  4829. .tool-btn {
  4830. background: transparent;
  4831. color: #000;
  4832. width: 20px;
  4833. height: 20px;
  4834. font-size: 16px;
  4835. display: flex;
  4836. align-items: center;
  4837. &:hover {
  4838. background: transparent;
  4839. transform: none;
  4840. }
  4841. }
  4842. }
  4843. /* Loading状态样式 */
  4844. .loading-overlay {
  4845. position: absolute;
  4846. top: 0;
  4847. left: 0;
  4848. right: 0;
  4849. bottom: 0;
  4850. background: rgba(255, 255, 255, 0.95);
  4851. display: flex;
  4852. align-items: center;
  4853. justify-content: center;
  4854. z-index: 1000;
  4855. .loading-spinner {
  4856. width: 40px;
  4857. height: 40px;
  4858. border: 4px solid #f3f3f3;
  4859. border-top: 4px solid #1890ff;
  4860. border-radius: 50%;
  4861. animation: spin 1s linear infinite;
  4862. margin: 0 auto 16px;
  4863. }
  4864. }
  4865. .loading-content {
  4866. text-align: center;
  4867. color: #666;
  4868. }
  4869. .loading-text {
  4870. font-size: 14px;
  4871. color: #666;
  4872. }
  4873. @keyframes spin {
  4874. 0% { transform: rotate(0deg); }
  4875. 100% { transform: rotate(360deg); }
  4876. }
  4877. /* 标签页切换器样式 */
  4878. .tab-switcher {
  4879. display: flex;
  4880. flex: 1;
  4881. margin-right: 12px;
  4882. border-bottom: 1px solid #e0e0e0;
  4883. padding-bottom: 0;
  4884. height: 100%;
  4885. justify-content: center;
  4886. gap: 20px;
  4887. }
  4888. .tab-btn {
  4889. // flex: 1;
  4890. // padding: 12px 16px;
  4891. border: none;
  4892. background: transparent;
  4893. color: #666;
  4894. cursor: pointer;
  4895. transition: all 0.2s ease;
  4896. font-size: 14px;
  4897. font-weight: 500;
  4898. text-align: center;
  4899. white-space: nowrap;
  4900. position: relative;
  4901. border-radius: 0;
  4902. &:hover {
  4903. color: #333;
  4904. }
  4905. &.active {
  4906. color: #333;
  4907. font-weight: 600;
  4908. &::after {
  4909. content: '';
  4910. position: absolute;
  4911. bottom: -1px;
  4912. left: 0;
  4913. right: 0;
  4914. height: 2px;
  4915. background: #333;
  4916. border-radius: 1px;
  4917. }
  4918. }
  4919. }
  4920. // 在适当位置添加连接状态指示器
  4921. .connection-status {
  4922. position: fixed;
  4923. top: 10px;
  4924. right: 10px;
  4925. background-color: rgba(255, 255, 255, 0.9);
  4926. border-radius: 5px;
  4927. padding: 5px 10px;
  4928. display: flex;
  4929. align-items: center;
  4930. z-index: 1000;
  4931. .status-indicator {
  4932. // 胶囊浅蓝底 + 蓝色文字
  4933. padding: 5px 12px 5px 22px;
  4934. border-radius: 5px;
  4935. margin-right: 10px;
  4936. display: flex;
  4937. justify-content: center;
  4938. align-items: center;
  4939. position: relative;
  4940. background: transparent; // 根据具体状态设置渐变
  4941. // 边框去除
  4942. // border: 1px solid rgba(59, 111, 255, 0.35);
  4943. box-shadow: 0 2px 8px rgba(59, 111, 255, 0.15);
  4944. // 左侧状态圆点(不同状态不同颜色)
  4945. &::before {
  4946. content: "";
  4947. position: absolute;
  4948. left: 8px;
  4949. width: 8px;
  4950. height: 8px;
  4951. border-radius: 50%;
  4952. background-color: #1890ff; // 默认使用连接中蓝色
  4953. box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.12);
  4954. }
  4955. &.connected::before {
  4956. background-color: #52c41a; // 原始绿色
  4957. box-shadow: 0 0 0 2px rgba(82, 196, 26, 0.18);
  4958. }
  4959. &.connecting::before {
  4960. background-color: #1890ff; // 原始蓝色
  4961. box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.18);
  4962. }
  4963. &.disconnected::before {
  4964. background-color: #ff4d4f; // 原始红色
  4965. box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.18);
  4966. }
  4967. span {
  4968. color: #1890ff; // 默认蓝色,具体状态里覆盖
  4969. font-size: 12px;
  4970. // font-weight: 600;
  4971. letter-spacing: 0.2px;
  4972. }
  4973. // 以原始主色为基础的浅色渐变与文字色
  4974. &.connected {
  4975. background: rgba(82, 196, 26, 0.15);
  4976. span { color: #52c41a; }
  4977. }
  4978. &.connecting {
  4979. background: rgba(24, 144, 255, 0.15);
  4980. span { color: #1890ff; }
  4981. }
  4982. &.disconnected {
  4983. background: rgba(255, 77, 79, 0.15);
  4984. span { color: #ff4d4f; }
  4985. }
  4986. }
  4987. .reconnect-btn {
  4988. background: linear-gradient(180deg, #eaf2ff 0%, #ddebff 100%);
  4989. color: #3b6fff;
  4990. border: none;
  4991. border-radius: 5px;
  4992. padding: 6px 14px;
  4993. cursor: pointer;
  4994. transition: all 0.2s ease;
  4995. // font-weight: 600;
  4996. box-shadow: 0 2px 8px rgba(59, 111, 255, 0.15);
  4997. &:hover {
  4998. background: linear-gradient(180deg, #e2edff 0%, #d3e4ff 100%);
  4999. border-color: rgba(59, 111, 255, 0.55);
  5000. box-shadow: 0 4px 12px rgba(59, 111, 255, 0.2);
  5001. }
  5002. }
  5003. }
  5004. .homework-check-box {
  5005. position: absolute;
  5006. top: 0;
  5007. left: 50%;
  5008. transform: translate(-50%, 0);
  5009. display: flex;
  5010. align-items: center;
  5011. // box-shadow: 0px 3px 4px 3px #f2f2f2;
  5012. padding: 8px;
  5013. border-radius: 0 0 5px 5px;
  5014. background: #fff;
  5015. z-index: 999;
  5016. .homework-check-box-item{
  5017. padding: 10px 18px;
  5018. border-radius: 5px;
  5019. font-weight: 600;
  5020. cursor: pointer;
  5021. transition: all 0.3s ease;
  5022. &.active{
  5023. background: #f6c82b;
  5024. }
  5025. &:hover{
  5026. background: #fff;
  5027. color: #f6c82b;
  5028. }
  5029. }
  5030. .homework-check-box-item-title{}
  5031. }
  5032. .aiBtn {
  5033. position: absolute;
  5034. display: flex;
  5035. align-items: center;
  5036. background: #fff;
  5037. z-index: 9999;
  5038. border-radius: 50px;
  5039. border: 3px solid #f6c82b;
  5040. padding: 10px 15px;
  5041. font-weight: 600;
  5042. gap: 5px;
  5043. cursor: move;
  5044. user-select: none;
  5045. touch-action: none; /* 防止触摸设备上的默认行为 */
  5046. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
  5047. .aiBtn-icon{
  5048. font-size: 16px;
  5049. color: #f6c82b;
  5050. }
  5051. &:hover {
  5052. background: #f9f9f9;
  5053. }
  5054. &:active {
  5055. transform: scale(0.98);
  5056. }
  5057. }
  5058. </style>