@ticatec/uniface-element 0.2.0 → 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/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/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,512 @@
|
|
|
1
|
+
# NavigatorMenu 导航菜单组件
|
|
2
|
+
|
|
3
|
+
NavigatorMenu 组件提供分层菜单系统,支持可展开/折叠的树形导航,具有嵌套菜单结构和流畅的动画效果。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- **分层导航**:多级树形菜单结构
|
|
8
|
+
- **可展开项目**:带有子导航的可折叠菜单项
|
|
9
|
+
- **流畅动画**:展开/折叠的滑动过渡效果
|
|
10
|
+
- **灵活的数据结构**:支持任何菜单项数据格式
|
|
11
|
+
- **自定义文本字段**:可配置从菜单项提取文本的方式
|
|
12
|
+
- **点击处理**:菜单操作的自定义点击处理器
|
|
13
|
+
- **递归渲染**:自动处理嵌套菜单层级
|
|
14
|
+
|
|
15
|
+
## 导入
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { NavigatorMenu, MenuItem } from '@ticatec/uniface-element/NavigatorMenu';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 基本用法
|
|
22
|
+
|
|
23
|
+
### 简单菜单
|
|
24
|
+
|
|
25
|
+
```svelte
|
|
26
|
+
<script>
|
|
27
|
+
import { NavigatorMenu } from '@ticatec/uniface-element/NavigatorMenu';
|
|
28
|
+
|
|
29
|
+
const menuItems = [
|
|
30
|
+
{
|
|
31
|
+
item: { name: "仪表板", route: "/dashboard" },
|
|
32
|
+
expand: false,
|
|
33
|
+
children: null
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
item: { name: "用户", route: "/users" },
|
|
37
|
+
expand: false,
|
|
38
|
+
children: [
|
|
39
|
+
{
|
|
40
|
+
item: { name: "所有用户", route: "/users/list" },
|
|
41
|
+
expand: false,
|
|
42
|
+
children: null
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
item: { name: "添加用户", route: "/users/add" },
|
|
46
|
+
expand: false,
|
|
47
|
+
children: null
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
item: { name: "设置", route: "/settings" },
|
|
53
|
+
expand: false,
|
|
54
|
+
children: null
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const handleMenuClick = (menuItem) => {
|
|
59
|
+
console.log('菜单点击:', menuItem.item.name);
|
|
60
|
+
console.log('导航到:', menuItem.item.route);
|
|
61
|
+
};
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<NavigatorMenu
|
|
65
|
+
menuItems={menuItems}
|
|
66
|
+
textField="name"
|
|
67
|
+
onItemClick={handleMenuClick}
|
|
68
|
+
/>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 自定义文本提取的菜单
|
|
72
|
+
|
|
73
|
+
```svelte
|
|
74
|
+
<script>
|
|
75
|
+
import { NavigatorMenu } from '@ticatec/uniface-element/NavigatorMenu';
|
|
76
|
+
|
|
77
|
+
const navigationMenu = [
|
|
78
|
+
{
|
|
79
|
+
item: { title: "首页", icon: "home", path: "/" },
|
|
80
|
+
expand: false,
|
|
81
|
+
children: null
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
item: { title: "产品", icon: "products", path: "/products" },
|
|
85
|
+
expand: true, // 初始展开
|
|
86
|
+
children: [
|
|
87
|
+
{
|
|
88
|
+
item: { title: "电子产品", path: "/products/electronics" },
|
|
89
|
+
expand: false,
|
|
90
|
+
children: [
|
|
91
|
+
{
|
|
92
|
+
item: { title: "电脑", path: "/products/electronics/computers" },
|
|
93
|
+
expand: false,
|
|
94
|
+
children: null
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
item: { title: "手机", path: "/products/electronics/phones" },
|
|
98
|
+
expand: false,
|
|
99
|
+
children: null
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
item: { title: "服装", path: "/products/clothing" },
|
|
105
|
+
expand: false,
|
|
106
|
+
children: null
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
// 从菜单项提取文本的自定义函数
|
|
113
|
+
const getMenuText = (item) => {
|
|
114
|
+
return `${item.icon ? '📁 ' : '📄 '}${item.title}`;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const handleItemClick = (menuItem) => {
|
|
118
|
+
console.log('点击:', menuItem.item.title);
|
|
119
|
+
};
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<NavigatorMenu
|
|
123
|
+
menuItems={navigationMenu}
|
|
124
|
+
textField={getMenuText}
|
|
125
|
+
onItemClick={handleItemClick}
|
|
126
|
+
style="width: 300px; border: 1px solid #e0e0e0; border-radius: 4px;"
|
|
127
|
+
/>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## API 参考
|
|
131
|
+
|
|
132
|
+
### 属性
|
|
133
|
+
|
|
134
|
+
| 属性 | 类型 | 默认值 | 描述 |
|
|
135
|
+
|------|------|--------|------|
|
|
136
|
+
| `menuItems` | `Array<MenuItem>` | 必需 | 菜单项对象数组 |
|
|
137
|
+
| `style` | `string` | `''` | 附加CSS样式 |
|
|
138
|
+
| `textField` | `string \| GetText<MenuItem>` | 必需 | 提取文本的字段名或函数 |
|
|
139
|
+
| `onItemClick` | `OnMenuClick` | 必需 | 菜单项的点击处理器 |
|
|
140
|
+
|
|
141
|
+
### MenuItem 接口
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
interface MenuItem {
|
|
145
|
+
[key: string]: any; // 灵活的项目数据结构
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface MenuNode extends TreeNode<MenuItem> {
|
|
149
|
+
item: MenuItem; // 实际的菜单数据
|
|
150
|
+
expand: boolean; // 此节点是否展开
|
|
151
|
+
children: MenuNode[] | null; // 子菜单项
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 类型定义
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
type OnMenuClick = (item: MenuItem) => void;
|
|
159
|
+
type GetText<T> = (item: T) => string;
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 高级示例
|
|
163
|
+
|
|
164
|
+
### 带图标的应用导航
|
|
165
|
+
|
|
166
|
+
```svelte
|
|
167
|
+
<script>
|
|
168
|
+
import { NavigatorMenu } from '@ticatec/uniface-element/NavigatorMenu';
|
|
169
|
+
|
|
170
|
+
let appNavigation = [
|
|
171
|
+
{
|
|
172
|
+
item: {
|
|
173
|
+
id: 'dashboard',
|
|
174
|
+
label: "仪表板",
|
|
175
|
+
icon: "📊",
|
|
176
|
+
route: "/dashboard",
|
|
177
|
+
permissions: ["read"]
|
|
178
|
+
},
|
|
179
|
+
expand: false,
|
|
180
|
+
children: null
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
item: {
|
|
184
|
+
id: 'admin',
|
|
185
|
+
label: "管理",
|
|
186
|
+
icon: "⚙️",
|
|
187
|
+
permissions: ["admin"]
|
|
188
|
+
},
|
|
189
|
+
expand: false,
|
|
190
|
+
children: [
|
|
191
|
+
{
|
|
192
|
+
item: {
|
|
193
|
+
id: 'users',
|
|
194
|
+
label: "用户管理",
|
|
195
|
+
route: "/admin/users",
|
|
196
|
+
permissions: ["admin", "user_management"]
|
|
197
|
+
},
|
|
198
|
+
expand: false,
|
|
199
|
+
children: [
|
|
200
|
+
{
|
|
201
|
+
item: {
|
|
202
|
+
id: 'user_list',
|
|
203
|
+
label: "查看用户",
|
|
204
|
+
route: "/admin/users/list"
|
|
205
|
+
},
|
|
206
|
+
expand: false,
|
|
207
|
+
children: null
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
item: {
|
|
211
|
+
id: 'user_create',
|
|
212
|
+
label: "创建用户",
|
|
213
|
+
route: "/admin/users/create"
|
|
214
|
+
},
|
|
215
|
+
expand: false,
|
|
216
|
+
children: null
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
item: {
|
|
220
|
+
id: 'user_roles',
|
|
221
|
+
label: "管理角色",
|
|
222
|
+
route: "/admin/users/roles"
|
|
223
|
+
},
|
|
224
|
+
expand: false,
|
|
225
|
+
children: null
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
item: {
|
|
231
|
+
id: 'system',
|
|
232
|
+
label: "系统设置",
|
|
233
|
+
route: "/admin/system"
|
|
234
|
+
},
|
|
235
|
+
expand: false,
|
|
236
|
+
children: null
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
item: {
|
|
242
|
+
id: 'reports',
|
|
243
|
+
label: "报告",
|
|
244
|
+
icon: "📈",
|
|
245
|
+
route: "/reports"
|
|
246
|
+
},
|
|
247
|
+
expand: false,
|
|
248
|
+
children: [
|
|
249
|
+
{
|
|
250
|
+
item: {
|
|
251
|
+
id: 'sales_reports',
|
|
252
|
+
label: "销售报告",
|
|
253
|
+
route: "/reports/sales"
|
|
254
|
+
},
|
|
255
|
+
expand: false,
|
|
256
|
+
children: null
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
item: {
|
|
260
|
+
id: 'user_reports',
|
|
261
|
+
label: "用户报告",
|
|
262
|
+
route: "/reports/users"
|
|
263
|
+
},
|
|
264
|
+
expand: false,
|
|
265
|
+
children: null
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
];
|
|
270
|
+
|
|
271
|
+
const formatMenuText = (item) => {
|
|
272
|
+
return `${item.icon || '📄'} ${item.label}`;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const handleNavigation = (menuNode) => {
|
|
276
|
+
const item = menuNode.item;
|
|
277
|
+
|
|
278
|
+
if (item.route) {
|
|
279
|
+
console.log(`导航到: ${item.route}`);
|
|
280
|
+
// 在这里处理实际导航
|
|
281
|
+
} else {
|
|
282
|
+
console.log(`菜单部分: ${item.label}`);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
</script>
|
|
286
|
+
|
|
287
|
+
<div class="app-navigation">
|
|
288
|
+
<h3>应用菜单</h3>
|
|
289
|
+
<NavigatorMenu
|
|
290
|
+
menuItems={appNavigation}
|
|
291
|
+
textField={formatMenuText}
|
|
292
|
+
onItemClick={handleNavigation}
|
|
293
|
+
style="background: #f8f9fa; border-radius: 8px; padding: 10px;"
|
|
294
|
+
/>
|
|
295
|
+
</div>
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### 文件系统资源管理器菜单
|
|
299
|
+
|
|
300
|
+
```svelte
|
|
301
|
+
<script>
|
|
302
|
+
import { NavigatorMenu } from '@ticatec/uniface-element/NavigatorMenu';
|
|
303
|
+
|
|
304
|
+
let fileSystemMenu = [
|
|
305
|
+
{
|
|
306
|
+
item: {
|
|
307
|
+
name: "文档",
|
|
308
|
+
type: "folder",
|
|
309
|
+
path: "/documents",
|
|
310
|
+
size: null
|
|
311
|
+
},
|
|
312
|
+
expand: true,
|
|
313
|
+
children: [
|
|
314
|
+
{
|
|
315
|
+
item: {
|
|
316
|
+
name: "项目",
|
|
317
|
+
type: "folder",
|
|
318
|
+
path: "/documents/projects"
|
|
319
|
+
},
|
|
320
|
+
expand: false,
|
|
321
|
+
children: [
|
|
322
|
+
{
|
|
323
|
+
item: {
|
|
324
|
+
name: "webapp",
|
|
325
|
+
type: "folder",
|
|
326
|
+
path: "/documents/projects/webapp"
|
|
327
|
+
},
|
|
328
|
+
expand: false,
|
|
329
|
+
children: [
|
|
330
|
+
{
|
|
331
|
+
item: {
|
|
332
|
+
name: "src",
|
|
333
|
+
type: "folder",
|
|
334
|
+
path: "/documents/projects/webapp/src"
|
|
335
|
+
},
|
|
336
|
+
expand: false,
|
|
337
|
+
children: null
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
item: {
|
|
341
|
+
name: "package.json",
|
|
342
|
+
type: "file",
|
|
343
|
+
path: "/documents/projects/webapp/package.json",
|
|
344
|
+
size: "2.1 KB"
|
|
345
|
+
},
|
|
346
|
+
expand: false,
|
|
347
|
+
children: null
|
|
348
|
+
}
|
|
349
|
+
]
|
|
350
|
+
}
|
|
351
|
+
]
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
item: {
|
|
355
|
+
name: "简历.pdf",
|
|
356
|
+
type: "file",
|
|
357
|
+
path: "/documents/resume.pdf",
|
|
358
|
+
size: "145 KB"
|
|
359
|
+
},
|
|
360
|
+
expand: false,
|
|
361
|
+
children: null
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
item: {
|
|
367
|
+
name: "下载",
|
|
368
|
+
type: "folder",
|
|
369
|
+
path: "/downloads"
|
|
370
|
+
},
|
|
371
|
+
expand: false,
|
|
372
|
+
children: [
|
|
373
|
+
{
|
|
374
|
+
item: {
|
|
375
|
+
name: "安装程序.exe",
|
|
376
|
+
type: "file",
|
|
377
|
+
path: "/downloads/installer.exe",
|
|
378
|
+
size: "12.3 MB"
|
|
379
|
+
},
|
|
380
|
+
expand: false,
|
|
381
|
+
children: null
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
}
|
|
385
|
+
];
|
|
386
|
+
|
|
387
|
+
const getFileDisplayText = (item) => {
|
|
388
|
+
const icon = item.type === 'folder' ? '📁' : '📄';
|
|
389
|
+
const sizeText = item.size ? ` (${item.size})` : '';
|
|
390
|
+
return `${icon} ${item.name}${sizeText}`;
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const handleFileClick = (menuNode) => {
|
|
394
|
+
const file = menuNode.item;
|
|
395
|
+
|
|
396
|
+
if (file.type === 'file') {
|
|
397
|
+
console.log(`打开文件: ${file.path}`);
|
|
398
|
+
} else {
|
|
399
|
+
console.log(`访问文件夹: ${file.path}`);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
</script>
|
|
403
|
+
|
|
404
|
+
<div class="file-explorer">
|
|
405
|
+
<h3>文件资源管理器</h3>
|
|
406
|
+
<NavigatorMenu
|
|
407
|
+
menuItems={fileSystemMenu}
|
|
408
|
+
textField={getFileDisplayText}
|
|
409
|
+
onItemClick={handleFileClick}
|
|
410
|
+
style="font-family: 'Courier New', monospace; border: 1px solid #ccc; max-height: 400px; overflow-y: auto;"
|
|
411
|
+
/>
|
|
412
|
+
</div>
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
### 带状态管理的动态菜单
|
|
416
|
+
|
|
417
|
+
```svelte
|
|
418
|
+
<script>
|
|
419
|
+
import { NavigatorMenu } from '@ticatec/uniface-element/NavigatorMenu';
|
|
420
|
+
|
|
421
|
+
let dynamicMenu = [
|
|
422
|
+
{
|
|
423
|
+
item: { id: 1, title: "主要部分", active: false },
|
|
424
|
+
expand: false,
|
|
425
|
+
children: [
|
|
426
|
+
{
|
|
427
|
+
item: { id: 11, title: "子部分 A", active: false },
|
|
428
|
+
expand: false,
|
|
429
|
+
children: null
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
item: { id: 12, title: "子部分 B", active: true },
|
|
433
|
+
expand: false,
|
|
434
|
+
children: null
|
|
435
|
+
}
|
|
436
|
+
]
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
item: { id: 2, title: "次要部分", active: false },
|
|
440
|
+
expand: false,
|
|
441
|
+
children: null
|
|
442
|
+
}
|
|
443
|
+
];
|
|
444
|
+
|
|
445
|
+
let activeItemId = 12;
|
|
446
|
+
|
|
447
|
+
const getMenuText = (item) => {
|
|
448
|
+
const activeIndicator = item.id === activeItemId ? '▶ ' : '';
|
|
449
|
+
return `${activeIndicator}${item.title}`;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const handleMenuSelection = (menuNode) => {
|
|
453
|
+
const item = menuNode.item;
|
|
454
|
+
|
|
455
|
+
// 更新激活状态
|
|
456
|
+
activeItemId = item.id;
|
|
457
|
+
console.log(`选择: ${item.title} (ID: ${item.id})`);
|
|
458
|
+
|
|
459
|
+
// 通过触发响应式更新强制菜单刷新
|
|
460
|
+
dynamicMenu = [...dynamicMenu];
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
const addMenuItem = () => {
|
|
464
|
+
const newId = Date.now();
|
|
465
|
+
dynamicMenu[0].children.push({
|
|
466
|
+
item: { id: newId, title: `新项目 ${newId}`, active: false },
|
|
467
|
+
expand: false,
|
|
468
|
+
children: null
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
dynamicMenu = [...dynamicMenu]; // 触发响应式更新
|
|
472
|
+
};
|
|
473
|
+
</script>
|
|
474
|
+
|
|
475
|
+
<div class="dynamic-menu">
|
|
476
|
+
<NavigatorMenu
|
|
477
|
+
menuItems={dynamicMenu}
|
|
478
|
+
textField={getMenuText}
|
|
479
|
+
onItemClick={handleMenuSelection}
|
|
480
|
+
style="border: 2px solid #007acc; border-radius: 6px; padding: 8px;"
|
|
481
|
+
/>
|
|
482
|
+
|
|
483
|
+
<button on:click={addMenuItem} style="margin-top: 10px;">
|
|
484
|
+
添加新菜单项
|
|
485
|
+
</button>
|
|
486
|
+
</div>
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
## 最佳实践
|
|
490
|
+
|
|
491
|
+
1. **清晰的层次结构**:设计反映应用程序组织的菜单结构
|
|
492
|
+
2. **适当的嵌套**:避免过多嵌套层级(最多3-4级)
|
|
493
|
+
3. **一致的文本**:在菜单项中使用一致的命名约定
|
|
494
|
+
4. **性能优化**:对于非常大的菜单结构考虑延迟加载
|
|
495
|
+
5. **状态管理**:适当地跟踪展开/折叠状态
|
|
496
|
+
6. **无障碍访问**:确保菜单项的键盘导航支持
|
|
497
|
+
7. **视觉反馈**:为可展开项目和当前选择提供清晰的指示器
|
|
498
|
+
|
|
499
|
+
## 样式说明
|
|
500
|
+
|
|
501
|
+
- 组件使用`<ul>`和`<li>`元素构建语义化菜单结构
|
|
502
|
+
- 可展开项目有独特的样式类
|
|
503
|
+
- 滑动过渡提供流畅的展开/折叠动画
|
|
504
|
+
- 自定义CSS可以通过`style`属性应用
|
|
505
|
+
|
|
506
|
+
## 集成提示
|
|
507
|
+
|
|
508
|
+
- 与路由库结合使用进行导航处理
|
|
509
|
+
- 考虑菜单展开状态的状态持久化
|
|
510
|
+
- 为大型菜单实现搜索/筛选功能
|
|
511
|
+
- 为常见菜单操作添加键盘快捷键
|
|
512
|
+
- 使用各种数据结构进行测试以确保灵活性
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# ProgressBar 进度条组件
|
|
2
|
+
|
|
3
|
+
ProgressBar 组件提供可视化进度指示,支持圆形和线性显示模式,以及各种状态指示。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- **多种显示类型**:圆形和线性进度条
|
|
8
|
+
- **状态指示器**:成功、失败、取消和进行中状态
|
|
9
|
+
- **可定制外观**:可配置尺寸、颜色和文本显示
|
|
10
|
+
- **视觉反馈**:不同状态的图标和颜色编码
|
|
11
|
+
- **CSS 自定义属性**:通过 CSS 变量支持主题
|
|
12
|
+
|
|
13
|
+
## 导入
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { ProgressBar, ProgressStatus } from '@ticatec/uniface-element/ProgressBar';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 基本用法
|
|
20
|
+
|
|
21
|
+
### 圆形进度条
|
|
22
|
+
|
|
23
|
+
```svelte
|
|
24
|
+
<script>
|
|
25
|
+
import { ProgressBar, ProgressStatus } from '@ticatec/uniface-element/ProgressBar';
|
|
26
|
+
|
|
27
|
+
let progress = 65;
|
|
28
|
+
let status = ProgressStatus.progressing;
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<ProgressBar
|
|
32
|
+
{progress}
|
|
33
|
+
{status}
|
|
34
|
+
type="circular"
|
|
35
|
+
size={120}
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 线性进度条
|
|
40
|
+
|
|
41
|
+
```svelte
|
|
42
|
+
<script>
|
|
43
|
+
import { ProgressBar, ProgressStatus } from '@ticatec/uniface-element/ProgressBar';
|
|
44
|
+
|
|
45
|
+
let progress = 45;
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<ProgressBar
|
|
49
|
+
{progress}
|
|
50
|
+
type="liner"
|
|
51
|
+
height={8}
|
|
52
|
+
showText={true}
|
|
53
|
+
/>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API 参考
|
|
57
|
+
|
|
58
|
+
### 属性
|
|
59
|
+
|
|
60
|
+
| 属性 | 类型 | 默认值 | 描述 |
|
|
61
|
+
|------|------|--------|------|
|
|
62
|
+
| `progress` | `number` | `0` | 进度值 (0-100) |
|
|
63
|
+
| `size` | `number` | `100` | 圆形进度条的大小 |
|
|
64
|
+
| `type` | `'circular' \| 'liner'` | `'circular'` | 进度条类型 |
|
|
65
|
+
| `height` | `number` | `5` | 进度条高度/厚度 |
|
|
66
|
+
| `showText` | `boolean` | `true` | 是否显示进度文本 |
|
|
67
|
+
| `status` | `ProgressStatus` | `ProgressStatus.progressing` | 进度状态 |
|
|
68
|
+
|
|
69
|
+
### ProgressStatus 枚举
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
enum ProgressStatus {
|
|
73
|
+
progressing = 'progressing', // 进行中
|
|
74
|
+
successful = 'successful', // 成功
|
|
75
|
+
failure = 'failure', // 失败
|
|
76
|
+
canceled = 'canceled' // 已取消
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 状态示例
|
|
81
|
+
|
|
82
|
+
### 成功状态
|
|
83
|
+
|
|
84
|
+
```svelte
|
|
85
|
+
<ProgressBar
|
|
86
|
+
progress={100}
|
|
87
|
+
status={ProgressStatus.successful}
|
|
88
|
+
type="circular"
|
|
89
|
+
/>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 失败状态
|
|
93
|
+
|
|
94
|
+
```svelte
|
|
95
|
+
<ProgressBar
|
|
96
|
+
progress={50}
|
|
97
|
+
status={ProgressStatus.failure}
|
|
98
|
+
type="liner"
|
|
99
|
+
/>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 取消状态
|
|
103
|
+
|
|
104
|
+
```svelte
|
|
105
|
+
<ProgressBar
|
|
106
|
+
progress={30}
|
|
107
|
+
status={ProgressStatus.canceled}
|
|
108
|
+
type="circular"
|
|
109
|
+
/>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 样式定制
|
|
113
|
+
|
|
114
|
+
组件使用 CSS 自定义属性进行主题配置:
|
|
115
|
+
|
|
116
|
+
```css
|
|
117
|
+
:root {
|
|
118
|
+
--uniface-progress-bar-color: #22BDFF; /* 默认进度颜色 */
|
|
119
|
+
--uniface-progress-bar-success-color: #2DC071; /* 成功状态颜色 */
|
|
120
|
+
--uniface-progress-bar-failure-color: #FF685B; /* 失败状态颜色 */
|
|
121
|
+
--uniface-progress-bar-canceled-color: #FFC533; /* 取消状态颜色 */
|
|
122
|
+
--uniface-progress-bar-bg: #E2E8F0; /* 背景颜色 */
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 高级示例
|
|
127
|
+
|
|
128
|
+
### 动态进度与状态更新
|
|
129
|
+
|
|
130
|
+
```svelte
|
|
131
|
+
<script>
|
|
132
|
+
import { ProgressBar, ProgressStatus } from '@ticatec/uniface-element/ProgressBar';
|
|
133
|
+
|
|
134
|
+
let progress = 0;
|
|
135
|
+
let status = ProgressStatus.progressing;
|
|
136
|
+
|
|
137
|
+
const simulate = () => {
|
|
138
|
+
const timer = setInterval(() => {
|
|
139
|
+
progress += 10;
|
|
140
|
+
if (progress >= 100) {
|
|
141
|
+
clearInterval(timer);
|
|
142
|
+
status = ProgressStatus.successful;
|
|
143
|
+
}
|
|
144
|
+
}, 500);
|
|
145
|
+
};
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<ProgressBar {progress} {status} type="circular" size={100} />
|
|
149
|
+
<button on:click={simulate}>开始进度</button>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 文件上传进度指示器
|
|
153
|
+
|
|
154
|
+
```svelte
|
|
155
|
+
<script>
|
|
156
|
+
import { ProgressBar, ProgressStatus } from '@ticatec/uniface-element/ProgressBar';
|
|
157
|
+
|
|
158
|
+
let uploadProgress = 0;
|
|
159
|
+
let uploadStatus = ProgressStatus.progressing;
|
|
160
|
+
|
|
161
|
+
const handleUpload = async (file) => {
|
|
162
|
+
uploadStatus = ProgressStatus.progressing;
|
|
163
|
+
|
|
164
|
+
// 模拟上传进度
|
|
165
|
+
for (let i = 0; i <= 100; i += 10) {
|
|
166
|
+
uploadProgress = i;
|
|
167
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
uploadStatus = ProgressStatus.successful;
|
|
171
|
+
};
|
|
172
|
+
</script>
|
|
173
|
+
|
|
174
|
+
<div class="upload-container">
|
|
175
|
+
<ProgressBar
|
|
176
|
+
progress={uploadProgress}
|
|
177
|
+
status={uploadStatus}
|
|
178
|
+
type="liner"
|
|
179
|
+
height={6}
|
|
180
|
+
/>
|
|
181
|
+
<input type="file" on:change={handleUpload} />
|
|
182
|
+
</div>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## 最佳实践
|
|
186
|
+
|
|
187
|
+
1. **选择合适的类型**:在紧凑空间使用圆形,在宽布局中使用线性
|
|
188
|
+
2. **状态指示**:始终更新状态以反映操作的实际状态
|
|
189
|
+
3. **用户反馈**:提供关于正在发生的事情的清晰文本或视觉提示
|
|
190
|
+
4. **无障碍访问**:确保足够的颜色对比度并考虑屏幕阅读器
|
|
191
|
+
5. **性能优化**:避免过度的进度更新;限制到合理的间隔
|
|
192
|
+
6. **错误处理**:使用失败状态并在适当时提供重试机制
|
|
193
|
+
|
|
194
|
+
## 无障碍访问说明
|
|
195
|
+
|
|
196
|
+
- 进度条通过视觉指示器传达完成状态
|
|
197
|
+
- 状态特定的图标(✔、✗、!)提供额外的上下文
|
|
198
|
+
- 颜色编码支持不同的进度状态
|
|
199
|
+
- 可以切换文本显示以满足不同的无障碍访问需求
|