mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-09-24 14:26:40 +08:00
优化代码生成,添加字典预览与文件预览,使其适配当前版本
This commit is contained in:
parent
5136148ce1
commit
4062d5a4bb
@ -1,7 +1,6 @@
|
||||
package net.lab1024.sa.base.module.support.codegenerator.service.variable;
|
||||
|
||||
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.domain.form.CodeGeneratorConfigForm;
|
||||
import net.lab1024.sa.base.module.support.codegenerator.domain.model.CodeField;
|
||||
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,14 +84,6 @@ public class VOVariableService extends CodeGenerateBaseVariableService {
|
||||
packageList.add("import io.swagger.v3.oas.annotations.media.Schema;");
|
||||
}
|
||||
|
||||
|
||||
//字典
|
||||
if (isDict(field.getColumnName(), form)) {
|
||||
finalFieldMap.put("dict", "\n @JsonSerialize(using = DictValueVoSerializer.class)");
|
||||
packageList.add("import com.fasterxml.jackson.databind.annotation.JsonSerialize;");
|
||||
packageList.add("import net.lab1024.sa.base.common.json.serializer.DictValueVoSerializer;");
|
||||
}
|
||||
|
||||
//文件上传
|
||||
if (isFile(field.getColumnName(), form)) {
|
||||
finalFieldMap.put("file", "\n @JsonSerialize(using = FileKeyVoSerializer.class)");
|
||||
|
@ -2,9 +2,12 @@ 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.service.variable.CodeGenerateBaseVariableService;
|
||||
|
||||
@ -29,7 +32,7 @@ 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<Map<String, Object>> queryVariable = 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';");
|
||||
@ -52,11 +55,34 @@ public class ListVariableService extends CodeGenerateBaseVariableService {
|
||||
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<>();
|
||||
for (CodeInsertAndUpdateField field : form.getInsertAndUpdate().getFieldList()) {
|
||||
Map<String, Object> objectMap = BeanUtil.beanToMap(field);
|
||||
CodeField codeField = getCodeFieldByColumnName(field.getColumnName(), form);
|
||||
if (codeField == null) {
|
||||
continue;
|
||||
}
|
||||
objectMap.put("fieldName", codeField.getFieldName());
|
||||
objectMap.put("dict", codeField.getDict());
|
||||
|
||||
if(SmartStringUtil.isNotBlank(codeField.getDict())) {
|
||||
frontImportSet.add("import DictPreview from '/@/components/dict-preview/index.vue';");
|
||||
frontImportSet.add("import { useDict } from '/@/utils/dict';");
|
||||
}
|
||||
|
||||
if (CodeFrontComponentEnum.FILE_UPLOAD.equalsValue(field.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;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class ${name.upperCamel}VO {
|
||||
|
||||
#foreach ($field in $fields)
|
||||
|
||||
${field.apiModelProperty}$!{field.notEmpty}$!{field.dict}$!{field.file}
|
||||
${field.apiModelProperty}$!{field.notEmpty}$!{field.file}
|
||||
private $field.javaType $field.fieldName;
|
||||
#end
|
||||
|
||||
|
@ -101,18 +101,23 @@
|
||||
>
|
||||
<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 :fileList="text" type="picture" />
|
||||
</template>
|
||||
#end
|
||||
#end
|
||||
<!-- 方便直接复制粘贴修改 tag 的颜色 orange green purple success processing error default warning -->
|
||||
#foreach ($field in $listFields)
|
||||
#if($field.dict)
|
||||
<template v-if="column.dataIndex === '$!{field.fieldName}'">
|
||||
<a-tag color="cyan">
|
||||
<DictPreview :options="dictList['$!{field.dict}']" :value="text" />
|
||||
</a-tag>
|
||||
</template>
|
||||
#end
|
||||
#end
|
||||
|
||||
<template v-if="column.dataIndex === 'action'">
|
||||
<div class="smart-table-operate">
|
||||
@ -159,7 +164,13 @@
|
||||
#foreach ($import in $frontImportList)
|
||||
$!{import}
|
||||
#end
|
||||
//import FilePreview from '/@/components/support/file-preview/index.vue'; // 图片预览组件
|
||||
|
||||
#foreach ($field in $listFields)
|
||||
#if($field.dict)
|
||||
const dictList = useDict(#foreach($field in $fields)#if($field.dict)'$!{field.dict}'#if($foreach.hasNext), #end#end#end);
|
||||
#break
|
||||
#end
|
||||
#end
|
||||
|
||||
// ---------------------------- 表格列 ----------------------------
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.lab1024.sa.base.module.support.codegenerator.service.variable;
|
||||
|
||||
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.domain.form.CodeGeneratorConfigForm;
|
||||
import net.lab1024.sa.base.module.support.codegenerator.domain.model.CodeField;
|
||||
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,14 +84,6 @@ public class VOVariableService extends CodeGenerateBaseVariableService {
|
||||
packageList.add("import io.swagger.v3.oas.annotations.media.Schema;");
|
||||
}
|
||||
|
||||
|
||||
//字典
|
||||
if (isDict(field.getColumnName(), form)) {
|
||||
finalFieldMap.put("dict", "\n @JsonSerialize(using = DictValueVoSerializer.class)");
|
||||
packageList.add("import com.fasterxml.jackson.databind.annotation.JsonSerialize;");
|
||||
packageList.add("import net.lab1024.sa.base.common.json.serializer.DictValueVoSerializer;");
|
||||
}
|
||||
|
||||
//文件上传
|
||||
if (isFile(field.getColumnName(), form)) {
|
||||
finalFieldMap.put("file", "\n @JsonSerialize(using = FileKeyVoSerializer.class)");
|
||||
|
@ -2,9 +2,12 @@ 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.service.variable.CodeGenerateBaseVariableService;
|
||||
|
||||
@ -29,7 +32,7 @@ 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<Map<String, Object>> queryVariable = 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';");
|
||||
@ -52,11 +55,34 @@ public class ListVariableService extends CodeGenerateBaseVariableService {
|
||||
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<>();
|
||||
for (CodeInsertAndUpdateField field : form.getInsertAndUpdate().getFieldList()) {
|
||||
Map<String, Object> objectMap = BeanUtil.beanToMap(field);
|
||||
CodeField codeField = getCodeFieldByColumnName(field.getColumnName(), form);
|
||||
if (codeField == null) {
|
||||
continue;
|
||||
}
|
||||
objectMap.put("fieldName", codeField.getFieldName());
|
||||
objectMap.put("dict", codeField.getDict());
|
||||
|
||||
if(SmartStringUtil.isNotBlank(codeField.getDict())) {
|
||||
frontImportSet.add("import DictPreview from '/@/components/dict-preview/index.vue';");
|
||||
frontImportSet.add("import { useDict } from '/@/utils/dict';");
|
||||
}
|
||||
|
||||
if (CodeFrontComponentEnum.FILE_UPLOAD.equalsValue(field.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;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class ${name.upperCamel}VO {
|
||||
|
||||
#foreach ($field in $fields)
|
||||
|
||||
${field.apiModelProperty}$!{field.notEmpty}$!{field.dict}$!{field.file}
|
||||
${field.apiModelProperty}$!{field.notEmpty}$!{field.file}
|
||||
private $field.javaType $field.fieldName;
|
||||
#end
|
||||
|
||||
|
@ -101,18 +101,23 @@
|
||||
>
|
||||
<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 :fileList="text" type="picture" />
|
||||
</template>
|
||||
#end
|
||||
#end
|
||||
<!-- 方便直接复制粘贴修改 tag 的颜色 orange green purple success processing error default warning -->
|
||||
#foreach ($field in $listFields)
|
||||
#if($field.dict)
|
||||
<template v-if="column.dataIndex === '$!{field.fieldName}'">
|
||||
<a-tag color="cyan">
|
||||
<DictPreview :options="dictList['$!{field.dict}']" :value="text" />
|
||||
</a-tag>
|
||||
</template>
|
||||
#end
|
||||
#end
|
||||
|
||||
<template v-if="column.dataIndex === 'action'">
|
||||
<div class="smart-table-operate">
|
||||
@ -159,7 +164,13 @@
|
||||
#foreach ($import in $frontImportList)
|
||||
$!{import}
|
||||
#end
|
||||
//import FilePreview from '/@/components/support/file-preview/index.vue'; // 图片预览组件
|
||||
|
||||
#foreach ($field in $listFields)
|
||||
#if($field.dict)
|
||||
const dictList = useDict(#foreach($field in $fields)#if($field.dict)'$!{field.dict}'#if($foreach.hasNext), #end#end#end);
|
||||
#break
|
||||
#end
|
||||
#end
|
||||
|
||||
// ---------------------------- 表格列 ----------------------------
|
||||
|
||||
|
@ -120,7 +120,7 @@
|
||||
{{ text }}
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'place'">
|
||||
<DictPreview :options="descList['GOODS_PLACE']" :value="text" />
|
||||
<DictPreview :options="dictList['GOODS_PLACE']" :value="text" />
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'remark'">
|
||||
<span>{{ text ? text : '' }}</span>
|
||||
@ -206,7 +206,7 @@
|
||||
import DictPreview from '/@/components/dict-preview/index.vue';
|
||||
import { useDict } from '/@/utils/dict';
|
||||
|
||||
const descList = useDict('GOODS_PLACE');
|
||||
const dictList = useDict('GOODS_PLACE', 'GOODS_PLACE');
|
||||
// ---------------------------- 表格列 ----------------------------
|
||||
|
||||
const columns = ref([
|
||||
|
@ -59,6 +59,7 @@
|
||||
|
||||
<a-table
|
||||
size="small"
|
||||
:scroll="{ x: 1000 }"
|
||||
bordered
|
||||
class="smart-margin-top10"
|
||||
:dataSource="tableData"
|
||||
|
@ -120,7 +120,7 @@
|
||||
{{ text }}
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'place'">
|
||||
<DictPreview :options="descList['GOODS_PLACE']" :value="text" />
|
||||
<DictPreview :options="dictList['GOODS_PLACE']" :value="text" />
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'remark'">
|
||||
<span>{{ text ? text : '' }}</span>
|
||||
@ -205,7 +205,7 @@
|
||||
import SmartHeaderCell from '/@/components/smart-table-header-cell/index.vue';
|
||||
import DictPreview from '/@/components/dict-preview/index.vue';
|
||||
import { useDict } from '/@/utils/dict';
|
||||
const descList = useDict('GOODS_PLACE');
|
||||
const dictList = useDict('GOODS_PLACE');
|
||||
// ---------------------------- 表格列 ----------------------------
|
||||
|
||||
const columns = ref([
|
||||
|
@ -59,6 +59,7 @@
|
||||
|
||||
<a-table
|
||||
size="small"
|
||||
:scroll="{ x: 1000 }"
|
||||
bordered
|
||||
class="smart-margin-top10"
|
||||
:dataSource="tableData"
|
||||
|
Loading…
Reference in New Issue
Block a user