ApiCloud的各种方法集合

在APICloud创建了应用之后,应用的包结构如下图所示:

:

其中“config.xml”和 “index.html” 必须包含,其它均为可选。“config.xml”是配置文件,“index.html”是启动页面,“icon”为图标文件目录,“launch”为启动图片目录

actionSheet底部弹出框:

  1. api.actionSheet({
  2. title: '底部弹出框测试',
  3. cancelTitle: '这里是取消按钮',
  4. destructiveTitle: '红色警告按钮',
  5. buttons: [ '1', '2', '3']
  6. }, function(ret,err){
  7. api.alert({
  8. msg: '你刚点击了'+ret.buttonIndex
  9. });
  10. });
confirm对话框:
  1. api.confirm({
  2. title: 'testtitle',
  3. msg: 'testmsg',
  4. buttons:[ '确定', '取消']
  5. }, function(ret,err){
  6. if(ret.buttonIndex == 1){
  7. api.alert({ msg: '点击了确定'});
  8. }
  9. });


alert对话框:

  1. api.alert({
  2. title: 'testtitle',
  3. msg: 'testmsg',
  4. buttons:[ '确定']
  5. }, function(ret,err){
  6. if(ret.buttonIndex == 1){
  7. api.alert({ msg: '点击了确定'});
  8. }
  9. });
prompt带输入框的对话框

  1. api.prompt({
  2. buttons:[ '确定', '取消']
  3. }, function(ret,err){
  4. if(ret.buttonIndex == 1){
  5. api.alert({ msg:ret.text});
  6. }
  7. });

ajax:异步请求

  1. api.ajax({
  2. url: 'http://192.168.1.101:3101/upLoad',
  3. method: 'post',
  4. cache: false,
  5. timeout: 30,
  6. dataType: 'json',
  7. returnAll: false,
  8. data:{
  9. values: { name: 'haha'},
  10. files: { file: 'fs://a.gif'}
  11. }
  12. }, function(ret,err){
  13. if (ret) {
  14. var urlJson = JSON.stringify(ret);
  15. api.alert({ msg: urlJson});
  16. } else {
  17. api.alert({
  18. msg:( '错误码:'+err.code+ ';错误信息:'+err.msg+ '网络状态码:'+err.statusCode)
  19. });
  20. };
  21. });


animation动画:

  1. api.animation ({
  2. name: 'page1', //子窗口名称
  3. delay: 1000,
  4. duration: 3000,
  5. curve: 'easeIn', //动画曲线类型
  6. repeatCount: 2,
  7. autoreverse: true, //一次动画结束后是否自动反转动画
  8. alpha: 0.6,
  9. translation:{ //平移参数
  10. x: 0, //x轴上的平移距离
  11. y: 100,
  12. z: 0
  13. },
  14. scale:{
  15. x: 1.2, //<span style="font-family: Arial, Helvetica, sans-serif;">x轴上的放大倍率</span>
  16. y: 1,
  17. z: 1
  18. },
  19. rotation:{
  20. degree: 45, //旋转角度
  21. x: 0,
  22. y: 0,
  23. z: 1
  24. }
  25. }, function() {
  26. api.alert({ msg: '动画结束'});
  27. });

bringFrameToFront:调整子窗口到前面

  1. api.bringFrameToFront({
  2. from: 'page1',
  3. to: 'page2'
  4. });
call:拨打电话

  1. api.call({
  2. type: 'tel_prompt',
  3. number: '10086'
  4. });
cancelDownload:取消文件下载
  1. var url = 'http://file05.daimg.com/2013/photo/1401/DAimG_2014011335974260TA24.rar';
  2. api.cancelDownload ({
  3. url: url
  4. });
closeFrame:关闭子窗口

  1. api.closeFrame({
  2. name: 'page2'
  3. });
closeFrameGroup:关闭窗口组
  1. api.closeFrameGroup({
  2. name: 'group1'
  3. });
