Files
admin-sjzx/src/stores/monitoringPoint.ts
2024-02-29 10:31:32 +08:00

36 lines
954 B
TypeScript

import { reactive } from 'vue'
import { defineStore } from 'pinia'
interface MonitoringPoint {
lineId: string
lineName: string
lineIds: string[]
showCheckBox: boolean
}
export const useMonitoringPoint = defineStore(
'monitoringPoint',
() => {
const state: MonitoringPoint = reactive({
lineId: '',
lineName: '',
lineIds: [],
showCheckBox: false
})
const setValue = (key: keyof Pick<MonitoringPoint, 'lineId' | 'lineName' | 'lineIds'>, val: any) => {
state[key] = val
}
const setShowCheckBox = (val: boolean) => {
if (val && state.lineIds.length === 0) {
state.lineIds = [state.lineId]
}
state.showCheckBox = val
}
return { state, setValue, setShowCheckBox }
},
{
persist: {
paths: ['state.lineId', 'state.lineName']
}
}
)