@ticatec/uniface-element 0.1.71 → 0.2.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/README.md +273 -1
- package/README_CN.md +341 -0
- package/dist/common/MouseClickHandler.d.ts +1 -1
- package/dist/data-table/UniDataTable.js +6 -0
- package/dist/data-table/lib/DataColumn.d.ts +4 -0
- package/dist/dialog/CommonDialog.svelte +6 -3
- package/dist/dialog/CommonDialog.svelte.d.ts +2 -1
- package/dist/dialog/Dialog.svelte +36 -10
- package/dist/dialog/Dialog.svelte.d.ts +4 -3
- package/dist/dialog/DialogBoard.svelte +11 -8
- package/dist/dialog/DialogWrapper.svelte +10 -0
- package/dist/dialog/DialogWrapper.svelte.d.ts +22 -0
- package/dist/dialog/Dialogs.js +1 -1
- package/dist/dialog/ModalResult.d.ts +5 -0
- package/dist/dialog/ModalResult.js +5 -0
- package/dist/ticatec-uniface-web.css +7 -0
- package/docs/buttons/cn/ActionBar.md +459 -0
- package/docs/buttons/cn/Button.md +228 -0
- package/docs/buttons/cn/IconButton.md +294 -0
- package/docs/buttons/cn/README.md +600 -0
- package/docs/buttons/cn/TextButton.md +163 -0
- package/docs/buttons/en/ActionBar.md +459 -0
- package/docs/buttons/en/Button.md +228 -0
- package/docs/buttons/en/IconButton.md +294 -0
- package/docs/buttons/en/README.md +600 -0
- package/docs/buttons/en/TextButton.md +163 -0
- package/docs/containers/cn/accordion.md +622 -0
- package/docs/containers/cn/box.md +445 -0
- package/docs/containers/cn/card.md +404 -0
- package/docs/containers/cn/page.md +576 -0
- package/docs/containers/cn/tabs.md +686 -0
- package/docs/containers/en/accordion.md +622 -0
- package/docs/containers/en/box.md +445 -0
- package/docs/containers/en/card.md +404 -0
- package/docs/containers/en/page.md +576 -0
- package/docs/containers/en/tabs.md +686 -0
- package/docs/data-display/cn/concise-data-table.md +731 -0
- package/docs/data-display/cn/listbox.md +786 -0
- package/docs/data-display/cn/treeview.md +863 -0
- package/docs/data-display/en/concise-data-table.md +732 -0
- package/docs/data-display/en/listbox.md +786 -0
- package/docs/data-display/en/treeview.md +863 -0
- package/docs/data-table/cn/README.md +596 -0
- package/docs/data-table/en/README.md +596 -0
- package/docs/dialog/cn/README.md +767 -0
- package/docs/dialog/en/README.md +767 -0
- package/docs/form/cn/README.md +847 -0
- package/docs/form/en/README.md +847 -0
- package/docs/form-components/cn/README.md +495 -0
- package/docs/form-components/cn/attachmentfilesfield.md +757 -0
- package/docs/form-components/cn/cascade-options-select.md +374 -0
- package/docs/form-components/cn/checkbox.md +58 -0
- package/docs/form-components/cn/date-picker.md +138 -0
- package/docs/form-components/cn/datetime-picker.md +228 -0
- package/docs/form-components/cn/group-checkbox.md +405 -0
- package/docs/form-components/cn/group-radiobox.md +525 -0
- package/docs/form-components/cn/imagefilesfield.md +651 -0
- package/docs/form-components/cn/input-options-select.md +250 -0
- package/docs/form-components/cn/lookup-editor.md +406 -0
- package/docs/form-components/cn/memoeditor.md +409 -0
- package/docs/form-components/cn/number-editor.md +261 -0
- package/docs/form-components/cn/options-multi-select.md +177 -0
- package/docs/form-components/cn/options-select.md +83 -0
- package/docs/form-components/cn/passwordeditor.md +538 -0
- package/docs/form-components/cn/prompts-text-editor.md +241 -0
- package/docs/form-components/cn/radiobutton.md +84 -0
- package/docs/form-components/cn/switch.md +178 -0
- package/docs/form-components/cn/text-editor.md +142 -0
- package/docs/form-components/cn/time-editor.md +159 -0
- package/docs/form-components/cn/unit-number-editor.md +164 -0
- package/docs/form-components/en/README.md +463 -0
- package/docs/form-components/en/attachmentfilesfield.md +757 -0
- package/docs/form-components/en/cascade-options-select.md +358 -0
- package/docs/form-components/en/checkbox.md +59 -0
- package/docs/form-components/en/date-picker.md +138 -0
- package/docs/form-components/en/datetime-picker.md +228 -0
- package/docs/form-components/en/group-checkbox.md +395 -0
- package/docs/form-components/en/group-radiobox.md +498 -0
- package/docs/form-components/en/imagefilesfield.md +651 -0
- package/docs/form-components/en/input-options-select.md +239 -0
- package/docs/form-components/en/lookup-editor.md +389 -0
- package/docs/form-components/en/memoeditor.md +409 -0
- package/docs/form-components/en/number-editor.md +249 -0
- package/docs/form-components/en/options-multi-select.md +177 -0
- package/docs/form-components/en/options-select.md +83 -0
- package/docs/form-components/en/passwordeditor.md +538 -0
- package/docs/form-components/en/prompts-text-editor.md +241 -0
- package/docs/form-components/en/radiobutton.md +84 -0
- package/docs/form-components/en/switch.md +180 -0
- package/docs/form-components/en/text-editor.md +142 -0
- package/docs/form-components/en/time-editor.md +159 -0
- package/docs/form-components/en/unit-number-editor.md +164 -0
- package/docs/form-layout/cn/criteria-field.md +652 -0
- package/docs/form-layout/cn/flex-form.md +454 -0
- package/docs/form-layout/cn/flex-row-form.md +542 -0
- package/docs/form-layout/cn/form-field.md +923 -0
- package/docs/form-layout/cn/grid-form.md +676 -0
- package/docs/form-layout/en/criteria-field.md +652 -0
- package/docs/form-layout/en/flex-form.md +454 -0
- package/docs/form-layout/en/flex-row-form.md +542 -0
- package/docs/form-layout/en/form-field.md +923 -0
- package/docs/form-layout/en/grid-form.md +676 -0
- package/docs/global/cn/README.md +534 -0
- package/docs/global/en/README.md +534 -0
- package/docs/layout/cn/classiclayout.md +460 -0
- package/docs/layout/cn/headerlayout.md +524 -0
- package/docs/layout/cn/sidebarlayout.md +263 -0
- package/docs/layout/en/classiclayout.md +951 -0
- package/docs/layout/en/headerlayout.md +524 -0
- package/docs/layout/en/sidebarlayout.md +262 -0
- package/docs/misc/cn/README.md +1217 -0
- package/docs/misc/en/README.md +1217 -0
- package/docs/navigation/cn/breadcrumb.md +291 -0
- package/docs/navigation/cn/navigator.md +322 -0
- package/docs/navigation/cn/navigatormenu.md +512 -0
- package/docs/navigation/cn/progressbar.md +199 -0
- package/docs/navigation/cn/progressstepbar.md +299 -0
- package/docs/navigation/en/breadcrumb.md +291 -0
- package/docs/navigation/en/navigator.md +322 -0
- package/docs/navigation/en/navigatormenu.md +512 -0
- package/docs/navigation/en/progressbar.md +199 -0
- package/docs/navigation/en/progressstepbar.md +299 -0
- package/docs/search-filters/cn/daterange.md +1156 -0
- package/docs/search-filters/cn/numberrange.md +688 -0
- package/docs/search-filters/cn/searchbox.md +1582 -0
- package/docs/search-filters/en/daterange.md +1156 -0
- package/docs/search-filters/en/numberrange.md +688 -0
- package/docs/search-filters/en/searchbox.md +1582 -0
- package/package.json +38 -5
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
# ActionBar 组件
|
|
2
|
+
|
|
3
|
+
`ActionBar` 组件提供了一个容器,用于组织多个按钮操作,确保一致的间距和布局。
|
|
4
|
+
|
|
5
|
+
## 基础用法
|
|
6
|
+
|
|
7
|
+
```svelte
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import ActionBar from '@ticatec/uniface-element/ActionBar';
|
|
10
|
+
import type { ButtonActions } from '@ticatec/uniface-element';
|
|
11
|
+
|
|
12
|
+
const actions: ButtonActions = [
|
|
13
|
+
{
|
|
14
|
+
label: "保存",
|
|
15
|
+
type: "primary",
|
|
16
|
+
icon: "icon_google_save",
|
|
17
|
+
handler: async () => {
|
|
18
|
+
await saveChanges();
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: "取消",
|
|
23
|
+
type: "secondary",
|
|
24
|
+
handler: async () => {
|
|
25
|
+
closeDialog();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<ActionBar buttons={actions} />
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 高级用法
|
|
35
|
+
|
|
36
|
+
```svelte
|
|
37
|
+
<script lang="ts">
|
|
38
|
+
import ActionBar from '@ticatec/uniface-element/ActionBar';
|
|
39
|
+
import type { ButtonActions } from '@ticatec/uniface-element';
|
|
40
|
+
|
|
41
|
+
let isProcessing = false;
|
|
42
|
+
|
|
43
|
+
const formActions: ButtonActions = [
|
|
44
|
+
{
|
|
45
|
+
label: "重置",
|
|
46
|
+
type: "default",
|
|
47
|
+
icon: "icon_google_undo",
|
|
48
|
+
handler: async () => {
|
|
49
|
+
resetForm();
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
null, // 分隔符
|
|
53
|
+
{
|
|
54
|
+
label: "预览",
|
|
55
|
+
type: "secondary",
|
|
56
|
+
icon: "icon_google_visibility",
|
|
57
|
+
handler: async () => {
|
|
58
|
+
showPreview();
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: isProcessing ? "处理中..." : "提交",
|
|
63
|
+
type: "primary",
|
|
64
|
+
icon: "icon_google_send",
|
|
65
|
+
disabled: isProcessing,
|
|
66
|
+
handler: async () => {
|
|
67
|
+
isProcessing = true;
|
|
68
|
+
try {
|
|
69
|
+
await submitForm();
|
|
70
|
+
} finally {
|
|
71
|
+
isProcessing = false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<ActionBar
|
|
79
|
+
buttons={formActions}
|
|
80
|
+
gap={12}
|
|
81
|
+
style="padding: 16px; justify-content: flex-end;"
|
|
82
|
+
/>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 带自定义内容的 ActionBar
|
|
86
|
+
|
|
87
|
+
```svelte
|
|
88
|
+
<script lang="ts">
|
|
89
|
+
import ActionBar from '@ticatec/uniface-element/ActionBar';
|
|
90
|
+
import Button from '@ticatec/uniface-element/Button';
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<!-- 当没有提供 buttons 属性时,使用插槽内容 -->
|
|
94
|
+
<ActionBar gap={16} style="padding: 20px;">
|
|
95
|
+
<Button label="自定义操作 1" type="primary" onClick={action1} />
|
|
96
|
+
<Button label="自定义操作 2" type="secondary" onClick={action2} />
|
|
97
|
+
<Button label="自定义操作 3" type="default" onClick={action3} />
|
|
98
|
+
</ActionBar>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 属性
|
|
102
|
+
|
|
103
|
+
| 属性 | 类型 | 默认值 | 描述 |
|
|
104
|
+
|------|------|--------|------|
|
|
105
|
+
| `buttons` | `ButtonActions` | `[]` | 按钮配置数组 |
|
|
106
|
+
| `style` | `string` | `''` | 自定义 CSS 样式 |
|
|
107
|
+
| `gap` | `number` | `8` | 按钮间距,单位像素 |
|
|
108
|
+
|
|
109
|
+
## API 参考
|
|
110
|
+
|
|
111
|
+
### ButtonAction 接口
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
interface ButtonAction {
|
|
115
|
+
/** 按钮标签文本 */
|
|
116
|
+
label: string;
|
|
117
|
+
|
|
118
|
+
/** 按钮是否禁用 */
|
|
119
|
+
disabled?: boolean;
|
|
120
|
+
|
|
121
|
+
/** 图标类(如 Google Material Icons) */
|
|
122
|
+
icon?: string;
|
|
123
|
+
|
|
124
|
+
/** 按钮类型用于样式设置 */
|
|
125
|
+
type?: ButtonType;
|
|
126
|
+
|
|
127
|
+
/** 点击事件处理器 */
|
|
128
|
+
handler?: MouseClickHandler;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type ButtonActions = Array<ButtonAction | null>;
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### MouseClickHandler 类型
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
type MouseClickHandler = (event: MouseEvent) => Promise<void>;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## 使用示例
|
|
141
|
+
|
|
142
|
+
### 对话框操作
|
|
143
|
+
|
|
144
|
+
```svelte
|
|
145
|
+
<script lang="ts">
|
|
146
|
+
import ActionBar from '@ticatec/uniface-element/ActionBar';
|
|
147
|
+
import type { ButtonActions } from '@ticatec/uniface-element';
|
|
148
|
+
|
|
149
|
+
export let onSave: () => Promise<void>;
|
|
150
|
+
export let onCancel: () => void;
|
|
151
|
+
|
|
152
|
+
const dialogActions: ButtonActions = [
|
|
153
|
+
{
|
|
154
|
+
label: "取消",
|
|
155
|
+
type: "secondary",
|
|
156
|
+
handler: async () => {
|
|
157
|
+
onCancel();
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
label: "保存更改",
|
|
162
|
+
type: "primary",
|
|
163
|
+
icon: "icon_google_save",
|
|
164
|
+
handler: async () => {
|
|
165
|
+
await onSave();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
];
|
|
169
|
+
</script>
|
|
170
|
+
|
|
171
|
+
<div class="dialog-footer">
|
|
172
|
+
<ActionBar buttons={dialogActions} style="justify-content: flex-end;" />
|
|
173
|
+
</div>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 表单操作栏
|
|
177
|
+
|
|
178
|
+
```svelte
|
|
179
|
+
<script lang="ts">
|
|
180
|
+
import ActionBar from '@ticatec/uniface-element/ActionBar';
|
|
181
|
+
import type { ButtonActions } from '@ticatec/uniface-element';
|
|
182
|
+
|
|
183
|
+
let formData = {};
|
|
184
|
+
let isSubmitting = false;
|
|
185
|
+
let isDraft = false;
|
|
186
|
+
|
|
187
|
+
const formActions: ButtonActions = [
|
|
188
|
+
{
|
|
189
|
+
label: "重置",
|
|
190
|
+
type: "default",
|
|
191
|
+
handler: async () => {
|
|
192
|
+
formData = {};
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
null, // 分隔符
|
|
196
|
+
{
|
|
197
|
+
label: isDraft ? "保存中..." : "保存草稿",
|
|
198
|
+
type: "secondary",
|
|
199
|
+
icon: "icon_google_save",
|
|
200
|
+
disabled: isDraft,
|
|
201
|
+
handler: async () => {
|
|
202
|
+
isDraft = true;
|
|
203
|
+
try {
|
|
204
|
+
await saveDraft(formData);
|
|
205
|
+
} finally {
|
|
206
|
+
isDraft = false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
label: isSubmitting ? "提交中..." : "提交",
|
|
212
|
+
type: "primary",
|
|
213
|
+
icon: "icon_google_send",
|
|
214
|
+
disabled: isSubmitting,
|
|
215
|
+
handler: async () => {
|
|
216
|
+
isSubmitting = true;
|
|
217
|
+
try {
|
|
218
|
+
await submitForm(formData);
|
|
219
|
+
} finally {
|
|
220
|
+
isSubmitting = false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
];
|
|
225
|
+
</script>
|
|
226
|
+
|
|
227
|
+
<form>
|
|
228
|
+
<!-- 表单字段在此 -->
|
|
229
|
+
|
|
230
|
+
<div class="form-footer">
|
|
231
|
+
<ActionBar
|
|
232
|
+
buttons={formActions}
|
|
233
|
+
gap={12}
|
|
234
|
+
style="justify-content: flex-end; margin-top: 24px;"
|
|
235
|
+
/>
|
|
236
|
+
</div>
|
|
237
|
+
</form>
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 工具栏实现
|
|
241
|
+
|
|
242
|
+
```svelte
|
|
243
|
+
<script lang="ts">
|
|
244
|
+
import ActionBar from '@ticatec/uniface-element/ActionBar';
|
|
245
|
+
import type { ButtonActions } from '@ticatec/uniface-element';
|
|
246
|
+
|
|
247
|
+
let selectedItems = [];
|
|
248
|
+
|
|
249
|
+
const toolbarActions: ButtonActions = [
|
|
250
|
+
{
|
|
251
|
+
label: "全选",
|
|
252
|
+
icon: "icon_google_check_box",
|
|
253
|
+
type: "default",
|
|
254
|
+
handler: async () => {
|
|
255
|
+
selectAll();
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
null, // 分隔符
|
|
259
|
+
{
|
|
260
|
+
label: "导出",
|
|
261
|
+
icon: "icon_google_download",
|
|
262
|
+
type: "secondary",
|
|
263
|
+
disabled: selectedItems.length === 0,
|
|
264
|
+
handler: async () => {
|
|
265
|
+
await exportItems(selectedItems);
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
label: "删除选中",
|
|
270
|
+
icon: "icon_google_delete",
|
|
271
|
+
type: "third",
|
|
272
|
+
disabled: selectedItems.length === 0,
|
|
273
|
+
handler: async () => {
|
|
274
|
+
if (confirm(`删除 ${selectedItems.length} 个项目?`)) {
|
|
275
|
+
await deleteItems(selectedItems);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
];
|
|
280
|
+
</script>
|
|
281
|
+
|
|
282
|
+
<div class="toolbar">
|
|
283
|
+
<div class="toolbar-info">
|
|
284
|
+
已选择 {selectedItems.length} 个项目
|
|
285
|
+
</div>
|
|
286
|
+
<ActionBar buttons={toolbarActions} />
|
|
287
|
+
</div>
|
|
288
|
+
|
|
289
|
+
<style>
|
|
290
|
+
.toolbar {
|
|
291
|
+
display: flex;
|
|
292
|
+
justify-content: space-between;
|
|
293
|
+
align-items: center;
|
|
294
|
+
padding: 12px;
|
|
295
|
+
border-bottom: 1px solid #eee;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.toolbar-info {
|
|
299
|
+
color: #666;
|
|
300
|
+
font-size: 14px;
|
|
301
|
+
}
|
|
302
|
+
</style>
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### 卡片操作栏
|
|
306
|
+
|
|
307
|
+
```svelte
|
|
308
|
+
<script lang="ts">
|
|
309
|
+
import ActionBar from '@ticatec/uniface-element/ActionBar';
|
|
310
|
+
import type { ButtonActions } from '@ticatec/uniface-element';
|
|
311
|
+
|
|
312
|
+
export let item: any;
|
|
313
|
+
export let onEdit: (item: any) => Promise<void>;
|
|
314
|
+
export let onShare: (item: any) => Promise<void>;
|
|
315
|
+
export let onDelete: (item: any) => Promise<void>;
|
|
316
|
+
|
|
317
|
+
const cardActions: ButtonActions = [
|
|
318
|
+
{
|
|
319
|
+
label: "编辑",
|
|
320
|
+
icon: "icon_google_edit",
|
|
321
|
+
type: "primary",
|
|
322
|
+
handler: async () => {
|
|
323
|
+
await onEdit(item);
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
label: "分享",
|
|
328
|
+
icon: "icon_google_share",
|
|
329
|
+
type: "secondary",
|
|
330
|
+
handler: async () => {
|
|
331
|
+
await onShare(item);
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
label: "删除",
|
|
336
|
+
icon: "icon_google_delete",
|
|
337
|
+
type: "third",
|
|
338
|
+
handler: async () => {
|
|
339
|
+
if (confirm("确定要删除此项目吗?")) {
|
|
340
|
+
await onDelete(item);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
];
|
|
345
|
+
</script>
|
|
346
|
+
|
|
347
|
+
<div class="card">
|
|
348
|
+
<div class="card-content">
|
|
349
|
+
<!-- 卡片内容 -->
|
|
350
|
+
</div>
|
|
351
|
+
|
|
352
|
+
<div class="card-actions">
|
|
353
|
+
<ActionBar buttons={cardActions} gap={8} />
|
|
354
|
+
</div>
|
|
355
|
+
</div>
|
|
356
|
+
|
|
357
|
+
<style>
|
|
358
|
+
.card {
|
|
359
|
+
border: 1px solid #e0e0e0;
|
|
360
|
+
border-radius: 8px;
|
|
361
|
+
overflow: hidden;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.card-content {
|
|
365
|
+
padding: 16px;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.card-actions {
|
|
369
|
+
padding: 12px 16px;
|
|
370
|
+
background: #f8f9fa;
|
|
371
|
+
border-top: 1px solid #e0e0e0;
|
|
372
|
+
}
|
|
373
|
+
</style>
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## 最佳实践
|
|
377
|
+
|
|
378
|
+
### 使用分隔符组织操作
|
|
379
|
+
|
|
380
|
+
使用 `null` 值作为分隔符来组织相关操作:
|
|
381
|
+
|
|
382
|
+
```svelte
|
|
383
|
+
<script lang="ts">
|
|
384
|
+
const editorActions: ButtonActions = [
|
|
385
|
+
// 文件操作组
|
|
386
|
+
{ label: "新建", icon: "icon_google_add", handler: newFile },
|
|
387
|
+
{ label: "打开", icon: "icon_google_folder_open", handler: openFile },
|
|
388
|
+
{ label: "保存", icon: "icon_google_save", handler: saveFile },
|
|
389
|
+
|
|
390
|
+
null, // 分隔符
|
|
391
|
+
|
|
392
|
+
// 编辑操作组
|
|
393
|
+
{ label: "撤销", icon: "icon_google_undo", handler: undo },
|
|
394
|
+
{ label: "重做", icon: "icon_google_redo", handler: redo },
|
|
395
|
+
|
|
396
|
+
null, // 分隔符
|
|
397
|
+
|
|
398
|
+
// 主要操作
|
|
399
|
+
{ label: "发布", type: "primary", icon: "icon_google_publish", handler: publish }
|
|
400
|
+
];
|
|
401
|
+
</script>
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### 使用合适的间距
|
|
405
|
+
|
|
406
|
+
根据界面密度调整按钮间距:
|
|
407
|
+
|
|
408
|
+
```svelte
|
|
409
|
+
<!-- 紧凑界面 -->
|
|
410
|
+
<ActionBar buttons={actions} gap={4} />
|
|
411
|
+
|
|
412
|
+
<!-- 标准界面 -->
|
|
413
|
+
<ActionBar buttons={actions} gap={8} />
|
|
414
|
+
|
|
415
|
+
<!-- 宽松界面 -->
|
|
416
|
+
<ActionBar buttons={actions} gap={16} />
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### 响应式设计
|
|
420
|
+
|
|
421
|
+
考虑在小屏幕上隐藏或简化操作:
|
|
422
|
+
|
|
423
|
+
```svelte
|
|
424
|
+
<script lang="ts">
|
|
425
|
+
import { onMount } from 'svelte';
|
|
426
|
+
|
|
427
|
+
let isMobile = false;
|
|
428
|
+
|
|
429
|
+
onMount(() => {
|
|
430
|
+
const checkMobile = () => {
|
|
431
|
+
isMobile = window.innerWidth < 768;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
checkMobile();
|
|
435
|
+
window.addEventListener('resize', checkMobile);
|
|
436
|
+
|
|
437
|
+
return () => window.removeEventListener('resize', checkMobile);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
$: responsiveActions = isMobile
|
|
441
|
+
? [
|
|
442
|
+
{ label: "保存", type: "primary", handler: save },
|
|
443
|
+
{ label: "取消", type: "secondary", handler: cancel }
|
|
444
|
+
]
|
|
445
|
+
: [
|
|
446
|
+
{ label: "重置", type: "default", handler: reset },
|
|
447
|
+
null,
|
|
448
|
+
{ label: "预览", type: "secondary", handler: preview },
|
|
449
|
+
{ label: "保存", type: "primary", handler: save },
|
|
450
|
+
{ label: "取消", type: "secondary", handler: cancel }
|
|
451
|
+
];
|
|
452
|
+
</script>
|
|
453
|
+
|
|
454
|
+
<ActionBar buttons={responsiveActions} />
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## 点击节流
|
|
458
|
+
|
|
459
|
+
ActionBar 中的所有按钮都实现了自动点击节流,具有 500ms 冷却时间,以防止意外的双击并确保正确的异步操作处理。
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Button 组件
|
|
2
|
+
|
|
3
|
+
主要的 `Button` 组件提供了支持图标和标签的全面按钮功能。
|
|
4
|
+
|
|
5
|
+
## 基础用法
|
|
6
|
+
|
|
7
|
+
```svelte
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import Button from '@ticatec/uniface-element/Button';
|
|
10
|
+
|
|
11
|
+
const handleClick = async (event: MouseEvent) => {
|
|
12
|
+
console.log('按钮被点击!');
|
|
13
|
+
// 执行异步操作
|
|
14
|
+
};
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<Button
|
|
18
|
+
label="保存更改"
|
|
19
|
+
type="primary"
|
|
20
|
+
icon="icon_google_save"
|
|
21
|
+
onClick={handleClick}
|
|
22
|
+
/>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 高级配置
|
|
26
|
+
|
|
27
|
+
```svelte
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
import Button from '@ticatec/uniface-element/Button';
|
|
30
|
+
import type { ButtonType } from '@ticatec/uniface-element';
|
|
31
|
+
|
|
32
|
+
let isSubmitting = false;
|
|
33
|
+
|
|
34
|
+
const handleSubmit = async (event: MouseEvent) => {
|
|
35
|
+
isSubmitting = true;
|
|
36
|
+
try {
|
|
37
|
+
await submitForm();
|
|
38
|
+
} finally {
|
|
39
|
+
isSubmitting = false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<Button
|
|
45
|
+
label={isSubmitting ? "提交中..." : "提交表单"}
|
|
46
|
+
type="primary"
|
|
47
|
+
size="big"
|
|
48
|
+
variant="round"
|
|
49
|
+
icon="icon_google_send"
|
|
50
|
+
disabled={isSubmitting}
|
|
51
|
+
style="margin: 16px;"
|
|
52
|
+
onClick={handleSubmit}
|
|
53
|
+
/>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 属性
|
|
57
|
+
|
|
58
|
+
| 属性 | 类型 | 默认值 | 描述 |
|
|
59
|
+
|------|------|--------|------|
|
|
60
|
+
| `label` | `string` | `''` | 按钮文本标签 |
|
|
61
|
+
| `type` | `ButtonType` | `'default'` | 视觉样式变体 |
|
|
62
|
+
| `size` | `'big' \| 'medium' \| 'mini'` | `'medium'` | 按钮大小 |
|
|
63
|
+
| `variant` | `'plain' \| 'round' \| ''` | `''` | 附加样式变体 |
|
|
64
|
+
| `icon` | `string \| null` | `null` | 图标类(如 Google Material Icons) |
|
|
65
|
+
| `disabled` | `boolean` | `false` | 禁用按钮交互 |
|
|
66
|
+
| `style` | `string` | `''` | 自定义 CSS 样式 |
|
|
67
|
+
| `onClick` | `(event: MouseEvent) => void` | - | 点击事件处理器 |
|
|
68
|
+
|
|
69
|
+
## 带插槽内容的按钮
|
|
70
|
+
|
|
71
|
+
```svelte
|
|
72
|
+
<Button type="secondary" onClick={handleAction}>
|
|
73
|
+
<i class="icon_google_star"></i>
|
|
74
|
+
<span>自定义内容</span>
|
|
75
|
+
<span class="badge">3</span>
|
|
76
|
+
</Button>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 样式变体
|
|
80
|
+
|
|
81
|
+
### ButtonType 选项
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
type ButtonType = 'default' | 'primary' | 'secondary' | 'third' | 'forth';
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 视觉外观
|
|
88
|
+
|
|
89
|
+
- **default**: 标准中性按钮外观
|
|
90
|
+
- **primary**: 强调主要操作的按钮(通常为蓝色)
|
|
91
|
+
- **secondary**: 次要操作按钮(通常为灰色)
|
|
92
|
+
- **third**: 替代样式(通常用于警告/注意)
|
|
93
|
+
- **forth**: 附加样式变体
|
|
94
|
+
|
|
95
|
+
### 大小变体
|
|
96
|
+
|
|
97
|
+
- **big**: 大按钮尺寸,用于突出操作
|
|
98
|
+
- **medium**: 标准按钮尺寸,适用于大多数使用场景
|
|
99
|
+
- **mini**: 小按钮尺寸,用于紧凑界面
|
|
100
|
+
|
|
101
|
+
### 样式变体
|
|
102
|
+
|
|
103
|
+
- **plain**: 最小化样式变体
|
|
104
|
+
- **round**: 圆角变体
|
|
105
|
+
- **'' (空字符串)**: 标准样式
|
|
106
|
+
|
|
107
|
+
## 图标使用
|
|
108
|
+
|
|
109
|
+
组件使用 `@ticatec/uniface-google-material-icons` 作为图标库。只需传入图标类名:
|
|
110
|
+
|
|
111
|
+
```svelte
|
|
112
|
+
<!-- 常用 Material Icons -->
|
|
113
|
+
<Button icon="icon_google_save" label="保存" />
|
|
114
|
+
<Button icon="icon_google_edit" label="编辑" />
|
|
115
|
+
<Button icon="icon_google_delete" label="删除" />
|
|
116
|
+
<Button icon="icon_google_add" label="添加" />
|
|
117
|
+
<Button icon="icon_google_remove" label="移除" />
|
|
118
|
+
<Button icon="icon_google_search" label="搜索" />
|
|
119
|
+
<Button icon="icon_google_settings" label="设置" />
|
|
120
|
+
<Button icon="icon_google_home" label="主页" />
|
|
121
|
+
<Button icon="icon_google_check" label="确认" />
|
|
122
|
+
<Button icon="icon_google_arrow_back" label="返回" />
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 最佳实践
|
|
126
|
+
|
|
127
|
+
### 使用合适的按钮类型
|
|
128
|
+
|
|
129
|
+
根据操作重要性选择正确的按钮类型:
|
|
130
|
+
|
|
131
|
+
```svelte
|
|
132
|
+
<!-- 主要操作 -->
|
|
133
|
+
<Button label="保存" type="primary" />
|
|
134
|
+
<Button label="提交" type="primary" />
|
|
135
|
+
|
|
136
|
+
<!-- 次要操作 -->
|
|
137
|
+
<Button label="取消" type="secondary" />
|
|
138
|
+
<Button label="预览" type="secondary" />
|
|
139
|
+
|
|
140
|
+
<!-- 危险操作 -->
|
|
141
|
+
<Button label="删除" type="third" />
|
|
142
|
+
<Button label="移除" type="third" />
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 正确处理异步操作
|
|
146
|
+
|
|
147
|
+
始终处理加载状态和错误:
|
|
148
|
+
|
|
149
|
+
```svelte
|
|
150
|
+
<script lang="ts">
|
|
151
|
+
let isLoading = false;
|
|
152
|
+
let error = null;
|
|
153
|
+
|
|
154
|
+
const handleAction = async () => {
|
|
155
|
+
isLoading = true;
|
|
156
|
+
error = null;
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
await performAction();
|
|
160
|
+
} catch (err) {
|
|
161
|
+
error = err.message;
|
|
162
|
+
} finally {
|
|
163
|
+
isLoading = false;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<Button
|
|
169
|
+
label={isLoading ? "处理中..." : "开始处理"}
|
|
170
|
+
type="primary"
|
|
171
|
+
disabled={isLoading}
|
|
172
|
+
onClick={handleAction}
|
|
173
|
+
/>
|
|
174
|
+
|
|
175
|
+
{#if error}
|
|
176
|
+
<div class="error">{error}</div>
|
|
177
|
+
{/if}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 提供视觉反馈
|
|
181
|
+
|
|
182
|
+
使用图标和适当的样式:
|
|
183
|
+
|
|
184
|
+
```svelte
|
|
185
|
+
<!-- 成功操作 -->
|
|
186
|
+
<Button label="保存" icon="icon_google_save" type="primary" />
|
|
187
|
+
|
|
188
|
+
<!-- 危险操作 -->
|
|
189
|
+
<Button label="删除" icon="icon_google_delete" type="third" />
|
|
190
|
+
|
|
191
|
+
<!-- 导航操作 -->
|
|
192
|
+
<Button label="返回" icon="icon_google_arrow_back" type="secondary" />
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### 考虑移动端响应式
|
|
196
|
+
|
|
197
|
+
为不同屏幕尺寸使用合适的大小:
|
|
198
|
+
|
|
199
|
+
```svelte
|
|
200
|
+
<div class="responsive-buttons">
|
|
201
|
+
<!-- 桌面端: 普通大小,移动端: 更大以适应触摸 -->
|
|
202
|
+
<Button label="操作" size="big" class="mobile-friendly" />
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
<style>
|
|
206
|
+
.responsive-buttons .mobile-friendly {
|
|
207
|
+
/* 响应式样式 */
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@media (max-width: 768px) {
|
|
211
|
+
.responsive-buttons .mobile-friendly {
|
|
212
|
+
min-height: 44px; /* iOS 推荐的触摸目标大小 */
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
</style>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## 无障碍性注意事项
|
|
219
|
+
|
|
220
|
+
**⚠️ 重要提示**:当前的按钮组件存在以下无障碍性限制:
|
|
221
|
+
|
|
222
|
+
- **非语义化元素**:所有按钮都使用 `<div>` 元素而不是 `<button>`
|
|
223
|
+
- **对屏幕阅读器隐藏**:所有按钮默认都有 `aria-hidden="true"`
|
|
224
|
+
- **无键盘导航**:组件不支持 Tab 导航或 Enter/Space 激活
|
|
225
|
+
- **无焦点管理**:组件不提供 focus 方法或支持 `bind:this`
|
|
226
|
+
- **无 ARIA 属性支持**:自定义 aria-* 属性无法传递
|
|
227
|
+
|
|
228
|
+
如需完全的无障碍性支持,请考虑使用正确的语义化元素包装组件。
|