Compare commits

..

7 Commits

Author SHA1 Message Date
cheliangzhao
3765d2b6cf Feat: some todo ui 2023-10-07 17:55:41 +08:00
cheliangzhao
855412de3c 📝 Docs: add readme 2023-10-07 13:38:00 +08:00
cheliangzhao
b5c0263868 Feat: add database 2023-10-07 13:36:58 +08:00
clz
fae226f4fa 🐛 Bug: change index page 2023-09-30 22:11:39 +08:00
cheliangzhao
87fd13ff45 🔥 Prune: template project 2023-09-28 18:05:40 +08:00
clz
7fcc5d8950 Feat: can match 2023-09-25 23:20:38 +08:00
cheliangzhao
db3b628a14 Feat: finish cards game 2023-09-25 19:32:27 +08:00
48 changed files with 652 additions and 286 deletions

20
README.md Normal file
View File

@ -0,0 +1,20 @@
# Template
## database
注意事项
1. 由于`constructor()`函数不能异步,因此在其中调用`getRdbStore()`
函数时,不能保证新建对象后,数据库初始化完毕。那么此时如果调用`insert`等方法时,`RdbStore`可能还是`undefined`,导致数据库操作失败。
因此,只能使用回调来处理。
```typescript
aboutToAppear() {
this.todoTable.getRdbStore(async () => {
const res = await this.todoTable.query();
this.todoList = res;
})
}
```

View File

@ -5,13 +5,13 @@
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "C:\\Users\\Administrator\\.ohos\\config\\auto_debug_harmony-demo_com.example.myapplication_70086000144137060.cer",
"storePassword": "0000001B7D0C3655FB9772C4075AA8B911BF72A385223C9C6E31223CB2B7B4C8AFD5B33A57CFC7CC2A76E6",
"certpath": "C:\\Users\\Administrator\\.ohos\\config\\auto_debug_harmony4-template_com.example.myapplication_70086000144137060.cer",
"storePassword": "0000001BF0C7503EEB99D5360C10359536D3353B1F2C39787692D0526594DC53D8A9103366AB1B58CACBB6",
"keyAlias": "debugKey",
"keyPassword": "0000001BBEC8D2B369C85E907BDD68C151DEB7415B57223EA76BDB90DC4D8772B40C84EE3209ECF65DB1A8",
"profile": "C:\\Users\\Administrator\\.ohos\\config\\auto_debug_harmony-demo_com.example.myapplication_70086000144137060.p7b",
"keyPassword": "0000001BFE46D113BE907F9B0F067070188C870CD7DD7AF4E6CB9720F5CC73389CC6DE77567D43876B55FB",
"profile": "C:\\Users\\Administrator\\.ohos\\config\\auto_debug_harmony4-template_com.example.myapplication_70086000144137060.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "C:\\Users\\Administrator\\.ohos\\config\\auto_debug_harmony-demo_com.example.myapplication_70086000144137060.p12"
"storeFile": "C:\\Users\\Administrator\\.ohos\\config\\auto_debug_harmony4-template_com.example.myapplication_70086000144137060.p12"
}
}
],

View File

@ -0,0 +1,23 @@
import relationalStore from '@ohos.data.relationalStore'
export const DatabaseConfig = {
RDB_TAG: '[Debug.Rdb]',
STORE_CONFIG: {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
},
TODO_TABLE: {
tableName: 'todoTable',
sqlCreate: `CREATE TABLE IF NOT EXISTS todoTable(
id INTEGER PRIMARY KEY AUTOINCREMENT,
status INTEGER,
content TEXT
)`,
columns: ['id', 'status', 'content'],
update1to3: ``,
update2to3: ``,
},
}

View File

