Skip to content

Commit 43b85e6

Browse files
authored
Merge pull request dataease#99 from dataease/pr@dev@wjh-copy-view
feat: 仪表板编辑时可以进行视图的复制,复制后的视图样式等改变不影响原有视图
2 parents a590b45 + 2fc2bb1 commit 43b85e6

File tree

8 files changed

+101
-2
lines changed

8 files changed

+101
-2
lines changed

backend/src/main/java/io/dataease/base/mapper/ext/ExtChartViewMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
public interface ExtChartViewMapper {
1313
List<ChartViewDTO> search(ChartViewRequest request);
1414

15+
void chartCopy(@Param("newChartId")String newChartId,@Param("oldChartId")String oldChartId);
16+
1517
@Select("select id from chart_view where table_id = #{tableId}")
1618
List<String> allViewIds(@Param("tableId") String tableId);
1719
}

backend/src/main/java/io/dataease/base/mapper/ext/ExtChartViewMapper.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,45 @@
2727

2828

2929
</select>
30+
31+
<insert id="chartCopy">
32+
INSERT INTO chart_view (
33+
`id`,
34+
`name`,
35+
`scene_id`,
36+
`table_id`,
37+
`type`,
38+
`title`,
39+
`x_axis`,
40+
`y_axis`,
41+
`custom_attr`,
42+
`custom_style`,
43+
`custom_filter`,
44+
`create_by`,
45+
`create_time`,
46+
`update_time`,
47+
`snapshot`,
48+
`style_priority`
49+
) SELECT
50+
#{newChartId},
51+
GET_CHART_VIEW_COPY_NAME ( #{oldChartId} ),
52+
`scene_id`,
53+
`table_id`,
54+
`type`,
55+
`title`,
56+
`x_axis`,
57+
`y_axis`,
58+
`custom_attr`,
59+
`custom_style`,
60+
`custom_filter`,
61+
`create_by`,
62+
`create_time`,
63+
`update_time`,
64+
`snapshot`,
65+
`style_priority`
66+
FROM
67+
chart_view
68+
WHERE
69+
id = #{oldChartId}
70+
</insert>
3071
</mapper>

backend/src/main/java/io/dataease/controller/chart/ChartViewController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public ChartViewDTO getData(@PathVariable String id, @RequestBody ChartExtReques
5555
public Map<String, Object> chartDetail(@PathVariable String id) {
5656
return chartViewService.getChartDetail(id);
5757
}
58+
59+
@PostMapping("chartCopy/{id}")
60+
public String chartCopy(@PathVariable String id) {
61+
return chartViewService.chartCopy(id);
62+
}
5863
}

backend/src/main/java/io/dataease/service/chart/ChartViewService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,10 @@ public List<ChartView> viewsByIds(List<String> viewIds) {
342342
public ChartViewWithBLOBs findOne(String id) {
343343
return chartViewMapper.selectByPrimaryKey(id);
344344
}
345+
346+
public String chartCopy(String id) {
347+
String newChartId = UUID.randomUUID().toString();
348+
extChartViewMapper.chartCopy(newChartId,id);
349+
return newChartId;
350+
}
345351
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
DROP FUNCTION IF EXISTS `GET_CHART_VIEW_COPY_NAME`;
2+
delimiter ;;
3+
CREATE DEFINER=`root`@`%` FUNCTION `GET_CHART_VIEW_COPY_NAME`(chartId varchar(255)) RETURNS varchar(255) CHARSET utf8
4+
READS SQL DATA
5+
BEGIN
6+
7+
DECLARE chartName varchar(255);
8+
9+
DECLARE pid varchar(255);
10+
11+
DECLARE regexpInfo varchar(255);
12+
13+
DECLARE chartNameCount INTEGER;
14+
15+
select `name` ,`scene_id` into chartName, pid from chart_view where id =chartId;
16+
17+
set regexpInfo = concat('^',chartName,'-copy','\\(([0-9])+\\)$');
18+
19+
select (count(1)+1) into chartNameCount from chart_view where name REGEXP regexpInfo;
20+
21+
RETURN concat(chartName,'-copy(',chartNameCount,')');
22+
23+
END
24+
;;
25+
delimiter ;

frontend/src/api/chart/chart.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ export function getChartTree(data) {
2727
data
2828
})
2929
}
30+
31+
export function chartCopy(id) {
32+
return request({
33+
url: '/chart/view/chartCopy/' + id,
34+
method: 'post',
35+
loading: true
36+
})
37+
}

frontend/src/components/canvas/components/Editor/ContextMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<template v-if="curComponent">
55
<template v-if="!curComponent.isLock">
66
<li v-if="editFilter.includes(curComponent.type)" @click="edit"> {{ $t('panel.edit') }}</li>
7-
<!-- <li @click="copy"> {{ $t('panel.copy') }}</li>-->
7+
<li @click="copy"> {{ $t('panel.copy') }}</li>
88
<li @click="paste"> {{ $t('panel.paste') }}</li>
99
<li @click="cut"> {{ $t('panel.cut') }}</li>
1010
<li @click="deleteComponent"> {{ $t('panel.delete') }}</li>

frontend/src/components/canvas/store/copy.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import store from '@/store/index'
22
import toast from '@/components/canvas/utils/toast'
33
import generateID from '@/components/canvas/utils/generateID'
44
import { deepCopy } from '@/components/canvas/utils/utils'
5+
import { chartCopy } from '@/api/chart/chart'
56

67
export default {
78
state: {
@@ -36,7 +37,18 @@ export default {
3637
}
3738

3839
data.id = generateID()
39-
store.commit('addComponent', { component: deepCopy(data) })
40+
41+
// 如果是用户视图 测先进行底层复制
42+
debugger
43+
if (data.type === 'view') {
44+
chartCopy(data.propValue.viewId).then(res => {
45+
const newView = deepCopy(data)
46+
newView.propValue.viewId = res.data
47+
store.commit('addComponent', { component: newView })
48+
})
49+
} else {
50+
store.commit('addComponent', { component: deepCopy(data) })
51+
}
4052
if (state.isCut) {
4153
state.copyData = null
4254
}

0 commit comments

Comments
 (0)