index.vue 191 KB

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