v3.16.0 【新增】优化代码生成 字典和文件预览;【新增】代码生成 菜单SQL;【新增】登录页面GIF炫酷图片

This commit is contained in:
zhuoda
2025-04-06 20:57:30 +08:00
parent a2785fbee7
commit 51069fc130
39 changed files with 331 additions and 144 deletions

View File

@@ -158,7 +158,7 @@ public class CodeGeneratorTemplateService {
CodeDelete deleteInfo = JSON.parseObject(codeGeneratorConfigEntity.getDeleteInfo(), CodeDelete.class);
List<CodeQueryField> queryFields = JSONArray.parseArray(codeGeneratorConfigEntity.getQueryFields(), CodeQueryField.class);
List<CodeTableField> tableFields = JSONArray.parseArray(codeGeneratorConfigEntity.getTableFields(), CodeTableField.class);
tableFields.stream().forEach(e -> e.setWidth(e.getWidth() == null ? 0 : e.getWidth()));
tableFields.forEach(e -> e.setWidth(e.getWidth() == null ? 0 : e.getWidth()));
CodeGeneratorConfigForm form = CodeGeneratorConfigForm.builder().basic(basic).fields(fields).insertAndUpdate(insertAndUpdate).deleteInfo(deleteInfo).queryFields(queryFields).tableFields(tableFields).deleteInfo(deleteInfo).build();
form.setTableName(tableName);

View File

@@ -64,8 +64,7 @@ public abstract class CodeGenerateBaseVariableService {
return null;
}
return fields.stream().filter(e -> columnName.equals(e.getColumnName()))
.findFirst().get();
return fields.stream().filter(e -> SmartStringUtil.equals(columnName, e.getColumnName())).findFirst().orElse(null);
}
@@ -89,7 +88,7 @@ public abstract class CodeGenerateBaseVariableService {
}
CodeInsertAndUpdateField field = first.get();
return SmartStringUtil.equals(field.getFrontComponent(), CodeFrontComponentEnum.FILE_UPLOAD.getValue());
return CodeFrontComponentEnum.FILE_UPLOAD.equalsValue(field.getFrontComponent());
}
/**
@@ -114,8 +113,7 @@ public abstract class CodeGenerateBaseVariableService {
return null;
}
Optional<CodeField> first = fields.stream().filter(e -> columnName.equals(e.getColumnName())).findFirst();
return first.orElse(null);
return fields.stream().filter(e -> columnName.equals(e.getColumnName())).findFirst().orElse(null);
}
/**

View File

@@ -67,6 +67,7 @@ public class FormVariableService extends CodeGenerateBaseVariableService {
if (CodeFrontComponentEnum.DICT_SELECT.equalsValue(field.getFrontComponent())) {
frontImportSet.add("import DictSelect from '/@/components/support/dict-select/index.vue';");
frontImportSet.add("import { DICT_CODE_ENUM } from '/@/constants/support/dict-const.js';");
}
if (CodeFrontComponentEnum.FILE_UPLOAD.equalsValue(field.getFrontComponent())) {

View File

@@ -2,13 +2,18 @@ package net.lab1024.sa.base.module.support.codegenerator.service.variable.front;
import cn.hutool.core.bean.BeanUtil;
import com.google.common.base.CaseFormat;
import net.lab1024.sa.base.common.util.SmartStringUtil;
import net.lab1024.sa.base.module.support.codegenerator.constant.CodeFrontComponentEnum;
import net.lab1024.sa.base.module.support.codegenerator.constant.CodeQueryFieldQueryTypeEnum;
import net.lab1024.sa.base.module.support.codegenerator.domain.form.CodeGeneratorConfigForm;
import net.lab1024.sa.base.module.support.codegenerator.domain.model.CodeField;
import net.lab1024.sa.base.module.support.codegenerator.domain.model.CodeInsertAndUpdateField;
import net.lab1024.sa.base.module.support.codegenerator.domain.model.CodeQueryField;
import net.lab1024.sa.base.module.support.codegenerator.domain.model.CodeTableField;
import net.lab1024.sa.base.module.support.codegenerator.service.variable.CodeGenerateBaseVariableService;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author 1024创新实验室-主任:卓大
@@ -29,34 +34,74 @@ public class ListVariableService extends CodeGenerateBaseVariableService {
public Map<String, Object> getInjectVariablesMap(CodeGeneratorConfigForm form) {
Map<String, Object> variablesMap = new HashMap<>();
List<Map<String, Object>> variableList = new ArrayList<>();
List<CodeQueryField> queryFields = form.getQueryFields();
HashSet<String> frontImportSet = new HashSet<>();
frontImportSet.add("import " + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, form.getBasic().getModuleName()) + "Form from './" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, form.getBasic().getModuleName()) + "-form.vue';");
// 查询参数
List<Map<String, Object>> queryVariable = new ArrayList<>();
List<CodeQueryField> queryFields = form.getQueryFields();
for (CodeQueryField queryField : queryFields) {
Map<String, Object> objectMap = BeanUtil.beanToMap(queryField);
CodeField codeField = getCodeFieldByColumnName(queryField.getColumnNameList().get(0), form);
objectMap.put("frontEnumName", codeField.getEnumName());
objectMap.put("dict", codeField.getDict());
if(CodeQueryFieldQueryTypeEnum.ENUM.equalsValue(queryField.getQueryTypeEnum())){
if (CodeQueryFieldQueryTypeEnum.ENUM.equalsValue(queryField.getQueryTypeEnum())) {
objectMap.put("frontEnumName", codeField.getEnumName());
frontImportSet.add("import SmartEnumSelect from '/@/components/framework/smart-enum-select/index.vue';");
}
if(CodeQueryFieldQueryTypeEnum.DICT.equalsValue(queryField.getQueryTypeEnum())){
if (CodeQueryFieldQueryTypeEnum.DICT.equalsValue(queryField.getQueryTypeEnum())) {
objectMap.put("dict", codeField.getDict());
frontImportSet.add("import DictSelect from '/@/components/support/dict-select/index.vue';");
}
if(CodeQueryFieldQueryTypeEnum.DATE_RANGE.equalsValue(queryField.getQueryTypeEnum())){
if (CodeQueryFieldQueryTypeEnum.DATE_RANGE.equalsValue(queryField.getQueryTypeEnum())) {
frontImportSet.add("import { defaultTimeRanges } from '/@/lib/default-time-ranges';");
}
variableList.add(objectMap);
queryVariable.add(objectMap);
}
variablesMap.put("queryFields",variableList);
variablesMap.put("frontImportList",new ArrayList<>(frontImportSet));
// 表格列表
List<Map<String, Object>> listVariable = new ArrayList<>();
// 过滤掉不显示的字段
List<CodeTableField> tableFields = form.getTableFields().stream().filter(CodeTableField::getShowFlag).collect(Collectors.toList());
for (CodeTableField tableField : tableFields) {
Map<String, Object> objectMap = BeanUtil.beanToMap(tableField);
objectMap.put("fieldName", tableField.getFieldName());
CodeField codeField = getCodeFieldByColumnName(tableField.getColumnName(), form);
if (codeField == null) {
continue;
}
// 是否存在字典
if (SmartStringUtil.isNotBlank(codeField.getDict())) {
objectMap.put("dict", codeField.getDict());
frontImportSet.add("import { DICT_CODE_ENUM } from '/@/constants/support/dict-const.js';");
frontImportSet.add("import DictLabel from '/@/components/support/dict-label/index.vue';");
}
CodeInsertAndUpdateField codeInsertAndUpdateField = form.getInsertAndUpdate().getFieldList().stream().filter(e -> SmartStringUtil.equals(tableField.getColumnName(), e.getColumnName())).findFirst().orElse(null);
if (codeInsertAndUpdateField == null) {
continue;
}
// 是否存在上传组件
if (CodeFrontComponentEnum.FILE_UPLOAD.equalsValue(codeInsertAndUpdateField.getFrontComponent())) {
objectMap.put("frontComponent", codeInsertAndUpdateField.getFrontComponent());
frontImportSet.add("import FilePreview from '/@/components/support/file-preview/index.vue';");
}
listVariable.add(objectMap);
}
variablesMap.put("queryFields", queryVariable);
variablesMap.put("listFields", listVariable);
variablesMap.put("frontImportList", new ArrayList<>(frontImportSet));
return variablesMap;
}
}

View File

@@ -9,14 +9,14 @@ VALUES ( '${basic.description}', 2, 0, '/${name.lowerHyphenCamel}/list', '/busin
SET @parent_id = NULL;
SELECT t_menu.menu_id INTO @parent_id FROM t_menu WHERE t_menu.menu_name = '${basic.description}';
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
VALUES ( '查询', 3, @parent_id, false, true, true, false, '${name.lowerCamel}:query', 1, @parent_id, 1 );
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, perms_type, api_perms, web_perms, context_menu_id, create_user_id )
VALUES ( '查询', 3, @parent_id, false, false, true, false, 1, '${name.lowerCamel}:query', '${name.lowerCamel}:query', @parent_id, 1 );
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
VALUES ( '添加', 3, @parent_id, false, true, true, false, '${name.lowerCamel}:add', 1, @parent_id, 1 );
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, perms_type, api_perms, web_perms, context_menu_id, create_user_id )
VALUES ( '添加', 3, @parent_id, false, false, true, false, 1, '${name.lowerCamel}:add', '${name.lowerCamel}:add', @parent_id, 1 );
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
VALUES ( '更新', 3, @parent_id, false, true, true, false, '${name.lowerCamel}:update', 1, @parent_id, 1 );
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, perms_type, api_perms, web_perms, context_menu_id, create_user_id )
VALUES ( '更新', 3, @parent_id, false, false, true, false, 1, '${name.lowerCamel}:update', '${name.lowerCamel}:update', @parent_id, 1 );
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
VALUES ( '删除', 3, @parent_id, false, true, true, false, '${name.lowerCamel}:delete', 1, @parent_id, 1 );
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, perms_type, api_perms, web_perms, context_menu_id, create_user_id )
VALUES ( '删除', 3, @parent_id, false, false, true, false, 1, '${name.lowerCamel}:delete', '${name.lowerCamel}:delete', @parent_id, 1 );

View File

@@ -43,12 +43,12 @@
#end
#if($field.frontComponent == "SmartEnumSelect")
<a-form-item label="$codeGeneratorTool.removeEnumDesc($!{field.label})" name="${field.fieldName}">
<SmartEnumSelect width="100%" v-model:value="form.${field.fieldName}" enumName="$!{field.upperUnderscoreEnum}" placeholder="$codeGeneratorTool.removeEnumDesc($!{field.label})"/>
<SmartEnumSelect width="100%" v-model:value="form.${field.fieldName}" enum-name="$!{field.upperUnderscoreEnum}" placeholder="$codeGeneratorTool.removeEnumDesc($!{field.label})"/>
</a-form-item>
#end
#if($field.frontComponent == "DictSelect")
<a-form-item label="$codeGeneratorTool.removeEnumDesc($!{field.label})" name="${field.fieldName}">
<DictSelect width="100%" v-model:value="form.${field.fieldName}" dictCode="$!{field.dict}" placeholder="$!{field.label}"/>
<DictSelect width="100%" v-model:value="form.${field.fieldName}" dict-code="DICT_CODE_ENUM.$!{field.dict} || '$!{field.dict}'" placeholder="$!{field.label}"/>
</a-form-item>
#end
#if($field.frontComponent == "Date")
@@ -101,12 +101,12 @@
#end
#if($field.frontComponent == "SmartEnumSelect")
<a-form-item label="$codeGeneratorTool.removeEnumDesc($!{field.label})" name="${field.fieldName}">
<SmartEnumSelect width="100%" v-model:value="form.${field.fieldName}" enumName="$!{field.upperUnderscoreEnum}" placeholder="$codeGeneratorTool.removeEnumDesc($!{field.label})"/>
<SmartEnumSelect width="100%" v-model:value="form.${field.fieldName}" enum-name="$!{field.upperUnderscoreEnum}" placeholder="$codeGeneratorTool.removeEnumDesc($!{field.label})"/>
</a-form-item>
#end
#if($field.frontComponent == "DictSelect")
<a-form-item label="$codeGeneratorTool.removeEnumDesc($!{field.label})" name="${field.fieldName}">
<DictSelect width="100%" v-model:value="form.${field.fieldName}" dictCode="$!{field.dict}" placeholder="$!{field.label}"/>
<DictSelect width="100%" v-model:value="form.${field.fieldName}" dict-code="DICT_CODE_ENUM.$!{field.dict} || '$!{field.dict}'" placeholder="$!{field.label}"/>
</a-form-item>
#end
#if($field.frontComponent == "Date")

View File

@@ -22,12 +22,12 @@
#end
#if($field.queryTypeEnum == "Dict")
<a-form-item label="${field.label}" class="smart-query-form-item">
<DictSelect dictCode="$!{field.dict}" placeholder="${field.label}" v-model:value="queryForm.${field.fieldName}" width="${field.width}" />
<DictSelect dict-code="DICT_CODE_ENUM.$!{field.dict} || '$!{field.dict}'" placeholder="${field.label}" v-model:value="queryForm.${field.fieldName}" width="${field.width}" />
</a-form-item>
#end
#if($field.queryTypeEnum == "Enum")
<a-form-item label="$codeGeneratorTool.removeEnumDesc(${field.label})" class="smart-query-form-item">
<SmartEnumSelect width="${field.width}" v-model:value="queryForm.${field.fieldName}" enumName="$!{field.frontEnumName}" placeholder="$codeGeneratorTool.removeEnumDesc(${field.label})"/>
<SmartEnumSelect width="${field.width}" v-model:value="queryForm.${field.fieldName}" enum-name="$!{field.frontEnumName}" placeholder="$codeGeneratorTool.removeEnumDesc(${field.label})"/>
</a-form-item>
#end
#if($field.queryTypeEnum == "Date")
@@ -101,18 +101,20 @@
>
<template #bodyCell="{ text, record, column }">
<!-- 有图片预览时 注释解开并把下面的'picture'修改成自己的图片字段名即可 -->
<!-- <template v-if="column.dataIndex === 'picture'">
<FilePreview :fileList="text" type="picture" />
</template> -->
<!-- 使用字典时 注释解开并把下面的'dict'修改成自己的字典字段名即可 有多个字典字段就复制多份同理修改 不然不显示字典 -->
<!-- 方便修改tag的颜色 orange green purple success processing error default warning -->
<!-- <template v-if="column.dataIndex === 'dict'">
<a-tag color="cyan">
{{ text && text.length > 0 ? text.map((e) => e.valueName).join(',') : '暂无' }}
</a-tag>
</template> -->
#foreach ($field in $listFields)
#if($field.frontComponent == "FileUpload")
<template v-if="column.dataIndex === '$field.fieldName'">
<FilePreview :file-list="text" type="picture" />
</template>
#end
#end
#foreach ($field in $listFields)
#if($field.dict)
<template v-if="column.dataIndex === '$!{field.fieldName}'">
<DictLabel :dict-code="DICT_CODE_ENUM.$!{field.dict} || '$!{field.dict}'" :data-value="text" />
</template>
#end
#end
<template v-if="column.dataIndex === 'action'">
<div class="smart-table-operate">
@@ -159,7 +161,6 @@
#foreach ($import in $frontImportList)
$!{import}
#end
//import FilePreview from '/@/components/support/file-preview/index.vue'; // 图片预览组件
// ---------------------------- 表格列 ----------------------------

View File

@@ -9,8 +9,7 @@
and table_name = #{tableName}
</select>
<select id="selectTableColumn"
resultType="net.lab1024.sa.base.module.support.codegenerator.domain.vo.TableColumnVO">
<select id="selectTableColumn" resultType="net.lab1024.sa.base.module.support.codegenerator.domain.vo.TableColumnVO">
select *
from information_schema.columns
where table_schema = (select database())
@@ -18,19 +17,18 @@
order by ordinal_position
</select>
<select id="queryTableList"
resultType="net.lab1024.sa.base.module.support.codegenerator.domain.vo.TableVO">
<select id="queryTableList" resultType="net.lab1024.sa.base.module.support.codegenerator.domain.vo.TableVO">
select
tables.table_name,
tables.table_comment,
tables.create_time,
tables.update_time,
`tables`.table_name,
`tables`.table_comment,
`tables`.create_time,
`tables`.update_time,
t_code_generator_config.update_time configTime
from information_schema.tables tables
left join t_code_generator_config on tables.table_name = t_code_generator_config.table_name
where tables.table_schema = (select database())
from information_schema.tables `tables`
left join t_code_generator_config on `tables`.table_name = t_code_generator_config.table_name
where `tables`.table_schema = (select database())
<if test="queryForm.tableNameKeywords != null and queryForm.tableNameKeywords != ''">
AND INSTR(tables.table_name,#{queryForm.tableNameKeywords})
AND INSTR(`tables`.table_name,#{queryForm.tableNameKeywords})
</if>
</select>
</mapper>
</mapper>

View File

@@ -87,8 +87,8 @@ file:
region: oss-cn-hangzhou
endpoint: oss-cn-hangzhou.aliyuncs.com
bucket-name: 1024lab-smart-admin
access-key:
secret-key:
access-key:
secret-key:
url-prefix: https://${file.storage.cloud.bucket-name}.${file.storage.cloud.endpoint}/
private-url-expire-seconds: 3600