index.vue 171 KB

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