From 9810566b1ff820cbeddae33778e7ffcd073c5d6b Mon Sep 17 00:00:00 2001 From: freshman-white <2514756131@qq.com> Date: Fri, 8 Sep 2023 15:04:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=A0=87=E6=B3=A8=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/layer.ts | 9 ++ src/pages/page-web/projects/layer.vue | 129 ++++++++++++++------------ 2 files changed, 79 insertions(+), 59 deletions(-) diff --git a/src/api/layer.ts b/src/api/layer.ts index 9501201..29ee38b 100644 --- a/src/api/layer.ts +++ b/src/api/layer.ts @@ -51,3 +51,12 @@ export const deleteLayerEleReq = async (id: string, body: {}): Promise => { const result = await request.delete(url, body) return result.data } +export const importKmlFile = async function (workspaceId: string, file: {}, id:any): Promise> { + const url = `${PREFIX}/workspaces/${workspaceId}/elements/file/upload/${id}` + const result = await request.post(url, file, { + headers: { + 'Content-Type': 'multipart/form-data', + } + }) + return result.data +} diff --git a/src/pages/page-web/projects/layer.vue b/src/pages/page-web/projects/layer.vue index 8110d5c..cecba51 100644 --- a/src/pages/page-web/projects/layer.vue +++ b/src/pages/page-web/projects/layer.vue @@ -108,15 +108,18 @@ - - + + @@ -124,14 +127,14 @@ - + @@ -150,13 +153,15 @@ import { onMounted, reactive, ref, watch } from 'vue' import { deleteElementReq, getElementGroupsReq, - updateElementsReq + updateElementsReq, + importKmlFile } from '/@/api/layer' import LayersTree from '/@/components/LayersTree.vue' import { MapDoodleColor, MapElementEnum } from '/@/constants/map' import { useGMapCover } from '/@/hooks/use-g-map-cover' import { getRoot } from '/@/root' import { useMyStore } from '/@/store' +import { ELocalStorageKey } from '/@/types' import { GeojsonCoordinate, LayerResource } from '/@/types/map' import { Color, GeoType } from '/@/types/mapLayer' import { generatePoint } from '/@/utils/genjson' @@ -369,7 +374,6 @@ async function getElementGroups (type?: string) { isDistributed: true }) mapLayers.value = result.data - console.log('lizhao2', result) mapLayers.value = updateWgs84togcj02() if (type && type === 'init') { store.dispatch('setLayerInfo', mapLayers.value) @@ -483,63 +487,57 @@ function updateCoordinates (transformType: string, element: LayerResource) { } } /** 导入文件--------------start */ +interface FileItem { + uid: string; + name?: string; + status?: string; + response?: string; + url?: string; +} +const fileModalRef = ref() +const workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId) || '' const importVisible = ref(false) -const state = reactive({ name: '', file: '' }) -const fileList = ref() -const fileTree = [ - { - label: 'Node1', - value: '0-0', - children: [ - { - label: 'Child Node1', - value: '0-0-0', - }, - ], - }, - { - label: 'Node2', - value: '0-1', - - children: [ - { - label: 'Child Node3', - value: '0-1-0', - disabled: true, - }, - { - label: 'Child Node4', - value: '0-1-1', - }, - { - label: 'Child Node5', - value: '0-1-2', - }, - ], - }, -] - +const state = reactive({ id: '', file: [] }) // 打开文件导入弹框 const openFileDialog = () => { + state.id = '' + state.file = [] importVisible.value = true } // 确认导入操作 const importSubmit = () => { - + fileModalRef.value.validate().then(() => { + state.file.forEach(async (file: any) => { + const fileData = new FormData() + fileData.append('file', file, file.name) + await importKmlFile(workspaceId, fileData, state.id).then((res:any) => { + importVisible.value = false + getElementGroups() + }) + }) + }) } -// const beforeUpload = (file:any) => { -// // fileList.value = [file] -// // } -const handleChange = (info: any) => { - let resFileList = [...info.fileList] - resFileList = resFileList.slice(-1) - resFileList = resFileList.map(file => { - if (file.response) { - file.url = file.response.url +function beforeUpload (file: FileItem) { + fileModalRef.value.validate() + state.file = [file] + return true +} +const rules = { + id: [{ required: true, message: '请选择文件夹', trigger: 'change' }], + file: [ + { + required: true, + trigger: 'change', + validator: async (rule: any, value: string) => { + if (!value.length) { + throw new Error('请上传文件') + } + }, } - return file - }) - fileList.value = resFileList + ], +} +const removeFile = () => { + state.file = [] } /** 导入文件--------------end */ @@ -569,6 +567,19 @@ const handleChange = (info: any) => { background-color:#3c3c3c !important; border:none !important; } + ::v-deep{ + .ant-upload-list-item-name{ + color:#fff; + } + .anticon-paper-clip,.ant-upload-list-item-card-actions .anticon{ + color: #fff; + } + .ant-upload-list-item-info{ + &:hover{ + background: #1c1c1c; + } + } + } } .img-icon{ cursor: pointer;