index.vue 178 KB

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