bi-sdk-react 0.0.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/dist/es/css/bi-sdk.css +1 -0
- package/dist/es/js/bi-sdk.es.js +795 -0
- package/dist/es/js/bi-sdk.es.js.LICENSE.txt +9 -0
- package/dist/types/components/PageDesigner.d.ts +10 -0
- package/dist/types/components/context/DesignerContext.d.ts +15 -0
- package/dist/types/components/context/EnvContext.d.ts +15 -0
- package/dist/types/components/dnd/DropContainer.d.ts +21 -0
- package/dist/types/components/example.d.ts +225 -0
- package/dist/types/components/hooks/datasource.d.ts +1 -0
- package/dist/types/components/hooks/useDeepCompareEffect.d.ts +1 -0
- package/dist/types/components/icon/IconFont.d.ts +6 -0
- package/dist/types/components/index.d.ts +10 -0
- package/dist/types/components/layout/PageCanvas.d.ts +6 -0
- package/dist/types/components/layout/PageItem.d.ts +27 -0
- package/dist/types/components/panel/AiPanel.d.ts +8 -0
- package/dist/types/components/panel/CascadePanel.d.ts +2 -0
- package/dist/types/components/panel/ChatInput.d.ts +28 -0
- package/dist/types/components/panel/CodePanel.d.ts +2 -0
- package/dist/types/components/panel/ComponentPanel.d.ts +2 -0
- package/dist/types/components/panel/DatasourcePanel.d.ts +2 -0
- package/dist/types/components/panel/LayerPanel.d.ts +2 -0
- package/dist/types/components/panel/PaneHeader.d.ts +6 -0
- package/dist/types/components/panel/PropertiesPanel.d.ts +2 -0
- package/dist/types/components/panel/ScriptPanel.d.ts +2 -0
- package/dist/types/components/panel/VariablesPanel.d.ts +2 -0
- package/dist/types/components/panel/index.d.ts +9 -0
- package/dist/types/components/plugins/@antd/index.d.ts +22 -0
- package/dist/types/components/plugins/@antd/item-props/ButtonProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/CapsuleProps.d.ts +13 -0
- package/dist/types/components/plugins/@antd/item-props/CardProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/CheckboxProps.d.ts +13 -0
- package/dist/types/components/plugins/@antd/item-props/ColProps.d.ts +12 -0
- package/dist/types/components/plugins/@antd/item-props/DatePickerProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/EchartsProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/HtmlProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/ImageProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/InputNumberProps.d.ts +9 -0
- package/dist/types/components/plugins/@antd/item-props/InputProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/ListProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/PageHeaderProps.d.ts +7 -0
- package/dist/types/components/plugins/@antd/item-props/RowProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/SelectProps.d.ts +16 -0
- package/dist/types/components/plugins/@antd/item-props/SpaceProps.d.ts +7 -0
- package/dist/types/components/plugins/@antd/item-props/SwitchProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +15 -0
- package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/index.d.ts +19 -0
- package/dist/types/components/plugins/@antd/item-props/types.d.ts +5 -0
- package/dist/types/components/plugins/@antd/items/ButtonRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/CapsuleRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/CardRender.d.ts +12 -0
- package/dist/types/components/plugins/@antd/items/CheckboxRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/ColRender.d.ts +13 -0
- package/dist/types/components/plugins/@antd/items/DatePickerRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/EchartsRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/HtmlRender.d.ts +20 -0
- package/dist/types/components/plugins/@antd/items/ImageRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/InputNumberRender.d.ts +17 -0
- package/dist/types/components/plugins/@antd/items/InputRender.d.ts +17 -0
- package/dist/types/components/plugins/@antd/items/ListRender.d.ts +11 -0
- package/dist/types/components/plugins/@antd/items/PageHeaderRender.d.ts +8 -0
- package/dist/types/components/plugins/@antd/items/RowRender.d.ts +13 -0
- package/dist/types/components/plugins/@antd/items/SelectRender.d.ts +18 -0
- package/dist/types/components/plugins/@antd/items/SpaceRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/SwitchRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/TableRender.d.ts +12 -0
- package/dist/types/components/plugins/@antd/items/TextRender.d.ts +9 -0
- package/dist/types/components/plugins/@antd/items/index.d.ts +19 -0
- package/dist/types/components/typing.d.ts +80 -0
- package/dist/types/components/utils.d.ts +9 -0
- package/dist/types/example.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/umd/css/bi-sdk.css +1 -0
- package/dist/umd/js/bi-sdk.umd.min.js +795 -0
- package/dist/umd/js/bi-sdk.umd.min.js.LICENSE.txt +9 -0
- package/package.json +52 -0
- package/src/components/PageDesigner.tsx +509 -0
- package/src/components/context/DesignerContext.tsx +71 -0
- package/src/components/context/EnvContext.tsx +42 -0
- package/src/components/dnd/DropContainer.tsx +474 -0
- package/src/components/example.ts +577 -0
- package/src/components/hooks/datasource.ts +23 -0
- package/src/components/hooks/useDeepCompareEffect.ts +12 -0
- package/src/components/icon/IconFont.tsx +16 -0
- package/src/components/index.ts +29 -0
- package/src/components/layout/PageCanvas.tsx +145 -0
- package/src/components/layout/PageItem.tsx +182 -0
- package/src/components/panel/AiPanel.tsx +116 -0
- package/src/components/panel/CascadePanel.tsx +163 -0
- package/src/components/panel/ChatInput.tsx +550 -0
- package/src/components/panel/CodePanel.tsx +48 -0
- package/src/components/panel/ComponentPanel.tsx +119 -0
- package/src/components/panel/DatasourcePanel.tsx +419 -0
- package/src/components/panel/LayerPanel.tsx +238 -0
- package/src/components/panel/PaneHeader.tsx +34 -0
- package/src/components/panel/PropertiesPanel.tsx +394 -0
- package/src/components/panel/ScriptPanel.tsx +175 -0
- package/src/components/panel/VariablesPanel.tsx +153 -0
- package/src/components/panel/index.ts +9 -0
- package/src/components/plugins/@antd/index.ts +445 -0
- package/src/components/plugins/@antd/item-props/ButtonProps.tsx +91 -0
- package/src/components/plugins/@antd/item-props/CapsuleProps.tsx +102 -0
- package/src/components/plugins/@antd/item-props/CardProps.tsx +58 -0
- package/src/components/plugins/@antd/item-props/CheckboxProps.tsx +75 -0
- package/src/components/plugins/@antd/item-props/ColProps.tsx +43 -0
- package/src/components/plugins/@antd/item-props/DatePickerProps.tsx +72 -0
- package/src/components/plugins/@antd/item-props/EchartsProps.tsx +35 -0
- package/src/components/plugins/@antd/item-props/HtmlProps.tsx +61 -0
- package/src/components/plugins/@antd/item-props/ImageProps.tsx +43 -0
- package/src/components/plugins/@antd/item-props/InputNumberProps.tsx +18 -0
- package/src/components/plugins/@antd/item-props/InputProps.tsx +89 -0
- package/src/components/plugins/@antd/item-props/ListProps.tsx +69 -0
- package/src/components/plugins/@antd/item-props/PageHeaderProps.tsx +20 -0
- package/src/components/plugins/@antd/item-props/RowProps.tsx +21 -0
- package/src/components/plugins/@antd/item-props/SelectProps.tsx +136 -0
- package/src/components/plugins/@antd/item-props/SpaceProps.tsx +52 -0
- package/src/components/plugins/@antd/item-props/SwitchProps.tsx +17 -0
- package/src/components/plugins/@antd/item-props/TableProps.tsx +200 -0
- package/src/components/plugins/@antd/item-props/TextProps.tsx +41 -0
- package/src/components/plugins/@antd/item-props/index.ts +20 -0
- package/src/components/plugins/@antd/item-props/types.ts +6 -0
- package/src/components/plugins/@antd/items/ButtonRender.tsx +63 -0
- package/src/components/plugins/@antd/items/CapsuleRender.tsx +49 -0
- package/src/components/plugins/@antd/items/CardRender.tsx +119 -0
- package/src/components/plugins/@antd/items/CheckboxRender.tsx +56 -0
- package/src/components/plugins/@antd/items/ColRender.tsx +78 -0
- package/src/components/plugins/@antd/items/DatePickerRender.tsx +117 -0
- package/src/components/plugins/@antd/items/EchartsRender.tsx +98 -0
- package/src/components/plugins/@antd/items/HtmlRender.tsx +74 -0
- package/src/components/plugins/@antd/items/ImageRender.tsx +37 -0
- package/src/components/plugins/@antd/items/InputNumberRender.tsx +57 -0
- package/src/components/plugins/@antd/items/InputRender.tsx +75 -0
- package/src/components/plugins/@antd/items/ListRender.tsx +227 -0
- package/src/components/plugins/@antd/items/PageHeaderRender.tsx +74 -0
- package/src/components/plugins/@antd/items/RowRender.tsx +47 -0
- package/src/components/plugins/@antd/items/SelectRender.tsx +53 -0
- package/src/components/plugins/@antd/items/SpaceRender.tsx +54 -0
- package/src/components/plugins/@antd/items/SwitchRender.tsx +52 -0
- package/src/components/plugins/@antd/items/TableRender.tsx +99 -0
- package/src/components/plugins/@antd/items/TextRender.tsx +25 -0
- package/src/components/plugins/@antd/items/index.ts +20 -0
- package/src/components/styles.css +12 -0
- package/src/components/typing.ts +80 -0
- package/src/components/utils.ts +37 -0
- package/src/example.tsx +136 -0
- package/src/index.tsx +17 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useEffect,
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
8
|
+
import styled from "styled-components";
|
|
9
|
+
import { Input, Button, Space, Tooltip, Dropdown, Switch, Upload } from "antd";
|
|
10
|
+
import { PaperClipOutlined, SendOutlined } from "@ant-design/icons";
|
|
11
|
+
import * as XLSX from "xlsx";
|
|
12
|
+
|
|
13
|
+
export type ChatInputProps = {
|
|
14
|
+
value?: string;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
sending?: boolean;
|
|
18
|
+
rows?: number;
|
|
19
|
+
agentList?: { id: string | number; name: string }[];
|
|
20
|
+
title?: string;
|
|
21
|
+
agentId?: string | number | null;
|
|
22
|
+
attachments?: any[];
|
|
23
|
+
onInput?: (text: string) => void;
|
|
24
|
+
onSubmit?: (data: {
|
|
25
|
+
demand: string;
|
|
26
|
+
title: string;
|
|
27
|
+
agentId?: string | number;
|
|
28
|
+
csvData: Record<string, string>;
|
|
29
|
+
}) => void;
|
|
30
|
+
onUpdateTitle?: (title: string) => void;
|
|
31
|
+
onUpdateAgentId?: (id: string | number | null) => void;
|
|
32
|
+
onUpdateAttachments?: (list: any[]) => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const Wrapper = styled.div`
|
|
36
|
+
ul.agent-list {
|
|
37
|
+
margin: 0;
|
|
38
|
+
padding: 0;
|
|
39
|
+
list-style: none;
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: column;
|
|
42
|
+
gap: 4px;
|
|
43
|
+
}
|
|
44
|
+
ul.agent-list li {
|
|
45
|
+
padding: 4px 8px;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
font-size: 14px;
|
|
48
|
+
}
|
|
49
|
+
ul.agent-list li:hover {
|
|
50
|
+
background: var(--link-bg-color);
|
|
51
|
+
border-radius: 2px;
|
|
52
|
+
}
|
|
53
|
+
ul.agent-list li a {
|
|
54
|
+
color: var(--ant-color-text-secondary);
|
|
55
|
+
flex: auto;
|
|
56
|
+
overflow: hidden;
|
|
57
|
+
text-overflow: ellipsis;
|
|
58
|
+
white-space: nowrap;
|
|
59
|
+
}
|
|
60
|
+
.chat-input {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-direction: column;
|
|
63
|
+
width: 100%;
|
|
64
|
+
position: relative;
|
|
65
|
+
}
|
|
66
|
+
.input-stack {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-direction: column;
|
|
69
|
+
gap: 0;
|
|
70
|
+
}
|
|
71
|
+
.attachment-bar {
|
|
72
|
+
display: flex;
|
|
73
|
+
flex-wrap: wrap;
|
|
74
|
+
gap: 8px;
|
|
75
|
+
width: 100%;
|
|
76
|
+
box-sizing: border-box;
|
|
77
|
+
padding: 8px;
|
|
78
|
+
border: 1px solid #ddd;
|
|
79
|
+
border-radius: 6px 6px 0 0;
|
|
80
|
+
border-bottom: none;
|
|
81
|
+
background-color: #eff1f9;
|
|
82
|
+
}
|
|
83
|
+
.attachment-card {
|
|
84
|
+
max-height: 171px;
|
|
85
|
+
overflow: auto;
|
|
86
|
+
display: inline-flex;
|
|
87
|
+
align-items: center;
|
|
88
|
+
flex-direction: column;
|
|
89
|
+
gap: 12px;
|
|
90
|
+
padding: 8px;
|
|
91
|
+
border: 1px solid #eaeaea;
|
|
92
|
+
border-radius: 6px;
|
|
93
|
+
background-color: #fafafa;
|
|
94
|
+
font-size: 12px;
|
|
95
|
+
position: relative;
|
|
96
|
+
}
|
|
97
|
+
.attachment-card .name {
|
|
98
|
+
max-width: 80px;
|
|
99
|
+
overflow: hidden;
|
|
100
|
+
text-overflow: ellipsis;
|
|
101
|
+
white-space: nowrap;
|
|
102
|
+
color: #555;
|
|
103
|
+
}
|
|
104
|
+
.attachment-card .remove {
|
|
105
|
+
color: #999;
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
transition: color 0.2s ease;
|
|
108
|
+
position: absolute;
|
|
109
|
+
top: 4px;
|
|
110
|
+
right: 2px;
|
|
111
|
+
}
|
|
112
|
+
.attachment-card .remove:hover {
|
|
113
|
+
color: #666;
|
|
114
|
+
}
|
|
115
|
+
.agent-info {
|
|
116
|
+
box-sizing: border-box;
|
|
117
|
+
padding: 4px 8px;
|
|
118
|
+
border: 1px solid #ddd;
|
|
119
|
+
border-radius: 6px 6px 0 0;
|
|
120
|
+
border-bottom: none;
|
|
121
|
+
background-color: #eff1f9;
|
|
122
|
+
font-size: 14px;
|
|
123
|
+
color: #555;
|
|
124
|
+
display: flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: space-between;
|
|
127
|
+
user-select: none;
|
|
128
|
+
}
|
|
129
|
+
.attachment-bar + .agent-info {
|
|
130
|
+
border-radius: 0;
|
|
131
|
+
}
|
|
132
|
+
.agent-info + .title-input,
|
|
133
|
+
.agent-info + .textarea-stacked {
|
|
134
|
+
border-radius: 0;
|
|
135
|
+
}
|
|
136
|
+
.title-input {
|
|
137
|
+
width: 100%;
|
|
138
|
+
box-sizing: border-box;
|
|
139
|
+
padding: 8px;
|
|
140
|
+
border: 1px solid #ddd;
|
|
141
|
+
border-radius: 6px 6px 0 0;
|
|
142
|
+
border-bottom: none;
|
|
143
|
+
font-size: 14px;
|
|
144
|
+
}
|
|
145
|
+
.attachment-bar + .title-input {
|
|
146
|
+
border-top-left-radius: 0;
|
|
147
|
+
border-top-right-radius: 0;
|
|
148
|
+
}
|
|
149
|
+
.input {
|
|
150
|
+
width: 100%;
|
|
151
|
+
box-sizing: border-box;
|
|
152
|
+
padding: 8px;
|
|
153
|
+
border: 1px solid #ddd;
|
|
154
|
+
border-radius: 6px;
|
|
155
|
+
resize: vertical;
|
|
156
|
+
font-size: 14px;
|
|
157
|
+
}
|
|
158
|
+
.textarea-stacked {
|
|
159
|
+
border-top-left-radius: 5px;
|
|
160
|
+
border-top-right-radius: 5px;
|
|
161
|
+
border-bottom-left-radius: 0;
|
|
162
|
+
border-bottom-right-radius: 0;
|
|
163
|
+
outline: none;
|
|
164
|
+
resize: none;
|
|
165
|
+
}
|
|
166
|
+
.title-input + .textarea-stacked,
|
|
167
|
+
.attachment-bar + .textarea-stacked {
|
|
168
|
+
border-top-left-radius: 0;
|
|
169
|
+
border-top-right-radius: 0;
|
|
170
|
+
}
|
|
171
|
+
.footer {
|
|
172
|
+
display: flex;
|
|
173
|
+
justify-content: space-between;
|
|
174
|
+
align-items: center;
|
|
175
|
+
gap: 8px;
|
|
176
|
+
bottom: 0;
|
|
177
|
+
left: 0;
|
|
178
|
+
right: 0;
|
|
179
|
+
padding: 8px;
|
|
180
|
+
border: solid 1px #dddddd;
|
|
181
|
+
border-top: none;
|
|
182
|
+
border-bottom-left-radius: 5px;
|
|
183
|
+
border-bottom-right-radius: 5px;
|
|
184
|
+
background-color: #eff1f9;
|
|
185
|
+
}
|
|
186
|
+
.footer .left {
|
|
187
|
+
display: flex;
|
|
188
|
+
align-items: center;
|
|
189
|
+
gap: 8px;
|
|
190
|
+
}
|
|
191
|
+
.agent-trigger {
|
|
192
|
+
display: inline-flex;
|
|
193
|
+
align-items: center;
|
|
194
|
+
justify-content: center;
|
|
195
|
+
gap: 4px;
|
|
196
|
+
width: auto;
|
|
197
|
+
height: 26px;
|
|
198
|
+
color: var(--chat-blue);
|
|
199
|
+
background-color: #ffffff;
|
|
200
|
+
cursor: pointer;
|
|
201
|
+
transition: all 0.2s ease;
|
|
202
|
+
font-size: 12px;
|
|
203
|
+
border: solid 1px #dcdcdc;
|
|
204
|
+
border-radius: 5px;
|
|
205
|
+
padding: 0 4px;
|
|
206
|
+
}
|
|
207
|
+
.agent-trigger:hover {
|
|
208
|
+
background-color: #f7f7f7;
|
|
209
|
+
}
|
|
210
|
+
.title-toggle {
|
|
211
|
+
display: none;
|
|
212
|
+
align-items: center;
|
|
213
|
+
gap: 6px;
|
|
214
|
+
background-color: #ffffff;
|
|
215
|
+
border: solid 1px #dcdcdc;
|
|
216
|
+
border-radius: 5px;
|
|
217
|
+
padding: 0 4px;
|
|
218
|
+
height: 26px;
|
|
219
|
+
}
|
|
220
|
+
.title-toggle .label {
|
|
221
|
+
color: #666;
|
|
222
|
+
font-size: 12px;
|
|
223
|
+
user-select: none;
|
|
224
|
+
}
|
|
225
|
+
.attach-upload {
|
|
226
|
+
display: inline-flex;
|
|
227
|
+
align-items: center;
|
|
228
|
+
gap: 6px;
|
|
229
|
+
color: var(--chat-blue);
|
|
230
|
+
background-color: #ffffff;
|
|
231
|
+
border: solid 1px #dcdcdc;
|
|
232
|
+
border-radius: 5px;
|
|
233
|
+
padding: 0 4px;
|
|
234
|
+
height: 26px;
|
|
235
|
+
font-size: 12px;
|
|
236
|
+
cursor: pointer;
|
|
237
|
+
}
|
|
238
|
+
.tips {
|
|
239
|
+
color: #999;
|
|
240
|
+
font-size: 12px;
|
|
241
|
+
user-select: none;
|
|
242
|
+
padding: 4px;
|
|
243
|
+
border-radius: 4px;
|
|
244
|
+
}
|
|
245
|
+
.send-btn {
|
|
246
|
+
display: flex;
|
|
247
|
+
align-items: center;
|
|
248
|
+
justify-content: center;
|
|
249
|
+
width: 50px;
|
|
250
|
+
height: 26px;
|
|
251
|
+
color: #fff;
|
|
252
|
+
font-size: 22px;
|
|
253
|
+
background-color: rgb(184, 184, 191);
|
|
254
|
+
border: unset;
|
|
255
|
+
border-radius: 14px;
|
|
256
|
+
transition: background-color 0.3s ease 0s;
|
|
257
|
+
cursor: pointer;
|
|
258
|
+
}
|
|
259
|
+
.send-btn.send-btn-active {
|
|
260
|
+
background-color: var(--chat-blue);
|
|
261
|
+
}
|
|
262
|
+
`;
|
|
263
|
+
|
|
264
|
+
const DEFAULT_AGENT_LIST: any[] = [];
|
|
265
|
+
const DEFAULT_ATTACHMENTS: any[] = [];
|
|
266
|
+
|
|
267
|
+
export const ChatInput = React.forwardRef<
|
|
268
|
+
{ focus: () => void },
|
|
269
|
+
ChatInputProps
|
|
270
|
+
>(
|
|
271
|
+
(
|
|
272
|
+
{
|
|
273
|
+
value = "",
|
|
274
|
+
placeholder = "请输入需求,例如:分析 2025 年人口结构并生成可视化报告",
|
|
275
|
+
disabled = false,
|
|
276
|
+
sending = false,
|
|
277
|
+
rows = 6,
|
|
278
|
+
agentList = DEFAULT_AGENT_LIST,
|
|
279
|
+
title = "",
|
|
280
|
+
agentId = null,
|
|
281
|
+
attachments = DEFAULT_ATTACHMENTS,
|
|
282
|
+
onInput,
|
|
283
|
+
onSubmit,
|
|
284
|
+
onUpdateTitle,
|
|
285
|
+
onUpdateAgentId,
|
|
286
|
+
onUpdateAttachments,
|
|
287
|
+
},
|
|
288
|
+
ref
|
|
289
|
+
) => {
|
|
290
|
+
const inputRef = useRef<any>(null);
|
|
291
|
+
const [localTitle, setLocalTitle] = useState(title || "");
|
|
292
|
+
const [localAgentId, setLocalAgentId] = useState<string | number | null>(
|
|
293
|
+
agentId || null
|
|
294
|
+
);
|
|
295
|
+
const [selectedAgent, setSelectedAgent] = useState<{
|
|
296
|
+
id: string | number;
|
|
297
|
+
name: string;
|
|
298
|
+
} | null>(null);
|
|
299
|
+
const [localValue, setLocalValue] = useState(value || "");
|
|
300
|
+
const [lastSubmitAt, setLastSubmitAt] = useState(0);
|
|
301
|
+
const minIntervalMs = 400;
|
|
302
|
+
const [showTitle, setShowTitle] = useState(false);
|
|
303
|
+
const acceptXlsx =
|
|
304
|
+
".xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
305
|
+
const [localAttachments, setLocalAttachments] = useState<any[]>(
|
|
306
|
+
Array.isArray(attachments) ? attachments : []
|
|
307
|
+
);
|
|
308
|
+
const isMobile = useMemo(() => false, []);
|
|
309
|
+
useImperativeHandle(ref, () => ({
|
|
310
|
+
focus() {
|
|
311
|
+
inputRef.current?.focus();
|
|
312
|
+
},
|
|
313
|
+
}));
|
|
314
|
+
useEffect(() => setLocalValue(value || ""), [value]);
|
|
315
|
+
useEffect(() => {
|
|
316
|
+
onInput && onInput(localValue);
|
|
317
|
+
}, [localValue]);
|
|
318
|
+
useEffect(() => setLocalTitle(title || ""), [title]);
|
|
319
|
+
useEffect(() => {
|
|
320
|
+
setLocalAgentId(agentId || null);
|
|
321
|
+
setSelectedAgent(
|
|
322
|
+
agentId ? agentList.find((s) => s.id === agentId) || null : null
|
|
323
|
+
);
|
|
324
|
+
}, [agentId, agentList]);
|
|
325
|
+
useEffect(
|
|
326
|
+
() => setLocalAttachments(Array.isArray(attachments) ? attachments : []),
|
|
327
|
+
[attachments]
|
|
328
|
+
);
|
|
329
|
+
const canSubmit = !!(localValue && localValue.trim());
|
|
330
|
+
const agent = useMemo(() => {
|
|
331
|
+
if (!localAgentId) return null;
|
|
332
|
+
return agentList.find((it) => it.id === localAgentId) || null;
|
|
333
|
+
}, [localAgentId, agentList]);
|
|
334
|
+
const onTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
335
|
+
const v = e.target.value;
|
|
336
|
+
setLocalTitle(v);
|
|
337
|
+
onUpdateTitle && onUpdateTitle(v);
|
|
338
|
+
};
|
|
339
|
+
const onAgentSelect = (item: { id: string | number; name: string }) => {
|
|
340
|
+
const id = item.id || null;
|
|
341
|
+
setLocalAgentId(id);
|
|
342
|
+
onUpdateAgentId && onUpdateAgentId(id);
|
|
343
|
+
setSelectedAgent(item);
|
|
344
|
+
};
|
|
345
|
+
const clearAgent = () => {
|
|
346
|
+
setLocalAgentId(null);
|
|
347
|
+
onUpdateAgentId && onUpdateAgentId(null);
|
|
348
|
+
setSelectedAgent(null);
|
|
349
|
+
};
|
|
350
|
+
const onKeydown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
351
|
+
if (e.key === "Enter") {
|
|
352
|
+
if ((e as any).shiftKey) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
e.preventDefault();
|
|
356
|
+
submit();
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const convertXlsxToCsv = async (arrayBuffer: ArrayBuffer) => {
|
|
360
|
+
const workbook = XLSX.read(arrayBuffer, {
|
|
361
|
+
type: "array",
|
|
362
|
+
cellDates: true,
|
|
363
|
+
dateNF: "yyyy-mm-dd hh:mm:ss",
|
|
364
|
+
});
|
|
365
|
+
const result: Record<string, string> = {};
|
|
366
|
+
workbook.SheetNames.forEach((name) => {
|
|
367
|
+
const sheet = workbook.Sheets[name];
|
|
368
|
+
const csv = XLSX.utils.sheet_to_csv(sheet);
|
|
369
|
+
result[name] = csv;
|
|
370
|
+
});
|
|
371
|
+
return result;
|
|
372
|
+
};
|
|
373
|
+
const beforeUploadXlsx = (file: File) => {
|
|
374
|
+
const mimeOk =
|
|
375
|
+
file.type ===
|
|
376
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
|
|
377
|
+
!file.type;
|
|
378
|
+
const extOk = (file.name || "").toLowerCase().endsWith(".xlsx");
|
|
379
|
+
if (!mimeOk || !extOk) {
|
|
380
|
+
return Upload.LIST_IGNORE;
|
|
381
|
+
}
|
|
382
|
+
const reader = new FileReader();
|
|
383
|
+
reader.onload = async (e) => {
|
|
384
|
+
try {
|
|
385
|
+
const buffer = e.target?.result as ArrayBuffer;
|
|
386
|
+
const converted = await convertXlsxToCsv(buffer);
|
|
387
|
+
const next = [
|
|
388
|
+
...localAttachments,
|
|
389
|
+
{
|
|
390
|
+
uid: `${Date.now()}_${Math.random()}`,
|
|
391
|
+
name: file.name,
|
|
392
|
+
size: (file as any).size,
|
|
393
|
+
csvBySheet: converted,
|
|
394
|
+
},
|
|
395
|
+
];
|
|
396
|
+
setLocalAttachments(next);
|
|
397
|
+
onUpdateAttachments && onUpdateAttachments(next);
|
|
398
|
+
} catch {}
|
|
399
|
+
};
|
|
400
|
+
reader.readAsArrayBuffer(file);
|
|
401
|
+
return false;
|
|
402
|
+
};
|
|
403
|
+
const removeAttachment = (uid: string) => {
|
|
404
|
+
const next = localAttachments.filter((a) => a.uid !== uid);
|
|
405
|
+
setLocalAttachments(next);
|
|
406
|
+
onUpdateAttachments && onUpdateAttachments(next);
|
|
407
|
+
};
|
|
408
|
+
const submit = () => {
|
|
409
|
+
if (!canSubmit || sending) return;
|
|
410
|
+
const now = Date.now();
|
|
411
|
+
if (now - lastSubmitAt < minIntervalMs) return;
|
|
412
|
+
setLastSubmitAt(now);
|
|
413
|
+
const text = (localValue || "").trim();
|
|
414
|
+
if (!text) return;
|
|
415
|
+
const data = {
|
|
416
|
+
demand: text,
|
|
417
|
+
title: showTitle ? localTitle : "",
|
|
418
|
+
agentId: localAgentId || undefined,
|
|
419
|
+
csvData: localAttachments.reduce(
|
|
420
|
+
(acc, a) => ({ ...acc, [a.name]: a.csvBySheet }),
|
|
421
|
+
{}
|
|
422
|
+
),
|
|
423
|
+
};
|
|
424
|
+
onSubmit && onSubmit(data);
|
|
425
|
+
setLocalValue("");
|
|
426
|
+
};
|
|
427
|
+
const overlay = (
|
|
428
|
+
<div style={{ maxHeight: 400, overflow: "auto", background: "#fff" }}>
|
|
429
|
+
<ul className="agent-list">
|
|
430
|
+
{agentList.map((item) => (
|
|
431
|
+
<li key={String(item.id)}>
|
|
432
|
+
<a onClick={() => onAgentSelect(item)}>{item.name}</a>
|
|
433
|
+
</li>
|
|
434
|
+
))}
|
|
435
|
+
</ul>
|
|
436
|
+
</div>
|
|
437
|
+
);
|
|
438
|
+
return (
|
|
439
|
+
<Wrapper>
|
|
440
|
+
<div className="chat-input">
|
|
441
|
+
<div className="input-stack">
|
|
442
|
+
{localAttachments.length > 0 && (
|
|
443
|
+
<div className="attachment-bar">
|
|
444
|
+
{localAttachments.map((a) => (
|
|
445
|
+
<Tooltip
|
|
446
|
+
key={a.uid}
|
|
447
|
+
title={a.name}
|
|
448
|
+
className="attachment-card"
|
|
449
|
+
>
|
|
450
|
+
<svg style={{ width: 25, height: 25 }} viewBox="0 0 24 24">
|
|
451
|
+
<rect x="3" y="3" width="18" height="18" fill="#1f6f43" />
|
|
452
|
+
</svg>
|
|
453
|
+
<span className="name">{a.name}</span>
|
|
454
|
+
<a
|
|
455
|
+
className="remove"
|
|
456
|
+
onClick={() => removeAttachment(a.uid)}
|
|
457
|
+
>
|
|
458
|
+
×
|
|
459
|
+
</a>
|
|
460
|
+
</Tooltip>
|
|
461
|
+
))}
|
|
462
|
+
</div>
|
|
463
|
+
)}
|
|
464
|
+
{selectedAgent && (
|
|
465
|
+
<div className="agent-info">
|
|
466
|
+
<span className="name">@ {selectedAgent.name}</span>
|
|
467
|
+
<a className="remove" onClick={clearAgent}>
|
|
468
|
+
×
|
|
469
|
+
</a>
|
|
470
|
+
</div>
|
|
471
|
+
)}
|
|
472
|
+
{showTitle && (
|
|
473
|
+
<Input
|
|
474
|
+
className="title-input"
|
|
475
|
+
placeholder="请输入报告标题(可选)"
|
|
476
|
+
disabled={disabled || sending}
|
|
477
|
+
value={localTitle}
|
|
478
|
+
onChange={onTitleChange}
|
|
479
|
+
/>
|
|
480
|
+
)}
|
|
481
|
+
<Input.TextArea
|
|
482
|
+
ref={inputRef}
|
|
483
|
+
className="input textarea-stacked"
|
|
484
|
+
placeholder={placeholder}
|
|
485
|
+
disabled={disabled || sending}
|
|
486
|
+
autoSize={{ minRows: rows, maxRows: rows }}
|
|
487
|
+
value={localValue}
|
|
488
|
+
onPressEnter={onKeydown}
|
|
489
|
+
onChange={(e) => setLocalValue(e.target.value)}
|
|
490
|
+
/>
|
|
491
|
+
</div>
|
|
492
|
+
<div className="footer">
|
|
493
|
+
<div className="left">
|
|
494
|
+
<Dropdown
|
|
495
|
+
trigger={["click"]}
|
|
496
|
+
popupRender={() => overlay}
|
|
497
|
+
placement="topLeft"
|
|
498
|
+
>
|
|
499
|
+
<Tooltip title="选择助理">
|
|
500
|
+
<Button
|
|
501
|
+
className="agent-trigger"
|
|
502
|
+
onClick={(e) => e.preventDefault()}
|
|
503
|
+
>
|
|
504
|
+
@
|
|
505
|
+
</Button>
|
|
506
|
+
</Tooltip>
|
|
507
|
+
</Dropdown>
|
|
508
|
+
<div className="title-toggle">
|
|
509
|
+
<span className="label">标题</span>
|
|
510
|
+
<Switch
|
|
511
|
+
size="small"
|
|
512
|
+
checked={showTitle}
|
|
513
|
+
disabled={disabled || sending}
|
|
514
|
+
onChange={(v) => setShowTitle(v)}
|
|
515
|
+
/>
|
|
516
|
+
</div>
|
|
517
|
+
<Upload
|
|
518
|
+
multiple
|
|
519
|
+
accept={acceptXlsx}
|
|
520
|
+
beforeUpload={beforeUploadXlsx}
|
|
521
|
+
showUploadList={false}
|
|
522
|
+
disabled={disabled || sending}
|
|
523
|
+
>
|
|
524
|
+
<Tooltip title="上传 Excel 数据">
|
|
525
|
+
<Button
|
|
526
|
+
className="attach-upload"
|
|
527
|
+
icon={<PaperClipOutlined />}
|
|
528
|
+
/>
|
|
529
|
+
</Tooltip>
|
|
530
|
+
</Upload>
|
|
531
|
+
</div>
|
|
532
|
+
<div style={{ display: "flex", alignItems: "center", gap: 6 }}>
|
|
533
|
+
{!isMobile && (
|
|
534
|
+
<div className="tips">按 Enter 发送,Shift+Enter 换行</div>
|
|
535
|
+
)}
|
|
536
|
+
<a
|
|
537
|
+
className={`send-btn ${
|
|
538
|
+
!sending && localValue?.length > 0 ? "send-btn-active" : ""
|
|
539
|
+
}`}
|
|
540
|
+
onClick={submit}
|
|
541
|
+
>
|
|
542
|
+
<SendOutlined />
|
|
543
|
+
</a>
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
</div>
|
|
547
|
+
</Wrapper>
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React, { useContext, useMemo } from "react";
|
|
2
|
+
import Editor from "@monaco-editor/react";
|
|
3
|
+
import { Tooltip, Space, message } from "antd";
|
|
4
|
+
import { CopyOutlined } from "@ant-design/icons";
|
|
5
|
+
import copy from "copy-to-clipboard";
|
|
6
|
+
import { PaneHeader } from "./PaneHeader";
|
|
7
|
+
import { DesignerContext } from "../context/DesignerContext";
|
|
8
|
+
|
|
9
|
+
export const CodePanel: React.FC = () => {
|
|
10
|
+
const { schema } = useContext(DesignerContext);
|
|
11
|
+
const code = useMemo(() => JSON.stringify(schema || {}, null, 2), [schema]);
|
|
12
|
+
const handleCopy = () => {
|
|
13
|
+
if (copy(code || "")) {
|
|
14
|
+
message.success("复制成功");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return (
|
|
18
|
+
<div
|
|
19
|
+
className="code-panel"
|
|
20
|
+
style={{ display: "flex", flexDirection: "column", height: "100%" }}
|
|
21
|
+
>
|
|
22
|
+
<PaneHeader
|
|
23
|
+
title="代码"
|
|
24
|
+
extra={
|
|
25
|
+
<Space>
|
|
26
|
+
<Tooltip title="复制到剪切板">
|
|
27
|
+
<a className="toolbar" onClick={handleCopy}>
|
|
28
|
+
<CopyOutlined />
|
|
29
|
+
</a>
|
|
30
|
+
</Tooltip>
|
|
31
|
+
</Space>
|
|
32
|
+
}
|
|
33
|
+
/>
|
|
34
|
+
<div className="body" style={{ flex: "1 1 auto", display: "flex" }}>
|
|
35
|
+
<Editor
|
|
36
|
+
height="100%"
|
|
37
|
+
defaultLanguage="json"
|
|
38
|
+
value={code}
|
|
39
|
+
options={{
|
|
40
|
+
lineNumbers: "off",
|
|
41
|
+
readOnly: true,
|
|
42
|
+
minimap: { enabled: false },
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
2
|
+
import React, { useContext, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { DesignerContext } from "../context/DesignerContext";
|
|
5
|
+
import { IconFont } from "../icon/IconFont";
|
|
6
|
+
import { PluginType } from "../typing";
|
|
7
|
+
import { uuid } from "../utils";
|
|
8
|
+
import { PaneHeader } from "./PaneHeader";
|
|
9
|
+
|
|
10
|
+
const Root = styled.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
height: 100%;
|
|
14
|
+
.body {
|
|
15
|
+
flex: 1 1 auto;
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
gap: 12px;
|
|
19
|
+
padding: 12px;
|
|
20
|
+
}
|
|
21
|
+
.group-title {
|
|
22
|
+
font-size: 12px;
|
|
23
|
+
color: #ababab;
|
|
24
|
+
padding: 4px 12px;
|
|
25
|
+
}
|
|
26
|
+
.plugin-list {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-wrap: wrap;
|
|
29
|
+
gap: 20px 12px;
|
|
30
|
+
padding: 12px;
|
|
31
|
+
}
|
|
32
|
+
.plugin {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: 6px;
|
|
37
|
+
font-size: 14px;
|
|
38
|
+
width: calc(50% - 6px);
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
user-select: none;
|
|
41
|
+
}
|
|
42
|
+
.plugin .icon {
|
|
43
|
+
font-size: 24px;
|
|
44
|
+
color: #191b35;
|
|
45
|
+
}
|
|
46
|
+
.plugin .label {
|
|
47
|
+
text-overflow: ellipsis;
|
|
48
|
+
white-space: nowrap;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
font-size: 12px;
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const PluginTile: React.FC<{ plugin: PluginType }> = ({ plugin }) => {
|
|
55
|
+
const ref: React.RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 注册拖拽源:仅在设计模式下启用
|
|
59
|
+
*/
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const el = ref.current;
|
|
62
|
+
if (!el) return;
|
|
63
|
+
const cleanup = draggable({
|
|
64
|
+
element: el,
|
|
65
|
+
getInitialData: () => {
|
|
66
|
+
const item = {
|
|
67
|
+
id: uuid(),
|
|
68
|
+
type: plugin.key,
|
|
69
|
+
name: plugin.label,
|
|
70
|
+
...JSON.parse(JSON.stringify(plugin.defaultOptions || {})),
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
id: item.id,
|
|
74
|
+
data: item,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
canDrag: () => true,
|
|
78
|
+
onDragStart: () => {},
|
|
79
|
+
onDrop: () => {},
|
|
80
|
+
});
|
|
81
|
+
return () => cleanup();
|
|
82
|
+
}, []);
|
|
83
|
+
return (
|
|
84
|
+
<div className="plugin drag-move" ref={ref}>
|
|
85
|
+
<IconFont className="icon" type={plugin.icon} />
|
|
86
|
+
<div className="label">{plugin.label}</div>
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const ComponentPanel: React.FC = () => {
|
|
92
|
+
const { plugins } = useContext(DesignerContext);
|
|
93
|
+
const grouped = useMemo(() => {
|
|
94
|
+
const grouped: { group: string; items: PluginType[] }[] = [];
|
|
95
|
+
plugins.forEach((item) => {
|
|
96
|
+
const g = grouped.find((s) => s.group === item.group);
|
|
97
|
+
if (g) g.items.push(item);
|
|
98
|
+
else grouped.push({ group: item.group, items: [item] });
|
|
99
|
+
});
|
|
100
|
+
return grouped;
|
|
101
|
+
}, [plugins]);
|
|
102
|
+
return (
|
|
103
|
+
<Root className="component-panel">
|
|
104
|
+
<PaneHeader title="组件库" />
|
|
105
|
+
<div className="body">
|
|
106
|
+
{grouped.map((group) => (
|
|
107
|
+
<div className="plugin-group" key={group.group}>
|
|
108
|
+
<div className="group-title">{group.group}</div>
|
|
109
|
+
<div className="plugin-list">
|
|
110
|
+
{group.items.map((item) => (
|
|
111
|
+
<PluginTile key={item.key} plugin={item} />
|
|
112
|
+
))}
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
))}
|
|
116
|
+
</div>
|
|
117
|
+
</Root>
|
|
118
|
+
);
|
|
119
|
+
};
|