(function(window) {
/**
下载文件
@method app.download
@static
@param option {object}
@param option.url {string} 下载的地址
*/
app.download = function(option) {
if (option && !option.attachmentUrl) {
return;
}
var docuementName = option.attachmentName;
var filePath = window.savePath + "/" + docuementName;
console.log('下载处的filepath',filePath)
var url = option.attachmentUrl;
var fileTransfer = new FileTransfer();
fileTransfer.download(
url,
filePath,
function(entry) {
//将文件路径保存起来,方便后面调用
window.fileUri = entry.fullPath.replace("file:///", "file://");
var URL = window.fileUri;
app.openFile(URL, "", function(res) {
app.hint("打开成功!");
});
},
function(error) {
console.log('打开失败')
app.hint("下载失败!");
}
);
};
})(window);