main.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import { customAlphabet } from 'nanoid'
  2. import { defineStore } from 'pinia'
  3. import { ToolbarStates } from '@/types/toolbar'
  4. import type { CreatingElement, ShapeFormatPainter, TextFormatPainter } from '@/types/edit'
  5. import type { DialogForExportTypes } from '@/types/export'
  6. import { type TextAttrs, defaultRichTextAttrs } from '@/utils/prosemirror/utils'
  7. import { useSlidesStore } from './slides'
  8. export interface MainState {
  9. activeElementIdList: string[]
  10. handleElementId: string
  11. activeGroupElementId: string
  12. hiddenElementIdList: string[]
  13. canvasPercentage: number
  14. canvasScale: number
  15. canvasDragged: boolean
  16. thumbnailsFocus: boolean
  17. editorAreaFocus: boolean
  18. disableHotkeys: boolean
  19. gridLineSize: number
  20. showRuler: boolean
  21. creatingElement: CreatingElement | null
  22. creatingCustomShape: boolean
  23. toolbarState: ToolbarStates
  24. clipingImageElementId: string
  25. isScaling: boolean
  26. richTextAttrs: TextAttrs
  27. selectedTableCells: string[]
  28. selectedSlidesIndex: number[]
  29. dialogForExport: DialogForExportTypes
  30. databaseId: string
  31. textFormatPainter: TextFormatPainter | null
  32. shapeFormatPainter: ShapeFormatPainter | null
  33. showSelectPanel: boolean
  34. showSearchPanel: boolean
  35. showNotesPanel: boolean
  36. showMarkupPanel: boolean
  37. showAIPPTDialog: boolean
  38. childPageVisible: boolean
  39. childPageToolsArray: any[]
  40. childPageIndex: number
  41. userid: string
  42. courseTitle: string
  43. running: boolean
  44. }
  45. const nanoid = customAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
  46. export const databaseId = nanoid(10)
  47. export const useMainStore = defineStore('main', {
  48. state: (): MainState => ({
  49. activeElementIdList: [], // 被选中的元素ID集合,包含 handleElementId
  50. handleElementId: '', // 正在操作的元素ID
  51. activeGroupElementId: '', // 组合元素成员中,被选中可独立操作的元素ID
  52. hiddenElementIdList: [], // 被隐藏的元素ID集合
  53. canvasPercentage: 90, // 画布可视区域百分比
  54. canvasScale: 1, // 画布缩放比例(基于宽度{{slidesStore.viewportSize}}像素)
  55. canvasDragged: false, // 画布被拖拽移动
  56. thumbnailsFocus: false, // 左侧导航缩略图区域聚焦
  57. editorAreaFocus: false, // 编辑区域聚焦
  58. disableHotkeys: false, // 禁用快捷键
  59. gridLineSize: 0, // 网格线尺寸(0表示不显示网格线)
  60. showRuler: false, // 显示标尺
  61. creatingElement: null, // 正在插入的元素信息,需要通过绘制插入的元素(文字、形状、线条)
  62. creatingCustomShape: false, // 正在绘制任意多边形
  63. toolbarState: ToolbarStates.SLIDE_DESIGN, // 右侧工具栏状态
  64. clipingImageElementId: '', // 当前正在裁剪的图片ID
  65. richTextAttrs: defaultRichTextAttrs, // 富文本状态
  66. selectedTableCells: [], // 选中的表格单元格
  67. isScaling: true, // 正在进行元素缩放
  68. selectedSlidesIndex: [], // 当前被选中的页面索引集合
  69. dialogForExport: '', // 导出面板
  70. databaseId, // 标识当前应用的indexedDB数据库ID
  71. textFormatPainter: null, // 文字格式刷
  72. shapeFormatPainter: null, // 形状格式刷
  73. showSelectPanel: false, // 打开选择面板
  74. showSearchPanel: false, // 打开查找替换面板
  75. showNotesPanel: false, // 打开批注面板
  76. showMarkupPanel: false, // 打开类型标注面板
  77. showAIPPTDialog: false, // 打开AIPPT创建窗口
  78. childPageVisible: false, // 打开带选页
  79. childPageToolsArray: [], // 带选页工具数组
  80. childPageIndex: 0, // 带选页当前页面索引
  81. userid: '', // 当前用户ID
  82. courseTitle: '', // 课程标题
  83. running: false, // 是否正在运行AI任务
  84. }),
  85. getters: {
  86. activeElementList(state) {
  87. const slidesStore = useSlidesStore()
  88. const currentSlide = slidesStore.currentSlide
  89. if (!currentSlide || !currentSlide.elements) return []
  90. return currentSlide.elements.filter(element => state.activeElementIdList.includes(element.id))
  91. },
  92. handleElement(state) {
  93. const slidesStore = useSlidesStore()
  94. const currentSlide = slidesStore.currentSlide
  95. if (!currentSlide || !currentSlide.elements) return null
  96. return currentSlide.elements.find(element => state.handleElementId === element.id) || null
  97. },
  98. },
  99. actions: {
  100. setActiveElementIdList(activeElementIdList: string[]) {
  101. if (activeElementIdList.length === 1) this.handleElementId = activeElementIdList[0]
  102. else this.handleElementId = ''
  103. this.activeElementIdList = activeElementIdList
  104. },
  105. setHandleElementId(handleElementId: string) {
  106. this.handleElementId = handleElementId
  107. },
  108. setActiveGroupElementId(activeGroupElementId: string) {
  109. this.activeGroupElementId = activeGroupElementId
  110. },
  111. setHiddenElementIdList(hiddenElementIdList: string[]) {
  112. this.hiddenElementIdList = hiddenElementIdList
  113. },
  114. setCanvasPercentage(percentage: number) {
  115. this.canvasPercentage = percentage
  116. },
  117. setCanvasScale(scale: number) {
  118. this.canvasScale = scale
  119. },
  120. setCanvasDragged(isDragged: boolean) {
  121. this.canvasDragged = isDragged
  122. },
  123. setThumbnailsFocus(isFocus: boolean) {
  124. this.thumbnailsFocus = isFocus
  125. },
  126. setEditorareaFocus(isFocus: boolean) {
  127. this.editorAreaFocus = isFocus
  128. },
  129. setDisableHotkeysState(disable: boolean) {
  130. this.disableHotkeys = disable
  131. },
  132. setGridLineSize(size: number) {
  133. this.gridLineSize = size
  134. },
  135. setRulerState(show: boolean) {
  136. this.showRuler = show
  137. },
  138. setCreatingElement(element: CreatingElement | null) {
  139. this.creatingElement = element
  140. },
  141. setCreatingCustomShapeState(state: boolean) {
  142. this.creatingCustomShape = state
  143. },
  144. setToolbarState(toolbarState: ToolbarStates) {
  145. this.toolbarState = toolbarState
  146. },
  147. setClipingImageElementId(elId: string) {
  148. this.clipingImageElementId = elId
  149. },
  150. setRichtextAttrs(attrs: TextAttrs) {
  151. this.richTextAttrs = attrs
  152. },
  153. setSelectedTableCells(cells: string[]) {
  154. this.selectedTableCells = cells
  155. },
  156. setScalingState(isScaling: boolean) {
  157. this.isScaling = isScaling
  158. },
  159. updateSelectedSlidesIndex(selectedSlidesIndex: number[]) {
  160. this.selectedSlidesIndex = selectedSlidesIndex
  161. },
  162. setDialogForExport(type: DialogForExportTypes) {
  163. this.dialogForExport = type
  164. },
  165. setTextFormatPainter(textFormatPainter: TextFormatPainter | null) {
  166. this.textFormatPainter = textFormatPainter
  167. },
  168. setShapeFormatPainter(shapeFormatPainter: ShapeFormatPainter | null) {
  169. this.shapeFormatPainter = shapeFormatPainter
  170. },
  171. setSelectPanelState(show: boolean) {
  172. this.showSelectPanel = show
  173. },
  174. setSearchPanelState(show: boolean) {
  175. this.showSearchPanel = show
  176. },
  177. setNotesPanelState(show: boolean) {
  178. this.showNotesPanel = show
  179. },
  180. setMarkupPanelState(show: boolean) {
  181. this.showMarkupPanel = show
  182. },
  183. setAIPPTDialogState(show: boolean) {
  184. this.showAIPPTDialog = show
  185. },
  186. setChildPageState(show: boolean, tools: any[], pageIndex: number) {
  187. this.childPageVisible = show
  188. this.childPageToolsArray = tools
  189. this.childPageIndex = pageIndex
  190. },
  191. setUserid(userid: string) {
  192. this.userid = userid
  193. },
  194. setCourseTitle(courseTitle: string) {
  195. this.courseTitle = courseTitle
  196. },
  197. setRunningState(state: boolean) {
  198. this.running = state
  199. }
  200. },
  201. })