✨ 下载文件完成
This commit is contained in:
parent
25c078cd57
commit
7f59db44ce
|
@ -41,5 +41,6 @@ public class VmsArgumentDto {
|
||||||
|
|
||||||
@Schema(name = "sql", description = "SQL 语句")
|
@Schema(name = "sql", description = "SQL 语句")
|
||||||
private String sql;
|
private String sql;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class VmsServiceImpl implements VmsService {
|
||||||
// 下载文件名称
|
// 下载文件名称
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
String digestHex = MD5.create().digestHex(currentTimeMillis + "");
|
String digestHex = MD5.create().digestHex(currentTimeMillis + "");
|
||||||
String generateZipFilename = digestHex + ".zip";
|
String generateZipFilename = "generator-" + digestHex.substring(0, 4) + ".zip";
|
||||||
|
|
||||||
// 设置响应头
|
// 设置响应头
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// axios 配置
|
// axios 配置
|
||||||
const axiosInstance = axios.create({
|
const axiosInstance = axios.create({
|
||||||
baseURL: 'http://localhost:8800/api',
|
baseURL: 'http://localhost:8800/api',
|
||||||
timeout: 10000,
|
timeout: 16000,
|
||||||
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -62,11 +62,7 @@ const MainForm = {
|
||||||
{{ errors.tablePrefixes || '请输入去除开头前缀' }}
|
{{ errors.tablePrefixes || '请输入去除开头前缀' }}
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<div class="col-md-12" v-show="form.tableNames.length > 0">
|
||||||
<label class="form-label fw-medium" for="tableNames">已选择的要生成表({{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>
|
<span class="badge rounded-pill text-bg-dark me-1" v-for="(item,index) in form.tableNames" :ket="index">{{item}}</span>
|
||||||
|
@ -141,7 +137,7 @@ const MainForm = {
|
||||||
@click="onClearGeneratorData">清空生成记录</button>
|
@click="onClearGeneratorData">清空生成记录</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 d-grid gap-2">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -272,6 +268,54 @@ const MainForm = {
|
||||||
this.webList = data.web.map(item => ({...item, checked: false}));
|
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 - 要处理的列表
|
* @param {Array} list - 要处理的列表
|
||||||
|
|
Loading…
Reference in New Issue