@duxweb/dvha-core 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("vue"),d=require("vue-router"),h=require("../stores/auth.cjs"),s=require("./manage.cjs");function m(e){const n=s.useManage(),o=h.useAuthStore(),r=d.useRouter(),g=S.ref(!1);return{mutate:async t=>{var c,i,f;g.value=!0;const u=await((c=n.config.authProvider)==null?void 0:c.login(t,n));if(g.value=!1,u!=null&&u.success){if(!(u!=null&&u.data))throw new Error("Login response data is undefined");(i=e==null?void 0:e.onSuccess)==null||i.call(e,u),o.login(u.data),r.push(n.getRoutePath(u.redirectTo||"/"));return}(f=e==null?void 0:e.onError)==null||f.call(e,u)},isLoading:g}}function P(e){const n=s.useManage(),o=h.useAuthStore(),r=d.useRouter();return{mutate:async a=>{var u,c,i;const t=await((u=n.config.authProvider)==null?void 0:u.logout(a,n));if(t!=null&&t.success){(c=e==null?void 0:e.onSuccess)==null||c.call(e,t),o.logout(),await r.replace(n.getRoutePath(t.redirectTo||"/login")),setTimeout(()=>{window.location.reload()},100);return}(i=e==null?void 0:e.onError)==null||i.call(e,t)}}}function w(e){const n=s.useManage(),o=h.useAuthStore(),r=d.useRouter();return{mutate:async a=>{var u,c,i;const t=await((u=n.config.authProvider)==null?void 0:u.check(a,n));if(t!=null&&t.success){if((c=e==null?void 0:e.onSuccess)==null||c.call(e,t),!(t!=null&&t.data))throw new Error("Check response data is undefined");o.update(t.data);return}(i=e==null?void 0:e.onError)==null||i.call(e,t),t!=null&&t.logout&&r.push(n.getRoutePath(t.redirectTo||"/login"))}}}function R(e){const n=s.useManage(),o=h.useAuthStore(),r=d.useRouter();return{mutate:async a=>{var u,c,i,f;const t=await((c=(u=n.config.authProvider)==null?void 0:u.register)==null?void 0:c.call(u,a,n));if(t!=null&&t.success){if((i=e==null?void 0:e.onSuccess)==null||i.call(e,t),!(t!=null&&t.data))throw new Error("Register response data is undefined");o.login(t.data),r.push(n.getRoutePath(t.redirectTo||""));return}(f=e==null?void 0:e.onError)==null||f.call(e,t)}}}function v(e){const n=s.useManage(),o=d.useRouter();return{mutate:async g=>{var t,u,c,i;const a=await((u=(t=n.config.authProvider)==null?void 0:t.forgotPassword)==null?void 0:u.call(t,g,n));if(a!=null&&a.success){(c=e==null?void 0:e.onSuccess)==null||c.call(e,a),a.redirectTo&&o.push(n.getRoutePath(a.redirectTo));return}(i=e==null?void 0:e.onError)==null||i.call(e,a)}}}function E(e){const n=s.useManage(),o=d.useRouter();return{mutate:async g=>{var t,u,c,i;const a=await((u=(t=n.config.authProvider)==null?void 0:t.updatePassword)==null?void 0:u.call(t,g,n));if(a!=null&&a.success){(c=e==null?void 0:e.onSuccess)==null||c.call(e,a),a.redirectTo&&o.push(n.getRoutePath(a.redirectTo));return}(i=e==null?void 0:e.onError)==null||i.call(e,a)}}}function T(e){const{config:n,getRoutePath:o}=s.useManage(),r=d.useRouter();return{mutate:async a=>{var u;const t=await((u=n.authProvider)==null?void 0:u.onError(a));e==null||e(t),t!=null&&t.logout&&r.push(o(t.redirectTo||"/login"))}}}function y(e){return h.useAuthStore(e).getUser()}function A(e){return h.useAuthStore(e).isLogin()}function L(e){const n=s.useManage(e),r=h.useAuthStore(e).getUser();return(a,t)=>{var u;return(u=n.config.authProvider)!=null&&u.can?n.config.authProvider.can(a,t,n,r):!0}}exports.useCan=L;exports.useCheck=w;exports.useError=T;exports.useForgotPassword=v;exports.useGetAuth=y;exports.useIsLogin=A;exports.useLogin=m;exports.useLogout=P;exports.useRegister=R;exports.useUpdatePassword=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("vue"),f=require("vue-router"),d=require("../stores/auth.cjs"),h=require("./manage.cjs");function S(e){const n=h.useManage(),i=d.useAuthStore(),r=f.useRouter(),g=w.ref(!1);return{mutate:async t=>{var c,o,s;g.value=!0;const u=await((c=n.config.authProvider)==null?void 0:c.login(t,n));if(g.value=!1,u!=null&&u.success){if(!(u!=null&&u.data))throw new Error("Login response data is undefined");(o=e==null?void 0:e.onSuccess)==null||o.call(e,u),i.login(u.data),r.push(n.getRoutePath(u.redirectTo||"/"));return}(s=e==null?void 0:e.onError)==null||s.call(e,u)},isLoading:g}}function m(e){const n=h.useManage(),i=d.useAuthStore(),r=f.useRouter();return{mutate:async a=>{var u,c,o;const t=await((u=n.config.authProvider)==null?void 0:u.logout(a,n));if(t!=null&&t.success){(c=e==null?void 0:e.onSuccess)==null||c.call(e,t),i.logout(),await r.replace(n.getRoutePath(t.redirectTo||"/login")),setTimeout(()=>{window.location.reload()},100);return}(o=e==null?void 0:e.onError)==null||o.call(e,t)}}}function P(e){const n=h.useManage(),i=d.useAuthStore(),r=f.useRouter();return{mutate:async a=>{var u,c,o,s;const t=await((c=(u=n.config.authProvider)==null?void 0:u.check)==null?void 0:c.call(u,a,n,i.getUser()));if(t!=null&&t.success){if((o=e==null?void 0:e.onSuccess)==null||o.call(e,t),!(t!=null&&t.data))throw new Error("Check response data is undefined");i.update(t.data);return}(s=e==null?void 0:e.onError)==null||s.call(e,t),t!=null&&t.logout&&(await r.replace(n.getRoutePath(t.redirectTo||"/login")),setTimeout(()=>{window.location.reload()},100))}}}function R(e){const n=h.useManage(),i=d.useAuthStore(),r=f.useRouter();return{mutate:async a=>{var u,c,o,s;const t=await((c=(u=n.config.authProvider)==null?void 0:u.register)==null?void 0:c.call(u,a,n));if(t!=null&&t.success){if((o=e==null?void 0:e.onSuccess)==null||o.call(e,t),!(t!=null&&t.data))throw new Error("Register response data is undefined");i.login(t.data),r.push(n.getRoutePath(t.redirectTo||"/"));return}(s=e==null?void 0:e.onError)==null||s.call(e,t)}}}function v(e){const n=h.useManage(),i=f.useRouter();return{mutate:async g=>{var t,u,c,o;const a=await((u=(t=n.config.authProvider)==null?void 0:t.forgotPassword)==null?void 0:u.call(t,g,n));if(a!=null&&a.success){(c=e==null?void 0:e.onSuccess)==null||c.call(e,a),a.redirectTo&&i.push(n.getRoutePath(a.redirectTo||"/"));return}(o=e==null?void 0:e.onError)==null||o.call(e,a)}}}function T(e){const n=h.useManage(),i=f.useRouter();return{mutate:async g=>{var t,u,c,o;const a=await((u=(t=n.config.authProvider)==null?void 0:t.updatePassword)==null?void 0:u.call(t,g,n));if(a!=null&&a.success){(c=e==null?void 0:e.onSuccess)==null||c.call(e,a),a.redirectTo&&i.push(n.getRoutePath(a.redirectTo||"/"));return}(o=e==null?void 0:e.onError)==null||o.call(e,a)}}}function E(e){const{config:n,getRoutePath:i}=h.useManage(),r=f.useRouter(),g=d.useAuthStore();return{mutate:async t=>{var c;const u=await((c=n.authProvider)==null?void 0:c.onError(t));e==null||e(u),u!=null&&u.logout&&(g.logout(),await r.replace(i(u.redirectTo||"/login")),setTimeout(()=>{window.location.reload()},100))}}}function A(e){return d.useAuthStore(e).getUser()}function y(e){return d.useAuthStore(e).isLogin()}function L(e){const n=h.useManage(e),r=d.useAuthStore(e).getUser();return(a,t)=>{var u;return(u=n.config.authProvider)!=null&&u.can?n.config.authProvider.can(a,t,n,r):!0}}exports.useCan=L;exports.useCheck=P;exports.useError=E;exports.useForgotPassword=v;exports.useGetAuth=A;exports.useIsLogin=y;exports.useLogin=S;exports.useLogout=m;exports.useRegister=R;exports.useUpdatePassword=T;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("@vueuse/core"),H=require("lodash-es"),d=require("vue"),J=require("./upload/local.cjs");function Q(a){a=a||{};const v=d.ref(!1),i=d.ref([]),f=d.ref(-1),m=d.ref(new Map),A=a.driver||J.createLocalUploadDriver(),$=d.computed(()=>{const{onProgress:e,onDataCallback:n,onCancel:l,onComplete:t,maxFileSize:r,maxFileCount:c,accept:o,multiple:s,autoUpload:u,options:S,onSuccess:P,onError:b,method:W,driver:X,...V}=a;return V}),I=d.computed(()=>a.method||"POST"),x=d.computed(()=>{const e=i.value.length,n=i.value.reduce((c,o)=>c+(o.filesize||0),0);let l=0,t=0;return i.value.forEach((c,o)=>{var s;o<f.value?l+=c.filesize||0:o===f.value&&(l+=((s=c.progress)==null?void 0:s.loaded)||0)}),n>0&&(t=Math.round(l/n*100)),{index:f.value>=0?f.value+1:0,totalFiles:e,currentFile:i.value[f.value],totalPercent:t,totalLoaded:l,totalSize:n}}),w=e=>{if(e===0)return"0 Bytes";const n=1024,l=["Bytes","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(n));return`${Number.parseFloat((e/n**t).toFixed(2))} ${l[t]}`},g=e=>{if(e===0)return"0 B/s";const n=1024,l=["B/s","KB/s","MB/s","GB/s"],t=Math.floor(Math.log(e)/Math.log(n));return`${Number.parseFloat((e/n**t).toFixed(2))} ${l[t]}`},T=()=>H.uniqueId("upload-"),k=async(e,n,l)=>{switch(n){case"file":{if(!(e instanceof File))throw new TypeError('Payload must be a File when type is "file"');return e}case"blob":{if(!(e instanceof Blob))throw new TypeError('Payload must be a Blob when type is "blob"');return new File([e],"blob-file",{type:e.type})}case"base64":{if(typeof e!="string")throw new TypeError('Payload must be a string when type is "base64"');const t=e.includes(",")?e.split(",")[1]:e,r=e.includes(",")?e.split(",")[0].split(":")[1].split(";")[0]:"application/octet-stream",c=atob(t),o=new Uint8Array(c.length);for(let u=0;u<c.length;u++)o[u]=c.charCodeAt(u);const s=new Blob([o],{type:r});return new File([s],"base64-file",{type:r})}case"arrayBuffer":{if(!(e instanceof ArrayBuffer))throw new TypeError('Payload must be ArrayBuffer when type is "arrayBuffer"');const t=new Blob([e]);return new File([t],"array-buffer-file",{type:"application/octet-stream"})}default:throw new Error(`Unsupported upload type: ${n}`)}},z=e=>{if(a.maxFileSize&&e.size>a.maxFileSize)throw new Error(`File size cannot exceed ${w(a.maxFileSize)}`);if(a.maxFileCount&&i.value.length>=a.maxFileCount)throw new Error(`File count cannot exceed ${a.maxFileCount}`)},q=async(e,n,l)=>{const t=await k(e,n);z(t);const r={id:T(),file:t,filename:t.name,filesize:t.size,filetype:t.type,filesizeText:w(t.size),status:"pending",progress:{loaded:0,total:t.size,percent:0,speed:0,speedText:g(0),remainingTime:0,uploadTime:0}};return i.value.push(r),r},h=(e,n)=>{const l=i.value.findIndex(t=>t.id===e);l!==-1&&(i.value[l]={...i.value[l],...n})},C=()=>{var n;i.value.every(l=>l.status!=="uploading")&&((n=a.onComplete)==null||n.call(a,i.value))},y=e=>{var l;const n=i.value.find(t=>t.id===e);if(!n||n.status!=="pending"&&n.status!=="uploading")return!1;if(n.status==="uploading"){const t=m.value.get(e);t&&(t.abort(),m.value.delete(e))}return h(e,{status:"cancelled"}),(l=a.onCancel)==null||l.call(a,e),C(),!0},D=e=>{e?e.forEach(n=>y(n)):i.value.forEach(n=>y(n.id))},G=async e=>{if(!e.file)throw new Error("File not found");z(e.file);const n=new AbortController;m.value.set(e.id,n);const l=Date.now();return h(e.id,{status:"uploading"}),A.upload(e.file,{...$.value,method:I.value,signal:n.signal,onUploadProgress:t=>{var b;const o=(Date.now()-l)/1e3,s=o>0?t.loaded/o:0,u=(t.total||0)-t.loaded,S=s>0?u/s:0,P={loaded:t.loaded,total:t.total,percent:t.percent||0,speed:Math.round(s),speedText:g(s),uploadTime:Math.round(o),remainingTime:Math.round(S)};h(e.id,{status:"uploading",progress:P}),(b=a.onProgress)==null||b.call(a,x.value)}}).then(t=>{var s,u;if(e.status==="cancelled")throw new Error("Upload cancelled");const r=((s=a.onDataCallback)==null?void 0:s.call(a,t,e))||t.data,c=Math.round((Date.now()-l)/1e3),o={...e,status:"success",data:t,...r,progress:{...e.progress,loaded:e.filesize||0,percent:100,speed:0,speedText:g(0),uploadTime:c,remainingTime:0}};return h(e.id,o),m.value.delete(e.id),(u=a.onSuccess)==null||u.call(a,t),o}).catch(t=>{throw t.message==="canceled"||e.status==="cancelled"?new Error("Upload cancelled"):(h(e.id,{status:"error",error:t.message}),m.value.delete(e.id),t)}).finally(()=>{C()})},E=async()=>{var n;const e=i.value.filter(l=>l.status==="pending");if(e.length===0)return[];v.value=!0;try{const l=[];for(let t=0;t<e.length;t++){const r=e[t],c=i.value.findIndex(s=>s.id===r.id);f.value=c;const o=await G(r);l.push(o)}return l}catch(l){throw(n=a.onError)==null||n.call(a,{status:(l==null?void 0:l.status)||500,message:(l==null?void 0:l.message)||"upload failed"}),l}finally{v.value=!1,f.value=-1}},F=()=>{i.value.forEach(e=>{y(e.id)}),m.value.clear(),i.value=[],f.value=-1},B=async(e,n="file")=>{var l;try{if(!a.multiple&&e.length>1)throw new Error("Single file mode: only one file can be selected");if(!a.multiple&&i.value.length>0&&F(),a.maxFileCount&&i.value.length+e.length>a.maxFileCount)throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${a.maxFileCount}`);for(const t of e)await q(t,n)}catch(t){throw(l=a.onError)==null||l.call(a,{status:(t==null?void 0:t.status)||400,message:(t==null?void 0:t.message)||"Failed to add files"}),t}a.autoUpload&&E().catch(t=>{console.warn("Auto upload failed:",t)})},M=e=>{const n=i.value.find(t=>t.id===e);if(n&&n.status==="uploading"){h(e,{status:"cancelled"});const t=m.value.get(e);if(!t)return;t.abort(),m.value.delete(e)}const l=i.value.findIndex(t=>t.id===e);l!==-1&&i.value.splice(l,1)},K=e=>{e?e.forEach(n=>M(n)):i.value.forEach(n=>M(n.id))},{files:L,open:N,reset:U}=_.useFileDialog({accept:a.accept,multiple:a.multiple||!1}),O=e=>({id:T(),...e,filesizeText:e.filesize?w(e.filesize):void 0,status:e.url?"success":"pending",progress:{loaded:0,total:e.filesize||0,percent:e.url?100:0,speed:0,speedText:g(0),remainingTime:0,uploadTime:0}});d.watch(L,async e=>{if(e&&e.length>0){const n=Array.from(e);U(),await B(n,"file").catch(l=>{console.warn("Failed to add selected files:",l)})}});const j=d.computed(()=>i.value.filter(e=>e.status==="success").map(e=>({url:e.url,filename:e.filename,filesize:e.filesize,filetype:e.filetype})));return{isUploading:v,uploadFiles:i,dataFiles:j,progress:x,open:N,trigger:E,resetFiles:U,clearFiles:F,removeFiles:K,addFiles:B,addDataFiles:e=>{!a.multiple&&i.value.length>0&&F();const n=e.map(l=>O(l));i.value.push(...n)},cancelFiles:D}}exports.useUpload=Q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("@vueuse/core"),H=require("lodash-es"),d=require("vue"),J=require("./upload/local.cjs");function Q(l){l=l||{};const v=d.ref(!1),i=d.ref([]),f=d.ref(-1),m=d.ref(new Map),A=l.driver||J.createLocalUploadDriver(),$=d.computed(()=>{const{onProgress:e,onDataCallback:n,onCancel:a,onComplete:t,maxFileSize:c,maxFileCount:r,accept:o,multiple:s,autoUpload:u,options:S,onSuccess:P,onError:b,method:W,driver:X,params:Y,...V}=l;return V}),I=d.computed(()=>l.method||"POST"),x=d.computed(()=>{const e=i.value.length,n=i.value.reduce((r,o)=>r+(o.filesize||0),0);let a=0,t=0;return i.value.forEach((r,o)=>{var s;o<f.value?a+=r.filesize||0:o===f.value&&(a+=((s=r.progress)==null?void 0:s.loaded)||0)}),n>0&&(t=Math.round(a/n*100)),{index:f.value>=0?f.value+1:0,totalFiles:e,currentFile:i.value[f.value],totalPercent:t,totalLoaded:a,totalSize:n}}),w=e=>{if(e===0)return"0 Bytes";const n=1024,a=["Bytes","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(n));return`${Number.parseFloat((e/n**t).toFixed(2))} ${a[t]}`},g=e=>{if(e===0)return"0 B/s";const n=1024,a=["B/s","KB/s","MB/s","GB/s"],t=Math.floor(Math.log(e)/Math.log(n));return`${Number.parseFloat((e/n**t).toFixed(2))} ${a[t]}`},T=()=>H.uniqueId("upload-"),k=async(e,n,a)=>{switch(n){case"file":{if(!(e instanceof File))throw new TypeError('Payload must be a File when type is "file"');return e}case"blob":{if(!(e instanceof Blob))throw new TypeError('Payload must be a Blob when type is "blob"');return new File([e],"blob-file",{type:e.type})}case"base64":{if(typeof e!="string")throw new TypeError('Payload must be a string when type is "base64"');const t=e.includes(",")?e.split(",")[1]:e,c=e.includes(",")?e.split(",")[0].split(":")[1].split(";")[0]:"application/octet-stream",r=atob(t),o=new Uint8Array(r.length);for(let u=0;u<r.length;u++)o[u]=r.charCodeAt(u);const s=new Blob([o],{type:c});return new File([s],"base64-file",{type:c})}case"arrayBuffer":{if(!(e instanceof ArrayBuffer))throw new TypeError('Payload must be ArrayBuffer when type is "arrayBuffer"');const t=new Blob([e]);return new File([t],"array-buffer-file",{type:"application/octet-stream"})}default:throw new Error(`Unsupported upload type: ${n}`)}},z=e=>{if(l.maxFileSize&&e.size>l.maxFileSize)throw new Error(`File size cannot exceed ${w(l.maxFileSize)}`);if(l.maxFileCount&&i.value.length>=l.maxFileCount)throw new Error(`File count cannot exceed ${l.maxFileCount}`)},q=async(e,n,a)=>{const t=await k(e,n);z(t);const c={id:T(),file:t,filename:t.name,filesize:t.size,filetype:t.type,filesizeText:w(t.size),status:"pending",progress:{loaded:0,total:t.size,percent:0,speed:0,speedText:g(0),remainingTime:0,uploadTime:0}};return i.value.push(c),c},h=(e,n)=>{const a=i.value.findIndex(t=>t.id===e);a!==-1&&(i.value[a]={...i.value[a],...n})},C=()=>{var n;i.value.every(a=>a.status!=="uploading")&&((n=l.onComplete)==null||n.call(l,i.value))},y=e=>{var a;const n=i.value.find(t=>t.id===e);if(!n||n.status!=="pending"&&n.status!=="uploading")return!1;if(n.status==="uploading"){const t=m.value.get(e);t&&(t.abort(),m.value.delete(e))}return h(e,{status:"cancelled"}),(a=l.onCancel)==null||a.call(l,e),C(),!0},D=e=>{e?e.forEach(n=>y(n)):i.value.forEach(n=>y(n.id))},G=async e=>{if(!e.file)throw new Error("File not found");z(e.file);const n=new AbortController;m.value.set(e.id,n);const a=Date.now();return h(e.id,{status:"uploading"}),A.upload(e.file,{...$.value,method:I.value,signal:n.signal,params:l.params,onUploadProgress:t=>{var b;const o=(Date.now()-a)/1e3,s=o>0?t.loaded/o:0,u=(t.total||0)-t.loaded,S=s>0?u/s:0,P={loaded:t.loaded,total:t.total,percent:t.percent||0,speed:Math.round(s),speedText:g(s),uploadTime:Math.round(o),remainingTime:Math.round(S)};h(e.id,{status:"uploading",progress:P}),(b=l.onProgress)==null||b.call(l,x.value)}}).then(t=>{var s,u;if(e.status==="cancelled")throw new Error("Upload cancelled");const c=((s=l.onDataCallback)==null?void 0:s.call(l,t,e))||t.data,r=Math.round((Date.now()-a)/1e3),o={...e,status:"success",data:t,...c,progress:{...e.progress,loaded:e.filesize||0,percent:100,speed:0,speedText:g(0),uploadTime:r,remainingTime:0}};return h(e.id,o),m.value.delete(e.id),(u=l.onSuccess)==null||u.call(l,t),o}).catch(t=>{throw t.message==="canceled"||e.status==="cancelled"?new Error("Upload cancelled"):(h(e.id,{status:"error",error:t.message}),m.value.delete(e.id),t)}).finally(()=>{C()})},E=async()=>{var n;const e=i.value.filter(a=>a.status==="pending");if(e.length===0)return[];v.value=!0;try{const a=[];for(let t=0;t<e.length;t++){const c=e[t],r=i.value.findIndex(s=>s.id===c.id);f.value=r;const o=await G(c);a.push(o)}return a}catch(a){throw(n=l.onError)==null||n.call(l,{status:(a==null?void 0:a.status)||500,message:(a==null?void 0:a.message)||"upload failed"}),a}finally{v.value=!1,f.value=-1}},F=()=>{i.value.forEach(e=>{y(e.id)}),m.value.clear(),i.value=[],f.value=-1},B=async(e,n="file")=>{var a;try{if(!l.multiple&&e.length>1)throw new Error("Single file mode: only one file can be selected");if(!l.multiple&&i.value.length>0&&F(),l.maxFileCount&&i.value.length+e.length>l.maxFileCount)throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);for(const t of e)await q(t,n)}catch(t){throw(a=l.onError)==null||a.call(l,{status:(t==null?void 0:t.status)||400,message:(t==null?void 0:t.message)||"Failed to add files"}),t}l.autoUpload&&E().catch(t=>{console.warn("Auto upload failed:",t)})},M=e=>{const n=i.value.find(t=>t.id===e);if(n&&n.status==="uploading"){h(e,{status:"cancelled"});const t=m.value.get(e);if(!t)return;t.abort(),m.value.delete(e)}const a=i.value.findIndex(t=>t.id===e);a!==-1&&i.value.splice(a,1)},K=e=>{e?e.forEach(n=>M(n)):i.value.forEach(n=>M(n.id))},{files:L,open:N,reset:U}=_.useFileDialog({accept:l.accept,multiple:l.multiple||!1}),O=e=>({id:T(),...e,filesizeText:e.filesize?w(e.filesize):void 0,status:e.url?"success":"pending",progress:{loaded:0,total:e.filesize||0,percent:e.url?100:0,speed:0,speedText:g(0),remainingTime:0,uploadTime:0}});d.watch(L,async e=>{if(e&&e.length>0){const n=Array.from(e);U(),await B(n,"file").catch(a=>{console.warn("Failed to add selected files:",a)})}});const j=d.computed(()=>i.value.filter(e=>e.status==="success").map(e=>({url:e.url,filename:e.filename,filesize:e.filesize,filetype:e.filetype})));return{isUploading:v,uploadFiles:i,dataFiles:j,progress:x,open:N,trigger:E,resetFiles:U,clearFiles:F,removeFiles:K,addFiles:B,addDataFiles:e=>{!l.multiple&&i.value.length>0&&F();const n=e.map(a=>O(a));i.value.push(...n)},cancelFiles:D}}exports.useUpload=Q;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("axios");function l(t){return{login:async(n,c)=>{var d;return await g.post(c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.login)||"/login",t==null?void 0:t.dataProviderName),n).then(e=>{var i,a,s;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,redirectTo:((a=t==null?void 0:t.routePath)==null?void 0:a.index)||"/",data:(s=e==null?void 0:e.data)==null?void 0:s.data}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},check:async(n,c)=>{var d;return await g.get((c==null?void 0:c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.check)||"/check",t==null?void 0:t.dataProviderName))||"").then(e=>{var i,a;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,data:(a=e==null?void 0:e.data)==null?void 0:a.data}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},onError:async n=>{var c;return(n==null?void 0:n.status)===401?{logout:!0,redirectTo:((c=t==null?void 0:t.routePath)==null?void 0:c.login)||"/login",error:n}:{logout:!1,error:n}},logout:async()=>{var n;return{success:!0,redirectTo:((n=t==null?void 0:t.routePath)==null?void 0:n.login)||"/login"}},register:async(n,c)=>{var d;return await g.post((c==null?void 0:c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.register)||"/register",t==null?void 0:t.dataProviderName))||"",n).then(e=>{var i,a,s;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,redirectTo:((a=t==null?void 0:t.routePath)==null?void 0:a.index)||"/",data:(s=e==null?void 0:e.data)==null?void 0:s.data}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},forgotPassword:async(n,c)=>{var d;return await g.post((c==null?void 0:c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.forgotPassword)||"/forgot-password",t==null?void 0:t.dataProviderName))||"",n).then(e=>{var i,a;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,redirectTo:((a=t==null?void 0:t.routePath)==null?void 0:a.login)||"/login"}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},updatePassword:async(n,c)=>{var d;return await g.post((c==null?void 0:c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.updatePassword)||"/update-password",t==null?void 0:t.dataProviderName))||"",n).then(e=>{var i,a;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,redirectTo:((a=t==null?void 0:t.routePath)==null?void 0:a.login)||"/login"}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},can:(n,c,d,e)=>{var i,a;return!(e!=null&&e.permission)||Array.isArray(e==null?void 0:e.permission)&&((i=e==null?void 0:e.permission)==null?void 0:i.length)===0||typeof(e==null?void 0:e.permission)=="object"&&Object.keys(e==null?void 0:e.permission).length===0?!0:!(Array.isArray(e==null?void 0:e.permission)&&!((a=e==null?void 0:e.permission)!=null&&a.includes(n))||typeof(e==null?void 0:e.permission)=="object"&&(e==null?void 0:e.permission[n])===!1)}}}exports.simpleAuthProvider=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("axios");function l(t){return{login:async(n,c)=>{var d;return await g.post(c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.login)||"/login",t==null?void 0:t.dataProviderName),n).then(e=>{var i,a,s;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,redirectTo:((a=t==null?void 0:t.routePath)==null?void 0:a.index)||"/",data:(s=e==null?void 0:e.data)==null?void 0:s.data}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},check:async(n,c,d)=>{var e;return await g.get((c==null?void 0:c.getApiUrl(((e=t==null?void 0:t.apiPath)==null?void 0:e.check)||"/check",t==null?void 0:t.dataProviderName))||"",{headers:{Authorization:(d==null?void 0:d.token)||""}}).then(i=>{var a,s;return{success:!0,logout:!1,message:(a=i==null?void 0:i.data)==null?void 0:a.message,data:(s=i==null?void 0:i.data)==null?void 0:s.data}}).catch(i=>{var a,s;return{success:!1,logout:!0,message:((s=(a=i==null?void 0:i.response)==null?void 0:a.data)==null?void 0:s.message)||(i==null?void 0:i.message)}})},onError:async n=>{var c;return(n==null?void 0:n.status)===401?{logout:!0,redirectTo:((c=t==null?void 0:t.routePath)==null?void 0:c.login)||"/login",error:n}:{logout:!1,error:n}},logout:async()=>{var n;return{success:!0,redirectTo:((n=t==null?void 0:t.routePath)==null?void 0:n.login)||"/login"}},register:async(n,c)=>{var d;return await g.post((c==null?void 0:c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.register)||"/register",t==null?void 0:t.dataProviderName))||"",n).then(e=>{var i,a,s;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,redirectTo:((a=t==null?void 0:t.routePath)==null?void 0:a.index)||"/",data:(s=e==null?void 0:e.data)==null?void 0:s.data}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},forgotPassword:async(n,c)=>{var d;return await g.post((c==null?void 0:c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.forgotPassword)||"/forgot-password",t==null?void 0:t.dataProviderName))||"",n).then(e=>{var i,a;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,redirectTo:((a=t==null?void 0:t.routePath)==null?void 0:a.login)||"/login"}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},updatePassword:async(n,c)=>{var d;return await g.post((c==null?void 0:c.getApiUrl(((d=t==null?void 0:t.apiPath)==null?void 0:d.updatePassword)||"/update-password",t==null?void 0:t.dataProviderName))||"",n).then(e=>{var i,a;return{success:!0,message:(i=e==null?void 0:e.data)==null?void 0:i.message,redirectTo:((a=t==null?void 0:t.routePath)==null?void 0:a.login)||"/login"}}).catch(e=>{var i,a;return{success:!1,message:((a=(i=e==null?void 0:e.response)==null?void 0:i.data)==null?void 0:a.message)||(e==null?void 0:e.message)}})},can:(n,c,d,e)=>{var i,a;return!(e!=null&&e.permission)||Array.isArray(e==null?void 0:e.permission)&&((i=e==null?void 0:e.permission)==null?void 0:i.length)===0||typeof(e==null?void 0:e.permission)=="object"&&Object.keys(e==null?void 0:e.permission).length===0?!0:!(Array.isArray(e==null?void 0:e.permission)&&!((a=e==null?void 0:e.permission)!=null&&a.includes(n))||typeof(e==null?void 0:e.permission)=="object"&&(e==null?void 0:e.permission[n])===!1)}}}exports.simpleAuthProvider=l;
@@ -1,33 +1,33 @@
1
1
  import { ref as w } from "vue";
