Software purchase(软件购买)
购买表单收集用途、日期、席位数和结算频率,并展示金额和确认操作。
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",
"title": "购买专业版",
"asForm": true,
"confirm": {
"label": "确认",
"$action": {
"type": "confirm_purchase"
}
},
"cancel": {
"label": "舍弃"
},
"children": [
{
"$type": "Input",
"$key": "purpose",
"name": "purpose",
"label": "用途",
"placeholder": "例如:工程团队"
},
{
"$type": "Row",
"$key": "dates",
"gap": 3,
"children": [
{
"$type": "DatePicker",
"$key": "start",
"name": "startDate",
"label": "开始日期"
},
{
"$type": "DatePicker",
"$key": "end",
"name": "endDate",
"label": "续订日期"
}
]
},
{
"$type": "Row",
"$key": "selects",
"gap": 3,
"children": [
{
"$type": "Select",
"$key": "seats",
"name": "seats",
"label": "购买数量",
"placeholder": "席位数",
"options": [
{
"label": "5 个席位",
"value": "5"
},
{
"label": "10 个席位",
"value": "10"
},
{
"label": "25 个席位",
"value": "25"
},
{
"label": "50 个席位",
"value": "50"
}
]
},
{
"$type": "Select",
"$key": "frequency",
"name": "frequency",
"label": "结算频率",
"placeholder": "选择结算频率",
"options": [
{
"label": "按月",
"value": "monthly"
},
{
"label": "按年",
"value": "annual"
}
]
}
]
},
{
"$type": "Divider",
"$key": "divider"
},
{
"$type": "Fact",
"$key": "total",
"label": "总金额",
"value": "每月 125 美元"
}
]
}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
90
91
92
93
94
95
96
97
98
99
100
101
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
90
91
92
93
94
95
96
97
98
99
100
101