download文件下载:

  1. var url = 'http://file05.daimg.com/2013/photo/1401/DAimG_2014011335974260TA24.rar';
  2. api.download({
  3. url: url,
  4. savePath: 'fs://test.rar', //下载后的保存路径,如果为空会自动创建保存路径
  5. report: true, //是否上报
  6. cache: true, //是否缓存
  7. allowResume: true //是否支持断点续传
  8. }, function(ret,err){
  9. if (ret) {
  10. var value = ( '文件大小:'+ret.fileSize+ ';下载进度:'+ret.percent+ ';下载状态'+ret.state+ '存储路径: '+ret.savePath);
  11. } else{
  12. var value = err.msg;
  13. };
  14. });
execScript在指定窗口中执行脚本:

  1. api.execScript({
  2. name: 'page1',
  3. script: 'exec();' //执行的JS方法
  4. });
getLocation获取位置信息
  1. api.getLocation(
  2. function(ret, err){
  3. if(ret.status){
  4. var lat = ret.latitude; //纬度
  5. var lon = ret.longitude; //经度
  6. var t = ret.timestamp; //更新时间
  7. var str = '经度:'+ lon + '<br>';
  8. str += '纬度:'+ lat + '<br>';
  9. str += '更新时间:'+ t + '<br>';
  10. } else{
  11. api.alert({ msg:err.msg});
  12. }
  13. }
  14. );
getPicture获取图片:

  1. api.getPicture({
  2. sourceType: 'library', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">图片源类型</span>
  3. encodingType: 'png', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">编码格式</span>
  4. mediaValue: 'pic', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">媒体类型</span>
  5. destinationType: 'url', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">返回数据类型</span>
  6. allowEdit: true, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">是否可以编辑</span>
  7. quality: 50, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">图片质量</span>
  8. targetWidth: 100, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">压缩后的图片宽度</span>
  9. targetHeight: 100, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">压缩后的图片高度</span>
  10. saveToPhotoAlbum: false //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">是否保存到相册</span>
  11. }, function(ret, err){
  12. if (ret) {
  13. api.alert({ msg:ret.data});
  14. } else{
  15. api.alert({ msg:err.msg});
  16. };
  17. });

mail发送邮件:

  1. var recip = '[email protected]';
  2. var sub = '邮件测试';
  3. var body = '这是一封测试用的邮件';
  4. var attach = 'widget://a.txt';
  5. api.mail({
  6. recipients: [recip], //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">收件人</span>
  7. subject: sub, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">邮件主题</span>
  8. body: body, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">邮件内容</span>
  9. attachments: [attach] //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">附件地址</span>
  10. }, function(ret, err){
  11. if(ret.status){
  12. api.alert({
  13. msg: '发送成功'
  14. });
  15. } else{
  16. api.alert({
  17. msg: '发送失败'
  18. });
  19. }
  20. });
openApp打开手机上的其他应用:

  1. api.openApp({ //此方法只使用与Android应用
  2. androidPkg: 'android.intent.action.VIEW', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">目标应用的包名或action(Android平台使用)</span>
  3. mimeType: 'text/html', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">指定目标应用的响应数据类型</span>
  4. uri: 'http://www.baidu.com' //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">指定目标应用响应的uri</span>
  5. }, function(ret,err){
  6. var msg = JSON.stringify(ret);
  7. api.alert({
  8. title: 'openApp',
  9. msg: msg,
  10. buttons: [ '确定']
  11. });
  12. });
openFrame打开子窗口:

  1. api.openFrame({
  2. name: 'page2', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">窗口名字</span>
  3. url: './page2.html', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">请求地址</span>
  4. rect:{ //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">窗口区域</span>
  5. x: 0,
  6. y: 0,
  7. w: 320,
  8. h: 480
  9. },
  10. pageParam: { name: 'test'}, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">页面参数</span>
  11. bounces: true, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">页面是否弹动</span>
  12. opaque: false, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">页面是否不透明</span>
  13. bgColor: 'rgba(0,0,0,0)', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">背景色</span>
  14. vScrollBarEnabled: true, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">是否显示垂直滚动条</span>
  15. hScrollBarEnabled: true //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">是否显示<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">水平</span>滚动条</span>
  16. });
