@lark-apaas/coding-template-nestjs-react-fullstack 0.1.0-alpha.1
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 +13 -0
- package/README.md +41 -0
- package/hooks/after-install.mjs +3 -0
- package/hooks/after-render.mjs +3 -0
- package/hooks/before-render.mjs +3 -0
- package/package.json +36 -0
- package/template/.codebase/pipelines/ci.yaml +34 -0
- package/template/.codebase/pipelines/coco-code-review.yaml +21 -0
- package/template/.prettierrc +8 -0
- package/template/.spark_project +16 -0
- package/template/.stylelintrc.js +12 -0
- package/template/_env.local +38 -0
- package/template/_gitignore +64 -0
- package/template/_npmrc +1 -0
- package/template/client/index.html +23 -0
- package/template/client/public/favicon.svg +40 -0
- package/template/client/src/api/index.ts +19 -0
- package/template/client/src/app.tsx +22 -0
- package/template/client/src/components/Layout.tsx +11 -0
- package/template/client/src/components/business-ui/README.md +519 -0
- package/template/client/src/components/business-ui/api/chats/queries.ts +39 -0
- package/template/client/src/components/business-ui/api/chats/service.ts +29 -0
- package/template/client/src/components/business-ui/api/departments/queries.ts +42 -0
- package/template/client/src/components/business-ui/api/departments/service.ts +18 -0
- package/template/client/src/components/business-ui/api/files/service.ts +28 -0
- package/template/client/src/components/business-ui/api/user-profiles/queries.ts +42 -0
- package/template/client/src/components/business-ui/api/user-profiles/service.ts +23 -0
- package/template/client/src/components/business-ui/api/users/queries.ts +34 -0
- package/template/client/src/components/business-ui/api/users/service.ts +40 -0
- package/template/client/src/components/business-ui/chat-select/README.md +128 -0
- package/template/client/src/components/business-ui/chat-select/chat-item.tsx +85 -0
- package/template/client/src/components/business-ui/chat-select/chat-select-tag.tsx +83 -0
- package/template/client/src/components/business-ui/chat-select/chat-select.tsx +197 -0
- package/template/client/src/components/business-ui/chat-select/index.tsx +12 -0
- package/template/client/src/components/business-ui/chat-select/types.ts +102 -0
- package/template/client/src/components/business-ui/chat-select/use-chat-value.ts +180 -0
- package/template/client/src/components/business-ui/chat-select/utils.ts +81 -0
- package/template/client/src/components/business-ui/department-select/department-item.tsx +55 -0
- package/template/client/src/components/business-ui/department-select/department-select-field.tsx +86 -0
- package/template/client/src/components/business-ui/department-select/department-select-tag.tsx +56 -0
- package/template/client/src/components/business-ui/department-select/department-select.tsx +168 -0
- package/template/client/src/components/business-ui/department-select/icon-department.tsx +22 -0
- package/template/client/src/components/business-ui/department-select/index.tsx +7 -0
- package/template/client/src/components/business-ui/department-select/types.ts +15 -0
- package/template/client/src/components/business-ui/department-select/utils.ts +17 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-content.tsx +35 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-empty.tsx +28 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-error.tsx +35 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-item.tsx +55 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-list.tsx +174 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-loading.tsx +19 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-search.tsx +31 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox-trigger.tsx +281 -0
- package/template/client/src/components/business-ui/entity-combobox/base-combobox.tsx +132 -0
- package/template/client/src/components/business-ui/entity-combobox/context.tsx +19 -0
- package/template/client/src/components/business-ui/entity-combobox/entity-combobox.tsx +145 -0
- package/template/client/src/components/business-ui/entity-combobox/highlight-text.tsx +52 -0
- package/template/client/src/components/business-ui/entity-combobox/hooks.tsx +21 -0
- package/template/client/src/components/business-ui/entity-combobox/index.tsx +31 -0
- package/template/client/src/components/business-ui/entity-combobox/item-pill.tsx +179 -0
- package/template/client/src/components/business-ui/entity-combobox/popover-wrapper.tsx +149 -0
- package/template/client/src/components/business-ui/entity-combobox/search-trigger.tsx +262 -0
- package/template/client/src/components/business-ui/entity-combobox/shared-types.ts +296 -0
- package/template/client/src/components/business-ui/entity-combobox/size-variants.tsx +322 -0
- package/template/client/src/components/business-ui/entity-combobox/types.ts +246 -0
- package/template/client/src/components/business-ui/entity-combobox/use-fetch-data.tsx +81 -0
- package/template/client/src/components/business-ui/entity-combobox/use-infinite-scroll.tsx +99 -0
- package/template/client/src/components/business-ui/entity-combobox/use-popover-outside-click.tsx +32 -0
- package/template/client/src/components/business-ui/form/checkbox-field.tsx +83 -0
- package/template/client/src/components/business-ui/form/context.tsx +38 -0
- package/template/client/src/components/business-ui/form/field-layout.tsx +91 -0
- package/template/client/src/components/business-ui/form/form.tsx +54 -0
- package/template/client/src/components/business-ui/form/hooks/form-context.tsx +4 -0
- package/template/client/src/components/business-ui/form/hooks/form-utils.ts +23 -0
- package/template/client/src/components/business-ui/form/hooks/form.tsx +40 -0
- package/template/client/src/components/business-ui/form/index.tsx +4 -0
- package/template/client/src/components/business-ui/form/input-field.tsx +74 -0
- package/template/client/src/components/business-ui/form/radio-group-field.tsx +138 -0
- package/template/client/src/components/business-ui/form/select-field.tsx +155 -0
- package/template/client/src/components/business-ui/form/switch-field.tsx +66 -0
- package/template/client/src/components/business-ui/form/textarea-field.tsx +72 -0
- package/template/client/src/components/business-ui/form/types.ts +32 -0
- package/template/client/src/components/business-ui/tiptap-editor/README.md +324 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/attachment-toolbar-button.tsx +74 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/blockquote-toolbar-button.tsx +41 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/code-block-toolbar-button.tsx +41 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/color-highlight-toolbar-button.tsx +141 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/heading-toolbar-button.tsx +99 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/horizontal-rule-toolbar-button.tsx +39 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/image-upload-toolbar-button.tsx +65 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/link-edit-form.tsx +127 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/link-hover-toolbar.tsx +380 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/link-toolbar-button.tsx +96 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/list-toolbar-button.tsx +75 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/mark-toolbar-button.tsx +118 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/text-align-toolbar-button.tsx +84 -0
- package/template/client/src/components/business-ui/tiptap-editor/components/undo-redo-toolbar-button.tsx +54 -0
- package/template/client/src/components/business-ui/tiptap-editor/extensions/attachment.tsx +539 -0
- package/template/client/src/components/business-ui/tiptap-editor/extensions/code-block-shiki.tsx +236 -0
- package/template/client/src/components/business-ui/tiptap-editor/extensions/complete-kit.ts +260 -0
- package/template/client/src/components/business-ui/tiptap-editor/extensions/image.tsx +456 -0
- package/template/client/src/components/business-ui/tiptap-editor/hooks/use-tiptap-editor.ts +47 -0
- package/template/client/src/components/business-ui/tiptap-editor/index.ts +38 -0
- package/template/client/src/components/business-ui/tiptap-editor/tiptap-editor-complete.tsx +112 -0
- package/template/client/src/components/business-ui/tiptap-editor/tiptap-editor.tsx +169 -0
- package/template/client/src/components/business-ui/types/user.ts +74 -0
- package/template/client/src/components/business-ui/user-display/index.tsx +2 -0
- package/template/client/src/components/business-ui/user-display/overflow-tooltip-text.tsx +90 -0
- package/template/client/src/components/business-ui/user-display/type.ts +27 -0
- package/template/client/src/components/business-ui/user-display/user-display.tsx +99 -0
- package/template/client/src/components/business-ui/user-display/user-with-avatar.tsx +158 -0
- package/template/client/src/components/business-ui/user-display/utils.ts +37 -0
- package/template/client/src/components/business-ui/user-profile/error-image.tsx +302 -0
- package/template/client/src/components/business-ui/user-profile/user-external-script.ts +73 -0
- package/template/client/src/components/business-ui/user-profile/user-profile.tsx +370 -0
- package/template/client/src/components/business-ui/user-select/index.tsx +28 -0
- package/template/client/src/components/business-ui/user-select/types.ts +109 -0
- package/template/client/src/components/business-ui/user-select/use-user-value.ts +160 -0
- package/template/client/src/components/business-ui/user-select/user-item.tsx +98 -0
- package/template/client/src/components/business-ui/user-select/user-pill.tsx +140 -0
- package/template/client/src/components/business-ui/user-select/user-select-tag.tsx +82 -0
- package/template/client/src/components/business-ui/user-select/user-select.tsx +359 -0
- package/template/client/src/components/business-ui/user-select/utils.tsx +188 -0
- package/template/client/src/components/business-ui/utils/user.ts +72 -0
- package/template/client/src/components/ui/README.md +134 -0
- package/template/client/src/components/ui/accordion.tsx +66 -0
- package/template/client/src/components/ui/alert-dialog.tsx +157 -0
- package/template/client/src/components/ui/alert.tsx +71 -0
- package/template/client/src/components/ui/aspect-ratio.tsx +11 -0
- package/template/client/src/components/ui/avatar.tsx +53 -0
- package/template/client/src/components/ui/badge.tsx +42 -0
- package/template/client/src/components/ui/breadcrumb.tsx +109 -0
- package/template/client/src/components/ui/button-group.tsx +83 -0
- package/template/client/src/components/ui/button.tsx +69 -0
- package/template/client/src/components/ui/calendar.tsx +213 -0
- package/template/client/src/components/ui/card.tsx +82 -0
- package/template/client/src/components/ui/carousel.tsx +241 -0
- package/template/client/src/components/ui/chart.tsx +357 -0
- package/template/client/src/components/ui/checkbox.tsx +32 -0
- package/template/client/src/components/ui/collapsible.tsx +33 -0
- package/template/client/src/components/ui/command.tsx +208 -0
- package/template/client/src/components/ui/context-menu.tsx +324 -0
- package/template/client/src/components/ui/dialog.tsx +143 -0
- package/template/client/src/components/ui/drawer.tsx +135 -0
- package/template/client/src/components/ui/dropdown-menu.tsx +329 -0
- package/template/client/src/components/ui/empty.tsx +104 -0
- package/template/client/src/components/ui/field.tsx +248 -0
- package/template/client/src/components/ui/form.tsx +167 -0
- package/template/client/src/components/ui/hover-card.tsx +44 -0
- package/template/client/src/components/ui/icons/file-ae-colorful-icon.tsx +21 -0
- package/template/client/src/components/ui/icons/file-ai-colorful-icon.tsx +36 -0
- package/template/client/src/components/ui/icons/file-android-colorful-icon.tsx +33 -0
- package/template/client/src/components/ui/icons/file-audio-colorful-icon.tsx +21 -0
- package/template/client/src/components/ui/icons/file-code-colorful-icon.tsx +28 -0
- package/template/client/src/components/ui/icons/file-csv-colorful-icon.tsx +21 -0
- package/template/client/src/components/ui/icons/file-eml-colorful-icon.tsx +29 -0
- package/template/client/src/components/ui/icons/file-ios-colorful-icon.tsx +25 -0
- package/template/client/src/components/ui/icons/file-keynote-colorful-icon.tsx +29 -0
- package/template/client/src/components/ui/icons/file-pages-colorful-icon.tsx +29 -0
- package/template/client/src/components/ui/icons/file-ps-colorful-icon.tsx +21 -0
- package/template/client/src/components/ui/icons/file-sketch-colorful-icon.tsx +21 -0
- package/template/client/src/components/ui/icons/file-slide-colorful-icon.tsx +21 -0
- package/template/client/src/components/ui/icons/file-vcf-colorful-icon.tsx +29 -0
- package/template/client/src/components/ui/icons/file-wiki-excel-colorful-icon.tsx +23 -0
- package/template/client/src/components/ui/icons/file-wiki-image-colorful-icon.tsx +27 -0
- package/template/client/src/components/ui/icons/file-wiki-pdf-colorful-icon.tsx +20 -0
- package/template/client/src/components/ui/icons/file-wiki-ppt-colorful-icon.tsx +21 -0
- package/template/client/src/components/ui/icons/file-wiki-text-colorful-icon.tsx +12 -0
- package/template/client/src/components/ui/icons/file-wiki-unknown-colorful-icon.tsx +14 -0
- package/template/client/src/components/ui/icons/file-wiki-video-colorful-icon.tsx +23 -0
- package/template/client/src/components/ui/icons/file-wiki-word-colorful-icon.tsx +38 -0
- package/template/client/src/components/ui/icons/file-wiki-zip-colorful-icon.tsx +21 -0
- package/template/client/src/components/ui/image.tsx +183 -0
- package/template/client/src/components/ui/input-group.tsx +166 -0
- package/template/client/src/components/ui/input-otp.tsx +77 -0
- package/template/client/src/components/ui/input.tsx +21 -0
- package/template/client/src/components/ui/item.tsx +193 -0
- package/template/client/src/components/ui/kbd.tsx +28 -0
- package/template/client/src/components/ui/label.tsx +24 -0
- package/template/client/src/components/ui/menubar.tsx +348 -0
- package/template/client/src/components/ui/native-select.tsx +48 -0
- package/template/client/src/components/ui/navigation-menu.tsx +168 -0
- package/template/client/src/components/ui/pagination.tsx +127 -0
- package/template/client/src/components/ui/popover.tsx +48 -0
- package/template/client/src/components/ui/progress.tsx +31 -0
- package/template/client/src/components/ui/radio-group.tsx +45 -0
- package/template/client/src/components/ui/resizable.tsx +56 -0
- package/template/client/src/components/ui/scroll-area.tsx +58 -0
- package/template/client/src/components/ui/select.tsx +243 -0
- package/template/client/src/components/ui/separator.tsx +28 -0
- package/template/client/src/components/ui/sheet.tsx +139 -0
- package/template/client/src/components/ui/sidebar.tsx +727 -0
- package/template/client/src/components/ui/skeleton.tsx +13 -0
- package/template/client/src/components/ui/slider.tsx +87 -0
- package/template/client/src/components/ui/sonner.tsx +67 -0
- package/template/client/src/components/ui/spinner.tsx +16 -0
- package/template/client/src/components/ui/streamdown.tsx +186 -0
- package/template/client/src/components/ui/switch.tsx +31 -0
- package/template/client/src/components/ui/table.tsx +116 -0
- package/template/client/src/components/ui/tabs.tsx +66 -0
- package/template/client/src/components/ui/textarea.tsx +18 -0
- package/template/client/src/components/ui/toggle-group.tsx +83 -0
- package/template/client/src/components/ui/toggle.tsx +47 -0
- package/template/client/src/components/ui/tooltip.tsx +61 -0
- package/template/client/src/hooks/use-example.ts +52 -0
- package/template/client/src/hooks/use-mobile.ts +19 -0
- package/template/client/src/index.css +7 -0
- package/template/client/src/index.tsx +36 -0
- package/template/client/src/lib/shiki.ts +92 -0
- package/template/client/src/lib/utils.ts +6 -0
- package/template/client/src/pages/ExamplePage/ExamplePage.tsx +37 -0
- package/template/client/src/pages/NotFound/NotFound.tsx +11 -0
- package/template/client/src/tailwind-theme.css +257 -0
- package/template/client/src/types/common.ts +34 -0
- package/template/client/src/types/global.d.ts +53 -0
- package/template/client/src/types/index.ts +4 -0
- package/template/client/src/typography.css +41 -0
- package/template/client/src/utils/img-resources/avatar-placeholders.ts +12 -0
- package/template/client/src/utils/img-resources/banner-placeholders.ts +29 -0
- package/template/client/src/utils/img-resources/cover-placeholders.ts +47 -0
- package/template/components.json +21 -0
- package/template/eslint.config.js +50 -0
- package/template/nest-cli.json +25 -0
- package/template/package-lock.json +29195 -0
- package/template/package.json +202 -0
- package/template/postcss.config.js +10 -0
- package/template/scripts/build.sh +120 -0
- package/template/scripts/dev.js +295 -0
- package/template/scripts/dev.sh +2 -0
- package/template/scripts/lint.js +150 -0
- package/template/scripts/prune-smart.js +281 -0
- package/template/scripts/run.sh +5 -0
- package/template/server/app.module.ts +27 -0
- package/template/server/common/constants/api_response_code.ts +54 -0
- package/template/server/common/filters/exception.filter.ts +78 -0
- package/template/server/common/interfaces/api_response.interface.ts +21 -0
- package/template/server/common/interfaces/exception.interface.ts +19 -0
- package/template/server/database/schema.ts +90 -0
- package/template/server/main.ts +31 -0
- package/template/server/modules/hello/hello.controller.ts +16 -0
- package/template/server/modules/hello/hello.module.ts +10 -0
- package/template/server/modules/hello/hello.service.ts +28 -0
- package/template/server/modules/view/view.controller.ts +17 -0
- package/template/server/modules/view/view.module.ts +8 -0
- package/template/shared/api.interface.ts +1 -0
- package/template/tailwind.config.ts +9 -0
- package/template/tsconfig.app.json +23 -0
- package/template/tsconfig.json +8 -0
- package/template/tsconfig.node.json +16 -0
- package/template/vite.config.ts +10 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseEntitySelectProps,
|
|
3
|
+
ItemValue,
|
|
4
|
+
} from '@client/src/components/business-ui/entity-combobox/shared-types';
|
|
5
|
+
import type { I18nText } from '@client/src/components/business-ui/entity-combobox/types';
|
|
6
|
+
|
|
7
|
+
export type { I18nText };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 群组原始信息(对应 SearchChatEntity)
|
|
11
|
+
*/
|
|
12
|
+
export type ChatInfo = {
|
|
13
|
+
/** 群组 ID */
|
|
14
|
+
chatID: string;
|
|
15
|
+
/** 群组名称(国际化文本) */
|
|
16
|
+
name: I18nText;
|
|
17
|
+
/** 头像:URL 或 16 进制 RGB 颜色 */
|
|
18
|
+
avatar: string;
|
|
19
|
+
/** 是否是外部群 */
|
|
20
|
+
isExternal?: boolean;
|
|
21
|
+
/** 群成员数量(不包括机器人) */
|
|
22
|
+
userCount?: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 标准化后的群组数据(用于 BaseCombobox)
|
|
27
|
+
*/
|
|
28
|
+
export type Chat = ItemValue<ChatInfo>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 值类型
|
|
32
|
+
* - 'string': value 为 chatID 字符串
|
|
33
|
+
* - 'object': value 为 Chat 对象
|
|
34
|
+
* @default 'string'
|
|
35
|
+
*/
|
|
36
|
+
export type ValueType = 'string' | 'object';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 根据 valueType 和 multiple 推断 value 类型
|
|
40
|
+
*/
|
|
41
|
+
export type InferValue<
|
|
42
|
+
V extends ValueType,
|
|
43
|
+
M extends boolean,
|
|
44
|
+
> = V extends 'string'
|
|
45
|
+
? M extends true
|
|
46
|
+
? string[]
|
|
47
|
+
: string | null
|
|
48
|
+
: M extends true
|
|
49
|
+
? Chat[]
|
|
50
|
+
: Chat | null;
|
|
51
|
+
|
|
52
|
+
type ChatSelectBaseProps<
|
|
53
|
+
V extends ValueType = 'string',
|
|
54
|
+
M extends boolean = false,
|
|
55
|
+
> = Omit<
|
|
56
|
+
BaseEntitySelectProps<Chat>,
|
|
57
|
+
'value' | 'defaultValue' | 'onChange'
|
|
58
|
+
> & {
|
|
59
|
+
/**
|
|
60
|
+
* 值类型
|
|
61
|
+
* - 'string': value 为 chatID 字符串
|
|
62
|
+
* - 'object': value 为 Chat 对象
|
|
63
|
+
* @default 'string'
|
|
64
|
+
*/
|
|
65
|
+
valueType?: V;
|
|
66
|
+
/**
|
|
67
|
+
* 是否多选
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
multiple?: M;
|
|
71
|
+
/**
|
|
72
|
+
* 当前值
|
|
73
|
+
*/
|
|
74
|
+
value?: InferValue<V, M>;
|
|
75
|
+
/**
|
|
76
|
+
* 默认值
|
|
77
|
+
*/
|
|
78
|
+
defaultValue?: InferValue<V, M>;
|
|
79
|
+
/**
|
|
80
|
+
* 值变化回调
|
|
81
|
+
*/
|
|
82
|
+
onChange?: (value: InferValue<V, M>) => void;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* ChatSelect 组件 Props
|
|
87
|
+
*
|
|
88
|
+
* 类型组合:
|
|
89
|
+
* | valueType | multiple | value 类型 |
|
|
90
|
+
* |-----------|----------|------------|
|
|
91
|
+
* | 'string' | false | string \| null |
|
|
92
|
+
* | 'string' | true | string[] |
|
|
93
|
+
* | 'object' | false | Chat \| null |
|
|
94
|
+
* | 'object' | true | Chat[] |
|
|
95
|
+
*/
|
|
96
|
+
export type ChatSelectProps =
|
|
97
|
+
| ChatSelectBaseProps<'string', false>
|
|
98
|
+
| ChatSelectBaseProps<'string', true>
|
|
99
|
+
| ChatSelectBaseProps<'object', false>
|
|
100
|
+
| ChatSelectBaseProps<'object', true>;
|
|
101
|
+
|
|
102
|
+
export type ChatSelectValue = Chat | Chat[] | string | string[] | null;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { listChatsByIds } from '@client/src/components/business-ui/api/chats/service';
|
|
6
|
+
import type {
|
|
7
|
+
Chat,
|
|
8
|
+
ChatSelectValue,
|
|
9
|
+
ValueType,
|
|
10
|
+
} from '@client/src/components/business-ui/chat-select/types';
|
|
11
|
+
import {
|
|
12
|
+
chatInfoToChat,
|
|
13
|
+
createUnknownChat,
|
|
14
|
+
extractIdsFromValue,
|
|
15
|
+
} from '@client/src/components/business-ui/chat-select/utils';
|
|
16
|
+
|
|
17
|
+
export type UseChatValueResult = {
|
|
18
|
+
/**
|
|
19
|
+
* 标准化后的内部 value(Chat 对象格式)
|
|
20
|
+
* 用于传递给 BaseCombobox
|
|
21
|
+
*/
|
|
22
|
+
internalValue: Chat | Chat[] | null;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 是否正在加载群组信息
|
|
26
|
+
*/
|
|
27
|
+
isLoading: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 将内部 Chat 对象转换回外部格式
|
|
31
|
+
* ID 模式时返回字符串,对象模式时返回 Chat
|
|
32
|
+
*/
|
|
33
|
+
toExternalValue: (
|
|
34
|
+
internalVal: Chat | Chat[] | null,
|
|
35
|
+
multiple: boolean,
|
|
36
|
+
) => ChatSelectValue;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 处理 ChatSelect 的 value 类型转换
|
|
41
|
+
*
|
|
42
|
+
* - 根据 valueType 决定 value 是 chatID 字符串还是 Chat 对象
|
|
43
|
+
* - ID 模式下调用搜索 API 获取完整群组信息
|
|
44
|
+
* - 无效 ID 生成 "未知群组" 占位
|
|
45
|
+
*
|
|
46
|
+
* @param value - 外部传入的 value
|
|
47
|
+
* @param multiple - 是否多选模式
|
|
48
|
+
* @param valueType - 值类型,'string' 表示 ID 模式,'object' 表示 Chat 对象模式
|
|
49
|
+
*/
|
|
50
|
+
export function useChatValue(
|
|
51
|
+
value: ChatSelectValue,
|
|
52
|
+
multiple: boolean = false,
|
|
53
|
+
valueType: ValueType = 'string',
|
|
54
|
+
): UseChatValueResult {
|
|
55
|
+
const isIdMode = valueType === 'string';
|
|
56
|
+
|
|
57
|
+
const [resolvedChats, setResolvedChats] = useState<Map<string, Chat>>(
|
|
58
|
+
new Map(),
|
|
59
|
+
);
|
|
60
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
61
|
+
|
|
62
|
+
const currentIds = useMemo(() => extractIdsFromValue(value), [value]);
|
|
63
|
+
|
|
64
|
+
const missingIds = useMemo(() => {
|
|
65
|
+
if (!isIdMode) return [];
|
|
66
|
+
return currentIds.filter((id) => !resolvedChats.has(String(id)));
|
|
67
|
+
}, [isIdMode, currentIds, resolvedChats]);
|
|
68
|
+
|
|
69
|
+
// 稳定化 missingIds 引用
|
|
70
|
+
const missingIdsKey = missingIds.join(',');
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!missingIdsKey) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const ids = missingIdsKey.split(',');
|
|
78
|
+
let cancelled = false;
|
|
79
|
+
|
|
80
|
+
const fetchData = async () => {
|
|
81
|
+
setIsLoading(true);
|
|
82
|
+
try {
|
|
83
|
+
const response = await listChatsByIds(ids);
|
|
84
|
+
if (cancelled) return;
|
|
85
|
+
|
|
86
|
+
const chatInfoMap = response?.data?.chatInfoMap || {};
|
|
87
|
+
setResolvedChats((prev) => {
|
|
88
|
+
const next = new Map(prev);
|
|
89
|
+
for (const [chatId, chatInfo] of Object.entries(chatInfoMap)) {
|
|
90
|
+
const chat = chatInfoToChat(chatInfo);
|
|
91
|
+
next.set(String(chatId), chat);
|
|
92
|
+
}
|
|
93
|
+
// 标记未找到的 ID 为未知群组
|
|
94
|
+
for (const id of ids) {
|
|
95
|
+
if (!next.has(String(id))) {
|
|
96
|
+
next.set(String(id), createUnknownChat(id));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return next;
|
|
100
|
+
});
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error('Failed to resolve chat IDs:', error);
|
|
103
|
+
if (!cancelled) {
|
|
104
|
+
setResolvedChats((prev) => {
|
|
105
|
+
const next = new Map(prev);
|
|
106
|
+
for (const id of ids) {
|
|
107
|
+
if (!next.has(String(id))) {
|
|
108
|
+
next.set(String(id), createUnknownChat(id));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return next;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
} finally {
|
|
115
|
+
if (!cancelled) {
|
|
116
|
+
setIsLoading(false);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
fetchData();
|
|
122
|
+
|
|
123
|
+
return () => {
|
|
124
|
+
cancelled = true;
|
|
125
|
+
};
|
|
126
|
+
}, [missingIdsKey]);
|
|
127
|
+
|
|
128
|
+
const internalValue = useMemo((): Chat | Chat[] | null => {
|
|
129
|
+
if (value === null || value === undefined) {
|
|
130
|
+
return multiple ? [] : null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!isIdMode) {
|
|
138
|
+
return value as Chat | Chat[];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const chats = currentIds
|
|
142
|
+
.map((id) => resolvedChats.get(String(id)))
|
|
143
|
+
.filter((c): c is Chat => c !== undefined);
|
|
144
|
+
|
|
145
|
+
if (multiple) {
|
|
146
|
+
return chats;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return chats[0] ?? null;
|
|
150
|
+
}, [value, isIdMode, currentIds, resolvedChats, multiple]);
|
|
151
|
+
|
|
152
|
+
const toExternalValue = useCallback(
|
|
153
|
+
(
|
|
154
|
+
internalVal: Chat | Chat[] | null,
|
|
155
|
+
isMultiple: boolean,
|
|
156
|
+
): ChatSelectValue => {
|
|
157
|
+
if (internalVal === null) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (isIdMode) {
|
|
162
|
+
// ID 模式:返回 string 或 string[]
|
|
163
|
+
if (isMultiple) {
|
|
164
|
+
return (internalVal as Chat[]).map((c) => String(c.id));
|
|
165
|
+
}
|
|
166
|
+
return String((internalVal as Chat).id);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Object 模式:直接返回 Chat 对象
|
|
170
|
+
return internalVal;
|
|
171
|
+
},
|
|
172
|
+
[isIdMode],
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
internalValue,
|
|
177
|
+
isLoading,
|
|
178
|
+
toExternalValue,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Chat, ChatInfo, ChatSelectValue, I18nText } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 获取国际化文本显示值(独立实现,不依赖其他组件)
|
|
5
|
+
*/
|
|
6
|
+
function getI18nText(text: I18nText | string | undefined): string {
|
|
7
|
+
if (!text) return '';
|
|
8
|
+
if (typeof text === 'string') return text;
|
|
9
|
+
return text.zh_cn || text.en_us || text.ja_jp || '';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 获取群组显示名称
|
|
14
|
+
*/
|
|
15
|
+
export function getChatDisplayName(name: ChatInfo['name']): string {
|
|
16
|
+
return getI18nText(name);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* ChatInfo → Chat 标准化转换
|
|
21
|
+
*/
|
|
22
|
+
export function chatInfoToChat(chatInfo: ChatInfo): Chat {
|
|
23
|
+
return {
|
|
24
|
+
id: chatInfo.chatID,
|
|
25
|
+
name: getChatDisplayName(chatInfo.name),
|
|
26
|
+
avatar: chatInfo.avatar,
|
|
27
|
+
raw: chatInfo,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 创建未知群组占位(ID 无法解析时使用)
|
|
33
|
+
*/
|
|
34
|
+
export function createUnknownChat(id: string): Chat {
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
name: '未知群组',
|
|
38
|
+
avatar: '',
|
|
39
|
+
raw: undefined,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 判断 value 是否为 ID 模式(字符串或字符串数组)
|
|
45
|
+
*/
|
|
46
|
+
export function isIdModeValue(
|
|
47
|
+
value: ChatSelectValue,
|
|
48
|
+
): value is string | string[] {
|
|
49
|
+
if (value === null || value === undefined) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === 'string') {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
56
|
+
return typeof value[0] === 'string';
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 从 value 中提取 ID 列表
|
|
63
|
+
*/
|
|
64
|
+
export function extractIdsFromValue(value: ChatSelectValue): string[] {
|
|
65
|
+
if (value === null || value === undefined) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
if (typeof value === 'string') {
|
|
69
|
+
return [value];
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(value)) {
|
|
72
|
+
if (value.length === 0) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
if (typeof value[0] === 'string') {
|
|
76
|
+
return value as string[];
|
|
77
|
+
}
|
|
78
|
+
return (value as Chat[]).map((c) => c.id);
|
|
79
|
+
}
|
|
80
|
+
return [(value as Chat).id];
|
|
81
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { IconDepartment } from '@client/src/components/business-ui/department-select/icon-department';
|
|
4
|
+
import type { Department } from '@client/src/components/business-ui/department-select/types';
|
|
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 {
|
|
8
|
+
listItemAvatarVariants,
|
|
9
|
+
listItemNameVariants,
|
|
10
|
+
listItemVariants,
|
|
11
|
+
type ComboboxSize,
|
|
12
|
+
} from '@client/src/components/business-ui/entity-combobox/size-variants';
|
|
13
|
+
import { cn } from '@/lib/utils';
|
|
14
|
+
|
|
15
|
+
export const DepartmentItem = ({
|
|
16
|
+
departmentValue,
|
|
17
|
+
isSelected,
|
|
18
|
+
className,
|
|
19
|
+
size = 'medium',
|
|
20
|
+
searchKeyword,
|
|
21
|
+
disabled,
|
|
22
|
+
}: {
|
|
23
|
+
departmentValue: Department;
|
|
24
|
+
isSelected: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
size?: ComboboxSize;
|
|
27
|
+
searchKeyword?: string;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}) => {
|
|
30
|
+
return (
|
|
31
|
+
<BaseComboboxItem
|
|
32
|
+
item={departmentValue}
|
|
33
|
+
getItemValue={(item) => item}
|
|
34
|
+
isSelected={isSelected}
|
|
35
|
+
className={cn(listItemVariants({ size }), className)}
|
|
36
|
+
disabled={disabled}
|
|
37
|
+
>
|
|
38
|
+
<div
|
|
39
|
+
className={cn(
|
|
40
|
+
'flex items-center justify-center',
|
|
41
|
+
listItemAvatarVariants({ size }),
|
|
42
|
+
)}
|
|
43
|
+
>
|
|
44
|
+
<IconDepartment className={listItemAvatarVariants({ size })} />
|
|
45
|
+
</div>
|
|
46
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
47
|
+
<HighlightText
|
|
48
|
+
text={departmentValue.name}
|
|
49
|
+
highlight={searchKeyword}
|
|
50
|
+
className={listItemNameVariants({ size })}
|
|
51
|
+
/>
|
|
52
|
+
</div>
|
|
53
|
+
</BaseComboboxItem>
|
|
54
|
+
);
|
|
55
|
+
};
|
package/template/client/src/components/business-ui/department-select/department-select-field.tsx
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DepartmentSelect,
|
|
3
|
+
type DepartmentSelectProps,
|
|
4
|
+
} from '@client/src/components/business-ui/department-select';
|
|
5
|
+
import type { Department } from '@client/src/components/business-ui/department-select/types';
|
|
6
|
+
import { useFormGlobalProps } from '@client/src/components/business-ui/form/context';
|
|
7
|
+
import { FieldLayout } from '@client/src/components/business-ui/form/field-layout';
|
|
8
|
+
import { useFieldContext } from '@client/src/components/business-ui/form/hooks/form-context';
|
|
9
|
+
import {
|
|
10
|
+
useFieldName,
|
|
11
|
+
useFieldValidation,
|
|
12
|
+
} from '@client/src/components/business-ui/form/hooks/form-utils';
|
|
13
|
+
import type {
|
|
14
|
+
CommonFieldProps,
|
|
15
|
+
FieldLayoutClassNames,
|
|
16
|
+
FieldLayoutStyles,
|
|
17
|
+
} from '@client/src/components/business-ui/form/types';
|
|
18
|
+
|
|
19
|
+
type DepartmentSelectFieldProps = CommonFieldProps &
|
|
20
|
+
Omit<
|
|
21
|
+
DepartmentSelectProps,
|
|
22
|
+
'value' | 'onChange' | 'defaultValue' | 'name' | 'required'
|
|
23
|
+
> & {
|
|
24
|
+
classNames?: Partial<
|
|
25
|
+
FieldLayoutClassNames & {
|
|
26
|
+
DepartmentSelect: string;
|
|
27
|
+
}
|
|
28
|
+
>;
|
|
29
|
+
styles?: Partial<
|
|
30
|
+
FieldLayoutStyles & {
|
|
31
|
+
DepartmentSelect: React.CSSProperties;
|
|
32
|
+
}
|
|
33
|
+
>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function DepartmentSelectField(props: DepartmentSelectFieldProps) {
|
|
37
|
+
const {
|
|
38
|
+
label,
|
|
39
|
+
description,
|
|
40
|
+
required,
|
|
41
|
+
disabled,
|
|
42
|
+
classNames,
|
|
43
|
+
layout = 'vertical',
|
|
44
|
+
styles,
|
|
45
|
+
multiple,
|
|
46
|
+
...departmentSelectProps
|
|
47
|
+
} = props;
|
|
48
|
+
|
|
49
|
+
const field = useFieldContext<Department | Department[] | null>();
|
|
50
|
+
const { isInvalid, errorMessage } = useFieldValidation();
|
|
51
|
+
const { layout: formLayout } = useFormGlobalProps();
|
|
52
|
+
const name = useFieldName();
|
|
53
|
+
|
|
54
|
+
const {
|
|
55
|
+
DepartmentSelect: departmentSelectClassName,
|
|
56
|
+
...fieldLayoutClassNames
|
|
57
|
+
} = classNames ?? {};
|
|
58
|
+
const fieldLayoutStyles = styles ?? {};
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<FieldLayout
|
|
62
|
+
label={label}
|
|
63
|
+
description={description}
|
|
64
|
+
isInvalid={isInvalid}
|
|
65
|
+
required={required ?? false}
|
|
66
|
+
layout={layout ?? formLayout ?? 'vertical'}
|
|
67
|
+
classNames={fieldLayoutClassNames ?? {}}
|
|
68
|
+
styles={fieldLayoutStyles ?? {}}
|
|
69
|
+
errorMessage={errorMessage}
|
|
70
|
+
name={name}
|
|
71
|
+
>
|
|
72
|
+
<DepartmentSelect
|
|
73
|
+
{...departmentSelectProps}
|
|
74
|
+
multiple={multiple}
|
|
75
|
+
value={field.state.value ?? (multiple ? [] : null)}
|
|
76
|
+
onChange={(value: Department | Department[] | null) => {
|
|
77
|
+
field.handleChange(value);
|
|
78
|
+
}}
|
|
79
|
+
disabled={disabled ?? false}
|
|
80
|
+
name={name}
|
|
81
|
+
required={required}
|
|
82
|
+
className={departmentSelectClassName}
|
|
83
|
+
/>
|
|
84
|
+
</FieldLayout>
|
|
85
|
+
);
|
|
86
|
+
}
|
package/template/client/src/components/business-ui/department-select/department-select-tag.tsx
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { X } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
import { IconDepartment } from '@client/src/components/business-ui/department-select/icon-department';
|
|
6
|
+
import type { Department } from '@client/src/components/business-ui/department-select/types';
|
|
7
|
+
import { ItemPill } from '@client/src/components/business-ui/entity-combobox/item-pill';
|
|
8
|
+
import {
|
|
9
|
+
tagCloseIconVariants,
|
|
10
|
+
tagIconVariants,
|
|
11
|
+
type ComboboxSize,
|
|
12
|
+
} from '@client/src/components/business-ui/entity-combobox/size-variants';
|
|
13
|
+
|
|
14
|
+
export const DepartmentSelectTag = ({
|
|
15
|
+
departmentValue,
|
|
16
|
+
onClose,
|
|
17
|
+
maxTextLength,
|
|
18
|
+
className,
|
|
19
|
+
size = 'medium',
|
|
20
|
+
disabled,
|
|
21
|
+
}: {
|
|
22
|
+
departmentValue: Department;
|
|
23
|
+
onClose: (value: Department, e: React.MouseEvent) => void;
|
|
24
|
+
maxTextLength?: number;
|
|
25
|
+
className?: string;
|
|
26
|
+
size?: ComboboxSize;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
}) => {
|
|
29
|
+
const handleClose = (e: React.MouseEvent) => {
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
onClose(departmentValue, e);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const closeButton = !disabled ? (
|
|
35
|
+
<button
|
|
36
|
+
type="button"
|
|
37
|
+
className="rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none"
|
|
38
|
+
onClick={handleClose}
|
|
39
|
+
>
|
|
40
|
+
<X className={tagCloseIconVariants({ size })} />
|
|
41
|
+
<span className="sr-only">移除 {departmentValue.name}</span>
|
|
42
|
+
</button>
|
|
43
|
+
) : null;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<ItemPill
|
|
47
|
+
label={departmentValue.name}
|
|
48
|
+
avatar={<IconDepartment className={tagIconVariants({ size })} />}
|
|
49
|
+
avatarFallback={false}
|
|
50
|
+
className={className}
|
|
51
|
+
maxTextLength={maxTextLength}
|
|
52
|
+
suffix={closeButton}
|
|
53
|
+
size={size}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
};
|