@duxweb/dvha-core 1.0.40 → 1.0.42
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.
- package/dist/cjs/components/loader/remote/loader.cjs +1 -1
- package/dist/cjs/hooks/auth.cjs +1 -1
- package/dist/cjs/preset/authProvider.cjs +1 -1
- package/dist/cjs/stores/route.cjs +1 -1
- package/dist/esm/components/loader/remote/loader.js +81 -76
- package/dist/esm/hooks/auth.js +65 -62
- package/dist/esm/preset/authProvider.js +15 -15
- package/dist/esm/stores/route.js +18 -15
- package/dist/types/stores/route.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("vue"),$=require("@tanstack/vue-query"),C=require("@vueuse/core"),W=require("axios"),_=require("crypto-js"),E=require("dayjs"),T=require("lodash-es"),k=require("mathjs"),q=require("mime"),L=require("mitt"),D=require("pinia"),J=require("vue3-sfc-loader"),N=require("vue-router"),V=require("../../../hooks/auth.cjs"),B=require("../../../hooks/data.cjs");require("json-2-csv");require("@vee-validate/rules");require("vee-validate");const F=require("../../../hooks/i18n.cjs"),Q=require("../../../hooks/json.cjs");require("../../../hooks/json/index.cjs");const U=require("../../../hooks/manage.cjs");require("../../../utils/bus.cjs");require("@overlastic/vue");require("clsx");require("colorizr");const z=require("../../../index.cjs");function u(n){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const o in n)if(o!=="default"){const h=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(a,o,h.get?h:{enumerable:!0,get:()=>n[o]})}}return a.default=n,Object.freeze(a)}const A=u(v),H=u($),I=u(C),G=u(T),K=u(k),X=u(D),Y=u(N),y=new Map;function Z(n){return _.MD5(n).toString().substring(0,10)}function ee(n){const a=B.useClient(),{mutate:o}=V.useError(),{mergeLocale:h}=F.useI18n(),{config:d}=U.useManage(),j={moduleCache:{vue:A,"@duxweb/dvha-core":z,"@vueuse/core":I,"@tanstack/vue-query":H,axios:W,"crypto-js":_,mime:q,math:K,mitt:L,"lodash-es":G,pinia:X,dayjs:E,"vue-router":Y,...d?.remote?.packages,"static!":function(e,t,r){const s=q.getType(r);if(s?.startsWith("image"))return`data:${s};charset=utf-8;base64,${btoa(e)}`;if(r===".json")return JSON.parse(e);throw new Error(`${r} unable to parse`)}},async handleModule(e,t){if(e!==".vue"){if(e===".json"){const r=await t(),{render:s}=Q.useJsonSchema({data:r?.nodes||{},context:r?.data||{}});return()=>v.createVNode(s,null,null)}if(e!==".mjs")return t()}},customBlockHandler(e){if(e.type==="i18n"){const t=JSON.parse(e.content);for(const r in t)h(r,t[r])}},getFile:async e=>{e=g(e,".vue"),e=g(e,".json");const t=await a.request({path:typeof d?.remote?.apiRoutePath=="function"?d?.remote?.apiRoutePath(e):d?.remote?.apiRoutePath||"static",payload:{path:e},method:d?.remote?.apiMethod||"POST"}).then(s=>s?.data).catch(s=>{o(s)});if(!t)return;let r=t?.type||".vue";return(t?.type?.endsWith("js")||t?.type?.endsWith("ts")||t?.type?.endsWith("jsx")||t?.type?.endsWith("tsx"))&&(r=".mjs"),{content:t?.content,type:r}},getResource({refPath:e,relPath:t},r){const{moduleCache:s,pathResolve:b,getFile:S}=r,[w,...p]=t.match(/([^!]+!)|[^!]+$/g).reverse(),P=(c,m,l,f)=>p.reduce((O,M)=>s[M](O,m,l,f),c),i=b({refPath:e,relPath:w},r),x=p.join("")+i,R=c=>c.startsWith("@")?!0:!c.includes("/")&&!c.startsWith(".");return{id:x,path:i,async getContent(){if(R(i))throw new Error(`Package ${i} not imported`);const c=await S(i),{content:m,type:l}=c||{};return{getContentData:async f=>P(m,i,l,r),type:l}}}},addStyle(e){const t=Z(e);if(y.has(t))return;y.set(t,!0);const r=document.createElement("style");r.textContent=e,r.setAttribute("data-hash",t),document.head.appendChild(r)}};return()=>J.loadModule(`${n}`,{...j})}function g(n,a){const o=new RegExp(`${a}$`);return n.replace(o,"")}exports.sfcLoader=ee;
|
package/dist/cjs/hooks/auth.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("vue"),g=require("vue-router"),c=require("../stores/auth.cjs");require("pinia");require("lodash-es");const h=require("../stores/route.cjs"),i=require("./manage.cjs");function l(t){const e=i.useManage(),u=c.useAuthStore(),s=h.useRouteStore(),n=g.useRouter(),r=S.ref(!1);return{mutate:async d=>{r.value=!0;const a=await e.config.authProvider?.login(d,e);if(r.value=!1,a?.success){if(!a?.data)throw new Error("Login response data is undefined");s.resetRouteInit(),t?.onSuccess?.(a),u.login(a.data),n.push(e.getRoutePath(a.redirectTo||"/"));return}t?.onError?.(a)},isLoading:r}}function m(t){const e=i.useManage(),u=c.useAuthStore(),s=g.useRouter();return{mutate:async r=>{const o=await e.config.authProvider?.logout(r,e);if(o?.success){t?.onSuccess?.(o),u.logout(),await s.replace(e.getRoutePath(o.redirectTo||"/login")),setTimeout(()=>{window.location.reload()},100);return}t?.onError?.(o)}}}function w(t){const e=i.useManage(),u=c.useAuthStore(),{mutate:s}=f();return{mutate:async r=>{const o=await e.config.authProvider?.check?.(r,e,u.getUser());if(o?.success){if(t?.onSuccess?.(o),!o?.data)throw new Error("Check response data is undefined");u.update(o.data);return}t?.onError?.(o),o?.logout&&s({status:401,message:o.message||"Unauthorized"})}}}function P(t){const e=i.useManage(),u=c.useAuthStore(),s=g.useRouter();return{mutate:async r=>{const o=await e.config.authProvider?.register?.(r,e);if(o?.success){if(t?.onSuccess?.(o),!o?.data)throw new Error("Register response data is undefined");u.login(o.data),s.push(e.getRoutePath(o.redirectTo||"/"));return}t?.onError?.(o)}}}function R(t){const e=i.useManage(),u=g.useRouter();return{mutate:async n=>{const r=await e.config.authProvider?.forgotPassword?.(n,e);if(r?.success){t?.onSuccess?.(r),r.redirectTo&&u.push(e.getRoutePath(r.redirectTo||"/"));return}t?.onError?.(r)}}}function v(t){const e=i.useManage(),u=g.useRouter();return{mutate:async n=>{const r=await e.config.authProvider?.updatePassword?.(n,e);if(r?.success){t?.onSuccess?.(r),r.redirectTo&&u.push(e.getRoutePath(r.redirectTo||"/"));return}t?.onError?.(r)}}}function f(t){const{config:e,getRoutePath:u}=i.useManage(),s=g.useRouter(),n=c.useAuthStore(e.name),r=h.useRouteStore(e.name);return{mutate:async d=>{const a=await e.authProvider?.onError(d);t?.(a),a?.logout&&(await n.logout(),await r.resetRouteInit(),await s.replace(u(a.redirectTo||"/login")),setTimeout(()=>{},100))}}}function E(t){return c.useAuthStore(t).getUser()}function T(t){return c.useAuthStore(t).isLogin()}function A(t){const e=i.useManage(t),s=c.useAuthStore(t).getUser();return(r,o)=>e.config.authProvider?.can?e.config.authProvider.can(r,o,e,s):!0}exports.useCan=A;exports.useCheck=w;exports.useError=f;exports.useForgotPassword=R;exports.useGetAuth=E;exports.useIsLogin=T;exports.useLogin=l;exports.useLogout=m;exports.useRegister=P;exports.useUpdatePassword=v;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("axios");function n(s){return{login:async(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("axios");function n(s){return{login:async(t,r)=>await i.post(r.getApiUrl(s?.apiPath?.login||"/login",s?.dataProviderName),t).then(e=>({success:!0,message:e?.data?.message,redirectTo:s?.routePath?.index||"/",data:e?.data?.data})).catch(e=>({success:!1,message:e?.response?.data?.message||e?.message})),check:async(t,r,e)=>await i.get(r?.getApiUrl(s?.apiPath?.check||"/check",s?.dataProviderName)||"",{headers:{Authorization:e?.token||""}}).then(a=>({success:!0,logout:!1,message:a?.data?.message,data:a?.data?.data})).catch(a=>({success:!1,logout:a.status===401,message:a?.response?.data?.message||a?.message})),onError:async t=>t?.status===401?{logout:!0,redirectTo:s?.routePath?.login||"/login",error:t}:{logout:!1,error:t},logout:async()=>({success:!0,redirectTo:s?.routePath?.login||"/login"}),register:async(t,r)=>await i.post(r?.getApiUrl(s?.apiPath?.register||"/register",s?.dataProviderName)||"",t).then(e=>({success:!0,message:e?.data?.message,redirectTo:s?.routePath?.index||"/",data:e?.data?.data})).catch(e=>({success:!1,message:e?.response?.data?.message||e?.message})),forgotPassword:async(t,r)=>await i.post(r?.getApiUrl(s?.apiPath?.forgotPassword||"/forgot-password",s?.dataProviderName)||"",t).then(e=>({success:!0,message:e?.data?.message,redirectTo:s?.routePath?.login||"/login"})).catch(e=>({success:!1,message:e?.response?.data?.message||e?.message})),updatePassword:async(t,r)=>await i.post(r?.getApiUrl(s?.apiPath?.updatePassword||"/update-password",s?.dataProviderName)||"",t).then(e=>({success:!0,message:e?.data?.message,redirectTo:s?.routePath?.login||"/login"})).catch(e=>({success:!1,message:e?.response?.data?.message||e?.message})),can:(t,r,e,a)=>!a?.permission||Array.isArray(a?.permission)&&a?.permission?.length===0||typeof a?.permission=="object"&&Object.keys(a?.permission).length===0?!0:!(Array.isArray(a?.permission)&&!a?.permission?.includes(t)||typeof a?.permission=="object"&&a?.permission[t]===!1)}}exports.simpleAuthProvider=n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("pinia"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("pinia"),a=require("vue");function I(r){const t=a.inject("dux.manage");if(r||(r=t?.value||""),!r)throw new Error("manage not found");return b(r)()}function b(r){return g.defineStore(`routes-${r}`,()=>{const t=a.ref([]),l=e=>t.value?.find(n=>n.path===e),f=e=>t.value?.find(n=>n.name===e),d=e=>{t.value?.push(e)},v=e=>{t.value=[...t.value,...e]},R=e=>{t.value=e},p=()=>t.value,h=()=>{t.value=[]},S=()=>{const e=t.value?.filter(o=>!o.parent&&!o.name?.includes("404")&&!o.name?.includes("403"))?.sort((o,u)=>(o.sort||0)-(u.sort||0)),n=o=>{if(o.path)return o;const u=t.value?.filter(s=>s.parent===o.name)?.sort((s,c)=>(s.sort||0)-(c.sort||0));for(const s of u||[]){const c=n(s);if(c)return c}};for(const o of e||[]){const u=n(o);if(u)return u}},i=a.ref(!1);return{routes:t,searchRoute:l,searchRouteName:f,appendRoute:d,appendRoutes:v,setRoutes:R,getRoutes:p,clearRoutes:h,getIndexRoute:S,getRouteInit:()=>{const e=i.value;return i.value=!0,e},resetRouteInit:()=>{i.value=!1}}})}exports.useRouteStore=I;
|
|
@@ -1,149 +1,154 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as E from "vue";
|
|
2
2
|
import { createVNode as M } from "vue";
|
|
3
3
|
import * as b from "@tanstack/vue-query";
|
|
4
|
-
import * as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
4
|
+
import * as k from "@vueuse/core";
|
|
5
|
+
import J from "axios";
|
|
6
|
+
import g from "crypto-js";
|
|
7
|
+
import T from "dayjs";
|
|
8
|
+
import * as L from "lodash-es";
|
|
9
|
+
import * as N from "mathjs";
|
|
10
10
|
import h from "mime";
|
|
11
|
-
import
|
|
12
|
-
import * as
|
|
13
|
-
import { loadModule as
|
|
14
|
-
import * as
|
|
15
|
-
import {
|
|
16
|
-
import { useClient as
|
|
11
|
+
import O from "mitt";
|
|
12
|
+
import * as _ from "pinia";
|
|
13
|
+
import { loadModule as q } from "vue3-sfc-loader";
|
|
14
|
+
import * as B from "vue-router";
|
|
15
|
+
import { useError as D } from "../../../hooks/auth.js";
|
|
16
|
+
import { useClient as F } from "../../../hooks/data.js";
|
|
17
17
|
import "json-2-csv";
|
|
18
18
|
import "@vee-validate/rules";
|
|
19
19
|
import "vee-validate";
|
|
20
|
-
import { useI18n as
|
|
21
|
-
import { useJsonSchema as
|
|
20
|
+
import { useI18n as V } from "../../../hooks/i18n.js";
|
|
21
|
+
import { useJsonSchema as A } from "../../../hooks/json.js";
|
|
22
22
|
import "../../../hooks/json/index.js";
|
|
23
|
+
import { useManage as H } from "../../../hooks/manage.js";
|
|
23
24
|
import "../../../utils/bus.js";
|
|
24
25
|
import "@overlastic/vue";
|
|
25
26
|
import "clsx";
|
|
26
27
|
import "colorizr";
|
|
27
|
-
import * as
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
return
|
|
28
|
+
import * as I from "../../../index.js";
|
|
29
|
+
const l = /* @__PURE__ */ new Map();
|
|
30
|
+
function Q(s) {
|
|
31
|
+
return g.MD5(s).toString().substring(0, 10);
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
-
const c =
|
|
34
|
-
|
|
35
|
-
} =
|
|
33
|
+
function ft(s) {
|
|
34
|
+
const c = F(), {
|
|
35
|
+
mutate: u
|
|
36
|
+
} = D(), {
|
|
37
|
+
mergeLocale: v
|
|
38
|
+
} = V(), {
|
|
36
39
|
config: i
|
|
37
|
-
} =
|
|
40
|
+
} = H(), j = {
|
|
38
41
|
moduleCache: {
|
|
39
|
-
vue:
|
|
40
|
-
"@duxweb/dvha-core":
|
|
41
|
-
"@vueuse/core":
|
|
42
|
+
vue: E,
|
|
43
|
+
"@duxweb/dvha-core": I,
|
|
44
|
+
"@vueuse/core": k,
|
|
42
45
|
"@tanstack/vue-query": b,
|
|
43
|
-
axios:
|
|
44
|
-
"crypto-js":
|
|
46
|
+
axios: J,
|
|
47
|
+
"crypto-js": g,
|
|
45
48
|
mime: h,
|
|
46
|
-
math:
|
|
47
|
-
mitt:
|
|
48
|
-
"lodash-es":
|
|
49
|
-
pinia:
|
|
50
|
-
dayjs:
|
|
51
|
-
"vue-router":
|
|
49
|
+
math: N,
|
|
50
|
+
mitt: O,
|
|
51
|
+
"lodash-es": L,
|
|
52
|
+
pinia: _,
|
|
53
|
+
dayjs: T,
|
|
54
|
+
"vue-router": B,
|
|
52
55
|
...i?.remote?.packages,
|
|
53
|
-
"static!": function(t,
|
|
54
|
-
const o = h.getType(
|
|
56
|
+
"static!": function(t, e, r) {
|
|
57
|
+
const o = h.getType(r);
|
|
55
58
|
if (o?.startsWith("image"))
|
|
56
59
|
return `data:${o};charset=utf-8;base64,${btoa(t)}`;
|
|
57
|
-
if (
|
|
60
|
+
if (r === ".json")
|
|
58
61
|
return JSON.parse(t);
|
|
59
|
-
throw new Error(`${
|
|
62
|
+
throw new Error(`${r} unable to parse`);
|
|
60
63
|
}
|
|
61
64
|
},
|
|
62
|
-
async handleModule(t,
|
|
65
|
+
async handleModule(t, e) {
|
|
63
66
|
if (t !== ".vue") {
|
|
64
67
|
if (t === ".json") {
|
|
65
|
-
const
|
|
68
|
+
const r = await e(), {
|
|
66
69
|
render: o
|
|
67
|
-
} =
|
|
68
|
-
data:
|
|
69
|
-
context:
|
|
70
|
+
} = A({
|
|
71
|
+
data: r?.nodes || {},
|
|
72
|
+
context: r?.data || {}
|
|
70
73
|
});
|
|
71
74
|
return () => M(o, null, null);
|
|
72
75
|
}
|
|
73
76
|
if (t !== ".mjs")
|
|
74
|
-
return
|
|
77
|
+
return e();
|
|
75
78
|
}
|
|
76
79
|
},
|
|
77
80
|
customBlockHandler(t) {
|
|
78
81
|
if (t.type === "i18n") {
|
|
79
|
-
const
|
|
80
|
-
for (const
|
|
81
|
-
|
|
82
|
+
const e = JSON.parse(t.content);
|
|
83
|
+
for (const r in e)
|
|
84
|
+
v(r, e[r]);
|
|
82
85
|
}
|
|
83
86
|
},
|
|
84
87
|
getFile: async (t) => {
|
|
85
|
-
t =
|
|
86
|
-
const
|
|
88
|
+
t = y(t, ".vue"), t = y(t, ".json");
|
|
89
|
+
const e = await c.request({
|
|
87
90
|
path: typeof i?.remote?.apiRoutePath == "function" ? i?.remote?.apiRoutePath(t) : i?.remote?.apiRoutePath || "static",
|
|
88
91
|
payload: {
|
|
89
92
|
path: t
|
|
90
93
|
},
|
|
91
94
|
method: i?.remote?.apiMethod || "POST"
|
|
92
95
|
}).then((o) => o?.data).catch((o) => {
|
|
93
|
-
|
|
96
|
+
u(o);
|
|
94
97
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
if (!e)
|
|
99
|
+
return;
|
|
100
|
+
let r = e?.type || ".vue";
|
|
101
|
+
return (e?.type?.endsWith("js") || e?.type?.endsWith("ts") || e?.type?.endsWith("jsx") || e?.type?.endsWith("tsx")) && (r = ".mjs"), {
|
|
102
|
+
content: e?.content,
|
|
103
|
+
type: r
|
|
99
104
|
};
|
|
100
105
|
},
|
|
101
106
|
getResource({
|
|
102
107
|
refPath: t,
|
|
103
|
-
relPath:
|
|
104
|
-
},
|
|
108
|
+
relPath: e
|
|
109
|
+
}, r) {
|
|
105
110
|
const {
|
|
106
111
|
moduleCache: o,
|
|
107
|
-
pathResolve:
|
|
112
|
+
pathResolve: x,
|
|
108
113
|
getFile: w
|
|
109
|
-
} =
|
|
114
|
+
} = r, [R, ...d] = e.match(/([^!]+!)|[^!]+$/g).reverse(), P = (n, p, m, f) => d.reduce((C, W) => o[W](C, p, m, f), n), a = x({
|
|
110
115
|
refPath: t,
|
|
111
|
-
relPath:
|
|
112
|
-
},
|
|
116
|
+
relPath: R
|
|
117
|
+
}, r), S = d.join("") + a, $ = (n) => n.startsWith("@") ? !0 : !n.includes("/") && !n.startsWith(".");
|
|
113
118
|
return {
|
|
114
|
-
id:
|
|
119
|
+
id: S,
|
|
115
120
|
path: a,
|
|
116
121
|
async getContent() {
|
|
117
|
-
if (
|
|
122
|
+
if ($(a))
|
|
118
123
|
throw new Error(`Package ${a} not imported`);
|
|
119
|
-
const {
|
|
120
|
-
content:
|
|
124
|
+
const n = await w(a), {
|
|
125
|
+
content: p,
|
|
121
126
|
type: m
|
|
122
|
-
} =
|
|
127
|
+
} = n || {};
|
|
123
128
|
return {
|
|
124
|
-
getContentData: async (
|
|
129
|
+
getContentData: async (f) => P(p, a, m, r),
|
|
125
130
|
type: m
|
|
126
131
|
};
|
|
127
132
|
}
|
|
128
133
|
};
|
|
129
134
|
},
|
|
130
135
|
addStyle(t) {
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
136
|
+
const e = Q(t);
|
|
137
|
+
if (l.has(e))
|
|
133
138
|
return;
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
139
|
+
l.set(e, !0);
|
|
140
|
+
const r = document.createElement("style");
|
|
141
|
+
r.textContent = t, r.setAttribute("data-hash", e), document.head.appendChild(r);
|
|
137
142
|
}
|
|
138
143
|
};
|
|
139
|
-
return () =>
|
|
140
|
-
...
|
|
144
|
+
return () => q(`${s}`, {
|
|
145
|
+
...j
|
|
141
146
|
});
|
|
142
147
|
}
|
|
143
|
-
function
|
|
148
|
+
function y(s, c) {
|
|
144
149
|
const u = new RegExp(`${c}$`);
|
|
145
150
|
return s.replace(u, "");
|
|
146
151
|
}
|
|
147
152
|
export {
|
|
148
|
-
|
|
153
|
+
ft as sfcLoader
|
|
149
154
|
};
|
package/dist/esm/hooks/auth.js
CHANGED
|
@@ -1,127 +1,130 @@
|
|
|
1
|
-
import { ref as
|
|
1
|
+
import { ref as h } from "vue";
|
|
2
2
|
import { useRouter as g } from "vue-router";
|
|
3
3
|
import { useAuthStore as c } from "../stores/auth.js";
|
|
4
|
+
import "pinia";
|
|
5
|
+
import "lodash-es";
|
|
6
|
+
import { useRouteStore as f } from "../stores/route.js";
|
|
4
7
|
import { useManage as i } from "./manage.js";
|
|
5
|
-
function
|
|
6
|
-
const t = i(), n = c(), u =
|
|
8
|
+
function T(e) {
|
|
9
|
+
const t = i(), n = c(), u = f(), s = g(), o = h(!1);
|
|
7
10
|
return {
|
|
8
|
-
mutate: async (
|
|
9
|
-
|
|
10
|
-
const a = await t.config.authProvider?.login(
|
|
11
|
-
if (
|
|
11
|
+
mutate: async (d) => {
|
|
12
|
+
o.value = !0;
|
|
13
|
+
const a = await t.config.authProvider?.login(d, t);
|
|
14
|
+
if (o.value = !1, a?.success) {
|
|
12
15
|
if (!a?.data)
|
|
13
16
|
throw new Error("Login response data is undefined");
|
|
14
|
-
e?.onSuccess?.(a), n.login(a.data),
|
|
17
|
+
u.resetRouteInit(), e?.onSuccess?.(a), n.login(a.data), s.push(t.getRoutePath(a.redirectTo || "/"));
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
17
20
|
e?.onError?.(a);
|
|
18
21
|
},
|
|
19
|
-
isLoading:
|
|
22
|
+
isLoading: o
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
|
-
function
|
|
25
|
+
function p(e) {
|
|
23
26
|
const t = i(), n = c(), u = g();
|
|
24
27
|
return {
|
|
25
|
-
mutate: async (
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
e?.onSuccess?.(
|
|
28
|
+
mutate: async (o) => {
|
|
29
|
+
const r = await t.config.authProvider?.logout(o, t);
|
|
30
|
+
if (r?.success) {
|
|
31
|
+
e?.onSuccess?.(r), n.logout(), await u.replace(t.getRoutePath(r.redirectTo || "/login")), setTimeout(() => {
|
|
29
32
|
window.location.reload();
|
|
30
33
|
}, 100);
|
|
31
34
|
return;
|
|
32
35
|
}
|
|
33
|
-
e?.onError?.(
|
|
36
|
+
e?.onError?.(r);
|
|
34
37
|
}
|
|
35
38
|
};
|
|
36
39
|
}
|
|
37
|
-
function
|
|
38
|
-
const t = i(), n = c(), u =
|
|
40
|
+
function y(e) {
|
|
41
|
+
const t = i(), n = c(), { mutate: u } = m();
|
|
39
42
|
return {
|
|
40
|
-
mutate: async (
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
if (e?.onSuccess?.(
|
|
43
|
+
mutate: async (o) => {
|
|
44
|
+
const r = await t.config.authProvider?.check?.(o, t, n.getUser());
|
|
45
|
+
if (r?.success) {
|
|
46
|
+
if (e?.onSuccess?.(r), !r?.data)
|
|
44
47
|
throw new Error("Check response data is undefined");
|
|
45
|
-
n.update(
|
|
48
|
+
n.update(r.data);
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
48
|
-
e?.onError?.(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
e?.onError?.(r), r?.logout && u({
|
|
52
|
+
status: 401,
|
|
53
|
+
message: r.message || "Unauthorized"
|
|
54
|
+
});
|
|
51
55
|
}
|
|
52
56
|
};
|
|
53
57
|
}
|
|
54
|
-
function
|
|
58
|
+
function L(e) {
|
|
55
59
|
const t = i(), n = c(), u = g();
|
|
56
60
|
return {
|
|
57
|
-
mutate: async (
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
if (e?.onSuccess?.(
|
|
61
|
+
mutate: async (o) => {
|
|
62
|
+
const r = await t.config.authProvider?.register?.(o, t);
|
|
63
|
+
if (r?.success) {
|
|
64
|
+
if (e?.onSuccess?.(r), !r?.data)
|
|
61
65
|
throw new Error("Register response data is undefined");
|
|
62
|
-
n.login(
|
|
66
|
+
n.login(r.data), u.push(t.getRoutePath(r.redirectTo || "/"));
|
|
63
67
|
return;
|
|
64
68
|
}
|
|
65
|
-
e?.onError?.(
|
|
69
|
+
e?.onError?.(r);
|
|
66
70
|
}
|
|
67
71
|
};
|
|
68
72
|
}
|
|
69
|
-
function
|
|
73
|
+
function U(e) {
|
|
70
74
|
const t = i(), n = g();
|
|
71
75
|
return {
|
|
72
76
|
mutate: async (s) => {
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
e?.onSuccess?.(
|
|
77
|
+
const o = await t.config.authProvider?.forgotPassword?.(s, t);
|
|
78
|
+
if (o?.success) {
|
|
79
|
+
e?.onSuccess?.(o), o.redirectTo && n.push(t.getRoutePath(o.redirectTo || "/"));
|
|
76
80
|
return;
|
|
77
81
|
}
|
|
78
|
-
e?.onError?.(
|
|
82
|
+
e?.onError?.(o);
|
|
79
83
|
}
|
|
80
84
|
};
|
|
81
85
|
}
|
|
82
|
-
function
|
|
86
|
+
function k(e) {
|
|
83
87
|
const t = i(), n = g();
|
|
84
88
|
return {
|
|
85
89
|
mutate: async (s) => {
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
e?.onSuccess?.(
|
|
90
|
+
const o = await t.config.authProvider?.updatePassword?.(s, t);
|
|
91
|
+
if (o?.success) {
|
|
92
|
+
e?.onSuccess?.(o), o.redirectTo && n.push(t.getRoutePath(o.redirectTo || "/"));
|
|
89
93
|
return;
|
|
90
94
|
}
|
|
91
|
-
e?.onError?.(
|
|
95
|
+
e?.onError?.(o);
|
|
92
96
|
}
|
|
93
97
|
};
|
|
94
98
|
}
|
|
95
|
-
function
|
|
96
|
-
const { config: t, getRoutePath: n } = i(), u = g(), s = c();
|
|
99
|
+
function m(e) {
|
|
100
|
+
const { config: t, getRoutePath: n } = i(), u = g(), s = c(t.name), o = f(t.name);
|
|
97
101
|
return {
|
|
98
|
-
mutate: async (
|
|
99
|
-
const a = await t.authProvider?.onError(
|
|
100
|
-
e?.(a), a?.logout && (s.logout(), await u.replace(n(a.redirectTo || "/login")), setTimeout(() => {
|
|
101
|
-
window.location.reload();
|
|
102
|
+
mutate: async (d) => {
|
|
103
|
+
const a = await t.authProvider?.onError(d);
|
|
104
|
+
e?.(a), a?.logout && (await s.logout(), await o.resetRouteInit(), await u.replace(n(a.redirectTo || "/login")), setTimeout(() => {
|
|
102
105
|
}, 100));
|
|
103
106
|
}
|
|
104
107
|
};
|
|
105
108
|
}
|
|
106
|
-
function
|
|
109
|
+
function C(e) {
|
|
107
110
|
return c(e).getUser();
|
|
108
111
|
}
|
|
109
|
-
function
|
|
112
|
+
function I(e) {
|
|
110
113
|
return c(e).isLogin();
|
|
111
114
|
}
|
|
112
|
-
function
|
|
115
|
+
function A(e) {
|
|
113
116
|
const t = i(e), u = c(e).getUser();
|
|
114
|
-
return (
|
|
117
|
+
return (o, r) => t.config.authProvider?.can ? t.config.authProvider.can(o, r, t, u) : !0;
|
|
115
118
|
}
|
|
116
119
|
export {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
A as useCan,
|
|
121
|
+
y as useCheck,
|
|
122
|
+
m as useError,
|
|
123
|
+
U as useForgotPassword,
|
|
124
|
+
C as useGetAuth,
|
|
125
|
+
I as useIsLogin,
|
|
126
|
+
T as useLogin,
|
|
127
|
+
p as useLogout,
|
|
128
|
+
L as useRegister,
|
|
129
|
+
k as useUpdatePassword
|
|
127
130
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import i from "axios";
|
|
2
2
|
function o(a) {
|
|
3
3
|
return {
|
|
4
|
-
login: async (
|
|
4
|
+
login: async (t, r) => await i.post(r.getApiUrl(a?.apiPath?.login || "/login", a?.dataProviderName), t).then((e) => ({
|
|
5
5
|
success: !0,
|
|
6
6
|
message: e?.data?.message,
|
|
7
7
|
redirectTo: a?.routePath?.index || "/",
|
|
@@ -10,33 +10,33 @@ function o(a) {
|
|
|
10
10
|
success: !1,
|
|
11
11
|
message: e?.response?.data?.message || e?.message
|
|
12
12
|
})),
|
|
13
|
-
check: async (
|
|
13
|
+
check: async (t, r, e) => await i.get(r?.getApiUrl(a?.apiPath?.check || "/check", a?.dataProviderName) || "", {
|
|
14
14
|
headers: {
|
|
15
15
|
Authorization: e?.token || ""
|
|
16
16
|
}
|
|
17
|
-
}).then((
|
|
17
|
+
}).then((s) => ({
|
|
18
18
|
success: !0,
|
|
19
19
|
logout: !1,
|
|
20
|
-
message:
|
|
21
|
-
data:
|
|
22
|
-
})).catch((
|
|
20
|
+
message: s?.data?.message,
|
|
21
|
+
data: s?.data?.data
|
|
22
|
+
})).catch((s) => ({
|
|
23
23
|
success: !1,
|
|
24
|
-
logout:
|
|
25
|
-
message:
|
|
24
|
+
logout: s.status === 401,
|
|
25
|
+
message: s?.response?.data?.message || s?.message
|
|
26
26
|
})),
|
|
27
|
-
onError: async (
|
|
27
|
+
onError: async (t) => t?.status === 401 ? {
|
|
28
28
|
logout: !0,
|
|
29
29
|
redirectTo: a?.routePath?.login || "/login",
|
|
30
|
-
error:
|
|
30
|
+
error: t
|
|
31
31
|
} : {
|
|
32
32
|
logout: !1,
|
|
33
|
-
error:
|
|
33
|
+
error: t
|
|
34
34
|
},
|
|
35
35
|
logout: async () => ({
|
|
36
36
|
success: !0,
|
|
37
37
|
redirectTo: a?.routePath?.login || "/login"
|
|
38
38
|
}),
|
|
39
|
-
register: async (
|
|
39
|
+
register: async (t, r) => await i.post(r?.getApiUrl(a?.apiPath?.register || "/register", a?.dataProviderName) || "", t).then((e) => ({
|
|
40
40
|
success: !0,
|
|
41
41
|
message: e?.data?.message,
|
|
42
42
|
redirectTo: a?.routePath?.index || "/",
|
|
@@ -45,7 +45,7 @@ function o(a) {
|
|
|
45
45
|
success: !1,
|
|
46
46
|
message: e?.response?.data?.message || e?.message
|
|
47
47
|
})),
|
|
48
|
-
forgotPassword: async (
|
|
48
|
+
forgotPassword: async (t, r) => await i.post(r?.getApiUrl(a?.apiPath?.forgotPassword || "/forgot-password", a?.dataProviderName) || "", t).then((e) => ({
|
|
49
49
|
success: !0,
|
|
50
50
|
message: e?.data?.message,
|
|
51
51
|
redirectTo: a?.routePath?.login || "/login"
|
|
@@ -53,7 +53,7 @@ function o(a) {
|
|
|
53
53
|
success: !1,
|
|
54
54
|
message: e?.response?.data?.message || e?.message
|
|
55
55
|
})),
|
|
56
|
-
updatePassword: async (
|
|
56
|
+
updatePassword: async (t, r) => await i.post(r?.getApiUrl(a?.apiPath?.updatePassword || "/update-password", a?.dataProviderName) || "", t).then((e) => ({
|
|
57
57
|
success: !0,
|
|
58
58
|
message: e?.data?.message,
|
|
59
59
|
redirectTo: a?.routePath?.login || "/login"
|
|
@@ -61,7 +61,7 @@ function o(a) {
|
|
|
61
61
|
success: !1,
|
|
62
62
|
message: e?.response?.data?.message || e?.message
|
|
63
63
|
})),
|
|
64
|
-
can: (
|
|
64
|
+
can: (t, r, e, s) => !s?.permission || Array.isArray(s?.permission) && s?.permission?.length === 0 || typeof s?.permission == "object" && Object.keys(s?.permission).length === 0 ? !0 : !(Array.isArray(s?.permission) && !s?.permission?.includes(t) || typeof s?.permission == "object" && s?.permission[t] === !1)
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
export {
|
package/dist/esm/stores/route.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { defineStore as
|
|
2
|
-
import { inject as
|
|
3
|
-
function
|
|
4
|
-
const t =
|
|
1
|
+
import { defineStore as S } from "pinia";
|
|
2
|
+
import { inject as g, ref as l } from "vue";
|
|
3
|
+
function F(r) {
|
|
4
|
+
const t = g("dux.manage");
|
|
5
5
|
if (r || (r = t?.value || ""), !r)
|
|
6
6
|
throw new Error("manage not found");
|
|
7
|
-
return
|
|
7
|
+
return m(r)();
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
return
|
|
11
|
-
const t = l([]),
|
|
9
|
+
function m(r) {
|
|
10
|
+
return S(`routes-${r}`, () => {
|
|
11
|
+
const t = l([]), i = (e) => t.value?.find((n) => n.path === e), f = (e) => t.value?.find((n) => n.name === e), d = (e) => {
|
|
12
12
|
t.value?.push(e);
|
|
13
13
|
}, v = (e) => {
|
|
14
14
|
t.value = [...t.value, ...e];
|
|
@@ -16,7 +16,7 @@ function I(r) {
|
|
|
16
16
|
t.value = e;
|
|
17
17
|
}, p = () => t.value, h = () => {
|
|
18
18
|
t.value = [];
|
|
19
|
-
},
|
|
19
|
+
}, I = () => {
|
|
20
20
|
const e = t.value?.filter((o) => !o.parent && !o.name?.includes("404") && !o.name?.includes("403"))?.sort((o, u) => (o.sort || 0) - (u.sort || 0)), n = (o) => {
|
|
21
21
|
if (o.path)
|
|
22
22
|
return o;
|
|
@@ -32,24 +32,27 @@ function I(r) {
|
|
|
32
32
|
if (u)
|
|
33
33
|
return u;
|
|
34
34
|
}
|
|
35
|
-
},
|
|
35
|
+
}, a = l(!1);
|
|
36
36
|
return {
|
|
37
37
|
routes: t,
|
|
38
|
-
searchRoute:
|
|
38
|
+
searchRoute: i,
|
|
39
39
|
searchRouteName: f,
|
|
40
40
|
appendRoute: d,
|
|
41
41
|
appendRoutes: v,
|
|
42
42
|
setRoutes: R,
|
|
43
43
|
getRoutes: p,
|
|
44
44
|
clearRoutes: h,
|
|
45
|
-
getIndexRoute:
|
|
45
|
+
getIndexRoute: I,
|
|
46
46
|
getRouteInit: () => {
|
|
47
|
-
const e =
|
|
48
|
-
return
|
|
47
|
+
const e = a.value;
|
|
48
|
+
return a.value = !0, e;
|
|
49
|
+
},
|
|
50
|
+
resetRouteInit: () => {
|
|
51
|
+
a.value = !1;
|
|
49
52
|
}
|
|
50
53
|
};
|
|
51
54
|
});
|
|
52
55
|
}
|
|
53
56
|
export {
|
|
54
|
-
|
|
57
|
+
F as useRouteStore
|
|
55
58
|
};
|
|
@@ -11,10 +11,11 @@ export interface RouteStoreState {
|
|
|
11
11
|
clearRoutes: () => void;
|
|
12
12
|
getIndexRoute: () => IMenu | undefined;
|
|
13
13
|
getRouteInit: () => boolean;
|
|
14
|
+
resetRouteInit: () => void;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* use route store
|
|
17
18
|
* @param manageName manage name
|
|
18
19
|
* @returns route store
|
|
19
20
|
*/
|
|
20
|
-
export declare function useRouteStore(manageName?: string): import("pinia").Store<string, Pick<RouteStoreState, "routes">, Pick<RouteStoreState, never>, Pick<RouteStoreState, "searchRoute" | "searchRouteName" | "appendRoute" | "appendRoutes" | "setRoutes" | "getRoutes" | "clearRoutes" | "getIndexRoute" | "getRouteInit">>;
|
|
21
|
+
export declare function useRouteStore(manageName?: string): import("pinia").Store<string, Pick<RouteStoreState, "routes">, Pick<RouteStoreState, never>, Pick<RouteStoreState, "searchRoute" | "searchRouteName" | "appendRoute" | "appendRoutes" | "setRoutes" | "getRoutes" | "clearRoutes" | "getIndexRoute" | "getRouteInit" | "resetRouteInit">>;
|