diff --git a/src/main/resources/static/src/views/database/DatabaseGeneratorPage.js b/src/main/resources/static/src/components/AppGeneratorPage.js
similarity index 99%
rename from src/main/resources/static/src/views/database/DatabaseGeneratorPage.js
rename to src/main/resources/static/src/components/AppGeneratorPage.js
index 6b002b4..eac08ed 100644
--- a/src/main/resources/static/src/views/database/DatabaseGeneratorPage.js
+++ b/src/main/resources/static/src/components/AppGeneratorPage.js
@@ -1,4 +1,4 @@
-const DatabaseGeneratorPage = defineComponent({
+const AppGeneratorPage = defineComponent({
name: "MainGeneratorPage",
template: `
diff --git a/src/main/resources/static/src/lib/css/index.css b/src/main/resources/static/src/lib/css/index.css
index cfaa931..c367a49 100644
--- a/src/main/resources/static/src/lib/css/index.css
+++ b/src/main/resources/static/src/lib/css/index.css
@@ -4,4 +4,4 @@
/* 引入Highlight.js的CSS */
@import url("highlight/atom-one-dark.min.css");
/* 添加自定义样式 */
-@import url("./style/style.css");
\ No newline at end of file
+@import url("./style/style.css");
diff --git a/src/main/resources/static/src/lib/css/style/style.css b/src/main/resources/static/src/lib/css/style/style.css
index cc824b8..aa718ae 100644
--- a/src/main/resources/static/src/lib/css/style/style.css
+++ b/src/main/resources/static/src/lib/css/style/style.css
@@ -18,4 +18,46 @@
.offcanvas.offcanvas-start {
width: 100%;
}
+}
+
+/* 添加自定义样式 */
+.database-info-card {
+ border-left: 4px solid #0d6efd;
+ margin-top: 20px;
+}
+
+.table-info-section {
+ background-color: #f8f9fa;
+ border-radius: 5px;
+ padding: 15px;
+ margin-bottom: 20px;
+}
+
+.column-list {
+ max-height: 500px;
+ overflow-y: auto;
+}
+
+.column-item {
+ border-left: 3px solid #6c757d;
+ margin-bottom: 10px;
+ transition: all 0.3s;
+}
+
+.column-item:hover {
+ border-left-color: #0d6efd;
+ background-color: #f8f9fa;
+}
+
+.badge-java {
+ background-color: #5382a1;
+}
+
+.badge-jdbc {
+ background-color: #4479a1;
+}
+
+.badge-js {
+ background-color: #f7df1e;
+ color: #000;
}
\ No newline at end of file
diff --git a/src/main/resources/static/src/views/database/DatabaseForm.js b/src/main/resources/static/src/views/database/DatabaseForm.js
index c79dfd0..7749112 100644
--- a/src/main/resources/static/src/views/database/DatabaseForm.js
+++ b/src/main/resources/static/src/views/database/DatabaseForm.js
@@ -63,93 +63,93 @@ const DatabaseForm = {
+
-
-
-
-
-
-
-
-
-
-
-
- {{ errors.webTemplates }}
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ errors.serverTemplates }}
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ {{ errors.webTemplates }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ errors.serverTemplates }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -289,7 +289,7 @@ const DatabaseForm = {
this.downloadLoading = true;
try {
const response = await axiosInstance({
- url: "/vms/downloadByZip",
+ url: "/generator/downloadByZip",
method: "POST",
data: this.form,
responseType: 'blob' // 重要:指定响应类型为blob
diff --git a/src/main/resources/static/src/views/sql/SqlForm.js b/src/main/resources/static/src/views/sql/SqlForm.js
new file mode 100644
index 0000000..e5ef400
--- /dev/null
+++ b/src/main/resources/static/src/views/sql/SqlForm.js
@@ -0,0 +1,413 @@
+const SqlForm = {
+ name: "MainForm",
+ template: `
+
+ `,
+ props: {
+ // 表单数据对象,包含生成代码所需的各种参数
+ form: {type: Object, required: true},
+ // 生成代码的回调函数
+ onGeneratorCode: {type: Function, required: true},
+ // 清空生成记录
+ onClearGeneratorData: {type: Function, required: true},
+ // 生成代码加载
+ generatorCodeLoading: {type: Boolean, required: true},
+ // sql语句中表信息
+ tableInfo: {type: Object, required: true},
+ // sql语句中列信息
+ columnMetaList: {type: Object, required: true},
+ },
+ data() {
+ return {
+ // 控制表单默认是否展开
+ defaultCollapse: true,
+ // 后端模板选项列表
+ serverList: ref([]),
+ // 前端模板选项列表
+ webList: ref([]),
+ // 错误信息对象
+ errors: {
+ author: '',
+ requestMapping: '',
+ packageName: '',
+ simpleDateFormat: '',
+ tablePrefixes: '',
+ webTemplates: '',
+ serverTemplates: '',
+ sql: ''
+ },
+ downloadLoading: ref(false),
+ };
+ },
+ methods: {
+ /**
+ * 验证表单字段
+ * @param {string} field - 字段名
+ */
+ validateField(field) {
+ if (!this.form[field] || this.form[field].trim() === '') {
+ this.errors[field] = '此字段为必填项';
+ return false;
+ }
+ this.errors[field] = '';
+ return true;
+ },
+
+ /* 验证模板选择 */
+ validateTemplates() {
+ // 检查列表是否有一个选中的
+ const hasWebSelected = this.webList.some(item => item.checked);
+ const hasServerSelected = this.serverList.some(item => item.checked);
+
+ // 列表都没有选中
+ if (!hasWebSelected && !hasServerSelected) {
+ this.errors.webTemplates = '请至少选择一个前端或后端模板';
+ this.errors.serverTemplates = '请至少选择一个前端或后端模板';
+ return false;
+ }
+
+ // 列表选中让错误提示小时
+ this.errors.webTemplates = '';
+ this.errors.serverTemplates = '';
+
+ // 发生选择变化时,同时父级更新表单
+ this.updateForm();
+ return true;
+ },
+
+ /* 验证整个表单 */
+ validateForm() {
+ let isValid = true;
+
+ // 验证文本字段
+ const textFields = ['author', 'requestMapping', 'packageName', 'simpleDateFormat', 'tablePrefixes', "sql"];
+ textFields.forEach(field => {
+ if (!this.validateField(field)) {
+ isValid = false;
+ }
+ });
+
+ // 验证模板选择
+ if (!this.validateTemplates()) {
+ isValid = false;
+ }
+
+ return isValid;
+ },
+
+ /* 更新父级表单 */
+ updateForm() {
+ const webList = this.webList.filter(item => item.checked).map(item => item.name);
+ const serverList = this.serverList.filter(item => item.checked).map(item => item.name);
+
+ const newForm = {...this.form, path: [...webList, ...serverList,]};
+ this.$emit("update:form", newForm);
+ },
+
+ /* 获取Sql内容信息 */
+ async onGetSqlParserInfo() {
+ const validate = this.validateForm();
+ if (!validate) return;
+
+ // 设置请求参数
+ const data = {sql: this.form.sql};
+
+ // 获取表信息
+ const tableInfoResponse = await axiosInstance.post("/sqlParser/tableInfo", data, {headers: {'Content-Type': 'multipart/form-data'}});
+ if (tableInfoResponse.code === 200) {
+ this.$emit("update:tableInfo", tableInfoResponse.data)
+ }
+
+ // 获取sql中的列信息
+ const columnMetaDataResponse = await axiosInstance.post("/sqlParser/columnMetaData", data, {headers: {'Content-Type': 'multipart/form-data'}});
+ if (columnMetaDataResponse.code === 200) {
+ this.$emit("update:columnMetaList", columnMetaDataResponse.data)
+ }
+ },
+
+ /* 处理表单提交 */
+ handleSubmit() {
+ if (this.validateForm()) {
+ this.updateForm();
+ // 如果验证通过,调用父组件提供的生成代码方法
+ this.onGeneratorCode();
+ } else {
+ // 验证失败,可以在这里添加额外的处理逻辑
+ antd.message.error("表单验证失败")
+ }
+ },
+
+ /**
+ * 获取VMS资源路径列表
+ * 从服务器获取前端和后端模板的路径列表
+ * @async
+ * @returns {Promise
}
+ */
+ async getVmsResourcePathList() {
+ const response = await axiosInstance.get("/vms/vmsResourcePathList");
+ const {data, code, message} = response;
+
+ if (code !== 200) {
+ antd.message.error(message);
+ return;
+ }
+ // 初始化模板选择状态
+ this.serverList = data.server.map(item => ({...item, checked: false}));
+ this.webList = data.web.map(item => ({...item, checked: false}));
+ },
+
+ /**
+ * 下载Zip文件
+ * @returns {Promise}
+ */
+ async onDownloadZip() {
+ this.downloadLoading = true;
+ try {
+ const response = await axiosInstance({
+ url: "/generator/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);
+ }
+
+ this.downloadLoading = false;
+ },
+
+ /**
+ * 全选指定列表
+ * @param {Array} list - 要处理的列表
+ */
+ onTableSelectAll(list) {
+ list.forEach(item => item.checked = true);
+ this.validateTemplates();
+ },
+
+ /**
+ * 反选指定列表
+ * @param {Array} list - 要处理的列表
+ */
+ onTableInvertSelection(list) {
+ list.forEach(item => item.checked = !item.checked);
+ this.validateTemplates();
+ },
+
+ /**
+ * 清空指定列表的选择
+ * @param {Array} list - 要处理的列表
+ */
+ onTableClearAll(list) {
+ list.forEach(item => item.checked = false);
+ this.validateTemplates();
+ },
+
+ /* 全选所有模板 */
+ onSelectAll() {
+ this.onTableSelectAll(this.webList);
+ this.onTableSelectAll(this.serverList);
+ },
+
+ /* 反选所有模板 */
+ onInvertSelection() {
+ this.onTableInvertSelection(this.webList);
+ this.onTableInvertSelection(this.serverList);
+ },
+
+ /* 清空所有模板的选择 */
+ onClearAll() {
+ this.onTableClearAll(this.webList);
+ this.onTableClearAll(this.serverList);
+ }
+ },
+ async mounted() {
+ // 组件挂载时获取模板列表
+ await this.getVmsResourcePathList();
+ },
+}
\ No newline at end of file
diff --git a/src/main/resources/static/src/views/sql/SqlParserInfo.js b/src/main/resources/static/src/views/sql/SqlParserInfo.js
new file mode 100644
index 0000000..f317e50
--- /dev/null
+++ b/src/main/resources/static/src/views/sql/SqlParserInfo.js
@@ -0,0 +1,112 @@
+const SqlParserInfo = {
+ name: "SqlParserInfo",
+ template: `
+
+
+
+
+
+
+
+
+
+
表信息
+
+
+
+
+
+
+
+ -
+ 表名: {{ tableInfo.tableName }}
+
+ -
+ 注释: {{ tableInfo.comment || '无' }}
+
+
+
+
+
+ -
+ 表类型: {{ tableInfo.tableType || '无' }}
+
+ -
+ 表目录: {{ tableInfo.tableCat || '无' }}
+
+
+
+
+
+
+
+
+
+
+
列信息 ({{ columnMetaList.length }})
+
+
+
+
+
+
+
+
+
+ {{column.columnName.replace(/\`/g, '')}} {{ column.comment || '无注释' }}
+
+
主键
+
+
+
+ Java类型:
+ {{ column.javaType }}
+
+
+ JDBC类型:
+ {{ column.jdbcType }}
+
+
+ JS类型:
+ {{ column.javascriptType }}
+
+
+
+ 字段名:
+ {{ column.lowercaseName.replace(/\`/g, '') }}
+
+
+
+
+
+
+
+
+
+`,
+ props: {
+ // sql语句中表信息
+ tableInfo: {type: Object, required: true},
+ // sql语句中列信息
+ columnMetaList: {type: Object, required: true},
+ },
+ data() {
+ return {};
+ },
+
+};
\ No newline at end of file
diff --git a/src/main/resources/templates/database.html b/src/main/resources/templates/database.html
index 4644d12..551c6f5 100644
--- a/src/main/resources/templates/database.html
+++ b/src/main/resources/templates/database.html
@@ -45,8 +45,8 @@
:raw-table-list="rawTableList" :table-list="tableList" v-model:form="form">
-
+