index.vue 199 KB

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