Merge pull request #104 from ckcz123/v2.0

V2.0
This commit is contained in:
Zhang Chen 2018-04-18 20:00:34 +08:00 committed by GitHub
commit f49a600278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 25 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

@ -285,6 +285,14 @@ utils.prototype.isset = function (val) {
////// 读取一个本地文件内容 //////
utils.prototype.readFile = function (success, error, readType) {
core.platform.successCallback = success;
core.platform.errorCallback = error;
if (core.isset(window.jsinterface)) {
window.jsinterface.readFile();
return;
}
// step 0: 不为http/https直接不支持
if (!core.platform.isOnline) {
alert("离线状态下不支持文件读取!");
@ -316,11 +324,34 @@ utils.prototype.readFile = function (success, error, readType) {
}
}
core.platform.successCallback = success;
core.platform.errorCallback = error;
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) {
@ -384,6 +415,12 @@ utils.prototype.download = function (filename, content) {
////// 复制一段内容到剪切板 //////
utils.prototype.copy = function (data) {
if (core.isset(window.jsinterface)) {
window.jsinterface.copy(filename, content);
return true;
}
if (!core.platform.supportCopy) return false;
var textArea = document.createElement("textarea");