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

View File

@ -121,20 +121,22 @@ public class PanelGroupService {
} }
@DeCleaner(value = DePermissionType.PANEL, key = "pid") @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(); String panelId = request.getId();
if (StringUtils.isNotEmpty(panelId)) { panelViewService.syncPanelViews(request);
panelViewService.syncPanelViews(request); if ("toDefaultPanel".equals(request.getOptType())) { // 转存为默认仪表板
}
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())) { // 转存为默认仪表板
panelId = UUID.randomUUID().toString(); panelId = UUID.randomUUID().toString();
PanelGroupWithBLOBs newDefaultPanel = panelGroupMapper.selectByPrimaryKey(request.getId()); PanelGroupWithBLOBs newDefaultPanel = panelGroupMapper.selectByPrimaryKey(request.getId());
newDefaultPanel.setPanelType(PanelConstants.PANEL_TYPE.SYSTEM); newDefaultPanel.setPanelType(PanelConstants.PANEL_TYPE.SYSTEM);

View File

@ -72,14 +72,16 @@ export function panelSave(data) {
data data
}) })
} }
export function panelSaveWithData(data) {
export function panelUpdate(data) {
return request({ return request({
url: 'panel/group/saveWithData', url: 'panel/group/update',
method: 'post', method: 'post',
loading: true, loading: true,
data data
}) })
} }
export function findOne(id) { export function findOne(id) {
return request({ return request({
url: 'panel/group/findOne/' + id, 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 { commonStyle, commonAttr } from '@/components/canvas/custom-component/component-list'
import eventBus from '@/components/canvas/utils/eventBus' import eventBus from '@/components/canvas/utils/eventBus'
import { deepCopy, mobile2MainCanvas } from '@/components/canvas/utils/utils' 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 { saveLinkage, getPanelAllLinkageInfo } from '@/api/panel/linkage'
import bus from '@/utils/bus' import bus from '@/utils/bus'
import { import {
@ -295,7 +295,7 @@ export default {
}) })
// //
requestInfo.panelData = JSON.stringify(components) requestInfo.panelData = JSON.stringify(components)
panelSave(requestInfo).then(response => { panelUpdate(requestInfo).then(response => {
this.$store.commit('refreshSaveStatus') this.$store.commit('refreshSaveStatus')
this.$message({ this.$message({
message: this.$t('commons.save_success'), message: this.$t('commons.save_success'),

View File

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

View File

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