Compare commits
2 Commits
54fe820d26
...
7f59db44ce
Author | SHA1 | Date |
---|---|---|
|
7f59db44ce | |
|
25c078cd57 |
|
@ -1,6 +1,7 @@
|
|||
package cn.bunny.core.template;
|
||||
|
||||
import cn.bunny.domain.dto.VmsArgumentDto;
|
||||
import cn.bunny.domain.entity.TableMetaData;
|
||||
import cn.bunny.utils.TypeConvertUtil;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
@ -18,17 +19,17 @@ public class VmsArgumentDtoBaseVmsGeneratorTemplate extends AbstractVmsGenerator
|
|||
|
||||
private final VmsArgumentDto dto;
|
||||
private final String path;
|
||||
private final String tableName;
|
||||
private final TableMetaData tableMetaData;
|
||||
|
||||
/**
|
||||
* @param dto 类名称可以自定义,格式为 xxx_xxx
|
||||
* @param path 当前路径
|
||||
* @param tableName 表名称
|
||||
* @param dto 类名称可以自定义,格式为 xxx_xxx
|
||||
* @param path 当前路径
|
||||
* @param tableMetaData 表名称
|
||||
*/
|
||||
public VmsArgumentDtoBaseVmsGeneratorTemplate(VmsArgumentDto dto, String path, String tableName) {
|
||||
public VmsArgumentDtoBaseVmsGeneratorTemplate(VmsArgumentDto dto, String path, TableMetaData tableMetaData) {
|
||||
this.dto = dto;
|
||||
this.path = path;
|
||||
this.tableName = tableName;
|
||||
this.tableMetaData = tableMetaData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,6 +39,11 @@ public class VmsArgumentDtoBaseVmsGeneratorTemplate extends AbstractVmsGenerator
|
|||
*/
|
||||
@Override
|
||||
void addContext(VelocityContext context) {
|
||||
// 当前的表名
|
||||
String tableName = tableMetaData.getTableName();
|
||||
// 表的注释内容
|
||||
String comment = tableMetaData.getComment();
|
||||
|
||||
// 当前日期
|
||||
String date = new SimpleDateFormat(dto.getSimpleDateFormat()).format(new Date());
|
||||
context.put("date", date);
|
||||
|
@ -49,7 +55,7 @@ public class VmsArgumentDtoBaseVmsGeneratorTemplate extends AbstractVmsGenerator
|
|||
context.put("requestMapping", dto.getRequestMapping());
|
||||
|
||||
// 表字段的注释内容
|
||||
context.put("comment", dto.getComment());
|
||||
context.put("comment", comment);
|
||||
|
||||
// 设置包名称
|
||||
context.put("package", dto.getPackageName());
|
||||
|
|
|
@ -36,13 +36,11 @@ public class VmsArgumentDto {
|
|||
@Schema(name = "tablePrefixes", description = "去除表前缀")
|
||||
private String tablePrefixes;
|
||||
|
||||
@Schema(name = "comment", description = "注释内容")
|
||||
private String comment;
|
||||
|
||||
@Schema(name = "path", description = "路径")
|
||||
private List<String> path;
|
||||
|
||||
@Schema(name = "sql", description = "SQL 语句")
|
||||
private String sql;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ public class VmsServiceImpl implements VmsService {
|
|||
// 下载文件名称
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
String digestHex = MD5.create().digestHex(currentTimeMillis + "");
|
||||
String generateZipFilename = digestHex + ".zip";
|
||||
String generateZipFilename = "generator-" + digestHex.substring(0, 4) + ".zip";
|
||||
|
||||
// 设置响应头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
|
|
@ -44,7 +44,7 @@ public class VmsCodeGeneratorService {
|
|||
|
||||
return dto.getPath().stream()
|
||||
.map(path -> {
|
||||
VmsArgumentDtoBaseVmsGeneratorTemplate generator = new VmsArgumentDtoBaseVmsGeneratorTemplate(dto, path, tableName);
|
||||
VmsArgumentDtoBaseVmsGeneratorTemplate generator = new VmsArgumentDtoBaseVmsGeneratorTemplate(dto, path, tableMetaData);
|
||||
StringWriter writer = generator.generatorCodeTemplate(tableMetaData, columnInfoList);
|
||||
String processedPath = VmsUtil.handleVmFilename(path, tableMetaData.getTableName());
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// axios 配置
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: 'http://localhost:8800/api',
|
||||
timeout: 10000,
|
||||
timeout: 16000,
|
||||
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
||||
});
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@ const MainForm = {
|
|||
<form class="card-body row" @submit.prevent="handleSubmit" novalidate>
|
||||
<!-- 基本信息输入区域 -->
|
||||
<div class="col-md-4 mb-3 has-validation">
|
||||
<label class="form-label fw-medium" for="authorName">作者名称</label>
|
||||
<input class="form-control border-secondary" :class="{ 'is-invalid': errors.authorName }"
|
||||
id="authorName" placeholder="输入作者名称" v-model="form.authorName" type="text"
|
||||
@input="validateField('authorName')">
|
||||
<label class="form-label fw-medium" for="author">作者名称</label>
|
||||
<input class="form-control border-secondary" :class="{ 'is-invalid': errors.author }"
|
||||
id="author" placeholder="输入作者名称" v-model="form.author" type="text"
|
||||
@input="validateField('author')">
|
||||
<div class="invalid-feedback">
|
||||
{{ errors.authorName || '请输入作者名称' }}
|
||||
{{ errors.author || '请输入作者名称' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3 has-validation">
|
||||
|
@ -62,13 +62,9 @@ const MainForm = {
|
|||
{{ errors.tablePrefixes || '请输入去除开头前缀' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label fw-medium" for="comment">注释内容</label>
|
||||
<input class="form-control border-secondary" id="comment" placeholder="注释内容" v-model="form.comment"
|
||||
type="text" />
|
||||
</div>
|
||||
|
||||
<div class="col-md-12" v-show="form.tableNames.length > 0">
|
||||
<label class="form-label fw-medium" for="comment">已选择的要生成表({{form.tableNames.length}}):</label>
|
||||
<label class="form-label fw-medium" for="tableNames">已选择的要生成表({{form.tableNames.length}}):</label>
|
||||
<span class="badge rounded-pill text-bg-dark me-1" v-for="(item,index) in form.tableNames" :ket="index">{{item}}</span>
|
||||
</div>
|
||||
|
||||
|
@ -141,7 +137,7 @@ const MainForm = {
|
|||
@click="onClearGeneratorData">清空生成记录</button>
|
||||
</div>
|
||||
<div class="col-md-4 d-grid gap-2">
|
||||
<button class="btn btn-primary text-white" type="button">下载ZIP</button>
|
||||
<button class="btn btn-primary text-white" type="button" @click="onDownloadZip">下载ZIP</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -166,7 +162,7 @@ const MainForm = {
|
|||
webList: ref([]),
|
||||
// 错误信息对象
|
||||
errors: {
|
||||
authorName: '',
|
||||
author: '',
|
||||
requestMapping: '',
|
||||
packageName: '',
|
||||
simpleDateFormat: '',
|
||||
|
@ -217,7 +213,7 @@ const MainForm = {
|
|||
let isValid = true;
|
||||
|
||||
// 验证文本字段
|
||||
const textFields = ['authorName', 'requestMapping', 'packageName', 'simpleDateFormat', 'tablePrefixes'];
|
||||
const textFields = ['author', 'requestMapping', 'packageName', 'simpleDateFormat', 'tablePrefixes'];
|
||||
textFields.forEach(field => {
|
||||
if (!this.validateField(field)) {
|
||||
isValid = false;
|
||||
|
@ -272,6 +268,54 @@ const MainForm = {
|
|||
this.webList = data.web.map(item => ({...item, checked: false}));
|
||||
},
|
||||
|
||||
/**
|
||||
* 下载Zip文件
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async onDownloadZip() {
|
||||
try {
|
||||
const response = await axiosInstance({
|
||||
url: "/vms/downloadByZip",
|
||||
method: "POST",
|
||||
data: this.form,
|
||||
responseType: 'blob' // 重要:指定响应类型为blob
|
||||
});
|
||||
|
||||
// 从响应头中获取文件名
|
||||
const contentDisposition = response.headers['content-disposition'];
|
||||
let fileName = 'download.zip';
|
||||
if (contentDisposition) {
|
||||
const fileNameMatch = contentDisposition.match(/filename=(.+)/);
|
||||
if (fileNameMatch && fileNameMatch[1]) {
|
||||
fileName = fileNameMatch[1];
|
||||
// 处理可能的编码文件名(如UTF-8编码)
|
||||
if (fileName.startsWith("UTF-8''")) {
|
||||
fileName = decodeURIComponent(fileName.replace("UTF-8''", ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 创建Blob对象
|
||||
const blob = new Blob([response.data]);
|
||||
|
||||
// 创建下载链接
|
||||
const downloadUrl = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = downloadUrl;
|
||||
link.download = fileName;
|
||||
document.body.appendChild(link);
|
||||
|
||||
// 触发点击下载
|
||||
link.click();
|
||||
|
||||
// 清理
|
||||
window.URL.revokeObjectURL(downloadUrl);
|
||||
document.body.removeChild(link);
|
||||
} catch (error) {
|
||||
console.error('下载失败:', error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 全选指定列表
|
||||
* @param {Array} list - 要处理的列表
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
// 提交的表单
|
||||
form: ref({
|
||||
// 作者名称
|
||||
authorName: "Bunny",
|
||||
author: "Bunny",
|
||||
// requestMapping名称
|
||||
requestMapping: "/api",
|
||||
// 表名称
|
||||
|
@ -128,7 +128,7 @@
|
|||
// 去除开头前缀
|
||||
tablePrefixes: "t_,sys_,qrtz_,log_",
|
||||
// 生成代码路径
|
||||
path: []
|
||||
path: [],
|
||||
}),
|
||||
// 是否显示生成页面
|
||||
generatorPageFlag: ref(false),
|
||||
|
|
Loading…
Reference in New Issue