导出证书
This commit is contained in:
parent
c0b4b3d464
commit
4cc9979b8c
@ -118,10 +118,12 @@ export const eventscoreDownloadtemplateGet = () => {
|
|||||||
* @param {string} [data.groupName] - 组别名称
|
* @param {string} [data.groupName] - 组别名称
|
||||||
* @param {string} [data.name] - 姓名
|
* @param {string} [data.name] - 姓名
|
||||||
* @param {string} [data.unitName] - 单位名称
|
* @param {string} [data.unitName] - 单位名称
|
||||||
* @returns {Promise<string>} 返回导出文件URL
|
* @returns {Promise<Blob>} 返回ZIP文件流
|
||||||
*/
|
*/
|
||||||
export const eventscoreExportcertificatePost = (data) => {
|
export const eventscoreExportcertificatePost = (data) => {
|
||||||
return http.post('/eventscore/exportcertificate', data);
|
return http.post('/eventscore/exportcertificate', data, {
|
||||||
|
responseType: 'blob'
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1236,28 +1236,27 @@ const downloadTemplate = async () => {
|
|||||||
|
|
||||||
const exportCertificate = async () => {
|
const exportCertificate = async () => {
|
||||||
try {
|
try {
|
||||||
const { succeeded, data, errors } = await eventscoreExportcertificatePost({
|
const data = await eventscoreExportcertificatePost({
|
||||||
eventId: initParam.value.eventId
|
eventId: initParam.value.eventId,
|
||||||
|
projectId: scoreQueryParam.value.projectId,
|
||||||
|
groupName: scoreQueryParam.value.groupName,
|
||||||
|
name: scoreQueryParam.value.name
|
||||||
});
|
});
|
||||||
if (!succeeded) {
|
if (data instanceof Blob) {
|
||||||
ElMessage.error(errors || '导出证书失败');
|
if (data.type && data.type.includes('application/json')) {
|
||||||
return;
|
const text = await data.text();
|
||||||
|
const err = JSON.parse(text);
|
||||||
|
ElMessage.error(err.errors || err.message || '导出证书失败');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const blob = new Blob([data], {
|
||||||
|
type: 'application/zip'
|
||||||
|
});
|
||||||
|
downloadByBlob(blob, `证书导出_${new Date().getTime()}.zip`);
|
||||||
|
ElMessage.success('导出成功');
|
||||||
|
} else {
|
||||||
|
ElMessage.error('导出证书失败,未获取到文件');
|
||||||
}
|
}
|
||||||
if (!data) {
|
|
||||||
ElMessage.warning('未获取到导出文件');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const byteCharacters = atob(data);
|
|
||||||
const byteNumbers = new Array(byteCharacters.length);
|
|
||||||
for (let i = 0; i < byteCharacters.length; i++) {
|
|
||||||
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
||||||
}
|
|
||||||
const byteArray = new Uint8Array(byteNumbers);
|
|
||||||
const blob = new Blob([byteArray], {
|
|
||||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
||||||
});
|
|
||||||
downloadByBlob(blob, '证书导出.xlsx');
|
|
||||||
ElMessage.success('导出成功');
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('导出证书失败:', error);
|
console.error('导出证书失败:', error);
|
||||||
ElMessage.error('导出证书失败');
|
ElMessage.error('导出证书失败');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user