openFrameGroup打开窗口组:

  1. api.openFrameGroup ({
  2. name: 'group1',
  3. background: '#fff',
  4. scrollEnabled: false,
  5. rect:{ x: 0, y: 0, w: 320, h: 240},
  6. index: 0, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">默认显示的页面索引</span>
  7. frames: //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">子窗口数组</span>
  8. [{
  9. name: 'frame1',
  10. url: 'frame1.html',
  11. pageParam:{},
  12. bounces: true,
  13. opaque: true,
  14. bgColor: '#fff',
  15. vScrollBarEnabled: true,
  16. hScrollBarEnabled: false
  17. },{
  18. name: 'frame2',
  19. url: 'frame2.html',
  20. pageParam:{},
  21. bounces: true,
  22. opaque: true,
  23. bgColor: '#fff',
  24. vScrollBarEnabled: true,
  25. hScrollBarEnabled: false
  26. }]
  27. }, function(ret, err){
  28. var name = ret.name;
  29. var index = ret.index;
  30. });
openPicker打开时间选择器:

  1. api.openPicker({
  2. type: 'date_time', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">拾取器类型</span>
  3. date: '2014-05-01 12:30', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">时间格式化字符串,格式yyyy-MM-dd HH:mm</span>
  4. title: '选择时间' //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">标题</span>
  5. }, function(ret,err){
  6. var year = ret.year;
  7. var month = ret.month;
  8. var day = ret.day;
  9. var hour = ret.hour;
  10. var minute = ret.minute;
  11. if (type == 'date') {
  12. var value = year+ '年'+month+ '月'+day+ '日';
  13. } else if (type == 'time') {
  14. var value = hour+ '时'+minute+ '分';
  15. } else if (type == 'date_time') {
  16. var value = year+ '年'+month+ '月'+day+ '日'+hour+ '时'+minute+ '分';
  17. }
  18. });
openSlidLayout打开侧滑式布局:

  1. api.openSlidLayout ({
  2. type: 'all', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">侧滑类型(left:左侧滑、right:右侧滑、all:左右侧滑)</span>
  3. leftEdge: 80, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">左侧滑时,侧滑window停留时露出的宽度</span>
  4. rightEdge: 60,
  5. fixedPane: { //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">底部固定层window</span>
  6. name: 'frame1',
  7. url: 'frame1.html',
  8. bgColor: '#fff',
  9. bounces: true,
  10. opaque: true,
  11. vScrollBarEnabled: true,
  12. hScrollBarEnabled: false
  13. },
  14. slidPane: {
  15. name: 'frame1',
  16. url: 'frame1.html',
  17. bgColor: '#fff',
  18. bounces: true,
  19. opaque: true,
  20. vScrollBarEnabled: true,
  21. hScrollBarEnabled: false
  22. }
  23. }, function(ret){
  24. var type = ret.type;
  25. if (type == 'left') {
  26. } else {
  27. }
  28. });
openSlidPane侧滑:

  1. api.openSlidPane ({
  2. type: 'left' //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">侧滑类型,left或right,不能为空</span>
  3. });
openWidget打开Widget:

  1. api.openWidget({
  2. id: 'UZ00000001',
  3. animation: {
  4. type: 'flip',
  5. subType: 'from_bottom',
  6. duration: 500
  7. }
  8. }, function(ret, err){
  9. if(ret){
  10. } else{
  11. api.alert({ msg:err.msg});
  12. }
  13. });
openWin打开窗口,如果窗口已存在,则会把窗口显示到最前面:

  1. api.openWin({
  2. name: 'page1',
  3. url: './page1.html',
  4. pageParam: { name: 'test'},
  5. bounces: true,
  6. opaque: false,
  7. bgColor: 'rgba(0,0,0,0)',
  8. vScrollBarEnabled: true,
  9. hScrollBarEnabled: true,
  10. animation: {
  11. type: 'flip',
  12. subType: 'from_bottom',
  13. duration: 500
  14. }
  15. });

