index.vue 180 KB

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