index.vue 182 KB

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