@ -0,0 +1,85 @@
import relationalStore from '@ohos.data.relationalStore';
import { Logger } from '../../utils/Logger';
import { DatabaseConfig } from '../config';
export default class Rdb {
private rdbStore: relationalStore.RdbStore = null;
private tableName: string;
private sqlCreateTable: string;
private columns: Array<string>;
constructor(tableName: string, sqlCreateTable: string, columns: Array<string>) {
this.tableName = tableName;
this.sqlCreateTable = sqlCreateTable;
this.columns = columns;
}
getRdbStore(callback) {
const context = getContext(this)
relationalStore.getRdbStore(context, DatabaseConfig.STORE_CONFIG, (err, store) => {
if (err) {
console.error('getRdbStore() failed, error: ' + err)
return
}
this.rdbStore = store;
console.info('getRdbStore() finished.');
callback(store)
})
}
async insertData(data) {
const valueBucket = data
try {
const rowId = await this.rdbStore.insert(this.tableName, valueBucket);
console.info("insertData() finished: ", rowId)
return rowId;
} catch (err) {
console.error('insertData() failed, err: ' + err)
}
}
async updateData(predicates, data) {
const valueBucket = data;
try {
const rows = await this.rdbStore.update(valueBucket, predicates);
console.info('updateData() finished: ' + rows);
return rows;
} catch (err) {
console.error('update() failed, err: ' + err);
}
}
async deleteData(predicates) {
try {
const rows = await this.rdbStore.delete(predicates);
console.info('deleteData() finished: ' + rows);
return rows;
} catch (err) {
console.error('deleteData() failed, err: ' + err);
}
}
async query(predicates, mapFunc: Function) {
try {
const resSet = await this.rdbStore.query(predicates, this.columns)
const resList = [];
while (resSet.goToNextRow()) {
const resKeys = this.columns;
const resItem = mapFunc(resKeys, resSet);
resList.push(resItem);
}
resSet.close()
return resList;
}
catch (err) {
console.error('query() failed, err: ', err);
}
}
}

View File

@ -0,0 +1,91 @@
import { TodoData } from '../../types/Todo'
import { DatabaseConfig } from '../../config'
import Rdb from '../Rdb'
import relationalStore from '@ohos.data.relationalStore'
export default class TodoTable {
private todoTable = new Rdb(
DatabaseConfig.TODO_TABLE.tableName,
DatabaseConfig.TODO_TABLE.sqlCreate,
DatabaseConfig.TODO_TABLE.columns
)
constructor(callback: Function = () => {
}) {
this.getRdbStore(callback)
}
getRdbStore(callback) {
// 假设当前数据库版本为3
this.todoTable.getRdbStore(store => {
// 当数据库创建时数据库版本默认为0
if (store.version == 0) {
store.executeSql(DatabaseConfig.TODO_TABLE.sqlCreate);
store.version = 3;
}
// 如果数据库版本不为0且和当前数据库的版本不匹配需要进行升降级操作
// 当数据库存在并假定版本为1时将其升级为2版本
if (store.version != 3 && store.version == 1) {
store.executeSql(DatabaseConfig.TODO_TABLE.update1to3);
store.version = 2;
}
// 当数据库存在并假定版本为2时将其升级为3版本
if (store.version != 3 && store.version == 2) {
store.executeSql(DatabaseConfig.TODO_TABLE.update2to3);
store.version = 3;
}
if (callback) callback()
})
}
async insertData(data: TodoData) {
return await this.todoTable.insertData(generateBucket(data));
}
async updateData(data: TodoData) {
const valueBucket = generateBucket(data)
const predicates = new relationalStore.RdbPredicates(DatabaseConfig.TODO_TABLE.tableName)
predicates.equalTo('id', data.id)
return await this.todoTable.updateData(predicates, valueBucket)
}
async deleteData(data: TodoData) {
const predicates = new relationalStore.RdbPredicates(DatabaseConfig.TODO_TABLE.tableName);
predicates.equalTo('id', data.id);
return await this.todoTable.deleteData(predicates);
}
async query(content: string = ''): Promise<TodoData[]> {
const predicates = new relationalStore.RdbPredicates(DatabaseConfig.TODO_TABLE.tableName)
if (content) predicates.contains('content', content)
else {
predicates.glob('content', '*')
}
return await this.todoTable.query(predicates, (_, resSet: relationalStore.ResultSet): TodoData => {
return {
id: resSet.getLong(resSet.getColumnIndex('id')),
status: resSet.getLong(resSet.getColumnIndex('status')),
content: resSet.getString(resSet.getColumnIndex('content')),
}
})
}
}
function generateBucket(account: TodoData) {
let obj = {};
DatabaseConfig.TODO_TABLE.columns.forEach((item) => {
if (item != 'id') {
obj[item] = account[item];
}
});
return obj;
}

View File

@ -0,0 +1,5 @@
export interface TodoData {
id: number,
status: number,
content: string,
}

View File

