refactor: 仪表板保存优化

This commit is contained in:
wangjiahao 2022-05-31 13:31:01 +08:00
parent 23acb3c9c0
commit edc9878368
6 changed files with 55 additions and 37 deletions

View File

@ -62,20 +62,20 @@ public class PanelGroupController {
@DePermission(type = DePermissionType.PANEL, value = "pid", level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE)
}, logical = Logical.AND)
@I18n
public String saveOrUpdate(@RequestBody PanelGroupRequest request) {
return panelGroupService.saveOrUpdate(request);
public PanelGroup save(@RequestBody PanelGroupRequest request) throws Exception{
String panelId = panelGroupService.save(request);
return findOne(panelId);
}
@ApiOperation("保存并返回数据")
@PostMapping("/saveWithData")
@ApiOperation("更新")
@PostMapping("/update")
@DePermissions(value = {
@DePermission(type = DePermissionType.PANEL, value = "id"),
@DePermission(type = DePermissionType.PANEL, value = "pid", level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE)
}, logical = Logical.AND)
@I18n
public PanelGroup saveOrUpdateWithData(@RequestBody PanelGroupRequest request) throws Exception {
String panelId = panelGroupService.saveOrUpdate(request);
return findOne(panelId);
public String update(@RequestBody PanelGroupRequest request) {
return panelGroupService.update(request);
}
@ApiOperation("删除")

View File

@ -121,20 +121,22 @@ public class PanelGroupService {
}
@DeCleaner(value = DePermissionType.PANEL, key = "pid")
public String saveOrUpdate(PanelGroupRequest request) {
public String save(PanelGroupRequest request) {
checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_INSERT, null, request.getNodeType());
String panelId = newPanel(request);
panelGroupMapper.insertSelective(request);
// 清理权限缓存
clearPermissionCache();
sysAuthService.copyAuth(panelId, SysAuthConstants.AUTH_SOURCE_TYPE_PANEL);
DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, sourceType, panelId, request.getPid(), null, null);
return panelId;
}
public String update(PanelGroupRequest request) {
String panelId = request.getId();
if (StringUtils.isNotEmpty(panelId)) {
panelViewService.syncPanelViews(request);
}
if (StringUtils.isEmpty(panelId)) { // 新建
checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_INSERT, null, request.getNodeType());
panelId = newPanel(request);
panelGroupMapper.insertSelective(request);
// 清理权限缓存
clearPermissionCache();
sysAuthService.copyAuth(panelId, SysAuthConstants.AUTH_SOURCE_TYPE_PANEL);
DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, sourceType, panelId, request.getPid(), null, null);
} else if ("toDefaultPanel".equals(request.getOptType())) { // 转存为默认仪表板
panelViewService.syncPanelViews(request);
if ("toDefaultPanel".equals(request.getOptType())) { // 转存为默认仪表板
panelId = UUID.randomUUID().toString();
PanelGroupWithBLOBs newDefaultPanel = panelGroupMapper.selectByPrimaryKey(request.getId());
newDefaultPanel.setPanelType(PanelConstants.PANEL_TYPE.SYSTEM);

View File

@ -72,14 +72,16 @@ export function panelSave(data) {
data
})
}
export function panelSaveWithData(data) {
export function panelUpdate(data) {
return request({
url: 'panel/group/saveWithData',
url: 'panel/group/update',
method: 'post',
loading: true,
data
})
}
export function findOne(id) {
return request({
url: 'panel/group/findOne/' + id,

View File

@ -87,7 +87,7 @@ import { mapState } from 'vuex'
import { commonStyle, commonAttr } from '@/components/canvas/custom-component/component-list'
import eventBus from '@/components/canvas/utils/eventBus'
import { deepCopy, mobile2MainCanvas } from '@/components/canvas/utils/utils'
import { panelSave } from '@/api/panel/panel'
import { panelUpdate } from '@/api/panel/panel'
import { saveLinkage, getPanelAllLinkageInfo } from '@/api/panel/linkage'
import bus from '@/utils/bus'
import {
@ -295,7 +295,7 @@ export default {
})
//
requestInfo.panelData = JSON.stringify(components)
panelSave(requestInfo).then(response => {
panelUpdate(requestInfo).then(response => {
this.$store.commit('refreshSaveStatus')
this.$message({
message: this.$t('commons.save_success'),

View File

@ -32,7 +32,7 @@
</template>
<script>
import { panelSaveWithData } from '@/api/panel/panel'
import { panelSave, panelUpdate } from '@/api/panel/panel'
import { showTemplateList } from '@/api/system/template'
import TemplateAllList from './TemplateAllList'
import { deepCopy } from '@/components/canvas/utils/utils'
@ -147,17 +147,31 @@ export default {
}
this.editPanel.panelInfo['newFrom'] = this.inputType
this.loading = true
panelSaveWithData(this.editPanel.panelInfo).then(response => {
this.$message({
message: this.$t('commons.save_success'),
type: 'success',
showClose: true
if (this.editPanel.optType === 'new') {
panelSave(this.editPanel.panelInfo).then(response => {
this.$message({
message: this.$t('commons.save_success'),
type: 'success',
showClose: true
})
this.loading = false
this.$emit('closeEditPanelDialog', response.data)
}).catch(() => {
this.loading = false
})
this.loading = false
this.$emit('closeEditPanelDialog', response.data)
}).catch(() => {
this.loading = false
})
} else {
panelUpdate(this.editPanel.panelInfo).then(response => {
this.$message({
message: this.$t('commons.save_success'),
type: 'success',
showClose: true
})
this.loading = false
this.$emit('closeEditPanelDialog', response.data)
}).catch(() => {
this.loading = false
})
}
},
handleFileChange(e) {
const file = e.target.files[0]

View File

@ -228,7 +228,7 @@ import LinkGenerate from '@/views/link/generate'
import { uuid } from 'vue-uuid'
import bus from '@/utils/bus'
import EditPanel from './EditPanel'
import { addGroup, delGroup, groupTree, defaultTree, panelSave, initPanelData } from '@/api/panel/panel'
import {addGroup, delGroup, groupTree, defaultTree, panelSave, initPanelData, panelUpdate} from '@/api/panel/panel'
import { mapState } from 'vuex'
import {
DEFAULT_COMMON_CANVAS_STYLE_STRING
@ -779,7 +779,7 @@ export default {
saveMoveGroup() {
this.moveInfo.pid = this.tGroup.id
this.moveInfo['optType'] = 'move'
panelSave(this.moveInfo).then(response => {
panelUpdate(this.moveInfo).then(response => {
this.tree()
this.closeMoveGroup()
})