| | |
| | | import { ref } from 'vue' |
| | | import { ref, unref } from 'vue' |
| | | import { defineStore } from 'pinia' |
| | | import timeUtil from '@/utils/time-util' |
| | | import { useMapStore } from '@/stores/map.js' |
| | | import taskApi from '@/api/fysp/taskApi.js' |
| | | import marks from '@/utils/map/marks.js' |
| | | import mapUtil from '@/utils/map/util.js' |
| | | import scene_1 from '@/assets/icon/scene_1.png' |
| | | |
| | | const mapStore = useMapStore() |
| | | |
| | | // 巡查任务 |
| | | export const useSubtaskStore = defineStore('subtask', () => { |
| | | // 总任务信息 |
| | | const taskInfo = ref(null) |
| | | // 当期所有巡查统计信息 |
| | | const summaryList = ref([]) |
| | | // 每日的巡查统计信息 |
| | | const summaryMap = ref(new Map()) |
| | | const subtaskLoading = ref(false) |
| | | const onFetchInfo = [] |
| | | const onFetchList = [] |
| | | const onFetchMap = [] |
| | | |
| | | function fetchTopTaskProgress(area) { |
| | | subtaskLoading.value = true |
| | | taskApi.fetchTopTaskProgress(area).then((res) => { |
| | | if (res.data.length == 0) return |
| | | const data = res.data[0] |
| | | // 存储为全局数据 |
| | | setSummary(data) |
| | | subtaskLoading.value = false |
| | | // 绘制地图标记 |
| | | marks.createLabelMarks(scene_1, unref(data.subTaskSummary), (v) => { |
| | | mapStore.focusMarker = v |
| | | }) |
| | | mapUtil.setFitView() |
| | | }) |
| | | } |
| | | |
| | | // 设置新的值 |
| | | function setSummary(data) { |
| | | summaryList.value = data |
| | | taskInfo.value = data |
| | | summaryList.value = data.subTaskSummary |
| | | summaryMap.value.clear() |
| | | data.forEach((e) => { |
| | | data.subTaskSummary.forEach((e) => { |
| | | const tag = timeUtil.formatYMD(e.subtask.planstarttime) |
| | | if (!summaryMap.value.has(tag)) { |
| | | summaryMap.value.set(tag, []) |
| | |
| | | onFetchMap.forEach((e) => { |
| | | e(summaryMap.value) |
| | | }) |
| | | } |
| | | if (onFetchInfo.length > 0) { |
| | | onFetchInfo.forEach((e) => { |
| | | e(taskInfo.value) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | function getTaskInfo(callback) { |
| | | if (taskInfo.value == null) { |
| | | onFetchInfo.push(callback) |
| | | } else { |
| | | callback(taskInfo.value) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | return { summaryList, summaryMap, subtaskLoading, setSummary, getSummaryList, getSummaryMap } |
| | | return { |
| | | // taskInfo, |
| | | // summaryList, |
| | | // summaryMap, |
| | | subtaskLoading, |
| | | fetchTopTaskProgress, |
| | | setSummary, |
| | | getTaskInfo, |
| | | getSummaryList, |
| | | getSummaryMap |
| | | } |
| | | }) |