Merge pull request #99 from dataease/pr@dev@wjh-copy-view

feat: 仪表板编辑时可以进行视图的复制,复制后的视图样式等改变不影响原有视图
This commit is contained in:
王嘉豪 2021-06-29 13:47:19 +08:00 committed by GitHub
commit 43b85e6108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 101 additions and 2 deletions

View File

@ -12,6 +12,8 @@ import java.util.List;
public interface ExtChartViewMapper { public interface ExtChartViewMapper {
List<ChartViewDTO> search(ChartViewRequest request); List<ChartViewDTO> search(ChartViewRequest request);
void chartCopy(@Param("newChartId")String newChartId,@Param("oldChartId")String oldChartId);
@Select("select id from chart_view where table_id = #{tableId}") @Select("select id from chart_view where table_id = #{tableId}")
List<String> allViewIds(@Param("tableId") String tableId); List<String> allViewIds(@Param("tableId") String tableId);
} }

View File

@ -27,4 +27,45 @@
</select> </select>
<insert id="chartCopy">
INSERT INTO chart_view (
`id`,
`name`,
`scene_id`,
`table_id`,
`type`,
`title`,
`x_axis`,
`y_axis`,
`custom_attr`,
`custom_style`,
`custom_filter`,
`create_by`,
`create_time`,
`update_time`,
`snapshot`,
`style_priority`
) SELECT
#{newChartId},
GET_CHART_VIEW_COPY_NAME ( #{oldChartId} ),
`scene_id`,
`table_id`,
`type`,
`title`,
`x_axis`,
`y_axis`,
`custom_attr`,
`custom_style`,
`custom_filter`,
`create_by`,
`create_time`,
`update_time`,
`snapshot`,
`style_priority`
FROM
chart_view
WHERE
id = #{oldChartId}
</insert>
</mapper> </mapper>

View File

@ -55,4 +55,9 @@ public class ChartViewController {
public Map<String, Object> chartDetail(@PathVariable String id) { public Map<String, Object> chartDetail(@PathVariable String id) {
return chartViewService.getChartDetail(id); return chartViewService.getChartDetail(id);
} }
@PostMapping("chartCopy/{id}")
public String chartCopy(@PathVariable String id) {
return chartViewService.chartCopy(id);
}
} }

View File

@ -342,4 +342,10 @@ public class ChartViewService {
public ChartViewWithBLOBs findOne(String id) { public ChartViewWithBLOBs findOne(String id) {
return chartViewMapper.selectByPrimaryKey(id); return chartViewMapper.selectByPrimaryKey(id);
} }
public String chartCopy(String id) {
String newChartId = UUID.randomUUID().toString();
extChartViewMapper.chartCopy(newChartId,id);
return newChartId;
}
} }

View File

@ -0,0 +1,25 @@
DROP FUNCTION IF EXISTS `GET_CHART_VIEW_COPY_NAME`;
delimiter ;;
CREATE DEFINER=`root`@`%` FUNCTION `GET_CHART_VIEW_COPY_NAME`(chartId varchar(255)) RETURNS varchar(255) CHARSET utf8
READS SQL DATA
BEGIN
DECLARE chartName varchar(255);
DECLARE pid varchar(255);
DECLARE regexpInfo varchar(255);
DECLARE chartNameCount INTEGER;
select `name` ,`scene_id` into chartName, pid from chart_view where id =chartId;
set regexpInfo = concat('^',chartName,'-copy','\\(([0-9])+\\)$');
select (count(1)+1) into chartNameCount from chart_view where name REGEXP regexpInfo;
RETURN concat(chartName,'-copy(',chartNameCount,')');
END
;;
delimiter ;

View File

@ -27,3 +27,11 @@ export function getChartTree(data) {
data data
}) })
} }
export function chartCopy(id) {
return request({
url: '/chart/view/chartCopy/' + id,
method: 'post',
loading: true
})
}

View File

@ -4,7 +4,7 @@
<template v-if="curComponent"> <template v-if="curComponent">
<template v-if="!curComponent.isLock"> <template v-if="!curComponent.isLock">
<li v-if="editFilter.includes(curComponent.type)" @click="edit"> {{ $t('panel.edit') }}</li> <li v-if="editFilter.includes(curComponent.type)" @click="edit"> {{ $t('panel.edit') }}</li>
<!-- <li @click="copy"> {{ $t('panel.copy') }}</li>--> <li @click="copy"> {{ $t('panel.copy') }}</li>
<li @click="paste"> {{ $t('panel.paste') }}</li> <li @click="paste"> {{ $t('panel.paste') }}</li>
<li @click="cut"> {{ $t('panel.cut') }}</li> <li @click="cut"> {{ $t('panel.cut') }}</li>
<li @click="deleteComponent"> {{ $t('panel.delete') }}</li> <li @click="deleteComponent"> {{ $t('panel.delete') }}</li>

View File

@ -2,6 +2,7 @@ import store from '@/store/index'
import toast from '@/components/canvas/utils/toast' import toast from '@/components/canvas/utils/toast'
import generateID from '@/components/canvas/utils/generateID' import generateID from '@/components/canvas/utils/generateID'
import { deepCopy } from '@/components/canvas/utils/utils' import { deepCopy } from '@/components/canvas/utils/utils'
import { chartCopy } from '@/api/chart/chart'
export default { export default {
state: { state: {
@ -36,7 +37,18 @@ export default {
} }
data.id = generateID() data.id = generateID()
store.commit('addComponent', { component: deepCopy(data) })
// 如果是用户视图 测先进行底层复制
debugger
if (data.type === 'view') {
chartCopy(data.propValue.viewId).then(res => {
const newView = deepCopy(data)
newView.propValue.viewId = res.data
store.commit('addComponent', { component: newView })
})
} else {
store.commit('addComponent', { component: deepCopy(data) })
}
if (state.isCut) { if (state.isCut) {
state.copyData = null state.copyData = null
} }