@lark-apaas/coding-template-nestjs-react-fullstack 0.1.36-alpha.20260903095202 → 0.1.36-alpha.20260903185731
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/package.json +1 -1
- package/template/client/src/components/ui/markdown.tsx +43 -0
- package/template/client/src/index.css +0 -1
- package/template/package-lock.json +5783 -13022
- package/template/package.json +5 -68
- package/template/client/src/components/business-ui/README.md +0 -519
- package/template/client/src/components/business-ui/api/chats/queries.ts +0 -39
- package/template/client/src/components/business-ui/api/chats/service.ts +0 -29
- package/template/client/src/components/business-ui/api/departments/queries.ts +0 -42
- package/template/client/src/components/business-ui/api/departments/service.ts +0 -18
- package/template/client/src/components/business-ui/api/files/service.ts +0 -28
- package/template/client/src/components/business-ui/api/user-profiles/queries.ts +0 -42
- package/template/client/src/components/business-ui/api/user-profiles/service.ts +0 -23
- package/template/client/src/components/business-ui/api/users/queries.ts +0 -34
- package/template/client/src/components/business-ui/api/users/service.ts +0 -40
- package/template/client/src/components/business-ui/chat-select/README.md +0 -128
- package/template/client/src/components/business-ui/chat-select/chat-item.tsx +0 -85
- package/template/client/src/components/business-ui/chat-select/chat-select-tag.tsx +0 -83
- package/template/client/src/components/business-ui/chat-select/chat-select.tsx +0 -197
- package/template/client/src/components/business-ui/chat-select/index.tsx +0 -12
- package/template/client/src/components/business-ui/chat-select/types.ts +0 -102
- package/template/client/src/components/business-ui/chat-select/use-chat-value.ts +0 -180
- package/template/client/src/components/business-ui/chat-select/utils.ts +0 -81
- package/template/client/src/components/business-ui/department-select/department-item.tsx +0 -55
- package/template/client/src/components/business-ui/department-select/department-select-field.tsx +0 -86
- package/template/client/src/components/business-ui/department-select/department-select-tag.tsx +0 -56
- package/template/client/src/components/business-ui/department-select/department-select.tsx +0 -168
- package/template/client/src/components/business-ui/department-select/icon-department.tsx +0 -22
- package/template/client/src/components/business-ui/department-select/index.tsx +0 -7
- package/template/client/src/components/business-ui/department-select/types.ts +0 -15
- package/template/client/src/components/business-ui/department-select/utils.ts +0 -17
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-content.tsx +0 -35
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-empty.tsx +0 -28
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-error.tsx +0 -35
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-item.tsx +0 -55
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-list.tsx +0 -174
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-loading.tsx +0 -19
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-search.tsx +0 -31
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-trigger.tsx +0 -281
- package/template/client/src/components/business-ui/entity-combobox/base-combobox.tsx +0 -132
- package/template/client/src/components/business-ui/entity-combobox/context.tsx +0 -19
- package/template/client/src/components/business-ui/entity-combobox/entity-combobox.tsx +0 -145
- package/template/client/src/components/business-ui/entity-combobox/highlight-text.tsx +0 -52
- package/template/client/src/components/business-ui/entity-combobox/hooks.tsx +0 -21
- package/template/client/src/components/business-ui/entity-combobox/index.tsx +0 -31
- package/template/client/src/components/business-ui/entity-combobox/item-pill.tsx +0 -179
- package/template/client/src/components/business-ui/entity-combobox/popover-wrapper.tsx +0 -149
- package/template/client/src/components/business-ui/entity-combobox/search-trigger.tsx +0 -262
- package/template/client/src/components/business-ui/entity-combobox/shared-types.ts +0 -296
- package/template/client/src/components/business-ui/entity-combobox/size-variants.tsx +0 -322
- package/template/client/src/components/business-ui/entity-combobox/types.ts +0 -246
- package/template/client/src/components/business-ui/entity-combobox/use-fetch-data.tsx +0 -81
- package/template/client/src/components/business-ui/entity-combobox/use-infinite-scroll.tsx +0 -99
- package/template/client/src/components/business-ui/entity-combobox/use-popover-outside-click.tsx +0 -32
- package/template/client/src/components/business-ui/form/checkbox-field.tsx +0 -83
- package/template/client/src/components/business-ui/form/context.tsx +0 -38
- package/template/client/src/components/business-ui/form/field-layout.tsx +0 -91
- package/template/client/src/components/business-ui/form/form.tsx +0 -54
- package/template/client/src/components/business-ui/form/hooks/form-context.tsx +0 -4
- package/template/client/src/components/business-ui/form/hooks/form-utils.ts +0 -23
- package/template/client/src/components/business-ui/form/hooks/form.tsx +0 -40
- package/template/client/src/components/business-ui/form/index.tsx +0 -4
- package/template/client/src/components/business-ui/form/input-field.tsx +0 -74
- package/template/client/src/components/business-ui/form/radio-group-field.tsx +0 -138
- package/template/client/src/components/business-ui/form/select-field.tsx +0 -155
- package/template/client/src/components/business-ui/form/switch-field.tsx +0 -66
- package/template/client/src/components/business-ui/form/textarea-field.tsx +0 -72
- package/template/client/src/components/business-ui/form/types.ts +0 -32
- package/template/client/src/components/business-ui/tiptap-editor/README.md +0 -324
- package/template/client/src/components/business-ui/tiptap-editor/components/attachment-toolbar-button.tsx +0 -74
- package/template/client/src/components/business-ui/tiptap-editor/components/blockquote-toolbar-button.tsx +0 -41
- package/template/client/src/components/business-ui/tiptap-editor/components/code-block-toolbar-button.tsx +0 -41
- package/template/client/src/components/business-ui/tiptap-editor/components/color-highlight-toolbar-button.tsx +0 -141
- package/template/client/src/components/business-ui/tiptap-editor/components/heading-toolbar-button.tsx +0 -99
- package/template/client/src/components/business-ui/tiptap-editor/components/horizontal-rule-toolbar-button.tsx +0 -39
- package/template/client/src/components/business-ui/tiptap-editor/components/image-upload-toolbar-button.tsx +0 -65
- package/template/client/src/components/business-ui/tiptap-editor/components/link-edit-form.tsx +0 -127
- package/template/client/src/components/business-ui/tiptap-editor/components/link-hover-toolbar.tsx +0 -380
- package/template/client/src/components/business-ui/tiptap-editor/components/link-toolbar-button.tsx +0 -96
- package/template/client/src/components/business-ui/tiptap-editor/components/list-toolbar-button.tsx +0 -75
- package/template/client/src/components/business-ui/tiptap-editor/components/mark-toolbar-button.tsx +0 -118
- package/template/client/src/components/business-ui/tiptap-editor/components/text-align-toolbar-button.tsx +0 -84
- package/template/client/src/components/business-ui/tiptap-editor/components/undo-redo-toolbar-button.tsx +0 -54
- package/template/client/src/components/business-ui/tiptap-editor/extensions/attachment.tsx +0 -539
- package/template/client/src/components/business-ui/tiptap-editor/extensions/code-block-shiki.tsx +0 -236
- package/template/client/src/components/business-ui/tiptap-editor/extensions/complete-kit.ts +0 -260
- package/template/client/src/components/business-ui/tiptap-editor/extensions/image.tsx +0 -456
- package/template/client/src/components/business-ui/tiptap-editor/hooks/use-tiptap-editor.ts +0 -47
- package/template/client/src/components/business-ui/tiptap-editor/index.ts +0 -38
- package/template/client/src/components/business-ui/tiptap-editor/tiptap-editor-complete.tsx +0 -112
- package/template/client/src/components/business-ui/tiptap-editor/tiptap-editor.tsx +0 -169
- package/template/client/src/components/business-ui/types/user.ts +0 -74
- package/template/client/src/components/business-ui/user-display/index.tsx +0 -2
- package/template/client/src/components/business-ui/user-display/overflow-tooltip-text.tsx +0 -90
- package/template/client/src/components/business-ui/user-display/type.ts +0 -27
- package/template/client/src/components/business-ui/user-display/user-display.tsx +0 -99
- package/template/client/src/components/business-ui/user-display/user-with-avatar.tsx +0 -158
- package/template/client/src/components/business-ui/user-display/utils.ts +0 -37
- package/template/client/src/components/business-ui/user-profile/error-image.tsx +0 -302
- package/template/client/src/components/business-ui/user-profile/user-external-script.ts +0 -73
- package/template/client/src/components/business-ui/user-profile/user-profile.tsx +0 -370
- package/template/client/src/components/business-ui/user-select/index.tsx +0 -28
- package/template/client/src/components/business-ui/user-select/types.ts +0 -109
- package/template/client/src/components/business-ui/user-select/use-user-value.ts +0 -160
- package/template/client/src/components/business-ui/user-select/user-item.tsx +0 -98
- package/template/client/src/components/business-ui/user-select/user-pill.tsx +0 -140
- package/template/client/src/components/business-ui/user-select/user-select-tag.tsx +0 -82
- package/template/client/src/components/business-ui/user-select/user-select.tsx +0 -359
- package/template/client/src/components/business-ui/user-select/utils.tsx +0 -188
- package/template/client/src/components/business-ui/utils/user.ts +0 -72
- package/template/client/src/components/ui/streamdown.tsx +0 -186
- package/template/client/src/lib/shiki.ts +0 -92
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Loader2 } from 'lucide-react';
|
|
4
|
-
|
|
5
|
-
import { BaseComboboxItem } from '@client/src/components/business-ui/entity-combobox/base-combobox-item';
|
|
6
|
-
import { HighlightText } from '@client/src/components/business-ui/entity-combobox/highlight-text';
|
|
7
|
-
import { isHexColor } from '@client/src/components/business-ui/entity-combobox/item-pill';
|
|
8
|
-
import {
|
|
9
|
-
listItemAvatarVariants,
|
|
10
|
-
listItemNameVariants,
|
|
11
|
-
listItemSubTextVariants,
|
|
12
|
-
listItemVariants,
|
|
13
|
-
type ComboboxSize,
|
|
14
|
-
} from '@client/src/components/business-ui/entity-combobox/size-variants';
|
|
15
|
-
import type { UserSelectItemValue } from '@client/src/components/business-ui/user-select/types';
|
|
16
|
-
import { cn } from '@/lib/utils';
|
|
17
|
-
import { getI18nText } from '@client/src/components/business-ui/utils/user';
|
|
18
|
-
import {
|
|
19
|
-
Avatar,
|
|
20
|
-
AvatarFallback,
|
|
21
|
-
AvatarImage,
|
|
22
|
-
} from '@client/src/components/ui/avatar';
|
|
23
|
-
|
|
24
|
-
const ExternalUserTag = () => (
|
|
25
|
-
<span className="dark:blue-200 inline-flex shrink-0 items-center rounded-sm bg-blue-500/20 px-1.5 py-0.5 text-xs leading-4 text-blue-900">
|
|
26
|
-
外部
|
|
27
|
-
</span>
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
export const UserItem = ({
|
|
31
|
-
userValue,
|
|
32
|
-
isSelected,
|
|
33
|
-
className,
|
|
34
|
-
size = 'medium',
|
|
35
|
-
searchKeyword,
|
|
36
|
-
disabled,
|
|
37
|
-
isConverting,
|
|
38
|
-
}: {
|
|
39
|
-
userValue: UserSelectItemValue;
|
|
40
|
-
isSelected: boolean;
|
|
41
|
-
className?: string;
|
|
42
|
-
size?: ComboboxSize;
|
|
43
|
-
searchKeyword?: string;
|
|
44
|
-
disabled?: boolean;
|
|
45
|
-
isConverting?: boolean;
|
|
46
|
-
}) => {
|
|
47
|
-
const user = userValue.raw;
|
|
48
|
-
const displayName = getI18nText(user?.name);
|
|
49
|
-
const isExternalUser = user?.user_type === '_externalUser';
|
|
50
|
-
|
|
51
|
-
const isHex = isHexColor(user?.avatar);
|
|
52
|
-
|
|
53
|
-
const avatarImage = !isHex ? (
|
|
54
|
-
<AvatarImage src={user?.avatar} alt={displayName} loading="eager" />
|
|
55
|
-
) : (
|
|
56
|
-
<AvatarFallback style={{ backgroundColor: user?.avatar }}>
|
|
57
|
-
{displayName?.charAt?.(0).toUpperCase()}
|
|
58
|
-
</AvatarFallback>
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<BaseComboboxItem
|
|
63
|
-
item={userValue}
|
|
64
|
-
getItemValue={(item) => item}
|
|
65
|
-
isSelected={isSelected}
|
|
66
|
-
className={cn(listItemVariants({ size }), className)}
|
|
67
|
-
disabled={disabled}
|
|
68
|
-
>
|
|
69
|
-
<div className="relative shrink-0">
|
|
70
|
-
<Avatar className={listItemAvatarVariants({ size })}>
|
|
71
|
-
{user?.avatar ? (
|
|
72
|
-
avatarImage
|
|
73
|
-
) : (
|
|
74
|
-
<AvatarFallback>{displayName?.charAt?.(0)}</AvatarFallback>
|
|
75
|
-
)}
|
|
76
|
-
</Avatar>
|
|
77
|
-
{isConverting && (
|
|
78
|
-
<div className="absolute inset-0 flex items-center justify-center rounded-full bg-black/40">
|
|
79
|
-
<Loader2 className="h-3.5 w-3.5 animate-spin text-white" />
|
|
80
|
-
</div>
|
|
81
|
-
)}
|
|
82
|
-
</div>
|
|
83
|
-
<div className="flex min-w-0 flex-1 flex-col gap-px">
|
|
84
|
-
<div className="flex items-center gap-1">
|
|
85
|
-
<HighlightText
|
|
86
|
-
text={userValue.name}
|
|
87
|
-
highlight={searchKeyword}
|
|
88
|
-
className={listItemNameVariants({ size })}
|
|
89
|
-
/>
|
|
90
|
-
{isExternalUser && <ExternalUserTag />}
|
|
91
|
-
</div>
|
|
92
|
-
<span className={listItemSubTextVariants({ size })}>
|
|
93
|
-
{getI18nText(user?.department?.name) || user?.tenantName}
|
|
94
|
-
</span>
|
|
95
|
-
</div>
|
|
96
|
-
</BaseComboboxItem>
|
|
97
|
-
);
|
|
98
|
-
};
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
ItemPill,
|
|
7
|
-
renderPillAvatar,
|
|
8
|
-
} from '@client/src/components/business-ui/entity-combobox/item-pill';
|
|
9
|
-
import type { ComboboxSize } from '@client/src/components/business-ui/entity-combobox/size-variants';
|
|
10
|
-
import { UserProfile } from '@client/src/components/business-ui/user-profile/user-profile';
|
|
11
|
-
import type { AccountType } from '@client/src/components/business-ui/user-select/types';
|
|
12
|
-
import { cn } from '@/lib/utils';
|
|
13
|
-
import {
|
|
14
|
-
Popover,
|
|
15
|
-
PopoverContent,
|
|
16
|
-
PopoverTrigger,
|
|
17
|
-
} from '@client/src/components/ui/popover';
|
|
18
|
-
|
|
19
|
-
export type UserPillProps = {
|
|
20
|
-
/**
|
|
21
|
-
* 用户 ID,用于 UserProfile 展示
|
|
22
|
-
*/
|
|
23
|
-
userId: string;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 账户类型
|
|
27
|
-
* @default "apaas"
|
|
28
|
-
*/
|
|
29
|
-
accountType?: AccountType;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 显示的用户名
|
|
33
|
-
*/
|
|
34
|
-
label: string;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 头像 URL
|
|
38
|
-
*/
|
|
39
|
-
avatarUrl?: string;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 尺寸
|
|
43
|
-
* @default "medium"
|
|
44
|
-
*/
|
|
45
|
-
size?: ComboboxSize;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 是否禁用
|
|
49
|
-
*/
|
|
50
|
-
disabled?: boolean;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 最大文本长度
|
|
54
|
-
*/
|
|
55
|
-
maxTextLength?: number;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 后缀(如关闭按钮)
|
|
59
|
-
*/
|
|
60
|
-
suffix?: React.ReactNode;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 自定义样式
|
|
64
|
-
*/
|
|
65
|
-
className?: string;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 是否启用点击头像弹出 UserProfile
|
|
69
|
-
* @default true
|
|
70
|
-
*/
|
|
71
|
-
enableProfile?: boolean;
|
|
72
|
-
|
|
73
|
-
avatarFallback?: boolean;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const UserPill: React.FC<UserPillProps> = ({
|
|
77
|
-
userId,
|
|
78
|
-
accountType = 'apaas',
|
|
79
|
-
label,
|
|
80
|
-
avatarUrl,
|
|
81
|
-
size = 'medium',
|
|
82
|
-
disabled,
|
|
83
|
-
maxTextLength,
|
|
84
|
-
suffix,
|
|
85
|
-
className,
|
|
86
|
-
enableProfile = true,
|
|
87
|
-
avatarFallback,
|
|
88
|
-
}) => {
|
|
89
|
-
const baseAvatarElement = renderPillAvatar({
|
|
90
|
-
avatarUrl,
|
|
91
|
-
label,
|
|
92
|
-
size,
|
|
93
|
-
avatarFallback,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const avatarWithPopover = React.useMemo(() => {
|
|
97
|
-
if (!enableProfile) {
|
|
98
|
-
return baseAvatarElement;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
102
|
-
e.stopPropagation();
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<Popover>
|
|
107
|
-
<PopoverTrigger asChild>
|
|
108
|
-
<button
|
|
109
|
-
type="button"
|
|
110
|
-
className={cn('cursor-pointer rounded-full')}
|
|
111
|
-
onClick={handleClick}
|
|
112
|
-
>
|
|
113
|
-
{baseAvatarElement}
|
|
114
|
-
</button>
|
|
115
|
-
</PopoverTrigger>
|
|
116
|
-
<PopoverContent
|
|
117
|
-
side="bottom"
|
|
118
|
-
align="start"
|
|
119
|
-
sideOffset={8}
|
|
120
|
-
className="w-80 p-0"
|
|
121
|
-
>
|
|
122
|
-
<UserProfile userId={userId} accountType={accountType} />
|
|
123
|
-
</PopoverContent>
|
|
124
|
-
</Popover>
|
|
125
|
-
);
|
|
126
|
-
}, [enableProfile, baseAvatarElement, userId, accountType]);
|
|
127
|
-
|
|
128
|
-
return (
|
|
129
|
-
<ItemPill
|
|
130
|
-
label={label}
|
|
131
|
-
avatar={avatarWithPopover}
|
|
132
|
-
className={className}
|
|
133
|
-
maxTextLength={maxTextLength}
|
|
134
|
-
suffix={suffix}
|
|
135
|
-
size={size}
|
|
136
|
-
disabled={disabled}
|
|
137
|
-
avatarFallback={avatarFallback}
|
|
138
|
-
/>
|
|
139
|
-
);
|
|
140
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { X } from 'lucide-react';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
tagCloseIconVariants,
|
|
7
|
-
type ComboboxSize,
|
|
8
|
-
} from '@client/src/components/business-ui/entity-combobox/size-variants';
|
|
9
|
-
import type {
|
|
10
|
-
AccountType,
|
|
11
|
-
UserSelectItemValue,
|
|
12
|
-
} from '@client/src/components/business-ui/user-select/types';
|
|
13
|
-
import { UserPill } from '@client/src/components/business-ui/user-select/user-pill';
|
|
14
|
-
import { Skeleton } from '@client/src/components/ui/skeleton';
|
|
15
|
-
|
|
16
|
-
export const UserSelectTag = ({
|
|
17
|
-
userValue,
|
|
18
|
-
onClose,
|
|
19
|
-
maxTextLength,
|
|
20
|
-
className,
|
|
21
|
-
size = 'medium',
|
|
22
|
-
disabled,
|
|
23
|
-
isLoading,
|
|
24
|
-
accountType = 'apaas',
|
|
25
|
-
}: {
|
|
26
|
-
userValue: UserSelectItemValue;
|
|
27
|
-
onClose: (value: UserSelectItemValue, e: React.MouseEvent) => void;
|
|
28
|
-
maxTextLength?: number;
|
|
29
|
-
className?: string;
|
|
30
|
-
size?: ComboboxSize;
|
|
31
|
-
disabled?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* 是否正在加载用户信息(ID 模式下查询中)
|
|
34
|
-
*/
|
|
35
|
-
isLoading?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* 账户类型,用于 UserProfile 展示
|
|
38
|
-
*/
|
|
39
|
-
accountType?: AccountType;
|
|
40
|
-
}) => {
|
|
41
|
-
const user = userValue.raw;
|
|
42
|
-
|
|
43
|
-
const handleClose = (e: React.MouseEvent) => {
|
|
44
|
-
e.stopPropagation();
|
|
45
|
-
onClose(userValue, e);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const closeButton = !disabled ? (
|
|
49
|
-
<button
|
|
50
|
-
type="button"
|
|
51
|
-
className="rounded-sm text-foreground opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none"
|
|
52
|
-
onClick={handleClose}
|
|
53
|
-
>
|
|
54
|
-
<X className={tagCloseIconVariants({ size })} />
|
|
55
|
-
<span className="sr-only">移除 {userValue.name}</span>
|
|
56
|
-
</button>
|
|
57
|
-
) : null;
|
|
58
|
-
|
|
59
|
-
// 加载中状态显示 Skeleton(不触发 UserProfile)
|
|
60
|
-
if (isLoading && !user) {
|
|
61
|
-
return (
|
|
62
|
-
<div className="inline-flex items-center gap-1 rounded-md bg-secondary px-1.5 py-0.5">
|
|
63
|
-
<Skeleton className="h-4 w-4 rounded-full" />
|
|
64
|
-
<Skeleton className="h-3 w-12" />
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<UserPill
|
|
71
|
-
userId={userValue.id}
|
|
72
|
-
accountType={accountType}
|
|
73
|
-
label={userValue.name}
|
|
74
|
-
avatarUrl={userValue.avatar || user?.avatar}
|
|
75
|
-
className={className}
|
|
76
|
-
maxTextLength={maxTextLength}
|
|
77
|
-
suffix={closeButton}
|
|
78
|
-
size={size}
|
|
79
|
-
disabled={disabled}
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
};
|
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import { toast } from 'sonner';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
searchUsers,
|
|
8
|
-
convertExternalContact,
|
|
9
|
-
type AccountType,
|
|
10
|
-
} from '@client/src/components/business-ui/api/users/service';
|
|
11
|
-
import { BaseCombobox } from '@client/src/components/business-ui/entity-combobox/base-combobox';
|
|
12
|
-
import { useEntityComboboxContext } from '@client/src/components/business-ui/entity-combobox/context';
|
|
13
|
-
import type {
|
|
14
|
-
UserSelectItemValue,
|
|
15
|
-
UserSelectProps,
|
|
16
|
-
} from '@client/src/components/business-ui/user-select/types';
|
|
17
|
-
import { useUserValue } from '@client/src/components/business-ui/user-select/use-user-value';
|
|
18
|
-
import { UserItem } from '@client/src/components/business-ui/user-select/user-item';
|
|
19
|
-
import { UserSelectTag } from '@client/src/components/business-ui/user-select/user-select-tag';
|
|
20
|
-
import {
|
|
21
|
-
searchUserInfoToUser,
|
|
22
|
-
isUnregisteredExternalContact,
|
|
23
|
-
} from '@client/src/components/business-ui/user-select/utils';
|
|
24
|
-
|
|
25
|
-
function createUsersFetcher(options: { accountType?: AccountType; pageSize?: number } = {}) {
|
|
26
|
-
const { accountType = 'apaas', pageSize = 100 } = options;
|
|
27
|
-
|
|
28
|
-
return async (search: string) => {
|
|
29
|
-
const response = await searchUsers({ query: search, pageSize });
|
|
30
|
-
const userList = response?.data?.userList || [];
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
items: userList.map((user) => searchUserInfoToUser(user, accountType)),
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 内部包装组件用于获取 context 中的 size
|
|
39
|
-
const UserItemWrapper = ({
|
|
40
|
-
userValue,
|
|
41
|
-
isSelected,
|
|
42
|
-
className,
|
|
43
|
-
disabled,
|
|
44
|
-
isConverting,
|
|
45
|
-
}: {
|
|
46
|
-
userValue: UserSelectItemValue;
|
|
47
|
-
isSelected: boolean;
|
|
48
|
-
className?: string;
|
|
49
|
-
disabled?: boolean;
|
|
50
|
-
isConverting?: boolean;
|
|
51
|
-
}) => {
|
|
52
|
-
const { size, searchValue } = useEntityComboboxContext();
|
|
53
|
-
return (
|
|
54
|
-
<UserItem
|
|
55
|
-
userValue={userValue}
|
|
56
|
-
isSelected={isSelected}
|
|
57
|
-
className={className}
|
|
58
|
-
size={size}
|
|
59
|
-
searchKeyword={searchValue}
|
|
60
|
-
disabled={disabled}
|
|
61
|
-
isConverting={isConverting}
|
|
62
|
-
/>
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const UserSelectTagWrapper = ({
|
|
67
|
-
userValue,
|
|
68
|
-
onClose,
|
|
69
|
-
className,
|
|
70
|
-
disabled,
|
|
71
|
-
isLoading,
|
|
72
|
-
accountType,
|
|
73
|
-
}: {
|
|
74
|
-
userValue: UserSelectItemValue;
|
|
75
|
-
onClose: (value: UserSelectItemValue, e: React.MouseEvent) => void;
|
|
76
|
-
className?: string;
|
|
77
|
-
disabled?: boolean;
|
|
78
|
-
isLoading?: boolean;
|
|
79
|
-
accountType?: 'apaas' | 'lark';
|
|
80
|
-
}) => {
|
|
81
|
-
const { size } = useEntityComboboxContext();
|
|
82
|
-
return (
|
|
83
|
-
<UserSelectTag
|
|
84
|
-
userValue={userValue}
|
|
85
|
-
onClose={onClose}
|
|
86
|
-
className={className}
|
|
87
|
-
size={size}
|
|
88
|
-
disabled={disabled}
|
|
89
|
-
isLoading={isLoading}
|
|
90
|
-
accountType={accountType}
|
|
91
|
-
/>
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const UserSelect: React.FC<UserSelectProps> = (props) => {
|
|
96
|
-
const {
|
|
97
|
-
size = 'medium',
|
|
98
|
-
triggerType = 'button',
|
|
99
|
-
renderTrigger,
|
|
100
|
-
multiple = false,
|
|
101
|
-
value,
|
|
102
|
-
valueType = 'string',
|
|
103
|
-
accountType = 'apaas',
|
|
104
|
-
defaultValue,
|
|
105
|
-
onChange,
|
|
106
|
-
defaultOpen,
|
|
107
|
-
disabled,
|
|
108
|
-
autoFocus,
|
|
109
|
-
required,
|
|
110
|
-
name,
|
|
111
|
-
className,
|
|
112
|
-
classNames,
|
|
113
|
-
placeholder = '请选择',
|
|
114
|
-
emptyText = '没有匹配结果,换个关键词试试吧',
|
|
115
|
-
tagClosable,
|
|
116
|
-
maxTagCount,
|
|
117
|
-
onSelect,
|
|
118
|
-
onDeselect,
|
|
119
|
-
onClear,
|
|
120
|
-
onFocus,
|
|
121
|
-
onBlur,
|
|
122
|
-
slotProps,
|
|
123
|
-
getOptionDisabled,
|
|
124
|
-
} = props;
|
|
125
|
-
|
|
126
|
-
// 使用 useUserValue 处理不同类型的 value(包括 defaultValue)
|
|
127
|
-
const { internalValue, isLoading, toExternalValue } = useUserValue(
|
|
128
|
-
value ?? null,
|
|
129
|
-
multiple,
|
|
130
|
-
accountType,
|
|
131
|
-
valueType,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
// 始终追踪最新 internalValue,避免异步开户回调中闭包捕获过期值
|
|
135
|
-
const internalValueRef = useRef(internalValue);
|
|
136
|
-
internalValueRef.current = internalValue;
|
|
137
|
-
|
|
138
|
-
// 同样处理 defaultValue,确保 ID 字符串类型的 defaultValue 也能正确解析
|
|
139
|
-
const { internalValue: internalDefaultValue } = useUserValue(
|
|
140
|
-
defaultValue ?? null,
|
|
141
|
-
multiple,
|
|
142
|
-
accountType,
|
|
143
|
-
valueType,
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const baseFetchFn = useMemo(() => createUsersFetcher({ accountType }), [accountType]);
|
|
147
|
-
|
|
148
|
-
// 正在开户中的用户 ID 集合
|
|
149
|
-
const [convertingSet, setConvertingSet] = useState<Set<string>>(() => new Set());
|
|
150
|
-
|
|
151
|
-
// 已开户用户映射:旧 ID → 转换后的 UserSelectItemValue,用于回写到待选列表
|
|
152
|
-
const [convertedMap, setConvertedMap] = useState<Map<string, UserSelectItemValue>>(
|
|
153
|
-
() => new Map(),
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
// 包装 fetchFn,将已开户用户替换到搜索结果中
|
|
157
|
-
// convertedMap 变化 → fetchFn 引用变化 → useFetchData 自动 refetch
|
|
158
|
-
const fetchFn = useCallback(
|
|
159
|
-
async (search: string) => {
|
|
160
|
-
const result = await baseFetchFn(search);
|
|
161
|
-
if (convertedMap.size === 0) return result;
|
|
162
|
-
return {
|
|
163
|
-
...result,
|
|
164
|
-
items: result.items.map((item) => convertedMap.get(item.id) ?? item),
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
[baseFetchFn, convertedMap],
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
// 标记是否有即将开户的用户(用于在 handleOpenChange 中阻止关闭)
|
|
171
|
-
// 时序:handleChange(设置标记)→ handleOpenChange(检查标记)→ handleSelect(开始开户)
|
|
172
|
-
const pendingConvertRef = useRef(false);
|
|
173
|
-
|
|
174
|
-
// 受控 open 状态:开户期间阻止 popover 关闭
|
|
175
|
-
const [open, setOpen] = useState(defaultOpen ?? false);
|
|
176
|
-
const handleOpenChange = useCallback((nextOpen: boolean) => {
|
|
177
|
-
// 有正在开户或即将开户的用户时,不允许关闭下拉
|
|
178
|
-
if (!nextOpen && pendingConvertRef.current) return;
|
|
179
|
-
setOpen(nextOpen);
|
|
180
|
-
}, []);
|
|
181
|
-
|
|
182
|
-
// 开户中的用户禁止再次点击
|
|
183
|
-
const mergedGetOptionDisabled = useCallback(
|
|
184
|
-
(option: UserSelectItemValue) => {
|
|
185
|
-
if (convertingSet.has(option.id)) return true;
|
|
186
|
-
if (isUnregisteredExternalContact(option)) return false;
|
|
187
|
-
return getOptionDisabled?.(option) ?? false;
|
|
188
|
-
},
|
|
189
|
-
[getOptionDisabled, convertingSet],
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* onChange 门卫:过滤掉未注册外部联系人,不允许未开户用户进入选中列表。
|
|
194
|
-
* 同时设置 pendingConvertRef 标记,阻止 handleOpenChange 关闭下拉。
|
|
195
|
-
*/
|
|
196
|
-
const handleChange = useCallback(
|
|
197
|
-
(newValue: UserSelectItemValue | UserSelectItemValue[] | null) => {
|
|
198
|
-
if (!onChange) return;
|
|
199
|
-
|
|
200
|
-
if (multiple && Array.isArray(newValue)) {
|
|
201
|
-
const hasUnregistered = newValue.some((u) => isUnregisteredExternalContact(u));
|
|
202
|
-
if (hasUnregistered) {
|
|
203
|
-
pendingConvertRef.current = true;
|
|
204
|
-
}
|
|
205
|
-
const filtered = newValue.filter((u) => !isUnregisteredExternalContact(u));
|
|
206
|
-
const externalValue = toExternalValue(filtered, multiple);
|
|
207
|
-
(onChange as (value: unknown) => void)(externalValue);
|
|
208
|
-
} else if (!multiple) {
|
|
209
|
-
const user = newValue as UserSelectItemValue | null;
|
|
210
|
-
if (user && isUnregisteredExternalContact(user)) {
|
|
211
|
-
// 不允许未注册用户进入选中值,标记即将开户
|
|
212
|
-
pendingConvertRef.current = true;
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const externalValue = toExternalValue(newValue, multiple);
|
|
216
|
-
(onChange as (value: unknown) => void)(externalValue);
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
[onChange, multiple, toExternalValue],
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* onSelect 拦截:检测未注册外部联系人,触发开户流程。
|
|
224
|
-
* 开户成功后手动调用 onChange 回填转换后的用户。
|
|
225
|
-
*/
|
|
226
|
-
const handleSelect = useCallback(
|
|
227
|
-
(user: UserSelectItemValue) => {
|
|
228
|
-
if (!isUnregisteredExternalContact(user)) {
|
|
229
|
-
onSelect?.(user);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const larkUserID = user.raw?.larkUserId;
|
|
234
|
-
if (!larkUserID) return;
|
|
235
|
-
if (convertingSet.has(user.id)) return;
|
|
236
|
-
|
|
237
|
-
setConvertingSet((prev) => new Set(prev).add(user.id));
|
|
238
|
-
// pendingConvertRef 已在 handleChange 中设置,此处转为正式开户状态
|
|
239
|
-
|
|
240
|
-
void (async () => {
|
|
241
|
-
try {
|
|
242
|
-
const result = await convertExternalContact(larkUserID);
|
|
243
|
-
const { userInfo } = result.data;
|
|
244
|
-
const forceUserID = String(userInfo.userID);
|
|
245
|
-
const convertedUser: UserSelectItemValue = {
|
|
246
|
-
...user,
|
|
247
|
-
id: forceUserID,
|
|
248
|
-
raw: user.raw ? { ...user.raw, user_id: forceUserID } : undefined,
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// 回写到待选列表:触发 fetchFn 引用变化 → useFetchData refetch → 列表更新
|
|
252
|
-
setConvertedMap((prev) => new Map(prev).set(user.id, convertedUser));
|
|
253
|
-
|
|
254
|
-
onSelect?.(convertedUser);
|
|
255
|
-
if (onChange) {
|
|
256
|
-
if (multiple) {
|
|
257
|
-
const current = Array.isArray(internalValueRef.current)
|
|
258
|
-
? internalValueRef.current
|
|
259
|
-
: [];
|
|
260
|
-
const externalValue = toExternalValue([...current, convertedUser], multiple);
|
|
261
|
-
(onChange as (value: unknown) => void)(externalValue);
|
|
262
|
-
} else {
|
|
263
|
-
const externalValue = toExternalValue(convertedUser, multiple);
|
|
264
|
-
(onChange as (value: unknown) => void)(externalValue);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
// 开户成功后关闭下拉(单选)
|
|
268
|
-
if (!multiple) {
|
|
269
|
-
pendingConvertRef.current = false;
|
|
270
|
-
setOpen(false);
|
|
271
|
-
}
|
|
272
|
-
} catch {
|
|
273
|
-
toast.error('外部用户添加失败');
|
|
274
|
-
} finally {
|
|
275
|
-
setConvertingSet((prev) => {
|
|
276
|
-
const next = new Set(prev);
|
|
277
|
-
next.delete(user.id);
|
|
278
|
-
// 所有开户完成后清除标记
|
|
279
|
-
if (next.size === 0) {
|
|
280
|
-
pendingConvertRef.current = false;
|
|
281
|
-
}
|
|
282
|
-
return next;
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
})();
|
|
286
|
-
},
|
|
287
|
-
[onSelect, onChange, multiple, toExternalValue, convertingSet],
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
const renderTagWithLoading = useCallback(
|
|
291
|
-
(
|
|
292
|
-
userValue: UserSelectItemValue,
|
|
293
|
-
onClose: (value: UserSelectItemValue, e: React.MouseEvent) => void,
|
|
294
|
-
tagDisabled?: boolean,
|
|
295
|
-
) => (
|
|
296
|
-
<UserSelectTagWrapper
|
|
297
|
-
key={userValue.id}
|
|
298
|
-
userValue={userValue}
|
|
299
|
-
onClose={onClose}
|
|
300
|
-
disabled={tagDisabled}
|
|
301
|
-
isLoading={isLoading}
|
|
302
|
-
accountType={accountType}
|
|
303
|
-
/>
|
|
304
|
-
),
|
|
305
|
-
[isLoading, accountType],
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
return (
|
|
309
|
-
<BaseCombobox
|
|
310
|
-
autoFocus={autoFocus}
|
|
311
|
-
className={className}
|
|
312
|
-
classNames={classNames}
|
|
313
|
-
debounce={300}
|
|
314
|
-
open={open}
|
|
315
|
-
onOpenChange={handleOpenChange}
|
|
316
|
-
defaultValue={internalDefaultValue}
|
|
317
|
-
disabled={disabled}
|
|
318
|
-
emptyText={emptyText}
|
|
319
|
-
fetchFn={fetchFn}
|
|
320
|
-
getItemLabel={(userValue) => userValue.name}
|
|
321
|
-
getItemValue={(userValue) => userValue}
|
|
322
|
-
getOptionDisabled={mergedGetOptionDisabled}
|
|
323
|
-
maxTagCount={maxTagCount}
|
|
324
|
-
multiple={multiple}
|
|
325
|
-
name={name}
|
|
326
|
-
onBlur={onBlur}
|
|
327
|
-
onChange={handleChange}
|
|
328
|
-
onClear={onClear}
|
|
329
|
-
onDeselect={onDeselect}
|
|
330
|
-
onFocus={onFocus}
|
|
331
|
-
onSelect={handleSelect}
|
|
332
|
-
placeholder={placeholder}
|
|
333
|
-
renderItem={(userValue, isSelected, itemClassName, itemDisabled) => (
|
|
334
|
-
<UserItemWrapper
|
|
335
|
-
key={userValue.id}
|
|
336
|
-
userValue={userValue}
|
|
337
|
-
isSelected={isSelected}
|
|
338
|
-
className={itemClassName}
|
|
339
|
-
disabled={itemDisabled}
|
|
340
|
-
isConverting={convertingSet.has(userValue.id)}
|
|
341
|
-
/>
|
|
342
|
-
)}
|
|
343
|
-
renderTag={renderTagWithLoading}
|
|
344
|
-
renderTrigger={renderTrigger}
|
|
345
|
-
required={required}
|
|
346
|
-
searchPlaceholder=""
|
|
347
|
-
showSearch
|
|
348
|
-
size={size}
|
|
349
|
-
slotProps={slotProps}
|
|
350
|
-
tagClosable={tagClosable}
|
|
351
|
-
triggerType={triggerType}
|
|
352
|
-
value={internalValue}
|
|
353
|
-
/>
|
|
354
|
-
);
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
export { type UserSelectItemValue as UserValue };
|
|
358
|
-
|
|
359
|
-
export { ItemPill } from '@client/src/components/business-ui/entity-combobox/item-pill';
|