index.vue 80 KB

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