66 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-01-05 21:05:55 +08:00
import { defineStore } from 'pinia'
import { ChartLayoutType, ChartLayoutFilterType } from './chartLayoutStore.d'
import { setLocalStorage, getLocalStorage } from '@/utils'
2022-01-08 14:27:56 +08:00
import { StorageEnum } from '@/enums/storageEnum'
const { GO_CHART_LAYOUT_STORE } = StorageEnum
const storageChartLayout: ChartLayoutType = getLocalStorage(
2022-01-08 14:27:56 +08:00
GO_CHART_LAYOUT_STORE
)
2022-01-05 21:05:55 +08:00
export const useChartLayoutStore = defineStore({
id: 'useChartLayoutStore',
state: (): ChartLayoutType =>
storageChartLayout || {
// 图层控制
layers: true,
// 图表组件
charts: true,
// 详情设置
details: true,
// 对齐线
alignLine: true,
// 滤镜
filter: {
// 色相
hueRotate: 0,
// 饱和度
saturate: 0,
// 亮度
brightness: 100,
// 对比度
contrast: 100,
// 不透明度
2022-01-15 14:56:48 +08:00
unOpacity: 100,
},
},
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
},
getAlignLine(): boolean {
return this.alignLine
},
getFilter(): ChartLayoutFilterType {
2022-01-05 21:05:55 +08:00
return this.filter
2022-01-15 14:56:48 +08:00
},
},
actions: {
setItem(key: string, value: boolean): void {
;(this as any)[key] = value
2022-01-08 14:27:56 +08:00
setLocalStorage(GO_CHART_LAYOUT_STORE, this.$state)
},
2022-01-16 22:17:34 +08:00
setFilter<T extends keyof ChartLayoutFilterType>(key: T, value: boolean): void {
;(this.filter as any)[key] = value
2022-01-08 14:27:56 +08:00
setLocalStorage(GO_CHART_LAYOUT_STORE, this.$state)
2022-01-15 14:56:48 +08:00
},
},
2022-01-05 21:05:55 +08:00
})