index.vue 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041
  1. <template>
  2. <div class="pptist-student-viewer" :class="{ 'fullscreen': isFullscreen, 'laser-pen': laserPen }">
  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}" :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. }">
  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"/>
  85. <div class="slide-bottom" v-if="!isFullscreen"></div>
  86. </div>
  87. <!-- 全屏时的左右下角工具按钮 -->
  88. <div v-if="isFullscreen && (!isFollowModeActive || props.type == '1')" class="tools-left">
  89. <IconLeftTwo class="tool-btn" theme="two-tone" :fill="['#111', '#fff']" @click="previousSlide" />
  90. <IconRightTwo class="tool-btn" theme="two-tone" :fill="['#111', '#fff']" @click="nextSlide" />
  91. </div>
  92. <!-- 作业提交按钮 - 当当前幻灯片包含iframe时显示 -->
  93. <div v-if="currentSlideHasIframe" class="homework-submit-btn" :class="{ 'submitting': isSubmitting }"
  94. :style="{ right: getHomeworkButtonRight() + 'px' }" @click="handleHomeworkSubmit"
  95. v-tooltip="isSubmitting ? '作业提交中...' : '作业提交'">
  96. <IconEdit v-if="!isSubmitting" class="tool-btn" />
  97. <div v-else class="loading-spinner"></div>
  98. <span class="btn-text">{{ isSubmitting ? '提交中...' : '作业提交' }}</span>
  99. </div>
  100. <!-- 刷新iframe按钮 -->
  101. <div class="refresh-page-btn"
  102. v-if="currentSlideHasIframe"
  103. :style="{ right: getRefreshButtonRight() + 'px' }"
  104. @click="handleRefreshPage"
  105. v-tooltip="'刷新iframe内容'">
  106. <Refresh class="tool-btn" />
  107. <span class="btn-text">刷新</span>
  108. </div>
  109. <!-- 功能组件 -->
  110. <SlideThumbnails v-if="slideThumbnailModelVisible" :turnSlideToIndex="goToSlide"
  111. @close="slideThumbnailModelVisible = false" />
  112. <WritingBoardTool :slideWidth="slideWidth" :slideHeight="slideHeight" v-if="writingBoardToolVisible"
  113. @close="writingBoardToolVisible = false" />
  114. <CountdownTimer v-if="timerlVisible" @close="timerlVisible = false" />
  115. <div v-if="isFullscreen && (!isFollowModeActive || props.type == '1')" class="tools-right" :class="{ 'visible': rightToolsVisible }"
  116. @mouseleave="rightToolsVisible = false" @mouseenter="rightToolsVisible = true">
  117. <div class="content">
  118. <div class="tool-btn page-number" @click="slideThumbnailModelVisible = true">幻灯片 {{ slideIndex +
  119. 1 }} / {{ slides.length }}</div>
  120. <IconWrite class="tool-btn" v-tooltip="'画笔工具'" @click="writingBoardToolVisible = true" />
  121. <IconMagic class="tool-btn" v-tooltip="'激光笔'" :class="{ 'active': laserPen }" @click="toggleLaserPen" />
  122. <IconStopwatchStart class="tool-btn" v-tooltip="'计时器'" @click="timerlVisible = !timerlVisible" />
  123. <IconOffScreenOne class="tool-btn" v-tooltip="'退出全屏'" @click="enterFullscreen" />
  124. </div>
  125. </div>
  126. </div>
  127. </div>
  128. <div class="layout-content-right" v-show="type == '1'" :class="{ collapsed: workPanelCollapsed }">
  129. <div class="thumbnails">
  130. <div class="viewer-header right-panel-header">
  131. <button class="collapse-btn" @click="workPanelCollapsed = !workPanelCollapsed" :title="workPanelCollapsed ? '展开' : '收起'" v-if="rightPanelMode != ''" style="left: 8px;">
  132. <span v-if="workPanelCollapsed">
  133. <img src="@/assets/img/arrow.svg" style="transform: rotate(180deg);">
  134. </span>
  135. <span v-else>
  136. <img src="@/assets/img/arrow.svg">
  137. </span>
  138. </button>
  139. <!-- 标签页切换按钮 -->
  140. <div v-show="!workPanelCollapsed" class="tab-switcher">
  141. <button
  142. class="tab-btn"
  143. :class="{ active: rightPanelMode === 'homework' }"
  144. @click="switchToHomework"
  145. title="回答结果"
  146. >
  147. 回答结果
  148. </button>
  149. <button
  150. class="tab-btn"
  151. :class="{ active: rightPanelMode === 'dialogue' }"
  152. @click="switchToDialogue"
  153. title="对话区"
  154. >
  155. 对话区
  156. </button>
  157. <!-- <button
  158. v-if="isChoiceQuestion"
  159. class="tab-btn"
  160. :class="{ active: rightPanelMode === 'choice' }"
  161. @click="switchToChoice"
  162. title="统计"
  163. >
  164. 统计
  165. </button> -->
  166. </div>
  167. </div>
  168. <!-- 侧边导航标签 - 无论展开还是收缩都显示在左侧 -->
  169. <!-- <div class="side-nav-tabs">
  170. <button
  171. v-if="currentSlideHasIframe"
  172. class="side-nav-btn"
  173. :class="{ active: rightPanelMode === 'homework' }"
  174. @click="switchToHomework"
  175. title="作业"
  176. >
  177. <img :src="rightPanelMode === 'homework' ? homeworkActiveIcon : homeworkIcon" alt="作业">
  178. </button>
  179. <button
  180. v-if="isChoiceQuestion"
  181. class="side-nav-btn"
  182. :class="{ active: rightPanelMode === 'choice' }"
  183. @click="switchToChoice"
  184. title="统计"
  185. >
  186. <img :src="rightPanelMode === 'choice' ? choiceActiveIcon : choiceIcon" alt="统计">
  187. </button>
  188. <button
  189. class="side-nav-btn"
  190. :class="{ active: rightPanelMode === 'dialogue' }"
  191. @click="switchToDialogue"
  192. title="对话"
  193. >
  194. <img :src="rightPanelMode === 'dialogue' ? dialogueActiveIcon : dialogueIcon" alt="对话">
  195. </button>
  196. </div> -->
  197. <!-- 回答结果内容 -->
  198. <div v-show="!workPanelCollapsed && rightPanelMode === 'homework'" class="panel-content">
  199. <div class="homework-title">已提交</div>
  200. <div v-if="workLoading" class="homework-loading">正在加载作业...</div>
  201. <div v-else>
  202. <div v-if="workArray && workArray.length" class="homework-grid">
  203. <button class="homework-btn" v-for="(work, idx) in workArray" :key="work.id ?? idx" :title="work.name" @click="openWorkModal(work)">
  204. <span class="homework-btn__text">{{ work.name }}</span>
  205. </button>
  206. </div>
  207. <div class="homework-empty" v-else>
  208. 暂无作业提交
  209. </div>
  210. </div>
  211. <!-- 未提交作业的学生列表 -->
  212. <div v-if="unsubmittedStudents && unsubmittedStudents.length > 0" class="homework-title" style="margin-top: 20px;">未提交</div>
  213. <div v-if="unsubmittedStudents && unsubmittedStudents.length > 0">
  214. <div v-if="studentLoading" class="homework-loading">正在加载学生信息...</div>
  215. <div v-else>
  216. <div class="homework-grid">
  217. <button class="homework-btn unsubmitted" v-for="(student, idx) in unsubmittedStudents" :key="student.id ?? idx" :title="student.name" disabled>
  218. <span class="homework-btn__text">{{ student.name }}</span>
  219. </button>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. <!-- 对话区内容 -->
  225. <div v-show="!workPanelCollapsed && rightPanelMode === 'dialogue'" class="panel-content">
  226. <DialoguePanel :userid="props.userid" :courseid="props.courseid"/>
  227. </div>
  228. <!-- 选择题统计内容 -->
  229. <div v-show="!workPanelCollapsed && rightPanelMode === 'choice'" class="panel-content">
  230. <ChoiceStatistics :workArray="workArray" :elementList="elementList" />
  231. </div>
  232. </div>
  233. </div>
  234. </div>
  235. <ShotWorkModal v-model:visible="visibleShot" :work="selectedWork" />
  236. <QAWorkModal v-model:visible="visibleQA" :work="selectedWork" />
  237. <ChoiceWorkModal v-model:visible="visibleChoice" :work="selectedWork" />
  238. <AIWorkModal v-model:visible="visibleAI" :work="selectedWork" />
  239. <!-- 在适当位置添加连接状态指示器 -->
  240. <div class="connection-status" v-if="connectionStatus !== 'connected'">
  241. <div class="status-indicator" :class="connectionStatus">
  242. <span v-if="connectionStatus === 'connecting'">连接中...</span>
  243. <span v-else-if="connectionStatus === 'disconnected'">连接断开</span>
  244. </div>
  245. <button v-if="connectionStatus === 'disconnected'" @click="manualReconnect" class="reconnect-btn">
  246. 重新连接
  247. </button>
  248. </div>
  249. </template>
  250. <script lang="ts" setup>
  251. import { computed, ref, onMounted, onUnmounted, nextTick, inject, watch } from 'vue'
  252. import { storeToRefs } from 'pinia'
  253. import { useSlidesStore } from '@/store'
  254. import { ElementTypes } from '@/types/slides'
  255. import { fillDigit } from '@/utils/common'
  256. import ThumbnailSlide from '@/views/components/ThumbnailSlide/index.vue'
  257. import ScreenSlideList from '@/views/Screen/ScreenSlideList.vue'
  258. import ScreenElement from '@/views/Screen/ScreenElement.vue'
  259. import SlideThumbnails from '@/views/Screen/SlideThumbnails.vue'
  260. import WritingBoardTool from '@/views/Screen/WritingBoardTool.vue'
  261. import CountdownTimer from '@/views/Screen/CountdownTimer.vue'
  262. import useSlideBackgroundStyle from '@/hooks/useSlideBackgroundStyle'
  263. import useImport from '@/hooks/useImport'
  264. import message from '@/utils/message'
  265. import api from '@/services/course'
  266. import ShotWorkModal from './components/ShotWorkModal.vue'
  267. import QAWorkModal from './components/QAWorkModal.vue'
  268. import ChoiceWorkModal from './components/ChoiceWorkModal.vue'
  269. import AIWorkModal from './components/AIWorkModal.vue'
  270. import DialoguePanel from './components/DialoguePanel.vue'
  271. import ChoiceStatistics from './components/ChoiceStatistics.vue'
  272. import * as Y from 'yjs'
  273. import { WebsocketProvider } from 'y-websocket'
  274. import { Refresh } from '@icon-park/vue-next'
  275. // 导入图片资源
  276. import homeworkIcon from '@/assets/img/homework.png'
  277. import homeworkActiveIcon from '@/assets/img/homework-active.png'
  278. import dialogueIcon from '@/assets/img/dialogue.png'
  279. import dialogueActiveIcon from '@/assets/img/dialogue-active.png'
  280. import choiceIcon from '@/assets/img/choice.png'
  281. import choiceActiveIcon from '@/assets/img/choice-active.png'
  282. // 定义组件props
  283. interface Props {
  284. courseid?: string | null
  285. userid?: string | null
  286. oid?: string | null
  287. org?: string | null
  288. cid?: string | null
  289. type?: string | null
  290. }
  291. const props = withDefaults(defineProps<Props>(), {
  292. courseid: null,
  293. userid: null,
  294. oid: null,
  295. org: null,
  296. cid: null,
  297. type: null,
  298. })
  299. // 图标组件通过全局注册,无需导入
  300. const slidesStore = useSlidesStore()
  301. const { slides, slideIndex, currentSlide, viewportSize, viewportRatio } = storeToRefs(slidesStore)
  302. // 添加容器引用,用于计算幻灯片尺寸
  303. const viewerCanvasRef = ref<HTMLElement>()
  304. // 放映相关的状态
  305. const canvasScale = ref(1) // 画布缩放比例
  306. const isFullscreen = ref(false) // 是否全屏
  307. const containerWidth = ref(0) // 容器宽度
  308. const containerHeight = ref(0) // 容器高度
  309. // 全屏工具相关状态
  310. const rightToolsVisible = ref(false)
  311. const writingBoardToolVisible = ref(false)
  312. const timerlVisible = ref(false)
  313. const slideThumbnailModelVisible = ref(false)
  314. const laserPen = ref(false)
  315. // 作业提交状态
  316. const isSubmitting = ref(false)
  317. // 控制组件显示的开关
  318. const showSlideList = ref(true)
  319. const slideWidth = ref(0)
  320. const slideHeight = ref(0)
  321. const slideWidth2 = ref(0)
  322. const slideHeight2 = ref(0)
  323. // 添加loading状态
  324. const isLoading = ref(false)
  325. const workLoading = ref(false)
  326. const studentLoading = ref(false)
  327. // 作业数组
  328. type WorkItem = {
  329. id?: string | number
  330. name: string
  331. type: number | string
  332. [key: string]: any
  333. }
  334. const workArray = ref<WorkItem[]>([])
  335. // 作业弹窗相关
  336. const selectedWork = ref<any>(null)
  337. const visibleShot = ref(false)
  338. const visibleQA = ref(false)
  339. const visibleChoice = ref(false)
  340. const visibleAI = ref(false)
  341. // 回答结果收缩状态
  342. const workPanelCollapsed = ref(true)
  343. // 幻灯片导航收缩状态
  344. const slidePanelCollapsed = ref(true)
  345. // 右侧面板当前显示的内容:'homework' | 'dialogue' | 'choice'
  346. const rightPanelMode = ref<'homework' | 'dialogue' | 'choice' | ''>('homework')
  347. // 移除定时器相关代码,改用socket监听
  348. const courseDetail = ref<any>({})
  349. const studentArray = ref<any>([])
  350. // 跟随模式相关状态
  351. const isCreator = ref(false) // 是否为创建人
  352. const isFollowModeActive = ref(false) // 跟随模式是否开启
  353. // 计算未提交作业的学生
  354. const unsubmittedStudents = computed(() => {
  355. if (!studentArray.value || !workArray.value) return []
  356. // 获取已提交作业的学生姓名
  357. const submittedNames = workArray.value.map(work => work.name)
  358. // 过滤出未提交作业的学生
  359. return studentArray.value.filter((student: any) => !submittedNames.includes(student.name))
  360. })
  361. const docSocket = ref<Y.Doc | null>(null)
  362. const yMessage = ref<any | null>(null)
  363. const providerSocket = ref<WebsocketProvider | null>(null)
  364. const mId = ref<string | null>(null)
  365. // WebSocket重连相关变量
  366. const reconnectAttempts = ref(0)
  367. const maxReconnectAttempts = ref(5) // 最大重连次数
  368. const reconnectInterval = ref(5000) // 重连间隔(毫秒)
  369. const reconnectTimer = ref<NodeJS.Timeout | null>(null)
  370. const isConnecting = ref(false)
  371. const connectionStatus = ref<'disconnected' | 'connecting' | 'connected'>('disconnected')
  372. // 切换到回答结果
  373. const switchToHomework = () => {
  374. rightPanelMode.value = 'homework'
  375. if (workPanelCollapsed.value) {
  376. workPanelCollapsed.value = false
  377. }
  378. }
  379. // 切换到对话区
  380. const switchToDialogue = () => {
  381. rightPanelMode.value = 'dialogue'
  382. if (workPanelCollapsed.value) {
  383. workPanelCollapsed.value = false
  384. }
  385. }
  386. // 切换到选择题统计
  387. const switchToChoice = () => {
  388. rightPanelMode.value = 'choice'
  389. if (workPanelCollapsed.value) {
  390. workPanelCollapsed.value = false
  391. }
  392. }
  393. // 自动切换到可用的面板
  394. const autoSwitchToAvailablePanel = () => {
  395. // 如果当前在回答结果但没有iframe,自动切换到其他可用面板
  396. if (rightPanelMode.value === 'homework' && !currentSlideHasIframe.value) {
  397. if (isChoiceQuestion.value) {
  398. rightPanelMode.value = 'choice'
  399. console.log('自动切换到统计面板')
  400. }
  401. else {
  402. rightPanelMode.value = 'dialogue'
  403. console.log('自动切换到对话面板')
  404. }
  405. }
  406. // 如果当前在统计面板但不是选择题,自动切换到对话面板
  407. else if (rightPanelMode.value === 'choice' && !isChoiceQuestion.value) {
  408. rightPanelMode.value = 'dialogue'
  409. console.log('自动切换到对话面板')
  410. }
  411. }
  412. // 移除定时器相关函数,改用socket监听
  413. // 收缩/展开后重新计算中间画布尺寸(在 DOM 更新并完成过渡后)
  414. watch([() => workPanelCollapsed.value, () => slidePanelCollapsed.value], async () => {
  415. // 等待本次 DOM 更新
  416. await nextTick()
  417. // 先在下一帧计算一次,确保初步布局就绪
  418. requestAnimationFrame(() => {
  419. calculateScale()
  420. })
  421. // 再在过渡结束后(与左右栏 width .2s 过渡一致)复算一次,确保最终尺寸
  422. setTimeout(() => {
  423. calculateScale()
  424. }, 220)
  425. }, { flush: 'post' })
  426. const openWorkModal = (work: WorkItem) => {
  427. selectedWork.value = work
  428. const t = Number(work?.type)
  429. // if (t !== 1) {
  430. // message.warning('暂未开发完成')
  431. // return
  432. // }
  433. visibleShot.value = false
  434. visibleQA.value = false
  435. visibleChoice.value = false
  436. visibleAI.value = false
  437. if (t === 1) {
  438. visibleShot.value = true
  439. }
  440. else if (t === 3) {
  441. visibleQA.value = true
  442. }
  443. else if (t === 8) {
  444. visibleChoice.value = true
  445. }
  446. else if (t === 20) {
  447. visibleAI.value = true
  448. }
  449. else {
  450. message.info('暂不支持的作业类型')
  451. }
  452. }
  453. // 计算幻灯片尺寸的函数
  454. const calculateSlideSize = () => {
  455. const slideWrapRef = isFullscreen.value ? document.body : viewerCanvasRef.value
  456. const winWidth = slideWrapRef?.clientWidth || 0
  457. const winHeight = slideWrapRef?.clientHeight || 0
  458. const winWidth2 = slideWrapRef && typeof slideWrapRef.clientWidth === 'number' ? slideWrapRef.clientWidth - 40 : 0
  459. const winHeight2 = slideWrapRef && typeof slideWrapRef.clientHeight === 'number' ? slideWrapRef.clientHeight - 85 : 0
  460. // 根据视口比例计算最佳尺寸
  461. if (winHeight / winWidth === viewportRatio.value) {
  462. slideWidth.value = winWidth
  463. slideHeight.value = winHeight
  464. }
  465. else if (winHeight / winWidth > viewportRatio.value) {
  466. slideWidth.value = winWidth
  467. slideHeight.value = winWidth * viewportRatio.value
  468. }
  469. else {
  470. slideWidth.value = winHeight / viewportRatio.value
  471. slideHeight.value = winHeight
  472. }
  473. // 这里的逻辑存在一些问题和可以优化的地方:
  474. // 1. winWidth2 或 winHeight2 可能为0,导致后续计算为NaN。
  475. // 2. slideHeight.value - slideHeight2.value < 85 这个判断,slideHeight2.value 可能还未被合理赋值,导致判断不准确。
  476. // 3. 反复赋值 slideHeight2/slideWidth2,可能导致宽高比被破坏。
  477. // 4. 代码重复,可合并优化。
  478. // 先按比例计算
  479. let tempWidth = 0
  480. let tempHeight = 0
  481. if (winHeight2 / winWidth2 === viewportRatio.value) {
  482. tempWidth = winWidth2
  483. tempHeight = winHeight2
  484. }
  485. else if (winHeight2 / winWidth2 > viewportRatio.value) {
  486. tempWidth = winWidth2
  487. tempHeight = winWidth2 * viewportRatio.value
  488. }
  489. else {
  490. tempHeight = winHeight2
  491. tempWidth = winHeight2 / viewportRatio.value
  492. }
  493. // 检查底部空间
  494. if (slideHeight.value - tempHeight < 85) {
  495. tempHeight = Math.max(slideHeight.value - 85, 0)
  496. tempWidth = tempHeight > 0 ? tempHeight / viewportRatio.value : 0
  497. }
  498. slideWidth2.value = tempWidth
  499. slideHeight2.value = tempHeight
  500. console.log('calculateSlideSize', slideWidth.value, slideHeight.value, viewportRatio.value, canvasScale.value)
  501. console.log('calculateSlideSize', slideWidth2.value, slideHeight2.value, viewportRatio.value, canvasScale.value)
  502. }
  503. // 使用编辑模式的缩放逻辑
  504. const calculateScale = () => {
  505. console.log('calculateScale 开始执行')
  506. // 获取容器尺寸
  507. const container = viewerCanvasRef.value || document.querySelector('.viewer-canvas')
  508. if (container) {
  509. containerWidth.value = container.clientWidth
  510. containerHeight.value = container.clientHeight
  511. console.log('容器尺寸:', {
  512. width: containerWidth.value,
  513. height: containerHeight.value
  514. })
  515. // 计算基础尺寸
  516. const baseWidth = viewportSize.value
  517. const baseHeight = viewportSize.value * viewportRatio.value
  518. console.log('基础尺寸:', {
  519. baseWidth,
  520. baseHeight,
  521. viewportSize: viewportSize.value,
  522. viewportRatio: viewportRatio.value
  523. })
  524. // 计算缩放比例,让幻灯片能够合理利用空间
  525. const scaleX = containerWidth.value / baseWidth
  526. const scaleY = containerHeight.value / baseHeight
  527. console.log('原始缩放比例:', { scaleX, scaleY })
  528. // 选择较小的缩放比例,确保幻灯片完全显示且居中,留10%边距
  529. const scale = Math.min(scaleX, scaleY) * 0.9
  530. console.log('最终缩放比例:', scale)
  531. canvasScale.value = isFullscreen.value ? 1 : props.type == '1' ? 1 : 1
  532. // canvasScale.value = 1
  533. }
  534. else {
  535. console.error('找不到容器元素')
  536. }
  537. // 计算幻灯片尺寸
  538. nextTick(() => {
  539. setTimeout(() => {
  540. calculateSlideSize()
  541. }, 500)
  542. })
  543. }
  544. // 简化:直接使用放映功能的缩放逻辑
  545. const resetZoom = () => {
  546. calculateScale()
  547. }
  548. // 背景样式
  549. const background = computed(() => currentSlide.value?.background)
  550. const { backgroundStyle } = useSlideBackgroundStyle(background)
  551. // 计算当前幻灯片的元素列表
  552. const elementList = computed(() => {
  553. return currentSlide.value?.elements || []
  554. })
  555. // 检查当前是否为选择题(toolType为45)
  556. const isChoiceQuestion = computed(() => {
  557. const frame = elementList.value.find(element => element.type === ElementTypes.FRAME)
  558. return frame?.toolType === 45
  559. })
  560. // 检测当前幻灯片是否包含iframe元素
  561. const currentSlideHasIframe = computed(() => {
  562. console.log('elementList.value', elementList.value)
  563. return elementList.value.some(element => element.type === ElementTypes.FRAME)
  564. })
  565. // 跳转到指定幻灯片
  566. const goToSlide = (index: number) => {
  567. console.log('goToSlide 被调用,目标索引:', index)
  568. console.log('当前索引:', slideIndex.value)
  569. if (index >= 0 && index < slides.value.length) {
  570. slidesStore.updateSlideIndex(index)
  571. console.log('更新后的索引:', slideIndex.value)
  572. }
  573. else {
  574. console.warn('goToSlide: 无效的索引:', index)
  575. }
  576. }
  577. // 上一页
  578. const previousSlide = () => {
  579. if (slideIndex.value > 0) {
  580. const newIndex = slideIndex.value - 1
  581. console.log('上一页,从', slideIndex.value, '到', newIndex)
  582. slidesStore.updateSlideIndex(newIndex)
  583. }
  584. }
  585. // 下一页
  586. const nextSlide = () => {
  587. if (slideIndex.value < slides.value.length - 1) {
  588. const newIndex = slideIndex.value + 1
  589. console.log('下一页,从', slideIndex.value, '到', newIndex)
  590. slidesStore.updateSlideIndex(newIndex)
  591. }
  592. }
  593. // 监听slideIndex变化,调用getWork
  594. watch(() => slideIndex.value, (newIndex, oldIndex) => {
  595. console.log('slideIndex变化,调用getWork', { newIndex, oldIndex })
  596. if (newIndex !== oldIndex && typeof newIndex === 'number') {
  597. // 检查新页面是否有iframe
  598. const hasIframe = currentSlideHasIframe.value
  599. if (hasIframe) {
  600. console.log('当前页面有iframe,获取作业数据')
  601. console.log('触发getWork,当前幻灯片索引:', newIndex)
  602. getWork()
  603. }
  604. if (props.type == '1' && isFollowModeActive.value && isCreator.value) {
  605. api.updateCourseFollowC(newIndex, props.courseid as string)
  606. sendMessage({slideIndex: newIndex, courseid: props.courseid, type: 'slideIndex'})
  607. }
  608. // 自动切换到可用的面板
  609. autoSwitchToAvailablePanel()
  610. if (isSubmitting.value) {
  611. isSubmitting.value = false
  612. }
  613. }
  614. }, { immediate: false, deep: false })
  615. // 监听iframe状态变化,自动切换面板
  616. watch(() => currentSlideHasIframe.value, (hasIframe) => {
  617. if (!hasIframe) {
  618. autoSwitchToAvailablePanel()
  619. }
  620. }, { immediate: false })
  621. // 全屏
  622. const enterFullscreen = () => {
  623. if (document.fullscreenElement) {
  624. document.exitFullscreen()
  625. }
  626. else {
  627. document.documentElement.requestFullscreen()
  628. }
  629. }
  630. // 监听全屏状态变化
  631. const handleFullscreenChange = () => {
  632. isFullscreen.value = !!document.fullscreenElement
  633. if (isFullscreen.value) {
  634. // 全屏时不需要计算缩放,直接使用放映功能
  635. console.log('进入全屏模式')
  636. }
  637. else {
  638. // 退出全屏时重置所有工具状态并重新计算缩放比例
  639. console.log('退出全屏模式,重置工具状态')
  640. // 重置所有工具状态
  641. rightToolsVisible.value = false
  642. writingBoardToolVisible.value = false
  643. timerlVisible.value = false
  644. slideThumbnailModelVisible.value = false
  645. laserPen.value = false
  646. // 重新计算缩放比例
  647. nextTick(() => {
  648. setTimeout(() => {
  649. calculateScale()
  650. }, 1000)
  651. })
  652. }
  653. }
  654. // 切换激光笔模式
  655. const toggleLaserPen = () => {
  656. laserPen.value = !laserPen.value
  657. console.log('激光笔状态:', laserPen.value ? '开启' : '关闭')
  658. }
  659. // 获取导入导出功能
  660. const { readJSON, exportJSON2, getFile } = useImport()
  661. // 根据iframe的URL查找对应的幻灯片索引
  662. const findSlideIndexByIframeUrl = (iframeUrl: string): number => {
  663. try {
  664. console.log('查找iframe对应的幻灯片索引,iframe URL:', iframeUrl)
  665. // 遍历所有幻灯片,查找包含该iframe URL的幻灯片
  666. for (let i = 0; i < slides.value.length; i++) {
  667. const slide = slides.value[i]
  668. // 检查幻灯片的元素中是否有iframe
  669. if (slide.elements && slide.elements.length > 0) {
  670. for (const element of slide.elements) {
  671. // 检查是否是iframe元素
  672. if (element.type === ElementTypes.FRAME) {
  673. // 检查iframe的src是否匹配
  674. if (element.url === iframeUrl) {
  675. console.log(`找到匹配的幻灯片,索引: ${i}, 幻灯片ID: ${slide.id}`)
  676. return i
  677. }
  678. }
  679. }
  680. }
  681. }
  682. // 如果没有找到匹配的幻灯片,返回当前幻灯片索引
  683. console.log('未找到匹配的幻灯片,使用当前幻灯片索引:', slideIndex.value)
  684. return slideIndex.value
  685. }
  686. catch (error) {
  687. console.error('查找幻灯片索引时出错:', error)
  688. return slideIndex.value
  689. }
  690. }
  691. // 处理iframe链接,为包含workPage的iframe添加必要参数
  692. // 处理iframe链接,为包含workPage的iframe添加必要参数
  693. const processIframeLinks = async () => {
  694. try {
  695. console.log('开始处理iframe链接')
  696. console.log('当前props:', { courseid: props.courseid, userid: props.userid })
  697. // 从slides数据中查找包含iframe的元素
  698. let hasIframe = false
  699. // 由于有异步操作,需整体用Promise.all处理
  700. const updatedSlides = await Promise.all(
  701. slides.value.map(async (slide, slideIndex) => {
  702. if (slide.elements && slide.elements.length > 0) {
  703. // 这里不能直接用async map,否则会导致类型不对
  704. const updatedElements = await Promise.all(
  705. slide.elements.map(async (element) => {
  706. // 检查是否是iframe元素
  707. if (element.type === ElementTypes.FRAME && element.url) {
  708. const iframeSrc = element.url
  709. const toolType = element.toolType
  710. if (iframeSrc.includes('workPage')) {
  711. hasIframe = true
  712. console.log(`处理幻灯片 ${slideIndex + 1} 中的iframe链接:`, iframeSrc)
  713. try {
  714. // 解析URL,处理hash部分
  715. let baseUrl = iframeSrc
  716. let hashPart = ''
  717. // 分离base URL和hash部分
  718. if (iframeSrc.includes('#')) {
  719. const parts = iframeSrc.split('#')
  720. baseUrl = parts[0]
  721. hashPart = parts[1]
  722. }
  723. // 构建新的hash部分,添加参数
  724. // 使用当前幻灯片索引作为task参数
  725. let newHash = hashPart
  726. if (newHash.includes('?')) {
  727. // 如果hash中已经有查询参数,添加&
  728. newHash += `&courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=${slideIndex}&tool=0`
  729. }
  730. else {
  731. // 如果hash中没有查询参数,添加?
  732. newHash += `?courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=${slideIndex}&tool=0`
  733. }
  734. // 构建新的URL
  735. const newUrl = `${baseUrl}#${newHash}`
  736. console.log(`幻灯片 ${slideIndex + 1} 的iframe链接已更新:`, newUrl)
  737. // 返回更新后的元素
  738. return {
  739. ...element,
  740. url: newUrl
  741. }
  742. }
  743. catch (error) {
  744. console.error(`处理幻灯片 ${slideIndex + 1} 的iframe链接时出错:`, error)
  745. return element
  746. }
  747. }
  748. else if (toolType == 73) {
  749. hasIframe = true
  750. // 先尝试获取iframe的contentWindow,如果获取不到再使用HTML方式
  751. try {
  752. // 创建一个临时的iframe来测试是否能获取contentWindow
  753. const tempIframe = document.createElement('iframe')
  754. tempIframe.style.display = 'none'
  755. tempIframe.src = iframeSrc
  756. // 先将临时iframe添加到body,否则onload事件不会触发
  757. document.body.appendChild(tempIframe)
  758. // 等待iframe加载完成
  759. await new Promise((resolve, reject) => {
  760. tempIframe.onload = resolve
  761. tempIframe.onerror = reject
  762. // 可选:设置超时时间,避免长时间无响应
  763. setTimeout(() => reject(new Error('Timeout')), 5000)
  764. })
  765. // 尝试获取contentWindow
  766. if (tempIframe.contentWindow && tempIframe.contentWindow.document) {
  767. console.log(`iframe ${iframeSrc} 可以获取contentWindow,使用直接加载方式`)
  768. // 移除临时iframe
  769. document.body.removeChild(tempIframe)
  770. return {
  771. ...element,
  772. isHTML: false,
  773. url: iframeSrc
  774. }
  775. }
  776. // 加载完成但无法获取contentWindow,也要移除iframe
  777. document.body.removeChild(tempIframe)
  778. }
  779. catch (error) {
  780. console.log(`iframe ${iframeSrc} 无法获取contentWindow,使用HTML方式:`, error)
  781. }
  782. // 如果无法获取contentWindow,使用HTML方式
  783. const html = await api.getHTML(iframeSrc)
  784. // const html = await api.getHTML('https://knowledge.cocorobo.cn/zh-CN/story-telling/a7fa08b8-cf60-11ef-93e3-12e77c4cb76b')
  785. console.log('html', html)
  786. console.log(`处理幻灯片 ${slideIndex + 1} 中的iframe链接:`, iframeSrc)
  787. return {
  788. ...element,
  789. isHTML: true,
  790. url: html
  791. }
  792. }
  793. }
  794. // 不是iframe元素或不需要处理,直接返回
  795. return element
  796. })
  797. )
  798. // 返回更新后的幻灯片
  799. return {
  800. ...slide,
  801. elements: updatedElements
  802. }
  803. }
  804. // 没有元素的幻灯片直接返回
  805. return slide
  806. })
  807. )
  808. if (hasIframe) {
  809. console.log('找到iframe元素,更新slides数据')
  810. // 更新store中的slides数据
  811. slidesStore.setSlides(updatedSlides)
  812. console.log('slides数据更新完成')
  813. }
  814. else {
  815. console.log('未找到包含workPage的iframe元素')
  816. }
  817. console.log('iframe链接处理完成')
  818. }
  819. catch (error) {
  820. console.error('处理iframe链接时出错:', error)
  821. }
  822. }
  823. // 导入JSON功能
  824. const importJSON = (jsonData: any) => {
  825. try {
  826. console.log('Student importJSON 开始执行')
  827. const result = readJSON(jsonData, true)
  828. if (result.success) {
  829. console.log('Student importJSON 成功,开始重新渲染')
  830. // 强制重新渲染:先隐藏组件
  831. showSlideList.value = false
  832. // 重新计算画布尺寸和缩放比例
  833. nextTick(() => {
  834. calculateScale()
  835. // 延迟500ms后重新显示组件,确保重新渲染完成
  836. setTimeout(() => {
  837. showSlideList.value = true
  838. // 只有当当前页面存在iframe时才获取作业数据
  839. if (currentSlideHasIframe.value && props.type == '1') {
  840. getWork()
  841. }
  842. selectCourseSLook()
  843. console.log('组件重新渲染完成')
  844. }, 500)
  845. })
  846. return true
  847. }
  848. console.error('Student importJSON 失败:', result.error)
  849. return false
  850. }
  851. catch (error) {
  852. console.error('Student importJSON 执行失败:', error)
  853. return false
  854. }
  855. }
  856. // 导出JSON功能
  857. const exportJSON = () => {
  858. try {
  859. console.log('Student exportJSON 开始执行,调用 useImport.exportJSON2')
  860. // 直接调用 useImport 中的 exportJSON2 函数
  861. const exportData = exportJSON2()
  862. if (exportData) {
  863. return exportData
  864. }
  865. console.error('Student exportJSON 失败: exportJSON2 返回空数据')
  866. return false
  867. }
  868. catch (error) {
  869. console.error('Student exportJSON 执行失败:', error)
  870. return false
  871. }
  872. }
  873. // 返回编辑器
  874. const backToEditor = () => {
  875. // 通过路由跳转到编辑模式
  876. window.location.href = '/'
  877. }
  878. const submitWork = async (slideIndex: number, atool: string, content: string, type: string) => {
  879. const res = await api.submitWork({
  880. uid: props.userid as string,
  881. cid: props.courseid as string,
  882. stage: '0',
  883. task: String(slideIndex), // 转为字符串
  884. tool: '0',
  885. atool: atool,
  886. content: content,
  887. type: type
  888. })
  889. getWork()
  890. console.log(res)
  891. }
  892. // 文件上传到AWS S3的函数
  893. const uploadFile = (file: File): Promise<string> => {
  894. return new Promise((resolve, reject) => {
  895. try {
  896. // 检查AWS SDK是否可用
  897. if (!(window as any).AWS) {
  898. reject(new Error('AWS SDK not loaded'))
  899. return
  900. }
  901. const credentials = {
  902. accessKeyId: 'AKIATLPEDU37QV5CHLMH',
  903. secretAccessKey: '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'
  904. }
  905. // 配置AWS
  906. ;(window as any).AWS.config.update(credentials)
  907. ;(window as any).AWS.config.region = 'cn-northwest-1'
  908. // 创建S3实例
  909. const bucket = new (window as any).AWS.S3({ params: { Bucket: 'ccrb' } })
  910. if (file) {
  911. // 生成唯一的文件名
  912. const fileExtension = file.name.split('.').pop()
  913. const fileName = `${file.name.split('.')[0]}_${Date.now()}.${fileExtension}`
  914. const params = {
  915. Key: fileName,
  916. ContentType: file.type,
  917. Body: file,
  918. ACL: 'public-read'
  919. }
  920. const options = {
  921. partSize: 2048 * 1024 * 1024, // 2GB分片
  922. queueSize: 2,
  923. leavePartsOnError: true
  924. }
  925. bucket
  926. .upload(params, options)
  927. .on('httpUploadProgress', (evt: any) => {
  928. // 这里可以添加进度条逻辑
  929. const progress = Math.round((evt.loaded * 100) / evt.total)
  930. console.log(`Uploaded: ${progress}%`)
  931. })
  932. .send((err: any, data: any) => {
  933. if (err) {
  934. console.error('Upload failed:', err)
  935. message.error('文件上传失败')
  936. reject(err)
  937. }
  938. else {
  939. console.log('Upload successful:', data.Location)
  940. resolve(data.Location)
  941. }
  942. })
  943. }
  944. else {
  945. reject(new Error('No file provided'))
  946. }
  947. }
  948. catch (error) {
  949. console.error('Upload error:', error)
  950. reject(error)
  951. }
  952. })
  953. }
  954. // 作业提交功能(优化版)
  955. const handleHomeworkSubmit = async () => {
  956. console.log('作业提交按钮被点击')
  957. // 防抖:如果正在提交中,直接返回
  958. if (isSubmitting.value) {
  959. console.log('作业正在提交中,忽略重复点击')
  960. return
  961. }
  962. isSubmitting.value = true
  963. try {
  964. // 获取所有iframe元素
  965. const iframes = document.querySelectorAll('.viewer-canvas .screen-slide')[slideIndex.value].querySelectorAll('iframe')
  966. console.log('找到iframe元素数量:', iframes.length)
  967. if (iframes.length === 0) {
  968. message.warning('当前页面没有找到iframe元素')
  969. return
  970. }
  971. let hasSubmitWork = false
  972. for (let i = 0; i < iframes.length; i++) {
  973. const iframe = iframes[i] as HTMLIFrameElement
  974. const iframeSrc = iframe.src
  975. console.log(`iframe ${i + 1} 链接:`, iframeSrc)
  976. // 检查iframe链接是否包含workPage
  977. if (iframeSrc && iframeSrc.includes('workPage')) {
  978. console.log('找到包含workPage的iframe,尝试执行submitWork')
  979. try {
  980. const iframeWindow = iframe.contentWindow as Window & { submitWork?: (...args: any[]) => unknown }
  981. if (iframeWindow && typeof iframeWindow.submitWork === 'function') {
  982. console.log('执行iframe中的submitWork方法,参数可变')
  983. const iframeSlideIndex = slideIndex.value
  984. const submitArgs = [iframeSlideIndex]
  985. // 支持同步和异步submitWork
  986. const result = await iframeWindow.submitWork(...submitArgs)
  987. console.log('submitWork同步执行完成')
  988. message.success('作业提交成功')
  989. hasSubmitWork = true
  990. // 发送作业提交成功的socket消息
  991. sendMessage({
  992. type: 'homework_submitted',
  993. courseid: props.courseid,
  994. slideIndex: slideIndex.value,
  995. userid: props.userid
  996. })
  997. break
  998. }
  999. else {
  1000. console.log('iframe中没有找到submitWork方法')
  1001. }
  1002. }
  1003. catch (error) {
  1004. console.error('访问iframe内容时出错:', error)
  1005. }
  1006. }
  1007. else if (iframeSrc && (iframeSrc.includes('aichat.cocorobo') || iframeSrc.includes('knowledge.cocorobo'))) {
  1008. console.log('找到包含aichat.cocorobo或knowledge.cocorobo的iframe,尝试执行submitWork')
  1009. // 由于TS类型检查,需通过 any 绕过类型限制
  1010. const iframeWindow = iframe.contentWindow as any
  1011. if (iframeWindow && iframeWindow.exposed_outputs) {
  1012. console.log('执行iframe中的submitWork方法,参数可变')
  1013. const iframeSlideIndex = slideIndex.value
  1014. const Cow = JSON.stringify(iframeWindow.exposed_outputs)
  1015. // 这里假设 submitWork 是全局可用的函数
  1016. await submitWork(iframeSlideIndex, '72', Cow, '20')
  1017. message.success('作业提交成功')
  1018. hasSubmitWork = true
  1019. // 发送作业提交成功的socket消息
  1020. sendMessage({
  1021. type: 'homework_submitted',
  1022. courseid: props.courseid,
  1023. slideIndex: slideIndex.value,
  1024. userid: props.userid
  1025. })
  1026. }
  1027. }
  1028. else if (slides.value[slideIndex.value].elements.some((element: any) => element.isHTML)) {
  1029. // message.warning('当前页面暂不支持作业提交')
  1030. console.log('尝试截图当前页面并提交')
  1031. // return
  1032. try {
  1033. // 尝试使用html2canvas,对iframe支持更好
  1034. let imageData: string
  1035. const screenSlides = document.querySelectorAll('.viewer-canvas .screen-slide')
  1036. let iframeElement: HTMLIFrameElement | null = null
  1037. let iframeBody: HTMLElement | null = null
  1038. // 获取iframe元素
  1039. if (
  1040. screenSlides &&
  1041. screenSlides[slideIndex.value] &&
  1042. screenSlides[slideIndex.value].querySelector('iframe')
  1043. ) {
  1044. iframeElement = screenSlides[slideIndex.value].querySelector('iframe') as HTMLIFrameElement
  1045. }
  1046. else {
  1047. throw new Error('未能获取到iframe元素,无法截图')
  1048. }
  1049. // 获取iframe内部的body元素(同源)
  1050. if (
  1051. iframeElement.contentWindow &&
  1052. iframeElement.contentWindow.document &&
  1053. iframeElement.contentWindow.document.body
  1054. ) {
  1055. // 获取页面的所有注释节点
  1056. const comments = []
  1057. const childNodes = iframeElement.contentWindow.document.createTreeWalker(iframeElement.contentWindow.document.body, NodeFilter.SHOW_COMMENT, null)
  1058. while (childNodes.nextNode()) {
  1059. comments.push(childNodes.currentNode)
  1060. }
  1061. // 移除所有注释节点
  1062. comments.forEach(comment => {
  1063. comment?.parentNode?.removeChild(comment)
  1064. })
  1065. iframeBody = iframeElement.contentWindow.document.body as HTMLElement
  1066. }
  1067. else {
  1068. throw new Error('未能获取到iframe的body元素,无法截图')
  1069. }
  1070. try {
  1071. const a = iframeBody.getElementsByTagName('img')
  1072. const b = iframeBody.getElementsByTagName('video')
  1073. for (let i = 0;i < a.length;i++) {
  1074. a[i].crossOrigin = 'anonymous'
  1075. }
  1076. for (let i = 0;i < b.length;i++) {
  1077. b[i].crossOrigin = 'anonymous'
  1078. }
  1079. // 直接对iframe内部的body进行截图
  1080. const html2canvas = await import('html2canvas')
  1081. const canvas = await html2canvas.default(iframeBody, {
  1082. useCORS: true,
  1083. allowTaint: true,
  1084. scale: 1,
  1085. backgroundColor: '#ffffff',
  1086. logging: false,
  1087. foreignObjectRendering: true,
  1088. removeContainer: true
  1089. })
  1090. imageData = canvas.toDataURL('image/png', 0.95)
  1091. console.log('成功截图iframe内部内容')
  1092. }
  1093. catch (html2canvasError) {
  1094. console.log('html2canvas失败,尝试html-to-image:', html2canvasError)
  1095. try {
  1096. // 回退到html-to-image
  1097. const { toPng } = await import('html-to-image')
  1098. imageData = await toPng(iframeBody, {
  1099. quality: 0.95,
  1100. backgroundColor: '#ffffff',
  1101. filter: (node) => {
  1102. if (node.tagName === 'SCRIPT' || node.tagName === 'STYLE') {
  1103. return false
  1104. }
  1105. return true
  1106. }
  1107. })
  1108. console.log('使用html-to-image截图成功')
  1109. }
  1110. catch (htmlToImageError) {
  1111. console.log('html-to-image也失败了,使用canvas绘制方案:', htmlToImageError)
  1112. message.error('截图提交失败')
  1113. return
  1114. /*
  1115. // 最后的备用方案:使用canvas绘制
  1116. const canvas = document.createElement('canvas')
  1117. const ctx = canvas.getContext('2d')
  1118. if (ctx) {
  1119. canvas.width = iframeElement.offsetWidth || 800
  1120. canvas.height = iframeElement.offsetHeight || 600
  1121. // 绘制背景
  1122. const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height)
  1123. gradient.addColorStop(0, '#f8f9fa')
  1124. gradient.addColorStop(1, '#e9ecef')
  1125. ctx.fillStyle = gradient
  1126. ctx.fillRect(0, 0, canvas.width, canvas.height)
  1127. // 绘制边框
  1128. ctx.strokeStyle = '#dee2e6'
  1129. ctx.lineWidth = 3
  1130. ctx.strokeRect(2, 2, canvas.width - 4, canvas.height - 4)
  1131. // 绘制内边框
  1132. ctx.strokeStyle = '#ffffff'
  1133. ctx.lineWidth = 1
  1134. ctx.strokeRect(5, 5, canvas.width - 10, canvas.height - 10)
  1135. // 绘制iframe图标
  1136. ctx.fillStyle = '#6c757d'
  1137. ctx.font = 'bold 48px Arial'
  1138. ctx.textAlign = 'center'
  1139. ctx.fillText('', canvas.width / 2, canvas.height / 2 - 40)
  1140. // 绘制标题
  1141. ctx.font = 'bold 20px Arial'
  1142. ctx.fillStyle = '#495057'
  1143. ctx.fillText('iframe内容', canvas.width / 2, canvas.height / 2 + 20)
  1144. // 绘制URL
  1145. const src = iframeElement.srcf
  1146. if (src) {
  1147. ctx.font = '14px Arial'
  1148. ctx.fillStyle = '#6c757d'
  1149. const url = src.length > 80 ? src.substring(0, 80) + '...' : src
  1150. ctx.fillText(url, canvas.width / 2, canvas.height / 2 + 50)
  1151. }
  1152. // 绘制提示信息
  1153. ctx.font = '12px Arial'
  1154. ctx.fillStyle = '#adb5bd'
  1155. ctx.fillText('(截图失败)', canvas.width / 2, canvas.height / 2 + 80)
  1156. // 绘制装饰性元素
  1157. ctx.strokeStyle = '#dee2e6'
  1158. ctx.lineWidth = 1
  1159. ctx.setLineDash([5, 5])
  1160. ctx.strokeRect(20, 20, canvas.width - 40, canvas.height - 40)
  1161. ctx.setLineDash([])
  1162. imageData = canvas.toDataURL('image/png', 0.95)
  1163. console.log('使用canvas绘制方案截图成功')
  1164. }
  1165. else {
  1166. throw new Error('无法创建canvas上下文')
  1167. }*/
  1168. }
  1169. }
  1170. const _a = iframeBody.getElementsByTagName('img')
  1171. const _b = iframeBody.getElementsByTagName('video')
  1172. for (let i = 0; i < _a.length; i++) {
  1173. _a[i].removeAttribute('crossorigin')
  1174. }
  1175. for (let i = 0; i < _b.length; i++) {
  1176. _b[i].removeAttribute('crossorigin')
  1177. }
  1178. // 将base64字符串转换为File对象
  1179. const base64ToFile = (base64String: string, filename: string): File => {
  1180. const arr = base64String.split(',')
  1181. const mime = arr[0].match(/:(.*?);/)?.[1] || 'image/png'
  1182. const bstr = atob(arr[1])
  1183. let n = bstr.length
  1184. const u8arr = new Uint8Array(n)
  1185. while (n--) {
  1186. u8arr[n] = bstr.charCodeAt(n)
  1187. }
  1188. return new File([u8arr], filename, { type: mime })
  1189. }
  1190. const imageFile = base64ToFile(imageData, `screenshot_${Date.now()}.png`)
  1191. const imageUrl = await uploadFile(imageFile)
  1192. // 提交截图
  1193. await submitWork(slideIndex.value, '73', imageUrl, '1') // 73表示截图工具,21表示图片类型
  1194. message.success('页面截图提交成功')
  1195. hasSubmitWork = true
  1196. // 发送作业提交成功的socket消息
  1197. sendMessage({
  1198. type: 'homework_submitted',
  1199. courseid: props.courseid,
  1200. slideIndex: slideIndex.value,
  1201. userid: props.userid
  1202. })
  1203. }
  1204. catch (error) {
  1205. console.error('截图提交失败:', error)
  1206. message.error('截图提交失败')
  1207. }
  1208. }
  1209. else {
  1210. const screenSlides = document.querySelectorAll('.viewer-canvas .screen-slide')
  1211. let iframeElement: HTMLIFrameElement | null = null
  1212. // 获取iframe元素
  1213. if (
  1214. screenSlides &&
  1215. screenSlides[slideIndex.value] &&
  1216. screenSlides[slideIndex.value].querySelector('iframe')
  1217. ) {
  1218. iframeElement = screenSlides[slideIndex.value].querySelector('iframe') as HTMLIFrameElement
  1219. }
  1220. else {
  1221. throw new Error('未能获取到iframe元素,无法截图')
  1222. }
  1223. // 获取iframe内部的body元素(同源)
  1224. if (
  1225. iframeElement.contentWindow &&
  1226. iframeElement.contentWindow.document &&
  1227. iframeElement.contentWindow.document.body
  1228. ) {
  1229. isSubmitting.value = true
  1230. const _ajs = iframeElement.contentWindow.document.createElement('script')
  1231. _ajs.type = 'text/javascript'
  1232. _ajs.innerHTML =
  1233. 'var _js = document.createElement("script");\n' +
  1234. '_js.type="text/javascript";\n' +
  1235. '_js.src="https://html2canvas.hertzen.com/dist/html2canvas.min.js";\n' +
  1236. '_js.onload = function(){\n' +
  1237. ' var a = document.getElementsByTagName("img")\n' +
  1238. ' for(var i = 0;i<a.length;i++){a[i].crossOrigin="anonymous"}\n' +
  1239. ' html2canvas(document.body).then(canvas => {\n' +
  1240. ' var base64Url = canvas.toDataURL("image/png");\n' +
  1241. 'var base64 = "<img src=" + base64Url + " />"\n' +
  1242. 'var file = dataURLtoFile_shishi(base64Url, "截图")\n' +
  1243. 'beforeUpload_shishi(file,' +
  1244. "'" +
  1245. props.userid +
  1246. "'" +
  1247. ', ' +
  1248. "'" +
  1249. props.courseid +
  1250. "'" +
  1251. ', ' +
  1252. "'" +
  1253. slideIndex.value +
  1254. "'" +
  1255. ', ' +
  1256. "'0'" +
  1257. ', ' +
  1258. "'73'" +
  1259. ', ' +
  1260. "'1'" +
  1261. ')\n' +
  1262. ' });\n' +
  1263. '}\n' +
  1264. 'document.head.appendChild(_js);\n'
  1265. iframeElement.contentWindow.document.head.appendChild(_ajs)
  1266. return
  1267. }
  1268. }
  1269. }
  1270. if (!hasSubmitWork) {
  1271. message.info('未找到可用的作业提交功能')
  1272. }
  1273. isSubmitting.value = false
  1274. }
  1275. catch (error) {
  1276. console.error('作业提交过程中出错:', error)
  1277. message.error('作业提交失败')
  1278. isSubmitting.value = false
  1279. }
  1280. finally {
  1281. // isSubmitting.value = false
  1282. getWork(true)
  1283. }
  1284. }
  1285. const successSubmit = () => {
  1286. message.success('作业提交成功')
  1287. sendMessage({
  1288. type: 'homework_submitted',
  1289. courseid: props.courseid,
  1290. slideIndex: slideIndex.value,
  1291. userid: props.userid
  1292. })
  1293. isSubmitting.value = false
  1294. getWork(true)
  1295. }
  1296. // 刷新iframe功能
  1297. const handleRefreshPage = () => {
  1298. console.log('刷新iframe按钮被点击')
  1299. try {
  1300. // 获取当前幻灯片中的所有iframe元素
  1301. const iframes = document.querySelectorAll('.viewer-canvas .screen-slide')[slideIndex.value].querySelectorAll('iframe')
  1302. console.log('找到iframe元素数量:', iframes.length)
  1303. if (iframes.length === 0) {
  1304. message.warning('当前页面没有找到iframe元素')
  1305. return
  1306. }
  1307. let refreshedCount = 0
  1308. // 遍历所有iframe并刷新
  1309. for (let i = 0; i < iframes.length; i++) {
  1310. const iframe = iframes[i] as HTMLIFrameElement
  1311. // 优化刷新方式,避免闪烁和兼容 srcdoc 场景
  1312. if (iframe.src) {
  1313. // 仅当有src属性时刷新
  1314. const originalSrc = iframe.src
  1315. // 通过重新赋值src实现刷新,避免先清空再赋值导致的闪烁
  1316. iframe.src = originalSrc
  1317. console.log(`刷新iframe ${i + 1}:`, originalSrc)
  1318. refreshedCount++
  1319. }
  1320. else if (iframe.srcdoc) {
  1321. // srcdoc场景下,重新赋值srcdoc内容
  1322. const originalSrcdoc = iframe.srcdoc
  1323. iframe.srcdoc = ''
  1324. setTimeout(() => {
  1325. iframe.srcdoc = originalSrcdoc
  1326. console.log(`iframe ${i + 1} (srcdoc) 刷新完成`)
  1327. }, 50)
  1328. refreshedCount++
  1329. }
  1330. }
  1331. if (refreshedCount > 0) {
  1332. message.success(`刷新完成`)
  1333. // 如果当前页面有iframe,重新获取作业数据
  1334. if (currentSlideHasIframe.value && props.type == '1') {
  1335. setTimeout(() => {
  1336. getWork()
  1337. }, 500) // 延迟500ms等待iframe加载完成
  1338. }
  1339. isSubmitting.value = false
  1340. }
  1341. else {
  1342. message.info('没有找到可刷新的iframe')
  1343. }
  1344. }
  1345. catch (error) {
  1346. console.error('刷新iframe时出错:', error)
  1347. message.error('刷新iframe失败')
  1348. }
  1349. }
  1350. // 获取作业提交按钮的右侧位置
  1351. const getHomeworkButtonRight = () => {
  1352. if (isFullscreen.value) {
  1353. return 30 // 全屏时按钮在右侧30px
  1354. }
  1355. if (props.type === '1') {
  1356. // 展开回答结果:按钮更靠左;收起时:按钮更靠右侧
  1357. return workPanelCollapsed.value ? 60 : 430
  1358. }
  1359. return 30 // type=2时按钮在右侧30px
  1360. }
  1361. // 获取刷新按钮的右侧位置
  1362. const getRefreshButtonRight = () => {
  1363. if (isFullscreen.value) {
  1364. return 160 // 全屏时按钮在右侧150px
  1365. }
  1366. if (props.type === '1') {
  1367. // 展开回答结果:按钮更靠左;收起时:按钮更靠右侧
  1368. return workPanelCollapsed.value ? 190 : 560
  1369. }
  1370. return 160 // type=2时按钮在右侧150px
  1371. }
  1372. // 键盘快捷键
  1373. const handleKeydown = (e: KeyboardEvent) => {
  1374. switch (e.key) {
  1375. case 'ArrowLeft':
  1376. e.preventDefault()
  1377. if (!isFollowModeActive.value || props.type == '1') {
  1378. previousSlide()
  1379. }
  1380. break
  1381. case 'PageUp':
  1382. e.preventDefault()
  1383. if (!isFollowModeActive.value || props.type == '1') {
  1384. previousSlide()
  1385. }
  1386. break
  1387. case 'ArrowRight':
  1388. e.preventDefault()
  1389. if (!isFollowModeActive.value || props.type == '1') {
  1390. nextSlide()
  1391. }
  1392. break
  1393. case 'PageDown':
  1394. case ' ':
  1395. e.preventDefault()
  1396. if (!isFollowModeActive.value || props.type == '1') {
  1397. nextSlide()
  1398. }
  1399. break
  1400. case 'F11':
  1401. e.preventDefault()
  1402. enterFullscreen()
  1403. break
  1404. case 'Escape':
  1405. if (document.fullscreenElement) {
  1406. document.exitFullscreen()
  1407. }
  1408. break
  1409. default:
  1410. break
  1411. }
  1412. }
  1413. // 事件处理函数
  1414. const handleSlidesDataUpdated = () => {
  1415. console.log('收到 slidesDataUpdated 事件')
  1416. // 强制重新渲染:先隐藏组件
  1417. showSlideList.value = false
  1418. nextTick(() => {
  1419. calculateScale()
  1420. // 延迟500ms后重新显示组件,确保重新渲染完成
  1421. setTimeout(() => {
  1422. showSlideList.value = true
  1423. console.log('组件重新渲染完成')
  1424. // 重新处理iframe链接
  1425. processIframeLinks()
  1426. }, 500)
  1427. console.log('slidesDataUpdated 事件处理完成')
  1428. })
  1429. }
  1430. const handleViewportSizeUpdated = (event: any) => {
  1431. console.log('收到 viewportSizeUpdated 事件:', event.detail)
  1432. // 重新计算缩放比例
  1433. nextTick(() => {
  1434. calculateScale()
  1435. console.log('viewportSizeUpdated 事件处理完成')
  1436. })
  1437. }
  1438. const getCourseDetail = async () => {
  1439. isLoading.value = true
  1440. try {
  1441. const res = await api.getCourseDetail(props.courseid as string)
  1442. console.log(res)
  1443. const courseData = res[0][0]
  1444. courseDetail.value = courseData
  1445. selectWorksStudent()
  1446. checkIsCreator()
  1447. const pptJSONUrl = JSON.parse(courseData.chapters).pptData ? JSON.parse(courseData.chapters).pptData : ''
  1448. console.log(pptJSONUrl)
  1449. if (pptJSONUrl) {
  1450. const pptdata = await getFile(pptJSONUrl)
  1451. // pptdata.data 是 ArrayBuffer,需要先转成字符串再解析为 JSON
  1452. let jsonStr = ''
  1453. if (pptdata && pptdata.data) {
  1454. // 先将 ArrayBuffer 转为字符串
  1455. const uint8Array = new Uint8Array(pptdata.data)
  1456. jsonStr = new TextDecoder('utf-8').decode(uint8Array)
  1457. try {
  1458. const jsonObj = JSON.parse(jsonStr)
  1459. importJSON(jsonObj)
  1460. }
  1461. catch (e) {
  1462. console.error('解析pptdata.data失败:', e)
  1463. }
  1464. }
  1465. }
  1466. }
  1467. catch (error) {
  1468. console.error('获取课程详情失败:', error)
  1469. message.error('获取课程详情失败')
  1470. isLoading.value = false
  1471. }
  1472. finally {
  1473. isLoading.value = false
  1474. // if (props.type == '2') {
  1475. // console.log('判断是否是学生进入全屏')
  1476. // function panFull() {
  1477. // console.log('判断是否是学生进入全屏111')
  1478. // if (!document.fullscreenElement) {
  1479. // setTimeout(() => {
  1480. // if (!document.fullscreenElement) {
  1481. // if (document.documentElement.requestFullscreen) {
  1482. // document.documentElement.requestFullscreen()
  1483. // }
  1484. // else if (document.documentElement.mozRequestFullScreen) { // Firefox
  1485. // document.documentElement.mozRequestFullScreen()
  1486. // }
  1487. // else if (document.documentElement.webkitRequestFullscreen) { // Chrome, Safari and Opera
  1488. // document.documentElement.webkitRequestFullscreen()
  1489. // }
  1490. // else if (document.documentElement.msRequestFullscreen) { // IE/Edge
  1491. // document.documentElement.msRequestFullscreen()
  1492. // }
  1493. // panFull()
  1494. // }
  1495. // }, 50)
  1496. // }
  1497. // }
  1498. // nextTick(() => {
  1499. // setTimeout(() => {
  1500. // // enterFullscreen();
  1501. // panFull()
  1502. // }, 50)
  1503. // })
  1504. // }
  1505. }
  1506. }
  1507. const getWorkLoading = ref<any>(false)
  1508. const getWork = async (isUpdate = false) => {
  1509. try {
  1510. if (getWorkLoading.value) {
  1511. return
  1512. }
  1513. if (!isUpdate) {
  1514. workLoading.value = true
  1515. }
  1516. getWorkLoading.value = true
  1517. console.log('getWork 开始执行,参数:', {
  1518. courseid: props.courseid,
  1519. slideIndex: slideIndex.value,
  1520. type: props.type,
  1521. isUpdate
  1522. })
  1523. if (!props.courseid) {
  1524. console.warn('getWork: courseid 未提供,跳过执行')
  1525. if (!isUpdate) workLoading.value = false
  1526. return
  1527. }
  1528. const res = await api.selectSWorks(props.courseid, '0', slideIndex.value.toString())
  1529. console.log('getWork 执行成功,结果:', res)
  1530. const frame = elementList.value.find(element => element.type === ElementTypes.FRAME)
  1531. console.log('frame:', frame)
  1532. const toolType = frame?.toolType ?? ''
  1533. const newWorkArray = props.cid
  1534. ? res[0].filter((work: any) => {
  1535. return props.type == '1' || (props.type == '2' && work.classid.includes(props.cid)) && (work.atool === toolType || !toolType)
  1536. })
  1537. : res[0]
  1538. // 如果是更新模式,只有当数据真正变化时才更新
  1539. if (isUpdate) {
  1540. const hasChanged = checkWorkArrayChanged(workArray.value, newWorkArray)
  1541. if (hasChanged) {
  1542. console.log('检测到作业数据变化,更新显示')
  1543. workArray.value = newWorkArray
  1544. }
  1545. else {
  1546. console.log('作业数据无变化,跳过更新')
  1547. }
  1548. }
  1549. else {
  1550. workArray.value = newWorkArray
  1551. }
  1552. console.log('getWork 执行成功,结果:', workArray.value)
  1553. getWorkLoading.value = false
  1554. }
  1555. catch (error) {
  1556. console.error('getWork 执行失败:', error)
  1557. if (!isUpdate) {
  1558. message.error('获取作业信息失败')
  1559. }
  1560. getWorkLoading.value = false
  1561. }
  1562. finally {
  1563. if (!isUpdate) {
  1564. workLoading.value = false
  1565. }
  1566. getWorkLoading.value = false
  1567. }
  1568. }
  1569. const selectWorksStudent = async () => {
  1570. studentLoading.value = true
  1571. try {
  1572. const res = await api.selectWorksStudent(props.oid as string, courseDetail.value.juri as string)
  1573. console.log('selectWorksStudent', res)
  1574. const students = res[0]
  1575. console.log('students', students)
  1576. if (props.cid) {
  1577. studentArray.value = students.filter((student: any) => student.classid.includes(props.cid))
  1578. }
  1579. else {
  1580. studentArray.value = students
  1581. }
  1582. }
  1583. catch (error) {
  1584. console.error('获取学生信息失败:', error)
  1585. message.error('获取学生信息失败')
  1586. }
  1587. finally {
  1588. studentLoading.value = false
  1589. }
  1590. }
  1591. // 检查作业数组是否发生变化
  1592. const checkWorkArrayChanged = (oldArray: WorkItem[], newArray: WorkItem[]): boolean => {
  1593. if (oldArray.length !== newArray.length) return true
  1594. // 检查每个作业的 id 和 name 是否一致
  1595. for (let i = 0; i < oldArray.length; i++) {
  1596. const oldWork = oldArray[i]
  1597. const newWork = newArray[i]
  1598. if (oldWork.id !== newWork.id || oldWork.name !== newWork.name || oldWork.content !== newWork.content) {
  1599. return true
  1600. }
  1601. }
  1602. return false
  1603. }
  1604. // 查询课程跟随状态
  1605. const selectCourseSLook = async () => {
  1606. const res = await api.selectCourseSLook(props.courseid as string)
  1607. console.log('selectCourseSLook', res)
  1608. if (res[0][0].follow == 2) {
  1609. if (props.type == '2') {
  1610. goToSlide(Number(res[0][0].followC))
  1611. }
  1612. isFollowModeActive.value = true
  1613. if (props.userid == courseDetail.value.userid && props.type == '1') {
  1614. await api.updateCourseFollowC(slideIndex.value, props.courseid as string)
  1615. sendMessage({slideIndex: slideIndex.value, courseid: props.courseid, type: 'slideIndex'})
  1616. console.log('设置当前幻灯片为跟随目标:', slideIndex.value)
  1617. }
  1618. }
  1619. else {
  1620. isFollowModeActive.value = false
  1621. }
  1622. }
  1623. // 切换跟随模式
  1624. const toggleFollowMode = async () => {
  1625. try {
  1626. const newFollowState = !isFollowModeActive.value
  1627. const sopen = newFollowState ? 2 : 1
  1628. // 调用API更新跟随状态
  1629. const res = await api.updateCourseFollow(sopen, props.courseid as string)
  1630. console.log('更新跟随模式状态:', res)
  1631. sendMessage({sopen: newFollowState, courseid: props.courseid, type: 'sopen'})
  1632. if (res) {
  1633. isFollowModeActive.value = newFollowState
  1634. message.success(newFollowState ? '跟随模式已开启' : '跟随模式已关闭')
  1635. // 如果开启跟随模式,设置当前幻灯片为跟随目标
  1636. if (newFollowState) {
  1637. await api.updateCourseFollowC(slideIndex.value, props.courseid as string)
  1638. console.log('设置当前幻灯片为跟随目标:', slideIndex.value)
  1639. }
  1640. }
  1641. else {
  1642. message.error('操作失败,请重试')
  1643. }
  1644. }
  1645. catch (error) {
  1646. console.error('切换跟随模式失败:', error)
  1647. message.error('操作失败,请重试')
  1648. }
  1649. }
  1650. // 检查是否为创建人
  1651. const checkIsCreator = () => {
  1652. // 这里可以根据实际业务逻辑判断是否为创建人
  1653. // 比如通过props中的userid与课程创建者ID比较
  1654. if (courseDetail.value && props.userid) {
  1655. isCreator.value = courseDetail.value.userid === props.userid
  1656. }
  1657. }
  1658. /**
  1659. * 初始化消息监听
  1660. */
  1661. const messageInit = () => {
  1662. if (docSocket.value && !yMessage.value) {
  1663. console.log('获取message', docSocket.value, yMessage.value)
  1664. yMessage.value = docSocket.value.getArray('message')
  1665. yMessage.value.observe((e: any) => {
  1666. e.changes.added.forEach((i: any) => {
  1667. const message = i.content.getContent()[0]
  1668. console.log('yMessage', message)
  1669. const _nowTime = new Date()
  1670. const _msgTime = new Date(message.timestamp)
  1671. if (
  1672. (_nowTime as any) - (_msgTime as any) <= 1000 * 10 &&
  1673. message.mId !== mId.value
  1674. ) {
  1675. // 10秒内且不是自己发的消息
  1676. getMessages(message)
  1677. }
  1678. })
  1679. })
  1680. }
  1681. }
  1682. /**
  1683. * 发送消息
  1684. */
  1685. const sendMessage = (obj: any) => {
  1686. if (docSocket.value && yMessage.value) {
  1687. const message = obj
  1688. obj.timestamp = new Date().toISOString()
  1689. obj.mId = mId.value
  1690. docSocket.value.transact(() => {
  1691. yMessage.value.push([message])
  1692. })
  1693. }
  1694. }
  1695. /**
  1696. * 处理收到的消息
  1697. */
  1698. const getMessages = (msgObj: any) => {
  1699. console.log('message', msgObj)
  1700. // 处理幻灯片切换消息
  1701. if (props.type == '2' && msgObj.type === 'slideIndex') {
  1702. goToSlide(msgObj.slideIndex)
  1703. }
  1704. // 处理跟随模式状态变化
  1705. if (props.type == '2' && msgObj.type === 'sopen') {
  1706. selectCourseSLook()
  1707. }
  1708. // 处理作业提交消息 - 当有人提交作业时,重新获取作业数据
  1709. if (props.type == '1' && msgObj.type === 'homework_submitted' && msgObj.courseid === props.courseid) {
  1710. console.log('收到作业提交消息,重新获取作业数据')
  1711. // 延迟一点时间,确保后端数据已更新
  1712. setTimeout(() => {
  1713. if (currentSlideHasIframe.value) {
  1714. getWork(true) // 传入true表示是更新模式
  1715. }
  1716. }, 1000)
  1717. }
  1718. }
  1719. onMounted(() => {
  1720. document.addEventListener('keydown', handleKeydown)
  1721. // 处理URL参数
  1722. if (props.courseid || props.type) {
  1723. console.log('收到URL参数:', { courseid: props.courseid, type: props.type })
  1724. // 这里可以根据courseid和type进行相应的处理
  1725. // 比如加载特定的课程数据、设置特定的显示模式等
  1726. if (props.courseid) {
  1727. console.log('课程ID:', props.courseid)
  1728. // TODO: 根据courseid加载对应的课程数据
  1729. }
  1730. if (props.type) {
  1731. console.log('类型:', props.type)
  1732. // TODO: 根据type设置特定的显示模式或功能
  1733. }
  1734. }
  1735. getCourseDetail()
  1736. // 计算初始缩放比例
  1737. nextTick(() => {
  1738. calculateScale()
  1739. // 处理iframe链接
  1740. processIframeLinks()
  1741. // 初始化时检查并自动切换到可用面板
  1742. autoSwitchToAvailablePanel()
  1743. })
  1744. // 监听窗口大小变化
  1745. window.addEventListener('resize', calculateScale)
  1746. // 监听全屏状态变化
  1747. document.addEventListener('fullscreenchange', handleFullscreenChange)
  1748. // 监听幻灯片数据更新事件(来自useImport的readJSON)
  1749. window.addEventListener('slidesDataUpdated', handleSlidesDataUpdated)
  1750. // 监听视口尺寸更新事件
  1751. window.addEventListener('viewportSizeUpdated', handleViewportSizeUpdated)
  1752. // 将导入导出功能暴露到window上,方便调试和外部调用
  1753. ; (window as any).PPTistStudent = {
  1754. importJSON,
  1755. exportJSON,
  1756. slides: slidesStore.slides,
  1757. currentSlide: computed(() => slidesStore.currentSlide),
  1758. slideIndex: computed(() => slidesStore.slideIndex),
  1759. goToSlide,
  1760. previousSlide,
  1761. nextSlide,
  1762. enterFullscreen,
  1763. toggleLaserPen,
  1764. // 添加URL参数到全局对象中
  1765. courseid: props.courseid,
  1766. type: props.type,
  1767. successSubmit,
  1768. toggleFollowMode,
  1769. // 添加重连功能
  1770. manualReconnect,
  1771. connectionStatus: computed(() => connectionStatus.value)
  1772. }
  1773. console.log('PPTist Student View 已加载,可通过 window.PPTistStudent 访问功能')
  1774. console.log('URL参数:', { courseid: props.courseid, type: props.type })
  1775. // 初始化WebSocket连接
  1776. if (api.yweb_socket) {
  1777. createWebSocketConnection()
  1778. }
  1779. })
  1780. onUnmounted(() => {
  1781. document.removeEventListener('keydown', handleKeydown)
  1782. window.removeEventListener('resize', calculateScale)
  1783. document.removeEventListener('fullscreenchange', handleFullscreenChange)
  1784. // 移除幻灯片数据更新事件监听器
  1785. window.removeEventListener('slidesDataUpdated', handleSlidesDataUpdated)
  1786. // 移除视口尺寸更新事件监听器
  1787. window.removeEventListener('viewportSizeUpdated', handleViewportSizeUpdated)
  1788. // 清理WebSocket连接
  1789. if (reconnectTimer.value) {
  1790. clearTimeout(reconnectTimer.value)
  1791. reconnectTimer.value = null
  1792. }
  1793. if (providerSocket.value) {
  1794. providerSocket.value.destroy()
  1795. providerSocket.value = null
  1796. }
  1797. // 清理window上的引用
  1798. if ((window as any).PPTistStudent) {
  1799. delete (window as any).PPTistStudent
  1800. console.log('PPTist Student View 已卸载,window.PPTistStudent 已清理')
  1801. }
  1802. })
  1803. // 手动重连
  1804. const manualReconnect = () => {
  1805. if (isConnecting.value) return
  1806. reconnectAttempts.value = 0 // 重置重连次数
  1807. createWebSocketConnection()
  1808. }
  1809. // 创建WebSocket连接
  1810. const createWebSocketConnection = () => {
  1811. if (!api.yweb_socket || isConnecting.value) return
  1812. isConnecting.value = true
  1813. connectionStatus.value = 'connecting'
  1814. try {
  1815. // 清理之前的连接
  1816. if (providerSocket.value) {
  1817. providerSocket.value.destroy()
  1818. providerSocket.value = null
  1819. }
  1820. docSocket.value = new Y.Doc()
  1821. providerSocket.value = new WebsocketProvider(
  1822. api.yweb_socket,
  1823. 'PPT' + props.courseid,
  1824. docSocket.value
  1825. )
  1826. providerSocket.value.on('status', (event: any) => {
  1827. console.log('👉 WebSocket状态:', event.status)
  1828. if (event.status === 'connected') {
  1829. console.log('👉连接成功websocket(teachingMode)')
  1830. connectionStatus.value = 'connected'
  1831. isConnecting.value = false
  1832. reconnectAttempts.value = 0 // 重置重连次数
  1833. // 清理重连定时器
  1834. if (reconnectTimer.value) {
  1835. clearTimeout(reconnectTimer.value)
  1836. reconnectTimer.value = null
  1837. }
  1838. mId.value = Math.random().toString(36).substr(2, 9)
  1839. messageInit()
  1840. }
  1841. else if (event.status === 'disconnected') {
  1842. console.log('👉 WebSocket连接断开')
  1843. connectionStatus.value = 'disconnected'
  1844. isConnecting.value = false
  1845. handleDisconnection()
  1846. }
  1847. })
  1848. // 监听连接错误
  1849. providerSocket.value.on('connection-error', (error: any) => {
  1850. console.error('👉 WebSocket连接错误:', error)
  1851. connectionStatus.value = 'disconnected'
  1852. isConnecting.value = false
  1853. handleDisconnection()
  1854. })
  1855. }
  1856. catch (error) {
  1857. console.error('👉 创建WebSocket连接失败:', error)
  1858. connectionStatus.value = 'disconnected'
  1859. isConnecting.value = false
  1860. handleDisconnection()
  1861. }
  1862. }
  1863. // 处理连接断开
  1864. const handleDisconnection = () => {
  1865. if (reconnectAttempts.value < maxReconnectAttempts.value) {
  1866. reconnectAttempts.value++
  1867. console.log(`👉 尝试重连 (${reconnectAttempts.value}/${maxReconnectAttempts.value})`)
  1868. reconnectTimer.value = setTimeout(() => {
  1869. createWebSocketConnection()
  1870. }, reconnectInterval.value)
  1871. }
  1872. else {
  1873. console.error('👉 WebSocket重连次数已达上限,停止重连')
  1874. // 可以在这里显示用户提示
  1875. message.error('网络连接异常,请检查网络后刷新页面')
  1876. }
  1877. }
  1878. </script>
  1879. <style lang="scss" scoped>
  1880. .pptist-student-viewer {
  1881. height: 100vh;
  1882. display: flex;
  1883. background-color: #f4f4f4;
  1884. padding: 15px 0;
  1885. box-sizing: border-box;
  1886. // 全屏模式样式
  1887. &.fullscreen {
  1888. padding: 0;
  1889. .layout-content-left {
  1890. display: none; // 全屏时隐藏左侧导航栏
  1891. }
  1892. .layout-content-right {
  1893. display: none; // 全屏时隐藏左侧导航栏
  1894. }
  1895. .viewer-header {
  1896. display: none; // 全屏时隐藏顶部标题栏
  1897. }
  1898. }
  1899. // 激光笔模式样式
  1900. &.laser-pen {
  1901. 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;
  1902. }
  1903. }
  1904. .layout-content-left {
  1905. width: 200px;
  1906. height: 100%;
  1907. background-color: #fff;
  1908. border-radius: 0 5px 0 5px;
  1909. overflow: hidden;
  1910. transition: width .2s ease;
  1911. margin-left: 10px;
  1912. }
  1913. .layout-content-left.collapsed {
  1914. width: 48px;
  1915. margin-left: 0;
  1916. }
  1917. .slide-header {
  1918. display: flex;
  1919. align-items: center;
  1920. justify-content: space-between;
  1921. }
  1922. /* 收缩时头部仅显示按钮,并保持按钮在可用宽度内水平居中 */
  1923. .layout-content-left.collapsed .slide-header {
  1924. justify-content: center;
  1925. padding: 8px;
  1926. }
  1927. .layout-content-right {
  1928. width: 400px;
  1929. height: 100%;
  1930. background-color: #fff;
  1931. border-radius: 5px 0 5px 0;
  1932. overflow: hidden;
  1933. transition: width .2s ease;
  1934. position: relative;
  1935. margin-right: 10px;
  1936. }
  1937. .panel-content {
  1938. margin-right: 0;
  1939. // padding: 0 8px;
  1940. height: calc(100% - 65px);
  1941. overflow: auto;
  1942. }
  1943. .layout-content-right.collapsed {
  1944. width: 52px;
  1945. margin-right: 0px;
  1946. }
  1947. .right-panel-header {
  1948. display: flex;
  1949. align-items: center;
  1950. justify-content: space-between;
  1951. }
  1952. /* 侧边导航标签样式 */
  1953. .side-nav-tabs {
  1954. position: absolute;
  1955. right: 0;
  1956. top: 60px;
  1957. bottom: 0;
  1958. width: 52px;
  1959. display: flex;
  1960. flex-direction: column;
  1961. gap: 8px;
  1962. padding: 8px 0;
  1963. align-items: center;
  1964. background: #fff;
  1965. border-left: 1px solid #e0e0e0;
  1966. z-index: 10;
  1967. }
  1968. .side-nav-btn {
  1969. width: 45px;
  1970. height: 45px;
  1971. min-height: 45px;
  1972. border: 1px solid #d9d9d9;
  1973. background: #fff;
  1974. border-radius: 6px;
  1975. cursor: pointer;
  1976. transition: all 0.2s;
  1977. display: flex;
  1978. align-items: center;
  1979. justify-content: center;
  1980. padding: 8px;
  1981. gap: 8px;
  1982. overflow: hidden;
  1983. &:hover {
  1984. border-color: #1890ff;
  1985. transform: scale(1.02);
  1986. }
  1987. &.active {
  1988. border-color: #3681fc;
  1989. background: #3681fc;
  1990. box-shadow: 0 0 0 2px rgba(54, 129, 252, 0.2);
  1991. }
  1992. img {
  1993. width: 25px;
  1994. height: 25px;
  1995. object-fit: contain;
  1996. flex-shrink: 0;
  1997. }
  1998. span {
  1999. font-size: 12px;
  2000. font-weight: 500;
  2001. color: #333;
  2002. white-space: nowrap;
  2003. overflow: hidden;
  2004. text-overflow: ellipsis;
  2005. }
  2006. &.active span {
  2007. color: #fff;
  2008. }
  2009. }
  2010. /* 收缩时头部仅显示按钮,并保持按钮在可用宽度内水平居中 */
  2011. .layout-content-right.collapsed .right-panel-header {
  2012. justify-content: center;
  2013. padding: 8px;
  2014. }
  2015. /* 收缩状态下的切换按钮 */
  2016. .collapsed-tabs {
  2017. display: flex;
  2018. flex-direction: column;
  2019. gap: 8px;
  2020. // padding: 8px;
  2021. align-items: center;
  2022. }
  2023. .collapsed-tab-btn {
  2024. width: 32px;
  2025. height: 32px;
  2026. border: 1px solid #d9d9d9;
  2027. background: #fff;
  2028. border-radius: 6px;
  2029. cursor: pointer;
  2030. transition: all 0.2s;
  2031. display: flex;
  2032. align-items: center;
  2033. justify-content: center;
  2034. padding: 0;
  2035. overflow: hidden;
  2036. &:hover {
  2037. border-color: #1890ff;
  2038. transform: scale(1.05);
  2039. }
  2040. &.active {
  2041. border-color: #3681fc;
  2042. background: #3681fc;
  2043. box-shadow: 0 0 0 2px rgba(54, 129, 252, 0.2);
  2044. }
  2045. img {
  2046. width: 20px;
  2047. height: 20px;
  2048. object-fit: contain;
  2049. transition: transform 0.2s;
  2050. }
  2051. &:hover img {
  2052. transform: scale(1.1);
  2053. }
  2054. }
  2055. .collapse-btn {
  2056. display: inline-flex;
  2057. align-items: center;
  2058. justify-content: center;
  2059. width: 32px;
  2060. height: 32px;
  2061. // border: 1px solid #d9d9d9;
  2062. border: none;
  2063. border-radius: 8px;
  2064. background: #fff;
  2065. color: #333;
  2066. cursor: pointer;
  2067. line-height: 1;
  2068. font-weight: 700;
  2069. position: absolute;
  2070. }
  2071. .collapse-btn:hover {
  2072. // border-color: #1890ff;
  2073. // color: #1890ff;
  2074. }
  2075. .homework-title {
  2076. padding: 12px 12px 0 12px;
  2077. color: #333;
  2078. font-size: 14px;
  2079. font-weight: 600;
  2080. }
  2081. .homework-grid {
  2082. display: grid;
  2083. grid-template-columns: repeat(4, 1fr);
  2084. gap: 16px;
  2085. padding: 12px;
  2086. }
  2087. .homework-btn {
  2088. display: inline-flex;
  2089. align-items: center;
  2090. justify-content: center;
  2091. width: 100%;
  2092. min-width: 0;
  2093. height: 35px;
  2094. border: 1px solid #2f80ed;
  2095. color: #2f80ed;
  2096. background: #fff;
  2097. border-radius: 8px;
  2098. cursor: pointer;
  2099. font-weight: 600;
  2100. overflow: hidden;
  2101. padding: 0 10px;
  2102. text-align: center;
  2103. }
  2104. .homework-btn__text {
  2105. display: block;
  2106. max-width: 100%;
  2107. overflow: hidden;
  2108. white-space: nowrap;
  2109. text-overflow: ellipsis;
  2110. }
  2111. .homework-btn:hover {
  2112. box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  2113. }
  2114. .homework-btn.unsubmitted {
  2115. border-color: #d9d9d9;
  2116. color: #999;
  2117. background: #f5f5f5;
  2118. cursor: not-allowed;
  2119. }
  2120. .homework-btn.unsubmitted:hover {
  2121. box-shadow: none;
  2122. transform: none;
  2123. }
  2124. .homework-loading {
  2125. padding: 12px;
  2126. color: #666;
  2127. font-size: 13px;
  2128. }
  2129. .homework-empty {
  2130. padding: 12px;
  2131. color: #999;
  2132. font-size: 13px;
  2133. }
  2134. .thumbnails {
  2135. padding: 0;
  2136. height: 100%;
  2137. .viewer-header {
  2138. margin-bottom: 16px;
  2139. h3 {
  2140. margin: 0;
  2141. font-size: 16px;
  2142. font-weight: 600;
  2143. color: #333;
  2144. text-align: center;
  2145. width: 100%;
  2146. }
  2147. }
  2148. .thumbnail-list {
  2149. width: 100%;
  2150. padding: 0 16px;
  2151. box-sizing: border-box;
  2152. .thumbnail-item {
  2153. position: relative;
  2154. margin-bottom: 12px;
  2155. cursor: pointer;
  2156. border-radius: 8px;
  2157. overflow: hidden;
  2158. transition: all 0.2s ease;
  2159. border: 2px solid rgba(24, 144, 255, 0.2);
  2160. &:hover {
  2161. transform: translateY(-2px);
  2162. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  2163. border-color: rgba(24, 144, 255, 0.4);
  2164. }
  2165. &.active {
  2166. border: 2px solid #1890ff;
  2167. box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
  2168. }
  2169. .label {
  2170. position: absolute;
  2171. top: 8px;
  2172. left: 8px;
  2173. background-color: rgba(0, 0, 0, 0.6);
  2174. color: #fff;
  2175. padding: 2px 6px;
  2176. border-radius: 4px;
  2177. font-size: 12px;
  2178. font-weight: 600;
  2179. z-index: 1;
  2180. }
  2181. .thumbnail {
  2182. width: 100%;
  2183. height: auto;
  2184. }
  2185. }
  2186. }
  2187. .page-number {
  2188. text-align: center;
  2189. margin-top: 16px;
  2190. padding: 8px;
  2191. background-color: #f0f0f0;
  2192. border-radius: 4px;
  2193. font-size: 14px;
  2194. color: #666;
  2195. }
  2196. .progress-bar {
  2197. margin-top: 12px;
  2198. height: 6px;
  2199. background-color: #f0f0f0;
  2200. border-radius: 3px;
  2201. overflow: hidden;
  2202. .progress-fill {
  2203. height: 100%;
  2204. background: linear-gradient(90deg, #1890ff, #40a9ff);
  2205. border-radius: 3px;
  2206. transition: width 0.3s ease;
  2207. }
  2208. }
  2209. }
  2210. .layout-content-center {
  2211. flex: 1;
  2212. display: flex;
  2213. flex-direction: column;
  2214. background-color: #000;
  2215. }
  2216. .viewer-header {
  2217. height: 45px;
  2218. background-color: #fff;
  2219. border-bottom: 1px solid #e0e0e0;
  2220. display: flex;
  2221. align-items: center;
  2222. justify-content: space-between;
  2223. padding: 0 8px;
  2224. transition: transform 0.3s ease;
  2225. position: relative;
  2226. &.hidden {
  2227. transform: translateY(-100%);
  2228. }
  2229. .slide-title {
  2230. font-size: 18px;
  2231. font-weight: 600;
  2232. color: #333;
  2233. }
  2234. .viewer-controls {
  2235. display: flex;
  2236. gap: 12px;
  2237. button {
  2238. padding: 8px 12px;
  2239. border: 1px solid #d9d9d9;
  2240. border-radius: 6px;
  2241. background-color: #fff;
  2242. color: #333;
  2243. cursor: pointer;
  2244. transition: all 0.2s ease;
  2245. display: flex;
  2246. align-items: center;
  2247. justify-content: center;
  2248. min-width: 40px;
  2249. height: 36px;
  2250. &:hover:not(:disabled) {
  2251. border-color: #1890ff;
  2252. color: #1890ff;
  2253. }
  2254. &:disabled {
  2255. opacity: 0.5;
  2256. cursor: not-allowed;
  2257. }
  2258. &.back-btn {
  2259. background-color: #1890ff;
  2260. color: #fff;
  2261. border-color: #1890ff;
  2262. &:hover {
  2263. background-color: #40a9ff;
  2264. border-color: #40a9ff;
  2265. }
  2266. }
  2267. &.follow-active {
  2268. background-color: #3681fc;
  2269. color: #fff !important;
  2270. border-color: #3681fc;
  2271. &:hover {
  2272. background-color: #2d6fd9;
  2273. border-color: #2d6fd9;
  2274. color: #fff !important;
  2275. }
  2276. }
  2277. .control-icon {
  2278. font-size: 16px;
  2279. }
  2280. }
  2281. }
  2282. }
  2283. .viewer-canvas {
  2284. flex: 1;
  2285. position: relative;
  2286. background-color: rgb(244, 244, 244);
  2287. overflow: hidden;
  2288. // 全屏时隐藏滚动条和边框
  2289. &.fullscreen-mode {
  2290. overflow: hidden !important;
  2291. background-color: transparent !important;
  2292. }
  2293. }
  2294. .slide-list-wrap {
  2295. position: absolute;
  2296. overflow: hidden;
  2297. background-color: #fff;
  2298. box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.01), 0 0 12px 0 rgba(0, 0, 0, 0.1);
  2299. border-radius: 8px;
  2300. /* 全屏时去掉圆角 */
  2301. .pptist-student-viewer.fullscreen & {
  2302. border-radius: 0;
  2303. }
  2304. }
  2305. .slide-list-wrap-n{
  2306. border: 5px solid #595959;
  2307. background: #000;
  2308. padding: 15px 0 0 0;
  2309. box-sizing: border-box;
  2310. }
  2311. .slide-bottom{
  2312. height: 60px;
  2313. background: #000;
  2314. position: relative;
  2315. z-index: 10;
  2316. }
  2317. .loading-indicator {
  2318. position: absolute;
  2319. top: 50%;
  2320. left: 50%;
  2321. transform: translate(-50%, -50%);
  2322. display: flex;
  2323. align-items: center;
  2324. justify-content: center;
  2325. z-index: 10;
  2326. .loading-text {
  2327. color: #666;
  2328. font-size: 14px;
  2329. background-color: rgba(255, 255, 255, 0.9);
  2330. padding: 12px 20px;
  2331. border-radius: 6px;
  2332. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  2333. }
  2334. }
  2335. // 全屏模式样式
  2336. .fullscreen-slide {
  2337. // 使用放映功能的默认样式
  2338. }
  2339. // 全屏工具按钮样式,直接复制放映功能的样式
  2340. .tools-left {
  2341. position: fixed;
  2342. bottom: 8px;
  2343. left: 8px;
  2344. font-size: 25px;
  2345. color: #666;
  2346. z-index: 10;
  2347. .tool-btn {
  2348. opacity: .3;
  2349. cursor: pointer;
  2350. transition: opacity 0.3s;
  2351. &:hover {
  2352. opacity: .95;
  2353. }
  2354. &+.tool-btn {
  2355. margin-left: 8px;
  2356. }
  2357. }
  2358. }
  2359. .tools-right {
  2360. height: 66px;
  2361. position: fixed;
  2362. bottom: -66px;
  2363. right: 0;
  2364. z-index: 5;
  2365. padding: 8px;
  2366. transition: bottom 0.3s;
  2367. &.visible {
  2368. bottom: 0;
  2369. }
  2370. &::after {
  2371. content: '';
  2372. width: 100%;
  2373. height: 66px;
  2374. position: absolute;
  2375. left: 0;
  2376. top: -66px;
  2377. }
  2378. .content {
  2379. width: 100%;
  2380. height: 100%;
  2381. display: flex;
  2382. justify-content: center;
  2383. align-items: center;
  2384. border-radius: 4px;
  2385. font-size: 25px;
  2386. background-color: #fff;
  2387. color: #333;
  2388. padding: 8px 10px;
  2389. box-shadow: 0 2px 12px 0 rgb(56, 56, 56, .2);
  2390. border: 1px solid #e2e6ed;
  2391. }
  2392. .tool-btn {
  2393. cursor: pointer;
  2394. &:hover,
  2395. &.active {
  2396. color: #1890ff;
  2397. }
  2398. &+.tool-btn {
  2399. margin-left: 15px;
  2400. }
  2401. }
  2402. .page-number {
  2403. font-size: 12px;
  2404. padding: 0 12px;
  2405. cursor: pointer;
  2406. }
  2407. }
  2408. .viewport {
  2409. position: relative;
  2410. width: 100%;
  2411. height: 100%;
  2412. background-color: #fff;
  2413. }
  2414. .background {
  2415. width: 100%;
  2416. height: 100%;
  2417. background-position: center;
  2418. position: absolute;
  2419. }
  2420. // 响应式设计
  2421. @media (max-width: 768px) {
  2422. .layout-content-left {
  2423. width: 160px;
  2424. }
  2425. .layout-content-right {
  2426. width: 160px;
  2427. }
  2428. .viewer-header {
  2429. padding: 0 16px;
  2430. .slide-title {
  2431. font-size: 16px;
  2432. }
  2433. .viewer-controls button {
  2434. padding: 6px 12px;
  2435. font-size: 14px;
  2436. }
  2437. }
  2438. }
  2439. /* 作业提交按钮样式 */
  2440. .homework-submit-btn {
  2441. position: fixed;
  2442. bottom: 30px;
  2443. z-index: 100;
  2444. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  2445. color: white;
  2446. padding: 12px 20px;
  2447. border-radius: 25px;
  2448. cursor: pointer;
  2449. display: flex;
  2450. align-items: center;
  2451. gap: 8px;
  2452. box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  2453. transition: all 0.3s ease;
  2454. font-size: 14px;
  2455. font-weight: 500;
  2456. &:hover:not(.submitting) {
  2457. transform: translateY(-2px);
  2458. box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  2459. }
  2460. &:active:not(.submitting) {
  2461. transform: translateY(0);
  2462. }
  2463. &.submitting {
  2464. cursor: not-allowed;
  2465. opacity: 0.8;
  2466. background: linear-gradient(135deg, #999 0%, #666 100%);
  2467. }
  2468. .btn-text {
  2469. white-space: nowrap;
  2470. }
  2471. .tool-btn {
  2472. background: transparent;
  2473. color: white;
  2474. width: 20px;
  2475. height: 20px;
  2476. font-size: 16px;
  2477. &:hover {
  2478. background: transparent;
  2479. transform: none;
  2480. }
  2481. }
  2482. .loading-spinner {
  2483. width: 20px;
  2484. height: 20px;
  2485. border: 2px solid rgba(255, 255, 255, 0.3);
  2486. border-top: 2px solid white;
  2487. border-radius: 50%;
  2488. animation: spin 1s linear infinite;
  2489. }
  2490. }
  2491. /* 刷新网页按钮样式 */
  2492. .refresh-page-btn {
  2493. position: fixed;
  2494. bottom: 30px;
  2495. z-index: 100;
  2496. background: linear-gradient(135deg, #52c41a 0%, #389e0d 100%);
  2497. color: white;
  2498. padding: 12px 20px;
  2499. border-radius: 25px;
  2500. cursor: pointer;
  2501. display: flex;
  2502. align-items: center;
  2503. gap: 8px;
  2504. box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  2505. transition: all 0.3s ease;
  2506. font-size: 14px;
  2507. font-weight: 500;
  2508. &:hover {
  2509. transform: translateY(-2px);
  2510. box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  2511. }
  2512. &:active {
  2513. transform: translateY(0);
  2514. }
  2515. .btn-text {
  2516. white-space: nowrap;
  2517. }
  2518. .tool-btn {
  2519. background: transparent;
  2520. color: white;
  2521. width: 20px;
  2522. height: 20px;
  2523. font-size: 16px;
  2524. display: flex;
  2525. align-items: center;
  2526. &:hover {
  2527. background: transparent;
  2528. transform: none;
  2529. }
  2530. }
  2531. }
  2532. /* Loading状态样式 */
  2533. .loading-overlay {
  2534. position: absolute;
  2535. top: 0;
  2536. left: 0;
  2537. right: 0;
  2538. bottom: 0;
  2539. background: rgba(255, 255, 255, 0.95);
  2540. display: flex;
  2541. align-items: center;
  2542. justify-content: center;
  2543. z-index: 1000;
  2544. .loading-spinner {
  2545. width: 40px;
  2546. height: 40px;
  2547. border: 4px solid #f3f3f3;
  2548. border-top: 4px solid #1890ff;
  2549. border-radius: 50%;
  2550. animation: spin 1s linear infinite;
  2551. margin: 0 auto 16px;
  2552. }
  2553. }
  2554. .loading-content {
  2555. text-align: center;
  2556. color: #666;
  2557. }
  2558. .loading-text {
  2559. font-size: 14px;
  2560. color: #666;
  2561. }
  2562. @keyframes spin {
  2563. 0% { transform: rotate(0deg); }
  2564. 100% { transform: rotate(360deg); }
  2565. }
  2566. /* 标签页切换器样式 */
  2567. .tab-switcher {
  2568. display: flex;
  2569. flex: 1;
  2570. margin-right: 12px;
  2571. border-bottom: 1px solid #e0e0e0;
  2572. padding-bottom: 0;
  2573. height: 100%;
  2574. justify-content: center;
  2575. gap: 20px;
  2576. }
  2577. .tab-btn {
  2578. // flex: 1;
  2579. // padding: 12px 16px;
  2580. border: none;
  2581. background: transparent;
  2582. color: #666;
  2583. cursor: pointer;
  2584. transition: all 0.2s ease;
  2585. font-size: 14px;
  2586. font-weight: 500;
  2587. text-align: center;
  2588. white-space: nowrap;
  2589. position: relative;
  2590. border-radius: 0;
  2591. &:hover {
  2592. color: #333;
  2593. }
  2594. &.active {
  2595. color: #333;
  2596. font-weight: 600;
  2597. &::after {
  2598. content: '';
  2599. position: absolute;
  2600. bottom: -1px;
  2601. left: 0;
  2602. right: 0;
  2603. height: 2px;
  2604. background: #333;
  2605. border-radius: 1px;
  2606. }
  2607. }
  2608. }
  2609. // 在适当位置添加连接状态指示器
  2610. .connection-status {
  2611. position: fixed;
  2612. top: 10px;
  2613. right: 10px;
  2614. background-color: rgba(255, 255, 255, 0.8);
  2615. border-radius: 5px;
  2616. padding: 5px 10px;
  2617. display: flex;
  2618. align-items: center;
  2619. z-index: 1000;
  2620. .status-indicator {
  2621. width: 100px;
  2622. height: 20px;
  2623. border-radius: 5px;
  2624. margin-right: 10px;
  2625. display: flex;
  2626. justify-content: center;
  2627. align-items: center;
  2628. &.connected {
  2629. background-color: #52c41a;
  2630. }
  2631. &.connecting {
  2632. background-color: #1890ff;
  2633. }
  2634. &.disconnected {
  2635. background-color: #ff4d4f;
  2636. }
  2637. span {
  2638. color: #fff;
  2639. font-size: 12px;
  2640. }
  2641. }
  2642. .reconnect-btn {
  2643. background-color: #1890ff;
  2644. color: #fff;
  2645. border: none;
  2646. border-radius: 5px;
  2647. padding: 5px 10px;
  2648. cursor: pointer;
  2649. transition: background-color 0.3s;
  2650. &:hover {
  2651. background-color: #40a9ff;
  2652. }
  2653. }
  2654. }
  2655. </style>