diff --git a/README.md b/README.md index d3517afda7032764cae84d4bd22808fe2f5cfdb7..2472e60be1cadcf07ef00e97191006189953dfd9 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,13 @@ ## 项目简介 -本Codelab以分布式账单为例,使用关系型数据库的相关接口实现了对账单的增、删、改、查操作。效果图如下: +本Codelab以分布式账单为例,使用关系型数据库的相关接口实现了对账单的增、删、改、查和同步操作。效果图如下: ## 效果预览 -| **账单案例** | | | -|:------------------------------------------------------:|:------------------------------------------------------:|:-------------------------------------------------------:| -| 新增 | 删除 | 编辑 | -| | | | +| 新增 | 删除 | 编辑 | 查询 | +|:------------------------------------------------------------:|:----------------------------------------------------------:|:-----------------------------------------------------------:|:------------------------------------------------------------:| +| | | | | ## 使用说明 @@ -37,9 +36,14 @@ └──entry/src/main/resources // 资源文件 ``` -## 相关概念 +## 具体实现 -- 关系型数据库:基于关系模型来管理数据的数据库,提供了增、删、改、查等接口,也可运行输入的SQL语句满足复杂场景需要。 +1. 应用首次启动时,调用[requestPermissionsFromUser()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-abilityaccessctrl#requestpermissionsfromuser9)方法动态弹窗获取授权。 +2. 创建关系型数据库,通过[relationalStore.getRdbStore()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-data-relationalstore-f#relationalstoregetrdbstore)创建关系型数据库,并通过[setDistributedTables()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-data-relationalstore-rdbstore#setdistributedtables)方法设置分布式数据库表。 +3. 调用[on('dataChange')](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-data-relationalstore-rdbstore#ondatachange)接口订阅组网内其他设备的数据变化,并注册数据变化回调函数。 +4. 封装操作数据库的增([insert()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-data-rdb#insert-1))、删([delete()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-data-rdb#delete-1))、改([update()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-data-rdb#update-1))、查([query()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-data-rdb#query-1))四个方法。 +5. 调用同步数据的接口[sync()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-data-relationalstore-rdbstore#sync-1)推送当前设备数据变化至组网内其他设备。 +6. 获取到变化的数据列表,更新本地数据。 ## 相关权限 @@ -52,5 +56,5 @@ 3. DevEco Studio版本:DevEco Studio 5.1.1 Release及以上。 4. HarmonyOS SDK版本:HarmonyOS 5.1.1 Release SDK及以上。 5. 双端设备需要登录同一华为账号,建议打开查找设备功能。 -6. 双端设备需要打开Wi-Fi和蓝牙开关。 +6. 双端设备需要打开Wi-Fi和蓝牙开关,条件允许时最好连接同一局域网。 7. 双端设备都需要有该应用。 diff --git a/entry/src/main/ets/pages/BillHomePage.ets b/entry/src/main/ets/pages/BillHomePage.ets index 5fcda68b54a0cd3f5e9cf2839850c6dd39749f7a..aaf24460c644fac0f6a20e23aaf077fee900129a 100644 --- a/entry/src/main/ets/pages/BillHomePage.ets +++ b/entry/src/main/ets/pages/BillHomePage.ets @@ -180,9 +180,6 @@ struct BillHomePage { .backgroundColor('rgba(10, 89, 247, 0.15)') .borderRadius(40) .margin({ right: 16 }) - .onClick(() => { - this.getUIContext().getRouter().back(); - }) Text(TextList[item.typeText]) .fontSize($r('app.float.font_size_M')) @@ -248,57 +245,50 @@ struct BillHomePage { } if (!this.isEdit) { - Column() { - Row() { - SymbolGlyph($r('sys.symbol.plus')) - .fontSize(24) - .fontColor([Color.White]) - .fontWeight(400) - } - .alignItems(VerticalAlign.Center) - .justifyContent(FlexAlign.Center) - .width(48) - .height(48) - .backgroundColor('#0A59F7') - .borderRadius('50%') - .margin({ right: 8 }) - .onClick(() => { - this.isInsert = true; - this.newAccount = { - id: '', - accountType: 0, - typeText: '', - amount: 0 - }; - this.dialogController.open(); - }) + Row() { + SymbolGlyph($r('sys.symbol.plus')) + .fontSize(24) + .fontColor([Color.White]) + .fontWeight(400) } - .width('100%') + .alignItems(VerticalAlign.Center) .justifyContent(FlexAlign.Center) - .position({ bottom: 26 }) + .width(48) + .height(48) + .backgroundColor('#0A59F7') + .borderRadius('50%') + .position({ left: '50%', bottom: 26 }) + .translate({ x: '-50%' }) + .onClick(() => { + this.isInsert = true; + this.newAccount = { + id: '', + accountType: 0, + typeText: '', + amount: 0 + }; + this.dialogController.open(); + }) } if (this.isEdit) { - Row() { - Column() { - SymbolGlyph($r('sys.symbol.trash')) - .fontSize(20) - .fontColor([Color.Black]) - .fontWeight(400) - Text($r('app.string.delete_text')) - .fontSize(12) - .fontColor('rgba(0, 0, 0, 0.9)') - .lineHeight(16) - .fontWeight(400) - .margin({ top: 6 }) - } - .onClick(() => { - this.deleteListItem(); - }) + Column() { + SymbolGlyph($r('sys.symbol.trash')) + .fontSize(20) + .fontColor([Color.Black]) + .fontWeight(400) + Text($r('app.string.delete_text')) + .fontSize(12) + .fontColor('rgba(0, 0, 0, 0.9)') + .lineHeight(16) + .fontWeight(400) + .margin({ top: 6 }) } - .width('100%') - .justifyContent(FlexAlign.Center) - .position({ bottom: 0 }) + .position({ left: '50%', bottom: 0 }) + .translate({ x: '-50%' }) + .onClick(() => { + this.deleteListItem(); + }) } } .width('100%') diff --git a/screenshots/devices/add.gif b/screenshots/devices/add.gif deleted file mode 100644 index eb031b0c44d52831d8fa41ebca4e5d6a66c11ed5..0000000000000000000000000000000000000000 Binary files a/screenshots/devices/add.gif and /dev/null differ diff --git a/screenshots/devices/billAdd.gif b/screenshots/devices/billAdd.gif new file mode 100644 index 0000000000000000000000000000000000000000..aa555fb66b004836c53f1bdb156e025b682af954 Binary files /dev/null and b/screenshots/devices/billAdd.gif differ diff --git a/screenshots/devices/billDel.gif b/screenshots/devices/billDel.gif new file mode 100644 index 0000000000000000000000000000000000000000..ed07ff18456e69696d06d9ee117df03c569bfc88 Binary files /dev/null and b/screenshots/devices/billDel.gif differ diff --git a/screenshots/devices/billEdit.gif b/screenshots/devices/billEdit.gif new file mode 100644 index 0000000000000000000000000000000000000000..c164c8d211fe091ff90af903f0aa7282a383ba7b Binary files /dev/null and b/screenshots/devices/billEdit.gif differ diff --git a/screenshots/devices/billQuery.gif b/screenshots/devices/billQuery.gif new file mode 100644 index 0000000000000000000000000000000000000000..891a2c1998b77ae0f2f0255d9d021ad4e87fd5a6 Binary files /dev/null and b/screenshots/devices/billQuery.gif differ diff --git a/screenshots/devices/del.gif b/screenshots/devices/del.gif deleted file mode 100644 index 408d3238fa5f03d10796503e68e4111b1a6e0b55..0000000000000000000000000000000000000000 Binary files a/screenshots/devices/del.gif and /dev/null differ diff --git a/screenshots/devices/edit.gif b/screenshots/devices/edit.gif deleted file mode 100644 index 19aa7e97b96e7eb1163aef3f0c9fb257efedf0db..0000000000000000000000000000000000000000 Binary files a/screenshots/devices/edit.gif and /dev/null differ