@tsingroc/tsingroc-components 5.0.0-alpha.19 → 5.0.0-alpha.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.
package/dist/components/Auth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
1
2
|
import Sdk from "casdoor-js-sdk";
|
|
2
3
|
import { jwtDecode } from "jwt-decode";
|
|
3
|
-
import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
|
|
4
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
6
|
const commonAuth = (user, setUser) => ({
|
|
6
7
|
logout(redirect) {
|
|
@@ -215,29 +216,51 @@ export function AuthProvider(props) {
|
|
|
215
216
|
* 该组件必须在 {@linkcode AuthProvider} 内部才能使用。
|
|
216
217
|
*/
|
|
217
218
|
export function AuthCheck(props) {
|
|
219
|
+
const $ = _c(8);
|
|
218
220
|
const auth = useAuth("AuthCheck");
|
|
219
221
|
const userInfo = auth.userInfo;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
222
|
+
let t0;
|
|
223
|
+
if ($[0] !== auth || $[1] !== props.onFail) {
|
|
224
|
+
t0 = () => {
|
|
225
|
+
auth.validate().catch(props.onFail ?? (() => auth.login(location.href)));
|
|
226
|
+
};
|
|
227
|
+
$[0] = auth;
|
|
228
|
+
$[1] = props.onFail;
|
|
229
|
+
$[2] = t0;
|
|
230
|
+
} else {
|
|
231
|
+
t0 = $[2];
|
|
232
|
+
}
|
|
233
|
+
const onUnloggedIn = useEffectEvent(t0);
|
|
234
|
+
let t1;
|
|
235
|
+
if ($[3] !== auth.userInfo || $[4] !== onUnloggedIn) {
|
|
236
|
+
t1 = () => {
|
|
237
|
+
if (!auth.userInfo) {
|
|
238
|
+
onUnloggedIn();
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
$[3] = auth.userInfo;
|
|
242
|
+
$[4] = onUnloggedIn;
|
|
243
|
+
$[5] = t1;
|
|
244
|
+
} else {
|
|
245
|
+
t1 = $[5];
|
|
246
|
+
}
|
|
247
|
+
let t2;
|
|
248
|
+
if ($[6] !== auth) {
|
|
249
|
+
t2 = [auth];
|
|
250
|
+
$[6] = auth;
|
|
251
|
+
$[7] = t2;
|
|
252
|
+
} else {
|
|
253
|
+
t2 = $[7];
|
|
254
|
+
}
|
|
255
|
+
useEffect(t1, t2);
|
|
233
256
|
if (userInfo) {
|
|
234
257
|
if (!("roles" in userInfo) || (props.roles ?? []).every(role => userInfo.roles.includes(role))) {
|
|
235
258
|
return props.children;
|
|
236
259
|
} else {
|
|
237
|
-
return props.forbidden ?? "
|
|
260
|
+
return props.forbidden ?? "\u60A8\u65E0\u6743\u8BBF\u95EE\u6B64\u9875\u9762\uFF01";
|
|
238
261
|
}
|
|
239
262
|
} else {
|
|
240
|
-
return props.loading ?? "
|
|
263
|
+
return props.loading ?? "\u6B63\u5728\u767B\u5F55\u2026\u2026";
|
|
241
264
|
}
|
|
242
265
|
}
|
|
243
266
|
/**
|
|
@@ -57,8 +57,7 @@ export const withAutoResize = ECharts => function AutoResizedECharts(props) {
|
|
|
57
57
|
if (firstFire) {
|
|
58
58
|
firstFire = false;
|
|
59
59
|
} else {
|
|
60
|
-
|
|
61
|
-
ref.current.instance?.resize();
|
|
60
|
+
ref.current?.instance?.resize();
|
|
62
61
|
}
|
|
63
62
|
});
|
|
64
63
|
debugAssert(ref.current, "effect should run after ref is connected");
|