Table reservation(餐桌预订)
餐桌预订表单收集姓名、人数、日期、座位偏好和提醒选项,并通过卡片的确认操作提交。
loading
安装
bash
npm install @assistant-ui/generative-ui zod1
用法
将下方规格传给渲染器。提供 dispatch 可接收按钮或表单的动作载荷。演示只在本地显示操作反馈。
tsx
import { defaultGenerativeUILibrary, renderGenerativeUI } from "@assistant-ui/generative-ui/react";
renderGenerativeUI(spec, defaultGenerativeUILibrary, {
status: "done",
dispatch: (action) => {
// 将用户操作交给应用。
console.log(action);
},
});1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
规格
tsx
const spec = {
"$type": "Card",
"asForm": true,
"confirm": {
"label": "确认订位",
"$action": {
"type": "book_reservation"
}
},
"cancel": {
"label": "取消"
},
"children": [
{
"$type": "Header",
"$key": "title",
"text": "预订餐桌",
"size": "md"
},
{
"$type": "Text",
"$key": "intro",
"value": "餐桌将保留至预约时间后 15 分钟。",
"size": "sm",
"color": "secondary"
},
{
"$type": "Input",
"$key": "name",
"name": "guestName",
"label": "姓名",
"placeholder": "请输入姓名"
},
{
"$type": "Select",
"$key": "party",
"name": "partySize",
"label": "用餐人数",
"placeholder": "选择用餐人数",
"options": [
{
"label": "1 位",
"value": "1"
},
{
"label": "2 位",
"value": "2"
},
{
"label": "3 位",
"value": "3"
},
{
"label": "4 位及以上",
"value": "4"
}
]
},
{
"$type": "DatePicker",
"$key": "date",
"name": "date",
"label": "日期"
},
{
"$type": "RadioGroup",
"$key": "seating",
"name": "seating",
"label": "座位偏好",
"defaultValue": "indoor",
"options": [
{
"label": "室内",
"value": "indoor"
},
{
"label": "露台",
"value": "patio"
}
]
},
{
"$type": "Checkbox",
"$key": "reminder",
"name": "reminder",
"label": "提前 1 小时提醒"
}
]
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89