django-vue3-admin-web/dist/assets/uploader-form-8595f8fc.Da6W46xR.js
2025-10-20 21:21:14 +08:00

2 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{f as i,m as p,h as c,y as l}from"./index.Ct5zz34E.js";import"./vue.CZk_9PbR.js";function d(t,s,r){let e;r.response?e=`${r.response.error||r.response}`:r.responseText?e=`${r.responseText}`:e=`fail to post ${t} ${r.status}`;const o=new Error(e);return o.status=r.status,o.method="post",o.url=t,o}function f(t){const s=t.responseText||t.response;if(!s)return s;try{return JSON.parse(s)}catch{return s}}function m(t,s,r){if(typeof XMLHttpRequest>"u")return;const e=new XMLHttpRequest,o=t.action;e.timeout=t.timeout,e.upload&&(e.upload.onprogress=function(n){n.total>0&&(n.percent=n.loaded/n.total*100),t.onProgress(n)});const u=new FormData;t.data&&Object.keys(t.data).forEach(n=>{u.append(n,t.data[n])}),u.append(t.name,t.file,t.file.name),e.onerror=function(n){r(n)},e.onload=function(){if(e.status<200||e.status>=300)return t.onError(d(o,t,e));s(f(e))},e.open("post",o,!0),t.withCredentials&&"withCredentials"in e&&(e.withCredentials=!0);const a=t.headers||{};for(const n in a)a.hasOwnProperty(n)&&a[n]!==null&&e.setRequestHeader(n,a[n]);return e.send(u),e}function w(t){return new Promise((s,r)=>{m(t,async e=>{s(e)},e=>{r(e)})})}async function y(t){const{file:s,fileName:r,onProgress:e}=t,o=t.options,u=await l(s,r,o);o.data==null&&(o.data={}),o.data.key=u;const a={file:s,onProgress:e,timeout:6e4,...o};delete a.uploadRequest;let n=await(o.uploadRequest??w)(a);if(o.successHandle&&(n=await o.successHandle(n,a)),!n)throw new Error("上传成功successHandle处理后必须返回数据格式为 url 或{url} 或 {key}等");return n&&typeof n=="object"&&n.key==null&&(n.key=u),n}async function k(t){const{getConfig:s}=i(),r=s("form");return t.options=p({},c(r),t.options),await y(t)}export{k as upload};