1、修复基础配置
2、修复业务模块 3、拆分页面代码
This commit is contained in:
@@ -7,8 +7,20 @@ import 'nprogress/nprogress.css';
|
||||
const excelPattern = /\.(xls|xlsx)$/;
|
||||
|
||||
const isExcelResponse = res => {
|
||||
const contentType = res.headers['content-type'] || res.data.type || '';
|
||||
return contentType.includes('application/vnd.ms-excel');
|
||||
const headers = res.headers || {};
|
||||
const contentType = String(headers['content-type'] || res.data?.type || '').toLowerCase();
|
||||
const contentDisposition = String(headers['content-disposition'] || '').toLowerCase();
|
||||
if (
|
||||
contentType.includes('application/vnd.ms-excel') ||
|
||||
contentType.includes('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
// 网关或对象存储可能将 Excel 流标记为二进制类型,此时通过下载文件名识别。
|
||||
return (
|
||||
contentType.includes('application/octet-stream') &&
|
||||
/\.(xls|xlsx)(?:["';]|$)/.test(contentDisposition)
|
||||
);
|
||||
};
|
||||
|
||||
const parseBlobJson = async blob => {
|
||||
@@ -44,9 +56,10 @@ const decorateFailExcel = async (blob, businessName, failDetailDecorator) => {
|
||||
* @param {Function} [onSuccess] 导入成功回调
|
||||
* @param {Object} [options] 扩展项
|
||||
* @param {Function} [options.failDetailDecorator] 失败明细加工函数,用于对后端返回的失败 Excel 标红/改写原因
|
||||
* @param {Number} [options.timeout=60000] 导入请求超时时间(毫秒)
|
||||
*/
|
||||
export const openImportDialog = (vm, businessName, onSuccess, options = {}) => {
|
||||
const { failDetailDecorator } = options;
|
||||
const { failDetailDecorator, timeout = 60000 } = options;
|
||||
const excelOption = vm.excelOption || vm.excelOptionConfig;
|
||||
const column = vm.findColumn(excelOption?.column || [], 'excelFile');
|
||||
if (!column) {
|
||||
@@ -54,12 +67,15 @@ export const openImportDialog = (vm, businessName, onSuccess, options = {}) => {
|
||||
return;
|
||||
}
|
||||
column.httpRequest = (option, uploadColumn) =>
|
||||
handleImportExcel(vm, option, uploadColumn, businessName, onSuccess, { failDetailDecorator });
|
||||
handleImportExcel(vm, option, uploadColumn, businessName, onSuccess, {
|
||||
failDetailDecorator,
|
||||
timeout,
|
||||
});
|
||||
vm.excelBox = true;
|
||||
};
|
||||
|
||||
export const handleImportExcel = async (vm, option, column, businessName, onSuccess, options = {}) => {
|
||||
const { failDetailDecorator } = options;
|
||||
const { failDetailDecorator, timeout = 60000 } = options;
|
||||
const file = option.file;
|
||||
const fileName = file && file.name ? file.name.toLowerCase() : '';
|
||||
if (!excelPattern.test(fileName)) {
|
||||
@@ -77,7 +93,7 @@ export const handleImportExcel = async (vm, option, column, businessName, onSucc
|
||||
background: 'rgba(255, 255, 255, 0.7)',
|
||||
});
|
||||
try {
|
||||
const res = await importBlob(column.action, file);
|
||||
const res = await importBlob(column.action, file, { timeout });
|
||||
if (isExcelResponse(res)) {
|
||||
const decorated = await decorateFailExcel(res.data, businessName, failDetailDecorator);
|
||||
downloadXls(
|
||||
|
||||
Reference in New Issue
Block a user