@taicode/common-web 3.7.4 → 3.7.7
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/LICENSE +21 -0
- package/package.json +12 -13
- package/styles.css +2 -0
- package/output/components/alert-dialog.d.ts +0 -20
- package/output/components/alert-dialog.d.ts.map +0 -1
- package/output/components/alert-dialog.js +0 -65
- package/output/components/alert.d.ts +0 -11
- package/output/components/alert.d.ts.map +0 -1
- package/output/components/alert.js +0 -38
- package/output/components/avatar.d.ts +0 -13
- package/output/components/avatar.d.ts.map +0 -1
- package/output/components/avatar.js +0 -40
- package/output/components/badge.d.ts +0 -11
- package/output/components/badge.d.ts.map +0 -1
- package/output/components/badge.js +0 -39
- package/output/components/button.d.ts +0 -12
- package/output/components/button.d.ts.map +0 -1
- package/output/components/button.js +0 -48
- package/output/components/calendar.d.ts +0 -13
- package/output/components/calendar.d.ts.map +0 -1
- package/output/components/calendar.js +0 -57
- package/output/components/card.d.ts +0 -13
- package/output/components/card.d.ts.map +0 -1
- package/output/components/card.js +0 -43
- package/output/components/chart.d.ts +0 -56
- package/output/components/chart.d.ts.map +0 -1
- package/output/components/chart.js +0 -127
- package/output/components/checkbox.d.ts +0 -5
- package/output/components/checkbox.d.ts.map +0 -1
- package/output/components/checkbox.js +0 -21
- package/output/components/command.d.ts +0 -20
- package/output/components/command.d.ts.map +0 -1
- package/output/components/command.js +0 -55
- package/output/components/dialog.d.ts +0 -20
- package/output/components/dialog.d.ts.map +0 -1
- package/output/components/dialog.js +0 -58
- package/output/components/direction.d.ts +0 -9
- package/output/components/direction.d.ts.map +0 -1
- package/output/components/direction.js +0 -10
- package/output/components/drawer.d.ts +0 -14
- package/output/components/drawer.d.ts.map +0 -1
- package/output/components/drawer.js +0 -56
- package/output/components/dropdown-menu.d.ts +0 -29
- package/output/components/dropdown-menu.d.ts.map +0 -1
- package/output/components/dropdown-menu.js +0 -78
- package/output/components/field.d.ts +0 -39
- package/output/components/field.d.ts.map +0 -1
- package/output/components/field.js +0 -102
- package/output/components/footer/index.d.ts +0 -27
- package/output/components/footer/index.d.ts.map +0 -1
- package/output/components/footer/index.js +0 -17
- package/output/components/form.d.ts +0 -26
- package/output/components/form.d.ts.map +0 -1
- package/output/components/form.js +0 -69
- package/output/components/index.d.ts +0 -46
- package/output/components/index.d.ts.map +0 -1
- package/output/components/index.js +0 -45
- package/output/components/input-group.d.ts +0 -17
- package/output/components/input-group.d.ts.map +0 -1
- package/output/components/input-group.js +0 -75
- package/output/components/input.d.ts +0 -4
- package/output/components/input.d.ts.map +0 -1
- package/output/components/input.js +0 -19
- package/output/components/item.d.ts +0 -25
- package/output/components/item.d.ts.map +0 -1
- package/output/components/item.js +0 -89
- package/output/components/json-view/index.d.ts +0 -11
- package/output/components/json-view/index.d.ts.map +0 -1
- package/output/components/json-view/index.js +0 -52
- package/output/components/json-view/lazy/index.d.ts +0 -18
- package/output/components/json-view/lazy/index.d.ts.map +0 -1
- package/output/components/json-view/lazy/index.js +0 -22
- package/output/components/kbd.d.ts +0 -4
- package/output/components/kbd.d.ts.map +0 -1
- package/output/components/kbd.js +0 -22
- package/output/components/label.d.ts +0 -5
- package/output/components/label.d.ts.map +0 -1
- package/output/components/label.js +0 -20
- package/output/components/list-actions/index.d.ts +0 -23
- package/output/components/list-actions/index.d.ts.map +0 -1
- package/output/components/list-actions/index.js +0 -15
- package/output/components/loading-button/index.d.ts +0 -44
- package/output/components/loading-button/index.d.ts.map +0 -1
- package/output/components/loading-button/index.js +0 -75
- package/output/components/loading-button/index.test.d.ts +0 -2
- package/output/components/loading-button/index.test.d.ts.map +0 -1
- package/output/components/loading-button/index.test.js +0 -203
- package/output/components/native-select.d.ts +0 -9
- package/output/components/native-select.d.ts.map +0 -1
- package/output/components/native-select.js +0 -28
- package/output/components/page-back-button/index.d.ts +0 -8
- package/output/components/page-back-button/index.d.ts.map +0 -1
- package/output/components/page-back-button/index.js +0 -7
- package/output/components/page-state.d.ts +0 -19
- package/output/components/page-state.d.ts.map +0 -1
- package/output/components/page-state.js +0 -13
- package/output/components/pagination/index.d.ts +0 -34
- package/output/components/pagination/index.d.ts.map +0 -1
- package/output/components/pagination/index.js +0 -75
- package/output/components/popover.d.ts +0 -11
- package/output/components/popover.d.ts.map +0 -1
- package/output/components/popover.js +0 -44
- package/output/components/progress.d.ts +0 -5
- package/output/components/progress.d.ts.map +0 -1
- package/output/components/progress.js +0 -21
- package/output/components/radio-group.d.ts +0 -6
- package/output/components/radio-group.d.ts.map +0 -1
- package/output/components/radio-group.js +0 -25
- package/output/components/route-pending-indicator/index.d.ts +0 -20
- package/output/components/route-pending-indicator/index.d.ts.map +0 -1
- package/output/components/route-pending-indicator/index.js +0 -17
- package/output/components/scroll-area.d.ts +0 -6
- package/output/components/scroll-area.d.ts.map +0 -1
- package/output/components/scroll-area.js +0 -24
- package/output/components/searchable-select/index.d.ts +0 -41
- package/output/components/searchable-select/index.d.ts.map +0 -1
- package/output/components/searchable-select/index.js +0 -46
- package/output/components/select.d.ts +0 -17
- package/output/components/select.d.ts.map +0 -1
- package/output/components/select.js +0 -58
- package/output/components/separator.d.ts +0 -5
- package/output/components/separator.d.ts.map +0 -1
- package/output/components/separator.js +0 -20
- package/output/components/sheet.d.ts +0 -16
- package/output/components/sheet.d.ts.map +0 -1
- package/output/components/sheet.js +0 -58
- package/output/components/sidebar.d.ts +0 -78
- package/output/components/sidebar.d.ts.map +0 -1
- package/output/components/sidebar.js +0 -233
- package/output/components/size-provider/index.d.ts +0 -2
- package/output/components/size-provider/index.d.ts.map +0 -1
- package/output/components/size-provider/index.js +0 -1
- package/output/components/size-provider/size-provider.d.ts +0 -9
- package/output/components/size-provider/size-provider.d.ts.map +0 -1
- package/output/components/size-provider/size-provider.js +0 -29
- package/output/components/skeleton.d.ts +0 -3
- package/output/components/skeleton.d.ts.map +0 -1
- package/output/components/skeleton.js +0 -18
- package/output/components/sonner.d.ts +0 -8
- package/output/components/sonner.d.ts.map +0 -1
- package/output/components/sonner.js +0 -34
- package/output/components/spinner.d.ts +0 -3
- package/output/components/spinner.d.ts.map +0 -1
- package/output/components/spinner.js +0 -19
- package/output/components/switch.d.ts +0 -8
- package/output/components/switch.d.ts.map +0 -1
- package/output/components/switch.js +0 -20
- package/output/components/table.d.ts +0 -11
- package/output/components/table.d.ts.map +0 -1
- package/output/components/table.js +0 -47
- package/output/components/tabs.d.ts +0 -12
- package/output/components/tabs.d.ts.map +0 -1
- package/output/components/tabs.js +0 -45
- package/output/components/textarea.d.ts +0 -4
- package/output/components/textarea.d.ts.map +0 -1
- package/output/components/textarea.js +0 -19
- package/output/components/theme-switcher.d.ts +0 -6
- package/output/components/theme-switcher.d.ts.map +0 -1
- package/output/components/theme-switcher.js +0 -19
- package/output/components/toaster/index.d.ts +0 -16
- package/output/components/toaster/index.d.ts.map +0 -1
- package/output/components/toaster/index.js +0 -70
- package/output/components/toggle-group.d.ts +0 -12
- package/output/components/toggle-group.d.ts.map +0 -1
- package/output/components/toggle-group.js +0 -38
- package/output/components/toggle.d.ts +0 -10
- package/output/components/toggle.d.ts.map +0 -1
- package/output/components/toggle.js +0 -38
- package/output/components/tooltip.d.ts +0 -8
- package/output/components/tooltip.d.ts.map +0 -1
- package/output/components/tooltip.js +0 -33
- package/output/features/confirm-dialog/index.d.ts +0 -41
- package/output/features/confirm-dialog/index.d.ts.map +0 -1
- package/output/features/confirm-dialog/index.js +0 -19
- package/output/features/input-confirm/index.d.ts +0 -26
- package/output/features/input-confirm/index.d.ts.map +0 -1
- package/output/features/input-confirm/index.js +0 -59
- package/output/features/signin/context.d.ts +0 -14
- package/output/features/signin/context.d.ts.map +0 -1
- package/output/features/signin/context.js +0 -13
- package/output/features/signin/index.d.ts +0 -58
- package/output/features/signin/index.d.ts.map +0 -1
- package/output/features/signin/index.js +0 -137
- package/output/features/signin/service.d.ts +0 -92
- package/output/features/signin/service.d.ts.map +0 -1
- package/output/features/signin/service.js +0 -519
- package/output/features/signin/service.test.d.ts +0 -2
- package/output/features/signin/service.test.d.ts.map +0 -1
- package/output/features/signin/service.test.js +0 -211
- package/output/features/signin/types.d.ts +0 -63
- package/output/features/signin/types.d.ts.map +0 -1
- package/output/features/signin/types.js +0 -1
- package/output/hooks/use-loading/index.d.ts +0 -6
- package/output/hooks/use-loading/index.d.ts.map +0 -1
- package/output/hooks/use-loading/index.js +0 -14
- package/output/hooks/use-loading/index.test.d.ts +0 -2
- package/output/hooks/use-loading/index.test.d.ts.map +0 -1
- package/output/hooks/use-loading/index.test.js +0 -24
- package/output/hooks/use-mobile/index.d.ts +0 -2
- package/output/hooks/use-mobile/index.d.ts.map +0 -1
- package/output/hooks/use-mobile/index.js +0 -16
- package/output/hooks/use-observer/index.d.ts +0 -2
- package/output/hooks/use-observer/index.d.ts.map +0 -1
- package/output/hooks/use-observer/index.js +0 -1
- package/output/hooks/use-observer/use-observer.d.ts +0 -3
- package/output/hooks/use-observer/use-observer.d.ts.map +0 -1
- package/output/hooks/use-observer/use-observer.js +0 -16
- package/output/hooks/use-observer/use-observer.test.d.ts +0 -2
- package/output/hooks/use-observer/use-observer.test.d.ts.map +0 -1
- package/output/hooks/use-observer/use-observer.test.js +0 -134
- package/output/hooks/use-offline/index.d.ts +0 -6
- package/output/hooks/use-offline/index.d.ts.map +0 -1
- package/output/hooks/use-offline/index.js +0 -19
- package/output/layout/app/index.d.ts +0 -34
- package/output/layout/app/index.d.ts.map +0 -1
- package/output/layout/app/index.js +0 -34
- package/output/layout/dashboard/index.d.ts +0 -76
- package/output/layout/dashboard/index.d.ts.map +0 -1
- package/output/layout/dashboard/index.js +0 -84
- package/output/layout/index.d.ts +0 -3
- package/output/layout/index.d.ts.map +0 -1
- package/output/layout/index.js +0 -2
- package/output/services/cache-api/cache-api.d.ts +0 -23
- package/output/services/cache-api/cache-api.d.ts.map +0 -1
- package/output/services/cache-api/cache-api.js +0 -145
- package/output/services/cache-api/cache-api.test.d.ts +0 -2
- package/output/services/cache-api/cache-api.test.d.ts.map +0 -1
- package/output/services/cache-api/cache-api.test.js +0 -610
- package/output/services/cache-api/index.d.ts +0 -2
- package/output/services/cache-api/index.d.ts.map +0 -1
- package/output/services/cache-api/index.js +0 -1
- package/output/services/cached-fetch/index.d.ts +0 -50
- package/output/services/cached-fetch/index.d.ts.map +0 -1
- package/output/services/cached-fetch/index.js +0 -196
- package/output/services/service/index.d.ts +0 -2
- package/output/services/service/index.d.ts.map +0 -1
- package/output/services/service/index.js +0 -1
- package/output/services/service/service.d.ts +0 -135
- package/output/services/service/service.d.ts.map +0 -1
- package/output/services/service/service.js +0 -276
- package/output/services/service/service.test.d.ts +0 -2
- package/output/services/service/service.test.d.ts.map +0 -1
- package/output/services/service/service.test.js +0 -1399
- package/output/services/side-cache/index.d.ts +0 -2
- package/output/services/side-cache/index.d.ts.map +0 -1
- package/output/services/side-cache/index.js +0 -1
- package/output/services/side-cache/side-cache.d.ts +0 -11
- package/output/services/side-cache/side-cache.d.ts.map +0 -1
- package/output/services/side-cache/side-cache.js +0 -161
- package/output/services/side-cache/side-cache.test.d.ts +0 -2
- package/output/services/side-cache/side-cache.test.d.ts.map +0 -1
- package/output/services/side-cache/side-cache.test.js +0 -271
- package/output/utils/avatar/index.d.ts +0 -28
- package/output/utils/avatar/index.d.ts.map +0 -1
- package/output/utils/avatar/index.js +0 -35
- package/output/utils/delay/index.d.ts +0 -2
- package/output/utils/delay/index.d.ts.map +0 -1
- package/output/utils/delay/index.js +0 -5
- package/output/utils/form/index.d.ts +0 -3
- package/output/utils/form/index.d.ts.map +0 -1
- package/output/utils/form/index.js +0 -1
- package/output/utils/merge-class-names/index.d.ts +0 -3
- package/output/utils/merge-class-names/index.d.ts.map +0 -1
- package/output/utils/merge-class-names/index.js +0 -5
- package/output/utils/merge-class-names/index.test.d.ts +0 -2
- package/output/utils/merge-class-names/index.test.d.ts.map +0 -1
- package/output/utils/merge-class-names/index.test.js +0 -7
- package/output/utils/performance/index.d.ts +0 -82
- package/output/utils/performance/index.d.ts.map +0 -1
- package/output/utils/performance/index.js +0 -129
- package/output/utils/redirect/index.d.ts +0 -6
- package/output/utils/redirect/index.d.ts.map +0 -1
- package/output/utils/redirect/index.js +0 -32
|
@@ -1,137 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|