diff --git a/libs/core.js b/libs/core.js index a01080a5..a49f131d 100644 --- a/libs/core.js +++ b/libs/core.js @@ -216,29 +216,7 @@ core.prototype.init = function (coreData, callback) { if (window.FileReader) { core.platform.fileReader = new FileReader(); core.platform.fileReader.onload = function () { - var content=core.platform.fileReader.result; - var obj=null; - if(content.slice(0,4)==='data'){ - if (core.isset(core.platform.successCallback)) - core.platform.successCallback(content); - return; - } - try { - obj=JSON.parse(content); - if (core.isset(obj)) { - if (core.isset(core.platform.successCallback)) - core.platform.successCallback(obj); - return; - } - } - catch (e) { - console.log(e); - } - alert("不是有效的JSON文件!"); - - if (core.isset(core.platform.errorCallback)) - core.platform.errorCallback(); - + core.readFileContent(core.platform.fileReader.result); }; core.platform.fileReader.onerror = function () { if (core.isset(core.platform.errorCallback)) @@ -1078,6 +1056,11 @@ core.prototype.readFile = function (success, error, readType) { core.utils.readFile(success, error, readType); } +////// 读取本地文件完毕 ////// +core.prototype.readFileContent = function (content) { + core.utils.readFileContent(content); +} + ////// 下载文件到本地 ////// core.prototype.download = function (filename, content) { core.utils.download(filename, content); diff --git a/libs/utils.js b/libs/utils.js index aaf82da3..67f3022b 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -321,6 +321,31 @@ utils.prototype.readFile = function (success, error, readType) { core.platform.fileInput.click(); } +////// 读取文件完毕 ////// +utils.prototype.readFileContent = function (content) { + var obj=null; + if(content.slice(0,4)==='data'){ + if (core.isset(core.platform.successCallback)) + core.platform.successCallback(content); + return; + } + try { + obj=JSON.parse(content); + if (core.isset(obj)) { + if (core.isset(core.platform.successCallback)) + core.platform.successCallback(obj); + return; + } + } + catch (e) { + console.log(e); + } + alert("不是有效的JSON文件!"); + + if (core.isset(core.platform.errorCallback)) + core.platform.errorCallback(); +} + ////// 下载文件到本地 ////// utils.prototype.download = function (filename, content) {