Order tracking(订单追踪)
订单卡片用时间线展示已下单、已打包和配送中等阶段,并提供物流和支持入口。
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": "订单 #48213",
"children": [
{
"$type": "Alert",
"$key": "alert",
"tone": "success",
"title": "订单已确认",
"description": "包裹正在配送,预计今天送达。"
},
{
"$type": "ListView",
"$key": "timeline",
"children": [
{
"$type": "ListViewItem",
"$key": "placed",
"$action": {
"type": "view_order_event",
"eventId": "placed"
},
"children": {
"$type": "Row",
"justify": "between",
"children": [
{
"$type": "Col",
"$key": "label",
"gap": 1,
"children": [
{
"$type": "Text",
"$key": "title",
"value": "已下单",
"weight": "medium"
},
{
"$type": "Caption",
"$key": "time",
"value": "今天 09:02"
}
]
},
{
"$type": "Badge",
"$key": "badge",
"value": "完成",
"variant": "success"
}
]
}
},
{
"$type": "ListViewItem",
"$key": "packed",
"$action": {
"type": "view_order_event",
"eventId": "packed"
},
"children": {
"$type": "Row",
"justify": "between",
"children": [
{
"$type": "Col",
"$key": "label",
"gap": 1,
"children": [
{
"$type": "Text",
"$key": "title",
"value": "已打包",
"weight": "medium"
},
{
"$type": "Caption",
"$key": "time",
"value": "今天 09:41"
}
]
},
{
"$type": "Badge",
"$key": "badge",
"value": "完成",
"variant": "success"
}
]
}
},
{
"$type": "ListViewItem",
"$key": "transit",
"$action": {
"type": "view_order_event",
"eventId": "transit"
},
"children": {
"$type": "Row",
"justify": "between",
"children": [
{
"$type": "Col",
"$key": "label",
"gap": 1,
"children": [
{
"$type": "Text",
"$key": "title",
"value": "配送中",
"weight": "medium"
},
{
"$type": "Caption",
"$key": "time",
"value": "预计 14:00 至 16:00"
}
]
},
{
"$type": "Badge",
"$key": "badge",
"value": "进行中",
"variant": "info"
}
]
}
}
]
},
{
"$type": "Divider",
"$key": "divider"
},
{
"$type": "Row",
"$key": "actions",
"justify": "end",
"children": [
{
"$type": "Button",
"$key": "track",
"label": "查看物流",
"buttonStyle": "outline",
"$action": {
"type": "track_order",
"orderId": "48213"
}
},
{
"$type": "Button",
"$key": "support",
"label": "联系支持",
"buttonStyle": "ghost",
"$action": {
"type": "contact_support",
"orderId": "48213"
}
}
]
}
]
}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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164