//检测配置文件,不存在就创建,存在就修改
chkFile(par) {
let that = this;
let type = plus.io.PRIVATE_DOC;
plus.io.requestFileSystem(type, function(fs) {
let da = {
"data": that.data
};
fs.root.getFile('config.json', par == null ? {} : par, function(fe) {
if (par == null) {
fe.file(function(f) {
let reader = new plus.io.FileReader();
reader.onloadend = function(e) {
let res = JSON.parse(e.target.result);
that.data = res.data;
};
reader.readAsText(f);
}, function(e) {
console.log(e.message)
});
} else {
fe.createWriter(function(fw) {
fw.seek(0);
fw.write(JSON.stringify(da));
fw.abort();
if (par.create == false) {
uni.showToast({
title: '保存成功',
duration: 1000
});
setTimeout(function() {
keys.server_data = da.data;
uni.navigateBack();
}, 1000);
}
}, function(e) {
uni.showToast({
title: e.message,
icon: 'none',
duration: 2000
});
});
}
}, function(e) {
//文件已存在
that.chkFile(null);
});
},
function(e) {
console.log(e.message)
});
}
0 个回复