chartLayoutStore.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { defineStore } from 'pinia'
  2. import { ChartLayoutType, LayerModeEnum, ChartModeEnum } from './chartLayoutStore.d'
  3. import { setLocalStorage, getLocalStorage } from '@/utils'
  4. import { StorageEnum } from '@/enums/storageEnum'
  5. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  6. const chartEditStore = useChartEditStore()
  7. const { GO_CHART_LAYOUT_STORE } = StorageEnum
  8. const storageChartLayout: Partial<ChartLayoutType> = getLocalStorage(GO_CHART_LAYOUT_STORE)
  9. // 编辑区域布局和静态设置
  10. export const useChartLayoutStore = defineStore({
  11. id: 'useChartLayoutStore',
  12. state: (): ChartLayoutType => ({
  13. // 图层控制
  14. layers: true,
  15. // 图表组件
  16. charts: true,
  17. // 详情设置(收缩为true)
  18. details: false,
  19. // 组件列表展示类型(默认单列)
  20. chartType: ChartModeEnum.SINGLE,
  21. // 图层类型(默认图片)
  22. layerType: LayerModeEnum.THUMBNAIL,
  23. // 当前加载数量
  24. percentage: 0,
  25. // 防止值不存在
  26. ...storageChartLayout
  27. }),
  28. getters: {
  29. getLayers(): boolean {
  30. return this.layers
  31. },
  32. getCharts(): boolean {
  33. return this.charts
  34. },
  35. getDetails(): boolean {
  36. return this.details
  37. },
  38. getChartType(): ChartModeEnum {
  39. return this.chartType
  40. },
  41. getLayerType(): LayerModeEnum {
  42. return this.layerType
  43. },
  44. getPercentage(): number {
  45. return this.percentage
  46. }
  47. },
  48. actions: {
  49. setItem<T extends keyof ChartLayoutType, K extends ChartLayoutType[T]>(key: T, value: K): void {
  50. this.$patch(state => {
  51. state[key] = value
  52. })
  53. setLocalStorage(GO_CHART_LAYOUT_STORE, this.$state)
  54. // 重新计算拖拽区域缩放比例
  55. setTimeout(() => {
  56. chartEditStore.computedScale()
  57. }, 500)
  58. },
  59. setItemUnHandle<T extends keyof ChartLayoutType, K extends ChartLayoutType[T]>(key: T, value: K): void {
  60. this.$patch(state => {
  61. state[key] = value
  62. })
  63. }
  64. }
  65. })