refactor: 优化新建视图操作

This commit is contained in:
wangjiahao 2022-03-10 11:53:18 +08:00
parent 02df8cb956
commit 0c0f6d2f8b
7 changed files with 65 additions and 19 deletions

View File

@ -9,6 +9,7 @@ import io.dataease.commons.constants.DePermissionType;
import io.dataease.commons.constants.ResourceAuthLevel;
import io.dataease.controller.request.chart.ChartCalRequest;
import io.dataease.controller.request.chart.ChartExtRequest;
import io.dataease.controller.request.chart.ChartViewCacheRequest;
import io.dataease.controller.request.chart.ChartViewRequest;
import io.dataease.controller.response.ChartDetail;
import io.dataease.dto.chart.ChartViewDTO;
@ -36,8 +37,15 @@ public class ChartViewController {
@DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE)
@ApiOperation("保存")
@PostMapping("/save/{panelId}")
public ChartViewDTO save(@PathVariable String panelId, @RequestBody ChartViewCacheWithBLOBs chartViewWithBLOBs) {
return chartViewService.save(chartViewWithBLOBs);
public ChartViewDTO save(@PathVariable String panelId, @RequestBody ChartViewCacheRequest request) {
return chartViewService.save(request);
}
@DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE)
@ApiOperation("新建视图")
@PostMapping("/newOne/{panelId}")
public ChartViewWithBLOBs save(@PathVariable String panelId, @RequestBody ChartViewWithBLOBs chartViewWithBLOBs) {
return chartViewService.newOne(chartViewWithBLOBs);
}
@DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE)

View File

@ -0,0 +1,15 @@
package io.dataease.controller.request.chart;
import io.dataease.base.domain.ChartViewCacheWithBLOBs;
import lombok.Data;
/**
* Author: wangjiahao
* Date: 2022/3/10
* Description:
*/
@Data
public class ChartViewCacheRequest extends ChartViewCacheWithBLOBs {
private String savePosition = "cache";
}

View File

@ -79,7 +79,7 @@ public class ChartViewService {
private ReentrantLock lock = new ReentrantLock();
// 直接保存统一到缓存表
public ChartViewDTO save(ChartViewCacheWithBLOBs chartView) {
public ChartViewDTO save(ChartViewCacheRequest chartView) {
long timestamp = System.currentTimeMillis();
chartView.setUpdateTime(timestamp);
chartViewCacheMapper.updateByPrimaryKeySelective(chartView);
@ -90,6 +90,22 @@ public class ChartViewService {
}
public ChartViewWithBLOBs newOne(ChartViewWithBLOBs chartView) {
long timestamp = System.currentTimeMillis();
chartView.setUpdateTime(timestamp);
chartView.setId(UUID.randomUUID().toString());
chartView.setCreateBy(AuthUtils.getUser().getUsername());
chartView.setCreateTime(timestamp);
chartView.setUpdateTime(timestamp);
chartViewMapper.insertSelective(chartView);
// 新建的视图也存入缓存表中
extChartViewMapper.copyToCache(chartView.getId());
return chartView;
}
// 直接保存统一到缓存表
public void save2Cache(ChartViewCacheWithBLOBs chartView) {
long timestamp = System.currentTimeMillis();
@ -1761,6 +1777,7 @@ public class ChartViewService {
public void resetViewCache (String viewId){
extChartViewMapper.deleteViewCache(viewId);
extChartViewMapper.copyToCache(viewId);
}
}

View File

@ -104,9 +104,11 @@ public class PanelGroupService {
@DeCleaner(DePermissionType.PANEL)
// @Transactional
public PanelGroup saveOrUpdate(PanelGroupRequest request) {
Boolean mobileLayout = panelViewService.syncPanelViews(request);
request.setMobileLayout(mobileLayout);
String panelId = request.getId();
if(StringUtils.isNotEmpty(panelId)){
Boolean mobileLayout = panelViewService.syncPanelViews(request);
request.setMobileLayout(mobileLayout);
}
if (StringUtils.isEmpty(panelId)) {
// 新建
checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_INSERT, null, request.getNodeType());

View File

@ -784,7 +784,7 @@ export default {
view.extBubble = JSON.stringify([])
this.setChartDefaultOptions(view)
const _this = this
post('/chart/view/save/' + this.panelInfo.id, view).then(response => {
post('/chart/view/newOne/' + this.panelInfo.id, view).then(response => {
this.closeCreateChart()
this.$store.dispatch('chart/setTableId', null)
this.$store.dispatch('chart/setTableId', this.table.id)

View File

@ -1,5 +1,5 @@
<template>
<el-row v-loading="loading" style="height: 100%;overflow-y: hidden;width: 100%;">
<el-row v-loading="loading" style="height: 100%;overflow-y: hidden;width: 100%;border-left: 1px solid #E6E6E6">
<el-tooltip :content="$t('chart.draw_back')">
<el-button class="el-icon-d-arrow-right" style="position:absolute;left: 4px;top: 5px;z-index: 1000" size="mini" circle @click="closePanelEdit" />
</el-tooltip>

View File

@ -237,7 +237,7 @@
</el-row>
<el-row>
<div class="view-selected-message-class">
<span style="font-size: 14px;margin-left: 10px;font-weight: bold;line-height: 20px">{{$t('panel.select_view')}}</span>
<span style="font-size: 14px;margin-left: 10px;font-weight: bold;line-height: 20px">{{ $t('panel.select_view') }}</span>
</div>
</el-row>
</div>
@ -976,17 +976,21 @@ export default {
this.clearCurrentInfo()
this.$store.commit('setCurComponent', { component: component, index: this.componentData.length - 1 })
//
this.$store.dispatch('panel/setComponentDataTemp', JSON.stringify(this.componentData))
this.$store.dispatch('panel/setCanvasStyleDataTemp', JSON.stringify(this.canvasStyleData))
if (this.curComponent.type === 'view') {
this.$store.dispatch('chart/setViewId', null)
this.$store.dispatch('chart/setViewId', this.curComponent.propValue.viewId)
bus.$emit('PanelSwitchComponent', {
name: 'ChartEdit',
param: { 'id': this.curComponent.propValue.viewId, 'optType': 'edit' }
})
}
//
bus.$emit('change_panel_right_draw', true)
//
// //
// this.$store.dispatch('panel/setComponentDataTemp', JSON.stringify(this.componentData))
// this.$store.dispatch('panel/setCanvasStyleDataTemp', JSON.stringify(this.canvasStyleData))
// if (this.curComponent.type === 'view') {
// this.$store.dispatch('chart/setViewId', null)
// this.$store.dispatch('chart/setViewId', this.curComponent.propValue.viewId)
// bus.$emit('PanelSwitchComponent', {
// name: 'ChartEdit',
// param: { 'id': this.curComponent.propValue.viewId, 'optType': 'edit' }
// })
// }
},
canvasScroll(event) {
this.scrollLeft = event.target.scrollLeft