tt.createGridGamePanel
基础库 2.82.0 开始支持本方法,这是一个同步方法。
创建游戏推荐组件实例。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 目前仅支持抖音、抖音极速版。 |
注意事项 | 本接口是同步接口,传入参数不合法时会直接抛出参数错误的异常,请做好处理。 |
相关教程 | 无 |
语法
tt.createGridGamePanel(params)
参数说明
params 类型说明
object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
position | object | 否 | 控制游戏推荐组件的展示位置,不传入时默认展示在屏幕右下角。
仅 gridCount = one 时有效 | 2.82.0 | |
query | object | 否 | 从组件内打开游戏时附带的query信息,请阅读下文确认具体格式 | 2.82.0 | |
gridCount | enum | 是 | 表示游戏推荐组件的格子数量 | 2.82.0 | |
size | enum | large | 是 | 表示组件大小,仅 gridCount = one | four 时有效。 | 2.82.0 |
query 参数说明
属性 | 类型 | 默认值 | 必填 | 说明 |
appid1 | string | 否 | query字符串,必须是 key1=val1&key2=val2 的格式。打开游戏后,可通过 tt.getLaunchOptionsSync 获取启动参数中的 query。 appid1 是游戏的AppId的具体值,用于给指定游戏设置query。 | |
appid2 | string | 否 | 同上 | |
... |
合法的 query 格式如下:
{ "ttc203b4be5d39867a": "age=1", "ttc203b4be5d39867b": "age=2&name=xxx", "ttc203b4be5d39867c": "age=3&location=xxx" }
position 类型说明
object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
top | number | 是 | 组件左上角纵坐标 | 2.82.0 | |
left | number | 是 | 组件左上角横坐标 | 2.82.0 |
gridCount 的合法值
值 | 说明 | 最低支持版本 |
---|---|---|
one | 格子数量为 1 | 2.82.0 |
four | 格子数量为 4 | 2.82.0 |
nine | 格子数量为 9 | 2.82.0 |
size 的合法值
值 | 说明 | 最低支持版本 |
---|---|---|
large | large:100% | 2.82.0 |
medium | medium:90% | 2.82.0 |
small | small:80% | 2.82.0 |
返回值
类型 | 说明 | 最低支持版本 |
---|---|---|
object | 2.82.0 |
错误码
errNo | errMsg | 说明 | 最低支持版本 |
---|---|---|---|
10302 | In the gray scale experiment, the user will not display | 2.82.0 | |
10401 | operation is illegal | 2.82.0 | |
21101 | GridGamePanel with the same gridCount can show most one | 2.82.0 | |
10301 | feature is not supported in app | 2.82.0 | |
21102 | Fetch game list error | 小游戏框架内部错误,有需要请创建工单咨询 | 2.82.0 |
20001 | invalid param | 参数错误 | 2.82.0 |
20000 | internal error | 小游戏框架内部错误,有需要请创建工单咨询 | 2.82.0 |
代码示例
try { // 单宫格可设置大小和位置 const oneGridGamePanel = tt.createGridGamePanel({ gridCount: "one", size: "large", position: { top: 600, left: 300, }, query: { tt00000000000000: "age=12&name=xxxx", }, }); // 四宫格可设置大小 设置位置无实际作用 const fourGridGamePanel = tt.createGridGamePanel({ gridCount: "four", size: "large", query: { tt00000000000000: "age=12&name=xxxx", tt00000000000001: "age=12&name=xxxx", }, }); // 九宫格 设置大小和位置无实际作用 const nineGridGamePanel = tt.createGridGamePanel({ gridCount: "nine", query: { tt00000000000000: "age=12&name=xxxx", tt00000000000001: "age=12&name=xxxx", tt00000000000002: "age=12&name=xxxx", }, }); } catch (error) { console.error("创建游戏推荐组件失败", error); }