screenshot.png

通过天猫精灵技能平台,可以开发技能的卡片渲染。

上传到天猫精灵技能平台

前端开发完成后,上传到技能对应的屏显页面代码包里。
image.png

开发技能的渲染指令

在技能响应的指令中,指定渲染指令,并设置pageType为AliGenie.Card。

  1. {
  2. "version":"2.0",
  3. "response":{
  4. "outputSpeech":{
  5. "type":"PlainText",
  6. "text":"杭州未来四天内天气变化较大,周四会有雨。晚上气温较低请注意防寒保暖。"
  7. },
  8. "directive":[
  9. {
  10. "type":"TPL.RenderDocument",
  11. "document":{
  12. "pageType":"AliGenie.Card",
  13. "data":{
  14. "layout":{
  15. "backgroundColor":"linear-gradient(180deg, #5BD7CD 0%, #3DBAD3 100%)"
  16. },
  17. "content":[{
  18. "dataSource":{} //waft包中需要用到的数据内容
  19. }]
  20. }
  21. }
  22. }
  23. ],
  24. "shouldEndSession":true,
  25. "expectSpeech":false
  26. }
  27. }

详细可以参考:TPL模板渲染指令 https://www.yuque.com/waft/docs/vax3gi#RlAOV

修改卡片对应的样式展示

在返回的指令中,layout字段可以指定对应的卡片外围容器的展现样式。
image.png
具体的字段有:

"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,支持四个角设置,目前未实现