index.vue 192 KB

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