index.vue 140 KB

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