From 1ce2a7e2106f4f592a728b3cd0951e0657d696ca Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Fri, 4 Jul 2025 12:33:13 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=8C=81=E4=B9=85=E5=8C=96?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E8=A1=A8=E5=8D=95=E4=BF=A1=E6=81=AF;?= =?UTF-8?q?=E6=94=BE=E5=9C=A8=E5=89=8D=E7=AB=AFlocalStorage=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/src/config/axios-config.js | 2 ++ .../static/src/views/database/DatabaseForm.js | 3 +- src/main/resources/templates/database.html | 33 ++++++++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/resources/static/src/config/axios-config.js b/src/main/resources/static/src/config/axios-config.js index bf994d6..6234e1a 100644 --- a/src/main/resources/static/src/config/axios-config.js +++ b/src/main/resources/static/src/config/axios-config.js @@ -34,6 +34,8 @@ axiosInstance.interceptors.response.use( } else { antd.message.error(message || '系统出错'); } + + return error.response.data; } return Promise.reject(error.message); } diff --git a/src/main/resources/static/src/views/database/DatabaseForm.js b/src/main/resources/static/src/views/database/DatabaseForm.js index 7749112..fd84bb1 100644 --- a/src/main/resources/static/src/views/database/DatabaseForm.js +++ b/src/main/resources/static/src/views/database/DatabaseForm.js @@ -288,11 +288,12 @@ const DatabaseForm = { async onDownloadZip() { this.downloadLoading = true; try { + // 重要:指定响应类型为blob const response = await axiosInstance({ url: "/generator/downloadByZip", method: "POST", data: this.form, - responseType: 'blob' // 重要:指定响应类型为blob + responseType: 'blob' }); // 从响应头中获取文件名 diff --git a/src/main/resources/templates/database.html b/src/main/resources/templates/database.html index 0d12bb3..240ad21 100644 --- a/src/main/resources/templates/database.html +++ b/src/main/resources/templates/database.html @@ -169,21 +169,32 @@ }, watch: { /* 数据表选择 */ - dbSelect: { - handler() { - this.getDatabaseTableList(); - } - }, + dbSelect: "getDatabaseTableList", /* 过滤数据表 */ - tableSelect: { - handler(val) { - this.tableList = this.rawTableList; - // 根据表名进行过滤筛选或者根据注释内容进行筛选 - this.tableList = this.tableList.filter(table => table.tableName.includes(val) || table.comment.includes(val)); - } + tableSelect(val) { + this.tableList = this.rawTableList; + // 根据表名进行过滤筛选或者根据注释内容进行筛选 + this.tableList = this.tableList.filter(table => table.tableName.includes(val) || table.comment.includes(val)); }, + + /** + * 监听form表单放到 localStorage + * 不要使用 immediate 否则初始话加载的时候会将 localStorage 改成 原始表单 + */ + form: { + deep: true, + handler(val) { + localStorage.setItem("form", JSON.stringify(val)); + }, + } }, + mounted() { + const form = localStorage.getItem("form"); + if (form !== null) { + this.form = JSON.parse(form); + } + } }); // 注册组件