// 区域筛选的逻辑管理 import { defineStore } from 'pinia' import dayjs from 'dayjs' export const useAreaStore = defineStore('area', { state: () => { return { locations: {}, sceneType: {}, time: '', area: { provincecode: undefined, provincename: undefined, citycode: undefined, cityname: undefined, districtcode: undefined, districtname: undefined, starttime: undefined, endtime: undefined, scensetypeid: undefined } } }, actions: { // 设置行政区划信息 setLocation(location) { this.area.provincecode = location.pCode this.area.provincename = location.pName this.area.citycode = location.cCode this.area.cityname = location.cName this.area.districtcode = location.dCode this.area.districtname = location.dName this.locations = { pCode: location.pCode, pName: location.pName, cCode: location.cCode, cName: location.cName, dCode: location.dCode, dName: location.dName } }, setTimePeriod(time, type) { this.time = time ? time : new Date() const d = dayjs(this.time) this.area.starttime = d.startOf(type).format('YYYY-MM-DD HH:mm:ss') this.area.endtime = d.endOf(type).format('YYYY-MM-DD HH:mm:ss') }, // 设置时间为给定时间对应当日的头尾 setTimeOneDay(time) { this.setTimePeriod(time, 'day') }, // 设置时间为给定时间对应当月的头尾 setTimeOneMonth(time) { this.setTimePeriod(time, 'month') }, // 设置场景类型 setSceneType(t) { this.sceneType = t this.area.scensetypeid = t.value } } })