JS Interface

This commit is contained in:
ckcz123 2018-04-18 19:59:22 +08:00
parent 48a65ed1c1
commit 5a87dc95cb
2 changed files with 31 additions and 23 deletions

View File

@ -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);

View File

@ -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) {