index.vue 172 KB

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