From 392109d3490a7e7fb76c0bc114bd61e503b5db2b Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Thu, 16 Mar 2023 17:48:49 +0800 Subject: [PATCH 01/25] =?UTF-8?q?fix(=E8=A7=86=E5=9B=BE-=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=A0=86=E5=8F=A0=E6=9F=B1=E7=8A=B6=E5=9B=BE):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=88=86=E7=BB=84=E5=A0=86=E5=8F=A0=E6=9F=B1=E7=8A=B6?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E7=AD=BE=E5=86=85=E5=AE=B9=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E5=8D=95=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/chart/chart/bar/bar_antv.js | 2 +- frontend/src/views/chart/chart/util.js | 10 ----- .../shapeAttr/LabelSelectorAntV.vue | 38 +++++++++---------- frontend/src/views/chart/group/Group.vue | 24 +++++------- frontend/src/views/chart/view/ChartEdit.vue | 22 ++++------- 5 files changed, 38 insertions(+), 58 deletions(-) diff --git a/frontend/src/views/chart/chart/bar/bar_antv.js b/frontend/src/views/chart/chart/bar/bar_antv.js index 76c8121c05..3cb4b0d193 100644 --- a/frontend/src/views/chart/chart/bar/bar_antv.js +++ b/frontend/src/views/chart/chart/bar/bar_antv.js @@ -114,7 +114,7 @@ export function baseBarOptionAntV(plot, container, chart, action, isGroup, isSta if (chart.senior) { let emptyDataStrategy = JSON.parse(chart.senior)?.functionCfg?.emptyDataStrategy if (!emptyDataStrategy) { - emptyDataStrategy = 'breakLine' + emptyDataStrategy = 'ignoreData' } handleEmptyDataStrategy(emptyDataStrategy, chart, data, options) } diff --git a/frontend/src/views/chart/chart/util.js b/frontend/src/views/chart/chart/util.js index af5e81d5ff..c214e7eed3 100644 --- a/frontend/src/views/chart/chart/util.js +++ b/frontend/src/views/chart/chart/util.js @@ -3554,13 +3554,3 @@ export function resetRgbOpacity(sourceColor, times) { } return sourceColor } - -export function getDefaultLabelContent(chart) { - if (chart?.type?.includes('pie')) { - return ['dimension', 'proportion'] - } - if (chart?.type?.includes('bar')) { - return ['quota'] - } - return [] -} diff --git a/frontend/src/views/chart/components/shapeAttr/LabelSelectorAntV.vue b/frontend/src/views/chart/components/shapeAttr/LabelSelectorAntV.vue index ba980c4edb..b204c3a6d6 100644 --- a/frontend/src/views/chart/components/shapeAttr/LabelSelectorAntV.vue +++ b/frontend/src/views/chart/components/shapeAttr/LabelSelectorAntV.vue @@ -317,6 +317,25 @@ export default { ] } }, + computed: { + labelContentOptions() { + if (this.chart.type.includes('pie')) { + return [ + { name: this.$t('chart.dimension'), value: 'dimension' }, + { name: this.$t('chart.quota'), value: 'quota' }, + { name: this.$t('chart.proportion'), value: 'proportion' } + ] + } + if (this.chart.type.includes('bar')) { + return [ + { name: this.$t('chart.chart_group'), value: 'group' }, + { name: this.$t('chart.stack_item'), value: 'stack' }, + { name: this.$t('chart.quota'), value: 'quota' } + ] + } + return [] + } + }, watch: { 'chart': { handler: function() { @@ -398,25 +417,6 @@ export default { showProperty(property) { return this.propertyInner.includes(property) } - }, - computed: { - labelContentOptions() { - if (this.chart.type.includes('pie')) { - return [ - { name: this.$t('chart.dimension'), value: 'dimension' }, - { name: this.$t('chart.quota'), value: 'quota' }, - { name: this.$t('chart.proportion'), value: 'proportion' } - ] - } - if (this.chart.type.includes('bar')) { - return [ - { name: this.$t('chart.chart_group'), value: 'group' }, - { name: this.$t('chart.stack_item'), value: 'stack' }, - { name: this.$t('chart.quota'), value: 'quota' } - ] - } - return [] - } } } diff --git a/frontend/src/views/chart/group/Group.vue b/frontend/src/views/chart/group/Group.vue index 6482f85092..7f5609dfa0 100644 --- a/frontend/src/views/chart/group/Group.vue +++ b/frontend/src/views/chart/group/Group.vue @@ -513,7 +513,6 @@ import { } from '../chart/chart' import { checkViewTitle } from '@/components/canvas/utils/utils' import { adaptCurTheme } from '@/components/canvas/utils/style' -import { getDefaultLabelContent } from '@/views/chart/chart/util' export default { name: 'Group', @@ -1045,6 +1044,11 @@ export default { setChartDefaultOptions(view) { const type = view.type const attr = JSON.parse(view.customAttr) + if (view.render === 'echarts') { + attr.label.position = 'inside' + } else { + attr.label.position = 'middle' + } if (type.includes('pie')) { if (view.render === 'echarts') { attr.label.position = 'inside' @@ -1061,21 +1065,13 @@ export default { if (type === 'pie-donut-rose') { attr.size.pieInnerRadius = Math.round(attr.size.pieOuterRadius * 0.5) } - attr.label.labelContent = getDefaultLabelContent(view) + } else if (type.includes('bar')) { + attr.label.labelContent = ['quota'] + const senior = JSON.parse(view.senior) + senior.functionCfg.emptyDataStrategy = 'ignoreData' + view.senior = JSON.stringify(senior) } else if (type.includes('line')) { attr.label.position = 'top' - } else if (type.includes('treemap')) { - if (view.render === 'echarts') { - attr.label.position = 'inside' - } else { - attr.label.position = 'middle' - } - } else { - if (view.render === 'echarts') { - attr.label.position = 'inside' - } else { - attr.label.position = 'middle' - } } view.customAttr = JSON.stringify(attr) }, diff --git a/frontend/src/views/chart/view/ChartEdit.vue b/frontend/src/views/chart/view/ChartEdit.vue index 5319f4ba77..fdb8f96c1e 100644 --- a/frontend/src/views/chart/view/ChartEdit.vue +++ b/frontend/src/views/chart/view/ChartEdit.vue @@ -1748,7 +1748,6 @@ import CalcChartFieldEdit from '@/views/chart/view/CalcChartFieldEdit' import { equalsAny } from '@/utils/StringUtils' import PositionAdjust from '@/views/chart/view/PositionAdjust' import MarkMapDataEditor from '@/views/chart/components/map/MarkMapDataEditor' -import { getDefaultLabelContent } from '@/views/chart/chart/util' export default { name: 'ChartEdit', @@ -3282,6 +3281,11 @@ export default { const type = this.view.type const customAttr = this.view.customAttr const customStyle = this.view.customStyle + if (this.view.render === 'echarts') { + this.view.customAttr.label.position = 'inside' + } else { + this.view.customAttr.label.position = 'middle' + } if (type.includes('pie')) { if (this.view.render === 'echarts') { customAttr.label.position = 'inside' @@ -3299,22 +3303,12 @@ export default { if (equalsAny(type, 'pie', 'pie-rose')) { customAttr.size.pieInnerRadius = 0 } + } else if (type.includes('bar')) { + this.view.customAttr.label.labelContent = ['quota'] + this.view.senior.functionCfg.emptyDataStrategy = 'ignoreData' } else if (type.includes('line')) { this.view.customAttr.label.position = 'top' - } else if (type.includes('treemap')) { - if (this.view.render === 'echarts') { - this.view.customAttr.label.position = 'inside' - } else { - this.view.customAttr.label.position = 'middle' - } - } else { - if (this.view.render === 'echarts') { - this.view.customAttr.label.position = 'inside' - } else { - this.view.customAttr.label.position = 'middle' - } } - customAttr.label.labelContent = getDefaultLabelContent(this.view) // reset custom colors this.view.customAttr.color.seriesColors = [] }, From 09dd31c9f9fa13b64da406e97864ca9daeb4efc9 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Fri, 17 Mar 2023 11:57:50 +0800 Subject: [PATCH 02/25] =?UTF-8?q?fix:=20sql=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=97=B6=EF=BC=8C=E5=8F=98=E9=87=8F=E7=94=9F?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/dataease/service/dataset/DataSetTableService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index aab9f1367e..dfe4da5860 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -1069,8 +1069,7 @@ public class DataSetTableService { defaultsSqlVariableDetail.getDefaultValueScope().equals(SqlVariableDetails.DefaultValueScope.ALLSCOPE) && StringUtils.isNotEmpty(defaultsSqlVariableDetail.getDefaultValue())) { sql = sql.replace(matcher.group(), defaultsSqlVariableDetail.getDefaultValue()); } - if (isEdit && defaultsSqlVariableDetail != null && defaultsSqlVariableDetail.getDefaultValueScope() != null && - defaultsSqlVariableDetail.getDefaultValueScope().equals(SqlVariableDetails.DefaultValueScope.EDIT) && StringUtils.isNotEmpty(defaultsSqlVariableDetail.getDefaultValue())) { + if (isEdit && defaultsSqlVariableDetail != null && StringUtils.isNotEmpty(defaultsSqlVariableDetail.getDefaultValue())){ sql = sql.replace(matcher.group(), defaultsSqlVariableDetail.getDefaultValue()); } } @@ -1266,10 +1265,12 @@ public class DataSetTableService { sql = handleVariableDefaultValue(sql, dataSetTableRequest.getSqlVariableDetails(), ds.getType(), true); + System.out.println(sql); if (StringUtils.isEmpty(sql)) { DataEaseException.throwException(Translator.get("i18n_sql_not_empty")); } checkVariable(sql, ds.getType()); + System.out.println(sql); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); String sqlAsTable = qp.createSQLPreview(sql, null); datasourceRequest.setQuery(sqlAsTable); From 5a327e779a11792622f69e8b9806facadc7623bd Mon Sep 17 00:00:00 2001 From: junjun Date: Fri, 17 Mar 2023 16:26:28 +0800 Subject: [PATCH 03/25] =?UTF-8?q?fix(=E6=95=B0=E6=8D=AE=E9=9B=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B3=E8=81=94=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E4=B8=8D=E9=80=89=E5=AD=97=E6=AE=B5=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index dfe4da5860..c902bb2a75 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -1058,7 +1058,8 @@ public class DataSetTableService { Matcher matcher = pattern.matcher(sql); while (matcher.find()) { SqlVariableDetails defaultsSqlVariableDetail = null; - List defaultsSqlVariableDetails = new Gson().fromJson(sqlVariableDetails, new TypeToken>() {}.getType()); + List defaultsSqlVariableDetails = new Gson().fromJson(sqlVariableDetails, new TypeToken>() { + }.getType()); for (SqlVariableDetails sqlVariableDetail : defaultsSqlVariableDetails) { if (matcher.group().substring(2, matcher.group().length() - 1).equalsIgnoreCase(sqlVariableDetail.getVariableName())) { defaultsSqlVariableDetail = sqlVariableDetail; @@ -1642,7 +1643,9 @@ public class DataSetTableService { // field StringBuilder field = new StringBuilder(); for (Map.Entry next : checkedInfo.entrySet()) { - field.append(StringUtils.join(next.getValue(), ",")).append(","); + if (next.getValue().length > 0) { + field.append(StringUtils.join(next.getValue(), ",")).append(","); + } } String f = subPrefixSuffixChar(field.toString()); // join @@ -1790,7 +1793,9 @@ public class DataSetTableService { // field StringBuilder field = new StringBuilder(); for (Map.Entry next : checkedInfo.entrySet()) { - field.append(StringUtils.join(next.getValue(), ",")).append(","); + if (next.getValue().length > 0) { + field.append(StringUtils.join(next.getValue(), ",")).append(","); + } } String f = subPrefixSuffixChar(field.toString()); // join @@ -2269,7 +2274,7 @@ public class DataSetTableService { } Set nameSet = new HashSet<>(); for (DataSetTableRequest table : datasetTable) { - if(StringUtils.isEmpty(table.getName())){ + if (StringUtils.isEmpty(table.getName())) { throw new RuntimeException(Translator.get("I18n_name_cant_empty")); } nameSet.add(table.getName()); From 1539a4f857993d9e3f501d8fb336d0509a0e9a0a Mon Sep 17 00:00:00 2001 From: taojinlong Date: Fri, 17 Mar 2023 16:59:32 +0800 Subject: [PATCH 04/25] =?UTF-8?q?fix:=20sql=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=97=B6=EF=BC=8C=E5=8F=98=E9=87=8F=E7=94=9F?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/DataSetTableController.java | 2 +- .../service/dataset/DataSetTableService.java | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java b/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java index 3fd116cee9..de76fb86ac 100644 --- a/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java +++ b/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java @@ -170,7 +170,7 @@ public class DataSetTableController { @DePermission(type = DePermissionType.DATASOURCE, value = "dataSourceId", level = ResourceAuthLevel.DATASOURCE_LEVEL_USE) }, logical = Logical.AND) public ResultHolder getSQLPreview(@RequestBody DataSetTableRequest dataSetTableRequest) throws Exception { - return dataSetTableService.getSQLPreview(dataSetTableRequest); + return dataSetTableService.getSQLPreview(dataSetTableRequest, true); } @ApiOperation("根据sql查询预览数据") diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index dfe4da5860..3e33eafcc3 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -147,6 +147,7 @@ public class DataSetTableService { public static final String regex = "\\$\\{(.*?)\\}"; private static final String SubstitutedParams = "DATAEASE_PATAMS_BI"; private static final String SubstitutedSql = " 'BI' = 'BI' "; + private static final String SubstitutedSqlVirtualData = " 1 < 2 "; @Value("${upload.file.path}") private String path; @@ -323,7 +324,7 @@ public class DataSetTableService { if (StringUtils.equalsIgnoreCase(datasetTable.getType(), DatasetType.SQL.name()) && !"appApply".equalsIgnoreCase(datasetTable.getOptFrom())) { DataSetTableRequest dataSetTableRequest = new DataSetTableRequest(); BeanUtils.copyBean(dataSetTableRequest, datasetTable); - getSQLPreview(dataSetTableRequest); + getSQLPreview(dataSetTableRequest, false); } if (StringUtils.isEmpty(datasetTable.getId())) { datasetTable.setId(UUID.randomUUID().toString()); @@ -1242,7 +1243,7 @@ public class DataSetTableService { return datasetSqlLogMapper.selectByExample(example); } - public ResultHolder getSQLPreview(DataSetTableRequest dataSetTableRequest) throws Exception { + public ResultHolder getSQLPreview(DataSetTableRequest dataSetTableRequest, boolean realData) throws Exception { DatasetSqlLog datasetSqlLog = new DatasetSqlLog(); DataTableInfoDTO dataTableInfo = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class); @@ -1253,6 +1254,9 @@ public class DataSetTableService { throw new Exception(Translator.get("i18n_invalid_ds")); } String tmpSql = removeVariables(sql, ds.getType()); + if(!realData){ + tmpSql.replaceAll(SubstitutedSql, SubstitutedSqlVirtualData); + } if (dataSetTableRequest.getMode() == 1 && (tmpSql.contains(SubstitutedParams) || tmpSql.contains(SubstitutedSql.trim()))) { throw new Exception(Translator.get("I18N_SQL_variable_direct_limit")); } @@ -1263,14 +1267,11 @@ public class DataSetTableService { DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDatasource(ds); - - sql = handleVariableDefaultValue(sql, dataSetTableRequest.getSqlVariableDetails(), ds.getType(), true); - System.out.println(sql); + sql = realData ? handleVariableDefaultValue(sql, dataSetTableRequest.getSqlVariableDetails(), ds.getType(), true) : removeVariables(sql, ds.getType()).replaceAll(SubstitutedSql, SubstitutedSqlVirtualData); if (StringUtils.isEmpty(sql)) { DataEaseException.throwException(Translator.get("i18n_sql_not_empty")); } checkVariable(sql, ds.getType()); - System.out.println(sql); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); String sqlAsTable = qp.createSQLPreview(sql, null); datasourceRequest.setQuery(sqlAsTable); @@ -1932,7 +1933,7 @@ public class DataSetTableService { QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); DataTableInfoDTO dataTableInfo = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class); String sql = dataTableInfo.isBase64Encryption() ? new String(java.util.Base64.getDecoder().decode(dataTableInfo.getSql())) : dataTableInfo.getSql(); - sql = handleVariableDefaultValue(sql, null, ds.getType(), false); + sql = removeVariables(sql, ds.getType()).replaceAll(SubstitutedSql, SubstitutedSqlVirtualData); String sqlAsTable = qp.createSQLPreview(sql, null); datasourceRequest.setQuery(sqlAsTable); fields = datasourceProvider.fetchResultField(datasourceRequest); From ba14d9690fa5f52472d428fb49ac079eb2456211 Mon Sep 17 00:00:00 2001 From: maninhill <41712985+maninhill@users.noreply.github.com> Date: Sun, 19 Mar 2023 16:01:40 +0800 Subject: [PATCH 05/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7340f116f4..88e71059b3 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ curl -sSL https://dataease.oss-cn-hangzhou.aliyuncs.com/quick_start.sh | sh ## License -Copyright (c) 2014-2023 飞致云 FIT2CLOUD, All rights reserved. +Copyright (c) 2014-2023 [FIT2CLOUD 飞致云](https://fit2cloud.com/), All rights reserved. Licensed under The GNU General Public License version 3 (GPLv3) (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at From f314974312fa51c2246f0d284dcf0478710dbe2d Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Sun, 19 Mar 2023 21:19:20 +0800 Subject: [PATCH 06/25] =?UTF-8?q?perf(=E4=BB=AA=E8=A1=A8=E6=9D=BF):=20?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=9B=BE=E7=89=87=E6=8E=A5=E5=8F=A3=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E4=BB=BB=E6=84=8F=E6=96=87=E4=BB=B6issue#4798?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StaticResourceController.java | 2 +- .../staticResource/StaticResourceService.java | 69 ++++++++++++------- .../src/api/staticResource/staticResource.js | 4 +- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/backend/src/main/java/io/dataease/controller/staticResource/StaticResourceController.java b/backend/src/main/java/io/dataease/controller/staticResource/StaticResourceController.java index 277552ecc3..1d2e5368bf 100644 --- a/backend/src/main/java/io/dataease/controller/staticResource/StaticResourceController.java +++ b/backend/src/main/java/io/dataease/controller/staticResource/StaticResourceController.java @@ -16,7 +16,7 @@ import java.util.Map; * Description: */ @RestController -@RequestMapping("/static/resource") +@RequestMapping("/staticResource") public class StaticResourceController { @Resource diff --git a/backend/src/main/java/io/dataease/service/staticResource/StaticResourceService.java b/backend/src/main/java/io/dataease/service/staticResource/StaticResourceService.java index 309f0d6f3b..19a8c5a04d 100644 --- a/backend/src/main/java/io/dataease/service/staticResource/StaticResourceService.java +++ b/backend/src/main/java/io/dataease/service/staticResource/StaticResourceService.java @@ -3,6 +3,7 @@ package io.dataease.service.staticResource; import cn.hutool.core.codec.Base64Decoder; import cn.hutool.core.collection.CollectionUtil; import com.google.gson.Gson; +import io.dataease.commons.exception.DEException; import io.dataease.commons.utils.FileUtils; import io.dataease.commons.utils.LogUtil; import io.dataease.commons.utils.StaticResourceUtils; @@ -14,7 +15,10 @@ import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.web.multipart.MultipartFile; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -31,61 +35,78 @@ public class StaticResourceService { private final Path staticDir = Paths.get("/opt/dataease/data/static-resource/"); - public void upload(String fileId,MultipartFile file) { + public void upload(String fileId, MultipartFile file) { // check if the path is valid (not outside staticDir) Assert.notNull(file, "Multipart file must not be null"); try { + if (!isImage(file)) { + DEException.throwException("Multipart file must be image"); + } String originName = file.getOriginalFilename(); - String newFileName = fileId+originName.substring(originName.lastIndexOf("."),originName.length()); + String newFileName = fileId + originName.substring(originName.lastIndexOf("."), originName.length()); Path uploadPath = Paths.get(staticDir.toString(), newFileName); // create dir is absent FileUtils.createIfAbsent(Paths.get(staticDir.toString())); Files.createFile(uploadPath); file.transferTo(uploadPath); } catch (IOException e) { - LogUtil.error("文件上传失败",e); + LogUtil.error("文件上传失败", e); DataEaseException.throwException("文件上传失败"); - } catch (Exception e){ + } catch (Exception e) { DataEaseException.throwException(e); } } - public void saveFilesToServe(String staticResource){ + private boolean isImage(MultipartFile file) { + BufferedImage image = null; + try (InputStream input = file.getInputStream()) { + image = ImageIO.read(input); + } catch (IOException e) { + LogUtil.error(e.getMessage(), e); + return false; + } + if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0) { + return false; + } + return true; + } + + public void saveFilesToServe(String staticResource) { Gson gson = new Gson(); - if(StringUtils.isNotEmpty(staticResource)){ - Map resource = gson.fromJson(staticResource,Map.class); - for(Map.Entry entry:resource.entrySet()){ + if (StringUtils.isNotEmpty(staticResource)) { + Map resource = gson.fromJson(staticResource, Map.class); + for (Map.Entry entry : resource.entrySet()) { String path = entry.getKey(); - String fileName = path.substring(path.lastIndexOf("/")+1,path.length()); - saveSingleFileToServe(fileName,entry.getValue()); + String fileName = path.substring(path.lastIndexOf("/") + 1, path.length()); + saveSingleFileToServe(fileName, entry.getValue()); } } } - public void saveSingleFileToServe(String fileName,String content){ + public void saveSingleFileToServe(String fileName, String content) { Path uploadPath = Paths.get(staticDir.toString(), fileName); - try{ + try { if (uploadPath.toFile().exists()) { LogUtil.info("file exists"); - }else{ - if(StringUtils.isNotEmpty(content)){ + } else { + if (StringUtils.isNotEmpty(content)) { Files.createFile(uploadPath); - FileCopyUtils.copy(Base64Decoder.decode(content),Files.newOutputStream(uploadPath)); + FileCopyUtils.copy(Base64Decoder.decode(content), Files.newOutputStream(uploadPath)); } } - }catch (Exception e){ - LogUtil.error("template static resource save error"+e.getMessage()); + } catch (Exception e) { + LogUtil.error("template static resource save error" + e.getMessage()); } } - public Map findResourceAsBase64(StaticResourceRequest resourceRequest){ - Map result = new HashMap<>(); - if(CollectionUtil.isNotEmpty(resourceRequest.getResourcePathList())){ - for(String path :resourceRequest.getResourcePathList()){ - String value = StaticResourceUtils.getImgFileToBase64(path.substring(path.lastIndexOf("/")+1,path.length())); - result.put(path,value); + public Map findResourceAsBase64(StaticResourceRequest resourceRequest) { + Map result = new HashMap<>(); + if (CollectionUtil.isNotEmpty(resourceRequest.getResourcePathList())) { + for (String path : resourceRequest.getResourcePathList()) { + String value = StaticResourceUtils.getImgFileToBase64(path.substring(path.lastIndexOf("/") + 1, path.length())); + result.put(path, value); } } - return result; + return result; } } diff --git a/frontend/src/api/staticResource/staticResource.js b/frontend/src/api/staticResource/staticResource.js index 9af311c16d..3affe2c95a 100644 --- a/frontend/src/api/staticResource/staticResource.js +++ b/frontend/src/api/staticResource/staticResource.js @@ -4,7 +4,7 @@ import store from '@/store' export function uploadFile(fileId, param) { return request({ - url: '/static/resource/upload/' + fileId, + url: '/staticResource/upload/' + fileId, method: 'post', headers: { 'Content-Type': 'multipart/form-data' }, data: param, @@ -26,7 +26,7 @@ export function uploadFileResult(file, callback) { export function findResourceAsBase64(params) { return request({ - url: '/static/resource/findResourceAsBase64', + url: '/staticResource/findResourceAsBase64', method: 'post', data: params, loading: false From e43936fd3332a208c4ab20242fdb38520716c3eb Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Mon, 20 Mar 2023 11:34:57 +0800 Subject: [PATCH 07/25] =?UTF-8?q?refactor(=E8=A7=86=E5=9B=BE):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=BE=B9=E6=A1=86=E6=A0=B7=E5=BC=8F=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E7=BB=84=E4=BB=B6=E9=A2=84=E8=A7=88=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=8F=8C=E6=A1=86=20#4813?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/canvas/components/editor/ComponentWrapper.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/canvas/components/editor/ComponentWrapper.vue b/frontend/src/components/canvas/components/editor/ComponentWrapper.vue index 005c2e2d74..fab2e19b7c 100644 --- a/frontend/src/components/canvas/components/editor/ComponentWrapper.vue +++ b/frontend/src/components/canvas/components/editor/ComponentWrapper.vue @@ -1,7 +1,7 @@