App.vue 6.8 KB

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