perf: 地理信息上传地图文件验证

This commit is contained in:
fit2cloud-chenyw 2023-12-06 11:41:01 +08:00
parent a245a8008e
commit 54c8831dfc
3 changed files with 28 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package io.dataease.map.manage; package io.dataease.map.manage;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.dataease.api.map.dto.GeometryNodeCreator; import io.dataease.api.map.dto.GeometryNodeCreator;
import io.dataease.api.map.vo.AreaNode; import io.dataease.api.map.vo.AreaNode;
@ -110,6 +111,13 @@ public class MapManage {
@CacheEvict(cacheNames = WORLD_MAP_CACHE, key = "'world_map'") @CacheEvict(cacheNames = WORLD_MAP_CACHE, key = "'world_map'")
@Transactional @Transactional
public void saveMapGeo(GeometryNodeCreator request, MultipartFile file) { public void saveMapGeo(GeometryNodeCreator request, MultipartFile file) {
if (ObjectUtils.isEmpty(file) || file.isEmpty()) {
DEException.throwException("geometry file is require");
}
String suffix = FileUtil.getSuffix(file.getOriginalFilename());
if (!StringUtils.equalsIgnoreCase("json", suffix)) {
DEException.throwException("仅支持json格式文件");
}
List<Area> areas = proxy().defaultArea(); List<Area> areas = proxy().defaultArea();
String code = getBusiGeoCode(request.getCode()); String code = getBusiGeoCode(request.getCode());

View File

@ -17,12 +17,12 @@ const dialogVisible = ref(false)
const loadingInstance = ref(null) const loadingInstance = ref(null)
const geoForm = ref<FormInstance>() const geoForm = ref<FormInstance>()
const geoFile = ref() const geoFile = ref()
const fileName = ref()
const state = reactive({ const state = reactive({
form: reactive<GeometryFrom>({ form: reactive<GeometryFrom>({
pid: null, pid: null,
code: null, code: null,
name: null name: null,
fileName: null
}), }),
treeData: [] treeData: []
}) })
@ -53,6 +53,13 @@ const rule = reactive<FormRules>({
message: t('common.require'), message: t('common.require'),
trigger: 'blur' trigger: 'blur'
} }
],
fileName: [
{
required: true,
message: t('common.require'),
trigger: 'blur'
}
] ]
}) })
@ -63,7 +70,7 @@ const edit = (pid?: string) => {
state.form.code = null state.form.code = null
state.form.name = null state.form.name = null
geoFile.value = null geoFile.value = null
fileName.value = null state.form.fileName = null
dialogVisible.value = true dialogVisible.value = true
} }
@ -71,7 +78,7 @@ const emits = defineEmits(['saved'])
const submitForm = async (formEl: FormInstance | undefined) => { const submitForm = async (formEl: FormInstance | undefined) => {
if (!formEl) return if (!formEl) return
await formEl.validate((valid, fields) => { await formEl.validate(valid => {
if (valid) { if (valid) {
const param = { ...state.form } const param = { ...state.form }
const formData = buildFormData(geoFile.value, param) const formData = buildFormData(geoFile.value, param)
@ -96,7 +103,6 @@ const submitForm = async (formEl: FormInstance | undefined) => {
const resetForm = (formEl: FormInstance | undefined) => { const resetForm = (formEl: FormInstance | undefined) => {
if (!formEl) return if (!formEl) return
geoFile.value = null geoFile.value = null
fileName.value = null
formEl.resetFields() formEl.resetFields()
dialogVisible.value = false dialogVisible.value = false
} }
@ -119,7 +125,7 @@ const handleError = () => {
} }
const setFile = (options: UploadRequestOptions) => { const setFile = (options: UploadRequestOptions) => {
geoFile.value = options.file geoFile.value = options.file
fileName.value = options.file.name state.form.fileName = options.file.name
} }
const uploadValidate = file => { const uploadValidate = file => {
const suffix = file.name.substring(file.name.lastIndexOf('.') + 1) const suffix = file.name.substring(file.name.lastIndexOf('.') + 1)
@ -185,7 +191,7 @@ defineExpose({
</el-form-item> </el-form-item>
<div class="geo-label-mask" /> <div class="geo-label-mask" />
<el-form-item label="坐标文件"> <el-form-item label="坐标文件" prop="fileName">
<el-upload <el-upload
class="upload-geo" class="upload-geo"
action="" action=""
@ -196,14 +202,18 @@ defineExpose({
:show-file-list="false" :show-file-list="false"
:http-request="setFile" :http-request="setFile"
> >
<el-input :placeholder="t('userimport.placeholder')" readonly v-model="fileName"> <el-input
:placeholder="t('userimport.placeholder')"
readonly
v-model="state.form.fileName"
>
<template #suffix> <template #suffix>
<el-icon> <el-icon>
<Icon name="icon_upload_outlined" /> <Icon name="icon_upload_outlined" />
</el-icon> </el-icon>
</template> </template>
<template #prefix> <template #prefix>
<el-icon v-if="!!fileName"> <el-icon v-if="!!state.form.fileName">
<Icon name="de-json" /> <Icon name="de-json" />
</el-icon> </el-icon>
</template> </template>

View File

@ -2,4 +2,5 @@ export interface GeometryFrom {
pid?: string pid?: string
code?: string code?: string
name?: string name?: string
fileName?: string
} }