index.vue 85 KB

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