index.vue 210 KB

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