@ -1,3 +0,0 @@
export enum Constants {
SET_SIZE_STANDARD = 16
}

View File

@ -3,16 +3,12 @@ import hilog from '@ohos.hilog';
import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import window from '@ohos.window';
import PreferencesUtil from '../utils/PreferencesUtil';
import { Constants } from '../constants/CommonConstants';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
globalThis.abilityWant = want;
PreferencesUtil.createFontPreferences(this.context);
PreferencesUtil.saveDefaultFontSize(Constants.SET_SIZE_STANDARD)
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
@ -23,7 +19,7 @@ export default class EntryAbility extends UIAbility {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/HomePage', (err, data) => {
windowStage.loadContent('pages/TodoPage', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;

View File

@ -1,68 +0,0 @@
import PreferencesUtil from '../utils/PreferencesUtil';
import hilog from '@ohos.hilog';
import { Constants } from '../constants/CommonConstants';
import HomeViewModel from '../viewModel/HomeViewModel';
import router from '@ohos.router';
@Preview
@Entry
@Component
struct HomePage {
@State message: string = 'Hello World';
@State changeFontSize: number = Constants.SET_SIZE_STANDARD;
private settingList = HomeViewModel.initSettingData()
onPageShow() {
PreferencesUtil.getChangeFontSize().then((value) => {
this.changeFontSize = value;
hilog.info(0x0000, 'testTag', '%{public}s', 'Get the value of changeFontSize: ' + this.changeFontSize);
});
}
handleClick() {
router.pushUrl({ url: "pages/SetFontSizePage" })
}
@Builder
getListItems() {
Column() {
ForEach(this.settingList, (item) => {
Row() {
Image(item.settingImage)
.width(16)
.height(16)
.margin({ right: 4 })
Text(item.settingName)
.fontSize(this.changeFontSize)
}
.blockBackground(10)
.onClick(() => this.handleClick())
})
}
}
build() {
Column() {
Text("设置")
.fontSize(this.changeFontSize * 1.2)
.fontWeight(FontWeight.Bold)
.width('100%')
this.getListItems()
}
.backgroundColor($r('sys.color.ohos_id_color_sub_background'))
.height('100%')
.width('100%')
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
}
}
@Extend(Row)
function blockBackground(marginTop: string | number) {
.backgroundColor(Color.White)
.borderRadius(16)
.margin({ top: marginTop })
.padding({ top: 4, bottom: 4, left: 10, right: 10 })
.width('100%')
.height(40)
}

View File

@ -0,0 +1,17 @@
@Preview
@Entry
@Component
struct Index {
@State message: string = "This a Template Project"
build() {
Row() {
Text(this.message)
.fontSize(40)
.fontWeight(FontWeight.Bold)
}
.height('100%')
.width('100%')
.justifyContent(FlexAlign.Center)
}
}

View File

@ -1,79 +0,0 @@
import router from '@ohos.router'
import { Constants } from '../constants/CommonConstants';
import PreferencesUtil from '../utils/PreferencesUtil';
import hilog from '@ohos.hilog';
@Preview
@Entry
@Component
struct SetFontSizePage {
@State changeFontSize: number = Constants.SET_SIZE_STANDARD;
onPageShow() {
PreferencesUtil.getChangeFontSize().then((value) => {
this.changeFontSize = value;
hilog.info(0x0000, 'testTag', '%{public}s', 'Get the value of changeFontSize: ' + this.changeFontSize);
});
}
handleBack() {
router.back()
}
@Builder
setChat() {
Column() {
ForEach([1, 1, 1, 1,], (item, idx) => {
this.ChatItem(item + 'testsetestsetestsetestse', idx % 2 === 0)
})
}
.justifyContent(FlexAlign.Start)
.alignItems(HorizontalAlign.Start)
.height('100%')
.width('100%')
}
@Builder
ChatItem(text: string, me: boolean = false) {
Row() {
Row() {
Image(me ? $r('app.media.right_head') : $r('app.media.left_head'))
.width(16)
.height(16)
Text(text)
.fontSize(this.changeFontSize)
.chatBackground(me)
}
.width('60%')
}
.width('100%')
.justifyContent(me ? FlexAlign.End : FlexAlign.Start)
.margin({ top: 10 })
}
build() {
Navigation() {
Row() {
this.setChat()
}
.height('100%')
.width('100%')
.padding({ left: 24, right: 20, top: 4, bottom: 4 })
}
.mode(NavigationMode.Auto)
.titleMode(NavigationTitleMode.Mini)
.title("字体大小设置")
.backgroundColor($r('sys.color.ohos_id_color_sub_background'))
.height('100%')
.width('100%')
}
}
@Extend(Text)
function chatBackground(me: boolean = false) {
.backgroundColor(me ? $r('app.color.set_chat_right_bg') : $r('app.color.set_chat_left_bg'))
.borderRadius(12)
.padding({ top: 8, bottom: 8, left: 10, right: 10 })
}

View File

@ -0,0 +1,161 @@
/**
* Database apply demo
*/
import TodoTable from '../common/database/tables/TodoTable';
import { TodoData } from '../common/types/Todo';
import { Logger } from '../utils/Logger';
@Preview
@Entry
@Component
struct TodoPage {
@State searchText: string = ''
@State isInput: boolean = false
@State isEdit: boolean = false
@State todoList: TodoData[] = []
private todoTable = new TodoTable()
searchController: SearchController = new SearchController();
addDialogController: CustomDialogController = new CustomDialogController({
builder: AddTodoDialog({ submit: (value) => this.handleAddSubmit(value) }),
cancel: () => this.isInput = false,
})
aboutToAppear() {
this.todoTable.getRdbStore(async () => {
const res = await this.todoTable.query();
this.todoList = res;
})
}
handleSearchSubmit(value: string) {
this.isInput = false
}
async handleAddSubmit(value: string) {
this.isInput = false;
const data = {
id: 0,
content: value,
status: 0,
}
const rowId = await this.todoTable.insertData(data);
data.id = rowId;
this.todoList.push(data)
}
build() {
Stack() {
Column() {
Row() {
Text('Todo List')
.fontWeight(FontWeight.Bold)
.fontSize(24)
Image($rawfile('ic_public_edit.svg'))
.width(24)
.height(24)
}
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.alignItems(VerticalAlign.Center)
.margin({ top: 12, bottom: 12 })
Row() {
Search({ value: this.searchText, placeholder: 'Search', controller: this.searchController })
.onChange(value => this.searchText = value)
.onSubmit(this.handleSearchSubmit)
}
.width('100%')
Column() {
ForEach(this.todoList, (item: TodoData) => {
TodoItem({ content: item.content })
})
}
.margin({ top: 12 })
.width('100%')
.alignItems(HorizontalAlign.Start)
}
.padding({ left: 12, right: 12 })
if (!this.isEdit && !this.isInput) {
Button() {
Image($rawfile('add.png'))
}
.width(48)
.height(48)
.markAnchor({ x: '50%', y: '50%' })
.position({ x: '90%', y: '95%' })
.onClick(() => {
// this.isInput = true;
this.addDialogController.open()
})
}
if (this.isEdit) {
Button() {
Image($rawfile('delete.png'))
}
.width(48)
.height(48)
.markAnchor({ x: '50%', y: '50%' })
.position({ x: '90%', y: '95%' })
}
}
.height('100%')
.width('100%')
.alignContent(Alignment.Top)
}
}
@CustomDialog
struct AddTodoDialog {
submit: (value) => void = () => {
}
@State inputValue: string = ''
controller: CustomDialogController = new CustomDialogController({
builder: AddTodoDialog({
submit: this.submit,
}),
})
build() {
Column() {
Stack() {
TextInput({ placeholder: "please input" })
.onChange(value => this.inputValue = value)
Button("Submit")
.type(ButtonType.Normal)
.markAnchor({ x: "100%" })
.position({ x: '100%' })
.onClick(() => {
this.submit(this.inputValue);
this.controller.close();
})
}
}
}
}
@Preview
@Component
struct TodoItem {
@Prop content: string = 'Todo'
@Prop showSelect: boolean = false
build() {
Row() {
Text(this.content)
.padding({ left: 8, right: 8 })
if (this.showSelect) {
Checkbox()
}
}
.justifyContent(FlexAlign.SpaceBetween)
.width('100%')
.height(30)
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2022 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 { ILogger } from './ILogger';
export class ConsoleLogger implements ILogger {
private appIdentifier: string;
constructor(appIdentifier: string) {
this.appIdentifier = appIdentifier;
}
public verbose(tag: string, msg: string): void {
console.log(`[${this.appIdentifier}] [verbose] tag:${tag} msg:${msg}`);
}
public debug(tag: string, msg: string): void {
console.debug(`[${this.appIdentifier}] [debug] tag:${tag} msg:${msg}`);
}
public info(tag: string, msg: string): void {
console.info(`[${this.appIdentifier}] [info] tag:${tag} msg:${msg}`);
}
public warn(tag: string, msg: string): void {
console.warn(`[${this.appIdentifier}] [warn] tag:${tag} msg:${msg}`);
}
public error(tag: string, msg: string): void {
console.error(`[${this.appIdentifier}] [error] tag:${tag} msg:${msg}`);
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2022 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 '@ohos.hilog';
import { ILogger } from './ILogger';
export class HiLogger implements ILogger {
private appIdentifier: string;
private appDomain: number = 0x0001;
constructor(appIdentifier: string) {
this.appIdentifier = appIdentifier;
}
public verbose(tag: string, msg: string): void {
hilog.debug(this.appDomain, tag, `[${this.appIdentifier}] [verbose] tag:${tag} msg:${msg}`);
}
public debug(tag: string, msg: string): void {
hilog.debug(this.appDomain, tag, `[${this.appIdentifier}] [debug] tag:${tag} msg:${msg}`);
}
public info(tag: string, msg: string): void {
hilog.info(this.appDomain, tag, `[${this.appIdentifier}] [info] tag:${tag} msg:${msg}`);
}
public warn(tag: string, msg: string): void {
hilog.warn(this.appDomain, tag, `[${this.appIdentifier}] [warn] tag:${tag} msg:${msg}`);
}
public error(tag: string, msg: string): void {
hilog.error(this.appDomain, tag, `[${this.appIdentifier}] [error] tag:${tag} msg:${msg}`);
}
}

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 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 ILogger {
verbose(tag: string, msg: string): void;
debug(tag: string, msg: string): void;
info(tag: string, msg: string): void;
warn(tag: string, msg: string): void;
error(tag: string, msg: string): void;
}

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2022 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 { ILogger } from './ILogger';
import { HiLogger } from './HiLogger';
import { ConsoleLogger } from './ConsoleLogger';
export class Logger implements ILogger {
private static isAppDebugMode: boolean = true;
private static appIdentifier: string = 'RDB';
// if true, use a ConsoleLogger, or HiLogger otherwise
private static useConsoleLogger: boolean = true;
public static verbose(tag: string, msg: string): void {
if (Logger.isAppDebugMode) {
Logger.getInstance().verbose(tag, msg);
}
}
public static debug(tag: string, msg: string): void {
if (Logger.isAppDebugMode) {
Logger.getInstance().debug(tag, msg);
}
}
public static info(tag: string, msg: string): void {
if (Logger.isAppDebugMode) {
Logger.getInstance().info(tag, msg);
}
}
public static warn(tag: string, msg: string): void {
if (Logger.isAppDebugMode) {
Logger.getInstance().warn(tag, msg);
}
}
public static error(tag: string, msg: string): void {
if (Logger.isAppDebugMode) {
Logger.getInstance().error(tag, msg);
}
}
private static logger: ILogger;
private constructor() {
}
public static getInstance(): Logger {
if (!Logger.logger) {
Logger.logger = Logger.useConsoleLogger
? new ConsoleLogger(Logger.appIdentifier)
: new HiLogger(Logger.appIdentifier);
}
return Logger.logger;
}
public verbose(tag: string, msg: string): void {
Logger.logger.verbose(tag, msg);
}
public debug(tag: string, msg: string): void {
Logger.debug(tag, msg);
}
public info(tag: string, msg: string): void {
Logger.info(tag, msg);
}
public warn(tag: string, msg: string): void {
Logger.warn(tag, msg);
}
public error(tag: string, msg: string): void {
Logger.error(tag, msg);
}
}

View File

@ -1,43 +0,0 @@
import dataPreferences from '@ohos.data.preferences';
import hilog from '@ohos.hilog';
import { Constants } from '../constants/CommonConstants';
// 首选项名字
export const PREFERENCES_NAME = 'myPreferences';
// 首选项Key字段
export const KEY_APP_FONT_SIZE = 'appFontSize';
export default class PreferencesUtil {
static createFontPreferences(context) {
globalThis.getFontPreferences = () => {
const preferences: Promise<dataPreferences.Preferences> = dataPreferences.getPreferences(context, PREFERENCES_NAME)
return preferences
}
}
static saveDefaultFontSize(fontSize: number) {
globalThis.getFontPreferences().then((preferences) => {
// 判断保存的key是否存在
preferences.has(KEY_APP_FONT_SIZE).then(async (isExist) => {
hilog.info(0x0000, 'testTag', '%{public}s', 'preferences has changeFontSize is ' + isExist);
if (!isExist) {
// 保存数据
await preferences.put(KEY_APP_FONT_SIZE, fontSize);
preferences.flush();
}
}).catch((err) => {
hilog.error(0x0000, 'testTag', '%{public}s', 'Has the value failed with err: ' + err);
});
}).catch((err) => {
hilog.error(0x0000, 'testTag', '%{public}s', 'Get the preferences failed, err: ' + err);
});
}
// 获取fontSize
static async getChangeFontSize(): Promise<number> {
const preferences = await globalThis.getFontPreferences();
return await preferences.get(KEY_APP_FONT_SIZE, Constants.SET_SIZE_STANDARD);
}
}

View File

@ -1,44 +0,0 @@
export interface SettingData {
settingName: string | Resource;
settingImage: string | Resource;
}
export class HomeViewModel {
settingList: Array<SettingData> = [];
initSettingData(): Array<SettingData> {
if (this.settingList.length === 0) {
this.settingList = [
{
settingName: "显示和亮度",
settingImage: $r("app.media.icon"),
},
{
settingName: "声音",
settingImage: $r("app.media.icon"),
},
{
settingName: "应用管理",
settingImage: $r("app.media.icon"),
},
{
settingName: "存储",
settingImage: $r("app.media.icon"),
},
{
settingName: "隐私",
settingImage: $r("app.media.icon"),
},
{
settingName: "设置字体和大小",
settingImage: $r("app.media.icon"),
},
]
}
return this.settingList;
}
}
export default new HomeViewModel();

View File

View File

@ -6,8 +6,8 @@
"mainElement": "EntryAbility",
"deviceTypes": [
"phone",
"tablet",
"2in1"
// "tablet",
// "2in1"
],
"deliveryWithInstall": true,
"installationFree": false,

View File

@ -3,26 +3,6 @@
{
"name": "start_window_background",
"value": "#FFFFFF"
},
{
"name": "white",
"value": "#FFFFFF"
},
{
"name": "setting_item_divider",
"value": "#0d182431"
},
{
"name": "text",
"value": "#182431"
},
{
"name": "set_chat_right_bg",
"value": "#D7E9F3"
},
{
"name": "set_chat_left_bg",
"value": "#FFFFFF"
}
]
}

View File

@ -1,13 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="lucide lucide-arrow-left">
<path d="m12 19-7-7 7-7"/>
<path d="M19 12H5"/>
</svg>

Before

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -1,6 +1,6 @@
{
"src": [
"pages/HomePage",
"pages/SetFontSizePage"
"pages/Index",
"pages/TodoPage"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Public/ic_public_edit</title>
<defs>
<path d="M16.8722296,2 C17.8721999,2 18.5147251,2.05839169 19.0012003,2.17117304 L17.6599443,3.51379911 C17.4862664,3.50652642 17.2928183,3.5022817 17.0753381,3.50070655 L7.02453833,3.50017541 L6.82305804,3.501658 C5.6550816,3.5151767 5.20981608,3.61305534 4.75370688,3.8569852 C4.36325774,4.06579969 4.06579969,4.36325774 3.8569852,4.75370688 C3.59290159,5.24750032 3.5,5.72858421 3.5,7.1277704 L3.50017541,16.9754617 L3.501658,17.176942 C3.5151767,18.3449184 3.61305534,18.7901839 3.8569852,19.2462931 C4.06579969,19.6367423 4.36325774,19.9342003 4.75370688,20.1430148 C5.22281064,20.3938942 5.68044405,20.4902819 6.92466189,20.4992935 L16.8722296,20.5 C18.2714158,20.5 18.7524997,20.4070984 19.2462931,20.1430148 C19.6367423,19.9342003 19.9342003,19.6367423 20.1430148,19.2462931 C20.3938942,18.7771894 20.4902819,18.319556 20.4992935,17.0753381 L20.5,16.8722296 L20.5,7.1277704 C20.5,6.82616011 20.4956832,6.56721095 20.4862654,6.34159954 L21.8289375,4.9992768 C21.9416465,5.48569497 22,6.12812696 22,7.1277704 L22,16.8722296 L21.9989932,17.0937657 C21.9842401,18.674381 21.8076257,19.3015622 21.487765,19.91208 L21.4657346,19.9536914 C21.1337211,20.5745027 20.6538954,21.0680807 20.0458564,21.4148264 L19.9536914,21.4657346 C19.3018396,21.8143488 18.6552671,22 16.8722296,22 L7.1277704,22 L6.90623426,21.9989932 C5.32561899,21.9842401 4.69843783,21.8076257 4.08791999,21.487765 L4.04630859,21.4657346 C3.42549731,21.1337211 2.93191931,20.6538954 2.58517358,20.0458564 L2.53426541,19.9536914 C2.18565122,19.3018396 2,18.6552671 2,16.8722296 L2,7.1277704 C2,5.38266989 2.17783521,4.72618864 2.51223497,4.08791999 L2.53426541,4.04630859 C2.86627892,3.42549731 3.34610464,2.93191931 3.9541436,2.58517358 L4.04630859,2.53426541 C4.69816044,2.18565122 5.34473292,2 7.1277704,2 L16.8722296,2 Z M22.2300776,1.76992245 C22.6206018,2.16044674 22.6206018,2.79361172 22.2300776,3.18413601 L12.684136,12.7300776 C12.2936117,13.1206018 11.6604467,13.1206018 11.2699224,12.7300776 C10.8793982,12.3395533 10.8793982,11.7063883 11.2699224,11.315864 L20.815864,1.76992245 C21.2063883,1.37939815 21.8395533,1.37939815 22.2300776,1.76992245 Z" id="path-1"></path>
</defs>
<g id="Public/ic_public_edit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<mask id="mask-2" fill="white">
<use xlink:href="#path-1"></use>
</mask>
<use id="形状结合" fill="#182431" fill-rule="nonzero" xlink:href="#path-1"></use>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="18px" height="18px" viewBox="0 0 18 18" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Public/ic_public_input_search</title>
<defs>
<path d="M13.2129889,12.2463949 L15.6099466,14.6430364 C15.9028398,14.9359296 15.9028398,15.4108033 15.6099466,15.7036966 C15.3170533,15.9965898 14.8421796,15.9965898 14.5492864,15.7036966 L12.1424668,13.2968868 C12.5355197,12.9856781 12.8945263,12.6333482 13.2129889,12.2463949 Z M7.78125,1.5 C11.2502886,1.5 14.0625,4.31221142 14.0625,7.78125 C14.0625,9.23090694 13.571411,10.5658639 12.7465202,11.6288338 L12.5852288,11.8281795 C12.5065389,11.9214937 12.4251798,12.0124834 12.3412691,12.1010309 L12.2391385,12.2063305 L12.2391385,12.2063305 L12.1042686,12.3381988 L12.1042686,12.3381988 L12.0040285,12.4312816 L12.0040285,12.4312816 L11.7500714,12.6500283 L11.7500714,12.6500283 L11.6103411,12.7608162 L11.6103411,12.7608162 C10.5503999,13.5770819 9.22251268,14.0625 7.78125,14.0625 C4.31221142,14.0625 1.5,11.2502886 1.5,7.78125 C1.5,4.31221142 4.31221142,1.5 7.78125,1.5 Z M7.78125,3 C5.14063854,3 3,5.14063854 3,7.78125 C3,10.4218615 5.14063854,12.5625 7.78125,12.5625 C10.4218615,12.5625 12.5625,10.4218615 12.5625,7.78125 C12.5625,5.14063854 10.4218615,3 7.78125,3 Z" id="path-1"></path>
</defs>
<g id="Public/ic_public_input_search" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<mask id="mask-2" fill="white">
<use xlink:href="#path-1"></use>
</mask>
<g id="形状" fill-rule="nonzero"></g>
<g id="编组" mask="url(#mask-2)" fill="#000000" fill-opacity="0.9">
<g id="Symbol/color-light/colorPrimary">
<rect id="color/#000000" x="0" y="0" width="18" height="18"></rect>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB