提交 00b8e2d4 authored 作者: wangjiahao's avatar wangjiahao

fix: 模板不允许重名 但是可以允许覆盖

上级 45eb0acb
package io.dataease.commons.constants;
/**
* Author: wangjiahao
* Date: 2021-05-25
* Description:
*/
public class CommonConstants {
//操作类型
public static final class OPT_TYPE{
public static final String INSERT = "insert";
public static final String UPDATE = "update";
public static final String DELETE = "delete";
public static final String SELECT = "select";
}
//操作类型
public static final class CHECK_RESULT{
// 不存在
public static final String NONE = "none";
// 全局存在
public static final String EXIST_ALL= "exist_all";
// 当前用户存在
public static final String EXIST_USER= "exist_user";
// 其他用户存在
public static final String EXIST_OTHER= "exist_other";
}
}
...@@ -7,14 +7,11 @@ package io.dataease.commons.constants; ...@@ -7,14 +7,11 @@ package io.dataease.commons.constants;
*/ */
public class SystemConstants { public class SystemConstants {
public final static String WITH_EXTEND_NOW = "now"; public static final class WITH_EXTEND{
public final static String WITH_EXTEND_PARENT = "parent"; public final static String NOW = "now";
public final static String WITH_EXTEND_CHILDREN = "children"; public final static String PARENT = "parent";
public final static String CHILDREN = "children";
}
public final static int PRIVILEGE_VALUE_ON= 1;
public final static int PRIVILEGE_VALUE_OFF = 0;
......
...@@ -49,4 +49,10 @@ public class PanelTemplateController { ...@@ -49,4 +49,10 @@ public class PanelTemplateController {
} }
@PostMapping("/nameCheck")
public String nameCheck(@RequestBody PanelTemplateRequest request) {
return panelTemplateService.nameCheck(request);
}
} }
...@@ -22,7 +22,7 @@ public class BaseTreeRequest { ...@@ -22,7 +22,7 @@ public class BaseTreeRequest {
private String pid; private String pid;
//now 返回当前条件查询的数据 parent 返回当前数据查询的数据同时递归父节点数据; children 返回当前数据查询的数据同时递归子节点数据 //now 返回当前条件查询的数据 parent 返回当前数据查询的数据同时递归父节点数据; children 返回当前数据查询的数据同时递归子节点数据
private String withExtend= SystemConstants.WITH_EXTEND_NOW; private String withExtend= SystemConstants.WITH_EXTEND.NOW;
private String createBy; private String createBy;
......
...@@ -12,6 +12,8 @@ import lombok.Data; ...@@ -12,6 +12,8 @@ import lombok.Data;
public class PanelTemplateRequest extends PanelTemplateWithBLOBs { public class PanelTemplateRequest extends PanelTemplateWithBLOBs {
private String sort; private String sort;
private String optType;
private Boolean withChildren = false; private Boolean withChildren = false;
public PanelTemplateRequest() { public PanelTemplateRequest() {
......
...@@ -3,15 +3,20 @@ package io.dataease.service.panel; ...@@ -3,15 +3,20 @@ package io.dataease.service.panel;
import io.dataease.base.domain.*; import io.dataease.base.domain.*;
import io.dataease.base.mapper.PanelTemplateMapper; import io.dataease.base.mapper.PanelTemplateMapper;
import io.dataease.base.mapper.ext.ExtPanelTemplateMapper; import io.dataease.base.mapper.ext.ExtPanelTemplateMapper;
import io.dataease.commons.constants.CommonConstants;
import io.dataease.commons.constants.PanelConstants; import io.dataease.commons.constants.PanelConstants;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.BeanUtils; import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.request.panel.PanelTemplateRequest; import io.dataease.controller.request.panel.PanelTemplateRequest;
import io.dataease.dto.panel.PanelTemplateDTO; import io.dataease.dto.panel.PanelTemplateDTO;
import io.dataease.i18n.Translator;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -54,16 +59,30 @@ public class PanelTemplateService { ...@@ -54,16 +59,30 @@ public class PanelTemplateService {
} }
@Transactional
public PanelTemplateDTO save(PanelTemplateRequest request) { public PanelTemplateDTO save(PanelTemplateRequest request) {
if (StringUtils.isEmpty(request.getId())) { if (StringUtils.isEmpty(request.getId())) {
//如果level 是0(第一级)设置父级为对应的templateType request.setId(UUID.randomUUID().toString());
request.setCreateTime(System.currentTimeMillis());
request.setCreateBy(AuthUtils.getUser().getUsername());
//如果level 是0(第一级)指的是分类目录 设置父级为对应的templateType
if(request.getLevel()==0){ if(request.getLevel()==0){
request.setPid(request.getTemplateType()); request.setPid(request.getTemplateType());
String nameCheckResult = this.nameCheck(CommonConstants.OPT_TYPE.INSERT,request.getName(),request.getPid(),null);
if(CommonConstants.CHECK_RESULT.EXIST_ALL.equals(nameCheckResult)){
throw new RuntimeException(Translator.get("i18n_same_folder_can_not_repeat"));
}
}else{//模板插入 相同文件夹同名的模板进行覆盖(先删除)
PanelTemplateExample exampleDelete = new PanelTemplateExample();
exampleDelete.createCriteria().andPidEqualTo(request.getPid()).andNameEqualTo(request.getName());
panelTemplateMapper.deleteByExample(exampleDelete);
} }
request.setId(UUID.randomUUID().toString());
request.setCreateTime(System.currentTimeMillis());
panelTemplateMapper.insert(request); panelTemplateMapper.insert(request);
} else { } else {
String nameCheckResult = this.nameCheck(CommonConstants.OPT_TYPE.UPDATE,request.getName(),request.getPid(),request.getId());
if(CommonConstants.CHECK_RESULT.EXIST_ALL.equals(nameCheckResult)){
throw new RuntimeException(Translator.get("i18n_same_folder_can_not_repeat"));
}
panelTemplateMapper.updateByPrimaryKeySelective(request); panelTemplateMapper.updateByPrimaryKeySelective(request);
} }
PanelTemplateDTO panelTemplateDTO = new PanelTemplateDTO(); PanelTemplateDTO panelTemplateDTO = new PanelTemplateDTO();
...@@ -73,6 +92,29 @@ public class PanelTemplateService { ...@@ -73,6 +92,29 @@ public class PanelTemplateService {
} }
//名称检查
public String nameCheck(String optType,String name,String pid,String id){
PanelTemplateExample example = new PanelTemplateExample();
if(CommonConstants.OPT_TYPE.INSERT.equals(optType)){
example.createCriteria().andPidEqualTo(pid).andNameEqualTo(name);
}else if(CommonConstants.OPT_TYPE.UPDATE.equals(optType)){
example.createCriteria().andPidEqualTo(pid).andNameEqualTo(name).andIdNotEqualTo(id);
}
List<PanelTemplate> panelTemplates = panelTemplateMapper.selectByExample(example);
if(CollectionUtils.isEmpty(panelTemplates)){
return CommonConstants.CHECK_RESULT.NONE;
}else{
return CommonConstants.CHECK_RESULT.EXIST_ALL;
}
}
public String nameCheck(PanelTemplateRequest request){
return nameCheck(request.getOptType(),request.getName(),request.getPid(),request.getId());
}
public void delete(String id){ public void delete(String id){
Assert.notNull(id, "id cannot be null"); Assert.notNull(id, "id cannot be null");
panelTemplateMapper.deleteByPrimaryKey(id); panelTemplateMapper.deleteByPrimaryKey(id);
......
...@@ -103,7 +103,7 @@ public class SysAuthService { ...@@ -103,7 +103,7 @@ public class SysAuthService {
} }
private List<String> getAuthModels(String id, String type) { private List<String> getAuthModels(String id, String type) {
List<VAuthModelDTO> vAuthModelDTOS = searchAuthModelTree(new BaseTreeRequest(id,type, SystemConstants.WITH_EXTEND_CHILDREN)); List<VAuthModelDTO> vAuthModelDTOS = searchAuthModelTree(new BaseTreeRequest(id,type, SystemConstants.WITH_EXTEND.CHILDREN));
List<String> authSources = Optional.ofNullable(vAuthModelDTOS).orElse(new ArrayList<>()).stream().map(VAuthModelDTO::getId) List<String> authSources = Optional.ofNullable(vAuthModelDTOS).orElse(new ArrayList<>()).stream().map(VAuthModelDTO::getId)
.collect(Collectors.toList()); .collect(Collectors.toList());
return authSources; return authSources;
......
...@@ -36,3 +36,11 @@ export function find(data) { ...@@ -36,3 +36,11 @@ export function find(data) {
method: 'post' method: 'post'
}) })
} }
export function nameCheck(data) {
return request({
url: '/template/nameCheck',
data: data,
method: 'post'
})
}
...@@ -960,5 +960,11 @@ export default { ...@@ -960,5 +960,11 @@ export default {
enterprise: 'Enterprise', enterprise: 'Enterprise',
suport: 'Get technical support', suport: 'Get technical support',
update_success: 'Update Success' update_success: 'Update Success'
},
template: {
exit_same_template_check: 'The Same Name Exists In Now Class. Do You Want To Override It?',
override: 'Override',
cancel: '取消',
confirm_upload: 'Upload Confirm'
} }
} }
...@@ -959,5 +959,12 @@ export default { ...@@ -959,5 +959,12 @@ export default {
enterprise: '企業版', enterprise: '企業版',
suport: '獲取技術支持', suport: '獲取技術支持',
update_success: '更新成功' update_success: '更新成功'
},
template: {
exit_same_template_check: '当前存在相同名称模板,是否覆盖?',
override: '覆盖',
cancel: '取消',
confirm_upload: '上传确认'
} }
} }
...@@ -962,5 +962,11 @@ export default { ...@@ -962,5 +962,11 @@ export default {
enterprise: '企业版', enterprise: '企业版',
suport: '获取技术支持', suport: '获取技术支持',
update_success: '更新成功' update_success: '更新成功'
},
template: {
exit_same_template_check: '当前分类存在相同名称模板,是否覆盖?',
override: '覆盖',
cancel: '取消',
confirm_upload: '上传确认'
} }
} }
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
</el-tabs> </el-tabs>
</de-aside-container> </de-aside-container>
<de-main-container> <de-main-container>
<PanelViewShow /> <PanelViewShow v-if="mainActiveName==='PanelMain'" />
</de-main-container> </de-main-container>
</de-container> </de-container>
</template> </template>
...@@ -41,6 +41,14 @@ export default { ...@@ -41,6 +41,14 @@ export default {
showEnshrine: false showEnshrine: false
} }
}, },
computed: {
mainActiveName() {
return this.$store.state.panel.mainActiveName
}
},
mounted() {
this.$store.dispatch('panel/setMainActiveName', 'PanelMain')
},
methods: { methods: {
handleClick(tab, event) { handleClick(tab, event) {
// 点击分析面板需要刷新分享内容 // 点击分析面板需要刷新分享内容
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<!--TODO 仪表盘预览区域--> <!--TODO 仪表盘预览区域-->
<el-row class="panel-design-preview"> <el-row class="panel-design-preview">
<div ref="imageWrapper" style="width: 100%;height: 100%"> <div ref="imageWrapper" style="width: 100%;height: 100%">
<Preview v-if="mainActiveName==='PanelMain'&&showMain" /> <Preview v-if="showMain" />
</div> </div>
</el-row> </el-row>
</el-col> </el-col>
...@@ -74,7 +74,7 @@ export default { ...@@ -74,7 +74,7 @@ export default {
data() { data() {
return { return {
showMain: true, showMain: true,
templateInfo: '', templateInfo: {},
templateSaveTitle: '保存为模板', templateSaveTitle: '保存为模板',
templateSaveShow: false, templateSaveShow: false,
hasStar: false hasStar: false
...@@ -84,9 +84,6 @@ export default { ...@@ -84,9 +84,6 @@ export default {
panelInfo() { panelInfo() {
return this.$store.state.panel.panelInfo return this.$store.state.panel.panelInfo
}, },
mainActiveName() {
return this.$store.state.panel.mainActiveName
},
...mapState([ ...mapState([
'componentData', 'componentData',
'canvasStyleData' 'canvasStyleData'
...@@ -146,7 +143,7 @@ export default { ...@@ -146,7 +143,7 @@ export default {
}) })
}, },
refreshTemplateInfo() { refreshTemplateInfo() {
this.templateInfo = '' this.templateInfo = {}
html2canvas(this.$refs.imageWrapper).then(canvas => { html2canvas(this.$refs.imageWrapper).then(canvas => {
const snapshot = canvas.toDataURL('image/jpeg', 0.2) // 0.2是图片质量 const snapshot = canvas.toDataURL('image/jpeg', 0.2) // 0.2是图片质量
if (snapshot !== '') { if (snapshot !== '') {
......
<template> <template>
<el-row> <el-row>
<el-row> <el-row>
<el-col :span="4"> {{ $t('panel.template_nale')}}</el-col> <el-col :span="4"> {{ $t('panel.template_nale') }}</el-col>
<el-col :span="20"> <el-col :span="20">
<el-input v-model="templateInfo.name" clearable size="mini" /> <el-input v-model="templateInfo.name" clearable size="mini" />
</el-col> </el-col>
...@@ -26,21 +26,20 @@ ...@@ -26,21 +26,20 @@
</div> </div>
</el-row> </el-row>
<el-row class="root-class"> <el-row class="root-class">
<el-button @click="cancel()">{{ $t('commons.cancel')}}</el-button> <el-button @click="cancel()">{{ $t('commons.cancel') }}</el-button>
<el-button type="primary" @click="save()">{{ $t('commons.save')}}</el-button> <el-button type="primary" @click="save()">{{ $t('commons.save') }}</el-button>
</el-row> </el-row>
</el-row> </el-row>
</template> </template>
<script> <script>
import { post } from '@/api/panel/panel' import { save, nameCheck, showTemplateList } from '@/api/system/template'
export default { export default {
name: 'SaveToTemplate', name: 'SaveToTemplate',
props: { props: {
templateInfo: { templateInfo: {
type: Object, type: Object
require: true
} }
}, },
data() { data() {
...@@ -61,7 +60,7 @@ export default { ...@@ -61,7 +60,7 @@ export default {
templateType: 'self', templateType: 'self',
level: '0' level: '0'
} }
post('/template/templateList', param).then(response => { showTemplateList(param).then(response => {
this.data = response.data this.data = response.data
}) })
}, },
...@@ -81,13 +80,41 @@ export default { ...@@ -81,13 +80,41 @@ export default {
this.$warning(this.$t('panel.template_name_cannot_be_empty')) this.$warning(this.$t('panel.template_name_cannot_be_empty'))
return false return false
} }
post('/template/save', this.templateInfo).then(response => {
this.$message({ const nameCheckRequest = {
message: this.$t('commons.save_success'), pid: this.templateInfo.pid,
type: 'success', name: this.templateInfo.name,
showClose: true optType: 'insert'
}) }
this.$emit('closeSaveDialog') nameCheck(nameCheckRequest).then(response => {
if (response.data.indexOf('exist') > -1) {
this.$confirm(this.$t('template.exit_same_template_check'), this.$t('template.confirm_upload'), {
confirmButtonText: this.$t('template.override'),
cancelButtonText: this.$t('template.cancel'),
type: 'warning'
}).then(() => {
save(this.templateInfo).then(response => {
this.$message({
message: this.$t('commons.save_success'),
type: 'success',
showClose: true
})
debugger
this.$emit('closeSaveDialog')
})
}).catch(() => {
})
} else {
save(this.templateInfo).then(response => {
this.$message({
message: this.$t('commons.save_success'),
type: 'success',
showClose: true
})
debugger
this.$emit('closeSaveDialog')
})
}
}) })
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</template> </template>
<script> <script>
import { save } from '@/api/system/template' import { save, nameCheck } from '@/api/system/template'
export default { export default {
...@@ -70,14 +70,40 @@ export default { ...@@ -70,14 +70,40 @@ export default {
this.$warning(this.$t('chart.name_can_not_empty')) this.$warning(this.$t('chart.name_can_not_empty'))
return false return false
} }
save(this.templateInfo).then(response => { const nameCheckRequest = {
this.$message({ pid: this.templateInfo.pid,
message: this.$t('commons.save_success'), name: this.templateInfo.name,
type: 'success', optType: 'insert'
showClose: true }
}) nameCheck(nameCheckRequest).then(response => {
debugger if (response.data.indexOf('exist') > -1) {
this.$emit('closeEditTemplateDialog') this.$confirm(this.$t('template.exit_same_template_check'), this.$t('template.confirm_upload'), {
confirmButtonText: this.$t('template.override'),
cancelButtonText: this.$t('template.cancel'),
type: 'warning'
}).then(() => {
save(this.templateInfo).then(response => {
this.$message({
message: this.$t('commons.save_success'),
type: 'success',
showClose: true
})
debugger
this.$emit('closeEditTemplateDialog')
})
}).catch(() => {
})
} else {
save(this.templateInfo).then(response => {
this.$message({
message: this.$t('commons.save_success'),
type: 'success',
showClose: true
})
debugger
this.$emit('closeEditTemplateDialog')
})
}
}) })
}, },
handleFileChange(e) { handleFileChange(e) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
@templateEdit="templateEdit" @templateEdit="templateEdit"
@showCurrentTemplate="showCurrentTemplate" @showCurrentTemplate="showCurrentTemplate"
@templateImport="templateImport" @templateImport="templateImport"
@showTemplateEditDialog="showTemplateEditDialog"
/> />
</el-tab-pane> </el-tab-pane>
<el-tab-pane name="self"> <el-tab-pane name="self">
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
@templateEdit="templateEdit" @templateEdit="templateEdit"
@showCurrentTemplate="showCurrentTemplate" @showCurrentTemplate="showCurrentTemplate"
@templateImport="templateImport" @templateImport="templateImport"
@showTemplateEditDialog="showTemplateEditDialog"
/> />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论