59 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-01-05 21:05:55 +08:00
import { defineStore } from 'pinia'
2022-11-13 21:28:38 +08:00
import { ChartLayoutType, LayerModeEnum, ChartModeEnum } from './chartLayoutStore.d'
import { setLocalStorage, getLocalStorage } from '@/utils'
2022-01-08 14:27:56 +08:00
import { StorageEnum } from '@/enums/storageEnum'
2022-03-04 20:57:36 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
2022-01-20 21:25:35 +08:00
2022-03-04 20:57:36 +08:00
const chartEditStore = useChartEditStore()
2022-01-08 14:27:56 +08:00
const { GO_CHART_LAYOUT_STORE } = StorageEnum
const storageChartLayout: ChartLayoutType = getLocalStorage(GO_CHART_LAYOUT_STORE)
2022-01-05 21:05:55 +08:00
2022-01-20 21:25:35 +08:00
// 编辑区域布局和静态设置
2022-01-05 21:05:55 +08:00
export const useChartLayoutStore = defineStore({
id: 'useChartLayoutStore',
state: (): ChartLayoutType =>
storageChartLayout || {
// 图层控制
layers: true,
// 图表组件
charts: true,
// 详情设置收缩为true
details: false,
2022-11-13 21:28:38 +08:00
// 组件列表展示类型(默认单列)
chartType: ChartModeEnum.SINGLE,
// 图层类型(默认图片)
layerType: LayerModeEnum.THUMBNAIL
},
2022-01-05 21:05:55 +08:00
getters: {
getLayers(): boolean {
2022-01-05 21:05:55 +08:00
return this.layers
},
getCharts(): boolean {
return this.charts
},
getDetails(): boolean {
return this.details
},
2022-11-13 21:28:38 +08:00
getChartType(): ChartModeEnum {
return this.chartType
},
getLayerType(): LayerModeEnum {
return this.layerType
2022-01-20 21:25:35 +08:00
}
},
actions: {
setItem<T extends keyof ChartLayoutType, K extends ChartLayoutType[T]>(key: T, value: K): void {
this.$patch(state => {
state[key]= value
});
2022-01-08 14:27:56 +08:00
setLocalStorage(GO_CHART_LAYOUT_STORE, this.$state)
2022-01-20 21:25:35 +08:00
// 重新计算拖拽区域缩放比例
setTimeout(() => {
chartEditStore.computedScale()
}, 500)
}
}
2022-01-05 21:05:55 +08:00
})