parseTapmode解析元素tapmode属性,优化点击事件处理
api .parseTapmode () ;
readFile读取文本文件:

  1. api.readFile({
  2. path: 'fs://a.txt'
  3. }, function(ret, err){
  4. if(ret.status){
  5. api.alert({ msg:ret.data}); //data<span style="color: rgb(147, 161, 161); font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 18.571428298950195px; white-space: pre-wrap; background-color: rgb(238, 238, 238);">文件内容</span>
  6. } else{
  7. api.alert({
  8. msg: '错误码: '+err.code+ '错误信息'+err.msg<span style= "color: rgb(42, 161, 152); font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 18.571428298950195px; white-space: pre-wrap; background-color: rgb(238, 238, 238);"> //</span><span style="font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif;">msg:</span><span style="color: rgb(42, 161, 152); font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 18.571428298950195px; white-space: pre-wrap; background-color: rgb(238, 238, 238);">错误描述</span>
  9. });
  10. }
  11. });
refreshHeaderLoadDone通知顶部刷新数据加载完毕
api.refreshHeaderLoadDone();
removeEventListener删除事件:

  1. api.removeEventListener({
  2. name: 'online'
  3. });

sendFrameToBack调整子窗口到后面:

  1. api.sendFrameToBack ({ //调整page1到page2的后面即将page2放在最page1上
  2. from: 'page1',
  3. to: 'page2' //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">窗口名字,指定时调整窗口到此窗口后面,否则调整到最后面</span>
  4. });
setFrameAttr设置子窗口属性:

  1. api.setFrameAttr({
  2. name: 'page2',
  3. rect:{
  4. x: 0,
  5. y: 0,
  6. w: 320,
  7. h: 480
  8. },
  9. bounces: true,
  10. opaque: true,
  11. bgColor: '#fff',
  12. vScrollBarEnabled: true,
  13. hScrollBarEnabled: true
  14. });

setFrameGroupAttr设置窗口组属性:

  1. api.setFrameGroupAttr({
  2. name: 'group1',
  3. hidden: true
  4. });

setFrameGroupIndex设置窗口组当前可见子窗口:

  1. api.setFrameGroupIndex ({
  2. name: 'group1',
  3. index: 2, //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">子窗口索引</span>
  4. scroll: true //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">是否平滑滚动至目标窗口</span>
  5. });
setFullScreen设置是否全屏:

api.setFullScreen({fullScreen:true});
setRefreshHeaderInfo显示顶部刷新:

  1. api.setRefreshHeaderInfo({
  2. visible: true,
  3. loadingImg: 'widget://image/refresh.png', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">刷新图片地址</span>
  4. bgColor: '#ccc',
  5. textColor: '#fff',
  6. textDown: '下拉刷新...', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">下拉文字描述</span>
  7. textUp: '松开刷新...', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">松开时文字描述</span>
  8. showTime: true //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">是否显示更新时间</span>
  9. }, function(ret, err){
  10. });

showFloatBox展示一个悬浮框,浮动在屏幕上,点击时关闭当前widget:

  1. api.showFloatBox ({
  2. iconPath: 'widget://image/icon.png', //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">展示在悬浮框中的图片地址</span>
  3. duration: 3000 //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">自动消隐时长。在该时长内不发生触摸悬浮框行为,悬浮框自动消隐至半透状态</span>
  4. });
showProgress显示进度提示框:

  1. api.showProgress({
  2. style: 'default',
  3. animationType: 'fade',
  4. title: '努力加载中...',
  5. text: '先喝杯茶...',
  6. modal: false //<span style="color: rgb(128, 128, 128); font-family: ff-tisa-web-pro-1, ff-tisa-web-pro-2, 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', sans-serif; font-size: 14px; line-height: 20px;">是否模态</span>
  7. });
writeFile写入文件:

  1. api.writeFile({
  2. path: 'fs://a.txt',
  3. data: 'writeFile测试内容'
  4. }, function(ret, err){
  5. var status = ret.status;
  6. if(status){
  7. api.alert({ msg: '写入文件成功'});
  8. } else{
  9. api.alert({ msg:err.msg});
  10. }
  11. });
removeLaunchView移除启动图。若config.xml里面配置autoLaunch为false,则启动图不会自动消失,直到调用此方法移除。
api.removeLaunchView();

猜你喜欢

转载自blog.csdn.net/weixin_41722928/article/details/80927923