From b3a415d9c7d7eda3f3ce89a8b4fee87c5668528c Mon Sep 17 00:00:00 2001 From: genglingxia Date: Thu, 9 Mar 2023 14:44:55 +0800 Subject: [PATCH] manual demo fun add, Review comments modification. --- .../main/ets/Application/MyAbilityStage.ts | 2 +- .../src/main/ets/MainAbility/MainAbility.ts | 290 +++++++++++----- .../entry/src/main/ets/pages/index/index.ets | 322 +++++++++++------- 3 files changed, 401 insertions(+), 213 deletions(-) diff --git a/kvdb_stage_demo/entry/src/main/ets/Application/MyAbilityStage.ts b/kvdb_stage_demo/entry/src/main/ets/Application/MyAbilityStage.ts index 7334fe6..b2e09bd 100644 --- a/kvdb_stage_demo/entry/src/main/ets/Application/MyAbilityStage.ts +++ b/kvdb_stage_demo/entry/src/main/ets/Application/MyAbilityStage.ts @@ -1,4 +1,4 @@ -import AbilityStage from "@ohos.application.AbilityStage" +import AbilityStage from '@ohos.app.ability.UIAbility'; export default class MyAbilityStage extends AbilityStage { onCreate() { diff --git a/kvdb_stage_demo/entry/src/main/ets/MainAbility/MainAbility.ts b/kvdb_stage_demo/entry/src/main/ets/MainAbility/MainAbility.ts index f57e1b9..ca3fa77 100644 --- a/kvdb_stage_demo/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/kvdb_stage_demo/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,31 +1,49 @@ -import Ability from '@ohos.application.Ability'; +import Ability from '@ohos.app.ability.UIAbility'; import deviceManager from '@ohos.distributedHardware.deviceManager'; import distributedData from '@ohos.data.distributedKVStore'; import accessControl from '@ohos.abilityAccessCtrl'; import bundle from '@ohos.bundle'; -//import {AreaMode} from "application/Context" +const DEMO_KEY_PREFIX = '#TEST#' + +var nameList = ["Leila", "Ursa", "Crystal", "Rebecca", "Taylor", "Elizabeth", "Ayn", "Rosa", "Beatrice", "Tracy", + "Emily", "Glenn", "Iris", "Sara", "Freddie", "Cindy", "Devin", "Karen", "Zillah", "Ivy", "Xena", "Aimee", "Olivia", + "Elisabeth", "Ulrica", "Chris", "Leslie", "Felicity", "Alessandra", "Cherie", "Sonia", "Elsa", "Natasha", "Candy", + "Kim", "Darleen", "Lillian", "Abigail", "Del", "Serena", "Candice", "Gemma", "Irene", "Rita", "Genevieve", "Nora", + "Ivory", "Niki", "Jacky", "Betty", "Isabelle", "Ray", "Patty", "Cathy", "Tanya", "Alison", "Rachel", "Julia", + "Julie", "Yasmine", "Susan", "Odin", "Emma", "Jessie", "Zoie", "Paula", "Carrie", "Harriet", "Christian", "Hana", + "Charlotte", "Terry", "Leah", "Ximena", "Frederica", "Wing", "Qara", "Elaine", "Silvia", "Ella", "Francesca", + "Janet", "Phoebe", "Holly", "Xochitl", "Urania", "Qatar", "Yolanda", "Athena", "Georgia", "Beth", "Barbie", + "Della", "Isabella", "Wendi", "Ophelia", "Hanna", "Sarah", "Hayden", "Teresa"]; + +function random(min, max) { + return Math.floor(Math.random() * (max - min)) + min; +} export default class MainAbility extends Ability { devManager; deviceList; kvManager; kvStore; - syncMode; logText = ''; storeId = "device_sync_storeId_10"; appId = "com.example.kvdb_stage_demo"; syncListenerStarted = false; dataListenerStarted = false; - subscribeType = 1; // Ô¶³Ì¶©ÔÄ localDeviceId; - demoKvStoreType = 0; onCreate(want,launchParam){ // Ability is creating, initialize resources for this ability console.info("[Demo] MainAbility onCreate") globalThis.abilityWant = want; this.logText = "--------------Stage module----------------\r\n\n" + globalThis.encrypt = false; + globalThis.autoSync = false; + globalThis.kvStoreType = distributedData.KVStoreType.SINGLE_VERSION; + globalThis.securityLevel = distributedData.SecurityLevel.S1; + globalThis.subscribeType = distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE; + globalThis.syncMode = distributedData.SyncMode.PUSH_PULL; + globalThis.needDelLst = []; } onDestroy() { @@ -35,6 +53,7 @@ export default class MainAbility extends Ability { globalThis.DeleteKvStore(); globalThis.stopDataListener(); globalThis.stopSyncListener(); + this.kvManager = null; } } @@ -131,24 +150,20 @@ export default class MainAbility extends Ability { this.logText += "CreateKvManager Enter\r\n"; globalThis.CreateDevManager(); if (typeof (this.kvManager) === 'undefined') { - let self = this; try { const kvManagerConfig = { bundleName: this.appId, - userInfo: { - userId: '0', - userType: 0 - }, context : globalThis.abilityContext, } - distributedData.createKVManager(kvManagerConfig).then((manager) => { - console.log ("[JSDemo]: CreateKVManager success"); + try { + this.kvManager = distributedData.createKVManager(kvManagerConfig); + console.log("[JSDemo]: Succeeded in creating KVManager"); this.logText += "CreateKVManager success\r\n"; - self.kvManager = manager; - }).catch((err) => { + } catch (err) { console.log("[JSDemo]: createKVManager err: " + JSON.stringify(err)); this.logText += "createKVManager err: " + JSON.stringify(err) + "\r\n"; - }); + } + } catch (e) { console.log("[JSDemo]: An unexpected error occurred. Error:" + e); this.logText += "An unexpected error occurred. Error: " + e + "\r\n"; @@ -171,18 +186,19 @@ export default class MainAbility extends Ability { try { const options = { createIfMissing: true, - encrypt: false , + encrypt: globalThis.encrypt, backup: false, - autoSync: false, - kvStoreType: this.demoKvStoreType, // DEVICE_COLLABORATION--0, SINGLE_VERSION = 1 - securityLevel: distributedData.SecurityLevel.S1, + autoSync: globalThis.autoSync, + kvStoreType: globalThis.kvStoreType, // DEVICE_COLLABORATION--0, SINGLE_VERSION = 1 + securityLevel: globalThis.securityLevel, }; let self = this; this.kvManager.getKVStore(this.storeId, options).then((store) => { - console.log("[JSDemo]: getKVStore success"); - this.logText += "getKVStore success\r\n"; - this.logText += "kvStore options : " + JSON.stringify(options) +"\r\n"; + console.log("[JSDemo]: getKVStore success, options :" + JSON.stringify(options)); + + self.logText += "kvStore options : " + JSON.stringify(options) +"\r\n"; + self.logText += "getKVStore success\r\n"; self.kvStore = store; }).catch((err) => { console.log("[JSDemo]: getKVStore err: " + JSON.stringify(err)); @@ -193,20 +209,23 @@ export default class MainAbility extends Ability { this.logText += "GetKvStore: An unexpected error occurred. Error: " + e +"\r\n"; } }) - - globalThis.Put = (() => { + globalThis.PutRandom = (() => { if (this.kvStore == undefined) { console.log('[JSDemo]: Put: kvStore not initialized'); this.logText += "Put: kvStore not initialized\r\n"; return; } try { - this.kvStore.put(JSON.stringify('key_test_string'), JSON.stringify('value_test_string')).then((data) => { + let key = DEMO_KEY_PREFIX + nameList[Math.floor(Math.random() * nameList.length)]; + let value = random(1, 100); + let self = this; + this.kvStore.put(key, value).then((data) => { console.log("[JSDemo]: put success. "); - this.logText += "put success. \r\n"; + self.logText += "put success. \r\n"; + globalThis.needDelLst.push(key); }).catch((err) => { console.log("[JSDemo]: put err: " + JSON.stringify(err)); - this.logText += "put err: " + JSON.stringify(err) + "\r\n"; + self.logText += "put err: " + JSON.stringify(err) + "\r\n"; }); } catch (e) { console.log("[JSDemo]: An unexpected error occurred. Error:" + e); @@ -214,43 +233,43 @@ export default class MainAbility extends Ability { } }) - globalThis.Get = (() => { + globalThis.GetAllData = (() => { if (this.kvStore == undefined) { - console.log('[JSDemo]: Get: kvStore not initialized'); - this.logText += " Get: kvStore not initialized\r\n"; + console.log('[JSDemo]: GetAllData: kvStore not initialized'); + this.logText += " GetAllData: kvStore not initialized\r\n"; return; } try { - if (this.demoKvStoreType == 0) { //deviceKvStore + let self = this; + if (globalThis.kvStoreType == distributedData.KVStoreType.DEVICE_COLLABORATION) { //deviceKvStore var localDeviceId = this.devManager.getLocalDeviceInfoSync().deviceId; - const promise1 = this.kvStore.get(localDeviceId, JSON.stringify('key_test_string')); - promise1.then((data) => { - console.log("[JSDemo] Get with local deviceId success " + data); - this.logText += ("Get with local deviceId success. data:" + data + "\r\n"); + this.kvStore.getEntries(localDeviceId, DEMO_KEY_PREFIX).then((entries) => { + console.log("[JSDemo] Get All localDevice data success, entries.length: " + entries.length + ", entries:" + JSON.stringify(entries)); + self.logText += ("Get All local localDevice success. data : " + JSON.stringify(entries) + "\r\n"); }).catch((err) => { var remoteDeviceId = this.devManager.getTrustedDeviceListSync()[0].deviceId; - const promise2 = this.kvStore.get(remoteDeviceId, JSON.stringify('key_test_string')); - promise2.then((data) => { - console.log("[JSDemo] Get with remote deviceId success " + data); - this.logText += ("Get with remote deviceId success. data:" + data + "\r\n"); + this.kvStore.getEntries(remoteDeviceId, DEMO_KEY_PREFIX).then((entries) => { + console.log("[JSDemo] Get All remoteDevice data success, entries.length: " + entries.length + ", entries:" + JSON.stringify(entries)); + self.logText += ("Get All remoteDevice data success. data : " + JSON.stringify(entries) + "\r\n"); }).catch((err) => { - console.log("[JSDemo] Get fail " + err); - this.logText += "Get fail " + err + ".\r\n"; + console.error(`[JSDemo] Fail to Get All remoteDevice entries.code is ${err.code},message is ${err.message}`); + self.logText += (`Fail to Get All remoteDevice entries.code is ${err.code},message is ${err.message}` + ".\r\n"); }); }); - } else if (this.demoKvStoreType == 1) { // singleKvStore - const promise1 = this.kvStore.get(JSON.stringify('key_test_string')); - promise1.then((data) => { - console.log("[JSDemo] Get success " + data); - this.logText += ("Get success. data : " + data + "\r\n"); - }).catch((err) => { - console.log("[JSDemo] Get fail " + err); - this.logText += "Get fail " + err + ".\r\n"; + } else if (globalThis.kvStoreType == distributedData.KVStoreType.SINGLE_VERSION) { // singleKvStore + this.kvStore.getEntries(DEMO_KEY_PREFIX, function (err, entries) { + if (err != undefined) { + console.error(`[JSDemo] Fail to get Entries.code is ${err.code},message is ${err.message}`); + self.logText += (`Fail to get Entries.code is ${err.code},message is ${err.message}`+ "\r\n"); + return; + } + console.log("[JSDemo] GetAllData success, entries.length: " + entries.length + ", entries:" + JSON.stringify(entries)); + self.logText += ("GetAllData success. data : " + JSON.stringify(entries) + "\r\n"); }); } } catch (e) { - console.log("[JSDemo]: An unexpected error occurred. Error:" + e); - this.logText += "Get: An unexpected error occurred. Error: " + e +"\r\n"; + console.log("[JSDemo]:GetAllData An unexpected error occurred. Error:" + e); + this.logText += "GetAllData: An unexpected error occurred. Error: " + e +"\r\n"; } }) @@ -271,32 +290,40 @@ export default class MainAbility extends Ability { var devices = this.deviceList; console.info('[JSDemo] Sync start'); this.logText += "Sync start\r\n"; - this.kvStore.sync(devices, distributedData.SyncMode.PUSH_PULL); + this.kvStore.sync(devices, globalThis.syncMode); }) - globalThis.Delete = (() =>{ - console.info("[JSDemo] Delete begin"); - this.logText += "Delete begin\r\n"; + globalThis.DeleteAllData = (() =>{ + console.info("[JSDemo] DeleteAllData begin"); + this.logText += "DeleteAllData begin\r\n"; if(this.kvStore == null) { - console.info('[JSDemo] Delete kvStore is null'); - this.logText += "Delete kvStore is null\r\n"; + console.info('[JSDemo] DeleteAllData kvStore is null'); + this.logText += "DeleteAllData, kvStore is null\r\n"; + return; + } + if(globalThis.needDelLst.length<1){ + console.log("[JSDemo] DeleteAllData: no data need del"); + this.logText += "DeleteAllData: no data need del \r\n"; return; } try { - const promise1 = this.kvStore.delete(JSON.stringify('key_test_string')); - promise1.then((data) => { - console.log("[JSDemo] Delete success "); - this.logText += "Delete success\r\n"; + let self = this; + const promise = this.kvStore.deleteBatch(globalThis.needDelLst); + promise.then((data) => { + console.log("[JSDemo] DeleteAllData success,"+ globalThis.needDelLst); + self.logText += "DeleteAllData success,"+ globalThis.needDelLst +" \r\n"; }).catch((err) => { - console.log("[JSDemo] Delete fail " + err); - this.logText += "Delete fail" +JSON.stringify(err)+ "\r\n"; + console.error(`[JSDemo]Fail to DeleteAllData.code is ${err.code},message is ${err.message}`); + self.logText += (`DeleteAllData, Fail to delete.code is ${err.code},message is ${err.message}` + "\r\n"); }); + } catch(e) { - console.log("[JSDemo] Delete err " + e); - this.logText += "Delete err" +JSON.stringify(e)+ "\r\n"; + console.log("[JSDemo] DeleteAllData err " + e); + this.logText += "DeleteAllData err" +JSON.stringify(e)+ "\r\n"; } }) + globalThis.DeleteKvStore = (() =>{ console.info("[JSDemo] DeleteKvStore begin"); this.logText += "DeleteKvStore begin\r\n"; @@ -311,30 +338,6 @@ export default class MainAbility extends Ability { return; } try { -// this.kvManager.closeKVStore(this.context.applicationInfo.name, this.storeId, this.kvStore).then(() => { -// }) -// this.kvManager = null; -// -// this.context.switchArea(AreaMode.EL1); -// let context = this.context; -// const kvManagerConfig = { -// bundleName: this.appId, -// userInfo: { -// userId: '0', -// userType: distributedData.UserType.SAME_USER_ID -// }, -// context : context, -// } -// distributedData.createKVManager(kvManagerConfig).then((manager) => { -// console.log ("[JSDemo]: CreateKVManager success"); -// this.logText += "CreateKVManager success AreaMode::EL1\r\n"; -//// this.kvManager = manager; -// }).catch((err) => { -// console.log("[JSDemo]: createKVManager err: " + JSON.stringify(err)); -// this.logText += "createKVManager err: " + JSON.stringify(err) + "\r\n"; -// }); - - this.kvManager.closeKVStore(this.appId, this.storeId).then(() => { console.log('closeKVStore success'); this.logText += "closeKVStore success.\r\n"; @@ -346,7 +349,6 @@ export default class MainAbility extends Ability { console.log('deleteKVStore success'); this.logText += "deleteKVStore success.\r\n"; this.kvStore = null; - this.kvManager = null; }).catch((err) => { console.log('deleteKVStore err ' ); this.logText += "deleteKVStore fail." + JSON.stringify(err) + "\r\n"; @@ -419,8 +421,8 @@ export default class MainAbility extends Ability { return; } try { - this.logText += "register dataChange SubscribeType:" + this.subscribeType + ".\r\n"; - this.kvStore.on('dataChange', this.subscribeType, function (data) { + this.logText += "register dataChange SubscribeType:" + globalThis.subscribeType + ".\r\n"; + this.kvStore.on('dataChange', globalThis.subscribeType, function (data) { console.info('[JSDemo] dataChange callback call' + data); that.logText += "dataChange callback call.\r\n"; if(data) { @@ -475,13 +477,113 @@ export default class MainAbility extends Ability { }) globalThis.clearLog = (() =>{ - this.logText = "" + this.logText = ""; return this.logText; }) + + globalThis.SetEncrypt = ((encrypt) =>{ + let tmp = "NA"; + if(encrypt==0){ + globalThis.encrypt=false; + tmp = "false"; + }else{ + globalThis.encrypt=true; + tmp = "true"; + } + console.info("[JSDemo] SetEncrypt:" + tmp); + this.logText+="SetEncrypt:" + tmp + "\r\n"; + }) + + globalThis.SetAutoSync = ((autoSync) =>{ + let tmp = "NA"; + if(autoSync==0){ + globalThis.autoSync=false; + tmp = "false"; + }else{ + globalThis.autoSync=true; + tmp = "true"; + } + console.info("[JSDemo] SetAutoSync:" + tmp); + this.logText+="SetAutoSync:" + tmp + "\r\n"; + }) + + globalThis.SetKvStoreType = ((kvStoreType) =>{ + let tmp = "NA"; + if(kvStoreType==0){ + globalThis.kvStoreType=distributedData.KVStoreType.DEVICE_COLLABORATION; + tmp = "DEVICE_COLLABORATION"; + } else { + globalThis.kvStoreType=distributedData.KVStoreType.SINGLE_VERSION; + tmp = "SINGLE_VERSION"; + } + console.info("[JSDemo] SetKvStoreType:" + tmp); + this.logText+="SetKvStoreType:" + tmp + "\r\n"; + }) + + globalThis.SetSecurityLevel = ((securityLevel) =>{ + let tmp = "NA"; + if(securityLevel==0){ + globalThis.securityLevel=distributedData.SecurityLevel.S1; + tmp="S1"; + } else if(securityLevel==1) { + globalThis.securityLevel=distributedData.SecurityLevel.S2; + tmp="S2"; + } else if(securityLevel==2) { + globalThis.securityLevel=distributedData.SecurityLevel.S3; + tmp="S3"; + } else if(securityLevel==3) { + globalThis.securityLevel=distributedData.SecurityLevel.S4; + tmp="S4"; + } else { // para range error + globalThis.securityLevel=distributedData.SecurityLevel.S1; + tmp="S1, para range error"; + } + console.info("[JSDemo] SetSecurityLevel:" + tmp); + this.logText+="SetSecurityLevel:" + tmp + "\r\n"; + }) + + globalThis.SetSyncMode = ((syncMode) =>{ + let tmp = "NA"; + if(syncMode==0){ + globalThis.syncMode=distributedData.SyncMode.PULL_ONLY; + tmp="PULL_ONLY"; + } else if(syncMode==1){ + globalThis.syncMode=distributedData.SyncMode.PUSH_ONLY; + tmp="PUSH_ONLY"; + } else if(syncMode==2){ + globalThis.syncMode=distributedData.SyncMode.PUSH_PULL; + tmp="PUSH_PULL"; + } else { // para range error + globalThis.syncMode=distributedData.SyncMode.PUSH_PULL; + tmp="PUSH_PULL, para range error"; + } + console.info("[JSDemo] SetSyncMode:" + tmp); + this.logText+="SetSyncMode:" + tmp + "\r\n"; + }) + + globalThis.SetSubscribeType = ((subscribeType) =>{ + let tmp = "NA"; + if(subscribeType==0){ + globalThis.subscribeType=distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL; + tmp="SUBSCRIBE_TYPE_LOCAL"; + } else if(subscribeType==1){ + globalThis.subscribeType=distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE; + tmp="SUBSCRIBE_TYPE_REMOTE"; + } else if(subscribeType==2){ + globalThis.subscribeType=distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL; + tmp="SUBSCRIBE_TYPE_ALL"; + } else { // para range error + globalThis.subscribeType=distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE; + tmp="SUBSCRIBE_TYPE_REMOTE, para range error"; + } + console.info("[JSDemo] SetSubscribeType:" + tmp); + this.logText+="SetSubscribeType:" + tmp + "\r\n"; + }) + } onWindowStageDestroy() { - //Main window is destroyed, release UI related resources + // Main window is destroyed, release UI related resources console.info("[Demo] MainAbility onWindowStageDestroy") } diff --git a/kvdb_stage_demo/entry/src/main/ets/pages/index/index.ets b/kvdb_stage_demo/entry/src/main/ets/pages/index/index.ets index bee9840..22b3cbb 100644 --- a/kvdb_stage_demo/entry/src/main/ets/pages/index/index.ets +++ b/kvdb_stage_demo/entry/src/main/ets/pages/index/index.ets @@ -12,20 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -//import file from '@system.file'; -// -////import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets" + import {Core, ExpectExtend} from "hypium/index" -//import testsuite from "../../test/List.test" -import router from '@system.router'; +import router from '@ohos.router'; async function routePage() { let options = { - uri: 'pages/second' + url: 'pages/second/second' } try { - await router.push(options) + await router.pushUrl({url: 'pages/second/second'}) // API9 } catch (err) { console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`) } @@ -42,163 +39,252 @@ struct Index { 'id': 'extend' }) core.addService('expect', expectExtend) -// const reportExtend = new ReportExtend(file) - -// core.addService('report', reportExtend) core.init() -// core.subscribeEvent('task', reportExtend) const configService = core.getDefaultService('config') console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) globalThis.abilityWant.parameters.timeout = 70000; configService.setConfig(globalThis.abilityWant.parameters) globalThis.requestPermissions(); -// testsuite(globalThis.abilityContext) core.execute() } @State text: string = '' + + @State encryptSelect:number = 0 + private encryptLst:string[] = ['false','true'] + + @State autoSyncSelect:number = 0 + private autoSyncLst:string[] = ['false','true'] + + @State kvStoreTypeSelect:number = 1 + private kvStoreTypeLst:string[] = ['DEVICE_COLLABORATION','SINGLE_VERSION'] + + @State securityLevelSelect:number = 0 + private securityLevelLst:string[] = ['S1','S2','S3','S4'] + + @State subscribeTypeSelect:number = 1 + private subscribeTypeLst:string[] = ['LOCAL','REMOTE','ALL'] + + @State syncModSelect:number = 2 + private syncModLst:string[] = ['PULL_ONLY','PUSH_ONLY','PUSH_PULL'] build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { - Button('CreateKvManager').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('230') + Column({space:2}) { + Row({space:2}) { + Button('CreateKvManager').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') .backgroundColor('#f32dc400').onClick(() => { globalThis.CreateKvManager(); this.text = globalThis.printLogs(); }) + Button('SetEncrypt').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .onClick(() => { + TextPickerDialog.show({ + range:this.encryptLst, + selected:this.encryptSelect, + onAccept:(value:TextPickerResult)=>{ + globalThis.SetEncrypt(value.index) + this.encryptSelect=value.index; + console.info("[JSDemo]encrypt:onAccept()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + }, + onCancel:()=>{ + console.info("[JSDemo]encrypt:onCancel()"); + }, + onChange:(value:TextPickerResult)=>{ + console.info("[JSDemo]encrypt:onChange()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + } + }) + }) + Button('SetAutoSync').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .onClick(() => { + TextPickerDialog.show({ + range:this.autoSyncLst, + selected:this.autoSyncSelect, + onAccept:(value:TextPickerResult)=>{ + globalThis.SetAutoSync(value.index) + this.autoSyncSelect=value.index; + console.info("[JSDemo]autoSync:onAccept()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + }, + onCancel:()=>{ + console.info("[JSDemo]autoSync:onCancel()"); + }, + onChange:(value:TextPickerResult)=>{ + console.info("[JSDemo]autoSync:onChange()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + } + }) + }) } .width('100%') - .height('5%') - .border({width:1}) + .height('6%') - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { - Column() { - Button('GetKvStore').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('230') - .backgroundColor('#f32dc400').onClick(() => { - globalThis.GetKvStore(); - this.text = globalThis.printLogs(); + Row({space:2}) { + Button('SetKvStoreType').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .onClick(() => { + TextPickerDialog.show({ + range:this.kvStoreTypeLst, + selected:this.kvStoreTypeSelect, + onAccept:(value:TextPickerResult)=>{ + globalThis.SetKvStoreType(value.index) + this.kvStoreTypeSelect=value.index; + console.info("[JSDemo]kvStoreType:onAccept()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + }, + onCancel:()=>{ + console.info("[JSDemo]kvStoreType:onCancel()"); + }, + onChange:(value:TextPickerResult)=>{ + console.info("[JSDemo]kvStoreType:onChange()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + } }) - Button('DeleteKvStore').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('230') - .backgroundColor('#f32dc400').onClick(() => { - globalThis.DeleteKvStore(); - this.text = globalThis.printLogs(); + }) + Button('SetSecurityLevel').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .onClick(() => { + TextPickerDialog.show({ + range:this.securityLevelLst, + selected:this.securityLevelSelect, + onAccept:(value:TextPickerResult)=>{ + globalThis.SetSecurityLevel(value.index) + this.securityLevelSelect=value.index; + console.info("[JSDemo]securityLevel:onAccept()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + }, + onCancel:()=>{ + console.info("[JSDemo]securityLevel:onCancel()"); + }, + onChange:(value:TextPickerResult)=>{ + console.info("[JSDemo]securityLevel:onChange()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + } + }) }) - } - -// Column() { -// Button('SetSecurityLevel').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('230') -// .backgroundColor('#f32dc4aa').onClick(() => { -// this.text = globalThis.printLogs(); -// }) -// Button('GetSecurityLevel').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('230') -// .backgroundColor('#f32dc4aa').onClick(() => { -// this.text = globalThis.printLogs(); -// }) -// } + Button('GetKvStore').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { + globalThis.GetKvStore(); + this.text = globalThis.printLogs(); + }) + } .width('100%') - .height('10%') - .border({width:1}) + .height('6%') - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { - Column() { -// Button('SubscribeType').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('230') -// .backgroundColor('#f32dc4aa').onClick(() => { -// this.text = globalThis.printLogs(); -// }) - Button('RegDataChange').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('230') - .backgroundColor('#f32dc400').onClick(() => { - globalThis.RegDataChange(); - this.text = globalThis.printLogs(); + Row({space:2}) { + Button('SetSubscribeType').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .onClick(() => { + TextPickerDialog.show({ + range:this.subscribeTypeLst, + selected:this.subscribeTypeSelect, + onAccept:(value:TextPickerResult)=>{ + globalThis.SetSubscribeType(value.index) + this.subscribeTypeSelect=value.index; + console.info("[JSDemo]SetSubscribeType:onAccept()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + }, + onCancel:()=>{ + console.info("[JSDemo]SetSubscribeType:onCancel()"); + }, + onChange:(value:TextPickerResult)=>{ + console.info("[JSDemo]SetSubscribeType:onChange()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + } }) - } - - Column() { - Button('RegSyncComplete').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('230') - .backgroundColor('#f32dc400').onClick(() => { - globalThis.RegSyncComplete(); - this.text = globalThis.printLogs(); - }) - } + }) + Button('RegDataChange').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { + globalThis.RegDataChange(); + this.text = globalThis.printLogs(); + }) + Button('RegSyncComplete').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { + globalThis.RegSyncComplete(); + this.text = globalThis.printLogs(); + }) } .width('100%') - .height('10%') - .border({width:1}) + .height('6%') - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { - Column() { - Button('Put').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('120') + Row({space:2}) { + Button('Put').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') .backgroundColor('#f32dc400').onClick(() => { - globalThis.Put(); - this.text = globalThis.printLogs(); - }) - Button('Get').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('120') - .backgroundColor('#f32dc400').onClick(() => { - globalThis.Get(); - this.text = globalThis.printLogs(); - }) - } + globalThis.PutRandom(); + this.text = globalThis.printLogs(); + }) + Button('Get').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { + globalThis.GetAllData(); + this.text = globalThis.printLogs(); + }) - Column() { - Button('Delete').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('120') - .backgroundColor('#f32dc400').onClick(() => { - globalThis.Delete(); - this.text = globalThis.printLogs(); + Button('Delete').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { + globalThis.DeleteAllData(); + this.text = globalThis.printLogs(); + }) + } + .width('100%') + .height('6%') + + Row({space:2}) { + Button('SetSyncMode').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .onClick(() => { + TextPickerDialog.show({ + range:this.syncModLst, + selected:this.syncModSelect, + onAccept:(value:TextPickerResult)=>{ + globalThis.SetSyncMode(value.index) + this.syncModSelect=value.index; + console.info("[JSDemo]syncMod:onAccept()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + }, + onCancel:()=>{ + console.info("[JSDemo]syncMod:onCancel()"); + }, + onChange:(value:TextPickerResult)=>{ + console.info("[JSDemo]syncMod:onChange()" + JSON.stringify(value)); + this.text=globalThis.printLogs(); + } + }) }) - Button('Sync').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('120') - .backgroundColor('#f32dc400').onClick(() => { + Button('Sync').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { globalThis.Sync(); this.text = globalThis.printLogs(); }) - } - - Column() { - Button('SyncMode').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150') - .backgroundColor('#f32dc4aa').onClick(() => { + Button('DeleteKvStore').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { + globalThis.DeleteKvStore(); this.text = globalThis.printLogs(); }) - Button('ClearLog').fontSize(20).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150') - .backgroundColor('#f32dc400').onClick(() => { - this.text = globalThis.clearLog(); + } + .width('100%') + .height('6%') + + Row({space:2}){ + Button('PrintLogs').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { + this.text = globalThis.printLogs(); }) - } + Button('ClearLog').fontSize(12).fontWeight(FontWeight.Normal).type(ButtonType.Capsule).margin({}).width('150').height('100%') + .backgroundColor('#f32dc400').onClick(() => { + this.text = globalThis.clearLog(); + }) } .width('100%') - .height('10%') - .border({width:1}) + .height('6%') Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { Text(this.text) { - }.baselineOffset(10) + }.baselineOffset(10).fontSize(9) } .width('100%') - .height('55%') + .height('60%') .border({width:1}) } - - .width('100%') + .width('99%') .height('100%') } -// build() { -// Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { -// Text('Hello World') -// .fontSize(50) -// .fontWeight(FontWeight.Bold) -// Button() { -// Text('next page') -// .fontSize(25) -// .fontWeight(FontWeight.Bold) -// }.type(ButtonType.Capsule) -// .margin({ -// top: 20 -// }) -// .backgroundColor('#0D9FFB') -// .onClick(() => { -// -// }) -// } -// .width('100%') -// .height('100%') -// } -} \ No newline at end of file +} -- Gitee