@witlink/components 1.0.15 → 1.0.16
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/utils.cjs +1 -1
- package/dist/utils.js +47 -47
- package/package.json +1 -1
package/dist/utils.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 L=Object.prototype.toString;function i(e,n){return L.call(e)===`[object ${n}]`}function h(e){return i(e,"Function")}const U=e=>typeof e<"u",O=e=>!U(e),b=e=>e!==null&&i(e,"Object");function M(e){return i(e,"Date")}function v(e){return i(e,"Number")}function k(e){return i(e,"AsyncFunction")}function F(e){return i(e,"Promise")&&h(e.then)&&h(e.catch)}function K(e){return i(e,"String")}function J(e){return i(e,"Boolean")}function B(e){return e&&Array.isArray(e)}const R=()=>typeof window<"u",D=e=>typeof window<"u"&&i(e,"Window"),W=e=>b(e)&&!!e.tagName,_=typeof window>"u";function Y(e){return e&&["IMAGE","IMG"].includes(e.tagName)}function N(e){return e===null}function x(e){return O(e)||N(e)}function $(e,n){if(e&&typeof e=="object"){const r=window.URL.createObjectURL(new Blob([e])),t=document.createElement("a");t.style.display="none",t.href=r,t.setAttribute("download",n),document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(r)}}function w(e,n){e.forEach(r=>{n(r),Array.isArray(r.children)&&w(r.children,n)})}function G(e,n){n=Object.assign({id:"id",parentId:"parentId",children:"children",root:""},n);const{id:r,parentId:t,children:s,root:c}=n,a=JSON.parse(JSON.stringify(e));return a.filter(d=>{const y=a.filter(T=>d[r]===T[t]);return d[s]=y.length>0?y:null,d[t]===c})||e}const E="Witlink-Usercenter-QureyParams";function l(){const e=localStorage.getItem(E)||"{}",{token:n,lang:r,usercenterUrl:t}=JSON.parse(e);return{token:n,lang:r,usercenterUrl:t}}function q(e){const n=l();localStorage.setItem(E,JSON.stringify({...n,...e}))}function z(){const e=window.location.href,n={},r=e.split("?")[1];return r&&r.split("&").forEach(t=>{const[s,c]=t.split("=");s&&c&&(n[s]=decodeURIComponent(c))}),n}const C="Witlink-Usercenter";function Q(){const{usercenterUrl:e}=l();window.location.href=e}function X(){window.open(l().usercenterUrl,C),window.close()}const H="",f="ACCESS_TOKEN",m="locale",I="userInfo",S="menuInfo";function V(e){const n=new URL(e);return n.hash&&n.hash.startsWith("#/")?`/${n.hash.substring(2).split("?")[0]}`.replace(/\/+/g,"/"):n.pathname}function P(e,n={}){const r=Array.isArray(e)?e:[e];for(const t of r){if(t.path&&t.name!==void 0){const s=t.path.startsWith("/")?t.path:`/${t.path}`;n[s]=t.name.toString()}t.children&&t.children.length>0&&P(t.children,n)}return n}function o(e){return H+e}function Z(e){localStorage.setItem(o(f),e)}function ee(){return localStorage.getItem(o(f))}function ne(){localStorage.removeItem(o(f))}function te(e){localStorage.setItem(o(m),e)}function re(){return localStorage.getItem(o(m))}function oe(){localStorage.removeItem(o(m))}function se(e={}){e={...p()||{},...e},localStorage.setItem(o(I),JSON.stringify(e))}function p(e){const n=localStorage.getItem(o(I));if(e){if(typeof e=="string")return(n?JSON.parse(n):{})[e]||null;if(Array.isArray(e)){const r=n?JSON.parse(n):{},t={};return e.forEach(s=>{t[s]=r[s]||null}),t}}return n?JSON.parse(n):null}function ie(e){localStorage.setItem(o(S),JSON.stringify(e))}function A(){const e=localStorage.getItem(o(S));return e?JSON.parse(e):null}const g={},u={};function ce(){if(Object.keys(g).length===0){const e=A()||[];P(e,g)}return g}function j(){return Object.keys(u).length===0&&((p()||{}).role.permissions||[]).forEach(r=>{var t;if(r.actionEntitySet!=null&&((t=r.actionEntitySet)==null?void 0:t.length)>0){const s=r.actionEntitySet.map(c=>c.action);u[r.permissionId]=s}}),u}function ae(e){const n=j(),r=V(window.location.href),t=ce(),s=t[Object.keys(t||{}).find(a=>r.endsWith(a))]||"";return(n[s]||[]).includes(e)}function ue(){localStorage.removeItem(o(I)),localStorage.removeItem(o(S)),localStorage.removeItem(o(f)),localStorage.removeItem(o(m))}exports.UserCenterKey=C;exports.buildTree=G;exports.exportFile=$;exports.forEachTree=w;exports.getButtonPermissions=j;exports.getLocale=re;exports.getMenuInfo=A;exports.getToken=ee;exports.getUserCenterParams=l;exports.getUserCenterParamsByUrl=z;exports.getUserInfo=p;exports.hasPermission=ae;exports.is=i;exports.isArray=B;exports.isAsyncFunction=k;exports.isBoolean=J;exports.isClient=R;exports.isDate=M;exports.isDef=U;exports.isElement=W;exports.isFunction=h;exports.isImageDom=Y;exports.isNull=N;exports.isNullOrUndef=x;exports.isNumber=v;exports.isObject=b;exports.isPromise=F;exports.isServer=_;exports.isString=K;exports.isUndef=O;exports.isWindow=D;exports.logoutToUserCenter=X;exports.removeAll=ue;exports.removeLocale=oe;exports.removeToken=ne;exports.setLocale=te;exports.setMenuInfo=ie;exports.setToken=Z;exports.setUserCenterParams=q;exports.setUserInfo=se;exports.toUserCenterConsole=Q;
|
package/dist/utils.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
const
|
|
1
|
+
const w = Object.prototype.toString;
|
|
2
2
|
function i(n, t) {
|
|
3
|
-
return
|
|
3
|
+
return w.call(n) === `[object ${t}]`;
|
|
4
4
|
}
|
|
5
5
|
function S(n) {
|
|
6
6
|
return i(n, "Function");
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
function
|
|
8
|
+
const N = (n) => typeof n < "u", E = (n) => !N(n), A = (n) => n !== null && i(n, "Object");
|
|
9
|
+
function k(n) {
|
|
10
10
|
return i(n, "Date");
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function v(n) {
|
|
13
13
|
return i(n, "Number");
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function F(n) {
|
|
16
16
|
return i(n, "AsyncFunction");
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function W(n) {
|
|
19
19
|
return i(n, "Promise") && S(n.then) && S(n.catch);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function _(n) {
|
|
22
22
|
return i(n, "String");
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function B(n) {
|
|
25
25
|
return i(n, "Boolean");
|
|
26
26
|
}
|
|
27
27
|
function D(n) {
|
|
@@ -53,19 +53,19 @@ function X(n, t) {
|
|
|
53
53
|
{ id: "id", parentId: "parentId", children: "children", root: "" },
|
|
54
54
|
t
|
|
55
55
|
);
|
|
56
|
-
const { id: o, parentId: e, children: s, root: c } = t,
|
|
57
|
-
return
|
|
58
|
-
const
|
|
59
|
-
return
|
|
56
|
+
const { id: o, parentId: e, children: s, root: c } = t, u = JSON.parse(JSON.stringify(n));
|
|
57
|
+
return u.filter((m) => {
|
|
58
|
+
const p = u.filter((b) => m[o] === b[e]);
|
|
59
|
+
return m[s] = p.length > 0 ? p : null, m[e] === c;
|
|
60
60
|
}) || n;
|
|
61
61
|
}
|
|
62
62
|
const y = "Witlink-Usercenter-QureyParams";
|
|
63
|
-
function
|
|
63
|
+
function g() {
|
|
64
64
|
const n = localStorage.getItem(y) || "{}", { token: t, lang: o, usercenterUrl: e } = JSON.parse(n);
|
|
65
65
|
return { token: t, lang: o, usercenterUrl: e };
|
|
66
66
|
}
|
|
67
67
|
function H(n) {
|
|
68
|
-
const t =
|
|
68
|
+
const t = g();
|
|
69
69
|
localStorage.setItem(
|
|
70
70
|
y,
|
|
71
71
|
JSON.stringify({ ...t, ...n })
|
|
@@ -80,14 +80,14 @@ function V() {
|
|
|
80
80
|
}
|
|
81
81
|
const j = "Witlink-Usercenter";
|
|
82
82
|
function Z() {
|
|
83
|
-
const { usercenterUrl: n } =
|
|
83
|
+
const { usercenterUrl: n } = g();
|
|
84
84
|
window.location.href = n;
|
|
85
85
|
}
|
|
86
86
|
function nn() {
|
|
87
|
-
window.open(
|
|
87
|
+
window.open(g().usercenterUrl, j), window.close();
|
|
88
88
|
}
|
|
89
|
-
const
|
|
90
|
-
function
|
|
89
|
+
const L = "", l = "ACCESS_TOKEN", f = "locale", h = "userInfo", I = "menuInfo";
|
|
90
|
+
function M(n) {
|
|
91
91
|
const t = new URL(n);
|
|
92
92
|
return t.hash && t.hash.startsWith("#/") ? `/${t.hash.substring(2).split("?")[0]}`.replace(/\/+/g, "/") : t.pathname;
|
|
93
93
|
}
|
|
@@ -103,31 +103,31 @@ function O(n, t = {}) {
|
|
|
103
103
|
return t;
|
|
104
104
|
}
|
|
105
105
|
function r(n) {
|
|
106
|
-
return
|
|
106
|
+
return L + n;
|
|
107
107
|
}
|
|
108
108
|
function tn(n) {
|
|
109
|
-
localStorage.setItem(r(
|
|
109
|
+
localStorage.setItem(r(l), n);
|
|
110
110
|
}
|
|
111
111
|
function en() {
|
|
112
|
-
return localStorage.getItem(r(
|
|
112
|
+
return localStorage.getItem(r(l));
|
|
113
113
|
}
|
|
114
114
|
function on() {
|
|
115
|
-
localStorage.removeItem(r(
|
|
115
|
+
localStorage.removeItem(r(l));
|
|
116
116
|
}
|
|
117
117
|
function rn(n) {
|
|
118
|
-
localStorage.setItem(r(
|
|
118
|
+
localStorage.setItem(r(f), n);
|
|
119
119
|
}
|
|
120
120
|
function sn() {
|
|
121
|
-
return localStorage.getItem(r(
|
|
121
|
+
return localStorage.getItem(r(f));
|
|
122
122
|
}
|
|
123
123
|
function cn() {
|
|
124
|
-
localStorage.removeItem(r(
|
|
124
|
+
localStorage.removeItem(r(f));
|
|
125
125
|
}
|
|
126
126
|
function un(n = {}) {
|
|
127
|
-
n = { ...U() || {}, ...n }, localStorage.setItem(r(
|
|
127
|
+
n = { ...U() || {}, ...n }, localStorage.setItem(r(h), JSON.stringify(n));
|
|
128
128
|
}
|
|
129
129
|
function U(n) {
|
|
130
|
-
const t = localStorage.getItem(r(
|
|
130
|
+
const t = localStorage.getItem(r(h));
|
|
131
131
|
if (n) {
|
|
132
132
|
if (typeof n == "string")
|
|
133
133
|
return (t ? JSON.parse(t) : {})[n] || null;
|
|
@@ -141,35 +141,35 @@ function U(n) {
|
|
|
141
141
|
return t ? JSON.parse(t) : null;
|
|
142
142
|
}
|
|
143
143
|
function an(n) {
|
|
144
|
-
localStorage.setItem(r(
|
|
144
|
+
localStorage.setItem(r(I), JSON.stringify(n));
|
|
145
145
|
}
|
|
146
146
|
function J() {
|
|
147
|
-
const n = localStorage.getItem(r(
|
|
147
|
+
const n = localStorage.getItem(r(I));
|
|
148
148
|
return n ? JSON.parse(n) : null;
|
|
149
149
|
}
|
|
150
|
-
const
|
|
150
|
+
const d = {}, a = {};
|
|
151
151
|
function K() {
|
|
152
|
-
if (Object.keys(
|
|
152
|
+
if (Object.keys(d).length === 0) {
|
|
153
153
|
const n = J() || [];
|
|
154
|
-
O(n,
|
|
154
|
+
O(n, d);
|
|
155
155
|
}
|
|
156
|
-
return
|
|
156
|
+
return d;
|
|
157
157
|
}
|
|
158
158
|
function T() {
|
|
159
|
-
return Object.keys(
|
|
159
|
+
return Object.keys(a).length === 0 && ((U() || {}).role.permissions || []).forEach((o) => {
|
|
160
160
|
var e;
|
|
161
161
|
if (o.actionEntitySet != null && ((e = o.actionEntitySet) == null ? void 0 : e.length) > 0) {
|
|
162
162
|
const s = o.actionEntitySet.map((c) => c.action);
|
|
163
|
-
|
|
163
|
+
a[o.permissionId] = s;
|
|
164
164
|
}
|
|
165
|
-
}),
|
|
165
|
+
}), a;
|
|
166
166
|
}
|
|
167
167
|
function ln(n) {
|
|
168
|
-
const t = T(), o =
|
|
168
|
+
const t = T(), o = M(window.location.href), e = K(), s = e[Object.keys(e || {}).find((u) => o.endsWith(u))] || "";
|
|
169
169
|
return (t[s] || []).includes(n);
|
|
170
170
|
}
|
|
171
171
|
function fn() {
|
|
172
|
-
localStorage.removeItem(r(
|
|
172
|
+
localStorage.removeItem(r(h)), localStorage.removeItem(r(I)), localStorage.removeItem(r(l)), localStorage.removeItem(r(f));
|
|
173
173
|
}
|
|
174
174
|
export {
|
|
175
175
|
j as UserCenterKey,
|
|
@@ -180,27 +180,27 @@ export {
|
|
|
180
180
|
sn as getLocale,
|
|
181
181
|
J as getMenuInfo,
|
|
182
182
|
en as getToken,
|
|
183
|
-
|
|
183
|
+
g as getUserCenterParams,
|
|
184
184
|
V as getUserCenterParamsByUrl,
|
|
185
185
|
U as getUserInfo,
|
|
186
186
|
ln as hasPermission,
|
|
187
187
|
i as is,
|
|
188
188
|
D as isArray,
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
F as isAsyncFunction,
|
|
190
|
+
B as isBoolean,
|
|
191
191
|
Y as isClient,
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
k as isDate,
|
|
193
|
+
N as isDef,
|
|
194
194
|
$ as isElement,
|
|
195
195
|
S as isFunction,
|
|
196
196
|
q as isImageDom,
|
|
197
197
|
P as isNull,
|
|
198
198
|
z as isNullOrUndef,
|
|
199
|
-
|
|
199
|
+
v as isNumber,
|
|
200
200
|
A as isObject,
|
|
201
|
-
|
|
201
|
+
W as isPromise,
|
|
202
202
|
G as isServer,
|
|
203
|
-
|
|
203
|
+
_ as isString,
|
|
204
204
|
E as isUndef,
|
|
205
205
|
x as isWindow,
|
|
206
206
|
nn as logoutToUserCenter,
|