index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <div class="editor-header">
  3. <div class="left">
  4. <Popover trigger="click" placement="bottom-start" v-model:value="mainMenuVisible">
  5. <template #content>
  6. <!-- <PopoverMenuItem @click="openAIPPTDialog(); mainMenuVisible = false">AI 生成 PPT</PopoverMenuItem> -->
  7. <FileInput accept="application/vnd.openxmlformats-officedocument.presentationml.presentation" @change="files => {
  8. importPPTXFile(files)
  9. mainMenuVisible = false
  10. }">
  11. <PopoverMenuItem>导入 PPTX 文件</PopoverMenuItem>
  12. </FileInput>
  13. <!-- <FileInput accept=".json" @change="files => {
  14. importJSON(files)
  15. mainMenuVisible = false
  16. }">
  17. <PopoverMenuItem>导入 JSON 文件</PopoverMenuItem>
  18. </FileInput> -->
  19. <!-- <FileInput accept=".pptist" @change="files => {
  20. importSpecificFile(files)
  21. mainMenuVisible = false
  22. }">
  23. <PopoverMenuItem>导入 pptist 文件</PopoverMenuItem>
  24. </FileInput> -->
  25. <!-- <PopoverMenuItem @click="setDialogForExport('pptx')">导出文件</PopoverMenuItem> -->
  26. <PopoverMenuItem @click="resetSlides(); mainMenuVisible = false">重置幻灯片</PopoverMenuItem>
  27. <!-- <PopoverMenuItem @click="openMarkupPanel(); mainMenuVisible = false">幻灯片类型标注</PopoverMenuItem> -->
  28. <!-- <PopoverMenuItem @click="goLink('https://github.com/pipipi-pikachu/PPTist/issues')">意见反馈</PopoverMenuItem> -->
  29. <!-- <PopoverMenuItem @click="goLink('https://github.com/pipipi-pikachu/PPTist/blob/master/doc/Q&A.md')">常见问题</PopoverMenuItem> -->
  30. <PopoverMenuItem @click="mainMenuVisible = false; hotkeyDrawerVisible = true">快捷操作</PopoverMenuItem>
  31. </template>
  32. <div class="menu-item" v-show="false"><IconHamburgerButton class="icon" /></div>
  33. </Popover>
  34. <FileInput accept="application/vnd.openxmlformats-officedocument.presentationml.presentation" @change="files => {
  35. importPPTXFile(files)
  36. }">
  37. <div class="menu-item"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>上传 PPTX 文件</div>
  38. </FileInput>
  39. <div class="title" v-show="false">
  40. <Input
  41. class="title-input"
  42. ref="titleInputRef"
  43. v-model:value="titleValue"
  44. @blur="handleUpdateTitle()"
  45. v-if="editingTitle"
  46. ></Input>
  47. <div
  48. class="title-text"
  49. @click="startEditTitle()"
  50. :title="title"
  51. v-else
  52. >{{ title }}</div>
  53. </div>
  54. </div>
  55. <div class="right">
  56. <div class="group-menu-item">
  57. <div class="menu-item" v-tooltip="'幻灯片放映(F5)'" @click="enterScreening()">
  58. <IconPpt class="icon" />
  59. </div>
  60. <Popover trigger="click" center>
  61. <template #content>
  62. <PopoverMenuItem @click="enterScreeningFromStart()">从头开始</PopoverMenuItem>
  63. <PopoverMenuItem @click="enterScreening()">从当前页开始</PopoverMenuItem>
  64. </template>
  65. <div class="arrow-btn"><IconDown class="arrow" /></div>
  66. </Popover>
  67. </div>
  68. <!-- <div class="menu-item" v-tooltip="'学生视图'" @click="enterStudentView()">
  69. <IconUser class="icon" />
  70. </div> -->
  71. <!-- <div class="menu-item" v-tooltip="'AI生成PPT'" @click="openAIPPTDialog(); mainMenuVisible = false">
  72. <span class="text ai">AI</span>
  73. </div> -->
  74. <div class="menu-item" v-tooltip="'导出'" @click="setDialogForExport('pptx')">
  75. <IconDownload class="icon" />
  76. </div>
  77. <!-- <a class="github-link" v-tooltip="'Copyright © 2020-PRESENT pipipi-pikachu'" href="https://github.com/pipipi-pikachu/PPTist" target="_blank">
  78. <div class="menu-item"><IconGithub class="icon" /></div>
  79. </a> -->
  80. </div>
  81. <Drawer
  82. :width="320"
  83. v-model:visible="hotkeyDrawerVisible"
  84. placement="right"
  85. >
  86. <HotkeyDoc />
  87. <template v-slot:title>快捷操作</template>
  88. </Drawer>
  89. <FullscreenSpin :loading="exporting" tip="正在导入..." />
  90. </div>
  91. </template>
  92. <script lang="ts" setup>
  93. import { nextTick, ref, useTemplateRef, inject } from 'vue'
  94. import { storeToRefs } from 'pinia'
  95. import { useMainStore, useSlidesStore } from '@/store'
  96. import useScreening from '@/hooks/useScreening'
  97. import useImport from '@/hooks/useImport'
  98. import useSlideHandler from '@/hooks/useSlideHandler'
  99. import type { DialogForExportTypes } from '@/types/export'
  100. import HotkeyDoc from './HotkeyDoc.vue'
  101. import FileInput from '@/components/FileInput.vue'
  102. import FullscreenSpin from '@/components/FullscreenSpin.vue'
  103. import Drawer from '@/components/Drawer.vue'
  104. import Input from '@/components/Input.vue'
  105. import Popover from '@/components/Popover.vue'
  106. import PopoverMenuItem from '@/components/PopoverMenuItem.vue'
  107. const mainStore = useMainStore()
  108. const slidesStore = useSlidesStore()
  109. const { title } = storeToRefs(slidesStore)
  110. const { enterScreening, enterScreeningFromStart } = useScreening()
  111. const { importSpecificFile, importPPTXFile, importJSON, exporting } = useImport()
  112. const { resetSlides } = useSlideHandler()
  113. const mainMenuVisible = ref(false)
  114. const hotkeyDrawerVisible = ref(false)
  115. const editingTitle = ref(false)
  116. const titleValue = ref('')
  117. const titleInputRef = useTemplateRef<InstanceType<typeof Input>>('titleInputRef')
  118. const startEditTitle = () => {
  119. titleValue.value = title.value
  120. editingTitle.value = true
  121. nextTick(() => titleInputRef.value?.focus())
  122. }
  123. const handleUpdateTitle = () => {
  124. slidesStore.setTitle(titleValue.value)
  125. editingTitle.value = false
  126. }
  127. const goLink = (url: string) => {
  128. window.open(url)
  129. mainMenuVisible.value = false
  130. }
  131. const setDialogForExport = (type: DialogForExportTypes) => {
  132. mainStore.setDialogForExport(type)
  133. mainMenuVisible.value = false
  134. }
  135. const openMarkupPanel = () => {
  136. mainStore.setMarkupPanelState(true)
  137. }
  138. const openAIPPTDialog = () => {
  139. mainStore.setAIPPTDialogState(true)
  140. }
  141. const enterStudentView = () => {
  142. // 通过路由跳转到学生模式
  143. window.location.href = '/?mode=student'
  144. }
  145. const setTitle = (newTitle: string) => {
  146. titleValue.value = newTitle
  147. slidesStore.setTitle(newTitle)
  148. }
  149. (window as any).setTitle = setTitle
  150. </script>
  151. <style lang="scss" scoped>
  152. .editor-header {
  153. background-color: #fff;
  154. user-select: none;
  155. border-bottom: 1px solid $borderColor;
  156. display: flex;
  157. justify-content: space-between;
  158. padding: 0 5px;
  159. }
  160. .left, .right {
  161. display: flex;
  162. justify-content: center;
  163. align-items: center;
  164. }
  165. .menu-item {
  166. height: 30px;
  167. display: flex;
  168. justify-content: center;
  169. align-items: center;
  170. font-size: 14px;
  171. padding: 0 10px;
  172. border-radius: $borderRadius;
  173. cursor: pointer;
  174. .icon {
  175. font-size: 18px;
  176. color: #666;
  177. }
  178. .text {
  179. width: 18px;
  180. text-align: center;
  181. font-size: 17px;
  182. }
  183. .ai {
  184. background: linear-gradient(270deg, #d897fd, #33bcfc);
  185. background-clip: text;
  186. color: transparent;
  187. font-weight: 700;
  188. }
  189. &:hover {
  190. background-color: #f1f1f1;
  191. }
  192. svg {
  193. width: 18px;
  194. margin-right: 5px;
  195. }
  196. }
  197. .group-menu-item {
  198. height: 30px;
  199. display: flex;
  200. margin: 0 8px;
  201. padding: 0 2px;
  202. border-radius: $borderRadius;
  203. &:hover {
  204. background-color: #f1f1f1;
  205. }
  206. .menu-item {
  207. padding: 0 3px;
  208. }
  209. .arrow-btn {
  210. display: flex;
  211. justify-content: center;
  212. align-items: center;
  213. cursor: pointer;
  214. }
  215. }
  216. .title {
  217. height: 30px;
  218. margin-left: 2px;
  219. font-size: 13px;
  220. .title-input {
  221. width: 200px;
  222. height: 100%;
  223. padding-left: 0;
  224. padding-right: 0;
  225. ::v-deep(input) {
  226. height: 28px;
  227. line-height: 28px;
  228. }
  229. }
  230. .title-text {
  231. min-width: 20px;
  232. max-width: 400px;
  233. line-height: 30px;
  234. padding: 0 6px;
  235. border-radius: $borderRadius;
  236. cursor: pointer;
  237. @include ellipsis-oneline();
  238. &:hover {
  239. background-color: #f1f1f1;
  240. }
  241. }
  242. }
  243. .github-link {
  244. display: inline-block;
  245. height: 30px;
  246. }
  247. </style>