2022-01-05 21:05:55 +08:00
|
|
|
|
import { defineStore } from 'pinia'
|
2022-10-01 21:10:06 +08:00
|
|
|
|
import { ChartLayoutType, LayerModeEnum } from './chartLayoutStore.d'
|
2022-01-07 22:02:13 +08:00
|
|
|
|
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
|
2022-01-07 22:02:13 +08:00
|
|
|
|
|
2022-04-09 16:40:57 +08:00
|
|
|
|
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',
|
2022-01-07 22:02:13 +08:00
|
|
|
|
state: (): ChartLayoutType =>
|
|
|
|
|
storageChartLayout || {
|
|
|
|
|
// 图层控制
|
|
|
|
|
layers: true,
|
|
|
|
|
// 图表组件
|
|
|
|
|
charts: true,
|
2022-05-09 09:58:27 +08:00
|
|
|
|
// 详情设置(收缩为true)
|
2022-10-01 21:10:06 +08:00
|
|
|
|
details: false,
|
|
|
|
|
// 图层类型(默认图片)
|
|
|
|
|
layerType: LayerModeEnum.THUMBNAIL
|
2022-01-07 22:02:13 +08:00
|
|
|
|
},
|
2022-01-05 21:05:55 +08:00
|
|
|
|
getters: {
|
2022-01-07 22:02:13 +08:00
|
|
|
|
getLayers(): boolean {
|
2022-01-05 21:05:55 +08:00
|
|
|
|
return this.layers
|
|
|
|
|
},
|
|
|
|
|
getCharts(): boolean {
|
|
|
|
|
return this.charts
|
|
|
|
|
},
|
|
|
|
|
getDetails(): boolean {
|
|
|
|
|
return this.details
|
2022-10-01 21:10:06 +08:00
|
|
|
|
},
|
|
|
|
|
getLayerType(): LayerModeEnum {
|
|
|
|
|
return this.layerType
|
2022-01-20 21:25:35 +08:00
|
|
|
|
}
|
2022-01-07 22:02:13 +08:00
|
|
|
|
},
|
|
|
|
|
actions: {
|
2022-03-05 22:11:25 +08:00
|
|
|
|
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
|
|
|
|
})
|