2
- import { useRouter as f } from "vue-router";
3
- import { useAuthStore as h } from "../stores/auth.js";
4
- import { useManage as d } from "./manage.js";
5
- function s(t) {
6
- const u = d(), o = h(), r = f(), g = w(!1);
2
+ import { useRouter as m } from "vue-router";
3
+ import { useAuthStore as f } from "../stores/auth.js";
4
+ import { useManage as h } from "./manage.js";
5
+ function v(t) {
6
+ const a = h(), o = f(), r = m(), g = w(!1);
7
7
  return {
8
8
  mutate: async (e) => {
9
- var c, i, m;
9
+ var c, i, d;
10
10
  g.value = !0;
11
- const n = await ((c = u.config.authProvider) == null ? void 0 : c.login(e, u));
11
+ const n = await ((c = a.config.authProvider) == null ? void 0 : c.login(e, a));
12
12
  if (g.value = !1, n != null && n.success) {
13
13
  if (!(n != null && n.data))
14
14
  throw new Error("Login response data is undefined");
15
- (i = t == null ? void 0 : t.onSuccess) == null || i.call(t, n), o.login(n.data), r.push(u.getRoutePath(n.redirectTo || "/"));
15
+ (i = t == null ? void 0 : t.onSuccess) == null || i.call(t, n), o.login(n.data), r.push(a.getRoutePath(n.redirectTo || "/"));
16
16
  return;
17
17
  }
18
- (m = t == null ? void 0 : t.onError) == null || m.call(t, n);
18
+ (d = t == null ? void 0 : t.onError) == null || d.call(t, n);
19
19
  },
20
20
  isLoading: g
21
21
  };
22
22
  }
23
- function R(t) {
24
- const u = d(), o = h(), r = f();
23
+ function E(t) {
24
+ const a = h(), o = f(), r = m();
25
25
  return {
26
- mutate: async (a) => {
26
+ mutate: async (u) => {
27
27
  var n, c, i;
28
- const e = await ((n = u.config.authProvider) == null ? void 0 : n.logout(a, u));
28
+ const e = await ((n = a.config.authProvider) == null ? void 0 : n.logout(u, a));
29
29
  if (e != null && e.success) {
30
- (c = t == null ? void 0 : t.onSuccess) == null || c.call(t, e), o.logout(), await r.replace(u.getRoutePath(e.redirectTo || "/login")), setTimeout(() => {
30
+ (c = t == null ? void 0 : t.onSuccess) == null || c.call(t, e), o.logout(), await r.replace(a.getRoutePath(e.redirectTo || "/login")), setTimeout(() => {
31
31
  window.location.reload();
32
32
  }, 100);
33
33
  return;
@@ -36,98 +36,102 @@ function R(t) {
36
36
  }
37
37
  };
38
38
  }
39
- function T(t) {
40
- const u = d(), o = h(), r = f();
39
+ function R(t) {
40
+ const a = h(), o = f(), r = m();
41
41
  return {
42
- mutate: async (a) => {
43
- var n, c, i;
44
- const e = await ((n = u.config.authProvider) == null ? void 0 : n.check(a, u));
42
+ mutate: async (u) => {
43
+ var n, c, i, d;
44
+ const e = await ((c = (n = a.config.authProvider) == null ? void 0 : n.check) == null ? void 0 : c.call(n, u, a, o.getUser()));
45
45
  if (e != null && e.success) {
46
- if ((c = t == null ? void 0 : t.onSuccess) == null || c.call(t, e), !(e != null && e.data))
46
+ if ((i = t == null ? void 0 : t.onSuccess) == null || i.call(t, e), !(e != null && e.data))
47
47
  throw new Error("Check response data is undefined");
48
48
  o.update(e.data);
49
49
  return;
50
50
  }
51
- (i = t == null ? void 0 : t.onError) == null || i.call(t, e), e != null && e.logout && r.push(u.getRoutePath(e.redirectTo || "/login"));
51
+ (d = t == null ? void 0 : t.onError) == null || d.call(t, e), e != null && e.logout && (await r.replace(a.getRoutePath(e.redirectTo || "/login")), setTimeout(() => {
52
+ window.location.reload();
53
+ }, 100));
52
54
  }
53
55
  };
54
56
  }
55
57
  function y(t) {
56
- const u = d(), o = h(), r = f();
58
+ const a = h(), o = f(), r = m();
57
59
  return {
58
- mutate: async (a) => {
59
- var n, c, i, m;
60
- const e = await ((c = (n = u.config.authProvider) == null ? void 0 : n.register) == null ? void 0 : c.call(n, a, u));
60
+ mutate: async (u) => {
61
+ var n, c, i, d;
62
+ const e = await ((c = (n = a.config.authProvider) == null ? void 0 : n.register) == null ? void 0 : c.call(n, u, a));
61
63
  if (e != null && e.success) {
62
64
  if ((i = t == null ? void 0 : t.onSuccess) == null || i.call(t, e), !(e != null && e.data))
63
65
  throw new Error("Register response data is undefined");
64
- o.login(e.data), r.push(u.getRoutePath(e.redirectTo || ""));
66
+ o.login(e.data), r.push(a.getRoutePath(e.redirectTo || "/"));
65
67
  return;
66
68
  }
67
- (m = t == null ? void 0 : t.onError) == null || m.call(t, e);
69
+ (d = t == null ? void 0 : t.onError) == null || d.call(t, e);
68
70
  }
69
71
  };
70
72
  }
71
73
  function L(t) {
72
- const u = d(), o = f();
74
+ const a = h(), o = m();
73
75
  return {
74
76
  mutate: async (g) => {
75
77
  var e, n, c, i;
76
- const a = await ((n = (e = u.config.authProvider) == null ? void 0 : e.forgotPassword) == null ? void 0 : n.call(e, g, u));
77
- if (a != null && a.success) {
78
- (c = t == null ? void 0 : t.onSuccess) == null || c.call(t, a), a.redirectTo && o.push(u.getRoutePath(a.redirectTo));
78
+ const u = await ((n = (e = a.config.authProvider) == null ? void 0 : e.forgotPassword) == null ? void 0 : n.call(e, g, a));
79
+ if (u != null && u.success) {
80
+ (c = t == null ? void 0 : t.onSuccess) == null || c.call(t, u), u.redirectTo && o.push(a.getRoutePath(u.redirectTo || "/"));
79
81
  return;
80
82
  }
81
- (i = t == null ? void 0 : t.onError) == null || i.call(t, a);
83
+ (i = t == null ? void 0 : t.onError) == null || i.call(t, u);
82
84
  }
83
85
  };
84
86
  }
85
87
  function U(t) {
86
- const u = d(), o = f();
88
+ const a = h(), o = m();
87
89
  return {
88
90
  mutate: async (g) => {
89
91
  var e, n, c, i;
90
- const a = await ((n = (e = u.config.authProvider) == null ? void 0 : e.updatePassword) == null ? void 0 : n.call(e, g, u));
91
- if (a != null && a.success) {
92
- (c = t == null ? void 0 : t.onSuccess) == null || c.call(t, a), a.redirectTo && o.push(u.getRoutePath(a.redirectTo));
92
+ const u = await ((n = (e = a.config.authProvider) == null ? void 0 : e.updatePassword) == null ? void 0 : n.call(e, g, a));
93
+ if (u != null && u.success) {
94
+ (c = t == null ? void 0 : t.onSuccess) == null || c.call(t, u), u.redirectTo && o.push(a.getRoutePath(u.redirectTo || "/"));
93
95
  return;
94
96
  }
95
- (i = t == null ? void 0 : t.onError) == null || i.call(t, a);
97
+ (i = t == null ? void 0 : t.onError) == null || i.call(t, u);
96
98
  }
97
99
  };
98
100
  }
99
- function A(t) {
100
- const { config: u, getRoutePath: o } = d(), r = f();
101
+ function l(t) {
102
+ const { config: a, getRoutePath: o } = h(), r = m(), g = f();
101
103
  return {
102
- mutate: async (a) => {
103
- var n;
104
- const e = await ((n = u.authProvider) == null ? void 0 : n.onError(a));
105
- t == null || t(e), e != null && e.logout && r.push(o(e.redirectTo || "/login"));
104
+ mutate: async (e) => {
105
+ var c;
106
+ const n = await ((c = a.authProvider) == null ? void 0 : c.onError(e));
107
+ t == null || t(n), n != null && n.logout && (g.logout(), await r.replace(o(n.redirectTo || "/login")), setTimeout(() => {
108
+ window.location.reload();
109
+ }, 100));
106
110
  }
107
111
  };
108
112
  }
113
+ function A(t) {
114
+ return f(t).getUser();
115
+ }
109
116
  function x(t) {
110
- return h(t).getUser();
117
+ return f(t).isLogin();
111
118
  }
112
119
  function F(t) {
113
- return h(t).isLogin();
114
- }
115
- function G(t) {
116
- const u = d(t), r = h(t).getUser();
117
- return (a, e) => {
120
+ const a = h(t), r = f(t).getUser();
121
+ return (u, e) => {
118
122
  var n;
119
- return (n = u.config.authProvider) != null && n.can ? u.config.authProvider.can(a, e, u, r) : !0;
123
+ return (n = a.config.authProvider) != null && n.can ? a.config.authProvider.can(u, e, a, r) : !0;
120
124
  };
121
125
  }
122
126
  export {
123
- G as useCan,
124
- T as useCheck,
125
- A as useError,
127
+ F as useCan,
128
+ R as useCheck,
129
+ l as useError,
126
130
  L as useForgotPassword,
127
- x as useGetAuth,
128
- F as useIsLogin,
129
- s as useLogin,
130
- R as useLogout,
131
+ A as useGetAuth,
132
+ x as useIsLogin,
133
+ v as useLogin,
134
+ E as useLogout,
131
135
  y as useRegister,
132
136
  U as useUpdatePassword
133
137
  };
@@ -2,37 +2,37 @@ import { useFileDialog as Q } from "@vueuse/core";
2
2
  import { uniqueId as R } from "lodash-es";
3
3
  import { ref as g, computed as v, watch as V } from "vue";
4
4
  import { createLocalUploadDriver as W } from "./upload/local.js";
5
- function ne(a) {
6
- a = a || {};
7
- const w = g(!1), i = g([]), d = g(-1), f = g(/* @__PURE__ */ new Map()), $ = a.driver || W(), I = v(() => {
8
- const { onProgress: e, onDataCallback: n, onCancel: l, onComplete: t, maxFileSize: c, maxFileCount: r, accept: o, multiple: s, autoUpload: u, options: A, onSuccess: P, onError: b, method: Y, driver: Z, ...J } = a;
5
+ function ne(l) {
6
+ l = l || {};
7
+ const w = g(!1), i = g([]), d = g(-1), f = g(/* @__PURE__ */ new Map()), $ = l.driver || W(), I = v(() => {
8
+ const { onProgress: e, onDataCallback: a, onCancel: n, onComplete: t, maxFileSize: c, maxFileCount: r, accept: o, multiple: s, autoUpload: u, options: A, onSuccess: P, onError: b, method: Y, driver: Z, params: _, ...J } = l;
9
9
  return J;
10
- }), k = v(() => a.method || "POST"), T = v(() => {
11
- const e = i.value.length, n = i.value.reduce((r, o) => r + (o.filesize || 0), 0);
12
- let l = 0, t = 0;
10
+ }), k = v(() => l.method || "POST"), T = v(() => {
11
+ const e = i.value.length, a = i.value.reduce((r, o) => r + (o.filesize || 0), 0);
12
+ let n = 0, t = 0;
13
13
  return i.value.forEach((r, o) => {
14
14
  var s;
15
- o < d.value ? l += r.filesize || 0 : o === d.value && (l += ((s = r.progress) == null ? void 0 : s.loaded) || 0);
16
- }), n > 0 && (t = Math.round(l / n * 100)), {
15
+ o < d.value ? n += r.filesize || 0 : o === d.value && (n += ((s = r.progress) == null ? void 0 : s.loaded) || 0);
16
+ }), a > 0 && (t = Math.round(n / a * 100)), {
17
17
  index: d.value >= 0 ? d.value + 1 : 0,
18
18
  totalFiles: e,
19
19
  currentFile: i.value[d.value],
20
20
  totalPercent: t,
21
- totalLoaded: l,
22
- totalSize: n
21
+ totalLoaded: n,
22
+ totalSize: a
23
23
  };
24
24
  }), F = (e) => {
25
25
  if (e === 0)
26
26
  return "0 Bytes";
27
- const n = 1024, l = ["Bytes", "KB", "MB", "GB"], t = Math.floor(Math.log(e) / Math.log(n));
28
- return `${Number.parseFloat((e / n ** t).toFixed(2))} ${l[t]}`;
27
+ const a = 1024, n = ["Bytes", "KB", "MB", "GB"], t = Math.floor(Math.log(e) / Math.log(a));
28
+ return `${Number.parseFloat((e / a ** t).toFixed(2))} ${n[t]}`;
29
29
  }, h = (e) => {
30
30
  if (e === 0)
31
31
  return "0 B/s";
32
- const n = 1024, l = ["B/s", "KB/s", "MB/s", "GB/s"], t = Math.floor(Math.log(e) / Math.log(n));
33
- return `${Number.parseFloat((e / n ** t).toFixed(2))} ${l[t]}`;
34
- }, z = () => R("upload-"), D = async (e, n, l) => {
35
- switch (n) {
32
+ const a = 1024, n = ["B/s", "KB/s", "MB/s", "GB/s"], t = Math.floor(Math.log(e) / Math.log(a));
33
+ return `${Number.parseFloat((e / a ** t).toFixed(2))} ${n[t]}`;
34
+ }, z = () => R("upload-"), D = async (e, a, n) => {
35
+ switch (a) {
36
36
  case "file": {
37
37
  if (!(e instanceof File))
38
38
  throw new TypeError('Payload must be a File when type is "file"');
@@ -59,15 +59,15 @@ function ne(a) {
59
59
  return new File([t], "array-buffer-file", { type: "application/octet-stream" });
60
60
  }
61
61
  default:
62
- throw new Error(`Unsupported upload type: ${n}`);
62
+ throw new Error(`Unsupported upload type: ${a}`);
63
63
  }
64
64
  }, C = (e) => {
65
- if (a.maxFileSize && e.size > a.maxFileSize)
66
- throw new Error(`File size cannot exceed ${F(a.maxFileSize)}`);
67
- if (a.maxFileCount && i.value.length >= a.maxFileCount)
68
- throw new Error(`File count cannot exceed ${a.maxFileCount}`);
69
- }, G = async (e, n, l) => {
70
- const t = await D(e, n);
65
+ if (l.maxFileSize && e.size > l.maxFileSize)
66
+ throw new Error(`File size cannot exceed ${F(l.maxFileSize)}`);
67
+ if (l.maxFileCount && i.value.length >= l.maxFileCount)
68
+ throw new Error(`File count cannot exceed ${l.maxFileCount}`);
69
+ }, G = async (e, a, n) => {
70
+ const t = await D(e, a);
71
71
  C(t);
72
72
  const c = {
73
73
  id: z(),
@@ -88,40 +88,41 @@ function ne(a) {
88
88
  }
89
89
  };
90
90
  return i.value.push(c), c;
91
- }, m = (e, n) => {
92
- const l = i.value.findIndex((t) => t.id === e);
93
- l !== -1 && (i.value[l] = { ...i.value[l], ...n });
91
+ }, m = (e, a) => {
92
+ const n = i.value.findIndex((t) => t.id === e);
93
+ n !== -1 && (i.value[n] = { ...i.value[n], ...a });
94
94
  }, E = () => {
95
- var n;
96
- i.value.every((l) => l.status !== "uploading") && ((n = a.onComplete) == null || n.call(a, i.value));
95
+ var a;
96
+ i.value.every((n) => n.status !== "uploading") && ((a = l.onComplete) == null || a.call(l, i.value));
97
97
  }, y = (e) => {
98
- var l;
99
- const n = i.value.find((t) => t.id === e);
100
- if (!n || n.status !== "pending" && n.status !== "uploading")
98
+ var n;
99
+ const a = i.value.find((t) => t.id === e);
100
+ if (!a || a.status !== "pending" && a.status !== "uploading")
101
101
  return !1;
102
- if (n.status === "uploading") {
102
+ if (a.status === "uploading") {
103
103
  const t = f.value.get(e);
104
104
  t && (t.abort(), f.value.delete(e));
105
105
  }
106
106
  return m(e, {
107
107
  status: "cancelled"
108
- }), (l = a.onCancel) == null || l.call(a, e), E(), !0;
108
+ }), (n = l.onCancel) == null || n.call(l, e), E(), !0;
109
109
  }, K = (e) => {
110
- e ? e.forEach((n) => y(n)) : i.value.forEach((n) => y(n.id));
110
+ e ? e.forEach((a) => y(a)) : i.value.forEach((a) => y(a.id));
111
111
  }, L = async (e) => {
112
112
  if (!e.file)
113
113
  throw new Error("File not found");
114
114
  C(e.file);
115
- const n = new AbortController();
116
- f.value.set(e.id, n);
117
- const l = Date.now();
115
+ const a = new AbortController();
116
+ f.value.set(e.id, a);
117
+ const n = Date.now();
118
118
  return m(e.id, { status: "uploading" }), $.upload(e.file, {
119
119
  ...I.value,
120
120
  method: k.value,
121
- signal: n.signal,
121
+ signal: a.signal,
122
+ params: l.params,
122
123
  onUploadProgress: (t) => {
123
124
  var b;
124
- const o = (Date.now() - l) / 1e3, s = o > 0 ? t.loaded / o : 0, u = (t.total || 0) - t.loaded, A = s > 0 ? u / s : 0, P = {
125
+ const o = (Date.now() - n) / 1e3, s = o > 0 ? t.loaded / o : 0, u = (t.total || 0) - t.loaded, A = s > 0 ? u / s : 0, P = {
125
126
  loaded: t.loaded,
126
127
  total: t.total,
127
128
  percent: t.percent || 0,
@@ -133,13 +134,13 @@ function ne(a) {
133
134
  m(e.id, {
134
135
  status: "uploading",
135
136
  progress: P
136
- }), (b = a.onProgress) == null || b.call(a, T.value);
137
+ }), (b = l.onProgress) == null || b.call(l, T.value);
137
138
  }
138
139
  }).then((t) => {
139
140
  var s, u;
140
141
  if (e.status === "cancelled")
141
142
  throw new Error("Upload cancelled");
142
- const c = ((s = a.onDataCallback) == null ? void 0 : s.call(a, t, e)) || t.data, r = Math.round((Date.now() - l) / 1e3), o = {
143
+ const c = ((s = l.onDataCallback) == null ? void 0 : s.call(l, t, e)) || t.data, r = Math.round((Date.now() - n) / 1e3), o = {
143
144
  ...e,
144
145
  status: "success",
145
146
  data: t,
@@ -154,7 +155,7 @@ function ne(a) {
154
155
  remainingTime: 0
155
156
  }
156
157
  };
157
- return m(e.id, o), f.value.delete(e.id), (u = a.onSuccess) == null || u.call(a, t), o;
158
+ return m(e.id, o), f.value.delete(e.id), (u = l.onSuccess) == null || u.call(l, t), o;
158
159
  }).catch((t) => {
159
160
  throw t.message === "canceled" || e.status === "cancelled" ? new Error("Upload cancelled") : (m(e.id, {
160
161
  status: "error",
@@ -164,25 +165,25 @@ function ne(a) {
164
165
  E();
165
166
  });
166
167
  }, B = async () => {
167
- var n;
168
- const e = i.value.filter((l) => l.status === "pending");
168
+ var a;
169
+ const e = i.value.filter((n) => n.status === "pending");
169
170
  if (e.length === 0)
170
171
  return [];
171
172
  w.value = !0;
172
173
  try {
173
- const l = [];
174
+ const n = [];
174
175
  for (let t = 0; t < e.length; t++) {
175
176
  const c = e[t], r = i.value.findIndex((s) => s.id === c.id);
176
177
  d.value = r;
177
178
  const o = await L(c);
178
- l.push(o);
179
+ n.push(o);
179
180
  }
180
- return l;
181
- } catch (l) {
182
- throw (n = a.onError) == null || n.call(a, {
183
- status: (l == null ? void 0 : l.status) || 500,
184
- message: (l == null ? void 0 : l.message) || "upload failed"
185
- }), l;
181
+ return n;
182
+ } catch (n) {
183
+ throw (a = l.onError) == null || a.call(l, {
184
+ status: (n == null ? void 0 : n.status) || 500,
185
+ message: (n == null ? void 0 : n.message) || "upload failed"
186
+ }), n;
186
187
  } finally {
187
188
  w.value = !1, d.value = -1;
188
189
  }
@@ -190,27 +191,27 @@ function ne(a) {
190
191
  i.value.forEach((e) => {
191
192
  y(e.id);
192
193
  }), f.value.clear(), i.value = [], d.value = -1;
193
- }, M = async (e, n = "file") => {
194
- var l;
194
+ }, M = async (e, a = "file") => {
195
+ var n;
195
196
  try {
196
- if (!a.multiple && e.length > 1)
197
+ if (!l.multiple && e.length > 1)
197
198
  throw new Error("Single file mode: only one file can be selected");
198
- if (!a.multiple && i.value.length > 0 && x(), a.maxFileCount && i.value.length + e.length > a.maxFileCount)
199
- throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${a.maxFileCount}`);
199
+ if (!l.multiple && i.value.length > 0 && x(), l.maxFileCount && i.value.length + e.length > l.maxFileCount)
200
+ throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);
200
201
  for (const t of e)
201
- await G(t, n);
202
+ await G(t, a);
202
203
  } catch (t) {
203
- throw (l = a.onError) == null || l.call(a, {
204
+ throw (n = l.onError) == null || n.call(l, {
204
205
  status: (t == null ? void 0 : t.status) || 400,
205
206
  message: (t == null ? void 0 : t.message) || "Failed to add files"
206
207
  }), t;
207
208
  }
208
- a.autoUpload && B().catch((t) => {
209
+ l.autoUpload && B().catch((t) => {
209
210
  console.warn("Auto upload failed:", t);
210
211
  });
211
212
  }, U = (e) => {
212
- const n = i.value.find((t) => t.id === e);
213
- if (n && n.status === "uploading") {
213
+ const a = i.value.find((t) => t.id === e);
214
+ if (a && a.status === "uploading") {
214
215
  m(e, {
215
216
  status: "cancelled"
216
217
  });
@@ -219,13 +220,13 @@ function ne(a) {
219
220
  return;
220
221
  t.abort(), f.value.delete(e);
221
222
  }
222
- const l = i.value.findIndex((t) => t.id === e);
223
- l !== -1 && i.value.splice(l, 1);
223
+ const n = i.value.findIndex((t) => t.id === e);
224
+ n !== -1 && i.value.splice(n, 1);
224
225
  }, N = (e) => {
225
- e ? e.forEach((n) => U(n)) : i.value.forEach((n) => U(n.id));
226
+ e ? e.forEach((a) => U(a)) : i.value.forEach((a) => U(a.id));
226
227
  }, { files: q, open: O, reset: S } = Q({
227
- accept: a.accept,
228
- multiple: a.multiple || !1
228
+ accept: l.accept,
229
+ multiple: l.multiple || !1
229
230
  }), j = (e) => ({
230
231
  id: z(),
231
232
  ...e,
@@ -243,9 +244,9 @@ function ne(a) {
243
244
  });
244
245
  V(q, async (e) => {
245
246
  if (e && e.length > 0) {
246
- const n = Array.from(e);
247
- S(), await M(n, "file").catch((l) => {
248
- console.warn("Failed to add selected files:", l);
247
+ const a = Array.from(e);
248
+ S(), await M(a, "file").catch((n) => {
249
+ console.warn("Failed to add selected files:", n);
249
250
  });
250
251
  }
251
252
  });
@@ -267,9 +268,9 @@ function ne(a) {
267
268
  removeFiles: N,
268
269
  addFiles: M,
269
270
  addDataFiles: (e) => {
270
- !a.multiple && i.value.length > 0 && x();
271
- const n = e.map((l) => j(l));
272
- i.value.push(...n);
271
+ !l.multiple && i.value.length > 0 && x();
272
+ const a = e.map((n) => j(n));
273
+ i.value.push(...a);
273
274
  },
274
275
  cancelFiles: K
275
276
  };
@@ -1,38 +1,44 @@
1
1
  import g from "axios";
2
- function m(e) {
2
+ function m(t) {
3
3
  return {
4
4
  login: async (n, c) => {
5
5
  var d;
6
- return await g.post(c.getApiUrl(((d = e == null ? void 0 : e.apiPath) == null ? void 0 : d.login) || "/login", e == null ? void 0 : e.dataProviderName), n).then((t) => {
6
+ return await g.post(c.getApiUrl(((d = t == null ? void 0 : t.apiPath) == null ? void 0 : d.login) || "/login", t == null ? void 0 : t.dataProviderName), n).then((e) => {
7
7
  var i, a, s;
8
8
  return {
9
9
  success: !0,
10
- message: (i = t == null ? void 0 : t.data) == null ? void 0 : i.message,
11
- redirectTo: ((a = e == null ? void 0 : e.routePath) == null ? void 0 : a.index) || "/",
12
- data: (s = t == null ? void 0 : t.data) == null ? void 0 : s.data
10
+ message: (i = e == null ? void 0 : e.data) == null ? void 0 : i.message,
11
+ redirectTo: ((a = t == null ? void 0 : t.routePath) == null ? void 0 : a.index) || "/",
12
+ data: (s = e == null ? void 0 : e.data) == null ? void 0 : s.data
13
13
  };
14
- }).catch((t) => {
14
+ }).catch((e) => {
15
15
  var i, a;
16
16
  return {
17
17
  success: !1,
18
- message: ((a = (i = t == null ? void 0 : t.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (t == null ? void 0 : t.message)
18
+ message: ((a = (i = e == null ? void 0 : e.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (e == null ? void 0 : e.message)
19
19
  };
20
20
  });
21
21
  },
22
- check: async (n, c) => {
23
- var d;
24
- return await g.get((c == null ? void 0 : c.getApiUrl(((d = e == null ? void 0 : e.apiPath) == null ? void 0 : d.check) || "/check", e == null ? void 0 : e.dataProviderName)) || "").then((t) => {
25
- var i, a;
22
+ check: async (n, c, d) => {
23
+ var e;
24
+ return await g.get((c == null ? void 0 : c.getApiUrl(((e = t == null ? void 0 : t.apiPath) == null ? void 0 : e.check) || "/check", t == null ? void 0 : t.dataProviderName)) || "", {
25
+ headers: {
26
+ Authorization: (d == null ? void 0 : d.token) || ""
27
+ }
28
+ }).then((i) => {
29
+ var a, s;
26
30
  return {
27
31
  success: !0,
28
- message: (i = t == null ? void 0 : t.data) == null ? void 0 : i.message,
29
- data: (a = t == null ? void 0 : t.data) == null ? void 0 : a.data
32
+ logout: !1,
33
+ message: (a = i == null ? void 0 : i.data) == null ? void 0 : a.message,
34
+ data: (s = i == null ? void 0 : i.data) == null ? void 0 : s.data
30
35
  };
31
- }).catch((t) => {
32
- var i, a;
36
+ }).catch((i) => {
37
+ var a, s;
33
38
  return {
34
39
  success: !1,
35
- message: ((a = (i = t == null ? void 0 : t.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (t == null ? void 0 : t.message)
40
+ logout: !0,
41
+ message: ((s = (a = i == null ? void 0 : i.response) == null ? void 0 : a.data) == null ? void 0 : s.message) || (i == null ? void 0 : i.message)
36
42
  };
37
43
  });
38
44
  },
@@ -40,7 +46,7 @@ function m(e) {
40
46
  var c;
41
47
  return (n == null ? void 0 : n.status) === 401 ? {
42
48
  logout: !0,
43
- redirectTo: ((c = e == null ? void 0 : e.routePath) == null ? void 0 : c.login) || "/login",
49
+ redirectTo: ((c = t == null ? void 0 : t.routePath) == null ? void 0 : c.login) || "/login",
44
50
  error: n
45
51
  } : {
46
52
  logout: !1,
@@ -51,64 +57,64 @@ function m(e) {
51
57
  var n;
52
58
  return {
53
59
  success: !0,
54
- redirectTo: ((n = e == null ? void 0 : e.routePath) == null ? void 0 : n.login) || "/login"
60
+ redirectTo: ((n = t == null ? void 0 : t.routePath) == null ? void 0 : n.login) || "/login"
55
61
  };
56
62
  },
57
63
  register: async (n, c) => {
58
64
  var d;
59
- return await g.post((c == null ? void 0 : c.getApiUrl(((d = e == null ? void 0 : e.apiPath) == null ? void 0 : d.register) || "/register", e == null ? void 0 : e.dataProviderName)) || "", n).then((t) => {
65
+ return await g.post((c == null ? void 0 : c.getApiUrl(((d = t == null ? void 0 : t.apiPath) == null ? void 0 : d.register) || "/register", t == null ? void 0 : t.dataProviderName)) || "", n).then((e) => {
60
66
  var i, a, s;
61
67
  return {
62
68
  success: !0,
63
- message: (i = t == null ? void 0 : t.data) == null ? void 0 : i.message,
64
- redirectTo: ((a = e == null ? void 0 : e.routePath) == null ? void 0 : a.index) || "/",
65
- data: (s = t == null ? void 0 : t.data) == null ? void 0 : s.data
69
+ message: (i = e == null ? void 0 : e.data) == null ? void 0 : i.message,
70
+ redirectTo: ((a = t == null ? void 0 : t.routePath) == null ? void 0 : a.index) || "/",
71
+ data: (s = e == null ? void 0 : e.data) == null ? void 0 : s.data
66
72
  };
67
- }).catch((t) => {
73
+ }).catch((e) => {
68
74
  var i, a;
69
75
  return {
70
76
  success: !1,
71
- message: ((a = (i = t == null ? void 0 : t.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (t == null ? void 0 : t.message)
77
+ message: ((a = (i = e == null ? void 0 : e.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (e == null ? void 0 : e.message)
72
78
  };
73
79
  });
74
80
  },
75
81
  forgotPassword: async (n, c) => {
76
82
  var d;
77
- return await g.post((c == null ? void 0 : c.getApiUrl(((d = e == null ? void 0 : e.apiPath) == null ? void 0 : d.forgotPassword) || "/forgot-password", e == null ? void 0 : e.dataProviderName)) || "", n).then((t) => {
83
+ return await g.post((c == null ? void 0 : c.getApiUrl(((d = t == null ? void 0 : t.apiPath) == null ? void 0 : d.forgotPassword) || "/forgot-password", t == null ? void 0 : t.dataProviderName)) || "", n).then((e) => {
78
84
  var i, a;
79
85
  return {
80
86
  success: !0,
81
- message: (i = t == null ? void 0 : t.data) == null ? void 0 : i.message,
82
- redirectTo: ((a = e == null ? void 0 : e.routePath) == null ? void 0 : a.login) || "/login"
87
+ message: (i = e == null ? void 0 : e.data) == null ? void 0 : i.message,
88
+ redirectTo: ((a = t == null ? void 0 : t.routePath) == null ? void 0 : a.login) || "/login"
83
89
  };
84
- }).catch((t) => {
90
+ }).catch((e) => {
85
91
  var i, a;
86
92
  return {
87
93
  success: !1,
88
- message: ((a = (i = t == null ? void 0 : t.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (t == null ? void 0 : t.message)
94
+ message: ((a = (i = e == null ? void 0 : e.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (e == null ? void 0 : e.message)
89
95
  };
90
96
  });
91
97
  },
92
98
  updatePassword: async (n, c) => {
93
99
  var d;
94
- return await g.post((c == null ? void 0 : c.getApiUrl(((d = e == null ? void 0 : e.apiPath) == null ? void 0 : d.updatePassword) || "/update-password", e == null ? void 0 : e.dataProviderName)) || "", n).then((t) => {
100
+ return await g.post((c == null ? void 0 : c.getApiUrl(((d = t == null ? void 0 : t.apiPath) == null ? void 0 : d.updatePassword) || "/update-password", t == null ? void 0 : t.dataProviderName)) || "", n).then((e) => {
95
101
  var i, a;
96
102
  return {
97
103
  success: !0,
98
- message: (i = t == null ? void 0 : t.data) == null ? void 0 : i.message,
99
- redirectTo: ((a = e == null ? void 0 : e.routePath) == null ? void 0 : a.login) || "/login"
104
+ message: (i = e == null ? void 0 : e.data) == null ? void 0 : i.message,
105
+ redirectTo: ((a = t == null ? void 0 : t.routePath) == null ? void 0 : a.login) || "/login"
100
106
  };
101
- }).catch((t) => {
107
+ }).catch((e) => {
102
108
  var i, a;
103
109
  return {
104
110
  success: !1,
105
- message: ((a = (i = t == null ? void 0 : t.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (t == null ? void 0 : t.message)
111
+ message: ((a = (i = e == null ? void 0 : e.response) == null ? void 0 : i.data) == null ? void 0 : a.message) || (e == null ? void 0 : e.message)
106
112
  };
107
113
  });
108
114
  },
109
- can: (n, c, d, t) => {
115
+ can: (n, c, d, e) => {
110
116
  var i, a;
111
- return !(t != null && t.permission) || Array.isArray(t == null ? void 0 : t.permission) && ((i = t == null ? void 0 : t.permission) == null ? void 0 : i.length) === 0 || typeof (t == null ? void 0 : t.permission) == "object" && Object.keys(t == null ? void 0 : t.permission).length === 0 ? !0 : !(Array.isArray(t == null ? void 0 : t.permission) && !((a = t == null ? void 0 : t.permission) != null && a.includes(n)) || typeof (t == null ? void 0 : t.permission) == "object" && (t == null ? void 0 : t.permission[n]) === !1);
117
+ return !(e != null && e.permission) || Array.isArray(e == null ? void 0 : e.permission) && ((i = e == null ? void 0 : e.permission) == null ? void 0 : i.length) === 0 || typeof (e == null ? void 0 : e.permission) == "object" && Object.keys(e == null ? void 0 : e.permission).length === 0 ? !0 : !(Array.isArray(e == null ? void 0 : e.permission) && !((a = e == null ? void 0 : e.permission) != null && a.includes(n)) || typeof (e == null ? void 0 : e.permission) == "object" && (e == null ? void 0 : e.permission[n]) === !1);
112
118
  }
113
119
  };
114
120
  }
@@ -1,6 +1,6 @@
1
1
  import type { IDataProviderCustomOptions, IDataProviderResponse } from '../../types';
2
2
  export interface IUploadDriver {
3
- upload(file: File, options: IUploadDriverOptions): Promise<IDataProviderResponse>;
3
+ upload: (file: File, options: IUploadDriverOptions) => Promise<IDataProviderResponse>;
4
4
  }
5
5
  export interface IUploadDriverOptions extends Omit<IDataProviderCustomOptions, 'onUploadProgress' | 'onDownloadProgress'> {
6
6
  method?: 'POST' | 'PUT';
@@ -8,6 +8,7 @@ export interface IUseUploadProps extends Omit<IDataProviderCustomOptions, 'onUpl
8
8
  accept?: string;
9
9
  multiple?: boolean;
10
10
  autoUpload?: boolean;
11
+ params?: Record<string, string>;
11
12
  driver?: IUploadDriver;
12
13
  options?: UseMutationOptions<IDataProviderResponse, IDataProviderError, IDataProviderCustomOptions>;
13
14
  onSuccess?: (data: IDataProviderResponse) => void;
@@ -7,11 +7,11 @@ import type { IDataProviderError } from './data';
7
7
  */
8
8
  export interface IAuthProvider {
9
9
  login: (params: any, manage: IManageHook) => Promise<IAuthLoginResponse>;
10
- check: (params?: any, manage?: IManageHook) => Promise<IAuthCheckResponse>;
11
10
  logout: (params?: any, manage?: IManageHook) => Promise<IAuthLogoutResponse>;
12
11
  register?: (params: any, manage?: IManageHook) => Promise<IAuthLoginResponse>;
13
12
  forgotPassword?: (params: any, manage?: IManageHook) => Promise<IAuthActionResponse>;
14
13
  updatePassword?: (params: any, manage?: IManageHook) => Promise<IAuthActionResponse>;
14
+ check?: (params?: any, manage?: IManageHook, auth?: IUserState) => Promise<IAuthCheckResponse>;
15
15
  can?: (name: string, params?: any, manage?: IManageHook, auth?: IUserState) => boolean;
16
16
  onError: (error?: IDataProviderError) => Promise<IAuthErrorResponse>;
17
17
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@duxweb/dvha-core",
3
3
  "type": "module",
4
- "version": "1.0.20",
4
+ "version": "1.0.21",
5
5
  "author": "DuxWeb",
6
6
  "license": "MIT",
7
7
  "repository": {