美文网首页
cordova 里面index.js的写法

cordova 里面index.js的写法

作者: 皓皓amous | 来源:发表于2019-06-12 08:59 被阅读0次

var app = {
// Application Constructor
initialize: function () {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
// deviceready Event Handler
onDeviceReady: function () {
this.receivedEvent();
},
// get DOM
: function (id) { return document.getElementById(id); }, receivedEvent: function () { var _this = this; var dlDom = this.('download');
dlDom.onclick = function () {
_this.dl();
}
},
dl: function () {
var that = this;
console.log(requestFileSystem)
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 5 * 1024 * 1024, function (fs) {
//创建文件
console.log(111)
var url = 'http://k.zol-img.com.cn/sjbbs/7692/a7691515_s.jpg';
fs.root.getFile('download.jpg', {create: true, exclusive: false}, function (fileEntry) {
alert(fileEntry.nativeURL)
alert(fileEntry.toURL())
download(fileEntry, url);
}, function () {
alert('shibai')
});
}, function () {
alert('shibai')
})

    // var ft = new FileTransfer();
    function download(fileEntry, url) {
        var ft = new FileTransfer();
        var fileURL = fileEntry.toURL();
        // var fileURL = 'storage';
        //监听下载进度
        ft.onprogress = function (e) {
            console.info(e);
            if (e.lengthComputable) {
                console.log('当前进度:' + e.loaded / e.total);
            }
        }
        ft.download(url, fileURL, function (entry) {
                alert('下载成功');
                console.info(entry);
                console.log('文件位置:' + entry.toURL());
                that.url = entry.toURL()
                that.$$('myImage').src= entry.toURL()
            }, function (err) {
                alert("下载失败!");
            }, null, // or, pass false
            {
                //headers: {
                //    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
                //}
            });
    }
},

};

app.initialize();

相关文章

网友评论

      本文标题:cordova 里面index.js的写法

      本文链接:https://www.haomeiwen.com/subject/aqtkfctx.html