mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 17:58:17 +08:00
通过修改代码生成解决imageUpload类型组件,前台image-preview和image-upload 回现冲突问题;解决方案,通过在代码生成的时候过滤出imageUpload类型的组件,如果有就创建一个新的一行新的组件数据到columns中,这个数据是原始的字段加上Url;然后通过编写.vm过滤方法,把domain中新添加的字段加上@TableField("$column.columnName"),把vo中的字段添加@Translation(type = TransConstant.OSS_ID_TO_URL),然后在修改index.vue中表格回现字段的绑定,image-preview并绑定到javaField+Url,image-upload还是绑定原始的javaField,这样就解决的回现冲突问题
This commit is contained in:
parent
08fece39d8
commit
7a3934e986
@ -1,5 +1,6 @@
|
|||||||
package org.dromara.generator.service;
|
package org.dromara.generator.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
@ -48,6 +49,7 @@ import java.io.IOException;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
@ -326,6 +328,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
menuIds.add(identifierGenerator.nextId(null).longValue());
|
menuIds.add(identifierGenerator.nextId(null).longValue());
|
||||||
}
|
}
|
||||||
|
//处理图片上传组件回现问题
|
||||||
|
processImageUploadColumns(table);
|
||||||
|
|
||||||
table.setMenuIds(menuIds);
|
table.setMenuIds(menuIds);
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
setPkColumn(table);
|
setPkColumn(table);
|
||||||
@ -369,6 +374,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
public void generatorCode(Long tableId) {
|
public void generatorCode(Long tableId) {
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
GenTable table = baseMapper.selectGenTableById(tableId);
|
||||||
|
//处理图片上传组件回现问题
|
||||||
|
processImageUploadColumns(table);
|
||||||
|
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
setPkColumn(table);
|
setPkColumn(table);
|
||||||
|
|
||||||
@ -472,6 +480,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
menuIds.add(identifierGenerator.nextId(null).longValue());
|
menuIds.add(identifierGenerator.nextId(null).longValue());
|
||||||
}
|
}
|
||||||
|
//处理图片上传组件回现问题
|
||||||
|
processImageUploadColumns(table);
|
||||||
|
|
||||||
table.setMenuIds(menuIds);
|
table.setMenuIds(menuIds);
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
setPkColumn(table);
|
setPkColumn(table);
|
||||||
@ -574,5 +585,27 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
}
|
}
|
||||||
return genPath + File.separator + VelocityUtils.getFileName(template, table);
|
return genPath + File.separator + VelocityUtils.getFileName(template, table);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 传入数据库行数据,返回添加后数据字段
|
||||||
|
* @param table 表数据
|
||||||
|
*/
|
||||||
|
private void processImageUploadColumns( GenTable table) {
|
||||||
|
List<GenTableColumn> columns = table.getColumns();
|
||||||
|
List<GenTableColumn> newColumns = columns.stream()
|
||||||
|
.filter(column -> GenConstants.HTML_IMAGE_UPLOAD.equals(column.getHtmlType()))
|
||||||
|
.map(column -> {
|
||||||
|
GenTableColumn convert = BeanUtil.copyProperties(column, GenTableColumn.class);
|
||||||
|
convert.setJavaField(column.getJavaField() + "Url");
|
||||||
|
convert.setIsQuery("0");
|
||||||
|
convert.setIsEdit("0");
|
||||||
|
convert.setIsInsert("0");
|
||||||
|
convert.setIsList("1");
|
||||||
|
return convert;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 将新生成的列添加到原始列列表中
|
||||||
|
columns.addAll(newColumns);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,9 +40,22 @@ public class ${ClassName} extends ${Entity} {
|
|||||||
|
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if(!$table.isSuperColumn($column.javaField))
|
#if(!$table.isSuperColumn($column.javaField))
|
||||||
|
#set($nonUrlField = "")
|
||||||
|
#if ($column.javaField.endsWith("Url"))
|
||||||
|
#set($nonUrlField = $column.javaField.substring(0, $column.javaField.length() - 3))
|
||||||
|
#foreach ($otherColumn in $columns)
|
||||||
|
#if ($otherColumn.javaField == $nonUrlField)
|
||||||
|
#set($nonUrlField = $nonUrlField)
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
/**
|
/**
|
||||||
* $column.columnComment
|
* $column.columnComment
|
||||||
*/
|
*/
|
||||||
|
#if(($column.javaField.endsWith("Url") && $nonUrlField != ""))
|
||||||
|
@TableField("$column.columnName")
|
||||||
|
#end
|
||||||
#if($column.javaField=='delFlag')
|
#if($column.javaField=='delFlag')
|
||||||
@TableLogic
|
@TableLogic
|
||||||
#end
|
#end
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import org.dromara.common.excel.annotation.ExcelDictFormat;
|
|||||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
import org.dromara.common.excel.convert.ExcelDictConvert;
|
||||||
import io.github.linpeilie.annotations.AutoMapper;
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.dbn.common.translation.annotation.Translation;
|
||||||
|
import org.dbn.common.translation.constant.TransConstant;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -42,6 +44,16 @@ public class ${ClassName}Vo implements Serializable {
|
|||||||
#else
|
#else
|
||||||
#set($comment=$column.columnComment)
|
#set($comment=$column.columnComment)
|
||||||
#end
|
#end
|
||||||
|
#set($nonUrlField = "")
|
||||||
|
#if ($column.javaField.endsWith("Url"))
|
||||||
|
#set($nonUrlField = $column.javaField.substring(0, $column.javaField.length() - 3))
|
||||||
|
#foreach ($otherColumn in $columns)
|
||||||
|
#if ($otherColumn.javaField == $nonUrlField)
|
||||||
|
#set($nonUrlField = $nonUrlField)
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
#if(${column.dictType} && ${column.dictType} != '')
|
#if(${column.dictType} && ${column.dictType} != '')
|
||||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||||
@ExcelDictFormat(dictType = "${column.dictType}")
|
@ExcelDictFormat(dictType = "${column.dictType}")
|
||||||
@ -50,6 +62,9 @@ public class ${ClassName}Vo implements Serializable {
|
|||||||
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
|
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
|
||||||
#else
|
#else
|
||||||
@ExcelProperty(value = "${comment}")
|
@ExcelProperty(value = "${comment}")
|
||||||
|
#end
|
||||||
|
#if(($column.javaField.endsWith("Url") && $nonUrlField != ""))
|
||||||
|
@Translation(type = TransConstant.OSS_ID_TO_URL)
|
||||||
#end
|
#end
|
||||||
private $column.javaType $column.javaField;
|
private $column.javaType $column.javaField;
|
||||||
|
|
||||||
|
|||||||
@ -101,11 +101,23 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
#elseif($column.list && $column.htmlType == "imageUpload")
|
#elseif($column.list && $column.htmlType == "imageUpload")
|
||||||
|
#set($nonUrlField = "")
|
||||||
|
#if ($column.javaField.endsWith("Url"))
|
||||||
|
#set($nonUrlField = $column.javaField.substring(0, $column.javaField.length() - 3))
|
||||||
|
#foreach ($otherColumn in $columns)
|
||||||
|
#if ($otherColumn.javaField == $nonUrlField)
|
||||||
|
#set($nonUrlField = $nonUrlField)
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#if(!($column.javaField.endsWith("Url") && $nonUrlField != ""))
|
||||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100">
|
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
|
<image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
#end
|
||||||
#elseif($column.list && $column.dictType && "" != $column.dictType)
|
#elseif($column.list && $column.dictType && "" != $column.dictType)
|
||||||
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user