From 2ca712521a715e90381b3216781e91caf15da039 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Wed, 23 Feb 2022 18:21:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20tab=E7=BB=84=E4=BB=B6=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E8=A7=86=E5=9B=BE=E7=9B=B4=E6=8E=A5=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/dataease/base/domain/PanelView.java | 2 + .../base/domain/PanelViewExample.java | 70 +++++++++++++++++++ .../dataease/base/mapper/PanelViewMapper.xml | 29 ++++++-- .../dto/panel/po/PanelViewInsertDTO.java | 7 ++ .../service/panel/PanelViewService.java | 48 ++++++++----- .../main/resources/db/migration/V32__1.8.sql | 3 + .../src/main/resources/generatorConfig.xml | 2 +- .../src/components/widget/DeWidget/DeTabs.vue | 18 +++-- 8 files changed, 150 insertions(+), 29 deletions(-) diff --git a/backend/src/main/java/io/dataease/base/domain/PanelView.java b/backend/src/main/java/io/dataease/base/domain/PanelView.java index 0f323c61af..e2f43549e2 100644 --- a/backend/src/main/java/io/dataease/base/domain/PanelView.java +++ b/backend/src/main/java/io/dataease/base/domain/PanelView.java @@ -19,6 +19,8 @@ public class PanelView implements Serializable { private Long updateTime; + private String position; + private byte[] content; private static final long serialVersionUID = 1L; diff --git a/backend/src/main/java/io/dataease/base/domain/PanelViewExample.java b/backend/src/main/java/io/dataease/base/domain/PanelViewExample.java index 259289685b..67cb9a9e08 100644 --- a/backend/src/main/java/io/dataease/base/domain/PanelViewExample.java +++ b/backend/src/main/java/io/dataease/base/domain/PanelViewExample.java @@ -573,6 +573,76 @@ public class PanelViewExample { addCriterion("update_time not between", value1, value2, "updateTime"); return (Criteria) this; } + + public Criteria andPositionIsNull() { + addCriterion("`position` is null"); + return (Criteria) this; + } + + public Criteria andPositionIsNotNull() { + addCriterion("`position` is not null"); + return (Criteria) this; + } + + public Criteria andPositionEqualTo(String value) { + addCriterion("`position` =", value, "position"); + return (Criteria) this; + } + + public Criteria andPositionNotEqualTo(String value) { + addCriterion("`position` <>", value, "position"); + return (Criteria) this; + } + + public Criteria andPositionGreaterThan(String value) { + addCriterion("`position` >", value, "position"); + return (Criteria) this; + } + + public Criteria andPositionGreaterThanOrEqualTo(String value) { + addCriterion("`position` >=", value, "position"); + return (Criteria) this; + } + + public Criteria andPositionLessThan(String value) { + addCriterion("`position` <", value, "position"); + return (Criteria) this; + } + + public Criteria andPositionLessThanOrEqualTo(String value) { + addCriterion("`position` <=", value, "position"); + return (Criteria) this; + } + + public Criteria andPositionLike(String value) { + addCriterion("`position` like", value, "position"); + return (Criteria) this; + } + + public Criteria andPositionNotLike(String value) { + addCriterion("`position` not like", value, "position"); + return (Criteria) this; + } + + public Criteria andPositionIn(List values) { + addCriterion("`position` in", values, "position"); + return (Criteria) this; + } + + public Criteria andPositionNotIn(List values) { + addCriterion("`position` not in", values, "position"); + return (Criteria) this; + } + + public Criteria andPositionBetween(String value1, String value2) { + addCriterion("`position` between", value1, value2, "position"); + return (Criteria) this; + } + + public Criteria andPositionNotBetween(String value1, String value2) { + addCriterion("`position` not between", value1, value2, "position"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/dataease/base/mapper/PanelViewMapper.xml b/backend/src/main/java/io/dataease/base/mapper/PanelViewMapper.xml index f01b55c6ce..9e7209dfb9 100644 --- a/backend/src/main/java/io/dataease/base/mapper/PanelViewMapper.xml +++ b/backend/src/main/java/io/dataease/base/mapper/PanelViewMapper.xml @@ -9,6 +9,7 @@ + @@ -72,7 +73,7 @@ - id, panel_id, chart_view_id, create_by, create_time, update_by, update_time + id, panel_id, chart_view_id, create_by, create_time, update_by, update_time, `position` content @@ -128,10 +129,12 @@ insert into panel_view (id, panel_id, chart_view_id, create_by, create_time, update_by, - update_time, content) + update_time, `position`, content + ) values (#{id,jdbcType=VARCHAR}, #{panelId,jdbcType=VARCHAR}, #{chartViewId,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateBy,jdbcType=VARCHAR}, - #{updateTime,jdbcType=BIGINT}, #{content,jdbcType=LONGVARBINARY}) + #{updateTime,jdbcType=BIGINT}, #{position,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARBINARY} + ) insert into panel_view @@ -157,6 +160,9 @@ update_time, + + `position`, + content, @@ -183,6 +189,9 @@ #{updateTime,jdbcType=BIGINT}, + + #{position,jdbcType=VARCHAR}, + #{content,jdbcType=LONGVARBINARY}, @@ -218,6 +227,9 @@ update_time = #{record.updateTime,jdbcType=BIGINT}, + + `position` = #{record.position,jdbcType=VARCHAR}, + content = #{record.content,jdbcType=LONGVARBINARY}, @@ -235,6 +247,7 @@ create_time = #{record.createTime,jdbcType=BIGINT}, update_by = #{record.updateBy,jdbcType=VARCHAR}, update_time = #{record.updateTime,jdbcType=BIGINT}, + `position` = #{record.position,jdbcType=VARCHAR}, content = #{record.content,jdbcType=LONGVARBINARY} @@ -248,7 +261,8 @@ create_by = #{record.createBy,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, update_by = #{record.updateBy,jdbcType=VARCHAR}, - update_time = #{record.updateTime,jdbcType=BIGINT} + update_time = #{record.updateTime,jdbcType=BIGINT}, + `position` = #{record.position,jdbcType=VARCHAR} @@ -274,6 +288,9 @@ update_time = #{updateTime,jdbcType=BIGINT}, + + `position` = #{position,jdbcType=VARCHAR}, + content = #{content,jdbcType=LONGVARBINARY}, @@ -288,6 +305,7 @@ create_time = #{createTime,jdbcType=BIGINT}, update_by = #{updateBy,jdbcType=VARCHAR}, update_time = #{updateTime,jdbcType=BIGINT}, + `position` = #{position,jdbcType=VARCHAR}, content = #{content,jdbcType=LONGVARBINARY} where id = #{id,jdbcType=VARCHAR} @@ -298,7 +316,8 @@ create_by = #{createBy,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, update_by = #{updateBy,jdbcType=VARCHAR}, - update_time = #{updateTime,jdbcType=BIGINT} + update_time = #{updateTime,jdbcType=BIGINT}, + `position` = #{position,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/dto/panel/po/PanelViewInsertDTO.java b/backend/src/main/java/io/dataease/dto/panel/po/PanelViewInsertDTO.java index 1bdd000bda..bb1b8b9636 100644 --- a/backend/src/main/java/io/dataease/dto/panel/po/PanelViewInsertDTO.java +++ b/backend/src/main/java/io/dataease/dto/panel/po/PanelViewInsertDTO.java @@ -16,6 +16,13 @@ public class PanelViewInsertDTO extends PanelView { super(); super.setChartViewId(chartViewId); super.setPanelId(panelGroupId); + super.setPosition("panel"); + } + public PanelViewInsertDTO(String chartViewId,String panelGroupId,String position) { + super(); + super.setChartViewId(chartViewId); + super.setPanelId(panelGroupId); + super.setPosition(position); } } diff --git a/backend/src/main/java/io/dataease/service/panel/PanelViewService.java b/backend/src/main/java/io/dataease/service/panel/PanelViewService.java index 82121c05a0..1a9b052279 100644 --- a/backend/src/main/java/io/dataease/service/panel/PanelViewService.java +++ b/backend/src/main/java/io/dataease/service/panel/PanelViewService.java @@ -34,27 +34,27 @@ public class PanelViewService { private final static String SCENE_TYPE = "scene"; - public List groups(){ + public List groups() { return extPanelViewMapper.groups(String.valueOf(AuthUtils.getUser().getUserId())); } - public List views(){ + public List views() { return extPanelViewMapper.views(String.valueOf(AuthUtils.getUser().getUserId())); } - public List buildTree(List groups, List views){ + public List buildTree(List groups, List views) { if (CollectionUtils.isEmpty(groups) || CollectionUtils.isEmpty(views)) return null; Map> viewsMap = views.stream().collect(Collectors.groupingBy(PanelViewPo::getPid)); List dtos = groups.stream().map(group -> BeanUtils.copyBean(new PanelViewDto(), group)).collect(Collectors.toList()); List roots = new ArrayList<>(); dtos.forEach(group -> { // 查找跟节点 - if (ObjectUtils.isEmpty(group.getPid())){ + if (ObjectUtils.isEmpty(group.getPid())) { roots.add(group); } // 查找当前节点的子节点 // 当前group是场景 - if (StringUtils.equals(group.getType(), SCENE_TYPE)){ + if (StringUtils.equals(group.getType(), SCENE_TYPE)) { Optional.ofNullable(viewsMap.get(group.getId())).ifPresent(lists -> lists.forEach(view -> { PanelViewDto dto = BeanUtils.copyBean(new PanelViewDto(), view); group.addChild(dto); @@ -63,7 +63,7 @@ public class PanelViewService { } // 当前group是分组 dtos.forEach(item -> { - if (StringUtils.equals(item.getPid(), group.getId())){ + if (StringUtils.equals(item.getPid(), group.getId())) { group.addChild(item); } }); @@ -72,34 +72,48 @@ public class PanelViewService { return roots.stream().filter(item -> CollectionUtils.isNotEmpty(item.getChildren())).collect(Collectors.toList()); } - @Transactional(propagation=Propagation.REQUIRES_NEW) - public Boolean syncPanelViews(PanelGroupWithBLOBs panelGroup){ + @Transactional(propagation = Propagation.REQUIRES_NEW) + public Boolean syncPanelViews(PanelGroupWithBLOBs panelGroup) { Boolean mobileLayout = null; String panelId = panelGroup.getId(); Assert.notNull(panelId, "panelId cannot be null"); String panelData = panelGroup.getPanelData(); - if(StringUtils.isNotEmpty(panelData)){ + if (StringUtils.isNotEmpty(panelData)) { mobileLayout = false; JSONArray dataArray = JSON.parseArray(panelData); List panelViewInsertDTOList = new ArrayList<>(); - for(int i=0;i-1){ + panelViewInsertDTOList.add(new PanelViewInsertDTO(tabList.getJSONObject(y).getJSONObject("content").getJSONObject("propValue").getString("viewId"), panelId,"tab")); + } + } + } + } + } + if (jsonObject.getBoolean("mobileSelected") != null && jsonObject.getBoolean("mobileSelected")) { mobileLayout = true; } } extPanelViewMapper.deleteWithPanelId(panelId); - if(CollectionUtils.isNotEmpty(panelViewInsertDTOList)){ + if (CollectionUtils.isNotEmpty(panelViewInsertDTOList)) { extPanelViewMapper.savePanelView(panelViewInsertDTOList); } } return mobileLayout; } - public List detailList(String panelId){ - return extPanelViewMapper.getPanelViewDetails(panelId); + public List detailList(String panelId) { + return extPanelViewMapper.getPanelViewDetails(panelId); } } diff --git a/backend/src/main/resources/db/migration/V32__1.8.sql b/backend/src/main/resources/db/migration/V32__1.8.sql index 7e114e1572..13335f6742 100644 --- a/backend/src/main/resources/db/migration/V32__1.8.sql +++ b/backend/src/main/resources/db/migration/V32__1.8.sql @@ -350,3 +350,6 @@ INSERT INTO `sys_background_image` VALUES ('blue_5', '边框5', '蓝色调', NUL COMMIT; SET FOREIGN_KEY_CHECKS = 1; + +ALTER TABLE `panel_view` +ADD COLUMN `position` varchar(255) NULL DEFAULT 'panel' COMMENT '视图位置 panel 仪表板中,tab Tab页中' AFTER `update_time`; diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index c47b158407..a22bc71ba1 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -60,6 +60,6 @@ - +
diff --git a/frontend/src/components/widget/DeWidget/DeTabs.vue b/frontend/src/components/widget/DeWidget/DeTabs.vue index 99a164d901..b2b7c38d4e 100644 --- a/frontend/src/components/widget/DeWidget/DeTabs.vue +++ b/frontend/src/components/widget/DeWidget/DeTabs.vue @@ -95,6 +95,7 @@ import { uuid } from 'vue-uuid' import bus from '@/utils/bus' import componentList from '@/components/canvas/custom-component/component-list' import { mapState } from 'vuex' +import { chartCopy } from '@/api/chart/chart' export default { name: 'DeTabls', @@ -138,7 +139,9 @@ export default { dropdownShow() { return this.isEdit && !this.mobileLayoutStatus }, - + panelInfo() { + return this.$store.state.panel.panelInfo + }, ...mapState([ 'curComponent', 'mobileLayoutStatus' @@ -211,11 +214,14 @@ export default { component.id = newComponentId component.style.width = '100%' component.style.height = '100%' - this.curItem.content = component - this.curItem.name = newComponentId - this.viewDialogVisible = false - this.activeTabName = newComponentId - this.styleChange() + chartCopy(node.innerId, this.panelInfo.id).then(res => { + component.propValue.viewId = res.data + this.curItem.content = component + this.curItem.name = newComponentId + this.viewDialogVisible = false + this.activeTabName = newComponentId + this.styleChange() + }) // this.setComponentInfo() },