上传到天猫精灵技能平台
前端开发完成后,上传到技能对应的屏显页面代码包里。
开发技能的渲染指令
在技能响应的指令中,指定渲染指令,并设置pageType为AliGenie.Card。
{
"version":"2.0",
"response":{
"outputSpeech":{
"type":"PlainText",
"text":"杭州未来四天内天气变化较大,周四会有雨。晚上气温较低请注意防寒保暖。"
},
"directive":[
{
"type":"TPL.RenderDocument",
"document":{
"pageType":"AliGenie.Card",
"data":{
"layout":{
"backgroundColor":"linear-gradient(180deg, #5BD7CD 0%, #3DBAD3 100%)"
},
"content":[{
"dataSource":{} //waft包中需要用到的数据内容
}]
}
}
}
],
"shouldEndSession":true,
"expectSpeech":false
}
}
详细可以参考:TPL模板渲染指令 https://www.yuque.com/waft/docs/vax3gi#RlAOV
修改卡片对应的样式展示
在返回的指令中,layout字段可以指定对应的卡片外围容器的展现样式。
具体的字段有:
"layout":{
"version":"1.0",
"backgroundImage":"",
"window":{
"position":"right_center",
"viewport":"1024",
"width":"463rpx",
"height":"520rpx",
"padding":"0rpx 0rpx 0rpx 0rpx",
"margin":"0rpx 0rpx 40rpx 0rpx",
"anim":{
"enter":"slide_in_right",
"exit":"slide_out_right"
},
"borderRadius":"15rpx"
},
"listStyle":{
"type":"",
"orientation":""
}
}
参数说明 | 子参数 | 参数作用 | 取值范围 |
---|---|---|---|
layout:version | 协议版本信息,为后续协议扩展做区分 | 1.0 | |
layout: backgroundColor |
页面默认背景色或弹窗蒙层背景色 | 卡片默认透明,页面默认白色 支持范围: 纯色#RRGGBB(默认灰白色#D4E0F0) 渐变色(”backgroundColor”:”linear-gradient(180deg, #5BD7CD 0%, #3DBAD3 100%)”), |
|
layout: backgroundImage |
页面默认背景图片或弹窗蒙层背景图片 | 如果backgroundColor和backgroundImage同时存在,先用color再image,目前未实现 | |
layout:window | position | 窗口的位置 | left,center,right,top,bottom或其组合组合 (取值范围:left_center、left_top、left_bottom、right_top、right_bottom、right_center) |
viewport | 视觉稿的viewport大小 | 默认1024,公式: px=rpx * screenWidth / viewport | |
width | 窗口宽度 | 卡片默认463rpx,页面默认100% px, rpx, xx%, 如100%,200rpx |
|
height | 窗口高度 | 卡片默认520rpx,页面默认100% px, rpx, xx%, 如100%,200rpx |
|
padding | 窗口内间距 | 默认0rpx 0rpx 0rpx 0rpx | |
margin | 窗口外间距 | 卡片默认0rpx 0rpx 40rpx 0rpx,页面默认0rpx 0rpx 0rpx 0rpx | |
anim:enter | 窗口进入动画 | 卡片默认slide_in_right,页面默认fade_in ,(取值范围fade_in、slide_in_top 、slide_in_left、slide_in_bottom、scale_in) |
|
anim:exit | 窗口退出动画 | 卡片默认slide_out_right,页面默认fade_out ,(取值范围fade_out、slide_out_top 、slide_out_left、slide_out_bottom、scale_out) |
|
borderRadius | 卡片圆角弧度 | 0rpx,支持四个角设置,目前未实现 |