diff --git a/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f00442a8331f2c541a40f6cb995a4ed0ff0b2e5d --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.rdb", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f7eeb63e254c981a86d127d800290e31697b1ec3 --- /dev/null +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Rdb" + } + ] +} diff --git a/AppScope/resources/base/media/app_icon.png b/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/AppScope/resources/base/media/app_icon.png differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..381eb507bc1eef9b5158e496dedab769e810b657 --- /dev/null +++ b/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Apache License, Version 2.0 +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 2c7c6f140513f22fbc2f903bb63085fd8b5cca7e..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# Rdb - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index db4be7e675be8e89306ac5e8feec4027477b6ad9..1932be7ff4ffe04563adb50f3d57f2d991b06d76 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,29 @@ -# Rdb +# 关系型数据库(ArkTS) -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +### 简介 -#### 软件架构 -软件架构说明 +本Codelab以记账为例,使用关系型数据库的相关接口实现了对账单的增、删、改、查操作。效果图如下: +![image](screenshots/device/关系型数据库.gif) -#### 安装教程 +### 相关概念 -1. xxxx -2. xxxx -3. xxxx +- 关系型数据库:基于关系模型来管理数据的数据库,提供了增、删、改、查等接口,也可运行输入的SQL语句满足复杂场景需要。 -#### 使用说明 +### 相关权限 -1. xxxx -2. xxxx -3. xxxx +不涉及 -#### 参与贡献 +### 使用说明 -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +1. 在应用首页,点击右下角“添加”图标,在弹出的窗口中选择账目类型并填写金额,点击“确定”按钮添加一条账目。 +2. 在应用首页,点击右上角“编辑”图标,选中想要删除的账目,点击下方“删除”图标,删除选择的账目。 +3. 在应用首页,点击想要编辑的账目,在弹出的窗口中更改账目类型或金额,点击“确定”按钮修改一条账目。 +4. 在应用首页,点击搜索栏,填写想要查找的账目金额,点击“搜索”图标后下方刷新为金额为查找金额的账目,搜索栏为空时显示全部账目。 +### 约束与限制 -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 +2. HarmonyOS系统:HarmonyOS NEXT Developer Beta1及以上。 +3. DevEco Studio版本:DevEco Studio NEXT Developer Beta1及以上。 +4. HarmonyOS SDK版本:HarmonyOS NEXT Developer Beta1 SDK及以上。 diff --git a/build-profile.json5 b/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..26bea001ac6999860a2890121e380c122e6b601b --- /dev/null +++ b/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..13c5eda6e6a3dae913ec5c5c4d60ea3ac954f205 --- /dev/null +++ b/entry/build-profile.json5 @@ -0,0 +1,11 @@ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + } + ] +} \ No newline at end of file diff --git a/entry/hvigorfile.ts b/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..80e4ec5b81689f238c34614b167a0b9e9c83e8d9 --- /dev/null +++ b/entry/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..225946cb11a2c405c8dc81eea89c22f923556638 --- /dev/null +++ b/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/entry/src/main/ets/common/constants/CommonConstants.ets b/entry/src/main/ets/common/constants/CommonConstants.ets new file mode 100644 index 0000000000000000000000000000000000000000..a74b1a11d3bd0eec0a262ee42c25e3f935b1829d --- /dev/null +++ b/entry/src/main/ets/common/constants/CommonConstants.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { relationalStore } from '@kit.ArkData'; +import { AccountTable } from '../../viewmodel/ConstantsInterface'; + +export default class CommonConstants { + /** + * Rdb database config. + */ + static readonly STORE_CONFIG: relationalStore.StoreConfig = { + name: 'database.db', + securityLevel: relationalStore.SecurityLevel.S1 + }; + /** + * Account table config. + */ + static readonly ACCOUNT_TABLE: AccountTable = { + tableName: 'accountTable', + sqlCreate: 'CREATE TABLE IF NOT EXISTS accountTable(id INTEGER PRIMARY KEY AUTOINCREMENT, accountType INTEGER, ' + + 'typeText TEXT, amount INTEGER)', + columns: ['id', 'accountType', 'typeText', 'amount'] + }; + /** + * Search text of Search component. + */ + static readonly SEARCH_TEXT = '搜索'; + /** + * toast text of prompt component. + */ + static readonly TOAST_TEXT_1 = '账目类型不能为空'; + static readonly TOAST_TEXT_2 = '账目金额不为正整数'; + /** + * Component size. + */ + static readonly FULL_WIDTH = '100%'; + static readonly FULL_HEIGHT = '100%'; + static readonly DIALOG_HEIGHT = '55%'; + static readonly TABS_HEIGHT = '45%'; + static readonly MINIMUM_SIZE = 0; + static readonly FULL_SIZE = 1; + static readonly PROMPT_BOTTOM = '70vp'; + /** + * Component location. + */ + static readonly EDIT_POSITION_X = '80%'; + static readonly EDIT_POSITION_Y = '90%'; + static readonly DELETE_POSITION_X = '50%'; + static readonly DELETE_POSITION_Y = '90%'; + /** + * Log tag. + */ + static readonly RDB_TAG = '[Debug.Rdb]'; + static readonly TABLE_TAG = '[Debug.AccountTable]'; + static readonly INDEX_TAG = '[Debug.Index]'; +} \ No newline at end of file diff --git a/entry/src/main/ets/common/database/Rdb.ets b/entry/src/main/ets/common/database/Rdb.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e075248ea89fadd04e063c79265902558926b16 --- /dev/null +++ b/entry/src/main/ets/common/database/Rdb.ets @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { relationalStore } from '@kit.ArkData'; +import CommonConstants from '../constants/CommonConstants'; +import Logger from '../utils/Logger'; + +export default class Rdb { + private rdbStore: relationalStore.RdbStore | null = null; + private tableName: string; + private sqlCreateTable: string; + private columns: Array; + + constructor(tableName: string, sqlCreateTable: string, columns: Array) { + this.tableName = tableName; + this.sqlCreateTable = sqlCreateTable; + this.columns = columns; + } + + getRdbStore(callback: Function = () => { + }) { + if (!callback || typeof callback === 'undefined' || callback === undefined) { + Logger.info(CommonConstants.RDB_TAG, 'getRdbStore() has no callback!'); + return; + } + if (this.rdbStore !== null) { + Logger.info(CommonConstants.RDB_TAG, 'The rdbStore exists.'); + callback(); + return + } + let context: Context = getContext(this) as Context; + relationalStore.getRdbStore(context, CommonConstants.STORE_CONFIG, (err, rdb) => { + if (err) { + Logger.error(CommonConstants.RDB_TAG, `gerRdbStore() failed, err: ${err}`); + return; + } + this.rdbStore = rdb; + this.rdbStore.executeSql(this.sqlCreateTable); + Logger.info(CommonConstants.RDB_TAG, 'getRdbStore() finished.'); + callback(); + }); + } + + insertData(data: relationalStore.ValuesBucket, callback: Function = () => { + }) { + if (!callback || typeof callback === 'undefined' || callback === undefined) { + Logger.info(CommonConstants.RDB_TAG, 'insertData() has no callback!'); + return; + } + let resFlag: boolean = false; + const valueBucket: relationalStore.ValuesBucket = data; + if (this.rdbStore) { + this.rdbStore.insert(this.tableName, valueBucket, (err, ret) => { + if (err) { + Logger.error(CommonConstants.RDB_TAG, `insertData() failed, err: ${err}`); + callback(resFlag); + return; + } + Logger.info(CommonConstants.RDB_TAG, `insertData() finished: ${ret}`); + callback(ret); + }); + } + } + + deleteData(predicates: relationalStore.RdbPredicates, callback: Function = () => { + }) { + if (!callback || typeof callback === 'undefined' || callback === undefined) { + Logger.info(CommonConstants.RDB_TAG, 'deleteData() has no callback!'); + return; + } + let resFlag: boolean = false; + if (this.rdbStore) { + this.rdbStore.delete(predicates, (err, ret) => { + if (err) { + Logger.error(CommonConstants.RDB_TAG, `deleteData() failed, err: ${err}`); + callback(resFlag); + return; + } + Logger.info(CommonConstants.RDB_TAG, `deleteData() finished: ${ret}`); + callback(!resFlag); + }); + } + } + + updateData(predicates: relationalStore.RdbPredicates, data: relationalStore.ValuesBucket, callback: Function = () => { + }) { + if (!callback || typeof callback === 'undefined' || callback === undefined) { + Logger.info(CommonConstants.RDB_TAG, 'updateDate() has no callback!'); + return; + } + let resFlag: boolean = false; + const valueBucket: relationalStore.ValuesBucket = data; + if (this.rdbStore) { + this.rdbStore.update(valueBucket, predicates, (err, ret) => { + if (err) { + Logger.error(CommonConstants.RDB_TAG, `updateData() failed, err: ${err}`); + callback(resFlag); + return; + } + Logger.info(CommonConstants.RDB_TAG, `updateData() finished: ${ret}`); + callback(!resFlag); + }); + } + } + + query(predicates: relationalStore.RdbPredicates, callback: Function = () => { + }) { + if (!callback || typeof callback === 'undefined' || callback === undefined) { + Logger.info(CommonConstants.RDB_TAG, 'query() has no callback!'); + return; + } + if (this.rdbStore) { + this.rdbStore.query(predicates, this.columns, (err, resultSet) => { + if (err) { + Logger.error(CommonConstants.RDB_TAG, `query() failed, err: ${err}`); + return; + } + Logger.info(CommonConstants.RDB_TAG, 'query() finished.'); + callback(resultSet); + resultSet.close(); + }); + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/common/database/tables/AccountTable.ets b/entry/src/main/ets/common/database/tables/AccountTable.ets new file mode 100644 index 0000000000000000000000000000000000000000..f2aa1a174fdf5b79f3e6f7057728c28f728f48b7 --- /dev/null +++ b/entry/src/main/ets/common/database/tables/AccountTable.ets @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { relationalStore } from '@kit.ArkData'; +import AccountData from '../../../viewmodel/AccountData'; +import CommonConstants from '../../constants/CommonConstants'; +import Rdb from '../Rdb'; + +export default class AccountTable { + private accountTable = new Rdb(CommonConstants.ACCOUNT_TABLE.tableName, CommonConstants.ACCOUNT_TABLE.sqlCreate, + CommonConstants.ACCOUNT_TABLE.columns); + + constructor(callback: Function = () => { + }) { + this.accountTable.getRdbStore(callback); + } + + getRdbStore(callback: Function = () => { + }) { + this.accountTable.getRdbStore(callback); + } + + insertData(account: AccountData, callback: Function) { + const valueBucket: relationalStore.ValuesBucket = generateBucket(account); + this.accountTable.insertData(valueBucket, callback); + } + + deleteData(account: AccountData, callback: Function) { + let predicates = new relationalStore.RdbPredicates(CommonConstants.ACCOUNT_TABLE.tableName); + predicates.equalTo('id', account.id); + this.accountTable.deleteData(predicates, callback); + } + + updateData(account: AccountData, callback: Function) { + const valueBucket: relationalStore.ValuesBucket = generateBucket(account); + let predicates = new relationalStore.RdbPredicates(CommonConstants.ACCOUNT_TABLE.tableName); + predicates.equalTo('id', account.id); + this.accountTable.updateData(predicates, valueBucket, callback); + } + + query(amount: number, callback: Function, isAll: boolean = true) { + let predicates = new relationalStore.RdbPredicates(CommonConstants.ACCOUNT_TABLE.tableName); + if (!isAll) { + predicates.equalTo('amount', amount); + } + this.accountTable.query(predicates, (resultSet: relationalStore.ResultSet) => { + let count: number = resultSet.rowCount; + if (count === 0 || typeof count === 'string') { + console.log(`${CommonConstants.TABLE_TAG}` + 'Query no results!'); + callback([]); + } else { + resultSet.goToFirstRow(); + const result: AccountData[] = []; + for (let i = 0; i < count; i++) { + let tmp: AccountData = { + id: 0, accountType: 0, typeText: '', amount: 0 + }; + tmp.id = resultSet.getDouble(resultSet.getColumnIndex('id')); + tmp.accountType = resultSet.getDouble(resultSet.getColumnIndex('accountType')); + tmp.typeText = resultSet.getString(resultSet.getColumnIndex('typeText')); + tmp.amount = resultSet.getDouble(resultSet.getColumnIndex('amount')); + result[i] = tmp; + resultSet.goToNextRow(); + } + callback(result); + } + }); + } +} + +function generateBucket(account: AccountData): relationalStore.ValuesBucket { + let obj: relationalStore.ValuesBucket = {}; + obj.accountType = account.accountType; + obj.typeText = account.typeText; + obj.amount = account.amount; + return obj; +} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/Logger.ets b/entry/src/main/ets/common/utils/Logger.ets new file mode 100644 index 0000000000000000000000000000000000000000..480a05d25aab5d6d43247a033c415c750792c9aa --- /dev/null +++ b/entry/src/main/ets/common/utils/Logger.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + /** + * constructor. + * + * @param Prefix Identifies the log tag. + * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF. + */ + constructor(prefix: string = 'MyApp', domain: number = 0xFF00) { + this.prefix = prefix; + this.domain = domain; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + +export default new Logger('Rdb', 0xFF00) \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f7701e07e4897207ee760e02fa1a53d7a28d109 --- /dev/null +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class entryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); + } + + onDestroy(): void | Promise { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/MainPage', (err, data) => { + if (err.code) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/MainPage.ets b/entry/src/main/ets/pages/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..427f777e19e7f1e8906e7f3ccf5858592c7f4f62 --- /dev/null +++ b/entry/src/main/ets/pages/MainPage.ets @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AccountTable from '../common/database/tables/AccountTable'; +import AccountData from '../viewmodel/AccountData'; +import CommonConstants from '../common/constants/CommonConstants'; +import { DialogComponent } from '../view/DialogComponent'; +import { ImageList } from '../viewmodel/AccountList'; +import Logger from '../common/utils/Logger'; + +@Entry +@Component +struct MainPage { + @State accounts: Array = []; + @State searchText: string = ''; + @State isEdit: boolean = false; + @State isInsert: boolean = false; + @State newAccount: AccountData = { id: 0, accountType: 0, typeText: '', amount: 0 }; + @State index: number = -1; + private AccountTable = new AccountTable(() => {}); + private deleteList: Array = []; + searchController: SearchController = new SearchController(); + dialogController: CustomDialogController = new CustomDialogController({ + builder: DialogComponent({ + isInsert: $isInsert, + newAccount: $newAccount, + confirm: (isInsert: boolean, newAccount: AccountData) => this.accept(isInsert, newAccount) + }), + customStyle: true, + alignment: DialogAlignment.Bottom + }); + + accept(isInsert: boolean, newAccount: AccountData): void { + if (isInsert) { + Logger.info(`${CommonConstants.INDEX_TAG}`, `The account inserted is: ${JSON.stringify(newAccount)}`); + this.AccountTable.insertData(newAccount, (id: number) => { + newAccount.id = id; + this.accounts.push(newAccount); + }); + } else { + this.AccountTable.updateData(newAccount, () => { + }); + let list = this.accounts; + this.accounts = []; + list[this.index] = newAccount; + this.accounts = list; + this.index = -1; + } + } + + aboutToAppear() { + this.AccountTable.getRdbStore(() => { + this.AccountTable.query(0, (result: AccountData[]) => { + this.accounts = result; + }, true); + }); + } + + selectListItem(item: AccountData) { + this.isInsert = false; + this.index = this.accounts.indexOf(item); + this.newAccount = { + id: item.id, + accountType: item.accountType, + typeText: item.typeText, + amount: item.amount + }; + } + + deleteListItem() { + for (let i = 0; i < this.deleteList.length; i++) { + let index = this.accounts.indexOf(this.deleteList[i]); + this.accounts.splice(index, 1); + this.AccountTable.deleteData(this.deleteList[i], () => { + }); + } + this.deleteList = []; + this.isEdit = false; + } + + build() { + Stack() { + Column() { + Row() { + Text($r('app.string.MainAbility_label')) + .height($r('app.float.component_size_SP')) + .fontSize($r('app.float.font_size_L')) + .margin({ left: $r('app.float.font_size_L') }) + + Image($rawfile('ic_public_edit.svg')) + .width($r('app.float.component_size_S')) + .aspectRatio(CommonConstants.FULL_SIZE) + .margin({ right: $r('app.float.font_size_L') }) + .onClick(() => { + this.isEdit = true; + }) + } + .width(CommonConstants.FULL_WIDTH) + .justifyContent(FlexAlign.SpaceBetween) + .margin({ top: $r('app.float.edge_size_M'), bottom: $r('app.float.edge_size_MM') }) + + Row() { + Search({ + value: this.searchText, + placeholder: CommonConstants.SEARCH_TEXT, + controller: this.searchController + }) + .width(CommonConstants.FULL_WIDTH) + .borderRadius($r('app.float.radius_size_M')) + .borderWidth($r('app.float.border_size_S')) + .borderColor($r('app.color.border_color')) + .placeholderFont({ size: $r('app.float.font_size_M') }) + .textFont({ size: $r('app.float.font_size_M') }) + .backgroundColor(Color.White) + .onChange((searchValue: string) => { + this.searchText = searchValue; + }) + .onSubmit((searchValue: string) => { + if (searchValue === '') { + this.AccountTable.query(0, (result: AccountData[]) => { + this.accounts = result; + }, true); + } else { + this.AccountTable.query(Number(searchValue), (result: AccountData[]) => { + this.accounts = result; + }, false); + } + }) + } + .width(CommonConstants.FULL_WIDTH) + .padding({ left: $r('app.float.edge_size_M'), right: $r('app.float.edge_size_M') }) + .margin({ top: $r('app.float.edge_size_S'), bottom: $r('app.float.edge_size_S') }) + + Row() { + List({ space: CommonConstants.FULL_SIZE }) { + ForEach(this.accounts, (item: AccountData) => { + ListItem() { + Row() { + Image(ImageList[item.typeText]) + .width($r('app.float.component_size_M')) + .aspectRatio(CommonConstants.FULL_SIZE) + .margin({ right: $r('app.float.edge_size_MP') }) + + Text(item.typeText) + .height($r('app.float.component_size_SM')) + .fontSize($r('app.float.font_size_M')) + + Blank() + .layoutWeight(1) + + if (!this.isEdit) { + Text(item.accountType === 0 ? '-' + item.amount.toString() : '+' + item.amount.toString()) + .fontSize($r('app.float.font_size_M')) + .fontColor(item.accountType === 0 ? $r('app.color.pay_color') : $r('app.color.main_color')) + .align(Alignment.End) + .flexGrow(CommonConstants.FULL_SIZE) + } else { + Row() { + Toggle({ type: ToggleType.Checkbox }) + .onChange((isOn) => { + if (isOn) { + this.deleteList.push(item); + } else { + let index = this.deleteList.indexOf(item); + this.deleteList.splice(index, 1); + } + }) + } + .align(Alignment.End) + .flexGrow(CommonConstants.FULL_SIZE) + .justifyContent(FlexAlign.End) + } + + } + .width(CommonConstants.FULL_WIDTH) + .padding({ left: $r('app.float.edge_size_M'), right: $r('app.float.edge_size_M') }) + } + .width(CommonConstants.FULL_WIDTH) + .height($r('app.float.component_size_LM')) + .onClick(() => { + this.selectListItem(item); + this.dialogController.open(); + }) + }) + } + .width(CommonConstants.FULL_WIDTH) + .borderRadius($r('app.float.radius_size_L')) + .backgroundColor(Color.White) + } + .width(CommonConstants.FULL_WIDTH) + .padding({ left: $r('app.float.edge_size_M'), right: $r('app.float.edge_size_M') }) + .margin({ top: $r('app.float.edge_size_SM') }) + + } + .width(CommonConstants.FULL_WIDTH) + .height(CommonConstants.FULL_HEIGHT) + + if (!this.isEdit) { + Button() { + Image($rawfile('add.png')) + } + .width($r('app.float.component_size_MP')) + .height($r('app.float.component_size_MP')) + .position({ x: CommonConstants.EDIT_POSITION_X, y: CommonConstants.EDIT_POSITION_Y }) + .onClick(() => { + this.isInsert = true; + this.newAccount = { id: 0, accountType: 0, typeText: '', amount: 0 }; + this.dialogController.open(); + }) + } + + if (this.isEdit) { + Button() { + Image($rawfile('delete.png')) + } + .width($r('app.float.component_size_MP')) + .height($r('app.float.component_size_MP')) + .backgroundColor($r('app.color.background_color')) + .markAnchor({ x: $r('app.float.mark_anchor'), y: CommonConstants.MINIMUM_SIZE }) + .position({ x: CommonConstants.DELETE_POSITION_X, y: CommonConstants.DELETE_POSITION_Y }) + .onClick(() => { + this.deleteListItem(); + }) + } + } + .width(CommonConstants.FULL_WIDTH) + .height(CommonConstants.FULL_HEIGHT) + .backgroundColor($r('app.color.background_color')) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/view/DialogComponent.ets b/entry/src/main/ets/view/DialogComponent.ets new file mode 100644 index 0000000000000000000000000000000000000000..d97102f617165e2ba90eca6cf6d9cd64daea41e7 --- /dev/null +++ b/entry/src/main/ets/view/DialogComponent.ets @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { promptAction } from '@kit.ArkUI'; +import AccountData from '../viewmodel/AccountData'; +import AccountItem from '../viewmodel/AccountItem'; +import CommonConstants from '../common/constants/CommonConstants'; +import { PayList, EarnList } from '../viewmodel/AccountList'; + +@CustomDialog +export struct DialogComponent { + controller?: CustomDialogController; + @Link isInsert: boolean; + @Link newAccount: AccountData; + confirm?: (isInsert: boolean, newAccount: AccountData) => void; + private scroller: Scroller = new Scroller(); + private inputAmount = ''; + @State payList: Array = PayList; + @State earnList: Array = EarnList; + @State bgColor: string = ''; + @State curIndex: number = 0; + @State curType: string = ''; + + @Builder + TabBuilder(index: number) { + Column() { + Text(index === 0 ? $r('app.string.pay_text') : $r('app.string.income_text')) + .fontSize($r('app.float.font_size_M')) + .fontColor(this.curIndex === index ? $r('app.color.main_color') : Color.Gray) + } + .width($r('app.float.component_size_MP')) + .padding({ top: $r('app.float.edge_size_LM'), bottom: $r('app.float.edge_size_S') }) + .margin({ bottom: $r('app.float.edge_size_S') }) + .border({ + width: { bottom: this.curIndex === index ? $r('app.float.border_size_M') : '' }, + color: this.curIndex === index ? $r('app.color.main_color') : Color.White + }) + } + + aboutToAppear() { + this.inputAmount = this.newAccount.amount.toString(); + this.curIndex = this.newAccount.accountType; + this.curType = this.newAccount.typeText; + } + + selectAccount(item: AccountItem) { + this.newAccount.accountType = item.accountType; + this.newAccount.typeText = item.typeText; + this.curType = item.typeText; + } + + build() { + Column() { + Image($rawfile('half.png')) + .width($r('app.float.component_size_L')) + .height($r('app.float.component_size_S')) + .onClick(() => { + this.controller?.close(); + }) + + Tabs({ barPosition: BarPosition.Start, index: this.curIndex }) { + TabContent() { + Scroll(this.scroller) { + Row() { + ForEach(this.payList, (item: AccountItem) => { + Column() { + Image(this.curType === item.typeText ? item.iconSelected : item.icon) + .width($r('app.float.image_size')) + .aspectRatio(CommonConstants.FULL_SIZE) + + Text(item.typeText) + .fontSize($r('app.float.font_size_S')) + .fontColor(this.curType === item.typeText ? Color.White : $r('app.color.main_color')) + .margin({ top: $r('app.float.edge_size_S') }) + } + .width($r('app.float.component_size_LP')) + .aspectRatio(CommonConstants.FULL_SIZE) + .padding({ top: $r('app.float.edge_size_M') }) + .margin({ top: $r('app.float.edge_size_MP'), left: $r('app.float.edge_size_M') }) + .align(Alignment.TopStart) + .backgroundColor(this.curType === item.typeText ? $r('app.color.main_color') : $r('app.color.background_color')) + .borderRadius($r('app.float.radius_size_S')) + .onClick(() => { + this.selectAccount(item); + }) + }) + } + } + .scrollable(ScrollDirection.Horizontal) + .scrollBar(BarState.Off) + } + .tabBar(this.TabBuilder(0)) + .margin({ bottom: $r('app.float.edge_size_LP') }) + + TabContent() { + Scroll(this.scroller) { + Row() { + ForEach(this.earnList, (item: AccountItem) => { + Column() { + Image(this.curType === item.typeText ? item.iconSelected : item.icon) + .width($r('app.float.image_size')) + .aspectRatio(CommonConstants.FULL_SIZE) + + Text(item.typeText) + .fontSize($r('app.float.font_size_S')) + .fontColor(this.curType === item.typeText ? Color.White : $r('app.color.main_color')) + .margin({ top: $r('app.float.edge_size_S') }) + } + .width($r('app.float.component_size_LP')) + .aspectRatio(CommonConstants.FULL_SIZE) + .padding({ top: $r('app.float.edge_size_M') }) + .margin({ top: $r('app.float.edge_size_MP'), left: $r('app.float.edge_size_M') }) + .align(Alignment.TopStart) + .backgroundColor(this.curType === item.typeText ? $r('app.color.main_color') : $r('app.color.background_color')) + .borderRadius($r('app.float.radius_size_S')) + .onClick(() => { + this.selectAccount(item); + }) + }) + } + } + .scrollable(ScrollDirection.Horizontal) + .scrollBar(BarState.Off) + } + .tabBar(this.TabBuilder(1)) + .margin({ bottom: $r('app.float.edge_size_LP') }) + } + .width(CommonConstants.FULL_WIDTH) + .height(CommonConstants.TABS_HEIGHT) + .vertical(false) + .barMode(BarMode.Fixed) + .onChange((index) => { + this.curIndex = index; + }) + + Column() { + Text($r('app.string.count_text')) + .width(CommonConstants.FULL_WIDTH) + .fontSize($r('app.float.font_size_MP')) + .fontColor(Color.Black) + + Column() { + TextInput({ + placeholder: $r('app.string.input_text'), + text: this.newAccount.amount === 0 ? this.inputAmount : this.newAccount.amount.toString() + }) + .padding({ + left: CommonConstants.MINIMUM_SIZE, + top: CommonConstants.MINIMUM_SIZE, + bottom: CommonConstants.MINIMUM_SIZE + }) + .borderRadius(CommonConstants.MINIMUM_SIZE) + .backgroundColor(Color.White) + .type(InputType.Number) + .onChange((value: string) => { + this.inputAmount = value; + }) + } + .height($r('app.float.component_size_MP')) + .padding({ top: $r('app.float.edge_size_MPM'), bottom: $r('app.float.edge_size_MM') }) + .borderWidth({ bottom: CommonConstants.FULL_SIZE }) + .borderColor($r('app.color.border_color')) + } + .width(CommonConstants.FULL_WIDTH) + .padding({ left: $r('app.float.edge_size_M'), right: $r('app.float.edge_size_M') }) + + Column() { + Button() { + Text($r('app.string.confirm_text')) + .fontSize($r('app.float.font_size_M')) + .fontColor(Color.White) + } + .width(CommonConstants.FULL_WIDTH) + .height($r('app.float.component_size_M')) + .onClick(() => { + if (this.newAccount.typeText === '' || this.curIndex !== this.newAccount.accountType) { + promptAction.showToast({ message: CommonConstants.TOAST_TEXT_1, bottom: CommonConstants.PROMPT_BOTTOM }); + } else { + let regex: RegExp = new RegExp('[1-9][0-9]*'); + let matchValue: Array | null = this.inputAmount.match(regex); + if (matchValue !== null && matchValue[0] === this.inputAmount) { + this.newAccount.amount = Number(this.inputAmount); + this.confirm && this.confirm(this.isInsert, this.newAccount); + this.controller?.close(); + } else { + promptAction.showToast({ message: CommonConstants.TOAST_TEXT_2, bottom: CommonConstants.PROMPT_BOTTOM }); + } + } + }) + } + .layoutWeight(CommonConstants.FULL_SIZE) + .padding({ + bottom: $r('app.float.font_size_L'), + left: $r('app.float.font_size_L'), + right: $r('app.float.font_size_L') + }) + .justifyContent(FlexAlign.End) + } + .width(CommonConstants.FULL_WIDTH) + .height(CommonConstants.DIALOG_HEIGHT) + .borderRadius({ topLeft: $r('app.float.font_size_L'), topRight: $r('app.float.font_size_L') }) + .backgroundColor(Color.White) + .align(Alignment.BottomEnd) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/viewmodel/AccountData.ets b/entry/src/main/ets/viewmodel/AccountData.ets new file mode 100644 index 0000000000000000000000000000000000000000..79870cf2afea71ff80ee22a3f72a91fb1a59f9d6 --- /dev/null +++ b/entry/src/main/ets/viewmodel/AccountData.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class AccountData { + id: number = -1; + accountType: number = 0; + typeText: string = ''; + amount: number = 0; +} \ No newline at end of file diff --git a/entry/src/main/ets/viewmodel/AccountItem.ets b/entry/src/main/ets/viewmodel/AccountItem.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7a195d62621856683e1224912399a3f4ca11b48 --- /dev/null +++ b/entry/src/main/ets/viewmodel/AccountItem.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default interface AccountItem { + icon: Resource; + iconSelected: Resource; + accountType: number; + typeText: string; +} \ No newline at end of file diff --git a/entry/src/main/ets/viewmodel/AccountList.ets b/entry/src/main/ets/viewmodel/AccountList.ets new file mode 100644 index 0000000000000000000000000000000000000000..16c694d0efe4e53dd88992954dbb7864d840cc49 --- /dev/null +++ b/entry/src/main/ets/viewmodel/AccountList.ets @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AccountItem from '../viewmodel/AccountItem'; + +export const PayList: Array = [ + { + icon: $rawfile('foods.png'), + iconSelected: $rawfile('foods_selected.png'), + accountType: 0, + typeText: '吃饭' + }, + { + icon: $rawfile('snacks.png'), + iconSelected: $rawfile('snacks_selected.png'), + accountType: 0, + typeText: '零食' + }, + { + icon: $rawfile('fuel.png'), + iconSelected: $rawfile('fuel_selected.png'), + accountType: 0, + typeText: '汽车加油' + }, + { + icon: $rawfile('travel.png'), + iconSelected: $rawfile('travel_selected.png'), + accountType: 0, + typeText: '旅游' + }, + { + icon: $rawfile('games.png'), + iconSelected: $rawfile('games_selected.png'), + accountType: 0, + typeText: '娱乐' + }, + { + icon: $rawfile('pets.png'), + iconSelected: $rawfile('pets_selected.png'), + accountType: 0, + typeText: '宠物' + } +] + +export const EarnList: Array = [ + { + icon: $rawfile('income.png'), + iconSelected: $rawfile('income_selected.png'), + accountType: 1, + typeText: '工作收入' + }, + { + icon: $rawfile('invest.png'), + iconSelected: $rawfile('invest_selected.png'), + accountType: 1, + typeText: '投资' + } +] + +export const ImageList: Record = { + '吃饭': $rawfile('foods.png'), + '零食': $rawfile('snacks.png'), + '汽车加油': $rawfile('fuel.png'), + '旅游': $rawfile('travel.png'), + '娱乐': $rawfile('games.png'), + '宠物': $rawfile('pets.png'), + '工作收入': $rawfile('income.png'), + '投资': $rawfile('invest.png') +} \ No newline at end of file diff --git a/entry/src/main/ets/viewmodel/ConstantsInterface.ets b/entry/src/main/ets/viewmodel/ConstantsInterface.ets new file mode 100644 index 0000000000000000000000000000000000000000..5789ebb75b30b8543499326ccd5fde6b2312bd5c --- /dev/null +++ b/entry/src/main/ets/viewmodel/ConstantsInterface.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License,Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export interface AccountTable { + tableName: string; + sqlCreate: string; + columns: string[]; +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bf66fbd5498f44b3ddfbfb2b2a9ccac8a7bb2b63 --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,37 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:entry_desc", + "mainElement": "entryAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..c5f4bfbbce3c85dc3fd396293b654fc3771aaeab --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,24 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + }, + { + "name": "background_color", + "value": "#FFF1F3F5" + }, + { + "name": "main_color", + "value": "#FF007DFF" + }, + { + "name": "pay_color", + "value": "#FFE84826" + }, + { + "name": "border_color", + "value": "#33182431" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/pixel.json b/entry/src/main/resources/base/element/pixel.json new file mode 100644 index 0000000000000000000000000000000000000000..943ed37b31a7b7160ee86e1b48217dd723da0365 --- /dev/null +++ b/entry/src/main/resources/base/element/pixel.json @@ -0,0 +1,116 @@ +{ + "float": [ + { + "name": "font_size_S", + "value": "12vp" + }, + { + "name": "font_size_M", + "value": "16vp" + }, + { + "name": "font_size_MP", + "value": "20vp" + }, + { + "name": "font_size_L", + "value": "24vp" + }, + { + "name": "image_size", + "value": "40vp" + }, + { + "name": "component_size_SM", + "value": "22vp" + }, + { + "name": "component_size_S", + "value": "24vp" + }, + { + "name": "component_size_SP", + "value": "33vp" + }, + { + "name": "component_size_M", + "value": "40vp" + }, + { + "name": "component_size_MP", + "value": "48vp" + }, + { + "name": "component_size_LM", + "value": "56vp" + }, + { + "name": "component_size_L", + "value": "64vp" + }, + { + "name": "component_size_LP", + "value": "86vp" + }, + { + "name": "edge_size_SM", + "value": "4vp" + }, + { + "name": "edge_size_S", + "value": "8vp" + }, + { + "name": "edge_size_MM", + "value": "11vp" + }, + { + "name": "edge_size_M", + "value": "12vp" + }, + { + "name": "edge_size_MPM", + "value": "15vp" + }, + { + "name": "edge_size_MP", + "value": "16vp" + }, + { + "name": "edge_size_LM", + "value": "17vp" + }, + { + "name": "edge_size_L", + "value": "24vp" + }, + { + "name": "edge_size_LP", + "value": "36vp" + }, + { + "name": "radius_size_S", + "value": "16vp" + }, + { + "name": "radius_size_M", + "value": "20vp" + }, + { + "name": "radius_size_L", + "value": "24vp" + }, + { + "name": "border_size_S", + "value": "1.5vp" + }, + { + "name": "border_size_M", + "value": "2vp" + }, + { + "name": "mark_anchor", + "value": "24vp" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0e9596cca02dc80fe9546053c4a9e622a35c6adb --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "关系型数据库" + }, + { + "name": "edit_text", + "value": "编辑" + }, + { + "name": "pay_text", + "value": "支出" + }, + { + "name": "income_text", + "value": "收入" + }, + { + "name": "count_text", + "value": "金额" + }, + { + "name": "input_text", + "value": "请输入金额" + }, + { + "name": "confirm_text", + "value": "确定" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ diff --git a/entry/src/main/resources/base/media/icon1.png b/entry/src/main/resources/base/media/icon1.png new file mode 100644 index 0000000000000000000000000000000000000000..8f36e14e0b413fbe61865feb0dba5f1c49239626 Binary files /dev/null and b/entry/src/main/resources/base/media/icon1.png differ diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..f4241ef2f72e78047b4c449d92bd1a92accc39fb --- /dev/null +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/MainPage" + ] +} diff --git a/entry/src/main/resources/rawfile/add.png b/entry/src/main/resources/rawfile/add.png new file mode 100644 index 0000000000000000000000000000000000000000..98b9bd0756b7454a1ff33eb3170025b296ce15a6 Binary files /dev/null and b/entry/src/main/resources/rawfile/add.png differ diff --git a/entry/src/main/resources/rawfile/delete.png b/entry/src/main/resources/rawfile/delete.png new file mode 100644 index 0000000000000000000000000000000000000000..15f403e0a9d648a8922858f838766c11c46d9cf0 Binary files /dev/null and b/entry/src/main/resources/rawfile/delete.png differ diff --git a/entry/src/main/resources/rawfile/foods.png b/entry/src/main/resources/rawfile/foods.png new file mode 100644 index 0000000000000000000000000000000000000000..68fc0530e291b85a3e1541fba7d749220f3f6da2 Binary files /dev/null and b/entry/src/main/resources/rawfile/foods.png differ diff --git a/entry/src/main/resources/rawfile/foods_selected.png b/entry/src/main/resources/rawfile/foods_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..b09ed6d8628b6d06dd90925b1ecdc08a30e9e95b Binary files /dev/null and b/entry/src/main/resources/rawfile/foods_selected.png differ diff --git a/entry/src/main/resources/rawfile/fuel.png b/entry/src/main/resources/rawfile/fuel.png new file mode 100644 index 0000000000000000000000000000000000000000..83a761797e8f6d168cc37a4c6ac1e4244d989d55 Binary files /dev/null and b/entry/src/main/resources/rawfile/fuel.png differ diff --git a/entry/src/main/resources/rawfile/fuel_selected.png b/entry/src/main/resources/rawfile/fuel_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..e93b0a0d2f98995a759facb8a70b64523b42dbe1 Binary files /dev/null and b/entry/src/main/resources/rawfile/fuel_selected.png differ diff --git a/entry/src/main/resources/rawfile/games.png b/entry/src/main/resources/rawfile/games.png new file mode 100644 index 0000000000000000000000000000000000000000..4edfe312e87c700fbcf3bfdbe4e27b0680c845f8 Binary files /dev/null and b/entry/src/main/resources/rawfile/games.png differ diff --git a/entry/src/main/resources/rawfile/games_selected.png b/entry/src/main/resources/rawfile/games_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..f7d4569d74d1b6cc33347789440e91cc9ad716f3 Binary files /dev/null and b/entry/src/main/resources/rawfile/games_selected.png differ diff --git a/entry/src/main/resources/rawfile/half.png b/entry/src/main/resources/rawfile/half.png new file mode 100644 index 0000000000000000000000000000000000000000..f461b8bb567e42d4753f970165e29e4438c87421 Binary files /dev/null and b/entry/src/main/resources/rawfile/half.png differ diff --git a/entry/src/main/resources/rawfile/ic_public_edit.svg b/entry/src/main/resources/rawfile/ic_public_edit.svg new file mode 100644 index 0000000000000000000000000000000000000000..b007228d46de9ff5d67038180723c21d77162a04 --- /dev/null +++ b/entry/src/main/resources/rawfile/ic_public_edit.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_edit + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/ic_public_input_search.svg b/entry/src/main/resources/rawfile/ic_public_input_search.svg new file mode 100644 index 0000000000000000000000000000000000000000..c71cd84a4f238f79f71a71330fa5c5c4faaca50a --- /dev/null +++ b/entry/src/main/resources/rawfile/ic_public_input_search.svg @@ -0,0 +1,18 @@ + + + Public/ic_public_input_search + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/icon.png b/entry/src/main/resources/rawfile/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/rawfile/icon.png differ diff --git a/entry/src/main/resources/rawfile/icon1.png b/entry/src/main/resources/rawfile/icon1.png new file mode 100644 index 0000000000000000000000000000000000000000..8f36e14e0b413fbe61865feb0dba5f1c49239626 Binary files /dev/null and b/entry/src/main/resources/rawfile/icon1.png differ diff --git a/entry/src/main/resources/rawfile/income.png b/entry/src/main/resources/rawfile/income.png new file mode 100644 index 0000000000000000000000000000000000000000..0d086841f01778eba8a71613e76ba96fa0772b12 Binary files /dev/null and b/entry/src/main/resources/rawfile/income.png differ diff --git a/entry/src/main/resources/rawfile/income_selected.png b/entry/src/main/resources/rawfile/income_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..5cb2674ad727a3609f8aa23ecaa99ad001873875 Binary files /dev/null and b/entry/src/main/resources/rawfile/income_selected.png differ diff --git a/entry/src/main/resources/rawfile/invest.png b/entry/src/main/resources/rawfile/invest.png new file mode 100644 index 0000000000000000000000000000000000000000..e3565e6c650857e3d1f5b1343d9b1c7117880101 Binary files /dev/null and b/entry/src/main/resources/rawfile/invest.png differ diff --git a/entry/src/main/resources/rawfile/invest_selected.png b/entry/src/main/resources/rawfile/invest_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..637c04368d7f8b31c84a47bd3063827f7166b89e Binary files /dev/null and b/entry/src/main/resources/rawfile/invest_selected.png differ diff --git a/entry/src/main/resources/rawfile/pets.png b/entry/src/main/resources/rawfile/pets.png new file mode 100644 index 0000000000000000000000000000000000000000..6cd092ce874844841873b893becf5d73abe0d28d Binary files /dev/null and b/entry/src/main/resources/rawfile/pets.png differ diff --git a/entry/src/main/resources/rawfile/pets_selected.png b/entry/src/main/resources/rawfile/pets_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..b964f5528929ed8c44265a42ddb0fd9a64fb6577 Binary files /dev/null and b/entry/src/main/resources/rawfile/pets_selected.png differ diff --git a/entry/src/main/resources/rawfile/snacks.png b/entry/src/main/resources/rawfile/snacks.png new file mode 100644 index 0000000000000000000000000000000000000000..51c53e10afd2f845ec1400552200d168bdc54222 Binary files /dev/null and b/entry/src/main/resources/rawfile/snacks.png differ diff --git a/entry/src/main/resources/rawfile/snacks_selected.png b/entry/src/main/resources/rawfile/snacks_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..662549ca6088b0c63c33ac0ce93a03b00b691f1e Binary files /dev/null and b/entry/src/main/resources/rawfile/snacks_selected.png differ diff --git a/entry/src/main/resources/rawfile/travel.png b/entry/src/main/resources/rawfile/travel.png new file mode 100644 index 0000000000000000000000000000000000000000..8a784e2de4d779b13080257f7e3f8da9e4fc57cb Binary files /dev/null and b/entry/src/main/resources/rawfile/travel.png differ diff --git a/entry/src/main/resources/rawfile/travel_selected.png b/entry/src/main/resources/rawfile/travel_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..7016109c9091c58c733ecdfd687b1c796d7a68ae Binary files /dev/null and b/entry/src/main/resources/rawfile/travel_selected.png differ diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..73bfab4e997c8d4aea53b22fdd7f10112b30987f --- /dev/null +++ b/hvigor/hvigor-config.json5 @@ -0,0 +1,17 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } +} \ No newline at end of file diff --git a/hvigorfile.ts b/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6478186902c0c1ad7c966a929c7d6b7d8ae7a9f3 --- /dev/null +++ b/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bd012417ecf0ed7ce8392fd4f8756ddc4196f372 --- /dev/null +++ b/oh-package.json5 @@ -0,0 +1,13 @@ +{ + "modelVersion": "5.0.0", + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.15" + }, + "author": "", + "name": "rdb", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git "a/screenshots/device/\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223.gif" "b/screenshots/device/\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223.gif" new file mode 100644 index 0000000000000000000000000000000000000000..694cd1ec58aa79dd93d0bfd5c06da3f41a2998a3 Binary files /dev/null and "b/screenshots/device/\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223.gif" differ