@lark-apaas/coding-template-nestjs-react-fullstack 0.1.72-alpha.20261122094734 → 0.1.72-alpha.20261123002135
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/business-ui/chat-select/README.md +79 -79
- package/template/client/src/components/business-ui/chat-select/types.ts +5 -7
- package/template/server/common/constants/api_response_code.ts +2 -0
- package/template/server/common/filters/exception.filter.ts +17 -0
package/package.json
CHANGED
|
@@ -2,67 +2,119 @@
|
|
|
2
2
|
|
|
3
3
|
**组件路径**:`@/components/business-ui/chat-select`
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 群组类型
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/** 群组数据结构 */
|
|
12
11
|
interface Chat {
|
|
12
|
+
/** 唯一标识:对应 chatID */
|
|
13
13
|
id: string;
|
|
14
|
+
/** 群组名称:内部优先 zh_cn,其次 en_us */
|
|
14
15
|
name: string;
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
/** 头像:URL 或 16 进制 RGB 颜色 */
|
|
17
|
+
avatar: string;
|
|
17
18
|
}
|
|
18
19
|
```
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
---
|
|
21
22
|
|
|
22
23
|
## 功能概述
|
|
23
24
|
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
25
|
+
- 群组字段选择组件,用于表单中录入"群组"字段
|
|
26
|
+
- 通过触发器打开弹层,弹层内置搜索功能(始终可用)
|
|
27
|
+
- **仅支持 ID 模式**:`value/onChange` 只使用群组 `chatID`(string),该 ID 为飞书群聊 ID。
|
|
28
|
+
- 组件在 UI 上可展示群组信息(头像/名称),但对外值仅返回/接收 `chatID`
|
|
29
|
+
- 选择后自动回显已选群组信息:群头像 + 群名称(多选以 tag 形式展示)
|
|
30
|
+
- 组件自带群组检索能力,无需额外传搜索接口/数据源
|
|
27
31
|
|
|
28
|
-
##
|
|
32
|
+
## 类型定义
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
```typescript
|
|
35
|
+
/** 触发器类型 */
|
|
36
|
+
type TriggerType = 'button' | 'search' | 'custom';
|
|
37
|
+
|
|
38
|
+
/** 单选模式 Props */
|
|
39
|
+
interface ChatSelectSingleProps {
|
|
40
|
+
/** 当前选中的群组 ID,空值为 null */
|
|
41
|
+
value: string | null;
|
|
42
|
+
/** 选中变化回调 */
|
|
43
|
+
onChange: (value: string | null) => void;
|
|
44
|
+
/** 是否多选,单选时为 false 或不传 */
|
|
45
|
+
multiple?: false;
|
|
46
|
+
/** 触发器类型,仅影响样式,不影响搜索功能 */
|
|
47
|
+
triggerType?: TriggerType;
|
|
48
|
+
/** 是否禁用 */
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/** 占位文本 */
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 多选模式 Props */
|
|
55
|
+
interface ChatSelectMultipleProps {
|
|
56
|
+
/** 当前选中的群组 ID 列表,空值为 [] */
|
|
57
|
+
value: string[];
|
|
58
|
+
/** 选中变化回调 */
|
|
59
|
+
onChange: (value: string[]) => void;
|
|
60
|
+
/** 是否多选,多选时为 true */
|
|
61
|
+
multiple: true;
|
|
62
|
+
/** 触发器类型 */
|
|
63
|
+
triggerType?: TriggerType;
|
|
64
|
+
/** 是否禁用 */
|
|
65
|
+
disabled?: boolean;
|
|
66
|
+
/** 占位文本 */
|
|
67
|
+
placeholder?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type ChatSelectProps = ChatSelectSingleProps | ChatSelectMultipleProps;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Props 说明
|
|
36
74
|
|
|
37
75
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
38
76
|
|------|------|--------|------|
|
|
39
|
-
| `value` |
|
|
40
|
-
| `
|
|
41
|
-
| `onChange` | `(value) => void` | - | 可选,参数形态见上表 |
|
|
42
|
-
| `valueType` | `'string' \| 'object'` | `'string'` | 值的模式 |
|
|
77
|
+
| `value` | `string \| null` / `string[]` | - | **必填**。单选传 `string \| null`(群组 ID),多选传 `string[]` |
|
|
78
|
+
| `onChange` | `function` | - | **必填**。值变化回调,返回值形态与 `value` 匹配 |
|
|
43
79
|
| `multiple` | `boolean` | `false` | 是否多选 |
|
|
44
80
|
| `triggerType` | `'button' \| 'search' \| 'custom'` | `'button'` | 触发器类型,仅影响样式 |
|
|
45
81
|
| `disabled` | `boolean` | `false` | 是否禁用 |
|
|
46
82
|
| `placeholder` | `string` | `'请选择'` | 占位文本 |
|
|
47
|
-
| `getOptionDisabled` | `(chat
|
|
83
|
+
| `getOptionDisabled` | `(chat) => boolean` | - | 判断选项是否禁用 |
|
|
84
|
+
|
|
85
|
+
## 受控规范
|
|
48
86
|
|
|
49
|
-
|
|
87
|
+
> ⚠️ **强约束**
|
|
88
|
+
|
|
89
|
+
1. **必须受控**:始终传 `value` + `onChange`
|
|
90
|
+
2. **禁止传**:`undefined` / 群组对象 / 其他类型
|
|
91
|
+
3. **空值规则**:
|
|
92
|
+
- 单选清空:`null`
|
|
93
|
+
- 多选清空:`[]`
|
|
50
94
|
|
|
51
95
|
## 使用示例
|
|
52
96
|
|
|
53
97
|
```tsx
|
|
54
98
|
import { useState } from 'react';
|
|
55
|
-
import { ChatSelect
|
|
99
|
+
import { ChatSelect } from '@/components/business-ui/chat-select';
|
|
56
100
|
|
|
57
|
-
//
|
|
101
|
+
// 单选
|
|
58
102
|
function SingleSelectExample() {
|
|
59
103
|
const [chatId, setChatId] = useState<string | null>(null);
|
|
60
|
-
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<ChatSelect
|
|
107
|
+
value={chatId}
|
|
108
|
+
onChange={setChatId}
|
|
109
|
+
placeholder="请选择群组"
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
61
112
|
}
|
|
62
113
|
|
|
63
|
-
//
|
|
114
|
+
// 多选
|
|
64
115
|
function MultipleSelectExample() {
|
|
65
116
|
const [chatIds, setChatIds] = useState<string[]>([]);
|
|
117
|
+
|
|
66
118
|
return (
|
|
67
119
|
<ChatSelect
|
|
68
120
|
multiple
|
|
@@ -73,56 +125,4 @@ function MultipleSelectExample() {
|
|
|
73
125
|
/>
|
|
74
126
|
);
|
|
75
127
|
}
|
|
76
|
-
|
|
77
|
-
// 对象单选:需要原始群信息时使用
|
|
78
|
-
function SingleObjectExample() {
|
|
79
|
-
const [chat, setChat] = useState<Chat | null>(null);
|
|
80
|
-
return <ChatSelect valueType="object" value={chat} onChange={setChat} />;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 对象多选
|
|
84
|
-
function MultipleObjectExample() {
|
|
85
|
-
const [chats, setChats] = useState<Chat[]>([]);
|
|
86
|
-
return <ChatSelect valueType="object" multiple value={chats} onChange={setChats} />;
|
|
87
|
-
}
|
|
88
128
|
```
|
|
89
|
-
|
|
90
|
-
## 通知配置的保存与回填
|
|
91
|
-
|
|
92
|
-
通知接口需要通知标识时,从对象模式的真实选择结果取 `chat.raw?.openChatID`。缺 `raw`、`openChatID` 为 `undefined` 或空字符串时,当前结果不足以保存通知配置;提示缺少数据并保留原配置,不能以 `chat.id` 替代。
|
|
93
|
-
|
|
94
|
-
以下示例的业务保存接口只有一个 ID 槽位 `chatId`,该槽位约定存通知标识。`saveNotificationSetting` 由业务方提供,不是组件 API:
|
|
95
|
-
|
|
96
|
-
```tsx
|
|
97
|
-
import { useState } from 'react';
|
|
98
|
-
import { ChatSelect, type Chat } from '@/components/business-ui/chat-select';
|
|
99
|
-
|
|
100
|
-
function NotificationSelect({ saveNotificationSetting }: {
|
|
101
|
-
saveNotificationSetting: (setting: { chatId: string; chatName: string }) => Promise<void>;
|
|
102
|
-
}) {
|
|
103
|
-
const [chat, setChat] = useState<Chat | null>(null);
|
|
104
|
-
const [error, setError] = useState('');
|
|
105
|
-
|
|
106
|
-
async function save() {
|
|
107
|
-
const openChatID = chat?.raw?.openChatID;
|
|
108
|
-
if (!chat || !openChatID) {
|
|
109
|
-
setError('缺少可用的群通知标识,原配置未更改');
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
await saveNotificationSetting({ chatId: openChatID, chatName: chat.name });
|
|
113
|
-
setError('');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return (
|
|
117
|
-
<>
|
|
118
|
-
<ChatSelect valueType="object" value={chat} onChange={setChat} />
|
|
119
|
-
<button type="button" onClick={save}>保存</button>
|
|
120
|
-
{error && <p>{error}</p>}
|
|
121
|
-
</>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
此单 ID 合同不能扩展时,只保存通知 ID 和名称;当前会话可保留真实选择对象,但不能承诺刷新后重建。若业务合同允许保存并读回对应真实信息,可同时保留实际 `chatID`、名称等回显所需信息:已有可信数字 ID 可用字符串模式回填,已有真实 `Chat` 可用对象模式回填。
|
|
127
|
-
|
|
128
|
-
历史配置若只有通知 ID,先通过已有可信群信息取得对应数字 ID 或真实对象,再按对应模式回填;不能用通知 ID 和名称伪造 `Chat`。没有可信映射或第二存储位置且无权扩展合同时,保留原配置,说明回填数据不足或请求业务合同授权;需要完整刷新回显时,在授权下补充合同或可信来源。
|
|
@@ -7,13 +7,11 @@ import type { I18nText } from '@client/src/components/business-ui/entity-combobo
|
|
|
7
7
|
export type { I18nText };
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* 群组原始信息(对应 SearchChatEntity
|
|
10
|
+
* 群组原始信息(对应 SearchChatEntity)
|
|
11
11
|
*/
|
|
12
12
|
export type ChatInfo = {
|
|
13
|
-
/**
|
|
13
|
+
/** 群组 ID */
|
|
14
14
|
chatID: string;
|
|
15
|
-
/** 飞书群组通知等能力使用的 open ID */
|
|
16
|
-
openChatID?: string;
|
|
17
15
|
/** 群组名称(国际化文本) */
|
|
18
16
|
name: I18nText;
|
|
19
17
|
/** 头像:URL 或 16 进制 RGB 颜色 */
|
|
@@ -25,13 +23,13 @@ export type ChatInfo = {
|
|
|
25
23
|
};
|
|
26
24
|
|
|
27
25
|
/**
|
|
28
|
-
* 标准化后的群组数据(用于 BaseCombobox
|
|
26
|
+
* 标准化后的群组数据(用于 BaseCombobox)
|
|
29
27
|
*/
|
|
30
28
|
export type Chat = ItemValue<ChatInfo>;
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* 值类型
|
|
34
|
-
* - 'string': value
|
|
32
|
+
* - 'string': value 为 chatID 字符串
|
|
35
33
|
* - 'object': value 为 Chat 对象
|
|
36
34
|
* @default 'string'
|
|
37
35
|
*/
|
|
@@ -60,7 +58,7 @@ type ChatSelectBaseProps<
|
|
|
60
58
|
> & {
|
|
61
59
|
/**
|
|
62
60
|
* 值类型
|
|
63
|
-
* - 'string': value
|
|
61
|
+
* - 'string': value 为 chatID 字符串
|
|
64
62
|
* - 'object': value 为 Chat 对象
|
|
65
63
|
* @default 'string'
|
|
66
64
|
*/
|
|
@@ -16,6 +16,7 @@ export enum ResponseCode {
|
|
|
16
16
|
VALIDATION_ERROR = 'VALIDATION_ERROR',
|
|
17
17
|
CONFLICT = 'CONFLICT',
|
|
18
18
|
TOO_MANY_REQUESTS = 'TOO_MANY_REQUESTS',
|
|
19
|
+
PAYLOAD_TOO_LARGE = 'PAYLOAD_TOO_LARGE',
|
|
19
20
|
|
|
20
21
|
// 服务端错误
|
|
21
22
|
INTERNAL_ERROR = 'INTERNAL_ERROR',
|
|
@@ -40,6 +41,7 @@ export const RESPONSE_CODE_TO_HTTP_STATUS_MAP: Record<ResponseCode, number> = {
|
|
|
40
41
|
[ResponseCode.VALIDATION_ERROR]: HttpStatus.UNPROCESSABLE_ENTITY,
|
|
41
42
|
[ResponseCode.CONFLICT]: HttpStatus.CONFLICT,
|
|
42
43
|
[ResponseCode.TOO_MANY_REQUESTS]: HttpStatus.TOO_MANY_REQUESTS,
|
|
44
|
+
[ResponseCode.PAYLOAD_TOO_LARGE]: HttpStatus.PAYLOAD_TOO_LARGE,
|
|
43
45
|
|
|
44
46
|
[ResponseCode.INTERNAL_ERROR]: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
45
47
|
[ResponseCode.BAD_GATEWAY]: HttpStatus.BAD_GATEWAY,
|
|
@@ -44,6 +44,23 @@ export class GlobalExceptionFilter implements ExceptionFilter {
|
|
|
44
44
|
timestamp: Date.now(),
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
|
+
} else if (
|
|
48
|
+
typeof exception === 'object' &&
|
|
49
|
+
exception !== null &&
|
|
50
|
+
((exception as { status?: unknown }).status === HttpStatus.PAYLOAD_TOO_LARGE ||
|
|
51
|
+
(exception as { statusCode?: unknown }).statusCode === HttpStatus.PAYLOAD_TOO_LARGE ||
|
|
52
|
+
(exception as { type?: unknown }).type === 'entity.too.large')
|
|
53
|
+
) {
|
|
54
|
+
// body-parser 请求体超限(PayloadTooLargeError):status/statusCode 为 413 或 type 为 entity.too.large
|
|
55
|
+
// 错误发生在 Nest 路由之前,按异常自带语义状态码响应,避免被兜成 500
|
|
56
|
+
httpStatus = HttpStatus.PAYLOAD_TOO_LARGE;
|
|
57
|
+
errorResponse = {
|
|
58
|
+
error: {
|
|
59
|
+
code: ResponseCode.PAYLOAD_TOO_LARGE,
|
|
60
|
+
message: '请求体过大',
|
|
61
|
+
timestamp: Date.now(),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
47
64
|
} else if (
|
|
48
65
|
typeof exception === 'object' &&
|
|
49
66
|
exception !== null &&
|