App.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <template v-if="slides.length">
  3. <Screen v-if="viewMode !== 'student' && screening" key="screen" />
  4. <KeepAlive>
  5. <Editor
  6. v-if="viewMode === 'editor' && _isPC && !screening"
  7. :courseid="urlParams.courseid"
  8. key="editor"
  9. />
  10. <Editor2
  11. v-else-if="viewMode === 'editor2' && _isPC && !screening"
  12. :courseid="urlParams.courseid"
  13. key="editor2"
  14. />
  15. <Editor3
  16. v-else-if="viewMode === 'editor3' && _isPC && !screening"
  17. :courseid="urlParams.courseid"
  18. :userid="urlParams.userid"
  19. key="editor3"
  20. />
  21. <Student
  22. v-else-if="viewMode === 'student'"
  23. :courseid="urlParams.courseid"
  24. :type="urlParams.type"
  25. :userid="urlParams.userid"
  26. :oid="urlParams.oid"
  27. :org="urlParams.org"
  28. :cid="urlParams.cid"
  29. key="student"
  30. />
  31. <Mobile v-else key="mobile" />
  32. </KeepAlive>
  33. </template>
  34. <FullscreenSpin :tip="lang.ssInitDataWait" v-else loading :mask="false" />
  35. </template>
  36. <script lang="ts" setup>
  37. import { onMounted, ref, provide } from 'vue'
  38. import { storeToRefs } from 'pinia'
  39. import {
  40. useScreenStore,
  41. useMainStore,
  42. useSnapshotStore,
  43. useSlidesStore,
  44. } from '@/store'
  45. import { lang } from '@/main'
  46. import { LOCALSTORAGE_KEY_DISCARDED_DB } from '@/configs/storage'
  47. import { deleteDiscardedDB } from '@/utils/database'
  48. import { isPC } from '@/utils/common'
  49. import api from '@/services'
  50. import Editor from './views/Editor/index.vue'
  51. import Editor2 from './views/Editor/index2.vue'
  52. import Editor3 from './views/Editor/index3.vue'
  53. import Screen from './views/Screen/index.vue'
  54. import Mobile from './views/Mobile/index.vue'
  55. import Student from './views/Student/index.vue'
  56. import FullscreenSpin from '@/components/FullscreenSpin.vue'
  57. const _isPC = isPC()
  58. const mainStore = useMainStore()
  59. const slidesStore = useSlidesStore()
  60. const snapshotStore = useSnapshotStore()
  61. const { databaseId } = storeToRefs(mainStore)
  62. const { slides } = storeToRefs(slidesStore)
  63. const { screening } = storeToRefs(useScreenStore())
  64. // 视图模式:'editor', 'student', 'screen'
  65. // 支持通过URL参数直接访问学生模式
  66. const getInitialViewMode = () => {
  67. // 检查URL参数
  68. const urlParams = new URLSearchParams(window.location.search)
  69. const modeFromUrl = urlParams.get('mode')
  70. console.log(modeFromUrl)
  71. if (modeFromUrl === 'student') {
  72. return 'student'
  73. }
  74. if (modeFromUrl === 'editor2') {
  75. return 'editor2'
  76. }
  77. if (modeFromUrl === 'editor3') {
  78. return 'editor3'
  79. }
  80. // 检查localStorage
  81. const modeFromStorage = localStorage.getItem('viewMode')
  82. if (modeFromStorage) {
  83. return modeFromStorage
  84. }
  85. // 默认返回编辑模式
  86. return 'editor'
  87. }
  88. // 获取URL参数中的courseid和type
  89. const getUrlParams = () => {
  90. const urlParams = new URLSearchParams(window.location.search)
  91. return {
  92. courseid: urlParams.get('courseid'),
  93. userid: urlParams.get('userid'),
  94. oid: urlParams.get('oid'),
  95. org: urlParams.get('org'),
  96. cid: urlParams.get('cid'),
  97. type: urlParams.get('type'),
  98. }
  99. }
  100. const urlParams = getUrlParams()
  101. const viewMode = ref(getInitialViewMode())
  102. // 全局切换视图模式的函数
  103. const switchViewMode = (mode: string) => {
  104. viewMode.value = mode
  105. localStorage.setItem('viewMode', mode)
  106. // 更新URL参数
  107. const url = new URL(window.location.href)
  108. if (mode === 'student') {
  109. url.searchParams.set('mode', 'student')
  110. }
  111. else {
  112. url.searchParams.delete('mode')
  113. }
  114. // 使用 history.pushState 更新URL,不刷新页面
  115. window.history.pushState({}, '', url.toString())
  116. }
  117. // 使用provide提供切换函数,供子组件调用
  118. provide('switchViewMode', switchViewMode)
  119. if (import.meta.env.MODE !== 'development') {
  120. window.onbeforeunload = () => false
  121. }
  122. onMounted(async () => {
  123. const slides = await api.getFileData('slides')
  124. console.log(slides)
  125. slidesStore.setSlides(slides)
  126. // 初始化快照数据库
  127. // await deleteDiscardedDB()
  128. // snapshotStore.initSnapshotDatabase()
  129. // 监听视图模式切换事件
  130. window.addEventListener('viewModeChanged', (event: any) => {
  131. if (event.detail) {
  132. switchViewMode(event.detail)
  133. }
  134. })
  135. })
  136. // 应用注销时向 localStorage 中记录下本次 indexedDB 的数据库ID,用于之后清除数据库
  137. window.addEventListener('beforeunload', () => {
  138. const discardedDB = localStorage.getItem(LOCALSTORAGE_KEY_DISCARDED_DB)
  139. const discardedDBList: string[] = discardedDB ? JSON.parse(discardedDB) : []
  140. discardedDBList.push(databaseId.value)
  141. const newDiscardedDB = JSON.stringify(discardedDBList)
  142. localStorage.setItem(LOCALSTORAGE_KEY_DISCARDED_DB, newDiscardedDB)
  143. })
  144. </script>
  145. <style lang="scss">
  146. #app {
  147. height: 100%;
  148. }
  149. .image-preview {
  150. position: fixed;
  151. inset: 0;
  152. background: rgba(0, 0, 0, 0.85);
  153. display: flex;
  154. flex-direction: column;
  155. z-index: 6000;
  156. }
  157. .image-preview__toolbar {
  158. display: flex;
  159. gap: 8px;
  160. padding: 10px;
  161. justify-content: center;
  162. z-index: 9999;
  163. }
  164. .image-preview__toolbar button {
  165. padding: 8px 12px;
  166. border: none;
  167. background: linear-gradient(180deg, #3a8bff 0%, #2f80ed 100%);
  168. color: #fff;
  169. border-radius: 10px;
  170. cursor: pointer;
  171. transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
  172. box-shadow: 0 2px 8px rgba(47, 128, 237, 0.3);
  173. }
  174. .image-preview__toolbar button:hover {
  175. transform: translateY(-1px);
  176. box-shadow: 0 6px 16px rgba(47, 128, 237, 0.35);
  177. }
  178. .image-preview__toolbar button:active {
  179. transform: translateY(0);
  180. box-shadow: 0 2px 8px rgba(47, 128, 237, 0.28);
  181. background: linear-gradient(180deg, #2f80ed 0%, #1b6dde 100%);
  182. }
  183. .image-preview__toolbar button:focus-visible {
  184. outline: 2px solid rgba(47, 128, 237, 0.6);
  185. outline-offset: 2px;
  186. }
  187. .image-preview__stage {
  188. flex: 1;
  189. display: flex;
  190. align-items: center;
  191. justify-content: center;
  192. cursor: grab;
  193. }
  194. .image-preview__stage:active {
  195. cursor: grabbing;
  196. }
  197. .image-preview__img {
  198. max-width: 92vw;
  199. max-height: 92vh;
  200. border-radius: 8px;
  201. box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  202. user-select: none;
  203. will-change: transform;
  204. }
  205. // 清空聊天记录确认弹窗样式
  206. .clear-confirm {
  207. padding-top: 4px;
  208. &__title {
  209. font-size: 16px;
  210. font-weight: 600;
  211. margin-bottom: 12px;
  212. color: #333;
  213. }
  214. &__content {
  215. font-size: 14px;
  216. color: #666;
  217. line-height: 1.6;
  218. margin-bottom: 20px;
  219. }
  220. &__footer {
  221. display: flex;
  222. justify-content: flex-end;
  223. gap: 8px;
  224. }
  225. }
  226. </style>