index.vue 178 KB

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