@baishuyun/ai-design 2.1.0-alpha.0 → 2.1.0-alpha.2
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/.storybook/main.ts +31 -31
- package/.storybook/preview.ts +16 -16
- package/CHANGELOG.md +530 -512
- package/components.json +22 -22
- package/package.json +5 -5
- package/scripts/strip-layers.cjs +41 -41
- package/src/components/abs-fullscreen-gradient-bg.tsx +35 -35
- package/src/components/agent-helper/agent-category-select-menu/index.tsx +57 -57
- package/src/components/agent-helper/agent-entry-card/index.tsx +94 -94
- package/src/components/agent-helper/agent-helper-card/index.tsx +179 -179
- package/src/components/agent-helper/agent-helper-card-list/index.tsx +59 -59
- package/src/components/agent-helper/agent-helper-main-layout/index.tsx +60 -60
- package/src/components/agent-helper/agent-sort-select/index.tsx +89 -89
- package/src/components/agent-helper/agent-tag/index.tsx +29 -29
- package/src/components/agent-helper/app-select/index.tsx +559 -559
- package/src/components/agent-helper/condition-group/index.tsx +75 -75
- package/src/components/agent-helper/condition-input/index.tsx +233 -233
- package/src/components/agent-helper/condition-item/index.tsx +237 -237
- package/src/components/agent-helper/condition-quantifier-select/index.tsx +142 -142
- package/src/components/agent-helper/condition-trigger-description/index.tsx +49 -49
- package/src/components/agent-helper/date-picker/calendar-panel.tsx +164 -164
- package/src/components/agent-helper/date-picker/date-input.tsx +91 -91
- package/src/components/agent-helper/date-picker/date-picker.tsx +327 -327
- package/src/components/agent-helper/date-picker/footer-panel.tsx +44 -44
- package/src/components/agent-helper/date-picker/index.ts +3 -3
- package/src/components/agent-helper/date-picker/month-panel.tsx +82 -82
- package/src/components/agent-helper/date-picker/time-panel.tsx +146 -146
- package/src/components/agent-helper/date-picker/types.ts +37 -37
- package/src/components/agent-helper/date-picker/utils.ts +121 -121
- package/src/components/agent-helper/date-picker/year-panel.tsx +86 -86
- package/src/components/agent-helper/exec-log-filter/index.tsx +232 -232
- package/src/components/agent-helper/field-edit-preference-select/index.tsx +291 -291
- package/src/components/agent-helper/field-select/index.tsx +466 -466
- package/src/components/agent-helper/field-value-input/china-address-data.ts +4117 -4117
- package/src/components/agent-helper/field-value-input/display.tsx +71 -71
- package/src/components/agent-helper/field-value-input/icons.tsx +38 -38
- package/src/components/agent-helper/field-value-input/index.tsx +144 -144
- package/src/components/agent-helper/field-value-input/inputs.tsx +247 -247
- package/src/components/agent-helper/field-value-input/picker-inputs.tsx +1144 -1141
- package/src/components/agent-helper/flow-node-action-trigger-select/index.tsx +57 -57
- package/src/components/agent-helper/form-action-trigger-select/index.tsx +60 -60
- package/src/components/agent-helper/form-divider/index.tsx +44 -44
- package/src/components/agent-helper/form-select/index.tsx +732 -732
- package/src/components/agent-helper/monthdays-select/index.tsx +378 -378
- package/src/components/agent-helper/offset-preference-select/index.tsx +268 -268
- package/src/components/agent-helper/offset-type-select/index.tsx +66 -66
- package/src/components/agent-helper/offset-unit-select/index.tsx +54 -54
- package/src/components/agent-helper/placeholder-card/index.tsx +75 -75
- package/src/components/agent-helper/prompt-input/index.tsx +646 -646
- package/src/components/agent-helper/relational-operator-select/index.tsx +179 -179
- package/src/components/agent-helper/repeat-by-type-select/index.tsx +53 -53
- package/src/components/agent-helper/repeat-preference-select/index.tsx +162 -162
- package/src/components/agent-helper/repeat-preference-type-select/index.tsx +58 -58
- package/src/components/agent-helper/search-input/index.tsx +35 -35
- package/src/components/agent-helper/table/index.tsx +114 -114
- package/src/components/agent-helper/trigger-select/index.tsx +121 -121
- package/src/components/agent-helper/trigger-time-preference-select/index.tsx +189 -189
- package/src/components/agent-helper/trigger-time-source-type-select/index.tsx +53 -53
- package/src/components/agent-helper/weekdays-select/index.tsx +230 -230
- package/src/components/agent-scroll-selector.tsx +193 -193
- package/src/components/agent-select.tsx +154 -154
- package/src/components/attachment-part-group.tsx +35 -35
- package/src/components/attachment-part.tsx +296 -296
- package/src/components/attachments-previewer.tsx +272 -272
- package/src/components/base-button.tsx +49 -49
- package/src/components/border-animation.tsx +107 -107
- package/src/components/border-color-animation.tsx +66 -66
- package/src/components/bot-avatar-name.tsx +36 -36
- package/src/components/bot-icon.tsx +23 -23
- package/src/components/bs-entry-select/app-group-folder.tsx +61 -61
- package/src/components/bs-entry-select/bs-entry-select.tsx +296 -296
- package/src/components/bs-entry-select/build-tree.ts +265 -265
- package/src/components/bs-entry-select/entry-item.tsx +45 -45
- package/src/components/bs-entry-select/entry-popover.tsx +99 -99
- package/src/components/bs-entry-select/index.ts +7 -7
- package/src/components/bs-entry-select/other-app-section.tsx +96 -96
- package/src/components/bs-entry-select/scroll-slider.tsx +872 -872
- package/src/components/bs-entry-select/search-input.tsx +4 -4
- package/src/components/bs-entry-select/tree-item-node.tsx +84 -84
- package/src/components/bs-entry-select/types.ts +46 -46
- package/src/components/bs-icons.tsx +1362 -1362
- package/src/components/card-field.tsx +23 -23
- package/src/components/card.tsx +36 -36
- package/src/components/chat-area-header.tsx +65 -65
- package/src/components/check-card.tsx +77 -77
- package/src/components/circle-checker.tsx +66 -66
- package/src/components/collapsible-txt-msg.tsx +80 -75
- package/src/components/collapsible.tsx +9 -9
- package/src/components/confirm-dialog.tsx +139 -139
- package/src/components/date-range-picker.tsx +91 -91
- package/src/components/fake-bot-msg.tsx +53 -51
- package/src/components/field-checker-list-msg.tsx +146 -146
- package/src/components/field-checker.tsx +185 -185
- package/src/components/field-icon.tsx +13 -13
- package/src/components/field-value-checker.tsx +116 -116
- package/src/components/fields-design-info-table.tsx +160 -160
- package/src/components/fields-generating-indicator.tsx +95 -95
- package/src/components/fields-portal.tsx +18 -18
- package/src/components/fields-previewer.tsx +216 -216
- package/src/components/font-icon.tsx +65 -65
- package/src/components/form-info-editor.tsx +263 -263
- package/src/components/formula-tag.tsx +32 -32
- package/src/components/generate-animation.tsx +56 -56
- package/src/components/icon-btn.tsx +43 -43
- package/src/components/icon-card.tsx +67 -67
- package/src/components/icons/calendar-icon.tsx +5 -5
- package/src/components/icons/clear-all-icon.tsx +5 -5
- package/src/components/icons/empty-agent-icon.tsx +93 -93
- package/src/components/icons/empty-table-icon.tsx +104 -104
- package/src/components/icons/grids-icon.tsx +5 -5
- package/src/components/img-part.tsx +27 -27
- package/src/components/legacy-slot.tsx +110 -110
- package/src/components/line-checker.tsx +168 -168
- package/src/components/linear-gradient-border-btn.tsx +48 -48
- package/src/components/linear-gradient-color-bg-animation.tsx +103 -103
- package/src/components/memoized-markdown.tsx +32 -32
- package/src/components/message-content.tsx +21 -21
- package/src/components/number-part.tsx +46 -46
- package/src/components/office-container.tsx +289 -289
- package/src/components/option-item.tsx +27 -27
- package/src/components/output-config-editor.tsx +478 -478
- package/src/components/previewer-header.tsx +270 -270
- package/src/components/primary-confirm-btn.tsx +58 -58
- package/src/components/primary-entry-btn.tsx +48 -48
- package/src/components/radio-card.tsx +63 -63
- package/src/components/scroll-to-bottom-btn.tsx +28 -28
- package/src/components/split-line.tsx +9 -9
- package/src/components/square-checker.tsx +87 -87
- package/src/components/subform-fields-value-checker.tsx +184 -184
- package/src/components/tab-radio-group.tsx +83 -83
- package/src/components/tooltip.tsx +53 -53
- package/src/components/ui/button.tsx +51 -51
- package/src/components/ui/calendar.tsx +57 -57
- package/src/components/ui/dialog.tsx +104 -104
- package/src/components/ui/drawer.tsx +279 -279
- package/src/components/ui/form.tsx +202 -202
- package/src/components/ui/icons.tsx +1267 -1267
- package/src/components/ui/input.tsx +28 -28
- package/src/components/ui/label.tsx +30 -30
- package/src/components/ui/popover.tsx +85 -85
- package/src/components/ui/select.tsx +236 -236
- package/src/components/ui/spinner.tsx +17 -17
- package/src/components/ui/switch.tsx +33 -33
- package/src/components/ui/tabs.tsx +62 -62
- package/src/components/ui/textarea.tsx +28 -28
- package/src/components/ui/tooltip.tsx +53 -53
- package/src/components/user-txt-msg-bubble.tsx +47 -47
- package/src/components/warning-msg.tsx +27 -27
- package/src/const/ui.ts +119 -119
- package/src/css.d.ts +4 -4
- package/src/hooks/use-column-appear.ts +78 -78
- package/src/hooks/use-portal-container.ts +27 -27
- package/src/hooks/use-resizable-width.ts +129 -129
- package/src/hooks/use-select-popover-position.ts +74 -74
- package/src/hooks/use-shadow.ts +127 -127
- package/src/index.ts +226 -226
- package/src/lib/utils.ts +138 -138
- package/src/stories/AbsFullscreenGradientBg.stories.tsx +36 -36
- package/src/stories/AgentCategorySelectMenu.stories.tsx +33 -33
- package/src/stories/AgentEntryCard.stories.tsx +90 -90
- package/src/stories/AgentHelperCard.stories.tsx +105 -105
- package/src/stories/AgentHelperCardList.stories.tsx +120 -120
- package/src/stories/AgentHelperMainLayout.stories.tsx +71 -71
- package/src/stories/AgentScrollSelector.stories.tsx +95 -95
- package/src/stories/AgentSelect.stories.tsx +134 -134
- package/src/stories/AgentTag.stories.tsx +44 -44
- package/src/stories/AppSelect.stories.tsx +250 -250
- package/src/stories/AttachmentPart.stories.tsx +122 -122
- package/src/stories/AttachmentPartGroup.stories.tsx +152 -152
- package/src/stories/AttachmentsPreviewer.stories.tsx +306 -306
- package/src/stories/BaseButton.stories.tsx +33 -33
- package/src/stories/BorderAnimation.stories.tsx +116 -116
- package/src/stories/BorderColorAnimation.stories.tsx +63 -63
- package/src/stories/BotAvatarAndName.stories.ts +24 -24
- package/src/stories/BotIcon.stories.ts +22 -22
- package/src/stories/BsConditionInput.stories.tsx +460 -460
- package/src/stories/BsEntrySelect.stories.tsx +343 -343
- package/src/stories/BsTooltip.stories.tsx +32 -32
- package/src/stories/Card.stories.tsx +28 -28
- package/src/stories/CardField.stories.tsx +87 -87
- package/src/stories/ChatAreaHeader.stories.ts +26 -26
- package/src/stories/CheckCard.stories.tsx +114 -114
- package/src/stories/CircleChecker.stories.tsx +89 -89
- package/src/stories/CollapsibleTextMsg.stories.ts +44 -44
- package/src/stories/ConditionGroup.stories.tsx +216 -216
- package/src/stories/ConditionInput.stories.tsx +502 -502
- package/src/stories/ConditionItem.stories.tsx +163 -163
- package/src/stories/ConditonQuantifierSelect.stories.tsx +54 -54
- package/src/stories/ConditonTriggerDescription.stories.tsx +61 -61
- package/src/stories/ConfirmDialog.stories.tsx +123 -123
- package/src/stories/DataTable.stories.tsx +191 -191
- package/src/stories/DatePicker.stories.tsx +174 -174
- package/src/stories/ExecLogFilter.stories.tsx +145 -145
- package/src/stories/FakeBotMsg.stories.tsx +36 -36
- package/src/stories/FieldEditPreferenceSelect.stories.tsx +161 -161
- package/src/stories/FieldSelect.stories.tsx +228 -228
- package/src/stories/FieldValueInput.stories.tsx +442 -442
- package/src/stories/FlowNodeActionTriggerSelect.stories.tsx +80 -80
- package/src/stories/Form.stories.tsx +302 -302
- package/src/stories/FormActionTriggerSelect.stories.tsx +80 -80
- package/src/stories/FormDivider.stories.tsx +31 -31
- package/src/stories/FormInfoEditor.stories.tsx +173 -173
- package/src/stories/FormSelect.stories.tsx +222 -222
- package/src/stories/FormulaTag.stories.tsx +68 -68
- package/src/stories/GenerateAnimation.stories.ts +20 -20
- package/src/stories/IconBtn.stories.tsx +32 -32
- package/src/stories/IconCard.stories.tsx +35 -35
- package/src/stories/IconLib.tsx +45 -45
- package/src/stories/Icons.stories.ts +22 -22
- package/src/stories/ImgMsgPart.stories.tsx +42 -42
- package/src/stories/Input.stories.tsx +102 -102
- package/src/stories/Label.stories.tsx +66 -66
- package/src/stories/LegacySlot.stories.tsx +56 -56
- package/src/stories/LineChecker.stories.tsx +133 -133
- package/src/stories/LinearGradientBorderBtn.stories.tsx +86 -86
- package/src/stories/LinearGradientColorBgAnimation.stories.tsx +60 -60
- package/src/stories/MemoizedMarkdown.stories.tsx +102 -102
- package/src/stories/MessageContent.stories.tsx +36 -36
- package/src/stories/MonthdaysSelect.stories.tsx +78 -78
- package/src/stories/NumbersMsgPart.stories.tsx +42 -42
- package/src/stories/OfficeContainer.stories.tsx +287 -287
- package/src/stories/OffsetPreferenceSelect.stories.tsx +118 -118
- package/src/stories/OffsetTypeSelect.stories.tsx +75 -75
- package/src/stories/OffsetUnitSelect.stories.tsx +61 -61
- package/src/stories/OptionItem.stories.tsx +77 -77
- package/src/stories/OutputConfigEditor.stories.tsx +96 -96
- package/src/stories/PlaceholderCard.stories.tsx +35 -35
- package/src/stories/PreviewerHeader.stories.tsx +91 -91
- package/src/stories/PrimaryConfirmBtn.stories.tsx +60 -60
- package/src/stories/PrimaryEntryBtn.stories.tsx +74 -74
- package/src/stories/PromptInput.stories.tsx +228 -228
- package/src/stories/RadioCard.stories.tsx +103 -103
- package/src/stories/RelationalOperatorSelect.stories.tsx +61 -61
- package/src/stories/RepeatByTypeSelect.stories.tsx +58 -58
- package/src/stories/RepeatPreferenceSelect.stories.tsx +107 -107
- package/src/stories/RepeatPreferenceTypeSelect.stories.tsx +58 -58
- package/src/stories/ScrollToBottom.stories.tsx +24 -24
- package/src/stories/SearchInput.stories.tsx +50 -50
- package/src/stories/Select.stories.tsx +128 -128
- package/src/stories/SplitLine.stories.tsx +40 -40
- package/src/stories/SquareChecker.stories.tsx +96 -96
- package/src/stories/TabRadioGroup.stories.tsx +84 -84
- package/src/stories/Textarea.stories.tsx +67 -67
- package/src/stories/TriggerSelect.stories.tsx +48 -48
- package/src/stories/TriggerTimePreferenceSelect.stories.tsx +106 -106
- package/src/stories/TriggerTimeSourceTypeSelect.stories.tsx +68 -68
- package/src/stories/UserTextMsgBubble.stories.ts +24 -24
- package/src/stories/WarningMessage.stories.tsx +23 -23
- package/src/stories/WeekdaysSelect.stories.tsx +66 -66
- package/src/stories/assets/demo.css +539 -539
- package/src/stories/assets/demo_index.html +7988 -7988
- package/src/stories/assets/iconfont.css +1377 -1377
- package/src/stories/assets/iconfont.json +2382 -2382
- package/src/stories/assets/iconfont.svg +697 -697
- package/src/stories/collapsible.stories.tsx +47 -47
- package/src/stories/drawer.stories.tsx +196 -196
- package/src/stories/field-checker-list-msg.stories.tsx +95 -95
- package/src/stories/field-checker.stories.tsx +117 -117
- package/src/stories/field-icon.stories.tsx +70 -70
- package/src/stories/field-value-checker.stories.tsx +113 -113
- package/src/stories/fields-design-info-table.stories.tsx +203 -203
- package/src/stories/fields-generating.stories.tsx +41 -41
- package/src/stories/fields-previewer.stories.tsx +77 -77
- package/src/stories/subform-fields-value-checker.stories.tsx +98 -98
- package/src/style.css +226 -226
- package/src/types.ts +8 -8
- package/style.css +3652 -3652
- package/tsconfig.json +13 -13
- package/vite.config.ts +44 -44
|
@@ -1,1141 +1,1144 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect, useRef } from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
IFieldValueService,
|
|
4
|
-
IUserOption,
|
|
5
|
-
IDeptOption,
|
|
6
|
-
ILinkDataOption,
|
|
7
|
-
IAddressOption,
|
|
8
|
-
ILocationOption,
|
|
9
|
-
} from '@baishuyun/types';
|
|
10
|
-
import { Popover, PopoverTrigger, PopoverContent } from '../../ui/popover';
|
|
11
|
-
import { FieldWrapper, type FieldValueInputProps } from './index';
|
|
12
|
-
import { DropdownChevron, ClearIcon, CloseIcon, CheckIcon } from './icons';
|
|
13
|
-
import { SearchIcon } from '../../bs-icons';
|
|
14
|
-
import { ClearAllIcon } from '../../icons/clear-all-icon';
|
|
15
|
-
import { cn } from '../../../lib/utils';
|
|
16
|
-
import { transCls } from '../../../const/ui';
|
|
17
|
-
import { chinaAddressData } from './china-address-data';
|
|
18
|
-
|
|
19
|
-
const inputBaseCls =
|
|
20
|
-
'h-[34px] px-[10px] py-[7px] rounded-[4px] bg-white border text-[14px] text-[#030303] placeholder:text-[#999999] focus:outline-none focus:border-[#0265FF] w-full disabled:bg-[#EFF0F6] disabled:cursor-not-allowed';
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
label: string;
|
|
24
|
-
value: string | number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getItems(field: FieldValueInputProps['field']):
|
|
28
|
-
return field.widget?.items
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
<
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
case '
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const [
|
|
273
|
-
const [
|
|
274
|
-
const [
|
|
275
|
-
const [
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
onChange?.(
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
'
|
|
410
|
-
'
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
<span
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
<
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
<
|
|
459
|
-
{
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
)}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const [
|
|
546
|
-
const [
|
|
547
|
-
const [
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
const
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
'
|
|
611
|
-
'
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
<span
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
<
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
const
|
|
729
|
-
const
|
|
730
|
-
const
|
|
731
|
-
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const
|
|
745
|
-
? chinaAddressData[selectedProvince]
|
|
746
|
-
: [];
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
{
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
<div
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
<div
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
<div
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
const [
|
|
956
|
-
const
|
|
957
|
-
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
<
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
'
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
const [
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1055
|
-
const
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
<
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
'
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1
|
+
import { useState, useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
IFieldValueService,
|
|
4
|
+
IUserOption,
|
|
5
|
+
IDeptOption,
|
|
6
|
+
ILinkDataOption,
|
|
7
|
+
IAddressOption,
|
|
8
|
+
ILocationOption,
|
|
9
|
+
} from '@baishuyun/types';
|
|
10
|
+
import { Popover, PopoverTrigger, PopoverContent } from '../../ui/popover';
|
|
11
|
+
import { FieldWrapper, type FieldValueInputProps } from './index';
|
|
12
|
+
import { DropdownChevron, ClearIcon, CloseIcon, CheckIcon } from './icons';
|
|
13
|
+
import { SearchIcon } from '../../bs-icons';
|
|
14
|
+
import { ClearAllIcon } from '../../icons/clear-all-icon';
|
|
15
|
+
import { cn } from '../../../lib/utils';
|
|
16
|
+
import { transCls } from '../../../const/ui';
|
|
17
|
+
import { chinaAddressData } from './china-address-data';
|
|
18
|
+
|
|
19
|
+
const inputBaseCls =
|
|
20
|
+
'h-[34px] px-[10px] py-[7px] rounded-[4px] bg-white border text-[14px] text-[#030303] placeholder:text-[#999999] focus:outline-none focus:border-[#0265FF] w-full disabled:bg-[#EFF0F6] disabled:cursor-not-allowed';
|
|
21
|
+
|
|
22
|
+
type PickerItem = {
|
|
23
|
+
label: string;
|
|
24
|
+
value: string | number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function getItems(field: FieldValueInputProps['field']): PickerItem[] {
|
|
28
|
+
return (field.widget?.items ?? [])
|
|
29
|
+
.map((it) => {
|
|
30
|
+
if ('text' in it) {
|
|
31
|
+
return { label: it.text, value: it.value };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return null;
|
|
35
|
+
})
|
|
36
|
+
.filter((item): item is PickerItem => item !== null);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function usePortalContainer(attr: string) {
|
|
40
|
+
const [portalContainer, setPortalContainer] = useState<HTMLElement | null>(null);
|
|
41
|
+
const setTriggerRef = useCallback(
|
|
42
|
+
(node: HTMLButtonElement | null) => {
|
|
43
|
+
if (!node) { setPortalContainer(null); return; }
|
|
44
|
+
const rootNode = node.getRootNode();
|
|
45
|
+
if (rootNode instanceof ShadowRoot) {
|
|
46
|
+
const existing = rootNode.querySelector<HTMLElement>(`[${attr}]`);
|
|
47
|
+
if (existing) { setPortalContainer(existing); return; }
|
|
48
|
+
const container = document.createElement('div');
|
|
49
|
+
container.setAttribute(attr, 'true');
|
|
50
|
+
rootNode.appendChild(container);
|
|
51
|
+
setPortalContainer(container);
|
|
52
|
+
} else {
|
|
53
|
+
setPortalContainer(null);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
[attr],
|
|
57
|
+
);
|
|
58
|
+
return { portalContainer, setTriggerRef };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ── ComboInput (combo / linkdata / linkquery) ───────────────────────
|
|
62
|
+
|
|
63
|
+
export function ComboInput({ field, value, onChange, disabled, service, showLabel, showDescription }: FieldValueInputProps) {
|
|
64
|
+
const [open, setOpen] = useState(false);
|
|
65
|
+
const [asyncItems, setAsyncItems] = useState<ILinkDataOption[]>([]);
|
|
66
|
+
const [loading, setLoading] = useState(false);
|
|
67
|
+
const { portalContainer, setTriggerRef } = usePortalContainer('data-bs-field-value-input-portal');
|
|
68
|
+
|
|
69
|
+
const staticItems = getItems(field);
|
|
70
|
+
const hasAsync = !!(field.widget?.type === 'linkdata' || field.widget?.type === 'linkquery');
|
|
71
|
+
|
|
72
|
+
const selectedLabel =
|
|
73
|
+
staticItems.find((it) => it.value === value)?.label ??
|
|
74
|
+
asyncItems.find((it) => it.value === value)?.label ??
|
|
75
|
+
'';
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (hasAsync && open && service?.fetchLinkData) {
|
|
79
|
+
setLoading(true);
|
|
80
|
+
service.fetchLinkData(field.widget?.widgetName ?? '').then((data) => {
|
|
81
|
+
setAsyncItems(data);
|
|
82
|
+
setLoading(false);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}, [hasAsync, open, field.widget?.widgetName, service]);
|
|
86
|
+
|
|
87
|
+
const displayItems = hasAsync ? asyncItems : staticItems;
|
|
88
|
+
|
|
89
|
+
const handleSelect = useCallback(
|
|
90
|
+
(v: string | number) => {
|
|
91
|
+
onChange?.(v);
|
|
92
|
+
setOpen(false);
|
|
93
|
+
},
|
|
94
|
+
[onChange],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<FieldWrapper field={field} showLabel={showLabel} showDescription={showDescription}>
|
|
99
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
100
|
+
<PopoverTrigger asChild>
|
|
101
|
+
<button
|
|
102
|
+
ref={setTriggerRef}
|
|
103
|
+
type="button"
|
|
104
|
+
disabled={disabled}
|
|
105
|
+
className={cn(
|
|
106
|
+
'flex items-center justify-between gap-[10px]',
|
|
107
|
+
inputBaseCls,
|
|
108
|
+
'text-left cursor-pointer',
|
|
109
|
+
open ? 'border-[#0265FF]' : 'border-[#E0E0E0] hover:border-[#0265FF]',
|
|
110
|
+
)}
|
|
111
|
+
>
|
|
112
|
+
<span className={cn('truncate', !selectedLabel && 'text-[#999999]')}>
|
|
113
|
+
{selectedLabel || (field.description ?? `请选择${field.label}`)}
|
|
114
|
+
</span>
|
|
115
|
+
<DropdownChevron open={open} />
|
|
116
|
+
</button>
|
|
117
|
+
</PopoverTrigger>
|
|
118
|
+
<PopoverContent
|
|
119
|
+
align="start"
|
|
120
|
+
sideOffset={4}
|
|
121
|
+
portalContainer={portalContainer}
|
|
122
|
+
className="!border-0 rounded-[10px] shadow-[0px_0px_5px_rgba(0,0,0,0.04)] p-[4px]"
|
|
123
|
+
style={{ width: 'var(--radix-popover-trigger-width)' }}
|
|
124
|
+
>
|
|
125
|
+
{loading ? (
|
|
126
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">加载中...</div>
|
|
127
|
+
) : displayItems.length === 0 ? (
|
|
128
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">暂无数据</div>
|
|
129
|
+
) : (
|
|
130
|
+
<div className="flex flex-col gap-0 max-h-[240px] overflow-y-auto">
|
|
131
|
+
{displayItems.map((item) => (
|
|
132
|
+
<button
|
|
133
|
+
key={item.value}
|
|
134
|
+
type="button"
|
|
135
|
+
onClick={() => handleSelect(item.value)}
|
|
136
|
+
className={cn(
|
|
137
|
+
'h-[34px] px-[10px] rounded-[4px] text-left text-[14px] leading-[normal]',
|
|
138
|
+
value === item.value
|
|
139
|
+
? 'bg-[#F0F6FF] text-[#0265FF]'
|
|
140
|
+
: 'text-[#030303] hover:bg-[#EFF0F6]',
|
|
141
|
+
transCls,
|
|
142
|
+
)}
|
|
143
|
+
>
|
|
144
|
+
{item.label}
|
|
145
|
+
</button>
|
|
146
|
+
))}
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
</PopoverContent>
|
|
150
|
+
</Popover>
|
|
151
|
+
</FieldWrapper>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ── CheckboxGroupInput ──────────────────────────────────────────────
|
|
156
|
+
|
|
157
|
+
export function CheckboxGroupInput({ field, value, onChange, disabled, showLabel, showDescription }: FieldValueInputProps) {
|
|
158
|
+
const items = getItems(field);
|
|
159
|
+
const selectedValues: string[] = Array.isArray(value) ? value.map(String) : [];
|
|
160
|
+
|
|
161
|
+
const toggle = useCallback(
|
|
162
|
+
(itemValue: string) => {
|
|
163
|
+
const next = selectedValues.includes(itemValue)
|
|
164
|
+
? selectedValues.filter((v) => v !== itemValue)
|
|
165
|
+
: [...selectedValues, itemValue];
|
|
166
|
+
onChange?.(next);
|
|
167
|
+
},
|
|
168
|
+
[selectedValues, onChange],
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<FieldWrapper field={field} showLabel={showLabel} showDescription={showDescription}>
|
|
173
|
+
<div className="flex flex-col gap-[8px]">
|
|
174
|
+
{items.map((item) => {
|
|
175
|
+
const checked = selectedValues.includes(String(item.value));
|
|
176
|
+
return (
|
|
177
|
+
<label
|
|
178
|
+
key={item.value}
|
|
179
|
+
className={cn(
|
|
180
|
+
'flex items-center gap-[8px] cursor-pointer text-[14px] text-[#030303]',
|
|
181
|
+
disabled && 'cursor-not-allowed opacity-50',
|
|
182
|
+
)}
|
|
183
|
+
>
|
|
184
|
+
<div
|
|
185
|
+
className={cn(
|
|
186
|
+
'w-[16px] h-[16px] rounded-[2px] flex items-center justify-center shrink-0 border',
|
|
187
|
+
transCls,
|
|
188
|
+
checked ? 'bg-[#0265FF] border-[#0265FF]' : 'bg-white border-[#CCCCCC]',
|
|
189
|
+
!disabled && 'hover:border-[#0265FF]',
|
|
190
|
+
)}
|
|
191
|
+
>
|
|
192
|
+
{checked && <CheckIcon />}
|
|
193
|
+
</div>
|
|
194
|
+
<input
|
|
195
|
+
type="checkbox"
|
|
196
|
+
checked={checked}
|
|
197
|
+
onChange={() => toggle(String(item.value))}
|
|
198
|
+
disabled={disabled}
|
|
199
|
+
className="sr-only"
|
|
200
|
+
/>
|
|
201
|
+
{item.label}
|
|
202
|
+
</label>
|
|
203
|
+
);
|
|
204
|
+
})}
|
|
205
|
+
</div>
|
|
206
|
+
</FieldWrapper>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ── RadioGroupInput ─────────────────────────────────────────────────
|
|
211
|
+
|
|
212
|
+
export function RadioGroupInput({ field, value, onChange, disabled, showLabel, showDescription }: FieldValueInputProps) {
|
|
213
|
+
const items = getItems(field);
|
|
214
|
+
return (
|
|
215
|
+
<FieldWrapper field={field} showLabel={showLabel} showDescription={showDescription}>
|
|
216
|
+
<div className="flex flex-col gap-[8px]">
|
|
217
|
+
{items.map((item) => {
|
|
218
|
+
const checked = String(value) === String(item.value);
|
|
219
|
+
return (
|
|
220
|
+
<label
|
|
221
|
+
key={item.value}
|
|
222
|
+
className={cn(
|
|
223
|
+
'flex items-center gap-[8px] cursor-pointer text-[14px] text-[#030303]',
|
|
224
|
+
disabled && 'cursor-not-allowed opacity-50',
|
|
225
|
+
)}
|
|
226
|
+
>
|
|
227
|
+
<div
|
|
228
|
+
className={cn(
|
|
229
|
+
'w-[16px] h-[16px] rounded-full flex items-center justify-center shrink-0 border',
|
|
230
|
+
transCls,
|
|
231
|
+
checked ? 'border-[#0265FF]' : 'border-[#CCCCCC]',
|
|
232
|
+
!disabled && 'hover:border-[#0265FF]',
|
|
233
|
+
)}
|
|
234
|
+
>
|
|
235
|
+
{checked && <div className="w-[8px] h-[8px] rounded-full bg-[#0265FF]" />}
|
|
236
|
+
</div>
|
|
237
|
+
<input
|
|
238
|
+
type="radio"
|
|
239
|
+
checked={checked}
|
|
240
|
+
onChange={() => onChange?.(item.value)}
|
|
241
|
+
disabled={disabled}
|
|
242
|
+
className="sr-only"
|
|
243
|
+
/>
|
|
244
|
+
{item.label}
|
|
245
|
+
</label>
|
|
246
|
+
);
|
|
247
|
+
})}
|
|
248
|
+
</div>
|
|
249
|
+
</FieldWrapper>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ── AsyncPicker (user / dept / usergroup / deptgroup) ──────────────
|
|
254
|
+
|
|
255
|
+
type PickerKind = 'user' | 'dept' | 'usergroup' | 'deptgroup';
|
|
256
|
+
|
|
257
|
+
interface AsyncPickerProps extends FieldValueInputProps {
|
|
258
|
+
kind: PickerKind;
|
|
259
|
+
multiple?: boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function getSearchFn(kind: PickerKind, service?: IFieldValueService) {
|
|
263
|
+
switch (kind) {
|
|
264
|
+
case 'user': return service?.searchUsers;
|
|
265
|
+
case 'dept': return service?.searchDepts;
|
|
266
|
+
case 'usergroup': return service?.searchUserGroups;
|
|
267
|
+
case 'deptgroup': return service?.searchDeptGroups;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function AsyncPicker({ field, value, onChange, disabled, service, kind, multiple = false, showLabel, showDescription }: AsyncPickerProps) {
|
|
272
|
+
const [open, setOpen] = useState(false);
|
|
273
|
+
const [keyword, setKeyword] = useState('');
|
|
274
|
+
const [options, setOptions] = useState<Array<IUserOption | IDeptOption>>([]);
|
|
275
|
+
const [loading, setLoading] = useState(false);
|
|
276
|
+
const [selectedLabel, setSelectedLabel] = useState('');
|
|
277
|
+
const [nameMap, setNameMap] = useState<Record<string, string>>({});
|
|
278
|
+
const [isHovering, setIsHovering] = useState(false);
|
|
279
|
+
const { portalContainer, setTriggerRef } = usePortalContainer('data-bs-field-value-picker-portal');
|
|
280
|
+
|
|
281
|
+
const searchFn = getSearchFn(kind, service);
|
|
282
|
+
|
|
283
|
+
const selectedIds: string[] = multiple
|
|
284
|
+
? (Array.isArray(value) ? value.map(String) : [])
|
|
285
|
+
: [];
|
|
286
|
+
const selectedIdSet = new Set(selectedIds);
|
|
287
|
+
|
|
288
|
+
// Resolve labels for existing values
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
if (multiple) {
|
|
291
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
292
|
+
setNameMap({});
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (service?.searchUsers && kind === 'user') {
|
|
296
|
+
service.searchUsers('', { field: fieldName }).then((users) => {
|
|
297
|
+
const map: Record<string, string> = {};
|
|
298
|
+
users.forEach((u) => {
|
|
299
|
+
if (value.includes(u.id)) map[u.id] = u.name;
|
|
300
|
+
});
|
|
301
|
+
setNameMap(map);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
if (!value || value === '') {
|
|
306
|
+
setSelectedLabel('');
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (service?.searchUsers && kind === 'user') {
|
|
310
|
+
service.searchUsers('', { field: fieldName }).then((users) => {
|
|
311
|
+
const found = users.find((u) => u.id === value);
|
|
312
|
+
if (found) setSelectedLabel(found.name);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}, [value, service, kind, multiple]);
|
|
317
|
+
|
|
318
|
+
const fieldName = field.widget?.widgetName || "";
|
|
319
|
+
const doSearch = useCallback(
|
|
320
|
+
async (kw: string) => {
|
|
321
|
+
if (!searchFn) return;
|
|
322
|
+
setLoading(true);
|
|
323
|
+
try {
|
|
324
|
+
const results = await searchFn(kw, { field: fieldName });
|
|
325
|
+
setOptions(results);
|
|
326
|
+
} finally {
|
|
327
|
+
setLoading(false);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
[searchFn],
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
if (open) doSearch(keyword);
|
|
335
|
+
}, [open, keyword, doSearch]);
|
|
336
|
+
|
|
337
|
+
const handleSelect = useCallback(
|
|
338
|
+
(opt: IUserOption | IDeptOption) => {
|
|
339
|
+
if (multiple) {
|
|
340
|
+
const next = selectedIdSet.has(opt.id)
|
|
341
|
+
? selectedIds.filter((id) => id !== opt.id)
|
|
342
|
+
: [...selectedIds, opt.id];
|
|
343
|
+
onChange?.(next);
|
|
344
|
+
setNameMap((prev) => {
|
|
345
|
+
if (selectedIdSet.has(opt.id)) {
|
|
346
|
+
const nextMap = { ...prev };
|
|
347
|
+
delete nextMap[opt.id];
|
|
348
|
+
return nextMap;
|
|
349
|
+
}
|
|
350
|
+
return { ...prev, [opt.id]: opt.name };
|
|
351
|
+
});
|
|
352
|
+
} else {
|
|
353
|
+
onChange?.(opt.id);
|
|
354
|
+
setSelectedLabel(opt.name);
|
|
355
|
+
setOpen(false);
|
|
356
|
+
setKeyword('');
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
[onChange, multiple, selectedIds, selectedIdSet],
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
const handleClear = useCallback(() => {
|
|
363
|
+
if (multiple) {
|
|
364
|
+
onChange?.([]);
|
|
365
|
+
setNameMap({});
|
|
366
|
+
} else {
|
|
367
|
+
onChange?.('');
|
|
368
|
+
setSelectedLabel('');
|
|
369
|
+
}
|
|
370
|
+
}, [onChange, multiple]);
|
|
371
|
+
|
|
372
|
+
const handleRemoveMultiple = useCallback(
|
|
373
|
+
(id: string, e: React.MouseEvent) => {
|
|
374
|
+
e.stopPropagation();
|
|
375
|
+
onChange?.(selectedIds.filter((v) => v !== id));
|
|
376
|
+
setNameMap((prev) => {
|
|
377
|
+
const next = { ...prev };
|
|
378
|
+
delete next[id];
|
|
379
|
+
return next;
|
|
380
|
+
});
|
|
381
|
+
},
|
|
382
|
+
[selectedIds, onChange],
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
const handleClearAllMultiple = useCallback(
|
|
386
|
+
(e: React.MouseEvent) => {
|
|
387
|
+
e.stopPropagation();
|
|
388
|
+
onChange?.([]);
|
|
389
|
+
setNameMap({});
|
|
390
|
+
},
|
|
391
|
+
[onChange],
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
const hasSelectionMulti = multiple && selectedIds.length > 0;
|
|
395
|
+
const showClearMulti = hasSelectionMulti && isHovering;
|
|
396
|
+
|
|
397
|
+
return (
|
|
398
|
+
<FieldWrapper field={field} showLabel={showLabel} showDescription={showDescription}>
|
|
399
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
400
|
+
<PopoverTrigger asChild>
|
|
401
|
+
<button
|
|
402
|
+
ref={setTriggerRef}
|
|
403
|
+
type="button"
|
|
404
|
+
disabled={disabled}
|
|
405
|
+
onMouseEnter={() => setIsHovering(true)}
|
|
406
|
+
onMouseLeave={() => setIsHovering(false)}
|
|
407
|
+
className={cn(
|
|
408
|
+
'flex items-center justify-between w-full h-[34px] gap-2.5',
|
|
409
|
+
'bg-white border rounded-[4px]',
|
|
410
|
+
'py-[7px]',
|
|
411
|
+
(multiple ? hasSelectionMulti : !!selectedLabel) ? 'pl-[4px] pr-[10px]' : 'px-[10px]',
|
|
412
|
+
'text-left cursor-pointer',
|
|
413
|
+
'hover:border-[#0265FF]',
|
|
414
|
+
disabled && 'opacity-50 cursor-not-allowed hover:border-[#E0E0E0]',
|
|
415
|
+
open ? 'border-[#0265FF]' : 'border-[#E0E0E0]',
|
|
416
|
+
transCls,
|
|
417
|
+
)}
|
|
418
|
+
>
|
|
419
|
+
{multiple ? (
|
|
420
|
+
hasSelectionMulti ? (
|
|
421
|
+
<>
|
|
422
|
+
<div className="flex items-center gap-[4px] min-w-0 flex-1 overflow-x-auto scrollbar-hide">
|
|
423
|
+
{selectedIds.map((id) => (
|
|
424
|
+
<span
|
|
425
|
+
key={id}
|
|
426
|
+
className="flex items-center gap-[4px] bg-[#EEEEEE] rounded-[2px] h-[26px] px-[6px] shrink-0"
|
|
427
|
+
>
|
|
428
|
+
<span className="text-[14px] text-[#030303] leading-[normal]">
|
|
429
|
+
{nameMap[id] || id}
|
|
430
|
+
</span>
|
|
431
|
+
<span
|
|
432
|
+
className="cursor-pointer flex items-center shrink-0"
|
|
433
|
+
onClick={(e) => handleRemoveMultiple(id, e)}
|
|
434
|
+
>
|
|
435
|
+
<CloseIcon />
|
|
436
|
+
</span>
|
|
437
|
+
</span>
|
|
438
|
+
))}
|
|
439
|
+
</div>
|
|
440
|
+
{showClearMulti ? (
|
|
441
|
+
<span className="cursor-pointer flex items-center shrink-0" onClick={handleClearAllMultiple}>
|
|
442
|
+
<ClearAllIcon />
|
|
443
|
+
</span>
|
|
444
|
+
) : (
|
|
445
|
+
<DropdownChevron open={open} />
|
|
446
|
+
)}
|
|
447
|
+
</>
|
|
448
|
+
) : (
|
|
449
|
+
<>
|
|
450
|
+
<span className="text-[14px] text-[#999999] leading-[normal] truncate">
|
|
451
|
+
{field.description ?? `请选择${field.label}`}
|
|
452
|
+
</span>
|
|
453
|
+
<DropdownChevron open={open} />
|
|
454
|
+
</>
|
|
455
|
+
)
|
|
456
|
+
) : (
|
|
457
|
+
<>
|
|
458
|
+
<span className={cn('truncate', !selectedLabel && 'text-[#999999]')}>
|
|
459
|
+
{selectedLabel || (field.description ?? `请选择${field.label}`)}
|
|
460
|
+
</span>
|
|
461
|
+
<div className="flex items-center gap-[4px] shrink-0">
|
|
462
|
+
{!!selectedLabel && (
|
|
463
|
+
<span
|
|
464
|
+
role="button"
|
|
465
|
+
tabIndex={-1}
|
|
466
|
+
onClick={(e) => { e.stopPropagation(); handleClear(); }}
|
|
467
|
+
className="flex items-center justify-center w-[18px] h-[18px] hover:bg-[#EFF0F6] rounded-full"
|
|
468
|
+
>
|
|
469
|
+
<ClearIcon />
|
|
470
|
+
</span>
|
|
471
|
+
)}
|
|
472
|
+
<DropdownChevron open={open} />
|
|
473
|
+
</div>
|
|
474
|
+
</>
|
|
475
|
+
)}
|
|
476
|
+
</button>
|
|
477
|
+
</PopoverTrigger>
|
|
478
|
+
<PopoverContent
|
|
479
|
+
align="start"
|
|
480
|
+
sideOffset={4}
|
|
481
|
+
portalContainer={portalContainer}
|
|
482
|
+
className="!border-0 rounded-[10px] shadow-[0px_0px_5px_rgba(0,0,0,0.04)] p-[8px]"
|
|
483
|
+
style={{ width: 'var(--radix-popover-trigger-width)' }}
|
|
484
|
+
>
|
|
485
|
+
<div className="flex items-center gap-[8px] px-[6px] mb-[4px] h-[34px] bg-[#F6F7FA] rounded-[4px]">
|
|
486
|
+
<SearchIcon />
|
|
487
|
+
<input
|
|
488
|
+
type="text"
|
|
489
|
+
value={keyword}
|
|
490
|
+
onChange={(e) => setKeyword(e.target.value)}
|
|
491
|
+
placeholder={`搜索${field.label}`}
|
|
492
|
+
className="flex-1 bg-transparent text-[14px] text-[#030303] placeholder:text-[#999999] outline-none border-none"
|
|
493
|
+
autoFocus
|
|
494
|
+
/>
|
|
495
|
+
</div>
|
|
496
|
+
<div className="flex flex-col gap-0 max-h-[200px] overflow-y-auto">
|
|
497
|
+
{loading ? (
|
|
498
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">搜索中...</div>
|
|
499
|
+
) : options.length === 0 ? (
|
|
500
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">暂无数据</div>
|
|
501
|
+
) : (
|
|
502
|
+
options.map((opt) => {
|
|
503
|
+
const isSelected = multiple ? selectedIdSet.has(opt.id) : value === opt.id;
|
|
504
|
+
return (
|
|
505
|
+
<button
|
|
506
|
+
key={opt.id}
|
|
507
|
+
type="button"
|
|
508
|
+
onClick={() => handleSelect(opt)}
|
|
509
|
+
className={cn(
|
|
510
|
+
'flex items-center gap-[10px] h-[34px] px-[10px] rounded-[4px] text-left',
|
|
511
|
+
isSelected
|
|
512
|
+
? 'bg-[#F0F6FF] text-[#0265FF]'
|
|
513
|
+
: 'text-[#030303] hover:bg-[#EFF0F6]',
|
|
514
|
+
transCls,
|
|
515
|
+
)}
|
|
516
|
+
>
|
|
517
|
+
{multiple && (
|
|
518
|
+
<div
|
|
519
|
+
className={cn(
|
|
520
|
+
'w-[14px] h-[14px] rounded-[2px] flex items-center justify-center shrink-0 border',
|
|
521
|
+
isSelected ? 'bg-[#0265FF] border-[#0265FF]' : 'bg-white border-[#CCCCCC]',
|
|
522
|
+
)}
|
|
523
|
+
>
|
|
524
|
+
{isSelected && <CheckIcon />}
|
|
525
|
+
</div>
|
|
526
|
+
)}
|
|
527
|
+
{'avatar' in opt && opt.avatar && (
|
|
528
|
+
<img src={opt.avatar} alt="" className="w-[20px] h-[20px] rounded-full" />
|
|
529
|
+
)}
|
|
530
|
+
<span className="text-[14px]">{opt.name}</span>
|
|
531
|
+
</button>
|
|
532
|
+
);
|
|
533
|
+
})
|
|
534
|
+
)}
|
|
535
|
+
</div>
|
|
536
|
+
</PopoverContent>
|
|
537
|
+
</Popover>
|
|
538
|
+
</FieldWrapper>
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// ── TextMultiSelect (in/nin operators for text fields) ───────────────
|
|
543
|
+
|
|
544
|
+
export function TextMultiSelect({ field, value, onChange, disabled, service, showLabel, showDescription }: FieldValueInputProps) {
|
|
545
|
+
const [open, setOpen] = useState(false);
|
|
546
|
+
const [keyword, setKeyword] = useState('');
|
|
547
|
+
const [options, setOptions] = useState<ILinkDataOption[]>([]);
|
|
548
|
+
const [loading, setLoading] = useState(false);
|
|
549
|
+
const [labelMap, setLabelMap] = useState<Record<string, string>>({});
|
|
550
|
+
const [isHovering, setIsHovering] = useState(false);
|
|
551
|
+
const { portalContainer, setTriggerRef } = usePortalContainer('data-bs-field-value-picker-portal');
|
|
552
|
+
|
|
553
|
+
const selectedValues: string[] = Array.isArray(value) ? value.map(String) : [];
|
|
554
|
+
const selectedSet = new Set(selectedValues);
|
|
555
|
+
|
|
556
|
+
useEffect(() => {
|
|
557
|
+
if (open && service?.searchDistinctValues) {
|
|
558
|
+
setLoading(true);
|
|
559
|
+
service.searchDistinctValues(field, keyword).then((data) => {
|
|
560
|
+
setOptions(data);
|
|
561
|
+
const map: Record<string, string> = {};
|
|
562
|
+
data.forEach((opt) => { map[opt.value] = opt.label; });
|
|
563
|
+
setLabelMap(map);
|
|
564
|
+
setLoading(false);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}, [open, keyword, field, service]);
|
|
568
|
+
|
|
569
|
+
const handleToggle = useCallback(
|
|
570
|
+
(opt: ILinkDataOption) => {
|
|
571
|
+
const next = selectedSet.has(opt.value)
|
|
572
|
+
? selectedValues.filter((v) => v !== opt.value)
|
|
573
|
+
: [...selectedValues, opt.value];
|
|
574
|
+
onChange?.(next);
|
|
575
|
+
},
|
|
576
|
+
[selectedValues, selectedSet, onChange],
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
const handleClearAll = useCallback(
|
|
580
|
+
(e: React.MouseEvent) => {
|
|
581
|
+
e.stopPropagation();
|
|
582
|
+
onChange?.([]);
|
|
583
|
+
},
|
|
584
|
+
[onChange],
|
|
585
|
+
);
|
|
586
|
+
|
|
587
|
+
const handleRemove = useCallback(
|
|
588
|
+
(val: string, e: React.MouseEvent) => {
|
|
589
|
+
e.stopPropagation();
|
|
590
|
+
onChange?.(selectedValues.filter((v) => v !== val));
|
|
591
|
+
},
|
|
592
|
+
[selectedValues, onChange],
|
|
593
|
+
);
|
|
594
|
+
|
|
595
|
+
const hasSelection = selectedValues.length > 0;
|
|
596
|
+
const showClear = hasSelection && isHovering;
|
|
597
|
+
|
|
598
|
+
return (
|
|
599
|
+
<FieldWrapper field={field} showLabel={showLabel} showDescription={showDescription}>
|
|
600
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
601
|
+
<PopoverTrigger asChild>
|
|
602
|
+
<button
|
|
603
|
+
ref={setTriggerRef}
|
|
604
|
+
type="button"
|
|
605
|
+
disabled={disabled}
|
|
606
|
+
onMouseEnter={() => setIsHovering(true)}
|
|
607
|
+
onMouseLeave={() => setIsHovering(false)}
|
|
608
|
+
className={cn(
|
|
609
|
+
'flex items-center justify-between w-full h-[34px] gap-2.5',
|
|
610
|
+
'bg-white border rounded-[4px]',
|
|
611
|
+
'py-[7px]',
|
|
612
|
+
hasSelection ? 'pl-[4px] pr-[10px]' : 'px-[10px]',
|
|
613
|
+
'text-left cursor-pointer',
|
|
614
|
+
'hover:border-[#0265FF]',
|
|
615
|
+
disabled && 'opacity-50 cursor-not-allowed hover:border-[#E0E0E0]',
|
|
616
|
+
open ? 'border-[#0265FF]' : 'border-[#E0E0E0]',
|
|
617
|
+
transCls,
|
|
618
|
+
)}
|
|
619
|
+
>
|
|
620
|
+
{hasSelection ? (
|
|
621
|
+
<>
|
|
622
|
+
<div className="flex items-center gap-[4px] min-w-0 flex-1 overflow-x-auto scrollbar-hide">
|
|
623
|
+
{selectedValues.map((val) => (
|
|
624
|
+
<span
|
|
625
|
+
key={val}
|
|
626
|
+
className="flex items-center gap-[4px] bg-[#EEEEEE] rounded-[2px] h-[26px] px-[6px] shrink-0"
|
|
627
|
+
>
|
|
628
|
+
<span className="text-[14px] text-[#030303] leading-[normal]">
|
|
629
|
+
{labelMap[val] || val}
|
|
630
|
+
</span>
|
|
631
|
+
<span
|
|
632
|
+
className="cursor-pointer flex items-center shrink-0"
|
|
633
|
+
onClick={(e) => handleRemove(val, e)}
|
|
634
|
+
>
|
|
635
|
+
<CloseIcon />
|
|
636
|
+
</span>
|
|
637
|
+
</span>
|
|
638
|
+
))}
|
|
639
|
+
</div>
|
|
640
|
+
{showClear ? (
|
|
641
|
+
<span className="cursor-pointer flex items-center shrink-0" onClick={handleClearAll}>
|
|
642
|
+
<ClearAllIcon />
|
|
643
|
+
</span>
|
|
644
|
+
) : (
|
|
645
|
+
<DropdownChevron open={open} />
|
|
646
|
+
)}
|
|
647
|
+
</>
|
|
648
|
+
) : (
|
|
649
|
+
<>
|
|
650
|
+
<span className="text-[14px] text-[#999999] leading-[normal] truncate">
|
|
651
|
+
{field.description ?? `请输入${field.label}`}
|
|
652
|
+
</span>
|
|
653
|
+
<DropdownChevron open={open} />
|
|
654
|
+
</>
|
|
655
|
+
)}
|
|
656
|
+
</button>
|
|
657
|
+
</PopoverTrigger>
|
|
658
|
+
<PopoverContent
|
|
659
|
+
align="start"
|
|
660
|
+
sideOffset={4}
|
|
661
|
+
portalContainer={portalContainer}
|
|
662
|
+
className="!border-0 rounded-[10px] shadow-[0px_0px_5px_rgba(0,0,0,0.04)] p-[8px]"
|
|
663
|
+
style={{ width: 'var(--radix-popover-trigger-width)' }}
|
|
664
|
+
>
|
|
665
|
+
<div className="flex items-center gap-[8px] px-[6px] mb-[4px] h-[34px] bg-[#F6F7FA] rounded-[4px]">
|
|
666
|
+
<SearchIcon />
|
|
667
|
+
<input
|
|
668
|
+
type="text"
|
|
669
|
+
value={keyword}
|
|
670
|
+
onChange={(e) => setKeyword(e.target.value)}
|
|
671
|
+
placeholder="输入关键字搜索"
|
|
672
|
+
className="flex-1 bg-transparent text-[14px] text-[#030303] placeholder:text-[#999999] outline-none border-none"
|
|
673
|
+
autoFocus
|
|
674
|
+
/>
|
|
675
|
+
</div>
|
|
676
|
+
<div className="flex flex-col gap-0 max-h-[200px] overflow-y-auto">
|
|
677
|
+
{loading ? (
|
|
678
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">搜索中...</div>
|
|
679
|
+
) : options.length === 0 ? (
|
|
680
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">暂无数据</div>
|
|
681
|
+
) : (
|
|
682
|
+
options.map((opt) => {
|
|
683
|
+
const checked = selectedSet.has(opt.value);
|
|
684
|
+
return (
|
|
685
|
+
<button
|
|
686
|
+
key={opt.value}
|
|
687
|
+
type="button"
|
|
688
|
+
onClick={() => handleToggle(opt)}
|
|
689
|
+
className={cn(
|
|
690
|
+
'flex items-center gap-[10px] h-[34px] px-[10px] rounded-[4px] text-left',
|
|
691
|
+
checked
|
|
692
|
+
? 'bg-[#F0F6FF] text-[#0265FF]'
|
|
693
|
+
: 'text-[#030303] hover:bg-[#EFF0F6]',
|
|
694
|
+
transCls,
|
|
695
|
+
)}
|
|
696
|
+
>
|
|
697
|
+
<div
|
|
698
|
+
className={cn(
|
|
699
|
+
'w-[14px] h-[14px] rounded-[2px] flex items-center justify-center shrink-0 border',
|
|
700
|
+
checked ? 'bg-[#0265FF] border-[#0265FF]' : 'bg-white border-[#CCCCCC]',
|
|
701
|
+
)}
|
|
702
|
+
>
|
|
703
|
+
{checked && <CheckIcon />}
|
|
704
|
+
</div>
|
|
705
|
+
<span className="text-[14px]">{opt.label}</span>
|
|
706
|
+
</button>
|
|
707
|
+
);
|
|
708
|
+
})
|
|
709
|
+
)}
|
|
710
|
+
</div>
|
|
711
|
+
</PopoverContent>
|
|
712
|
+
</Popover>
|
|
713
|
+
</FieldWrapper>
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// ── CascadingAddressInput (province → city → district) ──────────────
|
|
718
|
+
|
|
719
|
+
const provinceList = Object.keys(chinaAddressData);
|
|
720
|
+
|
|
721
|
+
interface AddressValue {
|
|
722
|
+
province?: string;
|
|
723
|
+
city?: string;
|
|
724
|
+
district?: string;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
export function CascadingAddressInput({ field, value, onChange, disabled, showLabel, showDescription }: FieldValueInputProps) {
|
|
728
|
+
const [open, setOpen] = useState(false);
|
|
729
|
+
const [isHovering, setIsHovering] = useState(false);
|
|
730
|
+
const provinceRef = useRef<HTMLDivElement>(null);
|
|
731
|
+
const cityRef = useRef<HTMLDivElement>(null);
|
|
732
|
+
const districtRef = useRef<HTMLDivElement>(null);
|
|
733
|
+
const { portalContainer, setTriggerRef } = usePortalContainer('data-bs-field-value-picker-portal');
|
|
734
|
+
|
|
735
|
+
const addrValue: AddressValue =
|
|
736
|
+
value && typeof value === 'object' && !Array.isArray(value)
|
|
737
|
+
? (value as AddressValue)
|
|
738
|
+
: {};
|
|
739
|
+
|
|
740
|
+
const selectedProvince = addrValue.province || '';
|
|
741
|
+
const selectedCity = addrValue.city || '';
|
|
742
|
+
const selectedDistrict = addrValue.district || '';
|
|
743
|
+
|
|
744
|
+
const cityList = selectedProvince && chinaAddressData[selectedProvince]
|
|
745
|
+
? Object.keys(chinaAddressData[selectedProvince])
|
|
746
|
+
: [];
|
|
747
|
+
const districtList = selectedProvince && selectedCity && chinaAddressData[selectedProvince]?.[selectedCity]
|
|
748
|
+
? chinaAddressData[selectedProvince][selectedCity]
|
|
749
|
+
: [];
|
|
750
|
+
|
|
751
|
+
const displayText =
|
|
752
|
+
selectedProvince
|
|
753
|
+
? `${selectedProvince}${selectedCity ? ` ${selectedCity}` : ''}${selectedDistrict ? ` ${selectedDistrict}` : ''}`
|
|
754
|
+
: '';
|
|
755
|
+
|
|
756
|
+
const handleSelectProvince = useCallback(
|
|
757
|
+
(province: string) => {
|
|
758
|
+
if (province === selectedProvince) return;
|
|
759
|
+
onChange?.({ province, city: undefined, district: undefined });
|
|
760
|
+
setTimeout(() => {
|
|
761
|
+
const el = cityRef.current;
|
|
762
|
+
if (el) el.scrollTop = 0;
|
|
763
|
+
}, 0);
|
|
764
|
+
},
|
|
765
|
+
[onChange, selectedProvince],
|
|
766
|
+
);
|
|
767
|
+
|
|
768
|
+
const handleSelectCity = useCallback(
|
|
769
|
+
(city: string) => {
|
|
770
|
+
if (city === selectedCity) return;
|
|
771
|
+
onChange?.({ province: selectedProvince, city, district: undefined });
|
|
772
|
+
setTimeout(() => {
|
|
773
|
+
const el = districtRef.current;
|
|
774
|
+
if (el) el.scrollTop = 0;
|
|
775
|
+
}, 0);
|
|
776
|
+
},
|
|
777
|
+
[onChange, selectedProvince, selectedCity],
|
|
778
|
+
);
|
|
779
|
+
|
|
780
|
+
const handleSelectDistrict = useCallback(
|
|
781
|
+
(district: string) => {
|
|
782
|
+
onChange?.({ province: selectedProvince, city: selectedCity, district });
|
|
783
|
+
setOpen(false);
|
|
784
|
+
},
|
|
785
|
+
[onChange, selectedProvince, selectedCity],
|
|
786
|
+
);
|
|
787
|
+
|
|
788
|
+
const handleClear = useCallback(
|
|
789
|
+
(e: React.MouseEvent) => {
|
|
790
|
+
e.stopPropagation();
|
|
791
|
+
onChange?.({});
|
|
792
|
+
},
|
|
793
|
+
[onChange],
|
|
794
|
+
);
|
|
795
|
+
|
|
796
|
+
const scrollToSelected = useCallback(() => {
|
|
797
|
+
if (provinceRef.current) {
|
|
798
|
+
const idx = provinceList.indexOf(selectedProvince);
|
|
799
|
+
if (idx >= 0) provinceRef.current.scrollTop = idx * 32;
|
|
800
|
+
}
|
|
801
|
+
if (cityRef.current) {
|
|
802
|
+
const idx = cityList.indexOf(selectedCity);
|
|
803
|
+
if (idx >= 0) cityRef.current.scrollTop = idx * 32;
|
|
804
|
+
}
|
|
805
|
+
if (districtRef.current) {
|
|
806
|
+
const idx = districtList.indexOf(selectedDistrict);
|
|
807
|
+
if (idx >= 0) districtRef.current.scrollTop = idx * 32;
|
|
808
|
+
}
|
|
809
|
+
}, [selectedProvince, selectedCity, selectedDistrict, cityList, districtList]);
|
|
810
|
+
|
|
811
|
+
useEffect(() => {
|
|
812
|
+
if (open) scrollToSelected();
|
|
813
|
+
}, [open, scrollToSelected]);
|
|
814
|
+
|
|
815
|
+
const hasValue = !!displayText;
|
|
816
|
+
const showClear = hasValue && isHovering;
|
|
817
|
+
|
|
818
|
+
return (
|
|
819
|
+
<FieldWrapper field={field} showLabel={showLabel} showDescription={showDescription}>
|
|
820
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
821
|
+
<PopoverTrigger asChild>
|
|
822
|
+
<button
|
|
823
|
+
ref={setTriggerRef}
|
|
824
|
+
type="button"
|
|
825
|
+
disabled={disabled}
|
|
826
|
+
onMouseEnter={() => setIsHovering(true)}
|
|
827
|
+
onMouseLeave={() => setIsHovering(false)}
|
|
828
|
+
className={cn(
|
|
829
|
+
'flex items-center justify-between gap-[10px]',
|
|
830
|
+
inputBaseCls,
|
|
831
|
+
'text-left cursor-pointer',
|
|
832
|
+
open ? 'border-[#0265FF]' : 'border-[#E0E0E0] hover:border-[#0265FF]',
|
|
833
|
+
)}
|
|
834
|
+
>
|
|
835
|
+
<span className={cn('truncate', !displayText && 'text-[#999999]')}>
|
|
836
|
+
{displayText || (field.description ?? `请选择${field.label}`)}
|
|
837
|
+
</span>
|
|
838
|
+
{showClear ? (
|
|
839
|
+
<span className="cursor-pointer flex items-center shrink-0" onClick={handleClear}>
|
|
840
|
+
<ClearAllIcon />
|
|
841
|
+
</span>
|
|
842
|
+
) : (
|
|
843
|
+
<DropdownChevron open={open} />
|
|
844
|
+
)}
|
|
845
|
+
</button>
|
|
846
|
+
</PopoverTrigger>
|
|
847
|
+
<PopoverContent
|
|
848
|
+
align="start"
|
|
849
|
+
sideOffset={4}
|
|
850
|
+
portalContainer={portalContainer}
|
|
851
|
+
className="!border-0 rounded-[10px] shadow-[0px_0px_5px_rgba(0,0,0,0.04)] p-0"
|
|
852
|
+
style={{ width: '520px' }}
|
|
853
|
+
>
|
|
854
|
+
<div className="flex h-[280px]">
|
|
855
|
+
{/* Province Column */}
|
|
856
|
+
<div className="flex-1 border-r border-[#F0F0F0] flex flex-col min-w-0">
|
|
857
|
+
<div className="h-[34px] px-[12px] flex items-center text-[12px] text-[#999999] bg-[#FAFAFA] shrink-0 border-b border-[#F0F0F0]">
|
|
858
|
+
省份
|
|
859
|
+
</div>
|
|
860
|
+
<div ref={provinceRef} className="flex-1 overflow-y-auto">
|
|
861
|
+
{provinceList.map((province) => (
|
|
862
|
+
<button
|
|
863
|
+
key={province}
|
|
864
|
+
type="button"
|
|
865
|
+
onClick={() => handleSelectProvince(province)}
|
|
866
|
+
className={cn(
|
|
867
|
+
'w-full h-[32px] px-[12px] flex items-center justify-between text-left text-[14px]',
|
|
868
|
+
transCls,
|
|
869
|
+
province === selectedProvince
|
|
870
|
+
? 'bg-[#F0F6FF] text-[#0265FF]'
|
|
871
|
+
: 'text-[#030303] hover:bg-[#EFF0F6]',
|
|
872
|
+
)}
|
|
873
|
+
>
|
|
874
|
+
<span className="truncate">{province}</span>
|
|
875
|
+
{chinaAddressData[province] && (
|
|
876
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" className="shrink-0 ml-[4px]">
|
|
877
|
+
<path d="M4.5 2.5L8 6L4.5 9.5" stroke={province === selectedProvince ? '#0265FF' : '#999999'} strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round" />
|
|
878
|
+
</svg>
|
|
879
|
+
)}
|
|
880
|
+
</button>
|
|
881
|
+
))}
|
|
882
|
+
</div>
|
|
883
|
+
</div>
|
|
884
|
+
{/* City Column */}
|
|
885
|
+
<div className="flex-1 border-r border-[#F0F0F0] flex flex-col min-w-0">
|
|
886
|
+
<div className="h-[34px] px-[12px] flex items-center text-[12px] text-[#999999] bg-[#FAFAFA] shrink-0 border-b border-[#F0F0F0]">
|
|
887
|
+
城市
|
|
888
|
+
</div>
|
|
889
|
+
<div ref={cityRef} className="flex-1 overflow-y-auto">
|
|
890
|
+
{cityList.length === 0 ? (
|
|
891
|
+
<div className="px-[12px] py-[16px] text-[14px] text-[#999999] text-center">请选择省份</div>
|
|
892
|
+
) : (
|
|
893
|
+
cityList.map((city) => (
|
|
894
|
+
<button
|
|
895
|
+
key={city}
|
|
896
|
+
type="button"
|
|
897
|
+
onClick={() => handleSelectCity(city)}
|
|
898
|
+
className={cn(
|
|
899
|
+
'w-full h-[32px] px-[12px] flex items-center justify-between text-left text-[14px]',
|
|
900
|
+
transCls,
|
|
901
|
+
city === selectedCity
|
|
902
|
+
? 'bg-[#F0F6FF] text-[#0265FF]'
|
|
903
|
+
: 'text-[#030303] hover:bg-[#EFF0F6]',
|
|
904
|
+
)}
|
|
905
|
+
>
|
|
906
|
+
<span className="truncate">{city}</span>
|
|
907
|
+
{selectedProvince && chinaAddressData[selectedProvince]?.[city] && (
|
|
908
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" className="shrink-0 ml-[4px]">
|
|
909
|
+
<path d="M4.5 2.5L8 6L4.5 9.5" stroke={city === selectedCity ? '#0265FF' : '#999999'} strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round" />
|
|
910
|
+
</svg>
|
|
911
|
+
)}
|
|
912
|
+
</button>
|
|
913
|
+
))
|
|
914
|
+
)}
|
|
915
|
+
</div>
|
|
916
|
+
</div>
|
|
917
|
+
{/* District Column */}
|
|
918
|
+
<div className="flex-1 flex flex-col min-w-0">
|
|
919
|
+
<div className="h-[34px] px-[12px] flex items-center text-[12px] text-[#999999] bg-[#FAFAFA] shrink-0 border-b border-[#F0F0F0]">
|
|
920
|
+
区/县
|
|
921
|
+
</div>
|
|
922
|
+
<div ref={districtRef} className="flex-1 overflow-y-auto">
|
|
923
|
+
{districtList.length === 0 ? (
|
|
924
|
+
<div className="px-[12px] py-[16px] text-[14px] text-[#999999] text-center">请选择城市</div>
|
|
925
|
+
) : (
|
|
926
|
+
districtList.map((district) => (
|
|
927
|
+
<button
|
|
928
|
+
key={district}
|
|
929
|
+
type="button"
|
|
930
|
+
onClick={() => handleSelectDistrict(district)}
|
|
931
|
+
className={cn(
|
|
932
|
+
'w-full h-[32px] px-[12px] flex items-center text-left text-[14px]',
|
|
933
|
+
transCls,
|
|
934
|
+
district === selectedDistrict
|
|
935
|
+
? 'bg-[#F0F6FF] text-[#0265FF]'
|
|
936
|
+
: 'text-[#030303] hover:bg-[#EFF0F6]',
|
|
937
|
+
)}
|
|
938
|
+
>
|
|
939
|
+
<span className="truncate">{district}</span>
|
|
940
|
+
</button>
|
|
941
|
+
))
|
|
942
|
+
)}
|
|
943
|
+
</div>
|
|
944
|
+
</div>
|
|
945
|
+
</div>
|
|
946
|
+
</PopoverContent>
|
|
947
|
+
</Popover>
|
|
948
|
+
</FieldWrapper>
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// ── AddressInput ────────────────────────────────────────────────────
|
|
953
|
+
|
|
954
|
+
export function AddressInput({ field, value, onChange, disabled, service, showLabel, showDescription }: FieldValueInputProps) {
|
|
955
|
+
const [open, setOpen] = useState(false);
|
|
956
|
+
const [keyword, setKeyword] = useState('');
|
|
957
|
+
const [options, setOptions] = useState<IAddressOption[]>([]);
|
|
958
|
+
const [loading, setLoading] = useState(false);
|
|
959
|
+
const { portalContainer, setTriggerRef } = usePortalContainer('data-bs-field-value-picker-portal');
|
|
960
|
+
|
|
961
|
+
const selectedLabel =
|
|
962
|
+
value && typeof value === 'object' && 'province' in (value as Record<string, unknown>)
|
|
963
|
+
? `${(value as IAddressOption).province}${(value as IAddressOption).city}${(value as IAddressOption).district}`
|
|
964
|
+
: typeof value === 'string'
|
|
965
|
+
? value
|
|
966
|
+
: '';
|
|
967
|
+
|
|
968
|
+
useEffect(() => {
|
|
969
|
+
if (open && service?.searchAddress) {
|
|
970
|
+
setLoading(true);
|
|
971
|
+
service.searchAddress(keyword).then((data) => {
|
|
972
|
+
setOptions(data);
|
|
973
|
+
setLoading(false);
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
}, [open, keyword, service]);
|
|
977
|
+
|
|
978
|
+
return (
|
|
979
|
+
<FieldWrapper field={field} showLabel={showLabel} showDescription={showDescription}>
|
|
980
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
981
|
+
<PopoverTrigger asChild>
|
|
982
|
+
<button
|
|
983
|
+
ref={setTriggerRef}
|
|
984
|
+
type="button"
|
|
985
|
+
disabled={disabled}
|
|
986
|
+
className={cn(
|
|
987
|
+
'flex items-center justify-between gap-[10px]',
|
|
988
|
+
inputBaseCls,
|
|
989
|
+
'text-left cursor-pointer',
|
|
990
|
+
open ? 'border-[#0265FF]' : 'border-[#E0E0E0] hover:border-[#0265FF]',
|
|
991
|
+
)}
|
|
992
|
+
>
|
|
993
|
+
<span className={cn('truncate', !selectedLabel && 'text-[#999999]')}>
|
|
994
|
+
{selectedLabel || (field.description ?? `请选择${field.label}`)}
|
|
995
|
+
</span>
|
|
996
|
+
<DropdownChevron open={open} />
|
|
997
|
+
</button>
|
|
998
|
+
</PopoverTrigger>
|
|
999
|
+
<PopoverContent
|
|
1000
|
+
align="start"
|
|
1001
|
+
sideOffset={4}
|
|
1002
|
+
portalContainer={portalContainer}
|
|
1003
|
+
className="!border-0 rounded-[10px] shadow-[0px_0px_5px_rgba(0,0,0,0.04)] p-[8px]"
|
|
1004
|
+
style={{ width: 'var(--radix-popover-trigger-width)' }}
|
|
1005
|
+
>
|
|
1006
|
+
<div className="flex items-center gap-[8px] px-[6px] mb-[4px] h-[34px] bg-[#F6F7FA] rounded-[4px]">
|
|
1007
|
+
<SearchIcon />
|
|
1008
|
+
<input
|
|
1009
|
+
type="text"
|
|
1010
|
+
value={keyword}
|
|
1011
|
+
onChange={(e) => setKeyword(e.target.value)}
|
|
1012
|
+
placeholder={`搜索${field.label}`}
|
|
1013
|
+
className="flex-1 bg-transparent text-[14px] text-[#030303] placeholder:text-[#999999] outline-none border-none"
|
|
1014
|
+
autoFocus
|
|
1015
|
+
/>
|
|
1016
|
+
</div>
|
|
1017
|
+
<div className="flex flex-col gap-0 max-h-[200px] overflow-y-auto">
|
|
1018
|
+
{loading ? (
|
|
1019
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">搜索中...</div>
|
|
1020
|
+
) : options.length === 0 ? (
|
|
1021
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">暂无数据</div>
|
|
1022
|
+
) : (
|
|
1023
|
+
options.map((opt, i) => (
|
|
1024
|
+
<button
|
|
1025
|
+
key={i}
|
|
1026
|
+
type="button"
|
|
1027
|
+
onClick={() => {
|
|
1028
|
+
onChange?.(opt);
|
|
1029
|
+
setOpen(false);
|
|
1030
|
+
setKeyword('');
|
|
1031
|
+
}}
|
|
1032
|
+
className={cn(
|
|
1033
|
+
'h-[34px] px-[10px] rounded-[4px] text-left text-[14px] leading-[normal]',
|
|
1034
|
+
'text-[#030303] hover:bg-[#EFF0F6]',
|
|
1035
|
+
transCls,
|
|
1036
|
+
)}
|
|
1037
|
+
>
|
|
1038
|
+
{opt.province}{opt.city}{opt.district}
|
|
1039
|
+
</button>
|
|
1040
|
+
))
|
|
1041
|
+
)}
|
|
1042
|
+
</div>
|
|
1043
|
+
</PopoverContent>
|
|
1044
|
+
</Popover>
|
|
1045
|
+
</FieldWrapper>
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// ── LocationInput ───────────────────────────────────────────────────
|
|
1050
|
+
|
|
1051
|
+
export function LocationInput({ field, value, onChange, disabled, service, showLabel, showDescription }: FieldValueInputProps) {
|
|
1052
|
+
const [open, setOpen] = useState(false);
|
|
1053
|
+
const [keyword, setKeyword] = useState('');
|
|
1054
|
+
const [options, setOptions] = useState<ILocationOption[]>([]);
|
|
1055
|
+
const [loading, setLoading] = useState(false);
|
|
1056
|
+
const { portalContainer, setTriggerRef } = usePortalContainer('data-bs-field-value-picker-portal');
|
|
1057
|
+
|
|
1058
|
+
const selectedLabel =
|
|
1059
|
+
value && typeof value === 'object' && 'detail' in (value as Record<string, unknown>)
|
|
1060
|
+
? (value as ILocationOption).detail
|
|
1061
|
+
: typeof value === 'string'
|
|
1062
|
+
? value
|
|
1063
|
+
: '';
|
|
1064
|
+
|
|
1065
|
+
useEffect(() => {
|
|
1066
|
+
if (open && service?.searchLocation) {
|
|
1067
|
+
setLoading(true);
|
|
1068
|
+
service.searchLocation(keyword).then((data) => {
|
|
1069
|
+
setOptions(data);
|
|
1070
|
+
setLoading(false);
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
}, [open, keyword, service]);
|
|
1074
|
+
|
|
1075
|
+
return (
|
|
1076
|
+
<FieldWrapper field={field} showLabel={showLabel} showDescription={showDescription}>
|
|
1077
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
1078
|
+
<PopoverTrigger asChild>
|
|
1079
|
+
<button
|
|
1080
|
+
ref={setTriggerRef}
|
|
1081
|
+
type="button"
|
|
1082
|
+
disabled={disabled}
|
|
1083
|
+
className={cn(
|
|
1084
|
+
'flex items-center justify-between gap-[10px]',
|
|
1085
|
+
inputBaseCls,
|
|
1086
|
+
'text-left cursor-pointer',
|
|
1087
|
+
open ? 'border-[#0265FF]' : 'border-[#E0E0E0] hover:border-[#0265FF]',
|
|
1088
|
+
)}
|
|
1089
|
+
>
|
|
1090
|
+
<span className={cn('truncate', !selectedLabel && 'text-[#999999]')}>
|
|
1091
|
+
{selectedLabel || (field.description ?? `请选择${field.label}`)}
|
|
1092
|
+
</span>
|
|
1093
|
+
<DropdownChevron open={open} />
|
|
1094
|
+
</button>
|
|
1095
|
+
</PopoverTrigger>
|
|
1096
|
+
<PopoverContent
|
|
1097
|
+
align="start"
|
|
1098
|
+
sideOffset={4}
|
|
1099
|
+
portalContainer={portalContainer}
|
|
1100
|
+
className="!border-0 rounded-[10px] shadow-[0px_0px_5px_rgba(0,0,0,0.04)] p-[8px]"
|
|
1101
|
+
style={{ width: 'var(--radix-popover-trigger-width)' }}
|
|
1102
|
+
>
|
|
1103
|
+
<div className="flex items-center gap-[8px] px-[6px] mb-[4px] h-[34px] bg-[#F6F7FA] rounded-[4px]">
|
|
1104
|
+
<SearchIcon />
|
|
1105
|
+
<input
|
|
1106
|
+
type="text"
|
|
1107
|
+
value={keyword}
|
|
1108
|
+
onChange={(e) => setKeyword(e.target.value)}
|
|
1109
|
+
placeholder={`搜索${field.label}`}
|
|
1110
|
+
className="flex-1 bg-transparent text-[14px] text-[#030303] placeholder:text-[#999999] outline-none border-none"
|
|
1111
|
+
autoFocus
|
|
1112
|
+
/>
|
|
1113
|
+
</div>
|
|
1114
|
+
<div className="flex flex-col gap-0 max-h-[200px] overflow-y-auto">
|
|
1115
|
+
{loading ? (
|
|
1116
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">搜索中...</div>
|
|
1117
|
+
) : options.length === 0 ? (
|
|
1118
|
+
<div className="px-[10px] py-[8px] text-[14px] text-[#999999]">暂无数据</div>
|
|
1119
|
+
) : (
|
|
1120
|
+
options.map((opt, i) => (
|
|
1121
|
+
<button
|
|
1122
|
+
key={i}
|
|
1123
|
+
type="button"
|
|
1124
|
+
onClick={() => {
|
|
1125
|
+
onChange?.(opt);
|
|
1126
|
+
setOpen(false);
|
|
1127
|
+
setKeyword('');
|
|
1128
|
+
}}
|
|
1129
|
+
className={cn(
|
|
1130
|
+
'h-[34px] px-[10px] rounded-[4px] text-left text-[14px] leading-[normal]',
|
|
1131
|
+
'text-[#030303] hover:bg-[#EFF0F6]',
|
|
1132
|
+
transCls,
|
|
1133
|
+
)}
|
|
1134
|
+
>
|
|
1135
|
+
{opt.province}{opt.city}{opt.district} {opt.detail}
|
|
1136
|
+
</button>
|
|
1137
|
+
))
|
|
1138
|
+
)}
|
|
1139
|
+
</div>
|
|
1140
|
+
</PopoverContent>
|
|
1141
|
+
</Popover>
|
|
1142
|
+
</FieldWrapper>
|
|
1143
|
+
);
|
|
1144
|
+
}
|