You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
5.3 KiB
184 lines
5.3 KiB
import { defHttp } from '@/utils/http/axios';
|
|
import { ID, IDS, commonExport } from '@/api/base';
|
|
import { DocumentTaskResultsVO, DocumentTaskResultsForm, DocumentTaskResultsQuery, DocumentTaskResultDetailVO } from './model';
|
|
import { message } from 'ant-design-vue';
|
|
|
|
interface DownloadOptions {
|
|
filename?: string;
|
|
mimeType?: string;
|
|
}
|
|
|
|
/**
|
|
* 通用文件下载函数
|
|
* @param url 下载地址
|
|
* @param onError 错误处理回调
|
|
* @returns Promise<boolean> 下载是否成功
|
|
*/
|
|
export async function useDownload(
|
|
url: string,
|
|
onError?: (error: any) => void
|
|
): Promise<boolean> {
|
|
try {
|
|
const response = await defHttp.get(
|
|
{
|
|
url,
|
|
responseType: 'blob',
|
|
timeout: 60000, // 设置较长的超时时间
|
|
},
|
|
{
|
|
isReturnNativeResponse: true,
|
|
// 自定义错误处理
|
|
errorMessageMode: 'none',
|
|
}
|
|
);
|
|
|
|
// 检查响应类型
|
|
const contentType = response.headers['content-type'];
|
|
if (contentType && contentType.includes('application/json')) {
|
|
// 如果返回的是JSON(通常是错误信息),转换并抛出
|
|
const reader = new FileReader();
|
|
reader.onload = () => {
|
|
const error = JSON.parse(reader.result as string);
|
|
message.error(error.message || '下载失败');
|
|
onError?.(error);
|
|
};
|
|
reader.readAsText(response.data);
|
|
return false;
|
|
}
|
|
|
|
// 获取文件名
|
|
const contentDisposition = response.headers['content-disposition'];
|
|
let fileName = '';
|
|
|
|
if (contentDisposition) {
|
|
const matches = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
|
if (matches && matches[1]) {
|
|
fileName = decodeURIComponent(matches[1].replace(/['"]/g, ''));
|
|
}
|
|
}
|
|
|
|
// 创建Blob对象
|
|
const blob = new Blob([response.data], {
|
|
type: contentType || 'application/octet-stream'
|
|
});
|
|
|
|
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
|
|
// 针对IE的处理
|
|
window.navigator.msSaveOrOpenBlob(blob, fileName);
|
|
} else {
|
|
// 现代浏览器的处理
|
|
const url = window.URL.createObjectURL(blob);
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = fileName;
|
|
link.style.display = 'none';
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
window.URL.revokeObjectURL(url);
|
|
}
|
|
|
|
return true;
|
|
} catch (error: any) {
|
|
console.error('下载失败:', error);
|
|
message.error(error.message || '下载失败,请稍后重试');
|
|
onError?.(error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 查询文档任务结果列表
|
|
* @param params
|
|
* @returns
|
|
*/
|
|
export function DocumentTaskResultsList(params?: DocumentTaskResultsQuery) {
|
|
return defHttp.get<DocumentTaskResultsVO[]>({ url: '/productManagement/DocumentTaskResults/list', params });
|
|
}
|
|
|
|
/**
|
|
* 导出文档任务结果列表
|
|
* @param params
|
|
* @returns
|
|
*/
|
|
export function DocumentTaskResultsExport(params?: DocumentTaskResultsQuery) {
|
|
return commonExport('/productManagement/DocumentTaskResults/export', params ?? {});
|
|
}
|
|
|
|
/**
|
|
* 查询文档任务结果详细
|
|
* @param id id
|
|
* @returns
|
|
*/
|
|
export function DocumentTaskResultsInfo(id: ID) {
|
|
return defHttp.get<DocumentTaskResultsVO>({ url: '/productManagement/DocumentTaskResults/' + id });
|
|
}
|
|
|
|
/**
|
|
* 根据任务id查询文档任务结果详细
|
|
* @param id id
|
|
* @returns
|
|
*/
|
|
export function DocumentTaskResultsInfoByTaskId(id: ID) {
|
|
return defHttp.get<DocumentTaskResultsVO>({ url: '/productManagement/DocumentTaskResults/task/' + id });
|
|
}
|
|
|
|
/**
|
|
* 根据任务id查询详细分类的文档任务结果
|
|
* @param taskId 任务ID
|
|
* @returns 详细的文档任务结果列表
|
|
*/
|
|
export function getDetailResultsByTaskId(taskId: ID) {
|
|
return defHttp.get<DocumentTaskResultDetailVO[]>({ url: '/productManagement/DocumentTaskResults/taskDetail/' + taskId });
|
|
}
|
|
|
|
/**
|
|
* 新增文档任务结果
|
|
* @param data
|
|
* @returns
|
|
*/
|
|
export function DocumentTaskResultsAdd(data: DocumentTaskResultsForm) {
|
|
return defHttp.postWithMsg<void>({ url: '/productManagement/DocumentTaskResults', data });
|
|
}
|
|
|
|
/**
|
|
* 更新文档任务结果
|
|
* @param data
|
|
* @returns
|
|
*/
|
|
export function DocumentTaskResultsUpdate(data: DocumentTaskResultsForm) {
|
|
return defHttp.putWithMsg<void>({ url: '/productManagement/DocumentTaskResults', data });
|
|
}
|
|
|
|
/**
|
|
* 删除文档任务结果
|
|
* @param id id
|
|
* @returns
|
|
*/
|
|
export function DocumentTaskResultsRemove(id: ID | IDS) {
|
|
return defHttp.deleteWithMsg<void>({ url: '/productManagement/DocumentTaskResults/' + id },);
|
|
}
|
|
|
|
/**
|
|
* 更新文档任务结果项的状态(已读/采纳)
|
|
* @param id 结果项ID
|
|
* @param field 字段名(isRead/isAdopted)
|
|
* @param value 值(0/1)
|
|
* @returns
|
|
*/
|
|
export function updateResultItemStatus(id: ID, field: 'isRead' | 'isAdopted', value: '0' | '1') {
|
|
return defHttp.putWithMsg<void>({
|
|
url: `/productManagement/DocumentTaskResults/updateResultItemStatus/${id}/${field}/${value}`
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 下载文档任务结果
|
|
* @param id id
|
|
* @returns
|
|
*/
|
|
export function DocumentTaskResultDownload(id: ID | IDS) {
|
|
return useDownload(`/productManagement/DocumentTaskResults/downloadResult/${id}`);
|
|
|
|
// return defHttp.get<void>({ url: '/productManagement/DocumentTaskResults/downloadResult/' + id ,responseType: 'blob',headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED }},);
|
|
}
|
|
|