chartLayoutStore.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { defineStore } from 'pinia'
  2. import { ChartLayoutType } from './chartLayoutStore.d'
  3. import { setLocalStorage, getLocalStorage } from '@/utils'
  4. import { StorageEnum } from '@/enums/storageEnum'
  5. import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
  6. const chartEditStore = useChartEditStoreStore()
  7. const { GO_CHART_LAYOUT_STORE } = StorageEnum
  8. const storageChartLayout: ChartLayoutType = getLocalStorage( GO_CHART_LAYOUT_STORE)
  9. // 编辑区域布局和静态设置
  10. export const useChartLayoutStore = defineStore({
  11. id: 'useChartLayoutStore',
  12. state: (): ChartLayoutType =>
  13. storageChartLayout || {
  14. // 图层控制
  15. layers: true,
  16. // 图表组件
  17. charts: true,
  18. // 详情设置
  19. details: true,
  20. // 对齐线
  21. alignLine: true,
  22. },
  23. getters: {
  24. getLayers(): boolean {
  25. return this.layers
  26. },
  27. getCharts(): boolean {
  28. return this.charts
  29. },
  30. getDetails(): boolean {
  31. return this.details
  32. },
  33. getAlignLine(): boolean {
  34. return this.alignLine
  35. }
  36. },
  37. actions: {
  38. setItem(key: string, value: boolean): void {
  39. ;(this as any)[key] = value
  40. setLocalStorage(GO_CHART_LAYOUT_STORE, this.$state)
  41. // 重新计算拖拽区域缩放比例
  42. setTimeout(() => {
  43. chartEditStore.computedScale()
  44. }, 500)
  45. }
  46. }
  47. })