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.

1 line
3.4 KiB

import{a as e,i as t}from"./index-hRul7OAA.js";function n(e){if(!e||typeof e!=`object`)throw Error(`列表响应格式无效`);let t=e;if(Array.isArray(t.data)&&typeof t.current_page==`number`){let e=t.data;return{data:e,meta:{current_page:t.current_page,last_page:typeof t.last_page==`number`?t.last_page:1,per_page:typeof t.per_page==`number`?t.per_page:e.length||15,total:typeof t.total==`number`?t.total:e.length}}}throw Error(`列表响应格式无效`)}async function r(e,r){let{data:i}=await t.get(`/competitions/${e}/applications`,{params:r});return n(i)}async function i(e,n){let{data:r}=await t.get(`/competitions/${e}/applications/${n}`);if(!r||typeof r!=`object`)throw Error(`报名详情无效`);return r}async function a(n,r){try{let{data:e}=await t.post(`/competitions/${n}/applications/${r}/impersonate`);if(!e||typeof e!=`object`)throw Error(`代登响应无效`);let i=e;if(typeof i.token!=`string`||!i.token.trim())throw Error(`代登 Token 无效`);if(typeof i.competition_slug!=`string`||!i.competition_slug.trim())throw Error(`赛事标识无效`);return{token:i.token,competition_slug:i.competition_slug,expires_in:typeof i.expires_in==`number`?i.expires_in:1800,participant:i.participant&&typeof i.participant==`object`?i.participant:void 0}}catch(t){if(e.isAxiosError(t)){let e=t.response?.data;if(e&&typeof e==`object`){let t=e.message;if(typeof t==`string`&&t.trim())throw Error(t.trim())}}throw t instanceof Error?t:Error(`进入选手端失败`)}}async function o(e,n,r,i){try{s((await t.get(`/competitions/${e}/applications/${n}/files/${r}/download`,{responseType:`blob`})).data,i||`附件`)}catch(e){throw await l(e,`下载附件失败`)}}function s(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}function c(e,t){if(!e)return t;let n=/filename\*=UTF-8''([^;]+)/i.exec(e);if(n?.[1])return decodeURIComponent(n[1]);let r=/filename="?([^";]+)"?/i.exec(e);return r?.[1]?r[1]:t}async function l(t,n){if(e.isAxiosError(t)){let e=t.response?.data;if(e instanceof Blob){let t=await e.text();try{let e=JSON.parse(t);return Error(e.errors?.export?.[0]||e.errors?.application_ids?.[0]||e.errors?.part?.[0]||e.errors?.file?.[0]||e.message||n)}catch{}}if(e&&typeof e==`object`){let t=e;return Error(t.errors?.export?.[0]||t.errors?.application_ids?.[0]||t.errors?.part?.[0]||t.errors?.file?.[0]||t.message||n)}}return t instanceof Error?t:Error(n)}async function u(e){return l(e,`导出失败`)}function d(e){return new Promise(t=>{window.setTimeout(t,e)})}function f(e){let{mode:t,application_ids:n,part:r,...i}=e,a={mode:t,...i};return n?.length&&(a.application_ids=n),r!=null&&(a.part=r),a}async function p(e,n){try{let{data:r}=await t.get(`/competitions/${e}/applications/export/meta`,{params:f(n)});if(!r||typeof r!=`object`)throw Error(`导出信息无效`);return r}catch(e){throw await u(e)}}async function m(e,n,r){let i;try{i=await t.get(`/competitions/${e}/applications/export`,{params:f({...n,part:r}),responseType:`blob`,timeout:0})}catch(e){throw await u(e)}let a=n.mode===`xlsx`?`报名信息.xlsx`:`报名信息导出_第${r}部分.zip`,o=c(i.headers[`content-disposition`],a);s(i.data,o)}async function h(e,t,n){let r=await p(e,t);if(t.mode===`xlsx`)return n?.(1,1),await m(e,t,1),r;for(let i=1;i<=r.part_count;i+=1)n?.(i,r.part_count),await m(e,t,i),i<r.part_count&&await d(500);return r}export{a,p as i,h as n,r as o,i as r,o as t};