@taicode/common-web 3.7.7 → 3.7.10
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/output/components/alert-dialog.d.ts +20 -0
- package/output/components/alert-dialog.d.ts.map +1 -0
- package/output/components/alert-dialog.js +65 -0
- package/output/components/alert.d.ts +11 -0
- package/output/components/alert.d.ts.map +1 -0
- package/output/components/alert.js +38 -0
- package/output/components/avatar.d.ts +13 -0
- package/output/components/avatar.d.ts.map +1 -0
- package/output/components/avatar.js +40 -0
- package/output/components/badge.d.ts +11 -0
- package/output/components/badge.d.ts.map +1 -0
- package/output/components/badge.js +39 -0
- package/output/components/button.d.ts +12 -0
- package/output/components/button.d.ts.map +1 -0
- package/output/components/button.js +48 -0
- package/output/components/calendar.d.ts +13 -0
- package/output/components/calendar.d.ts.map +1 -0
- package/output/components/calendar.js +57 -0
- package/output/components/card.d.ts +13 -0
- package/output/components/card.d.ts.map +1 -0
- package/output/components/card.js +43 -0
- package/output/components/chart.d.ts +56 -0
- package/output/components/chart.d.ts.map +1 -0
- package/output/components/chart.js +127 -0
- package/output/components/checkbox.d.ts +5 -0
- package/output/components/checkbox.d.ts.map +1 -0
- package/output/components/checkbox.js +21 -0
- package/output/components/command.d.ts +20 -0
- package/output/components/command.d.ts.map +1 -0
- package/output/components/command.js +55 -0
- package/output/components/dialog.d.ts +20 -0
- package/output/components/dialog.d.ts.map +1 -0
- package/output/components/dialog.js +58 -0
- package/output/components/direction.d.ts +9 -0
- package/output/components/direction.d.ts.map +1 -0
- package/output/components/direction.js +10 -0
- package/output/components/drawer.d.ts +14 -0
- package/output/components/drawer.d.ts.map +1 -0
- package/output/components/drawer.js +56 -0
- package/output/components/dropdown-menu.d.ts +29 -0
- package/output/components/dropdown-menu.d.ts.map +1 -0
- package/output/components/dropdown-menu.js +78 -0
- package/output/components/field.d.ts +39 -0
- package/output/components/field.d.ts.map +1 -0
- package/output/components/field.js +102 -0
- package/output/components/footer/index.d.ts +27 -0
- package/output/components/footer/index.d.ts.map +1 -0
- package/output/components/footer/index.js +17 -0
- package/output/components/form.d.ts +26 -0
- package/output/components/form.d.ts.map +1 -0
- package/output/components/form.js +69 -0
- package/output/components/index.d.ts +46 -0
- package/output/components/index.d.ts.map +1 -0
- package/output/components/index.js +45 -0
- package/output/components/input-group.d.ts +17 -0
- package/output/components/input-group.d.ts.map +1 -0
- package/output/components/input-group.js +75 -0
- package/output/components/input.d.ts +4 -0
- package/output/components/input.d.ts.map +1 -0
- package/output/components/input.js +19 -0
- package/output/components/item.d.ts +25 -0
- package/output/components/item.d.ts.map +1 -0
- package/output/components/item.js +89 -0
- package/output/components/json-view/index.d.ts +11 -0
- package/output/components/json-view/index.d.ts.map +1 -0
- package/output/components/json-view/index.js +52 -0
- package/output/components/json-view/lazy/index.d.ts +18 -0
- package/output/components/json-view/lazy/index.d.ts.map +1 -0
- package/output/components/json-view/lazy/index.js +22 -0
- package/output/components/kbd.d.ts +4 -0
- package/output/components/kbd.d.ts.map +1 -0
- package/output/components/kbd.js +22 -0
- package/output/components/label.d.ts +5 -0
- package/output/components/label.d.ts.map +1 -0
- package/output/components/label.js +20 -0
- package/output/components/list-actions/index.d.ts +23 -0
- package/output/components/list-actions/index.d.ts.map +1 -0
- package/output/components/list-actions/index.js +15 -0
- package/output/components/loading-button/index.d.ts +44 -0
- package/output/components/loading-button/index.d.ts.map +1 -0
- package/output/components/loading-button/index.js +75 -0
- package/output/components/loading-button/index.test.d.ts +2 -0
- package/output/components/loading-button/index.test.d.ts.map +1 -0
- package/output/components/loading-button/index.test.js +203 -0
- package/output/components/native-select.d.ts +9 -0
- package/output/components/native-select.d.ts.map +1 -0
- package/output/components/native-select.js +28 -0
- package/output/components/page-back-button/index.d.ts +8 -0
- package/output/components/page-back-button/index.d.ts.map +1 -0
- package/output/components/page-back-button/index.js +7 -0
- package/output/components/page-state.d.ts +19 -0
- package/output/components/page-state.d.ts.map +1 -0
- package/output/components/page-state.js +13 -0
- package/output/components/pagination/index.d.ts +34 -0
- package/output/components/pagination/index.d.ts.map +1 -0
- package/output/components/pagination/index.js +75 -0
- package/output/components/popover.d.ts +11 -0
- package/output/components/popover.d.ts.map +1 -0
- package/output/components/popover.js +44 -0
- package/output/components/progress.d.ts +5 -0
- package/output/components/progress.d.ts.map +1 -0
- package/output/components/progress.js +21 -0
- package/output/components/radio-group.d.ts +6 -0
- package/output/components/radio-group.d.ts.map +1 -0
- package/output/components/radio-group.js +25 -0
- package/output/components/route-pending-indicator/index.d.ts +20 -0
- package/output/components/route-pending-indicator/index.d.ts.map +1 -0
- package/output/components/route-pending-indicator/index.js +17 -0
- package/output/components/scroll-area.d.ts +6 -0
- package/output/components/scroll-area.d.ts.map +1 -0
- package/output/components/scroll-area.js +24 -0
- package/output/components/searchable-select/index.d.ts +41 -0
- package/output/components/searchable-select/index.d.ts.map +1 -0
- package/output/components/searchable-select/index.js +46 -0
- package/output/components/select.d.ts +17 -0
- package/output/components/select.d.ts.map +1 -0
- package/output/components/select.js +58 -0
- package/output/components/separator.d.ts +5 -0
- package/output/components/separator.d.ts.map +1 -0
- package/output/components/separator.js +20 -0
- package/output/components/sheet.d.ts +16 -0
- package/output/components/sheet.d.ts.map +1 -0
- package/output/components/sheet.js +58 -0
- package/output/components/sidebar.d.ts +78 -0
- package/output/components/sidebar.d.ts.map +1 -0
- package/output/components/sidebar.js +233 -0
- package/output/components/size-provider/index.d.ts +2 -0
- package/output/components/size-provider/index.d.ts.map +1 -0
- package/output/components/size-provider/index.js +1 -0
- package/output/components/size-provider/size-provider.d.ts +9 -0
- package/output/components/size-provider/size-provider.d.ts.map +1 -0
- package/output/components/size-provider/size-provider.js +29 -0
- package/output/components/skeleton.d.ts +3 -0
- package/output/components/skeleton.d.ts.map +1 -0
- package/output/components/skeleton.js +18 -0
- package/output/components/sonner.d.ts +8 -0
- package/output/components/sonner.d.ts.map +1 -0
- package/output/components/sonner.js +34 -0
- package/output/components/spinner.d.ts +3 -0
- package/output/components/spinner.d.ts.map +1 -0
- package/output/components/spinner.js +19 -0
- package/output/components/switch.d.ts +8 -0
- package/output/components/switch.d.ts.map +1 -0
- package/output/components/switch.js +20 -0
- package/output/components/table.d.ts +11 -0
- package/output/components/table.d.ts.map +1 -0
- package/output/components/table.js +47 -0
- package/output/components/tabs.d.ts +12 -0
- package/output/components/tabs.d.ts.map +1 -0
- package/output/components/tabs.js +45 -0
- package/output/components/textarea.d.ts +4 -0
- package/output/components/textarea.d.ts.map +1 -0
- package/output/components/textarea.js +19 -0
- package/output/components/theme-switcher.d.ts +6 -0
- package/output/components/theme-switcher.d.ts.map +1 -0
- package/output/components/theme-switcher.js +19 -0
- package/output/components/toaster/index.d.ts +16 -0
- package/output/components/toaster/index.d.ts.map +1 -0
- package/output/components/toaster/index.js +70 -0
- package/output/components/toggle-group.d.ts +12 -0
- package/output/components/toggle-group.d.ts.map +1 -0
- package/output/components/toggle-group.js +38 -0
- package/output/components/toggle.d.ts +10 -0
- package/output/components/toggle.d.ts.map +1 -0
- package/output/components/toggle.js +38 -0
- package/output/components/tooltip.d.ts +8 -0
- package/output/components/tooltip.d.ts.map +1 -0
- package/output/components/tooltip.js +33 -0
- package/output/features/confirm-dialog/index.d.ts +41 -0
- package/output/features/confirm-dialog/index.d.ts.map +1 -0
- package/output/features/confirm-dialog/index.js +19 -0
- package/output/features/input-confirm/index.d.ts +26 -0
- package/output/features/input-confirm/index.d.ts.map +1 -0
- package/output/features/input-confirm/index.js +59 -0
- package/output/features/signin/context.d.ts +14 -0
- package/output/features/signin/context.d.ts.map +1 -0
- package/output/features/signin/context.js +13 -0
- package/output/features/signin/index.d.ts +58 -0
- package/output/features/signin/index.d.ts.map +1 -0
- package/output/features/signin/index.js +137 -0
- package/output/features/signin/service.d.ts +92 -0
- package/output/features/signin/service.d.ts.map +1 -0
- package/output/features/signin/service.js +519 -0
- package/output/features/signin/service.test.d.ts +2 -0
- package/output/features/signin/service.test.d.ts.map +1 -0
- package/output/features/signin/service.test.js +211 -0
- package/output/features/signin/types.d.ts +63 -0
- package/output/features/signin/types.d.ts.map +1 -0
- package/output/features/signin/types.js +1 -0
- package/output/hooks/use-loading/index.d.ts +6 -0
- package/output/hooks/use-loading/index.d.ts.map +1 -0
- package/output/hooks/use-loading/index.js +14 -0
- package/output/hooks/use-loading/index.test.d.ts +2 -0
- package/output/hooks/use-loading/index.test.d.ts.map +1 -0
- package/output/hooks/use-loading/index.test.js +24 -0
- package/output/hooks/use-mobile/index.d.ts +2 -0
- package/output/hooks/use-mobile/index.d.ts.map +1 -0
- package/output/hooks/use-mobile/index.js +16 -0
- package/output/hooks/use-observer/index.d.ts +2 -0
- package/output/hooks/use-observer/index.d.ts.map +1 -0
- package/output/hooks/use-observer/index.js +1 -0
- package/output/hooks/use-observer/use-observer.d.ts +3 -0
- package/output/hooks/use-observer/use-observer.d.ts.map +1 -0
- package/output/hooks/use-observer/use-observer.js +16 -0
- package/output/hooks/use-observer/use-observer.test.d.ts +2 -0
- package/output/hooks/use-observer/use-observer.test.d.ts.map +1 -0
- package/output/hooks/use-observer/use-observer.test.js +134 -0
- package/output/hooks/use-offline/index.d.ts +6 -0
- package/output/hooks/use-offline/index.d.ts.map +1 -0
- package/output/hooks/use-offline/index.js +19 -0
- package/output/layout/app/index.d.ts +34 -0
- package/output/layout/app/index.d.ts.map +1 -0
- package/output/layout/app/index.js +34 -0
- package/output/layout/dashboard/index.d.ts +76 -0
- package/output/layout/dashboard/index.d.ts.map +1 -0
- package/output/layout/dashboard/index.js +84 -0
- package/output/layout/index.d.ts +3 -0
- package/output/layout/index.d.ts.map +1 -0
- package/output/layout/index.js +2 -0
- package/output/services/cache-api/cache-api.d.ts +23 -0
- package/output/services/cache-api/cache-api.d.ts.map +1 -0
- package/output/services/cache-api/cache-api.js +145 -0
- package/output/services/cache-api/cache-api.test.d.ts +2 -0
- package/output/services/cache-api/cache-api.test.d.ts.map +1 -0
- package/output/services/cache-api/cache-api.test.js +610 -0
- package/output/services/cache-api/index.d.ts +2 -0
- package/output/services/cache-api/index.d.ts.map +1 -0
- package/output/services/cache-api/index.js +1 -0
- package/output/services/cached-fetch/index.d.ts +50 -0
- package/output/services/cached-fetch/index.d.ts.map +1 -0
- package/output/services/cached-fetch/index.js +196 -0
- package/output/services/service/index.d.ts +2 -0
- package/output/services/service/index.d.ts.map +1 -0
- package/output/services/service/index.js +1 -0
- package/output/services/service/service.d.ts +135 -0
- package/output/services/service/service.d.ts.map +1 -0
- package/output/services/service/service.js +276 -0
- package/output/services/service/service.test.d.ts +2 -0
- package/output/services/service/service.test.d.ts.map +1 -0
- package/output/services/service/service.test.js +1399 -0
- package/output/services/side-cache/index.d.ts +2 -0
- package/output/services/side-cache/index.d.ts.map +1 -0
- package/output/services/side-cache/index.js +1 -0
- package/output/services/side-cache/side-cache.d.ts +11 -0
- package/output/services/side-cache/side-cache.d.ts.map +1 -0
- package/output/services/side-cache/side-cache.js +161 -0
- package/output/services/side-cache/side-cache.test.d.ts +2 -0
- package/output/services/side-cache/side-cache.test.d.ts.map +1 -0
- package/output/services/side-cache/side-cache.test.js +271 -0
- package/output/utils/avatar/index.d.ts +28 -0
- package/output/utils/avatar/index.d.ts.map +1 -0
- package/output/utils/avatar/index.js +35 -0
- package/output/utils/delay/index.d.ts +2 -0
- package/output/utils/delay/index.d.ts.map +1 -0
- package/output/utils/delay/index.js +5 -0
- package/output/utils/form/index.d.ts +3 -0
- package/output/utils/form/index.d.ts.map +1 -0
- package/output/utils/form/index.js +1 -0
- package/output/utils/merge-class-names/index.d.ts +3 -0
- package/output/utils/merge-class-names/index.d.ts.map +1 -0
- package/output/utils/merge-class-names/index.js +5 -0
- package/output/utils/merge-class-names/index.test.d.ts +2 -0
- package/output/utils/merge-class-names/index.test.d.ts.map +1 -0
- package/output/utils/merge-class-names/index.test.js +7 -0
- package/output/utils/performance/index.d.ts +82 -0
- package/output/utils/performance/index.d.ts.map +1 -0
- package/output/utils/performance/index.js +129 -0
- package/output/utils/redirect/index.d.ts +6 -0
- package/output/utils/redirect/index.d.ts.map +1 -0
- package/output/utils/redirect/index.js +32 -0
- package/package.json +8 -5
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
36
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
37
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
38
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
39
|
+
};
|
|
40
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
41
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
42
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
43
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
44
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
45
|
+
};
|
|
46
|
+
import { computed, observable, runInAction, reaction } from 'mobx';
|
|
47
|
+
import { Service, debounce, Disposer } from '@taicode/common-base';
|
|
48
|
+
const DEFAULT_CONFIG = {
|
|
49
|
+
pollInterval: 2000,
|
|
50
|
+
errorAutoCloseDelay: 3000,
|
|
51
|
+
successDisplayDuration: 1500
|
|
52
|
+
};
|
|
53
|
+
const STORAGE_KEY = '__signin_service_state__';
|
|
54
|
+
let SigninService = (() => {
|
|
55
|
+
var _a, _SigninService_inited_accessor_storage, _SigninService_check_accessor_storage, _SigninService_ticket_accessor_storage, _SigninService_dialogStatus_accessor_storage, _SigninService_errorMessage_accessor_storage;
|
|
56
|
+
var _b, _c;
|
|
57
|
+
let _classSuper = Service;
|
|
58
|
+
let _instanceExtraInitializers = [];
|
|
59
|
+
let _inited_decorators;
|
|
60
|
+
let _inited_initializers = [];
|
|
61
|
+
let _inited_extraInitializers = [];
|
|
62
|
+
let _check_decorators;
|
|
63
|
+
let _check_initializers = [];
|
|
64
|
+
let _check_extraInitializers = [];
|
|
65
|
+
let _ticket_decorators;
|
|
66
|
+
let _ticket_initializers = [];
|
|
67
|
+
let _ticket_extraInitializers = [];
|
|
68
|
+
let _dialogStatus_decorators;
|
|
69
|
+
let _dialogStatus_initializers = [];
|
|
70
|
+
let _dialogStatus_extraInitializers = [];
|
|
71
|
+
let _errorMessage_decorators;
|
|
72
|
+
let _errorMessage_initializers = [];
|
|
73
|
+
let _errorMessage_extraInitializers = [];
|
|
74
|
+
let _get_status_decorators;
|
|
75
|
+
let _get_signinUrl_decorators;
|
|
76
|
+
let _get_isDialogOpen_decorators;
|
|
77
|
+
let _get_hasActiveTicket_decorators;
|
|
78
|
+
let _start_decorators;
|
|
79
|
+
let _closeDialog_decorators;
|
|
80
|
+
let _cancel_decorators;
|
|
81
|
+
let _init_decorators;
|
|
82
|
+
return _a = class SigninService extends _classSuper {
|
|
83
|
+
get inited() { return __classPrivateFieldGet(this, _SigninService_inited_accessor_storage, "f"); }
|
|
84
|
+
set inited(value) { __classPrivateFieldSet(this, _SigninService_inited_accessor_storage, value, "f"); }
|
|
85
|
+
get check() { return __classPrivateFieldGet(this, _SigninService_check_accessor_storage, "f"); }
|
|
86
|
+
set check(value) { __classPrivateFieldSet(this, _SigninService_check_accessor_storage, value, "f"); }
|
|
87
|
+
get ticket() { return __classPrivateFieldGet(this, _SigninService_ticket_accessor_storage, "f"); }
|
|
88
|
+
set ticket(value) { __classPrivateFieldSet(this, _SigninService_ticket_accessor_storage, value, "f"); }
|
|
89
|
+
// UI 状态管理
|
|
90
|
+
get dialogStatus() { return __classPrivateFieldGet(this, _SigninService_dialogStatus_accessor_storage, "f"); }
|
|
91
|
+
set dialogStatus(value) { __classPrivateFieldSet(this, _SigninService_dialogStatus_accessor_storage, value, "f"); }
|
|
92
|
+
get errorMessage() { return __classPrivateFieldGet(this, _SigninService_errorMessage_accessor_storage, "f"); }
|
|
93
|
+
set errorMessage(value) { __classPrivateFieldSet(this, _SigninService_errorMessage_accessor_storage, value, "f"); }
|
|
94
|
+
constructor(apiConfig, config = {}) {
|
|
95
|
+
super();
|
|
96
|
+
_SigninService_inited_accessor_storage.set(this, (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _inited_initializers, false)));
|
|
97
|
+
this.isPolling = (__runInitializers(this, _inited_extraInitializers), false);
|
|
98
|
+
this.disposer = new Disposer();
|
|
99
|
+
this.pollingTimer = null;
|
|
100
|
+
_SigninService_check_accessor_storage.set(this, __runInitializers(this, _check_initializers, null));
|
|
101
|
+
_SigninService_ticket_accessor_storage.set(this, (__runInitializers(this, _check_extraInitializers), __runInitializers(this, _ticket_initializers, null
|
|
102
|
+
// UI 状态管理
|
|
103
|
+
)));
|
|
104
|
+
_SigninService_dialogStatus_accessor_storage.set(this, (__runInitializers(this, _ticket_extraInitializers), __runInitializers(this, _dialogStatus_initializers, 'idle')));
|
|
105
|
+
_SigninService_errorMessage_accessor_storage.set(this, (__runInitializers(this, _dialogStatus_extraInitializers), __runInitializers(this, _errorMessage_initializers, '')));
|
|
106
|
+
__runInitializers(this, _errorMessage_extraInitializers);
|
|
107
|
+
this.apiConfig = apiConfig;
|
|
108
|
+
this.config = Object.assign(Object.assign({}, DEFAULT_CONFIG), config);
|
|
109
|
+
}
|
|
110
|
+
get status() {
|
|
111
|
+
if (this.ticket == null)
|
|
112
|
+
return null;
|
|
113
|
+
if (this.check == null)
|
|
114
|
+
return null;
|
|
115
|
+
return this.check.status;
|
|
116
|
+
}
|
|
117
|
+
get signinUrl() {
|
|
118
|
+
var _b, _c;
|
|
119
|
+
return (_c = (_b = this.ticket) === null || _b === void 0 ? void 0 : _b.signinUrl) !== null && _c !== void 0 ? _c : null;
|
|
120
|
+
}
|
|
121
|
+
get isDialogOpen() {
|
|
122
|
+
return this.dialogStatus !== 'idle';
|
|
123
|
+
}
|
|
124
|
+
get hasActiveTicket() {
|
|
125
|
+
return this.ticket != null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 检查票据是否过期
|
|
129
|
+
*/
|
|
130
|
+
isTicketExpired(ticket) {
|
|
131
|
+
const expiredTime = new Date(ticket.expiredTime);
|
|
132
|
+
return new Date() > expiredTime;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 保存状态到 localStorage
|
|
136
|
+
*/
|
|
137
|
+
saveState() {
|
|
138
|
+
if (typeof window === 'undefined' || !window.localStorage)
|
|
139
|
+
return;
|
|
140
|
+
try {
|
|
141
|
+
const state = {
|
|
142
|
+
ticket: this.ticket,
|
|
143
|
+
dialogStatus: this.dialogStatus,
|
|
144
|
+
errorMessage: this.errorMessage,
|
|
145
|
+
timestamp: Date.now()
|
|
146
|
+
};
|
|
147
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.warn('Failed to save signin state:', error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 从 localStorage 恢复状态
|
|
155
|
+
*/
|
|
156
|
+
restoreState() {
|
|
157
|
+
if (typeof window === 'undefined' || !window.localStorage)
|
|
158
|
+
return false;
|
|
159
|
+
try {
|
|
160
|
+
const data = localStorage.getItem(STORAGE_KEY);
|
|
161
|
+
if (!data)
|
|
162
|
+
return false;
|
|
163
|
+
const state = JSON.parse(data);
|
|
164
|
+
// 检查票据是否存在且未过期(使用票据本身的过期时间)
|
|
165
|
+
if (state.ticket && !this.isTicketExpired(state.ticket)) {
|
|
166
|
+
runInAction(() => {
|
|
167
|
+
this.ticket = state.ticket;
|
|
168
|
+
this.dialogStatus = state.dialogStatus;
|
|
169
|
+
this.errorMessage = state.errorMessage;
|
|
170
|
+
});
|
|
171
|
+
// 如果是等待或打开中状态,恢复轮询并显示弹窗
|
|
172
|
+
if (state.dialogStatus === 'waiting' || state.dialogStatus === 'opening') {
|
|
173
|
+
// 确保弹窗显示
|
|
174
|
+
runInAction(() => {
|
|
175
|
+
this.dialogStatus = 'waiting';
|
|
176
|
+
});
|
|
177
|
+
this.watchTicketStatus();
|
|
178
|
+
}
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
// 票据无效或过期,清理状态
|
|
182
|
+
this.clearPersistedState();
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
console.warn('Failed to restore signin state:', error);
|
|
187
|
+
this.clearPersistedState();
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 清理持久化状态
|
|
193
|
+
*/
|
|
194
|
+
clearPersistedState() {
|
|
195
|
+
if (typeof window === 'undefined' || !window.localStorage)
|
|
196
|
+
return;
|
|
197
|
+
try {
|
|
198
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
console.warn('Failed to clear signin state:', error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 设置错误状态
|
|
206
|
+
*/
|
|
207
|
+
setError(message, autoClose = true) {
|
|
208
|
+
runInAction(() => {
|
|
209
|
+
this.dialogStatus = 'error';
|
|
210
|
+
this.errorMessage = message;
|
|
211
|
+
});
|
|
212
|
+
if (autoClose) {
|
|
213
|
+
setTimeout(() => {
|
|
214
|
+
if (this.dialogStatus === 'error') {
|
|
215
|
+
runInAction(() => this.dialogStatus = 'idle');
|
|
216
|
+
}
|
|
217
|
+
}, this.config.errorAutoCloseDelay);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 停止票据状态轮询
|
|
222
|
+
*/
|
|
223
|
+
stopPolling() {
|
|
224
|
+
this.isPolling = false;
|
|
225
|
+
if (this.pollingTimer) {
|
|
226
|
+
clearTimeout(this.pollingTimer);
|
|
227
|
+
this.pollingTimer = null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* 处理认证成功
|
|
232
|
+
*/
|
|
233
|
+
async handleAuthSuccess(token) {
|
|
234
|
+
try {
|
|
235
|
+
runInAction(() => {
|
|
236
|
+
this.ticket = null;
|
|
237
|
+
this.dialogStatus = 'success';
|
|
238
|
+
});
|
|
239
|
+
this.clearPersistedState();
|
|
240
|
+
// 显示成功状态一段时间
|
|
241
|
+
await new Promise(resolve => setTimeout(resolve, this.config.successDisplayDuration));
|
|
242
|
+
if (this.apiConfig.onSuccess) {
|
|
243
|
+
await this.apiConfig.onSuccess(token);
|
|
244
|
+
}
|
|
245
|
+
runInAction(() => {
|
|
246
|
+
this.dialogStatus = 'idle';
|
|
247
|
+
this.errorMessage = '';
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
console.error('Auth success handler failed:', error);
|
|
252
|
+
this.setError('Failed to complete authentication');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* 轮询检查票据状态
|
|
257
|
+
*/
|
|
258
|
+
async watchTicketStatus() {
|
|
259
|
+
if (!this.ticket || this.isPolling)
|
|
260
|
+
return;
|
|
261
|
+
this.isPolling = true;
|
|
262
|
+
const poll = async () => {
|
|
263
|
+
if (!this.ticket || !this.isPolling) {
|
|
264
|
+
this.stopPolling();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
// 检查票据是否过期
|
|
269
|
+
if (this.isTicketExpired(this.ticket)) {
|
|
270
|
+
this.stopPolling();
|
|
271
|
+
this.setError('Ticket expired');
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
// 调用外部提供的检查方法
|
|
275
|
+
const result = await this.apiConfig.checkStatus(this.ticket.ticket);
|
|
276
|
+
// 检查是否有错误
|
|
277
|
+
if (result.isError()) {
|
|
278
|
+
console.error('Check ticket failed:', result.error);
|
|
279
|
+
// API 调用失败,继续轮询
|
|
280
|
+
this.scheduleNextPoll(poll);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const check = result.value;
|
|
284
|
+
// 更新检查结果
|
|
285
|
+
runInAction(() => this.check = check);
|
|
286
|
+
// 根据状态处理
|
|
287
|
+
switch (check.status) {
|
|
288
|
+
case 'Finished':
|
|
289
|
+
this.stopPolling();
|
|
290
|
+
if (check.token) {
|
|
291
|
+
await this.handleAuthSuccess(check.token);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
this.setError('Authentication completed but no token received');
|
|
295
|
+
}
|
|
296
|
+
break;
|
|
297
|
+
case 'Cancelled':
|
|
298
|
+
this.stopPolling();
|
|
299
|
+
runInAction(() => {
|
|
300
|
+
this.dialogStatus = 'cancelled';
|
|
301
|
+
this.ticket = null;
|
|
302
|
+
});
|
|
303
|
+
this.clearPersistedState();
|
|
304
|
+
// 调用 onCancel 回调
|
|
305
|
+
if (this.apiConfig.onCancel) {
|
|
306
|
+
try {
|
|
307
|
+
await this.apiConfig.onCancel();
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
console.error('Cancel handler error:', error);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// 显示取消状态后自动关闭
|
|
314
|
+
setTimeout(() => {
|
|
315
|
+
if (this.dialogStatus === 'cancelled') {
|
|
316
|
+
runInAction(() => this.dialogStatus = 'idle');
|
|
317
|
+
}
|
|
318
|
+
}, this.config.errorAutoCloseDelay);
|
|
319
|
+
break;
|
|
320
|
+
case 'Expired':
|
|
321
|
+
this.stopPolling();
|
|
322
|
+
runInAction(() => {
|
|
323
|
+
this.dialogStatus = 'expired';
|
|
324
|
+
this.ticket = null;
|
|
325
|
+
});
|
|
326
|
+
this.clearPersistedState();
|
|
327
|
+
// 显示过期状态后自动关闭
|
|
328
|
+
setTimeout(() => {
|
|
329
|
+
if (this.dialogStatus === 'expired') {
|
|
330
|
+
runInAction(() => this.dialogStatus = 'idle');
|
|
331
|
+
}
|
|
332
|
+
}, this.config.errorAutoCloseDelay);
|
|
333
|
+
break;
|
|
334
|
+
case 'Pending':
|
|
335
|
+
// 继续轮询
|
|
336
|
+
this.scheduleNextPoll(poll);
|
|
337
|
+
break;
|
|
338
|
+
default:
|
|
339
|
+
// 未知状态,继续轮询
|
|
340
|
+
this.scheduleNextPoll(poll);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
console.error('Ticket polling error:', error);
|
|
345
|
+
// 出错继续轮询,避免暂时性网络问题导致整个流程中断
|
|
346
|
+
this.scheduleNextPoll(poll);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
// 开始轮询
|
|
350
|
+
poll();
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* 安排下一次轮询
|
|
354
|
+
*/
|
|
355
|
+
scheduleNextPoll(pollFn) {
|
|
356
|
+
if (!this.isPolling)
|
|
357
|
+
return;
|
|
358
|
+
this.pollingTimer = setTimeout(() => {
|
|
359
|
+
pollFn();
|
|
360
|
+
}, this.config.pollInterval);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* 开始登录流程
|
|
364
|
+
*/
|
|
365
|
+
async start() {
|
|
366
|
+
// 防止重复启动
|
|
367
|
+
if (this.dialogStatus !== 'idle') {
|
|
368
|
+
console.warn('Login already in progress');
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
runInAction(() => {
|
|
372
|
+
this.dialogStatus = 'opening';
|
|
373
|
+
this.errorMessage = '';
|
|
374
|
+
});
|
|
375
|
+
try {
|
|
376
|
+
// 调用外部提供的申请票据方法
|
|
377
|
+
const result = await this.apiConfig.applySignin();
|
|
378
|
+
// 检查是否有错误
|
|
379
|
+
if (result.isError()) {
|
|
380
|
+
this.setError(result.error.message || 'Failed to get signin ticket');
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
const ticket = result.value;
|
|
384
|
+
// 验证票据有效性
|
|
385
|
+
if (this.isTicketExpired(ticket)) {
|
|
386
|
+
this.setError('Received expired ticket');
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
runInAction(() => {
|
|
390
|
+
this.check = null;
|
|
391
|
+
this.ticket = ticket;
|
|
392
|
+
this.dialogStatus = 'waiting';
|
|
393
|
+
});
|
|
394
|
+
// 开始轮询
|
|
395
|
+
this.watchTicketStatus();
|
|
396
|
+
return this.signinUrl;
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
400
|
+
this.setError(message);
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* 关闭对话框
|
|
406
|
+
*/
|
|
407
|
+
async closeDialog() {
|
|
408
|
+
this.stopPolling();
|
|
409
|
+
this.clearPersistedState();
|
|
410
|
+
runInAction(() => {
|
|
411
|
+
this.dialogStatus = 'idle';
|
|
412
|
+
this.errorMessage = '';
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* 取消登录流程
|
|
417
|
+
*/
|
|
418
|
+
async cancel() {
|
|
419
|
+
this.stopPolling();
|
|
420
|
+
// 调用 onCancel 回调
|
|
421
|
+
if (this.apiConfig.onCancel) {
|
|
422
|
+
try {
|
|
423
|
+
await this.apiConfig.onCancel();
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
console.error('Cancel handler error:', error);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
this.clearPersistedState();
|
|
430
|
+
runInAction(() => {
|
|
431
|
+
this.ticket = null;
|
|
432
|
+
this.check = null;
|
|
433
|
+
this.dialogStatus = 'idle';
|
|
434
|
+
this.errorMessage = '';
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* 初始化服务
|
|
439
|
+
*/
|
|
440
|
+
async init() {
|
|
441
|
+
this.disposer.addDisposer(() => this.cleanup());
|
|
442
|
+
// 监听状态变化并自动保存
|
|
443
|
+
this.disposer.addDisposer(reaction(() => ({
|
|
444
|
+
ticket: this.ticket,
|
|
445
|
+
dialogStatus: this.dialogStatus,
|
|
446
|
+
errorMessage: this.errorMessage
|
|
447
|
+
}), () => {
|
|
448
|
+
// 只在需要恢复的状态时保存(等待或打开中且有有效票据)
|
|
449
|
+
if (this.ticket && (this.dialogStatus === 'waiting' || this.dialogStatus === 'opening')) {
|
|
450
|
+
this.saveState();
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
this.clearPersistedState();
|
|
454
|
+
}
|
|
455
|
+
}, { delay: 100 }));
|
|
456
|
+
// 尝试恢复持久化状态
|
|
457
|
+
this.restoreState();
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* 清理资源
|
|
462
|
+
*/
|
|
463
|
+
cleanup() {
|
|
464
|
+
this.stopPolling();
|
|
465
|
+
this.clearPersistedState();
|
|
466
|
+
runInAction(() => {
|
|
467
|
+
this.ticket = null;
|
|
468
|
+
this.check = null;
|
|
469
|
+
this.dialogStatus = 'idle';
|
|
470
|
+
this.errorMessage = '';
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* 销毁服务
|
|
475
|
+
*/
|
|
476
|
+
dispose() {
|
|
477
|
+
this.cleanup();
|
|
478
|
+
this.disposer.dispose();
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
_SigninService_inited_accessor_storage = new WeakMap(),
|
|
482
|
+
_SigninService_check_accessor_storage = new WeakMap(),
|
|
483
|
+
_SigninService_ticket_accessor_storage = new WeakMap(),
|
|
484
|
+
_SigninService_dialogStatus_accessor_storage = new WeakMap(),
|
|
485
|
+
_SigninService_errorMessage_accessor_storage = new WeakMap(),
|
|
486
|
+
(() => {
|
|
487
|
+
var _b;
|
|
488
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_b = _classSuper[Symbol.metadata]) !== null && _b !== void 0 ? _b : null) : void 0;
|
|
489
|
+
_inited_decorators = [observable];
|
|
490
|
+
_check_decorators = [(_b = observable).ref.bind(_b)];
|
|
491
|
+
_ticket_decorators = [(_c = observable).ref.bind(_c)];
|
|
492
|
+
_dialogStatus_decorators = [observable];
|
|
493
|
+
_errorMessage_decorators = [observable];
|
|
494
|
+
_get_status_decorators = [computed];
|
|
495
|
+
_get_signinUrl_decorators = [computed];
|
|
496
|
+
_get_isDialogOpen_decorators = [computed];
|
|
497
|
+
_get_hasActiveTicket_decorators = [computed];
|
|
498
|
+
_start_decorators = [debounce(100)];
|
|
499
|
+
_closeDialog_decorators = [debounce(100)];
|
|
500
|
+
_cancel_decorators = [debounce(100)];
|
|
501
|
+
_init_decorators = [debounce(100)];
|
|
502
|
+
__esDecorate(_a, null, _inited_decorators, { kind: "accessor", name: "inited", static: false, private: false, access: { has: obj => "inited" in obj, get: obj => obj.inited, set: (obj, value) => { obj.inited = value; } }, metadata: _metadata }, _inited_initializers, _inited_extraInitializers);
|
|
503
|
+
__esDecorate(_a, null, _check_decorators, { kind: "accessor", name: "check", static: false, private: false, access: { has: obj => "check" in obj, get: obj => obj.check, set: (obj, value) => { obj.check = value; } }, metadata: _metadata }, _check_initializers, _check_extraInitializers);
|
|
504
|
+
__esDecorate(_a, null, _ticket_decorators, { kind: "accessor", name: "ticket", static: false, private: false, access: { has: obj => "ticket" in obj, get: obj => obj.ticket, set: (obj, value) => { obj.ticket = value; } }, metadata: _metadata }, _ticket_initializers, _ticket_extraInitializers);
|
|
505
|
+
__esDecorate(_a, null, _dialogStatus_decorators, { kind: "accessor", name: "dialogStatus", static: false, private: false, access: { has: obj => "dialogStatus" in obj, get: obj => obj.dialogStatus, set: (obj, value) => { obj.dialogStatus = value; } }, metadata: _metadata }, _dialogStatus_initializers, _dialogStatus_extraInitializers);
|
|
506
|
+
__esDecorate(_a, null, _errorMessage_decorators, { kind: "accessor", name: "errorMessage", static: false, private: false, access: { has: obj => "errorMessage" in obj, get: obj => obj.errorMessage, set: (obj, value) => { obj.errorMessage = value; } }, metadata: _metadata }, _errorMessage_initializers, _errorMessage_extraInitializers);
|
|
507
|
+
__esDecorate(_a, null, _get_status_decorators, { kind: "getter", name: "status", static: false, private: false, access: { has: obj => "status" in obj, get: obj => obj.status }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
508
|
+
__esDecorate(_a, null, _get_signinUrl_decorators, { kind: "getter", name: "signinUrl", static: false, private: false, access: { has: obj => "signinUrl" in obj, get: obj => obj.signinUrl }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
509
|
+
__esDecorate(_a, null, _get_isDialogOpen_decorators, { kind: "getter", name: "isDialogOpen", static: false, private: false, access: { has: obj => "isDialogOpen" in obj, get: obj => obj.isDialogOpen }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
510
|
+
__esDecorate(_a, null, _get_hasActiveTicket_decorators, { kind: "getter", name: "hasActiveTicket", static: false, private: false, access: { has: obj => "hasActiveTicket" in obj, get: obj => obj.hasActiveTicket }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
511
|
+
__esDecorate(_a, null, _start_decorators, { kind: "method", name: "start", static: false, private: false, access: { has: obj => "start" in obj, get: obj => obj.start }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
512
|
+
__esDecorate(_a, null, _closeDialog_decorators, { kind: "method", name: "closeDialog", static: false, private: false, access: { has: obj => "closeDialog" in obj, get: obj => obj.closeDialog }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
513
|
+
__esDecorate(_a, null, _cancel_decorators, { kind: "method", name: "cancel", static: false, private: false, access: { has: obj => "cancel" in obj, get: obj => obj.cancel }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
514
|
+
__esDecorate(_a, null, _init_decorators, { kind: "method", name: "init", static: false, private: false, access: { has: obj => "init" in obj, get: obj => obj.init }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
515
|
+
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
516
|
+
})(),
|
|
517
|
+
_a;
|
|
518
|
+
})();
|
|
519
|
+
export { SigninService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.test.d.ts","sourceRoot":"","sources":["../../../source/features/signin/service.test.ts"],"names":[],"mappings":""}
|