@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,13 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export const SigninContext = createContext(null);
|
|
3
|
+
/**
|
|
4
|
+
* 使用登录上下文
|
|
5
|
+
* 用于在任何子组件中调用登录方法
|
|
6
|
+
*/
|
|
7
|
+
export function useSignin() {
|
|
8
|
+
const context = useContext(SigninContext);
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('useSigninContext must be used within SigninDialogProvider');
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SigninApi } from './types.js';
|
|
3
|
+
export { useSignin } from './context.js';
|
|
4
|
+
export type { SigninApi, SigninStatus, SigninApiError, ApplySigninResult, CheckStatusResult, } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* 登录弹窗文案配置
|
|
7
|
+
*/
|
|
8
|
+
export interface SigninDialogTexts {
|
|
9
|
+
/** 打开登录页标题 */
|
|
10
|
+
openingTitle?: string;
|
|
11
|
+
/** 等待登录标题 */
|
|
12
|
+
waitingTitle?: string;
|
|
13
|
+
/** 登录成功标题 */
|
|
14
|
+
successTitle?: string;
|
|
15
|
+
/** 登录失败标题 */
|
|
16
|
+
errorTitle?: string;
|
|
17
|
+
/** 登录已取消标题 */
|
|
18
|
+
cancelledTitle?: string;
|
|
19
|
+
/** 票据已过期标题 */
|
|
20
|
+
expiredTitle?: string;
|
|
21
|
+
/** 正在打开登录窗口描述 */
|
|
22
|
+
openingDescription?: string;
|
|
23
|
+
/** 请在新窗口中完成登录描述 */
|
|
24
|
+
waitingDescription?: string;
|
|
25
|
+
/** 登录成功描述 */
|
|
26
|
+
successDescription?: string;
|
|
27
|
+
/** 登录成功后此窗口将自动关闭提示 */
|
|
28
|
+
waitingHint?: string;
|
|
29
|
+
/** 登录过程中出现错误描述 */
|
|
30
|
+
errorDescription?: string;
|
|
31
|
+
/** 登录已被取消描述 */
|
|
32
|
+
cancelledDescription?: string;
|
|
33
|
+
/** 票据已过期描述 */
|
|
34
|
+
expiredDescription?: string;
|
|
35
|
+
/** 重新打开登录窗口按钮文字 */
|
|
36
|
+
reopenButton?: string;
|
|
37
|
+
/** 重新登录按钮文字 */
|
|
38
|
+
retryButton?: string;
|
|
39
|
+
/** 取消按钮文字 */
|
|
40
|
+
cancelButton?: string;
|
|
41
|
+
/** 关闭按钮文字 */
|
|
42
|
+
closeButton?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 登录弹窗 Provider
|
|
46
|
+
* 提供登录方法给子组件使用
|
|
47
|
+
*/
|
|
48
|
+
interface SigninDialogProviderProps {
|
|
49
|
+
children: React.ReactNode;
|
|
50
|
+
/** API 配置,用于适配不同的认证系统 */
|
|
51
|
+
apis: SigninApi;
|
|
52
|
+
/** 文案配置,用于 i18n */
|
|
53
|
+
texts?: SigninDialogTexts;
|
|
54
|
+
}
|
|
55
|
+
export declare const SigninDialogProvider: ((props: SigninDialogProviderProps) => React.JSX.Element) & {
|
|
56
|
+
displayName: string;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/features/signin/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAA;AAY3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAI3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAGxC,YAAY,EACV,SAAS,EACT,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,YAAY,CAAA;AAEnB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,cAAc;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc;IACd,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iBAAiB;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,mBAAmB;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,aAAa;IACb,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,sBAAsB;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kBAAkB;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,eAAe;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,cAAc;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,mBAAmB;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAkXD;;;GAGG;AACH,UAAU,yBAAyB;IACjC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,yBAAyB;IACzB,IAAI,EAAE,SAAS,CAAA;IACf,mBAAmB;IACnB,KAAK,CAAC,EAAE,iBAAiB,CAAA;CAC1B;AAED,eAAO,MAAM,oBAAoB,WAAoB,yBAAyB;;CAmC5E,CAAA"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import React, { useRef, useMemo, useCallback } from 'react';
|
|
14
|
+
import { observer } from 'mobx-react-lite';
|
|
15
|
+
import { motion, AnimatePresence } from 'framer-motion';
|
|
16
|
+
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
17
|
+
import { CheckCircleIcon, XCircleIcon, ExclamationTriangleIcon, ClockIcon } from '@heroicons/react/24/outline';
|
|
18
|
+
import { SigninService } from './service.js';
|
|
19
|
+
import { SigninContext } from './context.js';
|
|
20
|
+
import { ServiceProvider } from '../../services/service/index.js';
|
|
21
|
+
export { useSignin } from './context.js';
|
|
22
|
+
/**
|
|
23
|
+
* 默认文案
|
|
24
|
+
*/
|
|
25
|
+
const defaultTexts = {
|
|
26
|
+
openingTitle: '正在打开登录页',
|
|
27
|
+
waitingTitle: '等待登录',
|
|
28
|
+
successTitle: '登录成功',
|
|
29
|
+
errorTitle: '登录失败',
|
|
30
|
+
cancelledTitle: '登录已取消',
|
|
31
|
+
expiredTitle: '登录已过期',
|
|
32
|
+
openingDescription: '正在为您打开登录窗口...',
|
|
33
|
+
waitingDescription: '请在新窗口中完成登录',
|
|
34
|
+
successDescription: '登录成功!正在跳转...',
|
|
35
|
+
waitingHint: '登录成功后此窗口将自动关闭',
|
|
36
|
+
errorDescription: '登录过程中出现错误',
|
|
37
|
+
cancelledDescription: '您已取消本次登录',
|
|
38
|
+
expiredDescription: '登录票据已过期,请重新登录',
|
|
39
|
+
reopenButton: '重新打开登录窗口',
|
|
40
|
+
retryButton: '重新登录',
|
|
41
|
+
cancelButton: '取消',
|
|
42
|
+
closeButton: '关闭'
|
|
43
|
+
};
|
|
44
|
+
const Button = (_a) => {
|
|
45
|
+
var { variant = 'primary', className = '', children } = _a, props = __rest(_a, ["variant", "className", "children"]);
|
|
46
|
+
const baseStyles = 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-[var(--radius)] text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)] focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 h-10 px-4 py-2';
|
|
47
|
+
const variantStyles = variant === 'primary'
|
|
48
|
+
? 'bg-[var(--primary)] text-[var(--primary-foreground)] hover:opacity-90'
|
|
49
|
+
: 'border border-[var(--input)] bg-[var(--background)] hover:bg-[var(--accent)] hover:text-[var(--accent-foreground)]';
|
|
50
|
+
return (_jsx("button", Object.assign({ className: `${baseStyles} ${variantStyles} ${className}` }, props, { children: children })));
|
|
51
|
+
};
|
|
52
|
+
const SigninDialog = observer((props) => {
|
|
53
|
+
var _a;
|
|
54
|
+
const { service, texts } = props;
|
|
55
|
+
const title = (_a = texts[`${service.dialogStatus}Title`]) !== null && _a !== void 0 ? _a : texts.waitingTitle;
|
|
56
|
+
// 禁止关闭弹窗,防止用户误操作
|
|
57
|
+
const preventClose = () => {
|
|
58
|
+
// 不执行任何操作,阻止关闭
|
|
59
|
+
};
|
|
60
|
+
// 重新打开登录窗口
|
|
61
|
+
const handleReopenWindow = () => {
|
|
62
|
+
if (service.signinUrl) {
|
|
63
|
+
openSigninWindow(service.signinUrl);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
// 取消登录
|
|
67
|
+
const handleCancel = () => {
|
|
68
|
+
service.cancel();
|
|
69
|
+
};
|
|
70
|
+
// 关闭弹窗
|
|
71
|
+
const handleClose = () => {
|
|
72
|
+
service.closeDialog();
|
|
73
|
+
};
|
|
74
|
+
// 重新开始登录
|
|
75
|
+
const handleRetry = async () => {
|
|
76
|
+
const url = await service.start();
|
|
77
|
+
if (url) {
|
|
78
|
+
openSigninWindow(url);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* 打开登录窗口
|
|
83
|
+
*/
|
|
84
|
+
const openSigninWindow = (url) => {
|
|
85
|
+
window.open(url, '_blank');
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Opening 状态 - 正在打开登录窗口
|
|
89
|
+
*/
|
|
90
|
+
const OpeningState = () => (_jsxs(motion.div, { initial: { opacity: 0, scale: 0.9 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.9 }, transition: { duration: 0.2 }, className: "flex flex-col items-center gap-4", children: [_jsxs("div", { className: "relative flex items-center justify-center mb-8", children: [_jsx(motion.div, { className: "absolute size-16 rounded-full border-4 border-transparent border-t-emerald-600 border-r-emerald-600", animate: { rotate: 360 }, transition: { duration: 1, repeat: Infinity, ease: 'linear' } }), _jsx(motion.div, { className: "absolute size-12 rounded-full border-4 border-transparent border-b-emerald-400 border-l-emerald-400", animate: { rotate: -360 }, transition: { duration: 1.5, repeat: Infinity, ease: 'linear' } }), _jsx(motion.div, { className: "size-3 rounded-full bg-emerald-600", animate: {
|
|
91
|
+
scale: [1, 1.2, 1],
|
|
92
|
+
opacity: [1, 0.7, 1]
|
|
93
|
+
}, transition: { duration: 1, repeat: Infinity } })] }), _jsx(motion.p, { initial: { opacity: 0 }, animate: { opacity: 1 }, transition: { delay: 0.1 }, className: "text-base font-semibold text-[var(--foreground)]", children: texts.openingDescription }), _jsxs(motion.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { delay: 0.2 }, className: "mt-2 flex gap-2", children: [_jsx(Button, { variant: "primary", onClick: handleReopenWindow, children: texts.reopenButton }), _jsx(Button, { variant: "outline", onClick: handleCancel, children: texts.cancelButton })] })] }, "opening"));
|
|
94
|
+
/**
|
|
95
|
+
* Waiting 状态 - 等待用户登录
|
|
96
|
+
*/
|
|
97
|
+
const WaitingState = () => (_jsxs(motion.div, { initial: { opacity: 0, scale: 0.9 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.9 }, transition: { duration: 0.2 }, className: "flex flex-col items-center gap-4", children: [_jsxs("div", { className: "relative mb-2 size-16", children: [_jsx(motion.div, { className: "size-16 rounded-full border-4 border-emerald-200 dark:border-emerald-900", animate: { scale: [1, 1.1, 1] }, transition: { duration: 2, repeat: Infinity } }), _jsx(motion.div, { className: "absolute inset-0 rounded-full border-4 border-emerald-400", animate: { scale: [1, 1.3, 1], opacity: [0.75, 0, 0.75] }, transition: { duration: 2, repeat: Infinity } }), _jsx(motion.svg, { className: "absolute left-1/2 top-1/2 size-8 -translate-x-1/2 -translate-y-1/2 text-emerald-600", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", initial: { scale: 0 }, animate: { scale: 1 }, transition: { delay: 0.1 }, children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" }) })] }), _jsx("p", { className: "text-base font-semibold text-[var(--foreground)]", children: texts.waitingDescription }), _jsx("p", { className: "text-xs text-[var(--muted-foreground)]", children: texts.waitingHint }), _jsxs("div", { className: "mt-2 flex gap-2", children: [_jsx(Button, { variant: "primary", onClick: handleReopenWindow, children: texts.reopenButton }), _jsx(Button, { variant: "outline", onClick: handleCancel, children: texts.cancelButton })] })] }, "waiting"));
|
|
98
|
+
/**
|
|
99
|
+
* Success 状态 - 登录成功
|
|
100
|
+
*/
|
|
101
|
+
const SuccessState = () => (_jsxs(motion.div, { initial: { opacity: 0, scale: 0.5 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.5 }, transition: { duration: 0.3, type: 'spring' }, className: "flex flex-col items-center gap-4", children: [_jsx(motion.div, { className: "mb-2", initial: { scale: 0 }, animate: { scale: 1 }, transition: { delay: 0.1, type: 'spring', stiffness: 200 }, children: _jsx(CheckCircleIcon, { className: "size-16 text-emerald-600 dark:text-emerald-400" }) }), _jsx(motion.p, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { delay: 0.2 }, className: "text-base font-semibold text-[var(--primary)]", children: texts.successDescription })] }, "success"));
|
|
102
|
+
/**
|
|
103
|
+
* Error 状态 - 登录失败
|
|
104
|
+
*/
|
|
105
|
+
const ErrorState = () => (_jsxs(motion.div, { initial: { opacity: 0, scale: 0.9 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.9 }, transition: { duration: 0.2 }, className: "flex flex-col items-center gap-4", children: [_jsx(motion.div, { className: "mb-2", initial: { scale: 0 }, animate: { scale: 1, rotate: [0, -10, 10, -10, 0] }, transition: { scale: { delay: 0.1 }, rotate: { delay: 0.2, duration: 0.5 } }, children: _jsx(XCircleIcon, { className: "size-16 text-red-600 dark:text-red-400" }) }), _jsx("p", { className: "text-base font-semibold text-[var(--destructive)]", children: service.errorMessage || texts.errorDescription }), _jsxs("div", { className: "mt-2 flex gap-2", children: [_jsx(Button, { variant: "primary", onClick: handleRetry, children: texts.retryButton }), _jsx(Button, { variant: "outline", onClick: handleClose, children: texts.closeButton })] })] }, "error"));
|
|
106
|
+
/**
|
|
107
|
+
* Cancelled 状态 - 用户取消登录
|
|
108
|
+
*/
|
|
109
|
+
const CancelledState = () => (_jsxs(motion.div, { initial: { opacity: 0, scale: 0.9 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.9 }, transition: { duration: 0.2 }, className: "flex flex-col items-center gap-4", children: [_jsx(motion.div, { className: "mb-2", initial: { scale: 0 }, animate: { scale: 1 }, transition: { delay: 0.1, type: 'spring' }, children: _jsx(ExclamationTriangleIcon, { className: "size-16 text-amber-600 dark:text-amber-400" }) }), _jsx("p", { className: "text-base font-semibold text-[var(--muted-foreground)]", children: texts.cancelledDescription }), _jsxs("div", { className: "mt-2 flex gap-2", children: [_jsx(Button, { variant: "primary", onClick: handleRetry, children: texts.retryButton }), _jsx(Button, { variant: "outline", onClick: handleClose, children: texts.closeButton })] })] }, "cancelled"));
|
|
110
|
+
/**
|
|
111
|
+
* Expired 状态 - 票据过期
|
|
112
|
+
*/
|
|
113
|
+
const ExpiredState = () => (_jsxs(motion.div, { initial: { opacity: 0, scale: 0.9 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.9 }, transition: { duration: 0.2 }, className: "flex flex-col items-center gap-4", children: [_jsx(motion.div, { className: "mb-2", initial: { scale: 0 }, animate: { scale: 1 }, transition: { delay: 0.1, type: 'spring' }, children: _jsx(ClockIcon, { className: "size-16 text-orange-600 dark:text-orange-400" }) }), _jsx("p", { className: "text-base font-semibold text-[var(--muted-foreground)]", children: texts.expiredDescription }), _jsxs("div", { className: "mt-2 flex gap-2", children: [_jsx(Button, { variant: "primary", onClick: handleRetry, children: texts.retryButton }), _jsx(Button, { variant: "outline", onClick: handleClose, children: texts.closeButton })] })] }, "expired"));
|
|
114
|
+
return (_jsx(DialogPrimitive.Root, { open: service.isDialogOpen, onOpenChange: (open) => !open && preventClose(), children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Overlay, { className: "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" }), _jsxs(DialogPrimitive.Content, { "aria-describedby": undefined, className: "fixed left-[50%] top-[50%] z-50 w-[calc(100%-2rem)] max-w-md translate-x-[-50%] translate-y-[-50%] rounded-[var(--radius)] border border-[var(--border)] bg-[var(--background)] p-6 text-[var(--foreground)] shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]", children: [_jsx(DialogPrimitive.Title, { className: "sr-only", children: title }), _jsx("div", { className: "flex flex-col items-center justify-center py-8", children: _jsxs(AnimatePresence, { mode: "wait", children: [service.dialogStatus === 'opening' && _jsx(OpeningState, {}), service.dialogStatus === 'waiting' && _jsx(WaitingState, {}), service.dialogStatus === 'success' && _jsx(SuccessState, {}), service.dialogStatus === 'error' && _jsx(ErrorState, {}), service.dialogStatus === 'cancelled' && _jsx(CancelledState, {}), service.dialogStatus === 'expired' && _jsx(ExpiredState, {})] }) })] })] }) }));
|
|
115
|
+
});
|
|
116
|
+
export const SigninDialogProvider = observer((props) => {
|
|
117
|
+
const { children, apis: apiConfig, texts: customTexts } = props;
|
|
118
|
+
// 创建服务实例,使用 useRef 保持引用稳定
|
|
119
|
+
const signinService = useRef();
|
|
120
|
+
if (!signinService.current) {
|
|
121
|
+
signinService.current = new SigninService(apiConfig);
|
|
122
|
+
signinService.current.init();
|
|
123
|
+
}
|
|
124
|
+
// 合并默认文案和自定义文案
|
|
125
|
+
const texts = useMemo(() => (Object.assign(Object.assign({}, defaultTexts), customTexts)), [customTexts]);
|
|
126
|
+
const handleSignin = useCallback(async () => {
|
|
127
|
+
var _a;
|
|
128
|
+
const url = await ((_a = signinService.current) === null || _a === void 0 ? void 0 : _a.start());
|
|
129
|
+
if (url) {
|
|
130
|
+
window.open(url, '_blank');
|
|
131
|
+
}
|
|
132
|
+
}, []);
|
|
133
|
+
const contextValue = useMemo(() => ({
|
|
134
|
+
signin: handleSignin
|
|
135
|
+
}), [handleSignin]);
|
|
136
|
+
return (_jsx(SigninContext.Provider, { value: contextValue, children: _jsxs(ServiceProvider, { services: [{ provide: SigninService, useValue: signinService.current }], children: [children, signinService.current && _jsx(SigninDialog, { service: signinService.current, texts: texts })] }) }));
|
|
137
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Service } from '@taicode/common-base';
|
|
2
|
+
import type { SigninApi, SigninStatus } from './types.js';
|
|
3
|
+
export type SigninDialogStatus = 'idle' | 'opening' | 'waiting' | 'success' | 'error' | 'cancelled' | 'expired';
|
|
4
|
+
/**
|
|
5
|
+
* 登录服务配置
|
|
6
|
+
*/
|
|
7
|
+
export interface SigninServiceConfig {
|
|
8
|
+
/** 票据轮询间隔(毫秒),默认 2000ms */
|
|
9
|
+
pollInterval?: number;
|
|
10
|
+
/** 错误自动关闭延迟(毫秒),默认 3000ms */
|
|
11
|
+
errorAutoCloseDelay?: number;
|
|
12
|
+
/** 成功状态显示时长(毫秒),默认 1500ms */
|
|
13
|
+
successDisplayDuration?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class SigninService extends Service {
|
|
16
|
+
accessor inited: boolean;
|
|
17
|
+
private isPolling;
|
|
18
|
+
private readonly disposer;
|
|
19
|
+
private readonly apiConfig;
|
|
20
|
+
private readonly config;
|
|
21
|
+
private pollingTimer;
|
|
22
|
+
private accessor check;
|
|
23
|
+
private accessor ticket;
|
|
24
|
+
accessor dialogStatus: SigninDialogStatus;
|
|
25
|
+
accessor errorMessage: string;
|
|
26
|
+
constructor(apiConfig: SigninApi, config?: SigninServiceConfig);
|
|
27
|
+
get status(): SigninStatus | null;
|
|
28
|
+
get signinUrl(): string | null;
|
|
29
|
+
get isDialogOpen(): boolean;
|
|
30
|
+
get hasActiveTicket(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 检查票据是否过期
|
|
33
|
+
*/
|
|
34
|
+
private isTicketExpired;
|
|
35
|
+
/**
|
|
36
|
+
* 保存状态到 localStorage
|
|
37
|
+
*/
|
|
38
|
+
private saveState;
|
|
39
|
+
/**
|
|
40
|
+
* 从 localStorage 恢复状态
|
|
41
|
+
*/
|
|
42
|
+
private restoreState;
|
|
43
|
+
/**
|
|
44
|
+
* 清理持久化状态
|
|
45
|
+
*/
|
|
46
|
+
private clearPersistedState;
|
|
47
|
+
/**
|
|
48
|
+
* 设置错误状态
|
|
49
|
+
*/
|
|
50
|
+
private setError;
|
|
51
|
+
/**
|
|
52
|
+
* 停止票据状态轮询
|
|
53
|
+
*/
|
|
54
|
+
private stopPolling;
|
|
55
|
+
/**
|
|
56
|
+
* 处理认证成功
|
|
57
|
+
*/
|
|
58
|
+
private handleAuthSuccess;
|
|
59
|
+
/**
|
|
60
|
+
* 轮询检查票据状态
|
|
61
|
+
*/
|
|
62
|
+
private watchTicketStatus;
|
|
63
|
+
/**
|
|
64
|
+
* 安排下一次轮询
|
|
65
|
+
*/
|
|
66
|
+
private scheduleNextPoll;
|
|
67
|
+
/**
|
|
68
|
+
* 开始登录流程
|
|
69
|
+
*/
|
|
70
|
+
start(): Promise<string | null>;
|
|
71
|
+
/**
|
|
72
|
+
* 关闭对话框
|
|
73
|
+
*/
|
|
74
|
+
closeDialog(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* 取消登录流程
|
|
77
|
+
*/
|
|
78
|
+
cancel(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* 初始化服务
|
|
81
|
+
*/
|
|
82
|
+
init(): Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* 清理资源
|
|
85
|
+
*/
|
|
86
|
+
private cleanup;
|
|
87
|
+
/**
|
|
88
|
+
* 销毁服务
|
|
89
|
+
*/
|
|
90
|
+
dispose(): void;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../source/features/signin/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAsB,MAAM,sBAAsB,CAAA;AAElE,OAAO,KAAK,EAAE,SAAS,EAAwC,YAAY,EAAE,MAAM,YAAY,CAAA;AAE/F,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,CAAA;AAE/G;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,6BAA6B;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,6BAA6B;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC;AAoBD,qBAAa,aAAc,SAAQ,OAAO;IACxC,SACgB,MAAM,EAAE,OAAO,CAAQ;IAEvC,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;IACtD,OAAO,CAAC,YAAY,CAA6C;IAGjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IAGvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiC;IAGxD,SACgB,YAAY,EAAE,kBAAkB,CAAS;IAEzD,SACgB,YAAY,EAAE,MAAM,CAAK;gBAE7B,SAAS,EAAE,SAAS,EAAE,MAAM,GAAE,mBAAwB;IAMlE,IACW,MAAM,IAAI,YAAY,GAAG,IAAI,CAIvC;IAED,IACW,SAAS,IAAI,MAAM,GAAG,IAAI,CAEpC;IAED,IACW,YAAY,IAAI,OAAO,CAEjC;IAED,IACW,eAAe,IAAI,OAAO,CAEpC;IAED;;OAEG;IACH,OAAO,CAAC,eAAe;IAKvB;;OAEG;IACH,OAAO,CAAC,SAAS;IAgBjB;;OAEG;IACH,OAAO,CAAC,YAAY;IAuCpB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;OAEG;IACH,OAAO,CAAC,QAAQ;IAehB;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;OAEG;YACW,iBAAiB;IAyB/B;;OAEG;YACW,iBAAiB;IA4G/B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;OAEG;IAEG,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA+CrC;;OAEG;IAEG,WAAW;IASjB;;OAEG;IAEG,MAAM;IAqBZ;;OAEG;IAEU,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IA0BrC;;OAEG;IACH,OAAO,CAAC,OAAO;IAWf;;OAEG;IACI,OAAO;CAIf"}
|