Appearance
🔌 前端 API
前提
钩子/生命周期
created
created 生命周期,网页通知客户端,网页代码开始运行,准备调起后续业务逻辑。
js
/**
* created
* @param {string} methodName 方法名
* @param {requestCallback} res - 函数回调
*/
const methodName = "created";
dsBridge.call(methodName, (res) => {});updated
updated 生命周期,有配置或数据更新时,客户端通知网页
参数
updateName
| updateName | 类型 | 备注 |
|---|---|---|
config | String | 全局应用配置 |
user | String | 用户信息 |
video | String | 视频详细信息 |
fontSize | String | 调整字体大小,现的方案,需 update 视频相关信息给客户端 |
fontStyle | String | 调整字体样式 |
js
//updated config
const new_config = { type: "config", data: { version : '1.0.0'} };
dsBridge.call("updated", new_config, (res) => {});
//updated user
const new_user = { type: "user", data: { username: 'Mather'} };
dsBridge.call("updated", new_user, (res) => {});事件
event
event 事件,客户端通知网页,在 UI 或者网络耗时操作时候调用
参数
eventName
| eventName | 类型 | 备注 |
|---|---|---|
imageViewerOpen | String | 打开图片查看器 |
imageViewerClose | String | 关闭图片查看器 |
videoPause | String | 视频暂停播放 |
videoPlay | String | 视频开始播放 |
videoFullScreen | String | 视频全屏显示 |
videoExitFullScreen | String | 视频退出全屏显示 |
videoClosed | String | 关闭视频浮窗 |
shareTimeline | String | 分享朋友圈 |
shareWechat | String | 分享微信好友 |
shareWeibo | String | 分享微博 |
shareQQ | String | 分享QQ |
js
dsBridge.register('event', function (eventName) {
console.log(eventName); //ImageViewerOpen
return "true";
})业务方法
content
获取文章详情
参数
| 参数 | 典型值 | 类型 | 备注 |
|---|---|---|---|
| id | 147022 | String | 文章 ID |
返回值
| 返回值 | 典型值 | 类型 | 备注 |
|---|---|---|---|
json | content | JSONObject | 见数据结构 |
js
/**
* 获取文章详情
* @param {string} handlerName - 接口名称.
* @param {string} id - 文章资源 ID.
* @param {requestCallback} res - json 格式文章详情.
*/
const handlerName = "content";
const id = "147022";
dsBridge.call(handlerName, id, function (res) {
alert(JSON.stringify(res))
})rewards
comments
imageList
imageViewer
全屏显示文章内图片
js
/**
* 打开图片查看器
* @param {string} handlerName - 接口名称.
* @param {json} imagesObj - 当前图片 URL 和 相册 URL 数组.
*/
const handlerName = "imageViewer";
const imagesObj = {
current: "http://",
data : ["http://...", "http://...", "http://..."]
};
dsBridge.call(handlerName, imagesObj, function (res) {
alert(res)
})newContent
打开新的文章页,点击相关文章
参数
| 参数 | 典型值 | 类型 | 备注 |
|---|---|---|---|
| id | 147022 | String | 文章 ID |
返回值
| 返回值 | 典型值 | 类型 | 备注 |
|---|---|---|---|
true | true | String |
javascript
/**
* 打开新的文章页,点击相关文章
* @param {string} handlerName - 接口名称.
* @param {string} id - 文章资源 ID.
* @param {requestCallback} res - 回调参数.
*/
const handlerName = "newContent";
const id = "147022";
dsBridge.call(handlerName, id, function (res) {
alert(res)
})share
点击分享按钮
参数
| 参数 | 典型值 | 类型 | 备注 |
|---|---|---|---|
| type | timeline wechat weibo qq | String | 微信朋友圈、微信好友、微博、QQ |
返回值
| 返回值 | 典型值 | 类型 | 备注 |
|---|---|---|---|
true | true false | Boolean |
javascript
/**
* 点击分享按钮
* @param {string} handlerName - 接口名称.
* @param {string} type - 社交应用名称.
* @param {requestCallback} res - 回调参数.
*/
const handlerName = "share";
const type = "timeline";
dsBridge.call(handlerName, type, function (res) {
alert(res)
})video
参数
videoParams
| 参数 | 典型值 | 类型 | 备注 |
|---|---|---|---|
| type | timeline wechat weibo qq | String | 微信朋友圈、微信好友、微博、QQ |
返回值
| 返回值 | 典型值 | 类型 | 备注 |
|---|---|---|---|
true | true false | Boolean |
调起客户端视频播放功能
javascript
/**
* 调起客户端视频播放功能
* @param {string} handlerName - 接口名称.
* @param {json} videoParams - 视频详细参数.
* @param {requestCallback} res - 回调参数.
*/
const handlerName = "video";
const videoParams = {
left : "",
top : "",
width : "",
height: "",
url : "",
id : "",
};
dsBridge.call(handlerName, videoParams, function (res) {
alert(res)
})audio
调起客户端音频播放功能
javascript
/**
* 调起客户端音频播放功能
* @param {string} handlerName - 接口名称.
* @param {json} audioParams - 音频详细参数.
* @param {requestCallback} res - 回调参数.
*/
const handlerName = "audio";
const audioParams = {
url : "",
name : "",
duration : "",
};
dsBridge.call(handlerName, audioParams, function (res) {
alert(res)
})fontSize
调整字体大小
javascript
/**
* 调整字体大小
* @param {string} handlerName - 接口名称.
* @param {string} size - 字体大小.
* @param {requestCallback} res - 回调参数.
*/
const handlerName = "fontSize";
const size = "normal";
dsBridge.call(handlerName, size, function (res) {
alert(res)
})fontStyle
channel
打开相关频道/栏目
javascript
/**
* 打开相关频道
* @param {string} handlerName - 接口名称.
* @param {json} channelParams - 频道详细参数 频道/栏目 id 频道/栏目名称.
* @param {requestCallback} res - 回调参数.
*/
const handlerName = "audio";
const channelParams = {
id : "1",
name: "推荐",
};
dsBridge.call(handlerName, channelParams, function (res) {
alert(res)
})search
打开文章标签,搜索页面
javascript
/**
* 调整字体大小
* @param {string} handlerName - 接口名称.
* @param {string} keyword - 搜索关键字.
* @param {requestCallback} res - 回调参数.
*/
const handlerName = "search";
const keyword = "电动车";
dsBridge.call(handlerName, size, function (res) {
alert(res)
})user
user 数据结构见 user
javascript
/**
* 用户信息
* @param {string} handlerName - 接口名称.
* @param {requestCallback} res - 回调参数.
*/
const handlerName = "user";
dsBridge.call(handlerName, function (res) {
alert(res)
})device
设备信息、客户端版本
js
/**
* created
* @param {string} methodName 方法名
* @param {requestCallback} res - json 格式设备信息、客户端版本
*/
const methodName = "device";
dsBridge.call(methodName, (res) => {
alert( res );
})config
客户端、用户配置信息
js
/**
* created
* @param {string} methodName 方法名
* @param {requestCallback} res - json 格式设备信息、客户端版本
*/
const methodName = "config";
dsBridge.call(methodName, (res) => {
alert( res );
})