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.
12 lines
594 B
12 lines
594 B
async function apiDownload(path, method) { // 二进制直出(联系人导出/模板):失败时服务端回信封 JSON,成功返回 blob
|
|
const opt = { method: method || 'GET' };
|
|
if (TOKEN()) opt.headers = { Authorization: 'Bearer ' + TOKEN() };
|
|
const res = await fetch(API_BASE + path, opt);
|
|
const ct = res.headers.get('Content-Type') || '';
|
|
if (ct.indexOf('json') >= 0) {
|
|
const body = await res.json();
|
|
const e = new Error(body.message || '下载失败'); e.code = body.code; throw e;
|
|
}
|
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
return res.blob();
|
|
}
|
|
|