1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
import{n as e}from"./request--UCyt0wo.js";async function t(t,i,a){let o=localStorage.getItem(`token`),s,c=``;try{let n=await e.get(t,{baseURL:`/index.php`,params:i,responseType:`blob`,headers:o?{Authorization:`Bearer ${o}`}:{}});s=n.data,c=n.headers[`content-disposition`]||``}catch(e){let t=e?.response?.status,r=e?.response?.data;if(t===401){window.$message?.error(`您未登录,或者登录已经超时,请先登录!`),localStorage.removeItem(`token`),localStorage.removeItem(`auth-storage`),window.location.href=`/login`;return}if(r instanceof Blob){await n(r);return}window.$message?.error(`下载失败,请稍后重试`);return}if(s.type.includes(`application/json`)){await n(s);return}let l=r(c)||a,u=URL.createObjectURL(s),d=document.createElement(`a`);d.href=u,d.download=l,document.body.appendChild(d),d.click(),d.remove(),URL.revokeObjectURL(u)}async function n(e){try{let t=JSON.parse(await e.text());window.$message?.error(t?.msg||`导出失败`)}catch{window.$message?.error(`导出失败`)}}function r(e){if(!e)return null;let t=e.match(/filename\*\s*=\s*(?:UTF-8|utf-8)''([^;]+)/i);if(t?.[1])try{return decodeURIComponent(t[1].trim())}catch{return null}let n=e.match(/filename\s*=\s*"?([^";]+)"?/i);if(n?.[1])try{return decodeURIComponent(n[1].trim())}catch{return n[1].trim()}return null}export{t}; |