feat: 生成代码下载zip

下载zip的前端代码部分
This commit is contained in:
Ky10
2024-08-01 17:35:43 +08:00
parent fb44ba2b51
commit 0867fa8807
2 changed files with 28 additions and 0 deletions

View File

@@ -38,6 +38,26 @@ class GeneratorAPI {
method: "get",
});
}
/**
* 下载 ZIP 文件
* @param url
* @param fileName
*/
static downloadZip(tableName: string, fileName?: string) {
return request({
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);
});
}
}
export default GeneratorAPI;

View File

@@ -465,6 +465,14 @@ function handleNextClick() {
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");
}
}
}