diff --git a/src/api/generator.ts b/src/api/generator.ts index 2ff8d4d8..481fc346 100644 --- a/src/api/generator.ts +++ b/src/api/generator.ts @@ -38,12 +38,24 @@ class GeneratorAPI { method: "get", }); } - - /** 重置代码配置 */ - static resetGenConfig(tableName: string) { + /** + * 下载 ZIP 文件 + * @param url + * @param fileName + */ + static downloadZip(tableName: string, fileName?: string) { return request({ - url: `${GENERATOR_BASE_URL}/${tableName}/config`, - method: "delete", + url: `${GENERATOR_BASE_URL}/${tableName}/downloadZip`, + method: "get", + responseType: "blob", + }).then((res) => { + const blob = new Blob([res.data], { type: "application/zip" }); + const a = document.createElement("a"); + const url = window.URL.createObjectURL(blob); + a.href = url; + a.download = fileName || "下载文件.zip"; + a.click(); + window.URL.revokeObjectURL(url); }); } } diff --git a/src/views/generator/index.vue b/src/views/generator/index.vue index e091885f..5f284490 100644 --- a/src/views/generator/index.vue +++ b/src/views/generator/index.vue @@ -447,7 +447,17 @@ function handleNextClick() { loadingText.value = "loading..."; }); } else { - if (active.value++ >= 2) active.value = 2; + if (active.value++ >= 2) { + active.value = 2; + } + if (active.value === 2) { + const tableName = formData.value.tableName; + if (!tableName) { + ElMessage.error("表名不能为空"); + return; + } + GeneratorAPI.downloadZip(tableName, "youlai-admin-code.zip"); + } } }