Purchase receipt(购买收据)
购买收据用状态徽标提示完成,并列出商品、数量、预计送达时间和付款信息。
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",
"children": [
{
"$type": "Badge",
"$key": "status",
"value": "购买完成",
"variant": "success",
"children": {
"$type": "Icon",
"name": "check",
"size": "sm"
}
},
{
"$type": "Row",
"$key": "product",
"gap": 3,
"align": "center",
"children": [
{
"$type": "Image",
"$key": "thumb",
"src": "https://images.unsplash.com/photo-1587829741301-dc798b83add3?w=640&q=80",
"alt": "机械键盘",
"size": "sm"
},
{
"$type": "Col",
"$key": "info",
"gap": 0,
"children": [
{
"$type": "Text",
"$key": "title",
"value": "段落轴机械键盘",
"weight": "medium"
},
{
"$type": "Caption",
"$key": "qty",
"value": "数量 1"
}
]
}
]
},
{
"$type": "Divider",
"$key": "divider"
},
{
"$type": "Col",
"$key": "facts",
"gap": 2,
"children": [
{
"$type": "Fact",
"$key": "delivery",
"label": "预计送达",
"value": "7 月 29 日至 8 月 1 日"
},
{
"$type": "Fact",
"$key": "seller",
"label": "卖家",
"value": "北风供应商店"
},
{
"$type": "Fact",
"$key": "paid",
"label": "已支付",
"value": "$149.00"
}
]
},
{
"$type": "Button",
"$key": "details",
"label": "查看详情",
"buttonStyle": "outline",
"$action": {
"type": "view_order_details"
}
}
]
}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
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