| | |
| | | import { defineStore } from 'pinia'; |
| | | import mapGrid from '@/components/map/mapGrid'; |
| | | import baseMapUtil from '@/components/map/baseMapUtil'; |
| | | import gridInfoApi from '@/api/grid/gridInfoApi'; |
| | | import { parseToGridInfo } from '@/model/gridRecord'; |
| | | |
| | | export const useGridStore = defineStore('grid', () => { |
| | | // 当前加载的网格数据集合 |
| | | const gridList = ref([]); |
| | | // 当前是否有选中方案 |
| | | const hasScheme = ref(false); |
| | | // 当前选中操作的网格信息 |
| | | const selectedGrid = ref({}); |
| | | const selectedGrid = ref(); |
| | | // 当前选中操作的网格是否处于可编辑状态 |
| | | const isEdit = ref(false); |
| | | // 记录当前网格路径信息 |
| | | var selectedPath = undefined; |
| | | |
| | | /** |
| | | * 检查当前是否有选中的网格 |
| | | * @returns {Boolean} |
| | | */ |
| | | function _checkGridExist() { |
| | | return selectedGrid.value.gId != undefined; |
| | | return selectedGrid.value && selectedGrid.value.id != undefined; |
| | | } |
| | | |
| | | /**数据增删**************************************************************/ |
| | |
| | | function setGrid(index) { |
| | | if (index >= 0 && index < gridList.value.length) { |
| | | selectedGrid.value = gridList.value[index]; |
| | | selectedPath = selectedGrid.value.overlays.getPath().join(';'); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 取消选中 |
| | | */ |
| | | function clearSelect() { |
| | | selectedGrid.value = undefined; |
| | | selectedPath = undefined; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | function setGridList(list) { |
| | | gridList.value = list; |
| | | hasScheme.value = true; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | function saveSelectedGrid() { |
| | | if (!_checkGridExist()) return; |
| | | selectedGrid.value.gSide = selectedGrid.value.overlays.getPath(); |
| | | const newPath = selectedGrid.value.overlays.getPath().join(';'); |
| | | if (selectedPath != newPath) { |
| | | const _data = parseToGridInfo(selectedGrid.value); |
| | | return gridInfoApi.updateGrid(_data).then(() => { |
| | | selectedGrid.value.sides = |
| | | selectedGrid.value.overlays.getPath(); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | if (!_checkGridExist()) return; |
| | | baseMapUtil.removeView(selectedGrid.value.overlays); |
| | | selectedGrid.value.overlays = mapGrid.drawPolygon( |
| | | selectedGrid.value.gSide |
| | | selectedGrid.value.sides |
| | | ); |
| | | } |
| | | |
| | |
| | | showGrid(i); |
| | | grids.push(l.overlays); |
| | | }); |
| | | baseMapUtil.setFitView(grids, 1); |
| | | baseMapUtil.setFitView(...grids); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (item.overlays) { |
| | | baseMapUtil.setFitView(item.overlays); |
| | | } else { |
| | | item.overlays = mapGrid.drawPolygon(item.gSide); |
| | | item.overlays = mapGrid.drawPolygon(item.sides); |
| | | } |
| | | } |
| | | |
| | | return { |
| | | hasScheme, |
| | | gridList, |
| | | selectedGrid, |
| | | isEdit, |
| | | setGrid, |
| | | clearSelect, |
| | | setGridList, |
| | | addGrid, |
| | | deleteGrid, |