[关闭]
@zongwu 2016-12-27T06:11:57.000000Z 字数 4134 阅读 559

JS 桥连接口设计

开发设计


实现方式


将所有属性和方法封入 window.iPudong 或 iPudong 这个全局对象注意区分大小写。

另外出于安全因素,请务必判定仅针对可识别的内部网址(如:以http://www.healthbok-inc.com/ 开头的)再发送 Authorization 头和支持iPudong对象,避免跨站问题。

统一采用第三方库支持,实现iPudongJSBridgeJavaScript 桥联。

  1. bridge.init(function (message, responseCallback) {
  2. log('JS got a message', message);
  3. var data = {'Javascript Responds': 'Wee!'};
  4. log('JS responding with', data);
  5. responseCallback(data);
  6. });

接口列表


3.3 接口


postToolbarConfiguration(String configuration,Function callback)

状态通用接口 建议所有WebView页面都增加 该配置
应用版本:BP-V3.3
调用方:JS
方法描述:弹窗提示 附带按钮实现
参数configuration JSON字符串

  1. // ======= id: =======
  2. * prev 表示返回上一个WebView页面,若无WebView页面则关闭WebView 容器;
  3. * close 关闭WebView容器
  4. * share 分享
  5. * favorite 收藏/取消收藏;
  6. // ======= gravity: =======
  7. * start 表示左侧对齐
  8. * end 表示右侧对齐
  9. // ======= index: =======
  10. * 0 表示第1个位置
  11. * 1 表示第2个位置
  12. // ======= 举例: =======
  13. index = 0 , gravity = start --> XOOO
  14. index = 1 , gravity = start --> OXOO
  15. index = 0 , gravity = end --> OOOX
  16. index = 1 , gravity = end --> OOXO
  17. // 注意: index需要与gravity参数关联使用(未指定gravity,则默认为start);
  18. {
  19. "title": "我是标题",
  20. "state": "hide|show",
  21. "operates": [
  22. {
  23. "index": 0,
  24. "gravity": "start",
  25. "id": "prev"
  26. },
  27. {
  28. "index": 1,
  29. "gravity": "start",
  30. "id": "close"
  31. },
  32. {
  33. "index": 0, // 表示第1个位置
  34. "gravity": "end",
  35. "id": "share"
  36. },
  37. {
  38. "index": 1,
  39. "gravity": "end",
  40. "id": "favorite"  
  41. }
  42. ]
  43. }
  44. // 示例渲染样式
  45. * [prev][close]我是标题[favorite][share]

postMediaBasic(String configuration,Function callback)

状态适用于媒介类型的WebView 界面
应用版本:BP-V3.3
调用方:JS
方法描述:进入媒介详情,用于更新状态栏状态;进入媒介详情,用于操作收藏该媒介;(暂调用JS接口postShareBasic()获取分享状态)
参数configuration JSON字符串

  1. {
  2. "id": 40, // 媒介id 与接口返回 id 相同
  3. "isFavorite":0 // 收藏状态
  4. }

postToast(String content,Function callback)

状态适用于媒介类型的WebView 界面
应用版本:BP-V3.3
调用方:JS
方法描述:短暂提示用户后自动消失(Toast)
参数content 提示信息


postDialog(String configuration,Function callback)

状态适用于媒介类型的WebView 界面
应用版本:BP-V3.3
调用方:JS
方法描述:打开对话框提示面板
参数configuration JSON字符串

  1. // ======= useType: =======
  2. useType <= 100 表示使用Native 原生对话框;
  3. useType > 100 表示使用自定义 对话框;
  4. // ======= useType 实例: =======
  5. useType = 0 //表示拥有<确认>,对应配置positive;
  6. useType = 1 //表示拥有<确认>/<取消>,对应配置positive/negative;
  7. userType = 101 //表示使用配置<提现成功>
  8. {
  9. "title": "分享标题",
  10. "text": "分享内容",
  11. "useType": 0,
  12. "operates": { // useType <= 100 , 才会有 operates 节点;
  13. "negative": "取消", // 显示名称
  14. "negative_value": "cancel", // 值定义 , 如Web需知道用户点击事件 则原样将 value 带回;
  15. "positive": "确认",
  16. "positive_value": "confirm"
  17. }
  18. }

postIntent(String configuration,Function callback)

状态适用于媒介类型的WebView 界面
应用版本:BP-V3.3
调用方:JS
方法描述:调起意图
参数configuration JSON字符串


receiveIntent(String configuration,Function callback)

状态适用于媒介类型的WebView 界面
应用版本:BP-V3.3
调用方:APP
方法描述:接收服务端传来的意图
参数configuration JSON字符串


3.2 接口


operDialog(String content,Function callback)

状态已废弃 请使用 postDialog
应用版本:BP-V3.2
调用方:JS
方法描述:通用接口 建议所有WebView页面都增加 该配置
参数

  • content 提示内容
  • callback 确定按钮事件

dialog(String content,Function callback)

状态已废弃 请使用 postDialog
应用版本:BP-V3.2
调用方:JS
方法描述:弹窗提示
参数content 提示内容


errorTips(String desc,Function callback)

状态已废弃 请使用 postDialog
应用版本:BP-V3.2
调用方:JS
方法描述:错误标识
参数desc 提示内容


openQA(String articleId,Function callback)

状态已废弃 请使用 postIntent
应用版本:BP-V3.2
调用方:JS
方法描述:打开到作答页面(单道题目)
参数articleId 文章id


openDialogWithdrawals()

状态已废弃 请使用 postDialog
应用版本:BP-V3.2
调用方:JS
方法描述:打开提现成功对话框


3.1 接口


openLink(String url ,Function callback)

状态已废弃 请使用 postIntent
应用版本:BP-V3.1
调用方:JS
方法描述:打开WebView跳转到指定的url。

showActionBarTitle(String title)

状态已废弃
应用版本:BP-V3.1
调用方:JS
方法描述:当标题栏可见时更新标题栏文案。

close(String label,Function callback)

状态已废弃 请使用 postIntent
应用版本:BP-V3.1
调用方:JS
方法描述:关闭装载 Webview 的容器
参数

  • label = 0 —— 关闭整个容器
  • label = 1 —— 关闭当前页面

toast(String content,Function callback)

状态已废弃 请使用postToast
应用版本:BP-V3.1
调用方:JS
方法描述:短暂提示用户,Toast 会主动消失

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注