Merge pull request #7265 from dataease/pr@dev-v2@refactor_template-manage

Pr@dev v2@refactor template manage
This commit is contained in:
王嘉豪 2023-12-21 16:46:07 +08:00 committed by GitHub
commit 53273aebfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 356 additions and 150 deletions

View File

@ -17,4 +17,14 @@ public interface ExtVisualizationTemplateMapper{
List<TemplateManageDTO> findBaseTemplateList();
Long checkCategoryMap(@Param("categoryId") String categoryId);
Long checkRepeatTemplateId(@Param("categoryId") String categoryId, @Param("templateId") String templateId);
void deleteCategoryMapByTemplate(@Param("templateName") String templateName, @Param("templateId") String templateId);
Long checkCategoryTemplateName(@Param("templateName") String templateName,@Param("categories") List<String> categories);
List<String> findTemplateCategories(@Param("templateId") String templateId);
}

View File

@ -17,6 +17,7 @@ import io.dataease.template.dao.ext.ExtVisualizationTemplateMapper;
import io.dataease.utils.AuthUtils;
import io.dataease.utils.BeanUtils;
import io.dataease.visualization.server.StaticResourceServer;
import io.dataease.xpack.base.settings.dao.entity.BaseSetting;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.transaction.annotation.Transactional;
@ -56,16 +57,16 @@ public class TemplateManageService implements TemplateManageApi {
request.setWithBlobs("N");
List<TemplateManageDTO> templateList = extTemplateMapper.findTemplateList(request);
if (request.getWithChildren()) {
getTreeChildren(templateList,request.getLeafDvType());
getTreeChildren(templateList, request.getLeafDvType());
}
return templateList;
}
public void getTreeChildren(List<TemplateManageDTO> parentTemplateList,String dvType) {
public void getTreeChildren(List<TemplateManageDTO> parentTemplateList, String dvType) {
Optional.ofNullable(parentTemplateList).ifPresent(parent -> parent.forEach(parentTemplate -> {
List<TemplateManageDTO> panelTemplateDTOChildren = extTemplateMapper.findTemplateList(new TemplateManageRequest(parentTemplate.getId(),dvType));
List<TemplateManageDTO> panelTemplateDTOChildren = extTemplateMapper.findTemplateList(new TemplateManageRequest(parentTemplate.getId(), dvType));
parentTemplate.setChildren(panelTemplateDTOChildren);
getTreeChildren(panelTemplateDTOChildren,dvType);
getTreeChildren(panelTemplateDTOChildren, dvType);
}));
}
@ -96,17 +97,21 @@ public class TemplateManageService implements TemplateManageApi {
DEException.throwException("名称已存在");
}
VisualizationTemplateCategory templateCategory = new VisualizationTemplateCategory();
BeanUtils.copyBean(templateCategory,request);
BeanUtils.copyBean(templateCategory, request);
templateCategoryMapper.insert(templateCategory);
} else {//模板插入 同名的模板进行覆盖(先删除)
// 分类映射删除
extTemplateMapper.deleteCategoryMapByTemplate(request.getName(),null);
// 模版删除
QueryWrapper<VisualizationTemplate> wrapper = new QueryWrapper<>();
wrapper.eq("name",request.getName());
wrapper.eq("name", request.getName());
templateMapper.delete(wrapper);
VisualizationTemplate template = new VisualizationTemplate();
BeanUtils.copyBean(template,request);
BeanUtils.copyBean(template, request);
templateMapper.insert(template);
// 插入分类关系
request.getCategories().forEach(categoryId ->{
request.getCategories().forEach(categoryId -> {
VisualizationTemplateCategoryMap categoryMap = new VisualizationTemplateCategoryMap();
categoryMap.setId(UUID.randomUUID().toString());
categoryMap.setCategoryId(categoryId);
@ -122,16 +127,27 @@ public class TemplateManageService implements TemplateManageApi {
DEException.throwException("名称已存在");
}
VisualizationTemplateCategory templateCategory = new VisualizationTemplateCategory();
BeanUtils.copyBean(templateCategory,request);
BeanUtils.copyBean(templateCategory, request);
templateCategoryMapper.updateById(templateCategory);
}else{
} else {
String nameCheckResult = this.nameCheck(CommonConstants.OPT_TYPE.UPDATE, request.getName(), request.getId());
if (CommonConstants.CHECK_RESULT.EXIST_ALL.equals(nameCheckResult)) {
DEException.throwException("名称已存在");
}
VisualizationTemplate template = new VisualizationTemplate();
BeanUtils.copyBean(template,request);
BeanUtils.copyBean(template, request);
templateMapper.updateById(template);
//更新分类
// 分类映射删除
extTemplateMapper.deleteCategoryMapByTemplate(null,request.getId());
// 插入分类关系
request.getCategories().forEach(categoryId -> {
VisualizationTemplateCategoryMap categoryMap = new VisualizationTemplateCategoryMap();
categoryMap.setId(UUID.randomUUID().toString());
categoryMap.setCategoryId(categoryId);
categoryMap.setTemplateId(request.getId());
categoryMapMapper.insert(categoryMap);
});
}
}
@ -141,14 +157,14 @@ public class TemplateManageService implements TemplateManageApi {
return templateManageDTO;
}
//名称检查
public String nameCheck(String optType, String name,String id) {
//模版名称检查
public String nameCheck(String optType, String name, String id) {
QueryWrapper<VisualizationTemplate> wrapper = new QueryWrapper<>();
if (CommonConstants.OPT_TYPE.INSERT.equals(optType)) {
wrapper.eq("name",name);
wrapper.eq("name", name);
} else if (CommonConstants.OPT_TYPE.UPDATE.equals(optType)) {
wrapper.eq("name",name);
wrapper.ne("id",id);
wrapper.eq("name", name);
wrapper.ne("id", id);
}
List<VisualizationTemplate> templateList = templateMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(templateList)) {
@ -158,14 +174,25 @@ public class TemplateManageService implements TemplateManageApi {
}
}
//名称检查
//分类下模版名称检查
@Override
public String categoryTemplateNameCheck(TemplateManageRequest request) {
Long result = extTemplateMapper.checkCategoryTemplateName(request.getName(), request.getCategories());
if (result == 0) {
return CommonConstants.CHECK_RESULT.NONE;
} else {
return CommonConstants.CHECK_RESULT.EXIST_ALL;
}
}
//分类名称检查
public String categoryNameCheck(String optType, String name, String id) {
QueryWrapper<VisualizationTemplateCategory> wrapper = new QueryWrapper<>();
if (CommonConstants.OPT_TYPE.INSERT.equals(optType)) {
wrapper.eq("name",name);
wrapper.eq("name", name);
} else if (CommonConstants.OPT_TYPE.UPDATE.equals(optType)) {
wrapper.eq("name",name);
wrapper.ne("id",id);
wrapper.eq("name", name);
wrapper.ne("id", id);
}
List<VisualizationTemplateCategory> templateList = templateCategoryMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(templateList)) {
@ -174,31 +201,59 @@ public class TemplateManageService implements TemplateManageApi {
return CommonConstants.CHECK_RESULT.EXIST_ALL;
}
}
@Override
public String nameCheck(TemplateManageRequest request) {
return nameCheck(request.getOptType(), request.getName(), request.getId());
}
@Override
public void delete(String id) {
public void delete(String id, String categoryId) {
Assert.notNull(id, "id cannot be null");
templateMapper.deleteById(id);
Assert.notNull(categoryId, "categoryId cannot be null");
QueryWrapper<VisualizationTemplateCategoryMap> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("template_id", id);
queryWrapper.eq("category_id", categoryId);
categoryMapMapper.delete(queryWrapper);
// 如何是最后一个 则实际模版需要删除
Long result = extTemplateMapper.checkRepeatTemplateId(categoryId, id);
if (result == 0) {
templateMapper.deleteById(id);
}
}
@Override
public void deleteCategory(String id) {
public String deleteCategory(String id) {
Assert.notNull(id, "id cannot be null");
templateCategoryMapper.deleteById(id);
// 该分类下是否有其他分类公用的模版
Long checkResult = extTemplateMapper.checkCategoryMap(id);
if (checkResult == 0) {
templateCategoryMapper.deleteById(id);
QueryWrapper<VisualizationTemplateCategoryMap> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("category_id", id);
categoryMapMapper.delete(queryWrapper);
return "success";
} else {
return "repeat";
}
}
@Override
public VisualizationTemplateVO findOne(String templateId) {
VisualizationTemplate template = templateMapper.selectById(templateId);
if(template != null){
if (template != null) {
VisualizationTemplateVO templateVO = new VisualizationTemplateVO();
BeanUtils.copyBean(templateVO,template);
BeanUtils.copyBean(templateVO, template);
//查找分类
List<String> categories = extTemplateMapper.findTemplateCategories(templateId);
templateVO.setCategories(categories);
return templateVO;
}else{
} else {
return null;
}
}
@Override
public List<TemplateManageDTO> find(TemplateManageRequest request) {
return extTemplateMapper.findTemplateList(request);

View File

@ -3,24 +3,24 @@
<mapper namespace="io.dataease.template.dao.ext.ExtVisualizationTemplateMapper">
<resultMap id="BaseResultMap" type="io.dataease.api.template.vo.VisualizationTemplateVO">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="pid" jdbcType="VARCHAR" property="pid" />
<result column="level" jdbcType="INTEGER" property="level" />
<result column="dv_type" jdbcType="VARCHAR" property="dvType" />
<result column="node_type" jdbcType="VARCHAR" property="nodeType" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="template_type" jdbcType="VARCHAR" property="templateType" />
<result column="snapshot" jdbcType="LONGVARCHAR" property="snapshot" />
<result column="template_style" jdbcType="LONGVARCHAR" property="templateStyle" />
<result column="template_data" jdbcType="LONGVARCHAR" property="templateData" />
<result column="dynamic_data" jdbcType="LONGVARCHAR" property="dynamicData" />
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="level" jdbcType="INTEGER" property="level"/>
<result column="dv_type" jdbcType="VARCHAR" property="dvType"/>
<result column="node_type" jdbcType="VARCHAR" property="nodeType"/>
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
<result column="create_time" jdbcType="BIGINT" property="createTime"/>
<result column="template_type" jdbcType="VARCHAR" property="templateType"/>
<result column="snapshot" jdbcType="LONGVARCHAR" property="snapshot"/>
<result column="template_style" jdbcType="LONGVARCHAR" property="templateStyle"/>
<result column="template_data" jdbcType="LONGVARCHAR" property="templateData"/>
<result column="dynamic_data" jdbcType="LONGVARCHAR" property="dynamicData"/>
</resultMap>
<resultMap id="BaseResultMapDTO" type="io.dataease.api.template.dto.TemplateManageDTO"
extends="BaseResultMap">
<result column="recent_use_time" jdbcType="BIGINT" property="recentUseTime" />
<result column="recent_use_time" jdbcType="BIGINT" property="recentUseTime"/>
<result column="label" jdbcType="VARCHAR" property="label"/>
<result column="childrenCount" jdbcType="VARCHAR" property="childrenCount"/>
</resultMap>
@ -33,57 +33,55 @@
</resultMap>
<sql id="Base_Column_List">
vt.id, vt.`name`, vt.pid, vt.`level`,vt.`dv_type`, vt.node_type, vt.create_by, vt.create_time, vt.template_type, vt.snapshot
</sql>
vt
.
id
, vt.`name`, vt.pid, vt.`level`,vt.`dv_type`, vt.node_type, vt.create_by, vt.create_time, vt.template_type, vt.snapshot
</sql>
<sql id="Blob_Column_List">
,vt.template_style, vt.template_data, vt.dynamic_data
</sql>
,vt.template_style, vt.template_data, vt.dynamic_data
</sql>
<select id="findBaseTemplateList" resultMap="BaseResultMapCollectionDTO">
SELECT
vt.id,
vt.`name`,
vt.pid,
vt.`level`,
vt.`dv_type`,
vt.node_type,
vt.create_by,
vt.create_time,
vt.template_type,
vt.SNAPSHOT,
vtcm.category_id,
cor.time as 'recent_use_time'
FROM
visualization_template vt
LEFT JOIN visualization_template_category_map vtcm ON vt.id = vtcm.template_id
left JOIN core_opt_recent cor on cor.resource_type=6 and vt.id= cor.resource_name
ORDER BY
vt.create_time DESC
SELECT vt.id,
vt.`name`,
vt.pid,
vt.`level`,
vt.`dv_type`,
vt.node_type,
vt.create_by,
vt.create_time,
vt.template_type,
vt.SNAPSHOT,
vtcm.category_id,
cor.time as 'recent_use_time'
FROM visualization_template vt
LEFT JOIN visualization_template_category_map vtcm ON vt.id = vtcm.template_id
left JOIN core_opt_recent cor on cor.resource_type = 6 and vt.id = cor.resource_name
ORDER BY vt.create_time DESC
</select>
<select id="findCategories" resultMap="BaseResultMapDTO">
SELECT
id,
`name`,
`name` as lable,
pid,
`level`,
`dv_type`,
node_type,
create_by,
create_time,
template_type,
SNAPSHOT
FROM
visualization_template_category
SELECT id,
`name`,
`name` as lable,
pid,
`level`,
`dv_type`,
node_type,
create_by,
create_time,
template_type,
SNAPSHOT
FROM visualization_template_category
order by visualization_template_category.create_time desc
</select>
<select id="findTemplateList" resultMap="BaseResultMapDTO">
SELECT
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
<if test='withBlobs == "Y"'>
<include refid="Blob_Column_List" />
<include refid="Blob_Column_List"/>
</if>
FROM
visualization_template vt
@ -91,4 +89,52 @@
where vtcm.category_id=#{categoryId}
order by vt.create_time desc
</select>
<select id="checkCategoryMap" resultType="Long">
SELECT count(1)
FROM visualization_template_category_map cm
WHERE cm.category_id = #{categoryId}
</select>
<select id="checkRepeatTemplateId" resultType="Long">
SELECT count(1)
FROM visualization_template_category_map cm
where cm.category_id != #{categoryId}
and cm.template_id =#{templateId}
</select>
<select id="checkCategoryTemplateName" resultType="Long">
SELECT
count(1)
FROM
visualization_template vt
LEFT JOIN visualization_template_category_map vtcm ON vt.id = vtcm.template_id
WHERE
vt.NAME = #{templateName}
AND vtcm.category_id IN
<foreach collection="categories" item="categoryId" index="index" open="(" close=")" separator=",">
#{categoryId}
</foreach>
</select>
<delete id="deleteCategoryMapByTemplate">
delete from visualization_template_category_map tcm where tcm.template_id in (
select id from visualization_template vt
<where>
<if test="templateName">
and vt.name = #{templateName}
</if>
<if test="templateId">
and vt.template_id = #{templateId}
</if>
</where>
)
</delete>
<select id="findTemplateCategories" resultType="String">
select category_id
from visualization_template_category_map
where template_id = #{templateId}
</select>
</mapper>

View File

@ -7,9 +7,9 @@ export function save(data) {
loading: true
})
}
export function templateDelete(id) {
export function templateDelete(id, categoryId) {
return request.post({
url: '/templateManage/delete/' + id
url: '/templateManage/delete/' + id + '/' + categoryId
})
}
@ -54,3 +54,10 @@ export function nameCheck(data) {
data: data
})
}
export function categoryTemplateNameCheck(data) {
return request.post({
url: '/templateManage/categoryTemplateNameCheck',
data: data
})
}

View File

@ -49,6 +49,7 @@
:style="getPointStyle(item)"
@mousedown="handleMouseDownOnPoint(item, $event)"
></div>
<div class="shape-shadow" v-show="batchOptStatus" @mousedown="batchSelected"></div>
<template v-if="boardMoveActive">
<div
v-show="!element.editing"
@ -517,6 +518,15 @@ const selectCurComponent = e => {
}
}
const batchSelected = e => {
if (dvMainStore.batchOptStatus) {
componentEditBarRef.value.batchOptCheckOut()
e.stopPropagation()
e.preventDefault()
return
}
}
const handleMouseDownOnPoint = (point, e) => {
dashboardActive.value && emit('onStartResize', e)
dvMainStore.setInEditorStatus(true)
@ -833,6 +843,15 @@ onMounted(() => {
position: absolute;
}
.shape-shadow {
top: 0;
left: 0;
width: 100%;
height: 100%;
position: absolute;
background-size: 100% 100% !important;
}
.shape-inner {
width: 100%;
height: 100%;

View File

@ -23,11 +23,7 @@
/>
</div>
</el-form-item>
<el-row
v-show="!!state.importTemplateInfo.snapshot"
class="preview"
:style="classBackground"
/>
<el-row v-show="!!state.templateInfo.snapshot" class="preview" :style="classBackground" />
<el-form-item :label="'选择分类'" prop="categories" style="margin-top: 16px">
<el-select v-model="state.templateInfo.categories" multiple style="width: 100%">
<el-option
@ -48,10 +44,10 @@
</template>
<script lang="ts" setup>
import { save, nameCheck, find } from '@/api/template'
import { save, nameCheck, find, findOne, categoryTemplateNameCheck } from '@/api/template'
import { computed, onMounted, reactive, ref } from 'vue'
import { imgUrlTrans } from '@/utils/imgUtils'
import { ElMessage } from 'element-plus-secondary'
import { ElMessage, ElMessageBox } from 'element-plus-secondary'
import { useI18n } from '@/hooks/web/useI18n'
const emits = defineEmits(['closeEditTemplateDialog', 'refresh'])
const { t } = useI18n()
@ -64,6 +60,15 @@ const props = defineProps({
templateCategories: {
type: Array,
required: true
},
optType: {
type: String,
required: true,
default: 'insert'
},
templateId: {
type: String,
required: false
}
})
@ -105,9 +110,9 @@ const state = reactive({
})
const classBackground = computed(() => {
if (state.importTemplateInfo.snapshot) {
if (state.templateInfo.snapshot) {
return {
background: `url(${imgUrlTrans(state.importTemplateInfo.snapshot)}) no-repeat`
background: `url(${imgUrlTrans(state.templateInfo.snapshot)}) no-repeat`
}
} else {
return {}
@ -119,6 +124,7 @@ const showCurrentTemplate = pid => {
state.nameList = response.data
})
}
const cancel = () => {
emits('closeEditTemplateDialog')
}
@ -138,40 +144,63 @@ const saveTemplate = () => {
return false
}
if (props.optType === 'insert') {
importTemplate()
} else {
editTemplate()
}
}
const editTemplate = () => {
const nameCheckRequest = {
pid: state.templateInfo.pid,
name: state.templateInfo.name,
categories: state.templateInfo.categories,
optType: 'insert'
optType: props.optType
}
//
nameCheck(nameCheckRequest).then(response => {
if (response.data.indexOf('exist') > -1) {
ElMessage.warning(t('当前模版名称已经存在'))
// const options = {
// title: 'commons.prompt',
// content: 'system_parameter_setting.to_overwrite_them',
// type: 'primary',
// cb: () =>
// save(state.templateInfo).then(response => {
// ElMessage.success('')
// emits('refresh')
// emits('closeEditTemplateDialog')
// }),
// confirmButtonText: t('template.override')
// }
// handlerConfirm(options)
} else {
save(state.templateInfo).then(response => {
ElMessage.success(t('导入成功'))
emits('refresh')
emits('closeEditTemplateDialog')
})
}
save(state.templateInfo).then(response => {
ElMessage.success(t('导入成功'))
emits('refresh')
emits('closeEditTemplateDialog')
})
})
}
const handlerConfirm = option => {
// do handlerConfirm
const importTemplate = () => {
const nameCheckRequest = {
pid: state.templateInfo.pid,
name: state.templateInfo.name,
categories: state.templateInfo.categories,
optType: props.optType
}
categoryTemplateNameCheck(nameCheckRequest).then(response => {
if (response.data.indexOf('exist') > -1) {
ElMessageBox.confirm('提示?', {
tip: '当前分类存在相同模版名称,是否覆盖?',
confirmButtonType: 'danger',
type: 'warning',
autofocus: false,
showClose: false
}).then(() => {
save(state.templateInfo).then(response => {
ElMessage.success(t('覆盖成功'))
emits('refresh')
emits('closeEditTemplateDialog')
})
})
} else {
//
nameCheck(nameCheckRequest).then(response => {
save(state.templateInfo).then(response => {
ElMessage.success(t('导入成功'))
emits('refresh')
emits('closeEditTemplateDialog')
})
})
}
})
}
const handleFileChange = e => {
@ -196,8 +225,15 @@ const goFile = () => {
}
onMounted(() => {
showCurrentTemplate(props.pid)
// showCurrentTemplate(props.pid)
})
if (props.templateId) {
findOne(props.templateId).then(rsp => {
state.templateInfo = rsp.data
console.log('test=' + JSON.stringify(state.templateInfo))
})
}
</script>
<style scoped lang="less">

View File

@ -5,15 +5,6 @@
</div>
<div class="card-info">
<div style="display: flex; align-items: center; width: calc(100% - 24px)">
<el-tooltip class="item" effect="dark" :content="dvTypeName" placement="top">
<el-icon style="font-size: 18px" v-if="model.dvType === 'dashboard'">
<Icon name="dv-dashboard-spine"></Icon>
</el-icon>
<el-icon class="icon-screen-new" style="font-size: 18px" v-else>
<Icon name="icon_operation-analysis_outlined"></Icon>
</el-icon>
</el-tooltip>
<el-tooltip class="item" effect="dark" :content="model.name" placement="top">
<span class="de-model-text">{{ model.name }}</span>
</el-tooltip>
@ -24,7 +15,7 @@
<template #dropdown>
<el-dropdown-menu class="de-card-dropdown">
<slot>
<el-dropdown-item command="rename">
<el-dropdown-item command="templateEdit">
<el-icon><EditPen /></el-icon>
编辑
</el-dropdown-item>
@ -106,7 +97,7 @@ const handleCommand = key => {
display: flex;
align-items: center;
justify-content: space-between;
padding: 4px 12px 9px 12px;
padding: 4px 12px 9px 0px;
box-sizing: border-box;
.el-icon-more {

View File

@ -105,7 +105,7 @@ const add = () => {
}
const categoryDelete = template => {
ElMessageBox.confirm('确定删除该分类吗?', {
tip: '删除后,该分类下的所有模版也将删除。',
tip: '',
confirmButtonType: 'danger',
type: 'warning',
autofocus: false,

View File

@ -74,16 +74,17 @@
v-model="state.editTemplate"
append-to-body
class="de-dialog-form"
width="600px"
width="420px"
>
<el-form
ref="templateEditFormRef"
label-position="top"
class="de-form-item"
:model="state.templateEditForm"
:rules="state.templateEditFormRules"
>
<el-form-item :label="state.dialogTitleLabel" prop="name">
<el-input v-model="state.templateEditForm.name" />
<el-input :placeholder="'请输入分类名称'" v-model="state.templateEditForm.name" />
</el-form-item>
</el-form>
<template #footer>
@ -100,12 +101,15 @@
:title="state.templateDialog.title"
v-model="state.templateDialog.visible"
:show-close="true"
:destroy-on-close="true"
class="de-dialog-form"
width="600px"
>
<de-template-import
v-if="state.templateDialog.visible"
:pid="state.templateDialog.pid"
:template-id="state.templateDialog.templateId"
:opt-type="state.templateDialog.optType"
:template-categories="state.templateCategories"
@refresh="showCurrentTemplate(state.currentTemplateId, state.currentTemplateLabel)"
@closeEditTemplateDialog="closeEditTemplateDialog"
@ -121,7 +125,7 @@ import { save, templateDelete, find, findCategories, deleteCategory } from '@/ap
import elementResizeDetectorMaker from 'element-resize-detector'
import { computed, nextTick, onMounted, reactive, ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { ElMessage } from 'element-plus-secondary'
import { ElMessage, ElMessageBox } from 'element-plus-secondary'
import DeTemplateList from '@/views/template/component/DeTemplateList.vue'
const { t } = useI18n()
const templateEditFormRef = ref(null)
@ -183,6 +187,8 @@ const state = reactive({
templateDialog: {
title: t('visualization.import_template'),
visible: false,
templateId: null,
optType: 'insert',
pid: '',
categories: []
}
@ -220,7 +226,7 @@ const nameRepeat = value => {
const handleCommand = (key, data) => {
switch (key) {
case 'rename':
case 'templateEdit':
templateEdit(data)
break
case 'delete':
@ -256,24 +262,44 @@ const showCurrentTemplate = (pid, label) => {
const categoryDelete = id => {
if (id) {
deleteCategory(id).then(response => {
ElMessage({
message: t('commons.delete_success'),
type: 'success',
showClose: true
})
getTree()
if (response.data === 'success') {
ElMessage({
message: t('commons.delete_success'),
type: 'success',
showClose: true
})
getTree()
} else {
ElMessageBox.confirm('无法删除分类?', {
tip: '请移除该分类下所有模版再进行删除分类操作',
confirmButtonText: '知道了',
confirmButtonType: 'default',
showCancelButton: false,
type: 'warning',
autofocus: false,
showClose: false
})
}
})
}
}
const templateDeleteInfo = id => {
if (id) {
templateDelete(id).then(response => {
ElMessage({
message: t('commons.delete_success'),
type: 'success',
showClose: true
ElMessageBox.confirm('确定删除该模版吗?', {
tip: '',
confirmButtonType: 'danger',
type: 'warning',
autofocus: false,
showClose: false
}).then(() => {
templateDelete(id, state.currentTemplateId).then(response => {
ElMessage({
message: t('commons.delete_success'),
type: 'success',
showClose: true
})
showCurrentTemplate(state.currentTemplateId, state.currentTemplateLabel)
})
showCurrentTemplate(state.currentTemplateId, state.currentTemplateLabel)
})
}
}
@ -283,7 +309,7 @@ const showTemplateEditDialog = (type, templateInfo) => {
state.formType = type
if (type === 'edit') {
state.templateEditForm = JSON.parse(JSON.stringify(templateInfo))
state.dialogTitle = state.templateEditForm['nodeType'] === 'folder' ? '编辑分类' : '编辑模板'
state.dialogTitle = state.templateEditForm['nodeType'] === 'folder' ? '重命名' : '编辑模板'
state.originName = state.templateEditForm['label']
} else {
state.dialogTitle = t('visualization.add_category')
@ -299,7 +325,11 @@ const showTemplateEditDialog = (type, templateInfo) => {
}
const templateEdit = templateInfo => {
showTemplateEditDialog('edit', templateInfo)
console.log('templateInfo' + JSON.stringify(templateInfo))
state.templateDialog.visible = true
state.templateDialog.title = '编辑模版'
state.templateDialog.optType = 'update'
state.templateDialog.templateId = templateInfo.id
}
const categoryClick = params => {
@ -362,6 +392,8 @@ const closeEditTemplateDialog = () => {
const templateImport = pid => {
state.templateDialog.visible = true
state.templateDialog.templateId = null
state.templateDialog.optType = 'insert'
state.templateDialog.pid = pid
}

View File

@ -14,11 +14,11 @@ public interface TemplateManageApi {
@PostMapping("/save")
TemplateManageDTO save(@RequestBody TemplateManageRequest request);
@PostMapping("/delete/{id}")
void delete(@PathVariable String id);
@PostMapping("/delete/{id}/{categoryId}")
void delete(@PathVariable String id,@PathVariable String categoryId);
@PostMapping("/deleteCategory/{id}")
void deleteCategory(@PathVariable String id);
String deleteCategory(@PathVariable String id);
@GetMapping("/findOne/{templateId}")
VisualizationTemplateVO findOne(@PathVariable String templateId) throws Exception;
@ -32,4 +32,7 @@ public interface TemplateManageApi {
@PostMapping("/nameCheck")
String nameCheck(@RequestBody TemplateManageRequest request);
@PostMapping("/categoryTemplateNameCheck")
String categoryTemplateNameCheck(@RequestBody TemplateManageRequest request);
}

View File

@ -2,6 +2,8 @@ package io.dataease.api.template.vo;
import lombok.Data;
import java.util.List;
/**
* @author : WangJiaHao
* @date : 2023/11/7 13:22
@ -73,4 +75,9 @@ public class VisualizationTemplateVO {
* 预存数据
*/
private String dynamicData;
/**
* 分类
*/
private List<String> categories;
}