index.vue 183 KB

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