mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2026-05-08 18:54:27 +08:00
update 重构 增强代码生成器各项功能
update 自动类型判断可根据不同数据库精确识别 对应的java类型 update 优化java字段名与数据库名不匹配则增加别名注解 update 增加 是否导出 是否状态切换 是否组合唯一校验 是否排序调整 和树结构相关字段等功能选择 update 优化自定义路径导出 导出全部代码 update 删除无用主子表相关代码
This commit is contained in:
@@ -3,7 +3,9 @@ package ${packageName}.controller;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
#if($enableExport)
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
#end
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -16,7 +18,9 @@ import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
#if($enableExport)
|
||||
import org.dromara.common.excel.utils.ExcelUtil;
|
||||
#end
|
||||
import ${packageName}.domain.vo.${ClassName}Vo;
|
||||
import ${packageName}.domain.bo.${ClassName}Bo;
|
||||
import ${packageName}.service.I${ClassName}Service;
|
||||
@@ -58,6 +62,7 @@ public class ${ClassName}Controller extends BaseController {
|
||||
/**
|
||||
* 导出${functionName}列表
|
||||
*/
|
||||
#if($enableExport)
|
||||
@SaCheckPermission("${permissionPrefix}:export")
|
||||
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@@ -65,6 +70,7 @@ public class ${ClassName}Controller extends BaseController {
|
||||
List<${ClassName}Vo> list = ${className}Service.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "${functionName}", ${ClassName}Vo.class, response);
|
||||
}
|
||||
#end
|
||||
|
||||
/**
|
||||
* 获取${functionName}详细信息
|
||||
@@ -86,6 +92,11 @@ public class ${ClassName}Controller extends BaseController {
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody ${ClassName}Bo bo) {
|
||||
#if($enableUnique)
|
||||
if (!${className}Service.checkUnique(bo)) {
|
||||
return R.fail("新增${functionName}失败,组合唯一字段已存在");
|
||||
}
|
||||
#end
|
||||
return toAjax(${className}Service.insertByBo(bo));
|
||||
}
|
||||
|
||||
@@ -97,9 +108,38 @@ public class ${ClassName}Controller extends BaseController {
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody ${ClassName}Bo bo) {
|
||||
#if($enableUnique)
|
||||
if (!${className}Service.checkUnique(bo)) {
|
||||
return R.fail("修改${functionName}失败,组合唯一字段已存在");
|
||||
}
|
||||
#end
|
||||
return toAjax(${className}Service.updateByBo(bo));
|
||||
}
|
||||
|
||||
#if($enableStatus)
|
||||
/**
|
||||
* 修改${functionName}状态
|
||||
*/
|
||||
@SaCheckPermission("${permissionPrefix}:edit")
|
||||
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public R<Void> changeStatus(@RequestBody ${ClassName}Bo bo) {
|
||||
return toAjax(${className}Service.updateStatus(bo.get${pkColumn.capJavaField}(), bo.get${statusColumn.capJavaField}()));
|
||||
}
|
||||
#end
|
||||
|
||||
#if($enableSort)
|
||||
/**
|
||||
* 调整${functionName}排序
|
||||
*/
|
||||
@SaCheckPermission("${permissionPrefix}:edit")
|
||||
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/updateSort")
|
||||
public R<Void> updateSort(@RequestBody ${ClassName}Bo bo) {
|
||||
return toAjax(${className}Service.updateSort(bo.get${pkColumn.capJavaField}(), bo.get${sortColumn.capJavaField}()));
|
||||
}
|
||||
#end
|
||||
|
||||
/**
|
||||
* 删除${functionName}
|
||||
*
|
||||
|
||||
@@ -38,6 +38,8 @@ public class ${ClassName} extends ${Entity} {
|
||||
#end
|
||||
#if($column.isPk==1)
|
||||
@TableId(value = "$column.columnName")
|
||||
#elseif($column.needTableField)
|
||||
@TableField(value = "$column.columnName")
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
|
||||
@@ -45,6 +45,16 @@ public interface I${ClassName}Service {
|
||||
*/
|
||||
List<${ClassName}Vo> queryList(${ClassName}Bo bo);
|
||||
|
||||
#if($enableUnique)
|
||||
/**
|
||||
* 校验${functionName}是否满足组合唯一约束
|
||||
*
|
||||
* @param bo ${functionName}
|
||||
* @return 是否唯一
|
||||
*/
|
||||
boolean checkUnique(${ClassName}Bo bo);
|
||||
#end
|
||||
|
||||
/**
|
||||
* 新增${functionName}
|
||||
*
|
||||
@@ -61,6 +71,28 @@ public interface I${ClassName}Service {
|
||||
*/
|
||||
Boolean updateByBo(${ClassName}Bo bo);
|
||||
|
||||
#if($enableStatus)
|
||||
/**
|
||||
* 修改${functionName}状态
|
||||
*
|
||||
* @param ${pkColumn.javaField} 主键
|
||||
* @param status 状态值
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
Boolean updateStatus(${pkColumn.javaType} ${pkColumn.javaField}, ${statusColumn.javaType} status);
|
||||
#end
|
||||
|
||||
#if($enableSort)
|
||||
/**
|
||||
* 调整${functionName}排序
|
||||
*
|
||||
* @param ${pkColumn.javaField} 主键
|
||||
* @param sortValue 排序值
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
Boolean updateSort(${pkColumn.javaType} ${pkColumn.javaField}, ${sortColumn.javaType} sortValue);
|
||||
#end
|
||||
|
||||
/**
|
||||
* 校验并批量删除${functionName}信息
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ${packageName}.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
#if($table.crud)
|
||||
@@ -7,6 +8,9 @@ import org.dromara.common.core.domain.PageResult;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
#end
|
||||
#if($enableStatus || $enableSort)
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
#end
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -17,7 +21,11 @@ import ${packageName}.domain.vo.${ClassName}Vo;
|
||||
import ${packageName}.domain.${ClassName};
|
||||
import ${packageName}.mapper.${ClassName}Mapper;
|
||||
import ${packageName}.service.I${ClassName}Service;
|
||||
#if($table.tree)
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
#end
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
@@ -35,6 +43,19 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
|
||||
private final ${ClassName}Mapper baseMapper;
|
||||
|
||||
#set($TreeParentCap = "")
|
||||
#if("" != $treeParentCode)
|
||||
#set($TreeParentCap = $treeParentCode.substring(0,1).toUpperCase() + $treeParentCode.substring(1))
|
||||
#end
|
||||
#set($TreeAncestorsCap = "")
|
||||
#if("" != $treeAncestorsField)
|
||||
#set($TreeAncestorsCap = $treeAncestorsField.substring(0,1).toUpperCase() + $treeAncestorsField.substring(1))
|
||||
#end
|
||||
#set($TreeOrderCap = "")
|
||||
#if("" != $treeOrderField)
|
||||
#set($TreeOrderCap = $treeOrderField.substring(0,1).toUpperCase() + $treeOrderField.substring(1))
|
||||
#end
|
||||
|
||||
/**
|
||||
* 查询${functionName}
|
||||
*
|
||||
@@ -42,7 +63,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
* @return ${functionName}
|
||||
*/
|
||||
@Override
|
||||
public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||
public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
||||
return baseMapper.selectVoById(${pkColumn.javaField});
|
||||
}
|
||||
|
||||
@@ -74,7 +95,37 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
#if($enableUnique)
|
||||
/**
|
||||
* 校验${functionName}是否满足组合唯一约束
|
||||
*
|
||||
* @param bo ${functionName}
|
||||
* @return 是否唯一
|
||||
*/
|
||||
@Override
|
||||
public boolean checkUnique(${ClassName}Bo bo) {
|
||||
boolean hasUniqueValue = true;
|
||||
#foreach($column in $uniqueColumns)
|
||||
#if($column.javaType == 'String')
|
||||
hasUniqueValue = hasUniqueValue && StringUtils.isNotBlank(bo.get${column.capJavaField}());
|
||||
#else
|
||||
hasUniqueValue = hasUniqueValue && bo.get${column.capJavaField}() != null;
|
||||
#end
|
||||
#end
|
||||
if (!hasUniqueValue) {
|
||||
return true;
|
||||
}
|
||||
LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery();
|
||||
#foreach($column in $uniqueColumns)
|
||||
lqw.eq(${ClassName}::get${column.capJavaField}, bo.get${column.capJavaField}());
|
||||
#end
|
||||
lqw.ne(bo.get${pkColumn.capJavaField}() != null, ${ClassName}::get${pkColumn.capJavaField}, bo.get${pkColumn.capJavaField}());
|
||||
return !baseMapper.exists(lqw);
|
||||
}
|
||||
#end
|
||||
|
||||
private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName}Bo bo) {
|
||||
#set($hasBetween = false)
|
||||
#foreach ($column in $columns)
|
||||
#if($column.query && $column.queryType == 'BETWEEN')
|
||||
#set($hasBetween = true)
|
||||
@@ -87,10 +138,8 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
#foreach($column in $columns)
|
||||
#if($column.query)
|
||||
#set($queryType=$column.queryType)
|
||||
#set($javaField=$column.javaField)
|
||||
#set($javaType=$column.javaType)
|
||||
#set($columnName=$column.columnName)
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#set($AttrName=$column.capJavaField)
|
||||
#set($mpMethod=$column.queryType.toLowerCase())
|
||||
#if($queryType != 'BETWEEN')
|
||||
#if($javaType == 'String')
|
||||
@@ -101,14 +150,22 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName());
|
||||
#else
|
||||
lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null,
|
||||
${ClassName}::get$AttrName ,params.get("begin$AttrName"), params.get("end$AttrName"));
|
||||
${ClassName}::get$AttrName, params.get("begin$AttrName"), params.get("end$AttrName"));
|
||||
#end
|
||||
#end
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#if($column.isPk==1)
|
||||
lqw.orderByAsc(${ClassName}::get$AttrName);
|
||||
#end
|
||||
#if($table.tree && "" != $treeAncestorsField)
|
||||
lqw.orderByAsc(${ClassName}::get${TreeAncestorsCap});
|
||||
#end
|
||||
#if($table.tree && "" != $treeParentCode)
|
||||
lqw.orderByAsc(${ClassName}::get${TreeParentCap});
|
||||
#end
|
||||
#if($table.tree && "" != $treeOrderField)
|
||||
lqw.orderByAsc(${ClassName}::get${TreeOrderCap});
|
||||
#elseif($enableSort)
|
||||
lqw.orderByAsc(${ClassName}::get${sortColumn.capJavaField});
|
||||
#end
|
||||
lqw.orderByAsc(${ClassName}::get${pkColumn.capJavaField});
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@@ -121,11 +178,13 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
@Override
|
||||
public Boolean insertByBo(${ClassName}Bo bo) {
|
||||
${ClassName} add = MapstructUtils.convert(bo, ${ClassName}.class);
|
||||
#if($table.tree)
|
||||
fillTreeMetaBeforeSave(add, false);
|
||||
#end
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
#set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)})
|
||||
if (flag) {
|
||||
bo.set$pk(add.get$pk());
|
||||
bo.set${pkColumn.capJavaField}(add.get${pkColumn.capJavaField}());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
@@ -139,17 +198,133 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
@Override
|
||||
public Boolean updateByBo(${ClassName}Bo bo) {
|
||||
${ClassName} update = MapstructUtils.convert(bo, ${ClassName}.class);
|
||||
#if($table.tree)
|
||||
fillTreeMetaBeforeSave(update, true);
|
||||
#end
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
#if($enableStatus)
|
||||
/**
|
||||
* 修改${functionName}状态
|
||||
*
|
||||
* @param ${pkColumn.javaField} 主键
|
||||
* @param status 状态值
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateStatus(${pkColumn.javaType} ${pkColumn.javaField}, ${statusColumn.javaType} status) {
|
||||
return baseMapper.update(null, new LambdaUpdateWrapper<${ClassName}>()
|
||||
.set(${ClassName}::get${statusColumn.capJavaField}, status)
|
||||
.eq(${ClassName}::get${pkColumn.capJavaField}, ${pkColumn.javaField})) > 0;
|
||||
}
|
||||
#end
|
||||
|
||||
#if($enableSort)
|
||||
/**
|
||||
* 调整${functionName}排序
|
||||
*
|
||||
* @param ${pkColumn.javaField} 主键
|
||||
* @param sortValue 排序值
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateSort(${pkColumn.javaType} ${pkColumn.javaField}, ${sortColumn.javaType} sortValue) {
|
||||
return baseMapper.update(null, new LambdaUpdateWrapper<${ClassName}>()
|
||||
.set(${ClassName}::get${sortColumn.capJavaField}, sortValue)
|
||||
.eq(${ClassName}::get${pkColumn.capJavaField}, ${pkColumn.javaField})) > 0;
|
||||
}
|
||||
#end
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(${ClassName} entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
private void validEntityBeforeSave(${ClassName} entity) {
|
||||
// 可在此扩展通用业务校验
|
||||
}
|
||||
|
||||
#if($table.tree)
|
||||
private void fillTreeMetaBeforeSave(${ClassName} entity, boolean updateMode) {
|
||||
#if("" != $treeParentCode)
|
||||
if (entity.get${TreeParentCap}() == null) {
|
||||
entity.set${TreeParentCap}(${treeRootValueJavaLiteral});
|
||||
}
|
||||
if (ObjectUtil.equal(entity.get${pkColumn.capJavaField}(), entity.get${TreeParentCap}())) {
|
||||
throw new ServiceException("${functionName}父节点不能选择自身");
|
||||
}
|
||||
#if("" != $treeAncestorsField)
|
||||
${ClassName} parent = null;
|
||||
if (!ObjectUtil.equal(entity.get${TreeParentCap}(), ${treeRootValueJavaLiteral})) {
|
||||
parent = baseMapper.selectById(entity.get${TreeParentCap}());
|
||||
if (ObjectUtil.isNull(parent)) {
|
||||
throw new ServiceException("${functionName}父节点不存在");
|
||||
}
|
||||
}
|
||||
if (updateMode && entity.get${pkColumn.capJavaField}() != null && ObjectUtil.isNotNull(parent)
|
||||
&& containsAncestor(parent.get${TreeAncestorsCap}(), entity.get${pkColumn.capJavaField}())) {
|
||||
throw new ServiceException("不能选择当前节点或其子节点作为父节点");
|
||||
}
|
||||
String newAncestors = resolveAncestors(entity.get${TreeParentCap}(), parent);
|
||||
if (updateMode && entity.get${pkColumn.capJavaField}() != null) {
|
||||
${ClassName} oldEntity = baseMapper.selectById(entity.get${pkColumn.capJavaField}());
|
||||
if (ObjectUtil.isNull(oldEntity)) {
|
||||
throw new ServiceException("${functionName}不存在,无法修改");
|
||||
}
|
||||
String oldAncestors = oldEntity.get${TreeAncestorsCap}();
|
||||
entity.set${TreeAncestorsCap}(newAncestors);
|
||||
if (!StringUtils.equals(oldAncestors, newAncestors)) {
|
||||
updateChildrenAncestors(entity.get${pkColumn.capJavaField}(), newAncestors, oldAncestors);
|
||||
}
|
||||
} else {
|
||||
entity.set${TreeAncestorsCap}(newAncestors);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
}
|
||||
#if("" != $treeAncestorsField)
|
||||
|
||||
private String resolveAncestors(${treeParentColumn.javaType} parentId, ${ClassName} parent) {
|
||||
if (ObjectUtil.equal(parentId, ${treeRootValueJavaLiteral})) {
|
||||
return "${treeRootValue}";
|
||||
}
|
||||
String parentAncestors = parent.get${TreeAncestorsCap}();
|
||||
if (StringUtils.isBlank(parentAncestors)) {
|
||||
return String.valueOf(parentId);
|
||||
}
|
||||
return parentAncestors + StringUtils.SEPARATOR + parentId;
|
||||
}
|
||||
|
||||
private void updateChildrenAncestors(${pkColumn.javaType} currentId, String newAncestors, String oldAncestors) {
|
||||
List<${ClassName}> children = baseMapper.selectList(new LambdaQueryWrapper<${ClassName}>()
|
||||
.select(${ClassName}::get${pkColumn.capJavaField}, ${ClassName}::get${TreeAncestorsCap}()));
|
||||
List<${ClassName}> updateList = new ArrayList<>();
|
||||
for (${ClassName} child : children) {
|
||||
String ancestors = child.get${TreeAncestorsCap}();
|
||||
if (StringUtils.isBlank(ancestors) || !containsAncestor(ancestors, currentId)) {
|
||||
continue;
|
||||
}
|
||||
${ClassName} update = new ${ClassName}();
|
||||
update.set${pkColumn.capJavaField}(child.get${pkColumn.capJavaField}());
|
||||
update.set${TreeAncestorsCap}(StringUtils.replaceOnce(ancestors, oldAncestors, newAncestors));
|
||||
updateList.add(update);
|
||||
}
|
||||
if (!updateList.isEmpty()) {
|
||||
baseMapper.updateBatchById(updateList);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean containsAncestor(String ancestors, ${pkColumn.javaType} nodeId) {
|
||||
for (String item : StringUtils.splitList(ancestors)) {
|
||||
if (StringUtils.equals(item, String.valueOf(nodeId))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
/**
|
||||
* 校验并批量删除${functionName}信息
|
||||
*
|
||||
@@ -159,8 +334,8 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
if (isValid) {
|
||||
// 可在此扩展删除前业务校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,42 @@ export const update${BusinessName} = (data: ${BusinessName}Form) => {
|
||||
});
|
||||
};
|
||||
|
||||
#if($enableStatus)
|
||||
/**
|
||||
* 修改${functionName}状态
|
||||
* @param ${pkColumn.javaField}
|
||||
* @param status
|
||||
*/
|
||||
export const change${BusinessName}Status = (${pkColumn.javaField}: string | number, status: #if($statusColumn.javaType == 'String')string#else number#end) => {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}/changeStatus',
|
||||
method: 'put',
|
||||
data: {
|
||||
${pkColumn.javaField},
|
||||
${statusField}: status
|
||||
}
|
||||
});
|
||||
};
|
||||
#end
|
||||
|
||||
#if($enableSort)
|
||||
/**
|
||||
* 调整${functionName}排序
|
||||
* @param ${pkColumn.javaField}
|
||||
* @param sortValue
|
||||
*/
|
||||
export const update${BusinessName}Sort = (${pkColumn.javaField}: string | number, sortValue: #if($sortColumn.javaType == 'String' || $sortColumn.javaType == 'LocalDateTime')string#else number#end) => {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}/updateSort',
|
||||
method: 'put',
|
||||
data: {
|
||||
${pkColumn.javaField},
|
||||
${sortField}: sortValue
|
||||
}
|
||||
});
|
||||
};
|
||||
#end
|
||||
|
||||
/**
|
||||
* 删除${functionName}
|
||||
* @param ${pkColumn.javaField}
|
||||
|
||||
@@ -22,12 +22,37 @@
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-input v-model="queryParams.${column.javaField}" placeholder="请输入${comment}" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "inputNumber")
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-input-number v-model="queryParams.${column.javaField}" controls-position="right" />
|
||||
</el-form-item>
|
||||
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||
<el-option v-for="dict in ${dictType}" :key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "switch" && "" != $dictType)
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||
<el-option v-for="dict in ${dictType}" :key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "switch")
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||
#if($column.javaType == "Boolean")
|
||||
<el-option label="是" :value="true" />
|
||||
<el-option label="否" :value="false" />
|
||||
#elseif($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
<el-option label="开启" :value="0" />
|
||||
<el-option label="关闭" :value="1" />
|
||||
#else
|
||||
<el-option label="开启" value="0" />
|
||||
<el-option label="关闭" value="1" />
|
||||
#end
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||
@@ -75,6 +100,9 @@
|
||||
<div class="toolbar-actions">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd()" v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
|
||||
<el-button type="info" plain icon="Sort" @click="handleToggleExpandAll">展开/折叠</el-button>
|
||||
#if($enableExport)
|
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['${moduleName}:${businessName}:export']">导出</el-button>
|
||||
#end
|
||||
<right-toolbar v-model:show-search="showSearch" :search="false" @query-table="getList"></right-toolbar>
|
||||
</div>
|
||||
</div>
|
||||
@@ -104,6 +132,64 @@
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if($column.pk)
|
||||
#elseif($enableStatus && $statusField == $javaField)
|
||||
#if($javaField == $firstTreeListField)
|
||||
<el-table-column label="${comment}" prop="${javaField}">
|
||||
#else
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||
#end
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.${javaField}"
|
||||
:active-value="${statusField}ActiveValue"
|
||||
:inactive-value="${statusField}InactiveValue"
|
||||
@change="handleStatusChange(scope.row)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($enableSort && $sortField == $javaField)
|
||||
#if($javaField == $firstTreeListField)
|
||||
<el-table-column label="${comment}" prop="${javaField}" width="160">
|
||||
#else
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="160">
|
||||
#end
|
||||
<template #default="scope">
|
||||
#if($column.javaType == "LocalDateTime")
|
||||
<el-date-picker
|
||||
v-model="scope.row.${javaField}"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="选择${comment}"
|
||||
@change="handleSortChange(scope.row)"
|
||||
/>
|
||||
#else
|
||||
<el-input-number v-model="scope.row.${javaField}" controls-position="right" :min="0" @change="handleSortChange(scope.row)" />
|
||||
#end
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.list && $column.htmlType == "switch")
|
||||
#if($javaField == $firstTreeListField)
|
||||
<el-table-column label="${comment}" prop="${javaField}" width="120">
|
||||
#else
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="120">
|
||||
#end
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.${javaField}"
|
||||
#if($column.javaType == "Boolean")
|
||||
:active-value="true"
|
||||
:inactive-value="false"
|
||||
#elseif($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:active-value="0"
|
||||
:inactive-value="1"
|
||||
#else
|
||||
active-value="0"
|
||||
inactive-value="1"
|
||||
#end
|
||||
disabled
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.list && $column.htmlType == "datetime")
|
||||
#if($javaField == $firstTreeListField)
|
||||
<el-table-column label="${comment}" prop="${javaField}" width="180">
|
||||
@@ -124,7 +210,7 @@
|
||||
<image-preview :src="scope.row.${javaField}Url" :width="50" :height="50"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.list && $column.dictType && "" != $column.dictType)
|
||||
#elseif($column.list && $column.dictColumn)
|
||||
#if($javaField == $firstTreeListField)
|
||||
<el-table-column label="${comment}" prop="${javaField}">
|
||||
#else
|
||||
@@ -145,6 +231,35 @@
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($enableStatus && !$statusColumn.list)
|
||||
<el-table-column label="${statusColumn.columnComment}" align="center" prop="${statusField}">
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.${statusField}"
|
||||
:active-value="${statusField}ActiveValue"
|
||||
:inactive-value="${statusField}InactiveValue"
|
||||
@change="handleStatusChange(scope.row)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#end
|
||||
#if($enableSort && !$sortColumn.list)
|
||||
<el-table-column label="${sortColumn.columnComment}" align="center" prop="${sortField}" width="160">
|
||||
<template #default="scope">
|
||||
#if($sortColumn.javaType == "LocalDateTime")
|
||||
<el-date-picker
|
||||
v-model="scope.row.${sortField}"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="选择${sortColumn.columnComment}"
|
||||
@change="handleSortChange(scope.row)"
|
||||
/>
|
||||
#else
|
||||
<el-input-number v-model="scope.row.${sortField}" controls-position="right" :min="0" @change="handleSortChange(scope.row)" />
|
||||
#end
|
||||
</template>
|
||||
</el-table-column>
|
||||
#end
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
@@ -189,6 +304,10 @@
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "inputNumber")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-input-number v-model="form.${field}" controls-position="right" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "imageUpload")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<image-upload v-model="form.${field}"/>
|
||||
@@ -259,6 +378,22 @@
|
||||
<el-radio value="1">请选择字典生成</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "switch")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-switch
|
||||
v-model="form.${field}"
|
||||
#if($column.javaType == "Boolean")
|
||||
:active-value="true"
|
||||
:inactive-value="false"
|
||||
#elseif($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:active-value="0"
|
||||
:inactive-value="1"
|
||||
#else
|
||||
active-value="0"
|
||||
inactive-value="1"
|
||||
#end
|
||||
/>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "datetime")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-date-picker clearable
|
||||
@@ -293,7 +428,19 @@
|
||||
#end
|
||||
#end
|
||||
<script setup name="${BusinessName}" lang="ts">
|
||||
import { add${BusinessName}, del${BusinessName}, get${BusinessName}, list${BusinessName}, update${BusinessName} } from '@/api/${moduleName}/${businessName}';
|
||||
import {
|
||||
add${BusinessName},
|
||||
#if($enableStatus)
|
||||
change${BusinessName}Status,
|
||||
#end
|
||||
del${BusinessName},
|
||||
get${BusinessName},
|
||||
list${BusinessName},
|
||||
#if($enableSort)
|
||||
update${BusinessName}Sort,
|
||||
#end
|
||||
update${BusinessName}
|
||||
} from '@/api/${moduleName}/${businessName}';
|
||||
import { ${BusinessName}Form, ${BusinessName}Query, ${BusinessName}VO } from '@/api/${moduleName}/${businessName}/types';
|
||||
import { useLoading } from '@/hooks/async/useLoading';
|
||||
import { useFormDialog } from '@/hooks/dialog/useFormDialog';
|
||||
@@ -308,20 +455,29 @@ import { useDict } from '@/utils/dict';
|
||||
#end
|
||||
import modal from '@/plugins/modal';
|
||||
import { handleTree } from '@/utils/ruoyi';
|
||||
#if($enableExport)
|
||||
import { download as requestDownload } from '@/utils/request';
|
||||
#end
|
||||
|
||||
#if(${dicts} != '')
|
||||
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
||||
const { ${dictsNoSymbol} } = toRefs<any>(useDict(${dicts}));
|
||||
#end
|
||||
|
||||
#if($enableStatus)
|
||||
const ${statusField}ActiveValue = #if($statusColumn.javaType == "Boolean")true#elseif($statusColumn.javaType == "Integer" || $statusColumn.javaType == "Long")0#else'0'#end;
|
||||
const ${statusField}InactiveValue = #if($statusColumn.javaType == "Boolean")false#elseif($statusColumn.javaType == "Integer" || $statusColumn.javaType == "Long")1#else'1'#end;
|
||||
#end
|
||||
|
||||
type ${BusinessName}Option = {
|
||||
${treeCode}: number;
|
||||
${treeCode}: #if($treeParentColumn.javaType == 'String')string#else number#end;
|
||||
${treeName}: string;
|
||||
children?: ${BusinessName}Option[];
|
||||
};
|
||||
|
||||
const ${businessName}List = ref<${BusinessName}VO[]>([]);
|
||||
const ${businessName}Options = ref<${BusinessName}Option[]>([]);
|
||||
const all${BusinessName}Options = ref<${BusinessName}Option[]>([]);
|
||||
const buttonLoading = ref(false);
|
||||
const { showSearch } = useSearchToggle();
|
||||
const { loading, setLoading, withLoading } = useLoading();
|
||||
@@ -388,7 +544,7 @@ const data = reactive<PageData<${BusinessName}Form, ${BusinessName}Query>>({
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
$column.javaField: [
|
||||
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
|
||||
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio" || $column.htmlType == "switch" || $column.htmlType == "inputNumber")"change"#else"blur"#end }
|
||||
]#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
@@ -426,12 +582,12 @@ const getList = async () => {
|
||||
};
|
||||
|
||||
/** 查询${functionName}下拉树结构 */
|
||||
const getTreeselect = async () => {
|
||||
const getTreeselect = async (excludeId?: string | number) => {
|
||||
const res = await list${BusinessName}();
|
||||
${businessName}Options.value = [];
|
||||
const data: ${BusinessName}Option = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
|
||||
const data: ${BusinessName}Option = { ${treeCode}: ${treeRootValueTsLiteral}, ${treeName}: '顶级节点', children: [] };
|
||||
data.children = handleTree<${BusinessName}Option>(res.data, '${treeCode}', '${treeParentCode}');
|
||||
${businessName}Options.value.push(data);
|
||||
all${BusinessName}Options.value = [data];
|
||||
${businessName}Options.value = excludeId != null ? filterTreeOptions(all${BusinessName}Options.value, excludeId) : all${BusinessName}Options.value;
|
||||
};
|
||||
|
||||
/** 取消按钮 */
|
||||
@@ -468,14 +624,14 @@ const handleAdd = (row?: ${BusinessName}VO) => {
|
||||
if (row != null && row.${treeCode}) {
|
||||
form.value.${treeParentCode} = row.${treeCode};
|
||||
} else {
|
||||
form.value.${treeParentCode} = 0;
|
||||
form.value.${treeParentCode} = ${treeRootValueTsLiteral};
|
||||
}
|
||||
};
|
||||
|
||||
/** 修改按钮操作 */
|
||||
const handleUpdate = async (row: ${BusinessName}VO) => {
|
||||
reset();
|
||||
await getTreeselect();
|
||||
await getTreeselect(row.${treeCode});
|
||||
if (row != null) {
|
||||
form.value.${treeParentCode} = row.${treeParentCode};
|
||||
}
|
||||
@@ -520,6 +676,54 @@ const handleDelete = async (row: ${BusinessName}VO) => {
|
||||
modal.msgSuccess('删除成功');
|
||||
};
|
||||
|
||||
const filterTreeOptions = (options: ${BusinessName}Option[], excludeId: string | number): ${BusinessName}Option[] => {
|
||||
return options
|
||||
.filter(item => item.${treeCode} !== excludeId)
|
||||
.map(item => ({
|
||||
...item,
|
||||
children: item.children ? filterTreeOptions(item.children, excludeId) : []
|
||||
}));
|
||||
};
|
||||
|
||||
#if($enableStatus)
|
||||
/** 状态修改 */
|
||||
const handleStatusChange = async (row: ${BusinessName}VO) => {
|
||||
const text = row.${statusField} === ${statusField}ActiveValue ? '启用' : '停用';
|
||||
try {
|
||||
await modal.confirm('确认要"' + text + '"吗?');
|
||||
await change${BusinessName}Status(row.${pkColumn.javaField}, row.${statusField});
|
||||
modal.msgSuccess(text + '成功');
|
||||
} catch (err) {
|
||||
row.${statusField} = row.${statusField} === ${statusField}ActiveValue ? ${statusField}InactiveValue : ${statusField}ActiveValue;
|
||||
}
|
||||
};
|
||||
#end
|
||||
|
||||
#if($enableSort)
|
||||
/** 排序调整 */
|
||||
const handleSortChange = async (row: ${BusinessName}VO) => {
|
||||
try {
|
||||
await update${BusinessName}Sort(row.${pkColumn.javaField}, row.${sortField});
|
||||
modal.msgSuccess('排序更新成功');
|
||||
} catch (err) {
|
||||
await getList();
|
||||
}
|
||||
};
|
||||
#end
|
||||
|
||||
#if($enableExport)
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = () => {
|
||||
requestDownload(
|
||||
'${moduleName}/${businessName}/export',
|
||||
{
|
||||
...queryParams.value
|
||||
},
|
||||
`${businessName}_#[[${new Date().getTime()}]]#.xlsx`
|
||||
);
|
||||
};
|
||||
#end
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
|
||||
@@ -22,12 +22,37 @@
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-input v-model="queryParams.${column.javaField}" placeholder="请输入${comment}" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "inputNumber")
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-input-number v-model="queryParams.${column.javaField}" controls-position="right" />
|
||||
</el-form-item>
|
||||
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable >
|
||||
<el-option v-for="dict in ${dictType}" :key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "switch" && "" != $dictType)
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable >
|
||||
<el-option v-for="dict in ${dictType}" :key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "switch")
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable >
|
||||
#if($column.javaType == "Boolean")
|
||||
<el-option label="是" :value="true" />
|
||||
<el-option label="否" :value="false" />
|
||||
#elseif($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
<el-option label="开启" :value="0" />
|
||||
<el-option label="关闭" :value="1" />
|
||||
#else
|
||||
<el-option label="开启" value="0" />
|
||||
<el-option label="关闭" value="1" />
|
||||
#end
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable >
|
||||
@@ -76,7 +101,9 @@
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
|
||||
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['${moduleName}:${businessName}:edit']">修改</el-button>
|
||||
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['${moduleName}:${businessName}:remove']">删除</el-button>
|
||||
#if($enableExport)
|
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['${moduleName}:${businessName}:export']">导出</el-button>
|
||||
#end
|
||||
<right-toolbar v-model:show-search="showSearch" :search="false" @query-table="getList"></right-toolbar>
|
||||
</div>
|
||||
</div>
|
||||
@@ -94,6 +121,52 @@
|
||||
#end
|
||||
#if($column.pk)
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" v-if="${column.list}" />
|
||||
#elseif($enableStatus && $statusField == $javaField)
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.${javaField}"
|
||||
:active-value="${statusField}ActiveValue"
|
||||
:inactive-value="${statusField}InactiveValue"
|
||||
@change="handleStatusChange(scope.row)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($enableSort && $sortField == $javaField)
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="160">
|
||||
<template #default="scope">
|
||||
#if($column.javaType == "LocalDateTime")
|
||||
<el-date-picker
|
||||
v-model="scope.row.${javaField}"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="选择${comment}"
|
||||
@change="handleSortChange(scope.row)"
|
||||
/>
|
||||
#else
|
||||
<el-input-number v-model="scope.row.${javaField}" controls-position="right" :min="0" @change="handleSortChange(scope.row)" />
|
||||
#end
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.list && $column.htmlType == "switch")
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="120">
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.${javaField}"
|
||||
#if($column.javaType == "Boolean")
|
||||
:active-value="true"
|
||||
:inactive-value="false"
|
||||
#elseif($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:active-value="0"
|
||||
:inactive-value="1"
|
||||
#else
|
||||
active-value="0"
|
||||
inactive-value="1"
|
||||
#end
|
||||
disabled
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.list && $column.htmlType == "datetime")
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
||||
<template #default="scope">
|
||||
@@ -106,7 +179,7 @@
|
||||
<image-preview :src="scope.row.${javaField}Url" :width="50" :height="50"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.list && $column.dictType && "" != $column.dictType)
|
||||
#elseif($column.list && $column.dictColumn)
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||
<template #default="scope">
|
||||
#if($column.htmlType == "checkbox")
|
||||
@@ -119,6 +192,43 @@
|
||||
#elseif($column.list && "" != $javaField)
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||
#end
|
||||
#end
|
||||
#if($enableStatus && !$statusColumn.list)
|
||||
<el-table-column label="${statusColumn.columnComment}" align="center" prop="${statusField}">
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.${statusField}"
|
||||
#if($statusColumn.javaType == "Boolean")
|
||||
:active-value="true"
|
||||
:inactive-value="false"
|
||||
#elseif($statusColumn.javaType == "Integer" || $statusColumn.javaType == "Long")
|
||||
:active-value="0"
|
||||
:inactive-value="1"
|
||||
#else
|
||||
active-value="0"
|
||||
inactive-value="1"
|
||||
#end
|
||||
@change="handleStatusChange(scope.row)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#end
|
||||
#if($enableSort && !$sortColumn.list)
|
||||
<el-table-column label="${sortColumn.columnComment}" align="center" prop="${sortField}" width="160">
|
||||
<template #default="scope">
|
||||
#if($sortColumn.javaType == "LocalDateTime")
|
||||
<el-date-picker
|
||||
v-model="scope.row.${sortField}"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="选择${sortColumn.columnComment}"
|
||||
@change="handleSortChange(scope.row)"
|
||||
/>
|
||||
#else
|
||||
<el-input-number v-model="scope.row.${sortField}" controls-position="right" :min="0" @change="handleSortChange(scope.row)" />
|
||||
#end
|
||||
</template>
|
||||
</el-table-column>
|
||||
#end
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
@@ -151,6 +261,10 @@
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "inputNumber")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-input-number v-model="form.${field}" controls-position="right" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "imageUpload")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<image-upload v-model="form.${field}"/>
|
||||
@@ -221,6 +335,22 @@
|
||||
<el-radio value="1">请选择字典生成</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "switch")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-switch
|
||||
v-model="form.${field}"
|
||||
#if($column.javaType == "Boolean")
|
||||
:active-value="true"
|
||||
:inactive-value="false"
|
||||
#elseif($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:active-value="0"
|
||||
:inactive-value="1"
|
||||
#else
|
||||
active-value="0"
|
||||
inactive-value="1"
|
||||
#end
|
||||
/>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "datetime")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-date-picker clearable
|
||||
@@ -255,7 +385,19 @@
|
||||
#end
|
||||
#end
|
||||
<script setup name="${BusinessName}" lang="ts">
|
||||
import { add${BusinessName}, del${BusinessName}, get${BusinessName}, list${BusinessName}, update${BusinessName} } from '@/api/${moduleName}/${businessName}';
|
||||
import {
|
||||
add${BusinessName},
|
||||
#if($enableStatus)
|
||||
change${BusinessName}Status,
|
||||
#end
|
||||
del${BusinessName},
|
||||
get${BusinessName},
|
||||
list${BusinessName},
|
||||
#if($enableSort)
|
||||
update${BusinessName}Sort,
|
||||
#end
|
||||
update${BusinessName}
|
||||
} from '@/api/${moduleName}/${businessName}';
|
||||
import { ${BusinessName}Form, ${BusinessName}Query, ${BusinessName}VO } from '@/api/${moduleName}/${businessName}/types';
|
||||
import { useLoading } from '@/hooks/async/useLoading';
|
||||
import { useFormDialog } from '@/hooks/dialog/useFormDialog';
|
||||
@@ -269,13 +411,20 @@ import { useTableSelection } from '@/hooks/table/useTableSelection';
|
||||
import { useDict } from '@/utils/dict';
|
||||
#end
|
||||
import modal from '@/plugins/modal';
|
||||
#if($enableExport)
|
||||
import { download as requestDownload } from '@/utils/request';
|
||||
#end
|
||||
|
||||
#if(${dicts} != '')
|
||||
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
||||
const { ${dictsNoSymbol} } = toRefs<any>(useDict(${dicts}));
|
||||
#end
|
||||
|
||||
#if($enableStatus)
|
||||
const ${statusField}ActiveValue = #if($statusColumn.javaType == "Boolean")true#elseif($statusColumn.javaType == "Integer" || $statusColumn.javaType == "Long")0#else'0'#end;
|
||||
const ${statusField}InactiveValue = #if($statusColumn.javaType == "Boolean")false#elseif($statusColumn.javaType == "Integer" || $statusColumn.javaType == "Long")1#else'1'#end;
|
||||
#end
|
||||
|
||||
const ${businessName}List = ref<${BusinessName}VO[]>([]);
|
||||
const buttonLoading = ref(false);
|
||||
const { loading, withLoading } = useLoading(true);
|
||||
@@ -339,7 +488,7 @@ const data = reactive<PageData<${BusinessName}Form, ${BusinessName}Query>>({
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
$column.javaField: [
|
||||
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
|
||||
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio" || $column.htmlType == "switch" || $column.htmlType == "inputNumber")"change"#else"blur"#end }
|
||||
]#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
@@ -457,6 +606,7 @@ const handleDelete = async (row?: ${BusinessName}VO) => {
|
||||
};
|
||||
|
||||
/** 导出按钮操作 */
|
||||
#if($enableExport)
|
||||
const handleExport = () => {
|
||||
requestDownload(
|
||||
'${moduleName}/${businessName}/export',
|
||||
@@ -466,6 +616,33 @@ const handleExport = () => {
|
||||
`${businessName}_#[[${new Date().getTime()}]]#.xlsx`
|
||||
);
|
||||
};
|
||||
#end
|
||||
|
||||
#if($enableStatus)
|
||||
/** 状态修改 */
|
||||
const handleStatusChange = async (row: ${BusinessName}VO) => {
|
||||
const text = row.${statusField} === ${statusField}ActiveValue ? '启用' : '停用';
|
||||
try {
|
||||
await modal.confirm('确认要"' + text + '"吗?');
|
||||
await change${BusinessName}Status(row.${pkColumn.javaField}, row.${statusField});
|
||||
modal.msgSuccess(text + '成功');
|
||||
} catch (err) {
|
||||
row.${statusField} = row.${statusField} === ${statusField}ActiveValue ? ${statusField}InactiveValue : ${statusField}ActiveValue;
|
||||
}
|
||||
};
|
||||
#end
|
||||
|
||||
#if($enableSort)
|
||||
/** 排序调整 */
|
||||
const handleSortChange = async (row: ${BusinessName}VO) => {
|
||||
try {
|
||||
await update${BusinessName}Sort(row.${pkColumn.javaField}, row.${sortField});
|
||||
modal.msgSuccess('排序更新成功');
|
||||
} catch (err) {
|
||||
await getList();
|
||||
}
|
||||
};
|
||||
#end
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
|
||||
Reference in New Issue
Block a user