index.vue 200 KB

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