let i: number = 0;
for (; i < str.length; i += MaxLength) {
kvStore.put(Data_Key + (i.toString()), str.substring(i, i + MaxLength))
}
kvStore.put(Length_Key, str.length)
if (showPrompt)
prompt.showToast({
message: '发送成功,快去看看吧!',
duration: 1000,
});
} else {
if (showPrompt)
prompt.showToast({
message: '发送失败,发送数据不为最新',
duration: 1000,
});
}
});
}
/**
* 从数据库导入数据新版本
*/
async function ImportNewVersion(): Promise<[boolean, number, string]> {
let TerminalsSyncSwitch = AppStorage.Get<boolean>('TerminalsSyncSwitch')
if (!TerminalsSyncSwitch)
return [false, 0, '']
const kvStore = await getKVStore()
let newVersion: number = AppStorage.Get<number>('LocalVersionNumber')
console.log('[Sync] newVersion: ' + newVersion);
return new Promise((resolve) => {
kvStore.get(Version_Key, async function (err, SyncVersion) {
console.log("get success Version_Key: " + SyncVersion);
console.log("get error: " + err);
if (SyncVersion != undefined && SyncVersion > newVersion) {
let end: number = await kvStore.get(Length_Key)
let obj: string = ''
for (let i = 0; i < end; i += MaxLength) {
obj += await kvStore.get(Data_Key + (i.toString()))
}
console.log("get success Data_Key: " + obj);
console.log("get error: " + err);
console.log('[Sync] import: ' + JSON.stringify(obj));
let ret = JSON.parse(obj)
console.log('[Sync] import value: ' + JSON.stringify(ret));
backUpImpl.importData(ret, (flag: boolean, reason: string) => {
resolve([flag, SyncVersion, reason])
})
} else {
resolve([false, SyncVersion, '未接收到新数据'])
}
});
})
}
```