桩点支架分批次上传
This commit is contained in:
@ -89,6 +89,7 @@ import * as turf from '@turf/turf';
|
||||
import { FeatureCollection } from 'geojson';
|
||||
import { TreeInstance } from 'element-plus';
|
||||
import { addProjectFacilities, addProjectPilePoint, addProjectSquare, listDXFProject, addInverter, addBoxTransformer } from '@/api/project/project';
|
||||
import { BatchUploader } from '@/utils/batchUpload';
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
|
||||
const props = defineProps({
|
||||
@ -322,8 +323,8 @@ const handleMenuItemClick = (option: string) => {
|
||||
if (selectLayer.value.some((item) => item.location.name === contextMenu.value.name)) {
|
||||
return proxy?.$modal.msgError('已选择该图层,请勿重复选择');
|
||||
}
|
||||
if (selectLayer.value.some((item) => item.option !== '名称')) {
|
||||
if (option !== '名称') return proxy?.$modal.msgError('只能选择一个类型');
|
||||
if (selectLayer.value.some((item) => item.option !== '名称' && item.option !== '箱变')) {
|
||||
if (option !== '名称' && option !== '箱变') return proxy?.$modal.msgError('只能选择一个类型');
|
||||
}
|
||||
selectLayer.value.push({ location: contextMenu.value, option });
|
||||
console.log('selectLayer.value', selectLayer.value);
|
||||
@ -365,63 +366,6 @@ const onUnmounted = () => {
|
||||
window.removeEventListener('click', closeMenuOnClickOutside);
|
||||
};
|
||||
|
||||
// const addFacilities = async () => {
|
||||
// console.log(layerType.value);
|
||||
|
||||
// if (!layerType.value) {
|
||||
// return proxy?.$modal.msgError('请选择图层类型');
|
||||
// }
|
||||
// if (!selectLayer.value.length) {
|
||||
// return proxy?.$modal.msgError('请选择需要上传的图层');
|
||||
// }
|
||||
// const data = {
|
||||
// projectId: props.projectId,
|
||||
// nameGeoJson: null,
|
||||
// locationGeoJson: null,
|
||||
// pointGeoJson: null
|
||||
// };
|
||||
|
||||
// if (layerType.value == 1) {
|
||||
// if (!checkOptions(selectLayer.value, '光伏板')) {
|
||||
// return proxy?.$modal.msgError('请选择名称和光伏板');
|
||||
// }
|
||||
// loading.value = true;
|
||||
// if (selectLayer.value[0].option == '名称') {
|
||||
// data.nameGeoJson = treeData.value[selectLayer.value[0].location.index];
|
||||
// data.locationGeoJson = treeData.value[selectLayer.value[1].location.index];
|
||||
// } else {
|
||||
// data.nameGeoJson = treeData.value[selectLayer.value[1].location.index];
|
||||
// data.locationGeoJson = treeData.value[selectLayer.value[0].location.index];
|
||||
// }
|
||||
|
||||
// await addProjectFacilities(data);
|
||||
// await proxy?.$modal.msgSuccess('添加成功');
|
||||
// } else if (layerType.value == 2) {
|
||||
// if (selectLayer.value.length > 1) return proxy?.$modal.msgError('最多选择一个桩点/支架');
|
||||
// if (selectLayer.value[0].option != '桩点/支架') return proxy?.$modal.msgError('请选择类型为桩点/支架');
|
||||
// loading.value = true;
|
||||
// data.pointGeoJson = treeData.value[selectLayer.value[0].location.index];
|
||||
// await addProjectPilePoint(data);
|
||||
// await proxy?.$modal.msgSuccess('添加成功');
|
||||
// } else if (layerType.value == 3) {
|
||||
// if (!checkOptions(selectLayer.value, '方阵')) {
|
||||
// return proxy?.$modal.msgError('请选择名称和方阵');
|
||||
// }
|
||||
// loading.value = true;
|
||||
// if (selectLayer.value[0].option == '名称') {
|
||||
// data.nameGeoJson = treeData.value[selectLayer.value[0].location.index];
|
||||
// data.locationGeoJson = treeData.value[selectLayer.value[1].location.index];
|
||||
// } else {
|
||||
// data.nameGeoJson = treeData.value[selectLayer.value[1].location.index];
|
||||
// data.locationGeoJson = treeData.value[selectLayer.value[0].location.index];
|
||||
// }
|
||||
|
||||
// await addProjectSquare(data);
|
||||
// await proxy?.$modal.msgSuccess('添加成功');
|
||||
// }
|
||||
// reset();
|
||||
// loading.value = false;
|
||||
// };
|
||||
type LayerConfig = {
|
||||
optionB: string;
|
||||
apiFunc: (data: any) => Promise<any>;
|
||||
@ -439,7 +383,7 @@ const showSuccess = (msg: string) => proxy?.$modal.msgSuccess(msg);
|
||||
|
||||
const getGeoJsonData = (nameOption = '名称', secondOption: string): { nameGeoJson: any[]; locationGeoJson: any | null } | null => {
|
||||
const nameLayers = selectLayer.value.filter((item) => item.option === nameOption);
|
||||
const secondLayer = selectLayer.value.find((item) => item.option === secondOption);
|
||||
const secondLayer = selectLayer.value.filter((item) => item.option === secondOption);
|
||||
|
||||
if (!nameLayers.length || !secondLayer) {
|
||||
showError(`请选择${nameOption}和${secondOption}`);
|
||||
@ -447,7 +391,7 @@ const getGeoJsonData = (nameOption = '名称', secondOption: string): { nameGeoJ
|
||||
}
|
||||
|
||||
const nameGeoJson = nameLayers.map((item) => treeData.value[item.location.index]);
|
||||
const locationGeoJson = treeData.value[secondLayer.location.index];
|
||||
const locationGeoJson = secondLayer.map((item) => treeData.value[item.location.index]);
|
||||
|
||||
return { nameGeoJson, locationGeoJson };
|
||||
};
|
||||
@ -472,16 +416,35 @@ const handlePointUpload = async () => {
|
||||
if (selectLayer.value.length > 1) return showError('最多选择一个桩点/支架');
|
||||
if (selectLayer.value[0].option !== '桩点/支架') return showError('请选择类型为桩点/支架');
|
||||
|
||||
const data = {
|
||||
projectId: props.projectId,
|
||||
nameGeoJson: null,
|
||||
locationGeoJson: null,
|
||||
pointGeoJson: treeData.value[selectLayer.value[0].location.index]
|
||||
};
|
||||
const features = treeData.value[selectLayer.value[0].location.index]?.features || [];
|
||||
if (!features.length) return showError('桩点数据为空');
|
||||
|
||||
loading.value = true;
|
||||
await addProjectPilePoint(data);
|
||||
await showSuccess('添加成功');
|
||||
const sessionId = new Date().getTime().toString(36) + Math.random().toString(36).substring(2, 15);
|
||||
const uploader = new BatchUploader({
|
||||
dataList: features,
|
||||
chunkSize: 15000,
|
||||
delay: 200,
|
||||
uploadFunc: async (chunk, batchNum, totalBatch) => {
|
||||
await addProjectPilePoint({
|
||||
projectId: props.projectId,
|
||||
locationGeoJson: {
|
||||
type: 'FeatureCollection',
|
||||
features: chunk
|
||||
},
|
||||
sessionId,
|
||||
totalBatch,
|
||||
batchNum
|
||||
});
|
||||
},
|
||||
onComplete: () => {
|
||||
showSuccess('桩点上传完成');
|
||||
reset();
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
await uploader.start();
|
||||
};
|
||||
|
||||
const addFacilities = async () => {
|
||||
@ -512,21 +475,6 @@ const reset = () => {
|
||||
}
|
||||
layerType.value = null;
|
||||
};
|
||||
//校验
|
||||
function checkOptions(arr, type) {
|
||||
let hasName = false;
|
||||
let hasJson = false;
|
||||
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (arr[i].option === '名称') {
|
||||
hasName = true;
|
||||
} else if (arr[i].option === type) {
|
||||
hasJson = true;
|
||||
}
|
||||
}
|
||||
|
||||
return hasName && hasJson;
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.designId,
|
||||
|
Reference in New Issue
Block a user