refactor: tab组件加入视图直接进行复制

This commit is contained in:
wangjiahao 2022-02-23 18:21:52 +08:00
parent adc1bb92c8
commit 2ca712521a
8 changed files with 150 additions and 29 deletions

View File

@ -19,6 +19,8 @@ public class PanelView implements Serializable {
private Long updateTime; private Long updateTime;
private String position;
private byte[] content; private byte[] content;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -573,6 +573,76 @@ public class PanelViewExample {
addCriterion("update_time not between", value1, value2, "updateTime"); addCriterion("update_time not between", value1, value2, "updateTime");
return (Criteria) this; 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<String> values) {
addCriterion("`position` in", values, "position");
return (Criteria) this;
}
public Criteria andPositionNotIn(List<String> 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 { public static class Criteria extends GeneratedCriteria {

View File

@ -9,6 +9,7 @@
<result column="create_time" jdbcType="BIGINT" property="createTime" /> <result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" /> <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" /> <result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="position" jdbcType="VARCHAR" property="position" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.dataease.base.domain.PanelView"> <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.dataease.base.domain.PanelView">
<result column="content" jdbcType="LONGVARBINARY" property="content" /> <result column="content" jdbcType="LONGVARBINARY" property="content" />
@ -72,7 +73,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
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`
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
content content
@ -128,10 +129,12 @@
<insert id="insert" parameterType="io.dataease.base.domain.PanelView"> <insert id="insert" parameterType="io.dataease.base.domain.PanelView">
insert into panel_view (id, panel_id, chart_view_id, insert into panel_view (id, panel_id, chart_view_id,
create_by, create_time, update_by, create_by, create_time, update_by,
update_time, content) update_time, `position`, content
)
values (#{id,jdbcType=VARCHAR}, #{panelId,jdbcType=VARCHAR}, #{chartViewId,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{panelId,jdbcType=VARCHAR}, #{chartViewId,jdbcType=VARCHAR},
#{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateBy,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> </insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.PanelView"> <insert id="insertSelective" parameterType="io.dataease.base.domain.PanelView">
insert into panel_view insert into panel_view
@ -157,6 +160,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
update_time, update_time,
</if> </if>
<if test="position != null">
`position`,
</if>
<if test="content != null"> <if test="content != null">
content, content,
</if> </if>
@ -183,6 +189,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
#{updateTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
</if> </if>
<if test="position != null">
#{position,jdbcType=VARCHAR},
</if>
<if test="content != null"> <if test="content != null">
#{content,jdbcType=LONGVARBINARY}, #{content,jdbcType=LONGVARBINARY},
</if> </if>
@ -218,6 +227,9 @@
<if test="record.updateTime != null"> <if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
</if> </if>
<if test="record.position != null">
`position` = #{record.position,jdbcType=VARCHAR},
</if>
<if test="record.content != null"> <if test="record.content != null">
content = #{record.content,jdbcType=LONGVARBINARY}, content = #{record.content,jdbcType=LONGVARBINARY},
</if> </if>
@ -235,6 +247,7 @@
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
update_by = #{record.updateBy,jdbcType=VARCHAR}, update_by = #{record.updateBy,jdbcType=VARCHAR},
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
`position` = #{record.position,jdbcType=VARCHAR},
content = #{record.content,jdbcType=LONGVARBINARY} content = #{record.content,jdbcType=LONGVARBINARY}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
@ -248,7 +261,8 @@
create_by = #{record.createBy,jdbcType=VARCHAR}, create_by = #{record.createBy,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
update_by = #{record.updateBy,jdbcType=VARCHAR}, update_by = #{record.updateBy,jdbcType=VARCHAR},
update_time = #{record.updateTime,jdbcType=BIGINT} update_time = #{record.updateTime,jdbcType=BIGINT},
`position` = #{record.position,jdbcType=VARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -274,6 +288,9 @@
<if test="updateTime != null"> <if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
</if> </if>
<if test="position != null">
`position` = #{position,jdbcType=VARCHAR},
</if>
<if test="content != null"> <if test="content != null">
content = #{content,jdbcType=LONGVARBINARY}, content = #{content,jdbcType=LONGVARBINARY},
</if> </if>
@ -288,6 +305,7 @@
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
update_by = #{updateBy,jdbcType=VARCHAR}, update_by = #{updateBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
`position` = #{position,jdbcType=VARCHAR},
content = #{content,jdbcType=LONGVARBINARY} content = #{content,jdbcType=LONGVARBINARY}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
@ -298,7 +316,8 @@
create_by = #{createBy,jdbcType=VARCHAR}, create_by = #{createBy,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
update_by = #{updateBy,jdbcType=VARCHAR}, update_by = #{updateBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=BIGINT} update_time = #{updateTime,jdbcType=BIGINT},
`position` = #{position,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
</mapper> </mapper>

View File

@ -16,6 +16,13 @@ public class PanelViewInsertDTO extends PanelView {
super(); super();
super.setChartViewId(chartViewId); super.setChartViewId(chartViewId);
super.setPanelId(panelGroupId); super.setPanelId(panelGroupId);
super.setPosition("panel");
}
public PanelViewInsertDTO(String chartViewId,String panelGroupId,String position) {
super();
super.setChartViewId(chartViewId);
super.setPanelId(panelGroupId);
super.setPosition(position);
} }
} }

View File

@ -34,27 +34,27 @@ public class PanelViewService {
private final static String SCENE_TYPE = "scene"; private final static String SCENE_TYPE = "scene";
public List<PanelViewDto> groups(){ public List<PanelViewDto> groups() {
return extPanelViewMapper.groups(String.valueOf(AuthUtils.getUser().getUserId())); return extPanelViewMapper.groups(String.valueOf(AuthUtils.getUser().getUserId()));
} }
public List<PanelViewDto> views(){ public List<PanelViewDto> views() {
return extPanelViewMapper.views(String.valueOf(AuthUtils.getUser().getUserId())); return extPanelViewMapper.views(String.valueOf(AuthUtils.getUser().getUserId()));
} }
public List<PanelViewDto> buildTree(List<PanelViewPo> groups, List<PanelViewPo> views){ public List<PanelViewDto> buildTree(List<PanelViewPo> groups, List<PanelViewPo> views) {
if (CollectionUtils.isEmpty(groups) || CollectionUtils.isEmpty(views)) return null; if (CollectionUtils.isEmpty(groups) || CollectionUtils.isEmpty(views)) return null;
Map<String, List<PanelViewPo>> viewsMap = views.stream().collect(Collectors.groupingBy(PanelViewPo::getPid)); Map<String, List<PanelViewPo>> viewsMap = views.stream().collect(Collectors.groupingBy(PanelViewPo::getPid));
List<PanelViewDto> dtos = groups.stream().map(group -> BeanUtils.copyBean(new PanelViewDto(), group)).collect(Collectors.toList()); List<PanelViewDto> dtos = groups.stream().map(group -> BeanUtils.copyBean(new PanelViewDto(), group)).collect(Collectors.toList());
List<PanelViewDto> roots = new ArrayList<>(); List<PanelViewDto> roots = new ArrayList<>();
dtos.forEach(group -> { dtos.forEach(group -> {
// 查找跟节点 // 查找跟节点
if (ObjectUtils.isEmpty(group.getPid())){ if (ObjectUtils.isEmpty(group.getPid())) {
roots.add(group); roots.add(group);
} }
// 查找当前节点的子节点 // 查找当前节点的子节点
// 当前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 -> { Optional.ofNullable(viewsMap.get(group.getId())).ifPresent(lists -> lists.forEach(view -> {
PanelViewDto dto = BeanUtils.copyBean(new PanelViewDto(), view); PanelViewDto dto = BeanUtils.copyBean(new PanelViewDto(), view);
group.addChild(dto); group.addChild(dto);
@ -63,7 +63,7 @@ public class PanelViewService {
} }
// 当前group是分组 // 当前group是分组
dtos.forEach(item -> { dtos.forEach(item -> {
if (StringUtils.equals(item.getPid(), group.getId())){ if (StringUtils.equals(item.getPid(), group.getId())) {
group.addChild(item); group.addChild(item);
} }
}); });
@ -72,34 +72,48 @@ public class PanelViewService {
return roots.stream().filter(item -> CollectionUtils.isNotEmpty(item.getChildren())).collect(Collectors.toList()); return roots.stream().filter(item -> CollectionUtils.isNotEmpty(item.getChildren())).collect(Collectors.toList());
} }
@Transactional(propagation=Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public Boolean syncPanelViews(PanelGroupWithBLOBs panelGroup){ public Boolean syncPanelViews(PanelGroupWithBLOBs panelGroup) {
Boolean mobileLayout = null; Boolean mobileLayout = null;
String panelId = panelGroup.getId(); String panelId = panelGroup.getId();
Assert.notNull(panelId, "panelId cannot be null"); Assert.notNull(panelId, "panelId cannot be null");
String panelData = panelGroup.getPanelData(); String panelData = panelGroup.getPanelData();
if(StringUtils.isNotEmpty(panelData)){ if (StringUtils.isNotEmpty(panelData)) {
mobileLayout = false; mobileLayout = false;
JSONArray dataArray = JSON.parseArray(panelData); JSONArray dataArray = JSON.parseArray(panelData);
List<PanelViewInsertDTO> panelViewInsertDTOList = new ArrayList<>(); List<PanelViewInsertDTO> panelViewInsertDTOList = new ArrayList<>();
for(int i=0;i<dataArray.size();i++){ for (int i = 0; i < dataArray.size(); i++) {
JSONObject jsonObject = dataArray.getJSONObject(i); JSONObject jsonObject = dataArray.getJSONObject(i);
if("view".equals(jsonObject.getString("type"))){ if ("view".equals(jsonObject.getString("type"))) {
panelViewInsertDTOList.add(new PanelViewInsertDTO(jsonObject.getJSONObject("propValue").getString("viewId"),panelId)); panelViewInsertDTOList.add(new PanelViewInsertDTO(jsonObject.getJSONObject("propValue").getString("viewId"), panelId));
} }
if(jsonObject.getBoolean("mobileSelected")!=null&&jsonObject.getBoolean("mobileSelected")){ // 选项卡内部视图
if ("de-tabs".equals(jsonObject.getString("type"))) {
JSONObject options = jsonObject.getJSONObject("options");
if (options != null) {
JSONArray tabList = options.getJSONArray("tabList");
if (CollectionUtils.isNotEmpty(tabList)) {
for (int y = 0; y < tabList.size(); y++) {
if(tabList.getJSONObject(y).getString("content").indexOf("viewId")>-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; mobileLayout = true;
} }
} }
extPanelViewMapper.deleteWithPanelId(panelId); extPanelViewMapper.deleteWithPanelId(panelId);
if(CollectionUtils.isNotEmpty(panelViewInsertDTOList)){ if (CollectionUtils.isNotEmpty(panelViewInsertDTOList)) {
extPanelViewMapper.savePanelView(panelViewInsertDTOList); extPanelViewMapper.savePanelView(panelViewInsertDTOList);
} }
} }
return mobileLayout; return mobileLayout;
} }
public List<PanelViewTableDTO> detailList(String panelId){ public List<PanelViewTableDTO> detailList(String panelId) {
return extPanelViewMapper.getPanelViewDetails(panelId); return extPanelViewMapper.getPanelViewDetails(panelId);
} }
} }

View File

@ -350,3 +350,6 @@ INSERT INTO `sys_background_image` VALUES ('blue_5', '边框5', '蓝色调', NUL
COMMIT; COMMIT;
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;
ALTER TABLE `panel_view`
ADD COLUMN `position` varchar(255) NULL DEFAULT 'panel' COMMENT '视图位置 panel 仪表板中tab Tab页中' AFTER `update_time`;

View File

@ -60,6 +60,6 @@
</javaClientGenerator> </javaClientGenerator>
<!--要生成的数据库表 --> <!--要生成的数据库表 -->
<table tableName="sys_background_image"/> <table tableName="panel_view"/>
</context> </context>
</generatorConfiguration> </generatorConfiguration>

View File

@ -95,6 +95,7 @@ import { uuid } from 'vue-uuid'
import bus from '@/utils/bus' import bus from '@/utils/bus'
import componentList from '@/components/canvas/custom-component/component-list' import componentList from '@/components/canvas/custom-component/component-list'
import { mapState } from 'vuex' import { mapState } from 'vuex'
import { chartCopy } from '@/api/chart/chart'
export default { export default {
name: 'DeTabls', name: 'DeTabls',
@ -138,7 +139,9 @@ export default {
dropdownShow() { dropdownShow() {
return this.isEdit && !this.mobileLayoutStatus return this.isEdit && !this.mobileLayoutStatus
}, },
panelInfo() {
return this.$store.state.panel.panelInfo
},
...mapState([ ...mapState([
'curComponent', 'curComponent',
'mobileLayoutStatus' 'mobileLayoutStatus'
@ -211,11 +214,14 @@ export default {
component.id = newComponentId component.id = newComponentId
component.style.width = '100%' component.style.width = '100%'
component.style.height = '100%' component.style.height = '100%'
this.curItem.content = component chartCopy(node.innerId, this.panelInfo.id).then(res => {
this.curItem.name = newComponentId component.propValue.viewId = res.data
this.viewDialogVisible = false this.curItem.content = component
this.activeTabName = newComponentId this.curItem.name = newComponentId
this.styleChange() this.viewDialogVisible = false
this.activeTabName = newComponentId
this.styleChange()
})
// this.setComponentInfo() // this.setComponentInfo()
}, },