riku
2024-09-11 89ab2ec7f8790c5cc184de98682af032c69c2afc
src/stores/area.js
@@ -6,6 +6,9 @@
export const useAreaStore = defineStore('area', {
  state: () => {
    return {
      locations: {},
      sceneType: {},
      time: '',
      area: {
        provincecode: undefined,
        provincename: undefined,
@@ -28,16 +31,34 @@
      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) {
      const d = time ? dayjs(time) : dayjs()
      this.area.starttime = d.startOf('day').format('YYYY-MM-DD HH:mm:ss')
      this.area.endtime = d.endOf('day').format('YYYY-MM-DD HH:mm:ss')
      this.setTimePeriod(time, 'day')
    },
    // 设置时间为给定时间对应当月的头尾
    setTimeOneMonth(time) {
      this.setTimePeriod(time, 'month')
    },
    // 设置场景类型
    setSceneType(t) {
      this.area.scensetypeid = t
      this.sceneType = t
      this.area.scensetypeid = t.value
    }
  }
})