2 lines
2.1 KiB
JavaScript
2 lines
2.1 KiB
JavaScript
|
"use strict";var e=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,n=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o;const i=require("../common/vendor.js"),l=require("../store/user.js"),u=e=>{const u=l.useUserStore();return new Promise(((l,p)=>{var d,c;i.index.request((d=((e,t)=>{for(var r in t||(t={}))s.call(t,r)&&n(e,r,t[r]);if(o)for(var r of o(t))a.call(t,r)&&n(e,r,t[r]);return e})({},e),c={url:e.url,dataType:"json",success(t){t.statusCode>=200&&t.statusCode<300?l(t.data):401===t.statusCode?(u.clearUserInfo(),i.index.navigateTo({url:"/pages/login/index"}),p(t)):(!e.hideErrorToast&&i.index.showToast({icon:"none",title:t.data.message||"请求错误"}),p(t))},fail(e){i.index.showToast({icon:"none",title:"网络错误,换个网络试试"}),p(e)}},t(d,r(c))))}))},p=(e,t)=>u({url:e,query:t,method:"GET"}),d=(e,t,r)=>u({url:e,query:r,data:t,method:"POST"}),c=(e,t,r="file",o={})=>{const s=l.useUserStore();return new Promise(((a,n)=>{i.index.uploadFile({url:e,filePath:t,name:r,formData:o,header:{satoken:`Bearer ${s.token}`},timeout:1e4,success(e){e.statusCode>=200&&e.statusCode<300?a(JSON.parse(e.data)):401===e.statusCode?(s.clearUserInfo(),i.index.navigateTo({url:"/pages/login/index"}),n(e)):(i.index.showToast({icon:"none",title:"上传失败,"+(JSON.parse(e.data).message||"请稍后重试")}),n(e))},fail(e){i.index.showToast({icon:"none",title:"网络错误,换个网络试试"}),n(e)}})}))},h=(e,t,...r)=>{return o=exports,s=[e,t,...r],a=function*(e,t,r="file",o={}){const s=[];for(const n of t)try{const t=yield c(e,n,r,o);200==t.code&&s.push(t.data.url)}catch(a){}return s},new Promise(((e,t)=>{var r=e=>{try{i(a.next(e))}catch(r){t(r)}},n=e=>{try{i(a.throw(e))}catch(r){t(r)}},i=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,n);i((a=a.apply(o,s)).next())}));var o,s,a};u.uploadFile=c,u.uploadMultipleFiles=h,u.get=p,u.post=d,exports.http=u,exports.httpGet=p,exports.httpPost=d,exports.httpUploadFile=c,exports.httpUploadMultipleFiles=h;
|