index.vue 199 KB

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