From b6a44197074d7d35c0b29e6865ecf3b477e6dd04 Mon Sep 17 00:00:00 2001
From: wangjiahao <1522128093@qq.com>
Date: Tue, 14 Nov 2023 13:16:08 +0800
Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=AF=8C=E6=96=87=E6=9C=AC?=
=?UTF-8?q?=E3=80=81=E8=A1=A8=E6=A0=BC=E7=AD=89=E6=A8=A1=E7=89=88=E9=80=82?=
=?UTF-8?q?=E9=85=8D=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
core/core-backend/pom.xml | 14 +++++
.../service/TemplateManageService.java | 12 ++--
...VisualizationTemplateExtendDataManage.java | 5 +-
.../server/DataVisualizationServer.java | 25 ++++----
.../main/resources/application-standalone.yml | 4 +-
.../src/assets/svg/dv-up-arrow.svg | 1 +
.../rich-text/DeRichTextView.vue | 2 +-
core/core-frontend/src/utils/imgUtils.ts | 10 +++-
.../editor/common/ChartTemplateInfo.vue | 30 ++++++++++
.../views/components/ChartComponentG2Plot.vue | 2 +-
.../views/components/ChartComponentS2.vue | 2 +-
.../views/chart/components/views/index.vue | 3 +-
.../src/views/common/DeResourceCreateOpt.vue | 11 ++--
.../src/views/common/DeResourceTree.vue | 18 +++++-
...lateList.vue => DeTemplatePreviewList.vue} | 59 +++++++++++--------
.../src/views/dashboard/index.vue | 10 +++-
.../api/template/TemplateManageApi.java | 6 +-
.../request/TemplateManageRequest.java | 5 +-
18 files changed, 156 insertions(+), 63 deletions(-)
create mode 100644 core/core-frontend/src/assets/svg/dv-up-arrow.svg
create mode 100644 core/core-frontend/src/views/chart/components/editor/common/ChartTemplateInfo.vue
rename core/core-frontend/src/views/common/{DeTemplateList.vue => DeTemplatePreviewList.vue} (57%)
diff --git a/core/core-backend/pom.xml b/core/core-backend/pom.xml
index 202a279ec8..52e42b7bb4 100644
--- a/core/core-backend/pom.xml
+++ b/core/core-backend/pom.xml
@@ -92,6 +92,20 @@
+
+ com.h2database
+ h2
+
+
+ io.dataease
+ xpack-permissions
+ ${project.version}
+
+
+ io.dataease
+ xpack-base
+ ${project.version}
+
diff --git a/core/core-backend/src/main/java/io/dataease/template/service/TemplateManageService.java b/core/core-backend/src/main/java/io/dataease/template/service/TemplateManageService.java
index 9b1d81ace7..bc70d8d4f6 100644
--- a/core/core-backend/src/main/java/io/dataease/template/service/TemplateManageService.java
+++ b/core/core-backend/src/main/java/io/dataease/template/service/TemplateManageService.java
@@ -47,16 +47,16 @@ public class TemplateManageService implements TemplateManageApi {
request.setWithBlobs("N");
List templateList = extTemplateMapper.findTemplateList(request);
if (request.getWithChildren()) {
- getTreeChildren(templateList);
+ getTreeChildren(templateList,request.getLeafDvType());
}
return templateList;
}
- public void getTreeChildren(List parentTemplateList) {
+ public void getTreeChildren(List parentTemplateList,String dvType) {
Optional.ofNullable(parentTemplateList).ifPresent(parent -> parent.forEach(parentTemplate -> {
- List panelTemplateDTOChildren = extTemplateMapper.findTemplateList(new TemplateManageRequest(parentTemplate.getId()));
+ List panelTemplateDTOChildren = extTemplateMapper.findTemplateList(new TemplateManageRequest(parentTemplate.getId(),dvType));
parentTemplate.setChildren(panelTemplateDTOChildren);
- getTreeChildren(panelTemplateDTOChildren);
+ getTreeChildren(panelTemplateDTOChildren,dvType);
}));
}
@@ -140,8 +140,8 @@ public class TemplateManageService implements TemplateManageApi {
templateMapper.deleteById(id);
}
@Override
- public VisualizationTemplateVO findOne(String panelId) {
- VisualizationTemplate template = templateMapper.selectById(panelId);
+ public VisualizationTemplateVO findOne(String templateId) {
+ VisualizationTemplate template = templateMapper.selectById(templateId);
if(template != null){
VisualizationTemplateVO templateVO = new VisualizationTemplateVO();
BeanUtils.copyBean(templateVO,template);
diff --git a/core/core-backend/src/main/java/io/dataease/visualization/manage/VisualizationTemplateExtendDataManage.java b/core/core-backend/src/main/java/io/dataease/visualization/manage/VisualizationTemplateExtendDataManage.java
index c671b319b5..e6923d2260 100644
--- a/core/core-backend/src/main/java/io/dataease/visualization/manage/VisualizationTemplateExtendDataManage.java
+++ b/core/core-backend/src/main/java/io/dataease/visualization/manage/VisualizationTemplateExtendDataManage.java
@@ -27,11 +27,10 @@ public class VisualizationTemplateExtendDataManage {
public ChartViewDTO getChartDataInfo(Long viewId, ChartViewDTO view) {
QueryWrapper queryWrapper = new QueryWrapper();
- queryWrapper.ne("view_id",viewId);
+ queryWrapper.eq("view_id",viewId);
List extendDataList = extendDataMapper.selectList(queryWrapper);
if (CollectionUtils.isNotEmpty(extendDataList)) {
- ChartViewDTO chartViewTemplate = JsonUtil.parse(extendDataList.get(0).getViewDetails(),ChartViewDTO.class);
- Map dataInfo = chartViewTemplate.getData();
+ ChartViewDTO chartViewTemplate = JsonUtil.parseObject(extendDataList.get(0).getViewDetails(),ChartViewDTO.class);
view.setData(chartViewTemplate.getData());
} else {
DEException.throwException("模板缓存数据中未获取指定视图数据:" + viewId);
diff --git a/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java b/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java
index 549c25d194..323b2b1841 100644
--- a/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java
+++ b/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java
@@ -82,8 +82,8 @@ public class DataVisualizationServer implements DataVisualizationApi {
@Override
@XpackInteract(value = "dataVisualizationServer", original = true)
- public DataVisualizationVO findById(Long dvId,String busiFlag) {
- DataVisualizationVO result = extDataVisualizationMapper.findDvInfo(dvId,busiFlag);
+ public DataVisualizationVO findById(Long dvId, String busiFlag) {
+ DataVisualizationVO result = extDataVisualizationMapper.findDvInfo(dvId, busiFlag);
if (result != null) {
//获取视图信息
List chartViewDTOS = chartViewManege.listBySceneId(dvId);
@@ -154,7 +154,7 @@ public class DataVisualizationServer implements DataVisualizationApi {
*/
@Transactional
@Override
- public void deleteLogic(Long dvId,String busiFlag) {
+ public void deleteLogic(Long dvId, String busiFlag) {
coreVisualizationManage.delete(dvId);
}
@@ -261,31 +261,34 @@ public class DataVisualizationServer implements DataVisualizationApi {
// 解析动态数据
Map dynamicDataMap = JsonUtil.parseObject(dynamicData, Map.class);
List chartViews = new ArrayList<>();
- Map canvasViewInfo = new HashMap<>();
- Map extendDataInfo = new HashMap<>();
+ Map canvasViewInfo = new HashMap<>();
+ Map extendDataInfo = new HashMap<>();
for (Map.Entry entry : dynamicDataMap.entrySet()) {
String originViewId = entry.getKey();
- String originViewData = entry.getValue();
+ String originViewData = JsonUtil.toJSONString(entry.getValue()).toString();
ChartViewDTO chartView = JsonUtil.parseObject(originViewData, ChartViewDTO.class);
+ if(chartView == null){
+ continue;
+ }
Long newViewId = IDUtils.snowID();
chartView.setId(newViewId);
chartView.setSceneId(newDvId);
+ chartView.setTableId(null);
chartView.setDataFrom(CommonConstants.VIEW_DATA_FROM.TEMPLATE);
// 数据处理 1.替换viewId 2.加入模板view data数据
- VisualizationTemplateExtendDataDTO extendDataDTO = new VisualizationTemplateExtendDataDTO(newViewId, newDvId,originViewData);
+ VisualizationTemplateExtendDataDTO extendDataDTO = new VisualizationTemplateExtendDataDTO(newDvId, newViewId, originViewData);
extendDataInfo.put(newViewId, extendDataDTO);
templateData = templateData.replaceAll(originViewId, newViewId.toString());
- chartViewManege.save(chartView);
- canvasViewInfo.put(chartView.getId(),chartView);
+ canvasViewInfo.put(chartView.getId(), chartView);
//插入模版数据 此处预先插入减少数据交互量
VisualizationTemplateExtendData extendData = new VisualizationTemplateExtendData();
- templateExtendDataMapper.insert(BeanUtils.copyBean(extendData,extendDataDTO));
+ templateExtendDataMapper.insert(BeanUtils.copyBean(extendData, extendDataDTO));
}
request.setComponentData(templateData);
request.setCanvasStyleData(templateStyle);
//Store static resource into the server
staticResourceServer.saveFilesToServe(staticResource);
- return new DataVisualizationVO(newDvId,name,dvType,templateStyle,templateData,canvasViewInfo,null);
+ return new DataVisualizationVO(newDvId, name, dvType, templateStyle, templateData, canvasViewInfo, null);
}
@Override
diff --git a/core/core-backend/src/main/resources/application-standalone.yml b/core/core-backend/src/main/resources/application-standalone.yml
index 1fc31e9388..87971ae75d 100644
--- a/core/core-backend/src/main/resources/application-standalone.yml
+++ b/core/core-backend/src/main/resources/application-standalone.yml
@@ -1,8 +1,8 @@
spring:
datasource:
- url: jdbc:mysql://127.0.0.1:3306/de_standalone?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false
+ url: jdbc:mysql://localhost:3306/dataease?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false
username: root
- password: Password123@mysql
+ password: 123456
messages:
basename: i18n/core,i18n/permissions
flyway:
diff --git a/core/core-frontend/src/assets/svg/dv-up-arrow.svg b/core/core-frontend/src/assets/svg/dv-up-arrow.svg
new file mode 100644
index 0000000000..c589c33e26
--- /dev/null
+++ b/core/core-frontend/src/assets/svg/dv-up-arrow.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/core/core-frontend/src/custom-component/rich-text/DeRichTextView.vue b/core/core-frontend/src/custom-component/rich-text/DeRichTextView.vue
index 8d373c0de1..863bf1324d 100644
--- a/core/core-frontend/src/custom-component/rich-text/DeRichTextView.vue
+++ b/core/core-frontend/src/custom-component/rich-text/DeRichTextView.vue
@@ -301,7 +301,7 @@ const reShow = () => {
const calcData = (view: Chart, callback) => {
isError.value = false
- if (view.tableId) {
+ if (view.tableId || view['dataFrom'] === 'template') {
const v = JSON.parse(JSON.stringify(view))
getData(v)
.then(res => {
diff --git a/core/core-frontend/src/utils/imgUtils.ts b/core/core-frontend/src/utils/imgUtils.ts
index fc2f533c19..aece25c8ca 100644
--- a/core/core-frontend/src/utils/imgUtils.ts
+++ b/core/core-frontend/src/utils/imgUtils.ts
@@ -4,8 +4,10 @@ import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { storeToRefs } from 'pinia'
import { findResourceAsBase64 } from '@/api/staticResource'
import FileSaver from 'file-saver'
+import { deepCopy } from '@/utils/utils'
const dvMainStore = dvMainStoreWithOut()
-const { canvasStyleData, componentData, canvasViewInfo, dvInfo } = storeToRefs(dvMainStore)
+const { canvasStyleData, componentData, canvasViewInfo, canvasViewDataInfo, dvInfo } =
+ storeToRefs(dvMainStore)
const basePath = import.meta.env.VITE_API_BASEPATH
export function imgUrlTrans(url) {
@@ -29,6 +31,10 @@ export function download2AppTemplate(downloadType, canvasDom, name, callBack?) {
try {
findStaticSource(function (staticResource) {
html2canvas(canvasDom).then(canvas => {
+ const canvasViewDataTemplate = deepCopy(canvasViewInfo.value)
+ Object.keys(canvasViewDataTemplate).forEach(viewId => {
+ canvasViewDataTemplate[viewId].data = canvasViewDataInfo.value[viewId]
+ })
const snapshot = canvas.toDataURL('image/jpeg', 0.1) // 0.1是图片质量
if (snapshot !== '') {
const templateInfo = {
@@ -38,7 +44,7 @@ export function download2AppTemplate(downloadType, canvasDom, name, callBack?) {
dvType: dvInfo.value.type,
canvasStyleData: JSON.stringify(canvasStyleData.value),
componentData: JSON.stringify(componentData.value),
- dynamicData: JSON.stringify(canvasViewInfo.value),
+ dynamicData: JSON.stringify(canvasViewDataTemplate),
staticResource: JSON.stringify(staticResource || {})
}
const blob = new Blob([JSON.stringify(templateInfo)], { type: '' })
diff --git a/core/core-frontend/src/views/chart/components/editor/common/ChartTemplateInfo.vue b/core/core-frontend/src/views/chart/components/editor/common/ChartTemplateInfo.vue
new file mode 100644
index 0000000000..e6de16ab0a
--- /dev/null
+++ b/core/core-frontend/src/views/chart/components/editor/common/ChartTemplateInfo.vue
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
当前为模版视图,请更换数据集...
+
+
+
+
diff --git a/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue b/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue
index 9ffa3d652e..410f9dbfb6 100644
--- a/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue
+++ b/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue
@@ -58,7 +58,7 @@ const containerId = 'container-' + showPosition.value + '-' + view.value.id
const viewTrack = ref(null)
const calcData = (view, callback) => {
- if (view.tableId) {
+ if (view.tableId || view['dataFrom'] === 'template') {
state.loading = true
isError.value = false
const v = JSON.parse(JSON.stringify(view))
diff --git a/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue b/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue
index 59f5ece0fc..bb12e52c04 100644
--- a/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue
+++ b/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue
@@ -78,7 +78,7 @@ const containerId = 'container-' + showPosition.value + '-' + view.value.id
const viewTrack = ref(null)
const calcData = (view: Chart, callback, resetPageInfo = true) => {
- if (view.tableId) {
+ if (view.tableId || view['dataFrom'] === 'template') {
isError.value = false
const v = JSON.parse(JSON.stringify(view))
getData(v)
diff --git a/core/core-frontend/src/views/chart/components/views/index.vue b/core/core-frontend/src/views/chart/components/views/index.vue
index 7ccbb8de87..26dcfd9da7 100644
--- a/core/core-frontend/src/views/chart/components/views/index.vue
+++ b/core/core-frontend/src/views/chart/components/views/index.vue
@@ -501,7 +501,8 @@ const chartAreaShow = computed(() => {
(view.value.tableId &&
(element.value['state'] === undefined || element.value['state'] === 'ready')) ||
view.value.type === 'rich-text' ||
- (view.value.type === 'map' && view.value.customAttr.map.id)
+ (view.value.type === 'map' && view.value.customAttr.map.id) ||
+ view.value['dataFrom'] === 'template'
)
})
diff --git a/core/core-frontend/src/views/common/DeResourceCreateOpt.vue b/core/core-frontend/src/views/common/DeResourceCreateOpt.vue
index dfb57f7fab..7b26b3e31c 100644
--- a/core/core-frontend/src/views/common/DeResourceCreateOpt.vue
+++ b/core/core-frontend/src/views/common/DeResourceCreateOpt.vue
@@ -39,7 +39,7 @@
-
@@ -68,13 +68,13 @@ import { computed, reactive, ref, watch } from 'vue'
import { imgUrlTrans } from '@/utils/imgUtils'
import { ElMessage } from 'element-plus-secondary'
import { decompression } from '@/api/visualization/dataVisualization'
-import { deepCopy } from '@/utils/utils'
+import DeTemplatePreviewList from '@/views/common/DeTemplatePreviewList.vue'
const { t } = useI18n()
const emits = defineEmits(['finish'])
const files = ref(null)
const props = defineProps({
- editPanelOut: {
- type: Object,
+ curCanvasType: {
+ type: String,
required: true
}
})
@@ -148,7 +148,8 @@ const showCurrentTemplateInfo = data => {
const getTree = () => {
const request = {
- level: '-1',
+ level: '0',
+ leafDvType: props.curCanvasType,
withChildren: true
}
state.loading = true
diff --git a/core/core-frontend/src/views/common/DeResourceTree.vue b/core/core-frontend/src/views/common/DeResourceTree.vue
index ea816adf3f..b5f146186c 100644
--- a/core/core-frontend/src/views/common/DeResourceTree.vue
+++ b/core/core-frontend/src/views/common/DeResourceTree.vue
@@ -15,6 +15,8 @@ import router from '@/router'
import { useI18n } from '@/hooks/web/useI18n'
import _ from 'lodash'
import DeResourceCreateOpt from '@/views/common/DeResourceCreateOpt.vue'
+import { useCache } from '@/hooks/web/useCache'
+const { wsCache } = useCache()
const dvMainStore = dvMainStoreWithOut()
const { dvInfo } = storeToRefs(dvMainStore)
@@ -95,7 +97,8 @@ const state = reactive({
divided: true
}
],
- resourceTypeList: []
+ resourceTypeList: [],
+ templateCreatePid: 0
})
state.resourceTypeList = [
@@ -244,6 +247,7 @@ const addOperation = (
window.open(baseUrl, '_blank')
}
} else if (cmd === 'newFromTemplate') {
+ state.templateCreatePid = data.id
// newFromTemplate
resourceCreateOpt.value.optInit()
} else {
@@ -264,8 +268,18 @@ const resourceOptFinish = () => {
getTree()
}
-const resourceCreateFinish = () => {
+const resourceCreateFinish = templateData => {
// do create
+ wsCache.set(`de-template-data`, JSON.stringify(templateData))
+ const baseUrl =
+ curCanvasType.value === 'dataV'
+ ? '#/dvCanvas?opt=create'
+ : '#/dashboard?opt=create&createType=template'
+ if (state.templateCreatePid) {
+ window.open(baseUrl + `&pid=${state.templateCreatePid}`, '_blank')
+ } else {
+ window.open(baseUrl, '_blank')
+ }
}
const getParentKeys = (tree, targetKey, parentKeys = []) => {
diff --git a/core/core-frontend/src/views/common/DeTemplateList.vue b/core/core-frontend/src/views/common/DeTemplatePreviewList.vue
similarity index 57%
rename from core/core-frontend/src/views/common/DeTemplateList.vue
rename to core/core-frontend/src/views/common/DeTemplatePreviewList.vue
index cbd65365eb..a73b42d3ec 100644
--- a/core/core-frontend/src/views/common/DeTemplateList.vue
+++ b/core/core-frontend/src/views/common/DeTemplatePreviewList.vue
@@ -1,6 +1,6 @@
-
+
-
+
-
-
-
-
-
-
-
- {{ data.name }}
+
+
+
+
+
+
+
+
+
+
+ {{ data.name }}
@@ -57,6 +51,10 @@ const { t } = useI18n()
const emits = defineEmits(['showCurrentTemplateInfo'])
const props = defineProps({
+ curCanvasType: {
+ type: String,
+ required: true
+ },
templateList: {
type: Array,
default: function () {
@@ -77,13 +75,28 @@ const filterNode = (value, data) => {
}
const nodeClick = (data, node) => {
- findOne(data.id).then(res => {
- emits('showCurrentTemplateInfo', res.data)
- })
+ if (data.nodeType === 'template') {
+ findOne(data.id).then(res => {
+ emits('showCurrentTemplateInfo', res.data)
+ })
+ }
}
-