= {
1: widthWeightOneSection,
2: widthWeightTwoSection,
3: widthWeightThreeSection
diff --git a/common/utils/src/main/ets/default/model/databaseModel/FolderData.ets b/common/utils/src/main/ets/default/model/databaseModel/FolderData.ets
index fdf5ad41c8052d55d7667cfcf936f78fab9f8a9f..c35322b39a6fa87ac286587c4f2b647c08f5e0f9 100644
--- a/common/utils/src/main/ets/default/model/databaseModel/FolderData.ets
+++ b/common/utils/src/main/ets/default/model/databaseModel/FolderData.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -14,6 +14,7 @@
*/
import {FolderType, Delete} from './EnumData'
+import relationalStore from '@ohos.data.relationalStore';
/**
* 文件夹类
@@ -43,7 +44,7 @@ export default class FolderData {
/**
* 转化为folder_table表的valueBucket
*/
- toFolderObject(): any{
+ toFolderObject(): relationalStore.ValuesBucket {
return {
"name": this.name,
"uuid": this.uuid,
diff --git a/common/utils/src/main/ets/default/model/databaseModel/NoteData.ets b/common/utils/src/main/ets/default/model/databaseModel/NoteData.ets
index 4edcb198ac20cecc30f3a251c579318c4842aa8a..846b6eef2389719abe814044cb47d16733989544 100644
--- a/common/utils/src/main/ets/default/model/databaseModel/NoteData.ets
+++ b/common/utils/src/main/ets/default/model/databaseModel/NoteData.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -14,6 +14,7 @@
*/
import { NoteType, Favorite, Delete, Top } from './EnumData'
+import relationalStore from '@ohos.data.relationalStore';
/**
* 笔记类
@@ -56,7 +57,7 @@ export default class NoteData {
/**
* 转化为note_table表的valueBucket
*/
- toNoteObject(): any{
+ toNoteObject(): relationalStore.ValuesBucket {
return {
"title": this.title,
"uuid": this.uuid,
diff --git a/common/utils/src/main/ets/default/model/databaseModel/SysDefData.ets b/common/utils/src/main/ets/default/model/databaseModel/SysDefData.ets
index 538a4eeece0247ba4ebda5a03f77f1a287d0e087..751d7f6ff68ef93d871ec72a694fc550da6369fd 100644
--- a/common/utils/src/main/ets/default/model/databaseModel/SysDefData.ets
+++ b/common/utils/src/main/ets/default/model/databaseModel/SysDefData.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -13,168 +13,179 @@
* limitations under the License.
*/
-import {SysDefFolder, SysDefFolderUuid, FolderType, NoteType, Favorite, Top, Delete} from './EnumData'
-import relationalStore from '@ohos.data.relationalStore'
+import { SysDefFolder, SysDefFolderUuid, FolderType, NoteType, Favorite, Top, Delete } from './EnumData';
+import relationalStore from '@ohos.data.relationalStore';
-export default {
+interface DbInfoType {
+ db_name: DbNameType;
+ db_verison: number;
+}
+
+interface DbNameType {
+ name: string;
+ securityLevel: relationalStore.SecurityLevel;
+}
+
+class SysDefData {
/**
* db info
*/
- dbInfo: {
+ public dbInfo: DbInfoType = {
db_name: {
name: "note.db", // 数据库名称
securityLevel: relationalStore.SecurityLevel.S1
},
db_verison: 1 // 数据库版本
- },
+ };
/**
* system defined folder
*/
- sys_def_allNotes: {
- "id": 1,
- "name": SysDefFolder.AllNotes,
- "uuid": SysDefFolderUuid.AllNotes,
- "color": "#ffffff",
- "folder_type": FolderType.SysDef,
- "is_deleted": Delete.No,
- "created_time": 1641863695000,
- "modified_time": 1641863695000
- },
-
- sys_def_unClassified: {
- "id": 2,
- "name": SysDefFolder.UnClassified,
- "uuid": SysDefFolderUuid.UnClassified,
- "color": "#ffffff",
- "folder_type": FolderType.SysDef,
- "is_deleted": Delete.No,
- "created_time": 1641860095000,
- "modified_time": 1641860095000
- },
-
- sys_def_myFavorites: {
- "id": 3,
- "name": SysDefFolder.MyFavorites,
- "uuid": SysDefFolderUuid.MyFavorites,
- "color": "#ffffff",
- "folder_type": FolderType.FeatureDef,
- "is_deleted": Delete.No,
- "created_time": 1641856088000,
- "modified_time": 1641856088000
- },
+ public sys_def_allNotes: relationalStore.ValuesBucket = {
+ "id": 1,
+ "name": SysDefFolder.AllNotes,
+ "uuid": SysDefFolderUuid.AllNotes,
+ "color": "#ffffff",
+ "folder_type": FolderType.SysDef,
+ "is_deleted": Delete.No,
+ "created_time": 1641863695000,
+ "modified_time": 1641863695000
+ };
- sys_def_recentDeletes: {
- "id": 4,
- "name": SysDefFolder.RecentDeletes,
- "uuid": SysDefFolderUuid.RecentDeletes,
- "color": "#ffffff",
- "folder_type": FolderType.FeatureDef,
- "is_deleted": Delete.No,
- "created_time": 1641848898000,
- "modified_time": 1641848898000
- },
-
- sys_def_personal: {
- "id": 5,
- "name": "个人",
- "uuid": SysDefFolderUuid.Personal,
- "color": "#41ba41",
- "folder_type": FolderType.CusDef,
- "is_deleted": Delete.No,
- "created_time": 1641677288000,
- "modified_time": 1641677288000
- },
-
- sys_def_life: {
- "id": 6,
- "name": "生活",
- "uuid": SysDefFolderUuid.Life,
- "color": "#00aaee",
- "folder_type": FolderType.CusDef,
- "is_deleted": Delete.No,
- "created_time": 1641676108000,
- "modified_time": 1641676108000
- },
-
- sys_def_work: {
- "id": 7,
- "name": "工作",
- "uuid": SysDefFolderUuid.Work,
- "color": "#f86d05",
- "folder_type": FolderType.CusDef,
- "is_deleted": Delete.No,
- "created_time": 1641636508000,
- "modified_time": 1641636508000
- },
+ public sys_def_unClassified: relationalStore.ValuesBucket = {
+ "id": 2,
+ "name": SysDefFolder.UnClassified,
+ "uuid": SysDefFolderUuid.UnClassified,
+ "color": "#ffffff",
+ "folder_type": FolderType.SysDef,
+ "is_deleted": Delete.No,
+ "created_time": 1641860095000,
+ "modified_time": 1641860095000
+ };
+
+ public sys_def_myFavorites: relationalStore.ValuesBucket = {
+ "id": 3,
+ "name": SysDefFolder.MyFavorites,
+ "uuid": SysDefFolderUuid.MyFavorites,
+ "color": "#ffffff",
+ "folder_type": FolderType.FeatureDef,
+ "is_deleted": Delete.No,
+ "created_time": 1641856088000,
+ "modified_time": 1641856088000
+ };
+
+ public sys_def_recentDeletes: relationalStore.ValuesBucket = {
+ "id": 4,
+ "name": SysDefFolder.RecentDeletes,
+ "uuid": SysDefFolderUuid.RecentDeletes,
+ "color": "#ffffff",
+ "folder_type": FolderType.FeatureDef,
+ "is_deleted": Delete.No,
+ "created_time": 1641848898000,
+ "modified_time": 1641848898000
+ };
+
+ public sys_def_personal: relationalStore.ValuesBucket = {
+ "id": 5,
+ "name": "个人",
+ "uuid": SysDefFolderUuid.Personal,
+ "color": "#41ba41",
+ "folder_type": FolderType.CusDef,
+ "is_deleted": Delete.No,
+ "created_time": 1641677288000,
+ "modified_time": 1641677288000
+ };
+
+ public sys_def_life: relationalStore.ValuesBucket = {
+ "id": 6,
+ "name": "生活",
+ "uuid": SysDefFolderUuid.Life,
+ "color": "#00aaee",
+ "folder_type": FolderType.CusDef,
+ "is_deleted": Delete.No,
+ "created_time": 1641676108000,
+ "modified_time": 1641676108000
+ };
+
+ public sys_def_work: relationalStore.ValuesBucket = {
+ "id": 7,
+ "name": "工作",
+ "uuid": SysDefFolderUuid.Work,
+ "color": "#f86d05",
+ "folder_type": FolderType.CusDef,
+ "is_deleted": Delete.No,
+ "created_time": 1641636508000,
+ "modified_time": 1641636508000
+ };
/**
* system defined note
*/
- sys_def_note1: {
- "id": 1,
- "title": "数学公式",
- "uuid": "note1_uuid",
- "folder_uuid": SysDefFolderUuid.UnClassified,
- "content_text": '好好学习,天天向上',
- "content_img": "",
- "note_type": NoteType.SysDef,
- "is_top": Top.Yes,
- "is_favorite": Favorite.Yes,
- "is_deleted": Delete.No,
- "created_time": 1641869573000,
- "modified_time": 1641869573000,
- "deleted_time": 0,
- "slider_value":0
- },
-
- sys_def_note2: {
- "id": 2,
- "title": "UX会议纪要",
- "uuid": "note2_uuid",
- "folder_uuid": SysDefFolderUuid.Work,
- "content_text": "",
- "content_img": "",
- "note_type": NoteType.SysDef,
- "is_top": Top.Yes,
- "is_favorite": Favorite.No,
- "is_deleted": Delete.No,
- "created_time": 1640999288000,
- "modified_time": 1640999288000,
- "deleted_time": 0,
- "slider_value":0
- },
-
- sys_def_note3: {
- "id": 3,
- "title": "旅游心得",
- "uuid": "note3_uuid",
- "folder_uuid": SysDefFolderUuid.Work,
- "content_text": '要想整个旅程无遗憾,关键是心态,首先要对即将到的目的地有一个正确的认识和恰当的期望。
',
- "content_img": "",
- "note_type": NoteType.SysDef,
- "is_top": Top.No,
- "is_favorite": Favorite.No,
- "is_deleted": Delete.No,
- "created_time": 1641385708000,
- "modified_time": 1641385708000,
- "deleted_time": 0,
- "slider_value":0
- },
+ public sys_def_note1: relationalStore.ValuesBucket = {
+ "id": 1,
+ "title": "数学公式",
+ "uuid": "note1_uuid",
+ "folder_uuid": SysDefFolderUuid.UnClassified,
+ "content_text": '好好学习,天天向上',
+ "content_img": "",
+ "note_type": NoteType.SysDef,
+ "is_top": Top.Yes,
+ "is_favorite": Favorite.Yes,
+ "is_deleted": Delete.No,
+ "created_time": 1641869573000,
+ "modified_time": 1641869573000,
+ "deleted_time": 0,
+ "slider_value": 0
+ };
- sys_def_note4: {
+ public sys_def_note2: relationalStore.ValuesBucket = {
+ "id": 2,
+ "title": "UX会议纪要",
+ "uuid": "note2_uuid",
+ "folder_uuid": SysDefFolderUuid.Work,
+ "content_text": "",
+ "content_img": "",
+ "note_type": NoteType.SysDef,
+ "is_top": Top.Yes,
+ "is_favorite": Favorite.No,
+ "is_deleted": Delete.No,
+ "created_time": 1640999288000,
+ "modified_time": 1640999288000,
+ "deleted_time": 0,
+ "slider_value": 0
+ };
+
+ public sys_def_note3: relationalStore.ValuesBucket = {
+ "id": 3,
+ "title": "旅游心得",
+ "uuid": "note3_uuid",
+ "folder_uuid": SysDefFolderUuid.Work,
+ "content_text": '要想整个旅程无遗憾,关键是心态,首先要对即将到的目的地有一个正确的认识和恰当的期望。
',
+ "content_img": "",
+ "note_type": NoteType.SysDef,
+ "is_top": Top.No,
+ "is_favorite": Favorite.No,
+ "is_deleted": Delete.No,
+ "created_time": 1641385708000,
+ "modified_time": 1641385708000,
+ "deleted_time": 0,
+ "slider_value": 0
+ };
+
+ public sys_def_note4: relationalStore.ValuesBucket = {
"id": 4,
"title": "蛋糕做法",
"uuid": "note4_uuid",
"folder_uuid": SysDefFolderUuid.Life,
- "content_text": '' +
- '
' +
- '
糖60g' +
- '
' +
- '
玉米油40g' +
- '
1. 添加鸡蛋、盐、糖、蛋糕粉
' +
- ' 2. 加入玉米油、牛奶,烤箱预热15分钟
' +
- ' 3. 加入葡萄干、核桃仁,烤箱定时40分钟
',
+ "content_text": ' ' +
+ '' +
+ '糖60g
' +
+ ' ' +
+ '' +
+ '玉米油40g
' +
+ '
1. 添加鸡蛋、盐、糖、蛋糕粉
' +
+ ' 2. 加入玉米油、牛奶,烤箱预热15分钟
' +
+ ' 3. 加入葡萄干、核桃仁,烤箱定时40分钟
',
"content_img": "",
"note_type": NoteType.CusDef,
"is_top": Top.No,
@@ -183,6 +194,8 @@ export default {
"created_time": 1640909288000,
"modified_time": 1640909288000,
"deleted_time": 0,
- "slider_value":0
- }
-}
\ No newline at end of file
+ "slider_value": 0
+ };
+}
+
+export default new SysDefData();
\ No newline at end of file
diff --git a/common/utils/src/main/ets/default/model/searchModel/SearchModel.ets b/common/utils/src/main/ets/default/model/searchModel/SearchModel.ets
index 891ef4f92580b7dcb0a6f4b03e6c83ca0fdf1a10..ab28bddf139bbe4702fa6437de7813aefbed7453 100644
--- a/common/utils/src/main/ets/default/model/searchModel/SearchModel.ets
+++ b/common/utils/src/main/ets/default/model/searchModel/SearchModel.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -16,14 +16,20 @@
import { LogUtil } from '../../baseUtil/LogUtil'
import NoteData from '../../model/databaseModel/NoteData'
import util from '@ohos.util'
+import relationalStore from '@ohos.data.relationalStore';
-const TAG = "SearchModel"
+const TAG: string = 'SearchModel';
+
+interface TextSpan {
+ type: 0 | 1; // 0 表示正常文本,1 表示高亮关键词
+ text: string;
+}
/**
* Search service class
*/
export class SearchModel {
- private rdbStore;
+ private rdbStore: relationalStore.RdbStore | undefined = undefined;
/**
* Search
@@ -38,7 +44,7 @@ export class SearchModel {
}
let searchData: NoteData[] = [];
noteDataArray.forEach((noteData) => {
- let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
+ let base64regex = new RegExp('/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/');
let contentTextValue: string
if (base64regex.test(noteData.content_text) && noteData.content_text.length > 0) {
let Base64 = new util.Base64()
@@ -48,8 +54,8 @@ export class SearchModel {
} else {
contentTextValue = noteData.content_text
}
- if (contentTextValue.replace(/<[^>]+>/g, "").toLowerCase().indexOf(query.toLowerCase()) != -1
- || noteData.title.toLowerCase().indexOf(query.toLowerCase()) != -1) {
+ if (contentTextValue.replace(new RegExp('/<[^>]+>/g'), "").toLowerCase().indexOf(query.toLowerCase()) != -1
+ || noteData.title.toLowerCase().indexOf(query.toLowerCase()) != -1) {
LogUtil.info(TAG, "uuid " + noteData.uuid)
searchData.push(noteData);
}
@@ -58,14 +64,14 @@ export class SearchModel {
return searchData;
}
- splitToHighlightText(text: string, highlightKeyword): any[] {
- let spans: any[] = []
- var lowerSpans: string[] = text.toLowerCase().split(highlightKeyword.toLowerCase())
- var keywordStartIndex = 0
- var keywordLength = highlightKeyword.length
+ splitToHighlightText(text: string, highlightKeyword: string): TextSpan[] {
+ let spans: TextSpan[] = [];
+ let lowerSpans: string[] = text.toLowerCase().split(highlightKeyword.toLowerCase());
+ let keywordStartIndex = 0;
+ let keywordLength = highlightKeyword.length;
- for (var i = 0; i < lowerSpans.length; i++) {
- var normalText = text.substr(keywordStartIndex, lowerSpans[i].length)
+ for (let i = 0; i < lowerSpans.length; i++) {
+ let normalText = text.substr(keywordStartIndex, lowerSpans[i].length);
spans.push({
type: 0,
text: normalText
@@ -73,7 +79,7 @@ export class SearchModel {
// if not at last, append highlight keyword
if (i != lowerSpans.length - 1) {
keywordStartIndex += lowerSpans[i].length
- var keywordText = text.substr(keywordStartIndex, keywordLength)
+ let keywordText = text.substr(keywordStartIndex, keywordLength);
spans.push({
type: 1,
text: keywordText
diff --git a/features/index.ets b/features/index.ets
new file mode 100644
index 0000000000000000000000000000000000000000..6db6bab1577f68e4d76dc153453028701e8cc10c
--- /dev/null
+++ b/features/index.ets
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2023-2024 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 { NewOrEditFolderDialog } from './src/main/ets/components/CusDialogComp';
+
+export { DeleteDialog } from './src/main/ets/components/CusDialogComp';
+
+export { NoteDataMoveDialog } from './src/main/ets/components/CusDialogComp';
+
+export { EditContentDialog } from './src/main/ets/components/CusDialogComp';
+
+export { EditTitleDialog } from './src/main/ets/components/CusDialogComp';
+
+export { EditContentDialogPortrait } from './src/main/ets/components/CusDialogComp';
+
+export { FolderListComp } from './src/main/ets/components/FolderListComp';
+
+export { NoteAndCreateComp } from './src/main/ets/components/FolderListComp';
+
+export { NoteContent } from './src/main/ets/components/NoteContent';
+
+export { NoteContentComp } from './src/main/ets/components/NoteContentComp';
+
+export { NoteContentCompPortrait } from './src/main/ets/components/NoteContentCompPortrait';
+
+export { NoteContentOverViewComp } from './src/main/ets/components/NoteContentCompPortrait';
+
+export { ToolBarComp } from './src/main/ets/components/NoteContentCompPortrait';
+
+export { DeleteNoteComp } from './src/main/ets/components/NoteContentCompPortrait';
+
+export { NoteListComp } from './src/main/ets/components/NoteListComp';
+
+export { NoteItemComp } from './src/main/ets/components/NoteListComp';
+
+export { NoteItemListComp } from './src/main/ets/components/NoteListComp';
+
+export { OperateNoteComp } from './src/main/ets/components/NoteListComp';
+
+export { AddNoteComp } from './src/main/ets/components/NoteListComp';
+
+export { SearchComp } from './src/main/ets/components/NoteListComp';
+
+export { OperateNoteCompForPortrait } from './src/main/ets/components/NoteListComp';
+
diff --git a/features/src/main/ets/components/CusDialogComp.ets b/features/src/main/ets/components/CusDialogComp.ets
index e056b7462fbbb54acbbb0d2871ab9c952be9d83f..6e5d7b400b7337775cd51510372d90e6fdc0e66f 100644
--- a/features/src/main/ets/components/CusDialogComp.ets
+++ b/features/src/main/ets/components/CusDialogComp.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -18,7 +18,15 @@ import FolderData from '@ohos/utils/src/main/ets/default/model/databaseModel/Fol
import FolderUtil from '@ohos/utils/src/main/ets/default/baseUtil/FolderUtil'
import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData'
import NoteUtil from '@ohos/utils/src/main/ets/default/baseUtil/NoteUtil'
-import { circleColorArray, fontColorArray, SysDefFolderUuid, DeleteFileType, FolderType, LogUtil } from '@ohos/utils'
+import {
+ circleColorArray,
+ fontColorArray,
+ SysDefFolderUuid,
+ DeleteFileType,
+ FolderType,
+ Delete,
+ LogUtil
+} from '@ohos/utils';
import inputMethod from '@ohos.inputMethod'
const TAG = "CusDialogComp"
@@ -26,7 +34,8 @@ const TAG = "CusDialogComp"
@CustomDialog
export struct NewOrEditFolderDialog {
newOrEditFolderDialogCtl: CustomDialogController
- confirm: (color: string, name: string) => void
+ confirm: (color: string, name: string) => void = (color: string, name: string) => {
+ };
@State inputName: string = ""
private oriInputName: string = ""
private oriSelectedColor: string = ""
@@ -47,8 +56,9 @@ export struct NewOrEditFolderDialog {
Flex({ wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.SpaceBetween }) {
ForEach(circleColorArray, (colorStr: string) => {
ColorCircleComp({ circleColor: colorStr })
- }, colorStr => colorStr)
+ }, (colorStr: string) => colorStr)
}.margin({ bottom: 12, left: 24, right: 24 })
+
// folder name input
Flex({ wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.SpaceBetween }) {
Image($r("app.media.folder"))
@@ -107,21 +117,21 @@ export struct NewOrEditFolderDialog {
.strokeWidth(1)
.color($r("app.color.divider_color_e4e4e4"))
Text($r("app.string.save"))
- .opacity(this.inputName == ""
- || (this.oriSelectedColor == this.selectedColor && this.inputName == this.oriInputName && this.dialogType == 1)
- || (this.isExisted && this.dialogType == 0)
- || (this.isExisted && this.dialogType == 1 && this.inputName != this.oriInputName) ? 0.4 : 1)
- .enabled(this.inputName == ""
- || (this.oriSelectedColor == this.selectedColor && this.inputName == this.oriInputName && this.dialogType == 1)
- || (this.isExisted && this.dialogType == 0)
- || (this.isExisted && this.dialogType == 1 && this.inputName != this.oriInputName) ? false : true)
+ .opacity(this.inputName == "" || (this.oriSelectedColor == this.selectedColor &&
+ this.inputName == this.oriInputName && this.dialogType == 1) ||
+ (this.isExisted && this.dialogType == 0) ||
+ (this.isExisted && this.dialogType == 1 && this.inputName != this.oriInputName) ? 0.4 : 1)
+ .enabled(this.inputName == "" || (this.oriSelectedColor == this.selectedColor &&
+ this.inputName == this.oriInputName && this.dialogType == 1) ||
+ (this.isExisted && this.dialogType == 0) || (this.isExisted && this.dialogType == 1 &&
+ this.inputName != this.oriInputName) ? false : true)
.fontSize(18)
.textAlign(TextAlign.Center)
.fontColor($r("app.color.button_color_f86d05"))
.width('48%')
.onClick(() => {
this.newOrEditFolderDialogCtl.close()
- if (this.inputName.replace(/\s+/g, '') == '') {
+ if (this.inputName.replace(new RegExp('/\s+/g'), '') == '') {
return
} else {
this.confirm(this.selectedColor, this.inputName)
@@ -136,10 +146,11 @@ export struct NewOrEditFolderDialog {
.backgroundColor($r("app.color.create_folder_bg_color"))
.alignItems(HorizontalAlign.Start)
.margin({ bottom: 16, left: 12, right: 12 })
+ .offset({ y: -50 })
}
aboutToAppear(): void {
- var currentFolder: FolderData = FolderUtil.getFolderData(this.AllFolderArray, this.editFolderUuid) // 获取当前选中的文件夹
+ let currentFolder: FolderData = FolderUtil.getFolderData(this.AllFolderArray, this.editFolderUuid); // 获取当前选中的文件夹
if (currentFolder == null) {
return
}
@@ -148,7 +159,7 @@ export struct NewOrEditFolderDialog {
this.oriInputName = this.inputName
this.oriSelectedColor = currentFolder.color
} else {
- GlobalResourceManager.getStringByResource(FolderUtil.getFolderText(currentFolder)).then(result => {
+ GlobalResourceManager.getStringByResource(FolderUtil.getFolderText(currentFolder) as Resource).then(result => {
this.inputName = result
this.oriInputName = this.inputName
this.oriSelectedColor = currentFolder.color
@@ -159,7 +170,7 @@ export struct NewOrEditFolderDialog {
@Component
struct ColorCircleComp {
- private circleColor: string
+ private circleColor: string = '';
@Consume('SelectedColor') selectedColor: string
build() {
@@ -189,7 +200,8 @@ export struct DeleteDialog {
private multiSelect: boolean = false
private deleteFileType = DeleteFileType.NoteData
noteDataDeleteDialogCtl: CustomDialogController
- onConfirm: () => void
+ onConfirm: () => void = () => {
+ };
build() {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween }) {
@@ -200,30 +212,35 @@ export struct DeleteDialog {
.textAlign(TextAlign.Center)
.maxLines(1)
} else {
- Text(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? $r("app.string.deleteNoteComplete") : $r("app.string.deleteNote"))
+ Text(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ?
+ $r("app.string.deleteNoteComplete") : $r("app.string.deleteNote"))
.fontSize(14)
.textAlign(TextAlign.Center)
.maxLines(1)
- .visibility(this.multiSelect == false || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.Visible : Visibility.None)
+ .visibility(this.multiSelect == false || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ?
+ Visibility.Visible : Visibility.None)
if (this.CheckedNoteArray.length ==
NoteUtil.getNoteDataArray(this.AllNoteArray, this.selectedFolderData.uuid).length) {
Text($r("app.string.deleteAllNote"))
.fontSize(14)
.textAlign(TextAlign.Center)
.maxLines(1)
- .visibility(this.multiSelect == false || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible)
+ .visibility(this.multiSelect == false || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ?
+ Visibility.None : Visibility.Visible)
} else if (this.CheckedNoteArray.length > 1) {
Text($r("app.string.deletePartNote", this.CheckedNoteArray.length))
.fontSize(14)
.textAlign(TextAlign.Center)
.maxLines(1)
- .visibility(this.multiSelect == false || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible)
+ .visibility(this.multiSelect == false || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ?
+ Visibility.None : Visibility.Visible)
} else {
Text($r("app.string.deleteNote"))
.fontSize(14)
.textAlign(TextAlign.Center)
.maxLines(1)
- .visibility(this.multiSelect == false || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible)
+ .visibility(this.multiSelect == false || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ?
+ Visibility.None : Visibility.Visible)
}
}
}
@@ -267,6 +284,7 @@ export struct DeleteDialog {
.padding({ top: 24, bottom: 16, left: 16, right: 16 })
.backgroundColor($r("app.color.delete_note_bg_color"))
.margin({ bottom: 16, left: 12, right: 12 })
+ .offset({ y: -50 })
}
}
@@ -274,24 +292,25 @@ export struct DeleteDialog {
struct NoteDataMoveItemComp {
@StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = []
- private folderItem: FolderData
+ private folderItem: FolderData = new FolderData(0, '', new Date().getTime() + '', '', FolderType.CusDef, Delete.No,
+ new Date().getTime(), new Date().getTime());
dividerShow: boolean = true
build() {
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap }) {
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap }) {
- Image(FolderUtil.getFolderIcon(this.folderItem.uuid))
+ Image(FolderUtil.getFolderIcon(this.folderItem.uuid!))
.objectFit(ImageFit.Fill)
.width(24)
.height(24)
.flexShrink(0)
- .fillColor(FolderUtil.getFolderIconColor(this.AllFolderArray, this.folderItem.uuid, false))
+ .fillColor(FolderUtil.getFolderIconColor(this.AllFolderArray, this.folderItem.uuid!, false))
}
.width(24)
Column() {
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.SpaceBetween }) {
- Text(FolderUtil.getFolderText(this.folderItem))
+ Text(FolderUtil.getFolderText(this.folderItem!))
.fontSize(16)
.textAlign(TextAlign.Center)
.maxLines(1)
@@ -299,7 +318,8 @@ struct NoteDataMoveItemComp {
.flexShrink(1)
.fontWeight(FontWeight.Medium)
Image((FolderUtil.getCommonFolder(this.AllFolderArray, this.CheckedNoteArray) == null
- || FolderUtil.getCommonFolder(this.AllFolderArray, this.CheckedNoteArray) != this.folderItem) ? $r("app.media.foldMove_unselect") : $r("app.media.foldMove_select"))
+ || FolderUtil.getCommonFolder(this.AllFolderArray, this.CheckedNoteArray) != this.folderItem!) ?
+ $r("app.media.foldMove_unselect") : $r("app.media.foldMove_select"))
.objectFit(ImageFit.Fill)
.width(24)
.height(24)
@@ -326,15 +346,16 @@ struct NoteDataMoveItemComp {
@CustomDialog
export struct NoteDataMoveDialog {
noteDataMoveDialogCtl: CustomDialogController
- onConfirm: (folderUuid: string) => void
- NoteDataMoveArray: FolderData[]
+ onConfirm: (folderUuid: string) => void = (folderUuid: string) => {
+ };
+ NoteDataMoveArray: FolderData[] = [];
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = []
aboutToAppear() {
this.NoteDataMoveArray = this.AllFolderArray.slice(2, this.AllFolderArray.length);
if (this.AllFolderArray[1] === undefined || this.AllFolderArray[1] === null) {
- LogUtil.info(TAG, "this AllFolderArray[1] undefined")
- return
+ LogUtil.info(TAG, 'this AllFolderArray[1] undefined');
+ return;
}
this.NoteDataMoveArray.push(this.AllFolderArray[1]);
}
@@ -351,7 +372,7 @@ export struct NoteDataMoveDialog {
List() {
if (this.NoteDataMoveArray !== undefined && this.NoteDataMoveArray !== null && this.NoteDataMoveArray !== []) {
- ForEach(this.NoteDataMoveArray.slice(0, this.NoteDataMoveArray.length - 1), (item) => {
+ ForEach(this.NoteDataMoveArray.slice(0, this.NoteDataMoveArray.length - 1), (item: FolderData) => {
ListItem() {
NoteDataMoveItemComp({ folderItem: item })
}
@@ -359,7 +380,7 @@ export struct NoteDataMoveDialog {
this.noteDataMoveDialogCtl.close()
this.onConfirm(item.uuid)
})
- }, noteItem => noteItem.uuid)
+ }, (noteItem: FolderData) => noteItem.uuid)
}
ListItem() {
NoteDataMoveItemComp({
@@ -391,22 +412,24 @@ export struct NoteDataMoveDialog {
.padding({ left: 24, right: 24 })
.backgroundColor($r("app.color.choose_folder_bg_color"))
.margin({ bottom: 16, left: 12, right: 12 })
+ .offset({ y: -50 })
}
}
-let inSetValue = AppStorage.Link('inSetValue')
+let inSetValue: string = AppStorage.Link('inSetValue');
@CustomDialog
export struct EditContentDialog {
editContentDialogCtl: CustomDialogController
- confirm: (excuteJs: string) => void
+ confirm: (excuteJs: string) => void = (excuteJs: string) => {
+ };
@State selectFontColor: string = fontColorArray[0]
@Consume('SelectedNoteData') selectedNoteData: NoteData
- private circleColor: string
- private fontSize: number
+ private circleColor: string = '';
+ private fontSize: number = 0;
aboutToAppear() {
- this.confirm("javascript:RICH_EDITOR.getFontSizes()")
+ this.confirm('javascript:RICH_EDITOR.getFontSizes()');
}
build() {
@@ -608,7 +631,7 @@ export struct EditContentDialog {
this.selectFontColor = colorStr
this.confirm("javascript:RICH_EDITOR.setTextColor('" + this.selectFontColor + "')")
})
- }, colorStr => colorStr)
+ }, (colorStr: string) => colorStr)
}.padding({ bottom: 11 })
}
.alignItems(VerticalAlign.Top)
@@ -665,7 +688,8 @@ export struct EditContentDialog {
@CustomDialog
export struct EditTitleDialog {
editTitleDialog: CustomDialogController
- confirm: (newTitle: string) => void
+ confirm: (newTitle: string) => void = (newTitle: string) => {
+ };
@State inputName: string = ""
@State isEquivalentVal: boolean = true
@@ -722,7 +746,7 @@ export struct EditTitleDialog {
.onClick(() => {
this.editTitleDialog.close()
inputMethod.getController().stopInputSession();
- if (this.inputName.replace(/\s+/g, '') == '') {
+ if (this.inputName.replace(new RegExp('/\s+/g'), '') == '') {
return
} else {
this.confirm(this.inputName)
@@ -742,14 +766,20 @@ export struct EditTitleDialog {
@CustomDialog
export struct EditContentDialogPortrait {
editContentDialogCtl: CustomDialogController;
- confirm: (excuteJs: string) => void
+ confirm: (excuteJs: string) => void = (excuteJs: string) => {
+ };
@State selectFontColor: string = fontColorArray[0]
@Consume('SelectedNoteData') selectedNoteData: NoteData
- private circleColor: string
- private fontSize: number
+ private circleColor: string = '';
+ private fontSize: number = 0;
aboutToAppear() {
- this.confirm("javascript:RICH_EDITOR.getFontSizes()")
+ try {
+ this.confirm('javascript:RICH_EDITOR.getFontSizes()');
+ LogUtil.info(TAG, `runJavaScript success.`);
+ } catch (error) {
+ LogUtil.error(TAG, `runJavaScript failed.code:${JSON.stringify(error.code)},message:${JSON.stringify(error.message)}`);
+ }
}
build() {
@@ -939,7 +969,7 @@ export struct EditContentDialogPortrait {
this.selectFontColor = colorStr
this.confirm("javascript:RICH_EDITOR.setTextColor('" + this.selectFontColor + "')")
})
- }, colorStr => colorStr)
+ }, (colorStr: string) => colorStr)
}
}
.height(48)
@@ -979,5 +1009,6 @@ export struct EditContentDialogPortrait {
.height(266)
.backgroundColor($r("app.color.color_ffffff"))
.borderRadius(36)
+ .offset({ y: -35 })
}
}
\ No newline at end of file
diff --git a/features/src/main/ets/components/FolderListComp.ets b/features/src/main/ets/components/FolderListComp.ets
index 02033558ed118398ef1da16645fd7964b6afc9fc..c5277f27f0abf521895ac6a47bafc694498eb3a2 100644
--- a/features/src/main/ets/components/FolderListComp.ets
+++ b/features/src/main/ets/components/FolderListComp.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -29,6 +29,7 @@ import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil
import FolderUtil from '@ohos/utils/src/main/ets/default/baseUtil/FolderUtil'
import NoteUtil from '@ohos/utils/src/main/ets/default/baseUtil/NoteUtil'
import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
+import webview from '@ohos.web.webview';
// Folder list component
@Component
@@ -37,7 +38,7 @@ export struct FolderListComp {
@Consume('SectionStatus') sectionStatus: number
@Consume('ExpandStatus') expandStatus: boolean // 笔记本折叠展开状态
@StorageLink('breakPoint') breakPoints: string = 'lg'
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
TAG = "FolderListComp"
@Consume('AsideWidth') asideWidth: number
@@ -78,7 +79,7 @@ export struct FolderListComp {
FolderItemComp({ folderItem: folderItem, controllerShow: this.controllerShow })
}
}
- }, folderItem => folderItem.name.toString())
+ }, (folderItem: FolderData) => folderItem.name.toString())
}
.width('100%')
.height(500)
@@ -90,18 +91,19 @@ export struct FolderListComp {
Column() {
FolderItemComp({
- folderItem: FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), SysDefFolderUuid.MyFavorites),
+ folderItem: FolderUtil.getFolderData(AppStorage.Get('AllFolderArray')!, SysDefFolderUuid.MyFavorites),
controllerShow: this.controllerShow
})
FolderItemComp({
- folderItem: FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), SysDefFolderUuid.RecentDeletes),
+ folderItem: FolderUtil.getFolderData(AppStorage.Get('AllFolderArray')!, SysDefFolderUuid.RecentDeletes),
controllerShow: this.controllerShow
})
}
.backgroundColor($r("app.color.folderlist_bgcolor_f1f3f5"))
.flexGrow(0)
.width("100%")
- .padding({ left: 12, right: 12, bottom: 24 })
+ .padding({ left: 12, right: 12, bottom: 60 })
+ .margin({ bottom: 65 })
}
.height("100%")
.backgroundColor($r('app.color.folder_color_d6d6d6'))
@@ -122,14 +124,22 @@ export struct NoteAndCreateComp {
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = AppStorage.Link('AllFolderArray')
@Consume('SelectedColor') selectedColor: string
@Consume('PortraitModel') portraitModel: boolean
- folderCreateDialogCtl: CustomDialogController = new CustomDialogController({
- builder: NewOrEditFolderDialog({ confirm: this.onCreateConfirm.bind(this), dialogType: 0 }),
+ folderCreateDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: NewOrEditFolderDialog({
+ confirm: (color: string, name: string) => {
+ this.onCreateConfirm(color, name)
+ }, dialogType: 0
+ }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
})
- folderCreateDialogCtlBottom: CustomDialogController = new CustomDialogController({
- builder: NewOrEditFolderDialog({ confirm: this.onCreateConfirm.bind(this), dialogType: 0 }),
+ folderCreateDialogCtlBottom: CustomDialogController | null = new CustomDialogController({
+ builder: NewOrEditFolderDialog({
+ confirm: (color: string, name: string) => {
+ this.onCreateConfirm(color, name)
+ }, dialogType: 0
+ }),
alignment: DialogAlignment.Bottom,
autoCancel: false,
customStyle: true,
@@ -144,7 +154,7 @@ export struct NoteAndCreateComp {
let folderData = new FolderData(0, name, new Date().getTime() + "", color, FolderType.CusDef, Delete.No, new Date().getTime(), new Date().getTime()) // 新的的笔记本都是自定义类型 type为1
this.AllFolderArray.push(folderData)
// insert folder to db
- RdbStoreUtil.insert(TableName.FolderTable, folderData.toFolderObject(), null)
+ RdbStoreUtil.insert(TableName.FolderTable, folderData.toFolderObject(), null);
AppStorage.SetOrCreate('isUpdate', true)
}
@@ -163,9 +173,9 @@ export struct NoteAndCreateComp {
.onClick(() => {
this.selectedColor = "#e84026" // 新建的时候选中第一个颜色
if (this.portraitModel) {
- this.folderCreateDialogCtlBottom.open()
+ this.folderCreateDialogCtlBottom!.open();
} else {
- this.folderCreateDialogCtl.open()
+ this.folderCreateDialogCtl!.open();
}
}).padding({ right: 0 })
}.width(50)
@@ -188,15 +198,17 @@ struct FolderItemComp {
@Consume('Longpress') longpress: boolean
@Consume('SelectedColor') selectedColor: string
@Consume('PortraitModel') portraitModel: boolean
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
@State isLongPress: boolean = false
- TAG = "FolderListComp"
+ TAG = 'FolderItemComp';
@StorageLink('isUpdate') isUpdate: boolean = false
// Folder Edit Dialog
- folderEditDialogCtl: CustomDialogController = new CustomDialogController({
+ folderEditDialogCtl: CustomDialogController | null = new CustomDialogController({
builder: NewOrEditFolderDialog({
editFolderUuid: this.folderItem.uuid,
- confirm: this.onEditConfirm.bind(this),
+ confirm: (color: string, name: string) => {
+ this.onEditConfirm(color, name);
+ },
dialogType: 1
}),
alignment: DialogAlignment.Center,
@@ -204,10 +216,12 @@ struct FolderItemComp {
customStyle: true,
})
// Folder Edit Dialog for portrait model
- folderEditDialogCtlBottom: CustomDialogController = new CustomDialogController({
+ folderEditDialogCtlBottom: CustomDialogController | null = new CustomDialogController({
builder: NewOrEditFolderDialog({
editFolderUuid: this.folderItem.uuid,
- confirm: this.onEditConfirm.bind(this),
+ confirm: (color: string, name: string) => {
+ this.onEditConfirm(color, name);
+ },
dialogType: 1
}),
alignment: DialogAlignment.Bottom,
@@ -235,16 +249,25 @@ struct FolderItemComp {
RdbStoreUtil.update(this.folderItem.toFolderObject(), predicates_folder, null)
this.isUpdate = true
}
+
// Folder Delete Dialog
- folderDeleteDialogCtl: CustomDialogController = new CustomDialogController({
- builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), deleteFileType: DeleteFileType.FolderData }),
+ folderDeleteDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: DeleteDialog({
+ onConfirm: () => {
+ this.onDeleteConfirm();
+ }, deleteFileType: DeleteFileType.FolderData
+ }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
})
// Folder Delete Dialog for portrait model
- folderDeleteDialogCtlBottom: CustomDialogController = new CustomDialogController({
- builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), deleteFileType: DeleteFileType.FolderData }),
+ folderDeleteDialogCtlBottom: CustomDialogController | null = new CustomDialogController({
+ builder: DeleteDialog({
+ onConfirm: () => {
+ this.onDeleteConfirm();
+ }, deleteFileType: DeleteFileType.FolderData
+ }),
alignment: DialogAlignment.Bottom,
autoCancel: false,
customStyle: true,
@@ -253,8 +276,8 @@ struct FolderItemComp {
onDeleteConfirm() {
let currentFolder = FolderUtil.getFolderData(this.AllFolderArray, this.folderItem.uuid)
let index = this.AllFolderArray.indexOf(currentFolder)
- let currentNoteDataArray = NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.folderItem.uuid)
- let deleteNoteDataArray = NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), 'sys_def_recentDeletes_uuid')
+ let currentNoteDataArray = NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray')!, this.folderItem.uuid)
+ let deleteNoteDataArray = NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray')!, 'sys_def_recentDeletes_uuid')
if (index > -1) {
this.AllFolderArray.splice(index, 1)
if (deleteNoteDataArray.length != 0) {
@@ -277,7 +300,7 @@ struct FolderItemComp {
// update note to db
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
- RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
+ RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null);
})
}
// delete folder from db
@@ -286,15 +309,20 @@ struct FolderItemComp {
RdbStoreUtil.delete(predicates_folder, null)
// update selectedFolderData and selectedNoteData
this.selectedFolderData = FolderUtil.getFolderData(this.AllFolderArray, SysDefFolderUuid.AllNotes)
- this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, SysDefFolderUuid.AllNotes)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, SysDefFolderUuid.AllNotes)!;
if (!this.selectedNoteData) {
return
}
// 刷新web界面
if (this.portraitModel == false) {
- this.controllerShow.runJavaScript(
- "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
- )
+ try {
+ this.controllerShow.runJavaScript(
+ "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
+ );
+ LogUtil.info(this.TAG, `runJavaScript success.`);
+ } catch (error) {
+ LogUtil.error(this.TAG, `runJavaScript failed.code:${JSON.stringify(error.code)},message:${JSON.stringify(error.message)}`);
+ }
}
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
@@ -303,20 +331,30 @@ struct FolderItemComp {
}
this.isUpdate = true
}
+
// Folder Create Dialog
- folderCreateDialogCtl: CustomDialogController = new CustomDialogController({
- builder: NewOrEditFolderDialog({ confirm: this.onCreateConfirm.bind(this), dialogType: 0 }),
+ folderCreateDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: NewOrEditFolderDialog({
+ confirm: (color: string, name: string) => {
+ this.onCreateConfirm(color, name);
+ }, dialogType: 0
+ }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
})
// Folder Create Dialog for portrait model
- folderCreateDialogCtlBottom: CustomDialogController = new CustomDialogController({
- builder: NewOrEditFolderDialog({ confirm: this.onCreateConfirm.bind(this), dialogType: 0 }),
+ folderCreateDialogCtlBottom: CustomDialogController | null = new CustomDialogController({
+ builder: NewOrEditFolderDialog({
+ confirm: (color: string, name: string) => {
+ this.onCreateConfirm(color, name);
+ }, dialogType: 0
+ }),
alignment: DialogAlignment.Bottom,
autoCancel: false,
customStyle: true,
})
+
// Folder Create Callback
onCreateConfirm(color: string, name: string) {
let folderData = new FolderData(0, name, new Date().getTime() + "", color, FolderType.CusDef, Delete.No, new Date().getTime(), new Date().getTime()) // 新的的笔记本都是自定义类型 type为1
@@ -337,9 +375,9 @@ struct FolderItemComp {
.onClick(() => {
this.selectedColor = this.folderItem.color
if (this.portraitModel) {
- this.folderEditDialogCtlBottom.open()
+ this.folderEditDialogCtlBottom!.open();
} else {
- this.folderEditDialogCtl.open()
+ this.folderEditDialogCtl!.open();
}
ContextMenu.close()
})
@@ -354,9 +392,9 @@ struct FolderItemComp {
.fontColor($r("app.color.folder_color_182431"))
.onClick(() => {
if (this.portraitModel) {
- this.folderDeleteDialogCtlBottom.open()
+ this.folderDeleteDialogCtlBottom!.open();
} else {
- this.folderDeleteDialogCtl.open()
+ this.folderDeleteDialogCtl!.open();
}
ContextMenu.close()
})
@@ -372,9 +410,9 @@ struct FolderItemComp {
.onClick(() => {
this.selectedColor = "#e84026" // 新建的时候选中第一个颜色
if (this.portraitModel) {
- this.folderCreateDialogCtlBottom.open()
+ this.folderCreateDialogCtlBottom!.open();
} else {
- this.folderCreateDialogCtl.open()
+ this.folderCreateDialogCtl!.open();
}
ContextMenu.close()
})
@@ -422,7 +460,7 @@ struct FolderItemComp {
.height(56)
.padding({ left: 12, right: 12 })
.backgroundColor(this.isLongPress ? $r("app.color.folder_color_19182431") : this.selectedFolderData.uuid == this.folderItem.uuid
- ? $r("app.color.folder_color_ffffff") : "#00FFFFFF")
+ ? $r("app.color.folder_color_ffffff") : "#00FFFFFF")
.bindContextMenu(this.menuBuilder, ResponseType.LongPress)
.bindContextMenu(this.menuBuilder, ResponseType.RightClick)
.onClick(() => {
@@ -431,15 +469,21 @@ struct FolderItemComp {
NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
} else {
this.selectedFolderData = this.folderItem
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.folderItem.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray')!, this.folderItem.uuid)!;
if (!this.selectedNoteData) {
return
}
// 刷新web界面
if (this.portraitModel == false) {
- this.controllerShow.runJavaScript(
- "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
- )
+ try {
+ this.controllerShow.runJavaScript(
+ "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
+ );
+ LogUtil.info(this.TAG, `onClick runJavaScript setHtml success.`);
+ } catch (error) {
+ LogUtil.error(this.TAG, `onClick runJavaScript setHtml failed,code:${JSON.stringify(error.code)},
+ message:${JSON.stringify(error.message)}.`);
+ }
}
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
@@ -483,22 +527,28 @@ struct FolderItemComp {
.height(56)
.padding({ left: 12, right: 12 })
.backgroundColor(this.isLongPress ? $r("app.color.folder_color_19182431") : this.selectedFolderData.uuid == this.folderItem.uuid
- ? $r("app.color.folder_color_ffffff") : "#00FFFFFF")
+ ? $r("app.color.folder_color_ffffff") : "#00FFFFFF")
.onClick(() => {
if (this.longpress) {
this.longpress = false
NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
} else {
this.selectedFolderData = this.folderItem
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.folderItem.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray')!, this.folderItem.uuid)!;
if (!this.selectedNoteData) {
return
}
// 刷新web界面
if (this.portraitModel == false) {
- this.controllerShow.runJavaScript(
- "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
- )
+ try {
+ this.controllerShow.runJavaScript(
+ "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
+ );
+ LogUtil.info(this.TAG, `else runJavaScript setHtml success.`);
+ } catch (error) {
+ LogUtil.error(this.TAG, `else runJavaScript setHtml failed.code:${JSON.stringify(error.code)},
+ message:${JSON.stringify(error.message)}`);
+ }
}
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
@@ -513,17 +563,17 @@ struct FolderItemComp {
.width('100%')
.height(56)
.parallelGesture(
- GestureGroup(GestureMode.Exclusive,
- LongPressGesture()
- .onAction(() => {
- this.isLongPress = true
- this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
- })
- .onActionEnd(() => {
- this.isLongPress = false
- this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
- })
- )
+ GestureGroup(GestureMode.Exclusive,
+ LongPressGesture()
+ .onAction(() => {
+ this.isLongPress = true;
+ this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0);
+ })
+ .onActionEnd(() => {
+ this.isLongPress = false;
+ this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0);
+ })
+ )
)
}
}
\ No newline at end of file
diff --git a/features/src/main/ets/components/NoteContent.ets b/features/src/main/ets/components/NoteContent.ets
index c3689252f7401c6bd4ede9f2705d8ff5ec72961b..09bb6b156a9e9f72be7a52452fe4d99f035b4ab9 100644
--- a/features/src/main/ets/components/NoteContent.ets
+++ b/features/src/main/ets/components/NoteContent.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -23,8 +23,9 @@ import {
NoteTableColumn,
SysDefFolderUuid,
Favorite,
- Delete
-} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData'
+ Delete,
+ FolderType
+} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData';
import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants'
import { EditContentDialog, EditTitleDialog } from './CusDialogComp'
import FolderUtil from '@ohos/utils/src/main/ets/default/baseUtil/FolderUtil'
@@ -34,19 +35,30 @@ import OperationUtils from '@ohos/utils/src/main/ets/default/baseUtil/OperationU
import router from '@system.router';
import inputMethod from '@ohos.inputMethod';
import { folderTextMap } from '@ohos/utils/src/main/ets/default/model/NoteBaseData'
+import webview from '@ohos.web.webview';
+import common from '@ohos.app.ability.common';
-const TAG = "NoteContent"
+const TAG: string = 'NoteContent';
-var timeID: number
+let timeID: number = 0;
+let noteContext = AppStorage.Get('noteContext')!;
+
+interface NoteContentType {
+ callbackhtml: (html: string) => void;
+ callbackImagePath: (imgName: string) => void;
+ callbackScheduledSave: (html: string) => void;
+ callbackPasteImage: (html: string) => void;
+ callbackGetSize: (fontSize: number) => void;
+}
@Component
export struct NoteContent {
- @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('NewNote')
+ @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('NewNote')!;
@StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
@Provide('Issave') issave: number = 0
@Provide('EditModel') editModel: boolean = false
@StorageLink('dpi') dpi: number = 240
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
private editContentFlag = false
@StorageLink('ScrollTopPercent') scrollTopPercent: number = 0.0
@@ -61,7 +73,7 @@ export struct NoteContent {
if (!AppStorage.Has('remoteScrollTopPercent')) {
return
}
- var scrollTopPercent = AppStorage.Get('remoteScrollTopPercent')
+ let scrollTopPercent = AppStorage.Get('remoteScrollTopPercent')!;
if (scrollTopPercent < 0) {
return
}
@@ -82,8 +94,8 @@ export struct NoteContent {
AppStorage.Delete('isRemoteFocusOnSearch')
}
- noteContent = {
- callbackhtml: (html) => {
+ noteContent: NoteContentType = {
+ callbackhtml: (html: string) => {
LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData.uuid)
this.selectedNoteData.content_text = NoteUtil.contrastInitType(this.selectedNoteData.content_text);
if (this.selectedNoteData.content_text === html ) {
@@ -102,13 +114,13 @@ export struct NoteContent {
AppStorage.SetOrCreate('ContinueNote', continueNote)
LogUtil.info(TAG, "callbackhtml, set continue note success")
},
- callbackImagePath: (imgName) => {
+ callbackImagePath: (imgName: string) => {
// updata note image
LogUtil.info(TAG, 'note imgPath is:' + imgName)
this.selectedNoteData.content_img = imgName
},
- callbackScheduledSave: (html) => {
+ callbackScheduledSave: (html: string) => {
LogUtil.info(TAG, 'callbackScheduledSave')
if (this.selectedNoteData.content_text == html) {
LogUtil.info(TAG, 'callbackScheduledSave the same value return')
@@ -126,14 +138,14 @@ export struct NoteContent {
AppStorage.SetOrCreate('ContinueNote', continueNote)
LogUtil.info(TAG, 'callbackScheduledSave, set continue note success')
},
- callbackPasteImage: (html) => {
+ callbackPasteImage: (html: string) => {
if (html) {
LogUtil.info(TAG, 'paste info' + html)
let realHtml = ""
- let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
+ let base64regex: RegExp = new RegExp('/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/');
if (html && html.indexOf("base64") > 0) {
LogUtil.info(TAG, " getSrcFromHtml, src[1] : " + html)
- let imgData = html.split(',')[1];
+ let imgData: string = html.split(',')[1];
let imgType = 'png'
if (html.indexOf("jpeg") > 0) {
imgType = 'jpg'
@@ -156,7 +168,7 @@ export struct NoteContent {
LogUtil.info(TAG, 'paste info22223')
}
},
- callbackGetSize: (fontSize) => {
+ callbackGetSize: (fontSize: number) => {
if (fontSize === 16) {
this.selectedNoteData.slider_value = 0
} else if (fontSize === 18) {
@@ -208,7 +220,7 @@ export struct NoteContent {
"RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')",
() => {
// wait for the image in the note to load
- setTimeout(function () {
+ setTimeout(() => {
self.restoreScrollTop()
self.restoreFocus()
}, 100)
@@ -232,7 +244,13 @@ export struct NoteContent {
clearInterval(timeID)
}
timeID = setInterval(() => {
- this.controllerShow.runJavaScript("scheduledSaveContent()")
+ try {
+ this.controllerShow.runJavaScript("scheduledSaveContent()");
+ LogUtil.info(TAG, `runJavaScript scheduledSaveContent success.`);
+ } catch (error) {
+ LogUtil.error(TAG, `runJavaScript scheduledSaveContent failed.code:${JSON.stringify(error.code)},
+ message:${JSON.stringify(error.message)}`);
+ }
}, 3000)
LogUtil.info(TAG, "setInterval timeID : " + timeID)
this.issave = 0
@@ -265,9 +283,11 @@ export struct ToolBarComp {
@StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
@Consume('Issave') issave: number
@Consume('EditModel') editModel: boolean
- controllerShow: WebviewController
- editContentDialogCtl: CustomDialogController = new CustomDialogController({
- builder: EditContentDialog({ confirm: this.confirm.bind(this) }),
+ controllerShow: webview.WebviewController = new webview.WebviewController();
+ editContentDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: EditContentDialog({ confirm: (newTitle: string) => {
+ this.confirm(newTitle);
+ } }),
alignment: DialogAlignment.Bottom,
autoCancel: true,
customStyle: true,
@@ -288,8 +308,15 @@ export struct ToolBarComp {
.height(24)
.width(24)
.onClick(() => {
- this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)")
- this.controllerShow.runJavaScript("getHtmlContent()")
+ try {
+ this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)");
+ this.controllerShow.runJavaScript("getHtmlContent()");
+ LogUtil.info(TAG, `runJavaScript setInputEnabled and getHtmlContent success.`);
+ } catch (error) {
+ LogUtil.error(TAG, `runJavaScript setInputEnabled and getHtmlContent fail.code:${JSON.stringify(error.code)},
+ message:${JSON.stringify(error.message)}`);
+ }
+
// 清除定时器
if (timeID != undefined) {
LogUtil.info(TAG, "zoom, clearInterval timeID : " + timeID)
@@ -331,7 +358,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
// 清单
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.setTodo()")
@@ -347,10 +373,9 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
LogUtil.info(TAG, 'editContentDialogCtl start')
- this.editContentDialogCtl.open()
+ this.editContentDialogCtl!.open();
})
}.width(42)
.height(42)
@@ -361,27 +386,26 @@ export struct ToolBarComp {
Image($r('app.media.picture_white')).height(24).width(24)
.onClick(async () => {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
LogUtil.info(TAG, 'startAbility start')
- await globalThis.noteContext.startAbilityForResult({
+ await noteContext.startAbilityForResult({
parameters: { uri: "singleselect" },
bundleName: "com.ohos.photos",
abilityName: "com.ohos.photos.MainAbility",
})
- .then(v => {
+ .then((v: common.AbilityResult) => {
let want = v['want'];
if (want != null && want != undefined) {
let param = want['parameters'];
let imageUri = ""
if (param != null && param != undefined) {
- let uri = param['select-item-list'];
+ let uri = param['select-item-list'] as Record;
imageUri = uri[0];
}
// 拷贝
if (imageUri != null && imageUri != "") {
OperationUtils.copy(imageUri).then((uriPath) => {
- var path = "file://" + uriPath
+ let path = 'file://' + uriPath;
LogUtil.info(TAG, 'image uri is:' + path)
this.controllerShow.runJavaScript(
"javascript:RICH_EDITOR.insertImage('" + path + "')"
@@ -405,7 +429,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("RICH_EDITOR.undo()")
})
@@ -420,7 +443,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("RICH_EDITOR.redo()")
})
@@ -458,8 +480,10 @@ export struct NoteContentOverViewComp {
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = []
@StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
@StorageLink('isUpdate') isUpdate: boolean = false
- editTitleDialogCtl: CustomDialogController = new CustomDialogController({
- builder: EditTitleDialog({ confirm: this.confirm.bind(this) }),
+ editTitleDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: EditTitleDialog({ confirm: (newTitle: string) => {
+ this.confirm(newTitle);
+ } }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
@@ -485,7 +509,7 @@ export struct NoteContentOverViewComp {
@Builder MenuBuilder() {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
List() {
- ForEach(this.AllFolderArray, (item) => {
+ ForEach(this.AllFolderArray, (item: FolderData) => {
ListItem() {
NoteDataMoveItemComp({ folderItem: item })
}
@@ -500,7 +524,7 @@ export struct NoteContentOverViewComp {
LogUtil.info(TAG, "NoteContentOverViewComp MenuBuilder, set continue note success")
NoteUtil.refreshAll()
})
- }, noteItem => JSON.stringify(noteItem))
+ }, (noteItem: NoteData) => JSON.stringify(noteItem))
}.listDirection(Axis.Vertical)
.edgeEffect(EdgeEffect.Spring)
.height(this.AllFolderArray.length > 12 ? 504 : (this.AllFolderArray.length - 3) * 56)
@@ -521,7 +545,7 @@ export struct NoteContentOverViewComp {
.margin({ left: 12, right: 24 })
.onClick(() => {
clearInterval(timeID)
- this.editTitleDialogCtl.open()
+ this.editTitleDialogCtl!.open();
})
}.height(40)
.width(StyleConstants.PERCENTAGE_100)
@@ -535,7 +559,7 @@ export struct NoteContentOverViewComp {
.margin({ left: 12 })
Row() {
Text(FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData.folder_uuid)) ==
- folderTextMap["sys_def_myFavorites_uuid"] ? folderTextMap["sys_def_unClassified_uuid"] :
+ folderTextMap.sys_def_myFavorites_uuid ? folderTextMap.sys_def_unClassified_uuid :
FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData.folder_uuid)))
.id(this.isUpdate + '')
.fontSize(12)
@@ -548,7 +572,7 @@ export struct NoteContentOverViewComp {
.padding({ left: 8, right: 8, top: 4, bottom: 4 })
.margin({ left: 8 })
.borderRadius(16)
- .backgroundColor(NoteUtil.getNoteBgColor(AppStorage.Get('AllFolderArray'), this.selectedNoteData.folder_uuid, SysDefFolderUuid.AllNotes, false))
+ .backgroundColor(NoteUtil.getNoteBgColor(AppStorage.Get('AllFolderArray')!, this.selectedNoteData.folder_uuid, SysDefFolderUuid.AllNotes, false))
.bindMenu(this.MenuBuilder)
}.alignItems(VerticalAlign.Top).height(40).width(StyleConstants.PERCENTAGE_100)
}
@@ -563,7 +587,7 @@ export struct NoteContentOverViewComp {
struct NoteDataMoveItemComp {
@StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = []
- private folderItem: FolderData
+ private folderItem: FolderData = new FolderData(0, '', new Date().getTime() + '', '', FolderType.CusDef, Delete.No, new Date().getTime(), new Date().getTime());
build() {
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.Center }) {
diff --git a/features/src/main/ets/components/NoteContentComp.ets b/features/src/main/ets/components/NoteContentComp.ets
index 555d401d1029780e128b467819a1fcfd45136850..d932cf848c7946717dc53f7c28e11926b18a3d79 100644
--- a/features/src/main/ets/components/NoteContentComp.ets
+++ b/features/src/main/ets/components/NoteContentComp.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -22,8 +22,9 @@ import {
NoteTableColumn,
SysDefFolderUuid,
Favorite,
- Delete
-} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData'
+ Delete,
+ FolderType
+} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData';
import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants'
import { EditContentDialog, DeleteDialog, EditTitleDialog } from './CusDialogComp'
import FolderUtil from '@ohos/utils/src/main/ets/default/baseUtil/FolderUtil'
@@ -35,14 +36,28 @@ import OperationUtils from '@ohos/utils/src/main/ets/default/baseUtil/OperationU
import mediaquery from '@ohos.mediaquery'
import inputMethod from '@ohos.inputMethod';
import { folderTextMap } from '@ohos/utils/src/main/ets/default/model/NoteBaseData'
-import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
+import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
+import webview from '@ohos.web.webview';
+import common from '@ohos.app.ability.common';
+import { BusinessError } from '@ohos.base';
+import resourceManager from '@ohos.resourceManager';
const TAG = "NoteContentComp"
-var timeId: number
+let timeId: number = 0;
+let noteContext = AppStorage.Get('noteContext')!;
// Note content component
-let inSetValue = AppStorage.Link('inSetValue')
+let inSetValue: string = AppStorage.Link('inSetValue');
+
+interface NoteContentType {
+ callbackhtml: (html: string) => void;
+ callbackImagePath: (imgName: string) => void;
+ callbackhtmlSave: (html: string) => void;
+ callbackScheduledSave: (html: string) => void;
+ callbackPasteImage: (html: string) => void;
+ callbackGetSize: (fontSize: number) => void;
+}
@Component
export struct NoteContentComp {
@@ -56,7 +71,7 @@ export struct NoteContentComp {
@Consume('Issave') issave: number
@Consume('Search') search: boolean
@StorageLink('dpi') dpi: number = 240
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
private editContentFlag = false
@State uri1: string = ""
private context = getContext(this)
@@ -69,7 +84,13 @@ export struct NoteContentComp {
if (!this.refreshCurrentNote) {
return
}
- this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')")
+ try {
+ this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')");
+ LogUtil.info(TAG, `runJavaScript setHtml success.`);
+ } catch (error) {
+ LogUtil.error(TAG, `runJavaScript setHtml failed.code:${JSON.stringify(error.code)},
+ message:${JSON.stringify(error.message)}`);
+ }
this.refreshCurrentNote = false
}
@@ -84,7 +105,7 @@ export struct NoteContentComp {
if (!AppStorage.Has('remoteScrollTopPercent')) {
return
}
- var scrollTopPercent = AppStorage.Get('remoteScrollTopPercent')
+ let scrollTopPercent = AppStorage.Get('remoteScrollTopPercent')!;
if (scrollTopPercent < 0) {
return
}
@@ -104,7 +125,7 @@ export struct NoteContentComp {
AppStorage.Delete('isRemoteFocusOnSearch')
}
- noteContent = {
+ noteContent: NoteContentType = {
callbackhtml: (html) => {
LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData.uuid)
this.selectedNoteData.content_text = NoteUtil.contrastInitType(this.selectedNoteData.content_text);
@@ -169,7 +190,7 @@ export struct NoteContentComp {
if (html) {
LogUtil.info(TAG, 'paste info' + html)
let realHtml = ""
- let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
+ let base64regex: RegExp = new RegExp('/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/');
if (html && html.indexOf("base64") > 0) {
LogUtil.info(TAG, " getSrcFromHtml, src[1] : " + html)
let imgData = html.split(',')[1];
@@ -252,7 +273,7 @@ export struct NoteContentComp {
"RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')",
() => {
// wait for the image in the note to load
- setTimeout(function () {
+ setTimeout(() => {
self.restoreScrollTop()
self.restoreFocus()
}, 100)
@@ -342,10 +363,12 @@ export struct NoteContentOverViewComp {
@Consume('SectionStatus') sectionStatus: number
@Consume('RefreshFlag') refreshFlag: number
@StorageLink('isUpdate') isUpdate: boolean = false
- NoteDataMoveArray: FolderData[]
- controllerShow: WebviewController
- editTitleDialogCtl: CustomDialogController = new CustomDialogController({
- builder: EditTitleDialog({ confirm: this.confirm.bind(this) }),
+ NoteDataMoveArray: FolderData[] = [];
+ controllerShow: webview.WebviewController = new webview.WebviewController();
+ editTitleDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: EditContentDialog({ confirm: (newTitle: string) => {
+ this.confirm(newTitle);
+ } }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
@@ -386,7 +409,7 @@ export struct NoteContentOverViewComp {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
List() {
if (this.NoteDataMoveArray !== undefined && this.NoteDataMoveArray !== null && this.NoteDataMoveArray !== []) {
- ForEach(this.NoteDataMoveArray, (item) => {
+ ForEach(this.NoteDataMoveArray, (item: FolderData) => {
ListItem() {
NoteDataMoveItemCompTablet({ folderItem: item, uuid: this.selectedNoteData.folder_uuid })
}
@@ -396,7 +419,7 @@ export struct NoteContentOverViewComp {
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
if (this.sectionStatus != 1) {
- this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid)!;
this.controllerShow.runJavaScript(
"RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
)
@@ -410,7 +433,7 @@ export struct NoteContentOverViewComp {
LogUtil.info(TAG, "NoteContentOverViewComp, MenuBuilder, set continue note success")
NoteUtil.refreshAll()
})
- }, noteItem => noteItem.uuid)
+ }, (noteItem: NoteData) => noteItem.uuid)
}
}.listDirection(Axis.Vertical)
.edgeEffect(EdgeEffect.Spring)
@@ -432,7 +455,7 @@ export struct NoteContentOverViewComp {
.margin({ left: 0, right: 24 })
.onClick(() => {
clearInterval(timeId)
- this.editTitleDialogCtl.open()
+ this.editTitleDialogCtl!.open();
// save continue data
AppStorage.SetOrCreate('ContinueSection', this.sectionStatus)
LogUtil.info(TAG, "NoteContentComp, set continue section success")
@@ -449,7 +472,7 @@ export struct NoteContentOverViewComp {
.margin({ left: 0 })
Row() {
Text(FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData.folder_uuid)) ==
- folderTextMap["sys_def_myFavorites_uuid"] ? folderTextMap["sys_def_unClassified_uuid"] :
+ folderTextMap.sys_def_myFavorites_uuid ? folderTextMap.sys_def_unClassified_uuid :
FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData.folder_uuid)))
.id(this.isUpdate + '')
.fontSize(12)
@@ -487,10 +510,12 @@ export struct ToolBarComp {
@StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
@Consume('EditModel') editModel: boolean
@Consume('Issave') issave: number
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
private context = getContext(this)
- noteDataDeleteDialogCtl: CustomDialogController = new CustomDialogController({
- builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this) }),
+ noteDataDeleteDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: DeleteDialog({ onConfirm: () => {
+ this.onDeleteConfirm();
+ } }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
@@ -509,7 +534,7 @@ export struct ToolBarComp {
// update note to db
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
- RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
+ RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null);
} else {
NoteUtil.removeNoteData(this.AllNoteArray, this.selectedNoteData.uuid)
// delete note from db
@@ -518,8 +543,12 @@ export struct ToolBarComp {
RdbStoreUtil.delete(predicates_note, null)
}
this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
- this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')")
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)!;
+ try {
+ this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text! + "')");
+ } catch (error) {
+ LogUtil.error(TAG, `setHtml error. code:${JSON.stringify(error.code)},message:${error.message}`);
+ }
this.chooseNote = false
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
@@ -528,8 +557,10 @@ export struct ToolBarComp {
AppStorage.SetOrCreate('isUpdate', true)
}
- editContentDialogCtl: CustomDialogController = new CustomDialogController({
- builder: EditContentDialog({ confirm: this.confirm.bind(this) }),
+ editContentDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: EditContentDialog({ confirm: (newTitle: string) => {
+ this.confirm(newTitle);
+ } }),
alignment: DialogAlignment.Bottom,
autoCancel: true,
customStyle: true,
@@ -561,7 +592,6 @@ export struct ToolBarComp {
LogUtil.info(TAG, "close note" + this.selectedNoteData.uuid)
this.controllerShow.runJavaScript("saveHtmlContent()")
//退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
// 清除定时器
if (timeId != undefined) {
@@ -587,7 +617,7 @@ export struct ToolBarComp {
.height(24)
.width(24)
.onClick(() => {
- this.noteDataDeleteDialogCtl.open()
+ this.noteDataDeleteDialogCtl!.open();
})
Image($r('app.media.recover'))
.height(24)
@@ -595,13 +625,13 @@ export struct ToolBarComp {
.onClick(() => {
this.selectedNoteData.is_deleted = Delete.No
this.selectedNoteData.deleted_time = 0
- let context: any = getContext(this)
- let resource = {
+ let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+ let resource: resourceManager.Resource = {
bundleName: "com.ohos.note",
moduleName: "default",
id: $r('app.string.restore').id
};
- context.resourceManager.getString(resource, (error, value) => {
+ context.resourceManager.getStringValue(resource, (error: BusinessError, value: string) => {
if (error != null) {
LogUtil.error(TAG, "error is " + error);
} else {
@@ -615,10 +645,10 @@ export struct ToolBarComp {
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)!;
this.controllerShow.runJavaScript(
- "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
- )
+ "RICH_EDITOR.setHtml('" + this.selectedNoteData!.content_text + "')"
+ );
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
AppStorage.SetOrCreate('ContinueNote', continueNote)
@@ -636,7 +666,6 @@ export struct ToolBarComp {
// 清单
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.setTodo()")
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
})
}.width(42)
@@ -650,9 +679,8 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
- this.editContentDialogCtl.open()
+ this.editContentDialogCtl!.open();
})
}.width(42)
.height(42)
@@ -664,13 +692,12 @@ export struct ToolBarComp {
.height(24)
.width(24)
.onClick(async () => {
- let permissionList: Array = [
+ let permissionList: Permissions[] = [
"ohos.permission.READ_MEDIA",
"ohos.permission.WRITE_MEDIA",
]
- let context: any = getContext(this);
+ let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
let AtManager = abilityAccessCtrl.createAtManager();
- // @ts-ignore
await AtManager.requestPermissionsFromUser(context, permissionList).then((data) => {
LogUtil.info(TAG, 'data permissions : ' + data.permissions)
LogUtil.info(TAG, 'data result: ' + data.authResults)
@@ -679,31 +706,30 @@ export struct ToolBarComp {
sum += data.authResults[i]
}
LogUtil.info(TAG, 'request permissions sum: ' + sum)
- }).catch((err) => {
+ }).catch((err: BusinessError) => {
LogUtil.warn(TAG, 'failed to requestPermissionsFromUser : ' + err.code);
})
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
LogUtil.info(TAG, 'startAbility start')
- await globalThis.noteContext.startAbilityForResult({
+ await noteContext.startAbilityForResult({
parameters: { uri: "singleselect" },
bundleName: "com.ohos.photos",
abilityName: "com.ohos.photos.MainAbility",
})
- .then(v => {
+ .then((v: common.AbilityResult) => {
let want = v['want'];
if (want != null && want != undefined) {
let param = want['parameters'];
let imageUri = ""
if (param != null && param != undefined) {
let uri = param['select-item-list'];
- imageUri = uri;
+ imageUri = uri as string;
}
// 拷贝
if (imageUri != null && imageUri != "") {
OperationUtils.copy(imageUri).then((uriPath) => {
- var path = "file://" + uriPath
+ let path = 'file://' + uriPath;
LogUtil.info(TAG, 'image uri is:' + path)
this.controllerShow.runJavaScript(
"javascript:RICH_EDITOR.insertImage('" + path + "')"
@@ -728,7 +754,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("RICH_EDITOR.undo()")
})
@@ -743,7 +768,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("RICH_EDITOR.redo()")
})
@@ -786,7 +810,7 @@ export struct ToolBarComp {
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
if (this.selectedFolderData.uuid === SysDefFolderUuid.MyFavorites) {
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.MyFavorites)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray')!, SysDefFolderUuid.MyFavorites)!;
this.controllerShow.runJavaScript(
"RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
)
@@ -804,7 +828,7 @@ export struct ToolBarComp {
.height(24)
.width(24)
.onClick(() => {
- this.noteDataDeleteDialogCtl.open()
+ this.noteDataDeleteDialogCtl!.open();
})
}.width(72)
}
@@ -820,8 +844,8 @@ struct NoteDataMoveItemCompTablet {
@StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = []
@StorageLink('isUpdate') isUpdate: boolean = false
- folderItem: FolderData
- uuid: String
+ folderItem: FolderData = new FolderData(0, '', new Date().getTime() + '', '', FolderType.CusDef, Delete.No, new Date().getTime(), new Date().getTime());
+ uuid: string = '';
build() {
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.Center }) {
diff --git a/features/src/main/ets/components/NoteContentCompPortrait.ets b/features/src/main/ets/components/NoteContentCompPortrait.ets
index 58acc08e598487213006e27e39fd59761a40458b..adf3553e30ba4950b02aa514394723168c81fab4 100644
--- a/features/src/main/ets/components/NoteContentCompPortrait.ets
+++ b/features/src/main/ets/components/NoteContentCompPortrait.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -23,8 +23,9 @@ import {
NoteTableColumn,
SysDefFolderUuid,
Favorite,
- Delete
-} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData'
+ Delete,
+ FolderType
+} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData';
import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants'
import { EditContentDialogPortrait, DeleteDialog, EditTitleDialog } from './CusDialogComp'
import FolderUtil from '@ohos/utils/src/main/ets/default/baseUtil/FolderUtil'
@@ -35,12 +36,30 @@ import OperationUtils from '@ohos/utils/src/main/ets/default/baseUtil/OperationU
import router from '@system.router'
import inputMethod from '@ohos.inputMethod';
import { folderTextMap } from '@ohos/utils/src/main/ets/default/model/NoteBaseData'
-import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
+import abilityAccessCtrl,{ Permissions } from '@ohos.abilityAccessCtrl';
+import webview from '@ohos.web.webview';
+import { BusinessError } from '@ohos.base';
+import resourceManager from '@ohos.resourceManager';
+import common from '@ohos.app.ability.common';
+import window from '@ohos.window';
-var time_id: number
+let time_id: number = 0;
+let noteContext = AppStorage.Get('noteContext')!;
const TAG = "NoteContentCompPortrait"
+interface NoteContentType {
+ callbackhtml: (html: string) => void;
+ callbackImagePath: (imgName: string) => void;
+ callbackScheduledSave: (html: string) => void;
+ callbackPasteImage: (html: string) => void;
+ callbackGetSize: (fontSize: number) => void;
+ addToDo: () => void;
+ chooseStyle: () => void;
+ openAlbum: () => Promise;
+ getBreakPoint: () => void;
+}
+
async function routePage() {
try {
await router.back()
@@ -52,21 +71,27 @@ async function routePage() {
// Note content component
@Component
export struct NoteContentCompPortrait {
- @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('NewNote')
- @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get("NewFolder")
+ @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('NewNote')!;
+ @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get("NewFolder")!;
@StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
@Provide('EditModel') editModel: boolean = false
@StorageLink('dpi') dpi: number = 240
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
private editContentFlag = false
private isClickBack: boolean = false
@StorageLink('ScrollTopPercent') scrollTopPercent: number = 0.0
- editContentDialogCtl: CustomDialogController = new CustomDialogController({
- builder: EditContentDialogPortrait({ confirm: this.confirm.bind(this) }),
+ editContentDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: EditContentDialogPortrait({
+ confirm: (newTitle: string) => {
+ this.confirm(newTitle);
+ }
+ }),
alignment: DialogAlignment.Bottom,
autoCancel: true,
customStyle: true,
})
+ @StorageLink('topHeight') topHeight: number = 0; // 窗口规避区域高
+ @StorageLink('topWidth') topWidth: number = 0; // 窗口规避区域宽
confirm(excuteJs: string) {
this.controllerShow.runJavaScript(excuteJs)
@@ -84,7 +109,7 @@ export struct NoteContentCompPortrait {
if (!AppStorage.Has('remoteScrollTopPercent')) {
return
}
- var scrollTopPercent = AppStorage.Get('remoteScrollTopPercent')
+ let scrollTopPercent = AppStorage.Get('remoteScrollTopPercent')!;
if (scrollTopPercent < 0) {
return
}
@@ -108,7 +133,7 @@ export struct NoteContentCompPortrait {
AppStorage.Delete('isRemoteFocusOnSearch')
}
- noteContent = {
+ noteContent: NoteContentType = {
callbackhtml: (html) => {
LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData?.uuid)
this.selectedNoteData.content_text = NoteUtil.contrastInitType(this.selectedNoteData.content_text);
@@ -153,7 +178,7 @@ export struct NoteContentCompPortrait {
if (html) {
LogUtil.info(TAG, 'paste info' + html)
let realHtml = ""
- let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
+ let base64regex: RegExp = new RegExp('/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/');
if (html && html.indexOf("base64") > 0) {
LogUtil.info(TAG, " getSrcFromHtml, src[1] : " + html)
let imgData = html.split(',')[1];
@@ -197,16 +222,15 @@ export struct NoteContentCompPortrait {
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.setTodo()")
},
chooseStyle: () => {
- this.editContentDialogCtl.open()
+ this.editContentDialogCtl!.open();
},
openAlbum: async () => {
- let permissionList: Array = [
- "ohos.permission.READ_MEDIA",
- "ohos.permission.WRITE_MEDIA",
+ let permissionList: Permissions[] = [
+ "ohos.permission.READ_IMAGEVIDEO",
+ "ohos.permission.WRITE_IMAGEVIDEO"
]
- let context: any = AppStorage.Get("context");
+ let context: common.UIAbilityContext = AppStorage.Get("context")!;
let AtManager = abilityAccessCtrl.createAtManager();
- // @ts-ignore
await AtManager.requestPermissionsFromUser(context, permissionList).then((data) => {
LogUtil.info(TAG, 'data permissions : ' + data.permissions)
LogUtil.info(TAG, 'data result: ' + data.authResults)
@@ -215,28 +239,28 @@ export struct NoteContentCompPortrait {
sum += data.authResults[i]
}
LogUtil.info(TAG, 'request permissions sum: ' + sum)
- }).catch((err) => {
+ }).catch((err: BusinessError) => {
LogUtil.warn(TAG, 'failed to requestPermissionsFromUser : ' + err.code);
})
LogUtil.info(TAG, 'startAbility start')
- await globalThis.noteContext.startAbilityForResult({
- parameters: { uri: "singleselect" },
+ await noteContext.startAbilityForResult({
+ parameters: { uri: "singleselect", filterMediaType: "FILTER_MEDIA_TYPE_IMAGE" },
bundleName: "com.ohos.photos",
abilityName: "com.ohos.photos.MainAbility",
- }).then(v => {
+ }).then((v: common.AbilityResult) => {
let want = v['want'];
if (want != null && want != undefined) {
let param = want['parameters'];
let imageUri = ""
if (param != null && param != undefined) {
- let uri = param['select-item-list'];
+ let uri = param['select-item-list'] as Record;
imageUri = uri[0];
}
LogUtil.info(TAG, "image url" + imageUri)
// 拷贝
if (imageUri != null && imageUri != "") {
OperationUtils.copy(imageUri).then((uriPath) => {
- var path = "file://" + uriPath
+ let path = 'file://' + uriPath;
LogUtil.info(TAG, 'image uri is:' + path)
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.getFocus()")
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.insertImage('" + path + "')")
@@ -255,6 +279,10 @@ export struct NoteContentCompPortrait {
Flex({ direction: FlexDirection.Column, wrap: FlexWrap.NoWrap,
alignItems: ItemAlign.Start, alignContent: FlexAlign.SpaceAround }) {
Column() {
+ // 窗口顶部规避区域
+ Row()
+ .width(px2vp(this.topWidth))
+ .height(px2vp(this.topHeight))
ToolBarComp({ controllerShow: this.controllerShow })
NoteContentOverViewComp()
.enabled(this.selectedNoteData && this.selectedNoteData?.is_deleted == Delete.Yes ? false : true)
@@ -285,7 +313,7 @@ export struct NoteContentCompPortrait {
"RICH_EDITOR.setHtml('" + this.selectedNoteData?.content_text + "')",
() => {
// wait for the image in the note to load
- setTimeout(function () {
+ setTimeout(() => {
self.restoreScrollTop()
self.restoreFocus()
}, 100)
@@ -324,6 +352,7 @@ export struct NoteContentCompPortrait {
this.editModel = true
})
}
+ .height('100%')
.enabled(this.selectedNoteData && this.selectedNoteData?.is_deleted == Delete.Yes ? false : true)
.flexShrink(1)
.margin({ top: 16 })
@@ -331,7 +360,6 @@ export struct NoteContentCompPortrait {
}
.flexShrink(1)
.padding({ left: 24, right: 24 })
-
DeleteNoteComp()
}
.expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM])
@@ -342,6 +370,9 @@ export struct NoteContentCompPortrait {
aboutToAppear(): void {
this.isClickBack = false
LogUtil.info(TAG, "aboutToAppear")
+ window.getLastWindow(getContext(this)).then(currentWindow => {
+ currentWindow.setWindowLayoutFullScreen(true);
+ })
}
aboutToDisappear(): void {
@@ -359,9 +390,13 @@ export struct NoteContentOverViewComp {
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = []
@StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
@StorageLink('isUpdate') isUpdate: boolean = false
- NoteDataMoveArray: FolderData[]
- editTitleDialogCtl: CustomDialogController = new CustomDialogController({
- builder: EditTitleDialog({ confirm: this.confirm.bind(this) }),
+ NoteDataMoveArray: FolderData[] = [];
+ editTitleDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: EditTitleDialog({
+ confirm: (newTitle: string) => {
+ this.confirm(newTitle);
+ }
+ }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
@@ -398,7 +433,7 @@ export struct NoteContentOverViewComp {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
List() {
if (this.NoteDataMoveArray !== undefined && this.NoteDataMoveArray !== null && this.NoteDataMoveArray !== []) {
- ForEach(this.NoteDataMoveArray, (item) => {
+ ForEach(this.NoteDataMoveArray, (item: FolderData) => {
ListItem() {
NoteDataMoveItemCompMenu({ folderItem: item, uuid: this.selectedNoteData?.folder_uuid })
}
@@ -413,7 +448,7 @@ export struct NoteContentOverViewComp {
LogUtil.info(TAG, 'MenuBuilder, set continue note success')
NoteUtil.refreshAll()
})
- }, noteItem => noteItem?.uuid)
+ }, (noteItem: NoteData) => noteItem?.uuid)
}
}
.margin({ top: 4, bottom: 4 })
@@ -437,7 +472,7 @@ export struct NoteContentOverViewComp {
.fontSize(30).fontWeight(FontWeight.Medium)
.onClick(() => {
clearInterval(time_id)
- this.editTitleDialogCtl.open()
+ this.editTitleDialogCtl!.open();
})
}.height(40)
.width(StyleConstants.PERCENTAGE_100)
@@ -450,7 +485,7 @@ export struct NoteContentOverViewComp {
.fontColor($r("app.color.modified_time_font_color"))
Row() {
Text(FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData?.folder_uuid)) ==
- folderTextMap["sys_def_myFavorites_uuid"] ? folderTextMap["sys_def_unClassified_uuid"] :
+ folderTextMap.sys_def_myFavorites_uuid ? folderTextMap.sys_def_unClassified_uuid :
FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData?.folder_uuid)))
.id(this.isUpdate + '')
.fontColor($r('app.color.folder_color_99182431'))
@@ -481,7 +516,7 @@ export struct ToolBarComp {
@Consume('SelectedFolderData') selectedFolderData: FolderData
@Consume('EditModel') editModel: boolean
@StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
onDeleteConfirm() {
if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) {
@@ -503,8 +538,12 @@ export struct ToolBarComp {
AppStorage.SetOrCreate('isUpdate', true)
}
- noteDataDeleteDialogCtl: CustomDialogController = new CustomDialogController({
- builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }),
+ noteDataDeleteDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: DeleteDialog({
+ onConfirm: () => {
+ this.onDeleteConfirm();
+ }, multiSelect: true
+ }),
alignment: DialogAlignment.Bottom,
autoCancel: false,
customStyle: true,
@@ -552,7 +591,7 @@ export struct ToolBarComp {
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid)
RdbStoreUtil.update(this.selectedNoteData?.toNoteObject(), predicates_note, null)
if (this.selectedFolderData?.uuid === SysDefFolderUuid.MyFavorites) {
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.MyFavorites)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.MyFavorites)!;
if (!this.selectedNoteData) {
routePage()
}
@@ -571,7 +610,7 @@ export struct ToolBarComp {
})
Image($r('app.media.delete')).height(24).width(24)
.onClick(() => {
- this.noteDataDeleteDialogCtl.open()
+ this.noteDataDeleteDialogCtl!.open();
})
}.width(72)
.visibility(this.selectedNoteData?.is_deleted == Delete.Yes ? Visibility.None : Visibility.Visible)
@@ -582,7 +621,6 @@ export struct ToolBarComp {
.onClick(() => {
try {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.undo()")
} catch (error) {
@@ -599,7 +637,6 @@ export struct ToolBarComp {
.onClick(() => {
try {
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.redo()")
} catch (error) {
@@ -644,8 +681,12 @@ export struct DeleteNoteComp {
@Consume('SelectedFolderData') selectedFolderData: FolderData
@Consume('RefreshFlag') refreshFlag: number
@Consume('SelectedNoteData') selectedNoteData: NoteData;
- noteDataDeleteDialogCtlBottom: CustomDialogController = new CustomDialogController({
- builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }),
+ noteDataDeleteDialogCtlBottom: CustomDialogController | null = new CustomDialogController({
+ builder: DeleteDialog({
+ onConfirm: () => {
+ this.onDeleteConfirm();
+ }, multiSelect: true
+ }),
alignment: DialogAlignment.Bottom,
autoCancel: false,
customStyle: true,
@@ -684,7 +725,7 @@ export struct DeleteNoteComp {
.height(24)
.responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
.onClick(() => {
- this.noteDataDeleteDialogCtlBottom.open()
+ this.noteDataDeleteDialogCtlBottom!.open();
})
Text($r("app.string.delete"))
.fontSize(10)
@@ -695,6 +736,7 @@ export struct DeleteNoteComp {
.width(180)
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
+ .offset({ y: -50 })
Column() {
Image($r('app.media.recover'))
@@ -704,13 +746,13 @@ export struct DeleteNoteComp {
.onClick(() => {
this.selectedNoteData.is_deleted = Delete.No
this.selectedNoteData.deleted_time = 0
- let context: any = getContext(this)
- let resource = {
+ let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+ let resource: resourceManager.Resource = {
bundleName: "com.ohos.note",
moduleName: "default",
id: $r('app.string.restore').id
};
- context.resourceManager.getString(resource, (error, value) => {
+ context.resourceManager.getStringValue(resource, (error: BusinessError, value: string) => {
if (error != null) {
LogUtil.error(TAG, "error is " + error);
} else {
@@ -733,6 +775,7 @@ export struct DeleteNoteComp {
.width(180)
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
+ .offset({ y: -50 })
}
.width(360)
.height(56)
@@ -746,8 +789,8 @@ struct NoteDataMoveItemCompMenu {
@StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = []
@StorageLink('isUpdate') isUpdate: boolean = false
- folderItem: FolderData
- uuid: String
+ folderItem: FolderData = new FolderData(0, '', new Date().getTime() + '', '', FolderType.CusDef, Delete.No, new Date().getTime(), new Date().getTime());
+ uuid: string = '';
build() {
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.Center }) {
diff --git a/features/src/main/ets/components/NoteListComp.ets b/features/src/main/ets/components/NoteListComp.ets
index f56149e294213bf228dfe653782233a152e0d77c..e9e2ef3ecd44898100e36b0f0dd999ab3d9608ae 100644
--- a/features/src/main/ets/components/NoteListComp.ets
+++ b/features/src/main/ets/components/NoteListComp.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -23,8 +23,9 @@ import {
Favorite,
Delete,
Top,
- NoteType
-} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData'
+ NoteType,
+ FolderType
+} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData';
import { NoteDataMoveDialog, DeleteDialog } from './CusDialogComp'
import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil'
import prompt from '@system.prompt'
@@ -34,11 +35,19 @@ import SearchModel from '@ohos/utils/src/main/ets/default/model/searchModel/Sear
import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
import router from '@ohos.router';
import inputMethod from '@ohos.inputMethod';
+import webview from '@ohos.web.webview';
+import resourceManager from '@ohos.resourceManager';
+import common from '@ohos.app.ability.common';
+import { BusinessError } from '@ohos.base';
const TAG = "NoteListComp"
+interface RouteOption {
+ url: string;
+}
+
function routePage() {
- let options = {
+ let options: RouteOption = {
url: 'pages/NoteContentHome'
}
try {
@@ -48,6 +57,11 @@ function routePage() {
}
}
+interface TextSpan {
+ type: 0 | 1; // 0 表示正常文本,1 表示高亮关键词
+ text: string;
+}
+
abstract class BasicDataSource implements IDataSource {
private listeners: DataChangeListener[] = [];
@@ -154,10 +168,11 @@ class noteListData extends BasicDataSource {
// Note list component
@Component
export struct NoteListComp {
+ @StorageLink('topHeight') topHeight: number = 0;
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = AppStorage.Link('AllFolderArray')
@Consume('SelectedFolderData') selectedFolderData: FolderData
@Consume('Search') search: boolean
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
@Consume('AsideWidth') asideWidth: number
build() {
@@ -177,6 +192,7 @@ export struct NoteListComp {
OperateNoteCompForPortrait()
}
.flexShrink(0)
+ .padding({ bottom: 90})
}
.height('100%')
.width('100%')
@@ -194,8 +210,8 @@ export struct NoteListComp {
@Component
struct NoteOverViewComp {
- @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
- @StorageLink('breakPoint') breakPoints: string = AppStorage.Get('breakPoint')
+ @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')!;
+ @StorageLink('breakPoint') breakPoints: string = AppStorage.Get('breakPoint')!;
@StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
@Consume('SelectedFolderData') selectedFolderData: FolderData
@Consume('RefreshFlag') refreshFlag: number
@@ -204,8 +220,8 @@ struct NoteOverViewComp {
@Consume('ExpandStatus') expandStatus: boolean
@Consume('Search') search: boolean
@Consume('PortraitModel') portraitModel: boolean
- controllerShow: WebviewController
- @State noteNumber: number = undefined
+ controllerShow: webview.WebviewController = new webview.WebviewController();
+ @State noteNumber: number = 0;
@StorageLink('isUpdate') @Watch('notesNumberChange') isUpdate: boolean = false
@Consume('AsideWidth') asideWidth: number
@State isShow: boolean = false
@@ -319,9 +335,9 @@ struct NoteOverViewComp {
@Component
export struct NoteItemComp {
- public noteItem: NoteData
- public spans: any[]
- controllerShow: WebviewController
+ public noteItem: NoteData = new NoteData(0, '标题', new Date().getTime() + '', '', '', '', NoteType.SysDef, Top.No, Favorite.No, Delete.No, new Date().getTime(), new Date().getTime(), 0, 0);
+ public spans: TextSpan[] = [];
+ controllerShow: webview.WebviewController = new webview.WebviewController();
@Consume('SelectedFolderData') selectedFolderData: FolderData
@Consume('SelectedNoteData') selectedNoteData: NoteData
@StorageLink('AllFolderArray') AllFolderArray: FolderData[] = AppStorage.Link('AllFolderArray')
@@ -331,7 +347,7 @@ export struct NoteItemComp {
@Consume('Search') search: boolean
@Consume('selectedAll') selectedAll: boolean
@Consume('PortraitModel') portraitModel: boolean
- @State isChecked: boolean = undefined
+ @State isChecked: boolean = false;
@Consume('Longpress') @Watch('isLongPress') longpress: boolean
@StorageLink('isUpdate') isUpdate: boolean = false
@@ -451,12 +467,18 @@ export struct NoteItemComp {
LogUtil.info(TAG, "NoteItemComp, set continue note success")
}
if (this.portraitModel == false) {
- this.controllerShow.runJavaScript(
- "RICH_EDITOR.setHtml('" + this.selectedNoteData?.content_text + "')"
- )
- this.controllerShow.runJavaScript(
- "RICH_EDITOR.cancelSelection()"
- )
+ try {
+ this.controllerShow.runJavaScript(
+ "RICH_EDITOR.setHtml('" + this.selectedNoteData?.content_text + "')"
+ );
+ this.controllerShow.runJavaScript(
+ "RICH_EDITOR.cancelSelection()"
+ );
+ LogUtil.info(TAG, `runJavaScript setHtml and cancelSelection success`);
+ } catch (error) {
+ LogUtil.error(TAG, `runJavaScript setHtml and cancelSelection failed.
+ code:${JSON.stringify(error.code)},message:${JSON.stringify(error.message)}`);
+ }
}
if (this.portraitModel == true) {
AppStorage.SetOrCreate('NewNote', this.selectedNoteData)
@@ -497,7 +519,7 @@ export struct NoteItemListComp {
@Consume('PortraitModel') portraitModel: boolean
@State @Watch('setNoteListLazy') dateList: NoteData[] = [];
@State noteList: noteListData = new noteListData();
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
@StorageLink('isUpdate') @Watch('updateList') isUpdate: boolean = false
updateList() {
@@ -527,7 +549,7 @@ export struct NoteItemListComp {
if (this.searchResultList.length != 0) {
this.selectedNoteData = this.searchResultList[0]
} else {
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)!;
}
if (this.portraitModel == false) {
this.controllerShow.runJavaScript(
@@ -588,7 +610,8 @@ export struct NoteItemListComp {
.height('100%')
.padding({ bottom: 120 })
.visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.Visible : Visibility.None)
- LazyForEach(this.noteList, (noteItem) => {
+
+ LazyForEach(this.noteList, (noteItem: NoteData) => {
ListItem() {
Column() {
NoteItemComp({
@@ -600,7 +623,7 @@ export struct NoteItemListComp {
.padding({ left: 24, right: 24, bottom: 12 })
}
.visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.None : Visibility.Visible)
- }, noteItem => JSON.stringify(noteItem))
+ }, (noteItem: NoteData) => JSON.stringify(noteItem))
}
.id(this.isUpdate + '')
.margin((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? {
@@ -649,9 +672,13 @@ export struct OperateNoteComp {
@Consume('PortraitModel') portraitModel: boolean
@Consume('selectedAll') selectedAll: boolean
@StorageLink('isUpdate') isUpdate: boolean = false
- controllerShow: WebviewController
- noteDataMoveDialogCtl: CustomDialogController = new CustomDialogController({
- builder: NoteDataMoveDialog({ onConfirm: this.onMoveConfirm.bind(this) }),
+ controllerShow: webview.WebviewController = new webview.WebviewController();
+ noteDataMoveDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: NoteDataMoveDialog({
+ onConfirm: (folderUuid: string) => {
+ this.onMoveConfirm(folderUuid);
+ }
+ }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
@@ -670,7 +697,7 @@ export struct OperateNoteComp {
predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
})
- this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid)!;
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject())
AppStorage.SetOrCreate('ContinueNote', continueNote)
@@ -684,8 +711,12 @@ export struct OperateNoteComp {
NoteUtil.refreshAll()
}
- noteDataDeleteDialogCtl: CustomDialogController = new CustomDialogController({
- builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }),
+ noteDataDeleteDialogCtl: CustomDialogController | null = new CustomDialogController({
+ builder: DeleteDialog({
+ onConfirm: () => {
+ this.onDeleteConfirm();
+ }, multiSelect: true
+ }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
@@ -713,7 +744,7 @@ export struct OperateNoteComp {
NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
this.longpress = false
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)!;
if (this.portraitModel == false) {
this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData?.content_text + "')")
}
@@ -753,7 +784,7 @@ export struct OperateNoteComp {
.margin({ right: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 0 : 18 })
.visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible)
.onClick(() => {
- this.noteDataMoveDialogCtl.open()
+ this.noteDataMoveDialogCtl!.open();
})
Image($r('app.media.delete'))
.width(24)
@@ -762,7 +793,7 @@ export struct OperateNoteComp {
.opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1)
.enabled(this.CheckedNoteArray.length == 0 ? false : true)
.onClick(() => {
- this.noteDataDeleteDialogCtl.open()
+ this.noteDataDeleteDialogCtl!.open();
})
Image($r('app.media.recover'))
.width(24)
@@ -775,13 +806,13 @@ export struct OperateNoteComp {
this.CheckedNoteArray.forEach((noteItem) => {
noteItem.is_deleted = Delete.No
noteItem.deleted_time = 0
- let context: any = getContext(this)
- let resource = {
+ let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+ let resource: resourceManager.Resource = {
bundleName: "com.ohos.note",
moduleName: "default",
id: $r('app.string.restore').id
};
- context.resourceManager.getString(resource, (error, value) => {
+ context.resourceManager.getStringValue(resource, (error: BusinessError, value: string) => {
if (error != null) {
LogUtil.error(TAG, "error is " + error);
} else {
@@ -831,7 +862,7 @@ export struct AddNoteComp {
@Consume('EditModel') editModel: boolean
@Consume('ChooseNote') chooseNote: boolean
@Consume('PortraitModel') portraitModel: boolean
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
build() {
Image($r('app.media.addNote'))
@@ -840,7 +871,7 @@ export struct AddNoteComp {
.margin({ right: 12 })
.responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
.onClick(() => {
- let noteData
+ let noteData: NoteData;
if (this.selectedFolderData.uuid == SysDefFolderUuid.AllNotes || this.selectedFolderData.uuid == SysDefFolderUuid.MyFavorites) {
noteData = new NoteData(0, "标题", new Date().getTime() + "", SysDefFolderUuid.UnClassified, "", "", NoteType.SysDef, Top.No, Favorite.No, Delete.No, new Date().getTime(), new Date().getTime(), 0, 0)
} else {
@@ -867,8 +898,8 @@ export struct AddNoteComp {
AppStorage.SetOrCreate('NewFolder', this.selectedFolderData)
AppStorage.SetOrCreate('ContinueNote', continueNote)
LogUtil.info(TAG, "addNote, set continue note success")
- routePage()
AppStorage.SetOrCreate('isUpdate', true)
+ routePage();
})
.visibility(this.longpress || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible)
}
@@ -894,7 +925,6 @@ export struct SearchComp {
focusControl.requestFocus('searchFocus')
this.search = false
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
AppStorage.SetOrCreate('Search', this.search)
})
@@ -963,8 +993,12 @@ export struct OperateNoteCompForPortrait {
@Consume('PortraitModel') portraitModel: boolean
@State greyOpacity: boolean = false
@StorageLink('isUpdate') isUpdate: boolean = false
- noteDataMoveDialogCtlBottom: CustomDialogController = new CustomDialogController({
- builder: NoteDataMoveDialog({ onConfirm: this.onMoveConfirm.bind(this) }),
+ noteDataMoveDialogCtlBottom: CustomDialogController | null = new CustomDialogController({
+ builder: NoteDataMoveDialog({
+ onConfirm: (folderUuid: string) => {
+ this.onMoveConfirm(folderUuid);
+ }
+ }),
alignment: DialogAlignment.Bottom,
autoCancel: false,
customStyle: true,
@@ -993,7 +1027,7 @@ export struct OperateNoteCompForPortrait {
predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
})
- this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid)!;
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject())
AppStorage.SetOrCreate('ContinueNote', continueNote)
@@ -1004,8 +1038,12 @@ export struct OperateNoteCompForPortrait {
NoteUtil.refreshAll()
}
- noteDataDeleteDialogCtlBottom: CustomDialogController = new CustomDialogController({
- builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }),
+ noteDataDeleteDialogCtlBottom: CustomDialogController | null = new CustomDialogController({
+ builder: DeleteDialog({
+ onConfirm: () => {
+ this.onDeleteConfirm();
+ }, multiSelect: true
+ }),
alignment: DialogAlignment.Bottom,
autoCancel: false,
customStyle: true,
@@ -1033,7 +1071,7 @@ export struct OperateNoteCompForPortrait {
NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
this.longpress = false
this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
- this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
+ this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)!;
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject())
AppStorage.SetOrCreate('ContinueNote', continueNote)
@@ -1084,7 +1122,7 @@ export struct OperateNoteCompForPortrait {
.height(24)
.responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
.onClick(() => {
- this.noteDataDeleteDialogCtlBottom.open()
+ this.noteDataDeleteDialogCtlBottom!.open();
AppStorage.SetOrCreate('isUpdate', true)
})
Text($r("app.string.delete"))
@@ -1108,7 +1146,7 @@ export struct OperateNoteCompForPortrait {
.height(24)
.responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
.onClick(() => {
- this.noteDataMoveDialogCtlBottom.open()
+ this.noteDataMoveDialogCtlBottom!.open();
AppStorage.SetOrCreate('isUpdate', true)
})
Text($r("app.string.move"))
@@ -1136,13 +1174,13 @@ export struct OperateNoteCompForPortrait {
this.CheckedNoteArray.forEach((noteItem) => {
noteItem.is_deleted = Delete.No
noteItem.deleted_time = 0
- let context: any = getContext(this)
- let resource = {
+ let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+ let resource: resourceManager.Resource = {
bundleName: "com.ohos.note",
moduleName: "default",
id: $r('app.string.restore').id
};
- context.resourceManager.getString(resource, (error, value) => {
+ context.resourceManager.getStringValue(resource, (error: BusinessError, value: string) => {
if (error != null) {
LogUtil.error(TAG, "error is " + error);
} else {
diff --git a/product/default/src/main/ets/MainAbility/MainAbility.ts b/product/default/src/main/ets/MainAbility/MainAbility.ts
index 0a46735f94fcecf72f8df63260b5651952fa931e..dcd9b7917ff7bddec0780edf198a6f4e741980ec 100644
--- a/product/default/src/main/ets/MainAbility/MainAbility.ts
+++ b/product/default/src/main/ets/MainAbility/MainAbility.ts
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -15,211 +15,229 @@
import UIAbility from '@ohos.app.ability.UIAbility';
import deviceInfo from '@ohos.deviceInfo';
-import AbilityConstant from '@ohos.app.ability.AbilityConstant'
-import fileio from '@ohos.fileio'
+import AbilityConstant from '@ohos.app.ability.AbilityConstant';
+import fileio from '@ohos.fileio';
import inputMethod from '@ohos.inputMethod';
-import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
+import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil';
import display from '@ohos.display';
import window from '@ohos.window';
import util from '@ohos.util';
+import common from '@ohos.app.ability.common';
+import relationalStore from '@ohos.data.relationalStore';
-globalThis.rdbStore = undefined
+AppStorage.SetOrCreate('rdbStore', undefined);
export default class MainAbility extends UIAbility {
- private Tag = "MainAbility_Tablet"
-
- onCreate(want, launchParam) {
- AppStorage.SetOrCreate('context', this.context)
- // @ts-ignore
- window.getLastWindow(this.context, (err, data) => {
- if (data && data.getWindowProperties()) {
- let windowWidth = data.getWindowProperties().windowRect.width
- LogUtil.info(this.Tag, " getLastWindow:" + windowWidth)
- this.screenBreakPoints(windowWidth)
- } else {
- LogUtil.info(this.Tag, "getWindowProperties error:" + JSON.stringify(err))
- }
- })
- LogUtil.info(this.Tag, " onCreate, launchReason is " + launchParam.launchReason + ", deviceType" + deviceInfo.deviceType)
- if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
- AppStorage.SetOrCreate('Expand', false)
- AppStorage.SetOrCreate('Choose', true)
- }
- if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
- // 设置迁移标记
- AppStorage.SetOrCreate('IsContinue', true)
- // 获取对端的迁移数据
- let Search: boolean = want.parameters["Search"]
- let continueNote: string = want.parameters["ContinueNote"]
- let continueSection: number = want.parameters["ContinueSection"]
- let scrollTopPercent: number = want.parameters["ScrollTopPercent"]
- let isFocusOnSearch: boolean = want.parameters["isFocusOnSearch"]
- LogUtil.info(this.Tag, " continueSection : " + continueSection)
- AppStorage.SetOrCreate('Search', Search)
- AppStorage.SetOrCreate('ContinueNote', continueNote)
- AppStorage.SetOrCreate('ContinueSection', continueSection)
- // 使用新的key保存数据,防止迁移过来的数据在使用前被本地操作覆盖
- AppStorage.SetOrCreate('remoteScrollTopPercent', scrollTopPercent)
- AppStorage.SetOrCreate('isRemoteFocusOnSearch', isFocusOnSearch)
- // 来自手机的迁移
- let continueChoose: boolean = want.parameters["ContinueChoose"]
- if (continueChoose) {
- LogUtil.info(this.Tag, " continue from phone")
- AppStorage.SetOrCreate('ContinueFromPhone', true)
- } else {
- AppStorage.SetOrCreate('ContinueFromTablet', true)
- LogUtil.info(this.Tag, " continue from tablet")
- }
- this.context.restoreWindowStage(null)
- }
- globalThis.noteContext = this.context
+ private Tag = 'MainAbility_Tablet';
+
+ onCreate(want, launchParam) {
+ AppStorage.SetOrCreate('context', this.context);
+ LogUtil.info(this.Tag, " onCreate, launchReason is " + launchParam.launchReason + ", deviceType" + deviceInfo.deviceType);
+ if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
+ AppStorage.SetOrCreate('Expand', false);
+ AppStorage.SetOrCreate('Choose', true);
}
-
- onDestroy() {
- LogUtil.info(this.Tag, " onDestroy")
+ if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
+ // 设置迁移标记
+ AppStorage.SetOrCreate('IsContinue', true);
+ // 获取对端的迁移数据
+ let Search: boolean = want.parameters["Search"];
+ let continueNote: string = want.parameters["ContinueNote"];
+ let continueSection: number = want.parameters["ContinueSection"];
+ let scrollTopPercent: number = want.parameters["ScrollTopPercent"];
+ let isFocusOnSearch: boolean = want.parameters["isFocusOnSearch"];
+ LogUtil.info(this.Tag, " continueSection : " + continueSection);
+ AppStorage.SetOrCreate('Search', Search);
+ AppStorage.SetOrCreate('ContinueNote', continueNote);
+ AppStorage.SetOrCreate('ContinueSection', continueSection);
+ // 使用新的key保存数据,防止迁移过来的数据在使用前被本地操作覆盖
+ AppStorage.SetOrCreate('remoteScrollTopPercent', scrollTopPercent);
+ AppStorage.SetOrCreate('isRemoteFocusOnSearch', isFocusOnSearch);
+ // 来自手机的迁移
+ let continueChoose: boolean = want.parameters["ContinueChoose"];
+ if (continueChoose) {
+ LogUtil.info(this.Tag, " continue from phone");
+ AppStorage.SetOrCreate('ContinueFromPhone', true);
+ } else {
+ AppStorage.SetOrCreate('ContinueFromTablet', true);
+ LogUtil.error(this.Tag, " continue from tablet");
+ }
+ this.context.restoreWindowStage(null);
}
-
- onWindowStageCreate(windowStage) {
- windowStage.getMainWindow((err, data) => {
- let windowClass = data
- try {
- windowClass.on('windowSizeChange', (data) => {
- this.screenBreakPoints(data.width)
- })
- } catch (exception) {
- LogUtil.info(this.Tag, 'windowSizeChange fail')
- }
+ AppStorage.SetOrCreate('noteContext', this.context);
+ }
+
+ onDestroy() {
+ LogUtil.info(this.Tag, " onDestroy");
+ }
+
+ onWindowStageCreate(windowStage) {
+ windowStage.getMainWindow((err, data) => {
+ let windowClass = data;
+ try {
+ windowClass.on('windowSizeChange', (data) => {
+ this.screenBreakPoints(data.width);
})
-
- LogUtil.info(this.Tag, " onWindowStageCreate")
- windowStage.setUIContent(this.context, "pages/MyNoteHome", null)
+ // 窗口规避区域
+ windowClass.on('avoidAreaChange', ({ type, area }) => {
+ if (type === window.AvoidAreaType.TYPE_SYSTEM) {
+ AppStorage.setOrCreate('topHeight', area.topRect.height);
+ AppStorage.setOrCreate('topWidth', area.topRect.width);
+ }
+ });
+ windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
+ // 设置主窗口沉浸式
+ windowClass.setWindowLayoutFullScreen(true);
+ // 设置主窗口导航栏、状态栏、文字颜色等属性
+ const sysBarProps: window.SystemBarProperties = {
+ statusBarColor: "#ffffff",
+ navigationBarColor: '#ffffff',
+ statusBarContentColor: '#000000',
+ navigationBarContentColor: '#000000'
+ };
+ // 加载状态变量
+ windowClass.setWindowSystemBarProperties(sysBarProps);
+ } catch (exception) {
+ LogUtil.error(this.Tag, 'windowSizeChange fail');
+ }
+ })
+ window.getLastWindow(this.context, (err, data) => {
+ if (data && data.getWindowProperties()) {
+ let windowWidth = data.getWindowProperties().windowRect.width;
+ LogUtil.info(this.Tag, " getLastWindow:" + windowWidth);
+ this.screenBreakPoints(windowWidth);
+ } else {
+ LogUtil.error(this.Tag, "getWindowProperties error:" + JSON.stringify(err));
+ }
+ })
+ LogUtil.info(this.Tag, " onWindowStageCreate");
+ windowStage.setUIContent(this.context, "pages/MyNoteHome", null);
+ }
+
+ onWindowStageDestroy() {
+ LogUtil.info(this.Tag, " onWindowStageDestroy");
+ }
+
+ onForeground() {
+ LogUtil.info(this.Tag, " onForeground");
+ }
+
+ onBackground() {
+ LogUtil.info(this.Tag, " onBackground");
+ // 退出键盘
+ inputMethod.getController().stopInputSession();
+ }
+
+ onContinue(wantParam: { [key: string]: any }) {
+ LogUtil.info(this.Tag, " onContinue");
+ // 获取本端的迁移数据
+ let Search = AppStorage.Get('Search');
+ let continueNote = AppStorage.Get('ContinueNote');
+ if (continueNote == undefined || continueNote == null) {
+ LogUtil.info(this.Tag, " onContinue, continueNote is error, default [0]");
+ continueNote = JSON.stringify(AppStorage.Get('AllNoteArray')[0].toNoteObject());
}
- onWindowStageDestroy() {
- LogUtil.info(this.Tag, " onWindowStageDestroy")
+ let continueSection = AppStorage.Get('ContinueSection');
+ if (continueSection == undefined || continueSection == null) {
+ LogUtil.info(this.Tag, " onContinue, continueSection is error, default 3");
+ continueSection = 3;
}
+ LogUtil.info(this.Tag, " onContinue, continueSection : " + continueSection);
- onForeground() {
- LogUtil.info(this.Tag, " onForeground")
+ let scrollTopPercent = AppStorage.Get('ScrollTopPercent');
+ if (scrollTopPercent == undefined || scrollTopPercent == null) {
+ LogUtil.info(this.Tag, " onContinue, scrollTopPercent is error, default 0");
+ scrollTopPercent = 0;
}
- onBackground() {
- LogUtil.info(this.Tag, " onBackground")
- // 退出键盘
- // @ts-ignore
- inputMethod.getController().stopInputSession();
+ let isFocusOnSearch = AppStorage.Get('isFocusOnSearch');
+ if (isFocusOnSearch == undefined || isFocusOnSearch == null) {
+ LogUtil.info(this.Tag, " onContinue, isFocusOnSearch is error, default true");
+ isFocusOnSearch = true;
}
- onContinue(wantParam: { [key: string]: any }) {
- LogUtil.info(this.Tag, " onContinue")
- // 获取本端的迁移数据
- let Search = AppStorage.Get('Search')
- let continueNote = AppStorage.Get('ContinueNote')
- if (continueNote == undefined || continueNote == null) {
- LogUtil.info(this.Tag, " onContinue, continueNote is error, default [0]")
- continueNote = JSON.stringify(AppStorage.Get('AllNoteArray')[0].toNoteObject())
- }
-
- let continueSection = AppStorage.Get('ContinueSection')
- if (continueSection == undefined || continueSection == null) {
- LogUtil.info(this.Tag, " onContinue, continueSection is error, default 3")
- continueSection = 3
- }
- LogUtil.info(this.Tag, " onContinue, continueSection : " + continueSection)
-
- let scrollTopPercent = AppStorage.Get('ScrollTopPercent')
- if (scrollTopPercent == undefined || scrollTopPercent == null) {
- LogUtil.info(this.Tag, " onContinue, scrollTopPercent is error, default 0")
- scrollTopPercent = 0
- }
-
- let isFocusOnSearch = AppStorage.Get('isFocusOnSearch')
- if (isFocusOnSearch == undefined || isFocusOnSearch == null) {
- LogUtil.info(this.Tag, " onContinue, isFocusOnSearch is error, default true")
- isFocusOnSearch = true
- }
-
- // 保存本端的迁移数据
- wantParam["Search"] = Search
- wantParam["ContinueNote"] = continueNote
- wantParam["ContinueSection"] = continueSection
- wantParam["ScrollTopPercent"] = scrollTopPercent
- wantParam["isFocusOnSearch"] = isFocusOnSearch
- if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
- wantParam["ContinueChoose"] = true
- }
-
- // save img to DisFileDir
- LogUtil.info(this.Tag, " onContinue, save img to DisFileDir")
- let continueNoteObj = JSON.parse(continueNote)
- let srcArray = this.getSrcFromHtml(continueNoteObj.content_text)
- srcArray.forEach((src: string) => {
- let lastIndex = src.lastIndexOf('/')
- if (lastIndex != -1) {
- let imgName = src.substring(lastIndex + 1)
- this.writeToDisFileDir(imgName)
- }
- })
- LogUtil.info(this.Tag, " onContinue end")
- return AbilityConstant.OnContinueResult.AGREE
+ // 保存本端的迁移数据
+ wantParam["Search"] = Search;
+ wantParam["ContinueNote"] = continueNote;
+ wantParam["ContinueSection"] = continueSection;
+ wantParam["ScrollTopPercent"] = scrollTopPercent;
+ wantParam["isFocusOnSearch"] = isFocusOnSearch;
+ if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
+ wantParam["ContinueChoose"] = true;
}
- getSrcFromHtml(html: string): any {
- let srcArray = []
- if (html == undefined || html == null || html == "") {
- return srcArray
- }
- let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
- let realHtml
- if (base64regex.test(html)) {
- let base64 = new util.Base64Helper
- realHtml = base64.decodeSync(html).toString()
- } else {
- realHtml = html;
- }
- let imgReg = /
]+>/g
- let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i
- let imgArray = realHtml.match(imgReg)
- if (imgArray != null) {
- for (let i = 0; i < imgArray.length; i++) {
- let src = imgArray[i].match(srcReg)
- if (src != null && src.length > 1) {
- LogUtil.info(this.Tag, " getSrcFromHtml, src[1] : " + src[1])
- srcArray.push(src[1])
- }
- }
- }
- return srcArray
+ // save img to DisFileDir
+ LogUtil.info(this.Tag, " onContinue, save img to DisFileDir");
+ let continueNoteObj = JSON.parse(continueNote);
+ let srcArray = this.getSrcFromHtml(continueNoteObj.content_text);
+ srcArray.forEach((src: string) => {
+ let lastIndex = src.lastIndexOf('/');
+ if (lastIndex != -1) {
+ let imgName = src.substring(lastIndex + 1);
+ this.writeToDisFileDir(imgName);
+ }
+ })
+ LogUtil.info(this.Tag, " onContinue end");
+ return AbilityConstant.OnContinueResult.AGREE;
+ }
+
+ getSrcFromHtml(html: string): any {
+ let srcArray = [];
+ if (html == undefined || html == null || html == "") {
+ return srcArray;
}
-
- writeToDisFileDir(fileName: string) {
- LogUtil.info(this.Tag, " writeToDisFileDir, fileName : " + fileName)
- let filesDir = this.context.filesDir
- let srcPath = filesDir + "/" + fileName
- let distributedFilesDir = this.context.distributedFilesDir
- let desPath = distributedFilesDir + "/" + fileName
- try {
- fileio.copyFileSync(srcPath, desPath)
- LogUtil.info(this.Tag, " onContinue, writeToDisFileDir, copyFile successfully" + desPath + " " + srcPath)
- } catch (err) {
- LogUtil.warn(this.Tag, " onContinue, writeToDisFileDir, copyFile failed : " + err)
- }
+ let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
+ let realHtml;
+ if (base64regex.test(html)) {
+ let base64 = new util.Base64Helper;
+ realHtml = base64.decodeSync(html).toString();
+ } else {
+ realHtml = html;
}
-
- screenBreakPoints(data) {
- let displayClass = null
- let screenDpi = null
- displayClass = display.getDefaultDisplaySync()
- screenDpi = displayClass.densityDPI
- AppStorage.SetOrCreate('dpi', screenDpi)
- let windowWidth = data / (screenDpi / 160)
- LogUtil.debug(this.Tag, " screenBreakPoints windowWidth: " + windowWidth)
- if (windowWidth >= 320 && windowWidth < 520 || windowWidth < 320) {
- AppStorage.SetOrCreate('breakPoint', 'sm')
- } else if (windowWidth >= 520 && windowWidth < 840) {
- AppStorage.SetOrCreate('breakPoint', 'md')
- } else if (windowWidth >= 840) {
- AppStorage.SetOrCreate('breakPoint', 'lg')
+ let imgReg = /
]+>/g;
+ let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
+ let imgArray = realHtml.match(imgReg);
+ if (imgArray != null) {
+ for (let i = 0; i < imgArray.length; i++) {
+ let src = imgArray[i].match(srcReg);
+ if (src != null && src.length > 1) {
+ LogUtil.info(this.Tag, " getSrcFromHtml, src[1] : " + src[1]);
+ srcArray.push(src[1]);
}
+ }
+ }
+ return srcArray;
+ }
+
+ writeToDisFileDir(fileName: string) {
+ LogUtil.info(this.Tag, " writeToDisFileDir, fileName : " + fileName);
+ let filesDir = this.context.filesDir;
+ let srcPath = filesDir + "/" + fileName;
+ let distributedFilesDir = this.context.distributedFilesDir;
+ let desPath = distributedFilesDir + "/" + fileName;
+ try {
+ fileio.copyFileSync(srcPath, desPath);
+ LogUtil.info(this.Tag, " onContinue, writeToDisFileDir, copyFile successfully" + desPath + " " + srcPath);
+ } catch (err) {
+ LogUtil.error(this.Tag, " onContinue, writeToDisFileDir, copyFile failed : " + err);
+ }
+ }
+
+ screenBreakPoints(data) {
+ let displayClass = null;
+ let screenDpi = null;
+ displayClass = display.getDefaultDisplaySync();
+ screenDpi = displayClass.densityDPI;
+ AppStorage.SetOrCreate('dpi', screenDpi);
+ let windowWidth = data / (screenDpi / 160);
+ LogUtil.debug(this.Tag, " screenBreakPoints windowWidth: " + windowWidth);
+ if (windowWidth >= 320 && windowWidth < 520 || windowWidth < 320) {
+ AppStorage.SetOrCreate('breakPoint', 'sm');
+ } else if (windowWidth >= 520 && windowWidth < 840) {
+ AppStorage.SetOrCreate('breakPoint', 'md');
+ } else if (windowWidth >= 840) {
+ AppStorage.SetOrCreate('breakPoint', 'lg');
}
+ }
}
\ No newline at end of file
diff --git a/product/default/src/main/ets/pages/MyNoteHome.ets b/product/default/src/main/ets/pages/MyNoteHome.ets
index 6aa38041a06ce671c8df912201dd23d52ea02dd6..d4ed72b05261e7a772de824fcee271c5f703c5a5 100644
--- a/product/default/src/main/ets/pages/MyNoteHome.ets
+++ b/product/default/src/main/ets/pages/MyNoteHome.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -22,15 +22,19 @@ import inputMethod from '@ohos.inputMethod';
import router from '@system.router';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import webview from '@ohos.web.webview';
+import { BusinessError } from '@ohos.base';
+import common from '@ohos.app.ability.common';
@Entry
@Component
export struct MyNoteHomeComp {
+ @StorageLink('topHeight') topHeight: number = 0; // 窗口规避区域高
+ @StorageLink('topWidth') topWidth: number = 0; // 窗口规避区域宽
@StorageLink('DBQueryFinished') dBQueryFinished: number = 0
@Provide('PortraitModel') portraitModel: boolean = true
@Provide('RefreshFlag') refreshFlag: number = 0
private controllerShow: WebviewController = new webview.WebviewController()
- private context = getContext(this)
+ private context = getContext(this) as common.UIAbilityContext;
TAG = "MyNoteHomeComp_Tablet"
@StorageLink('breakPoint') @Watch('onBreakPointChange') breakPoints: string = 'lg'
@@ -43,23 +47,29 @@ export struct MyNoteHomeComp {
}
build() {
- Row() {
- if (this.dBQueryFinished == 1) {
- if (this.breakPoints == 'sm') {
- NoteHomePortraitComp()
- } else {
- NoteHomeComp({ controllerShow: this.controllerShow })
- }
+ Column() {
+ // 窗口顶部规避区域
+ Row()
+ .width(px2vp(this.topWidth))
+ .height(px2vp(this.topHeight))
+ Row() {
+ if (this.dBQueryFinished == 1) {
+ if (this.breakPoints == 'sm') {
+ NoteHomePortraitComp()
+ } else {
+ NoteHomeComp({ controllerShow: this.controllerShow })
+ }
+ }
}
+ .width('100%')
+ .height('100%')
}
- .width('100%')
- .height('100%')
}
aboutToAppear(): void {
LogUtil.info(this.TAG, "aboutToAppear")
- this.breakPoints = AppStorage.Get('breakPoint')
+ this.breakPoints = AppStorage.Get('breakPoint')!;
if (this.breakPoints == 'sm' || this.breakPoints == 'md') {
this.portraitModel = true
} else {
@@ -73,10 +83,9 @@ export struct MyNoteHomeComp {
"ohos.permission.DISTRIBUTED_DATASYNC"
]
LogUtil.info(this.TAG, 'permissions need to require from user')
- let context: any = getContext(this);
+ let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
let AtManager = abilityAccessCtrl.createAtManager();
//requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
- // @ts-ignore
AtManager.requestPermissionsFromUser(context, ["ohos.permission.MANAGE_DISPOSED_APP_STATUS"]).then((data) => {
LogUtil.info(this.TAG, 'data permissions : ' + data.permissions)
LogUtil.info(this.TAG, 'data result: ' + data.authResults)
@@ -85,7 +94,7 @@ export struct MyNoteHomeComp {
sum += data.authResults[i]
}
LogUtil.info(this.TAG, 'request permissions sum: ' + sum)
- }).catch((err) => {
+ }).catch((err: BusinessError) => {
LogUtil.warn(this.TAG, 'failed to requestPermissionsFromUser : ' + err.code);
})
let dbExist = false;
@@ -132,7 +141,6 @@ export struct MyNoteHomeComp {
onBackPress() {
LogUtil.info(this.TAG, "onBackPress")
// 退出键盘
- // @ts-ignore
inputMethod.getController().stopInputSession();
setTimeout(() => {
LogUtil.info(this.TAG, "wait save cotext")
diff --git a/product/default/src/main/ets/pages/NoteContentHome.ets b/product/default/src/main/ets/pages/NoteContentHome.ets
index 0733cca2e99b1098f6da206e87c1eb714684b1ad..36b0a5f8799d507ea145a4b3fff18c2e4b4f44c0 100644
--- a/product/default/src/main/ets/pages/NoteContentHome.ets
+++ b/product/default/src/main/ets/pages/NoteContentHome.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -20,6 +20,7 @@ import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil'
import inputMethod from '@ohos.inputMethod'
import webview from '@ohos.web.webview';
+import common from '@ohos.app.ability.common';
@Entry
@Component
@@ -53,7 +54,6 @@ struct NoteContentHome {
this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)")
this.controllerShow.runJavaScript("getHtmlContent()")
if (deviceInfo.deviceType !== 'phone' && deviceInfo.deviceType !== 'default') {
- // @ts-ignore
inputMethod.getController().stopInputSession();
}
} catch (error) {
@@ -62,12 +62,13 @@ struct NoteContentHome {
}
aboutToAppear(): void {
- this.breakPoints = AppStorage.Get('breakPoint')
+ let noteContext = AppStorage.Get('noteContext')!;
+ this.breakPoints = AppStorage.Get('breakPoint')!;
LogUtil.info(this.TAG, "aboutToAppear")
let isContinue = AppStorage.Get('IsContinue')
LogUtil.info(this.TAG, "aboutToAppear, isContinue : " + isContinue)
if (isContinue) {
- RdbStoreUtil.initAppStorage(globalThis.noteContext)
+ RdbStoreUtil.initAppStorage(noteContext);
}
if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
AppStorage.SetOrCreate('NoteContentHomeExist', true)
diff --git a/product/default/src/main/ets/pages/NoteHome.ets b/product/default/src/main/ets/pages/NoteHome.ets
index 0dcbb1e86c2359f9767cde00d565f22b1840447e..0f67db6dc9e4625afc4ce8710da72e707fa764c0 100644
--- a/product/default/src/main/ets/pages/NoteHome.ets
+++ b/product/default/src/main/ets/pages/NoteHome.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -22,27 +22,28 @@ import { circleColorArray } from '@ohos/utils/src/main/ets/default/model/NoteBas
import FolderData from '@ohos/utils/src/main/ets/default/model/databaseModel/FolderData'
import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData'
import LayoutUtil from '@ohos/utils/src/main/ets/default/baseUtil/LayoutUtil'
+import webview from '@ohos.web.webview';
@Entry
@Component
export struct NoteHomeComp {
// 当前文件夹、笔记、分栏
- @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get('Folder')
- @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('Note')
- @Provide('SectionStatus') sectionStatus: number = AppStorage.Get('Section')
+ @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get('Folder')!;
+ @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('Note')!;
+ @Provide('SectionStatus') sectionStatus: number = AppStorage.Get('Section')!;
@Provide('SelectedColor') selectedColor: string = circleColorArray[0]
@Provide('LastSectionStatus') lastSectionStatus: number = 3 // 记录分栏上一次的状态
@Provide('Longpress') longpress: boolean = false // 第二栏长按状态
@Provide('ExpandStatus') expandStatus: boolean = false // 笔记本折叠展开状态
@Provide('ChooseNote') chooseNote: boolean = true // 是否选择笔记进行打开
- @Provide('Search') search: boolean = AppStorage.Get('Search') // 是否处于搜索状态
+ @Provide('Search') search: boolean = AppStorage.Get('Search')!; // 是否处于搜索状态
@Provide('SearchResultList') searchResultList: NoteData[] = [] // 搜索得到的笔记列表
@Provide('InputKeyword') inputKeyword: string = '' // 搜索的字串
@Provide('SelectedAll') selectedAll: boolean = false
@Provide('EditModel') editModel: boolean = false //编辑模式:临时方案
@Provide('Issave') issave: number = 0
@StorageLink('breakPoint') breakPoints: string = 'lg'
- controllerShow: WebviewController
+ controllerShow: webview.WebviewController = new webview.WebviewController();
TAG = "NoteHomeComp_Tablet"
@Provide('AsideWidth') asideWidth: number = 200
@@ -159,7 +160,7 @@ export struct NoteHomeComp {
let isContinue = AppStorage.Get('IsContinue')
LogUtil.info(this.TAG, "aboutToAppear, isContinue : " + isContinue)
if (isContinue) {
- this.sectionStatus = AppStorage.Get('Section')
+ this.sectionStatus = AppStorage.Get('Section')!;
}
// continue from phone
let continueFromPhone = AppStorage.Get('ContinueFromPhone')
diff --git a/product/default/src/main/ets/pages/NoteHomePortrait.ets b/product/default/src/main/ets/pages/NoteHomePortrait.ets
index 37d98674b11770663369046eaad087b7ae620f45..ee39fadfb0e445dcf956ea5aa293de8ae0778939 100644
--- a/product/default/src/main/ets/pages/NoteHomePortrait.ets
+++ b/product/default/src/main/ets/pages/NoteHomePortrait.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -25,8 +25,8 @@ import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteD
@Component
export struct NoteHomePortraitComp {
// 当前文件夹、笔记、分栏
- @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get('Folder')
- @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('Note')
+ @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get('Folder')!;
+ @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('Note')!;
@Provide('SectionStatus') sectionStatus: number = 1; // 表示分栏状态, 3表示三分栏, 2表示二分栏,1表示一分栏
@Provide('LastSectionStatus') lastSectionStatus: number = 1; // 记录分栏上一次的状态
@Provide('SelectedColor') selectedColor: string = circleColorArray[0];
@@ -34,7 +34,7 @@ export struct NoteHomePortraitComp {
// 分栏状态
@Provide('ExpandStatus') expandStatus: boolean = false // 笔记本折叠展开状态
- @Provide('ChooseNote') chooseNote: boolean = AppStorage.Get('Choose') // 是否选择笔记进行打开
+ @Provide('ChooseNote') chooseNote: boolean = AppStorage.Get('Choose')!; // 是否选择笔记进行打开
@Provide('Search') search: boolean = false // 是否处于搜索状态
@Provide('SearchResultList') searchResultList: NoteData[] = [] // 搜索得到的笔记列表
diff --git a/product/default/src/main/module.json5 b/product/default/src/main/module.json5
index 90ee051fa5f305ac02cc3040c581ef090bac8fd9..9db89da5836d147e7274372024dea3b896571d47 100644
--- a/product/default/src/main/module.json5
+++ b/product/default/src/main/module.json5
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2022-2024 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
@@ -30,23 +30,47 @@
"name": "ohos.permission.INTERNET"
},
{
- "name": "ohos.permission.READ_MEDIA",
- "reason": "$string:read_media_permission"
+ "name": "ohos.permission.MEDIA_LOCATION",
+ "reason": "$string:media_location_permission",
+ "usedScene": {
+ "abilities": [
+ "MainAbility"
+ ],
+ "when":"inuse"
+ }
},
{
- "name": "ohos.permission.WRITE_MEDIA",
- "reason": "$string:write_media_permission"
+ "name": "ohos.permission.DISTRIBUTED_DATASYNC",
+ "reason": "$string:distributed_dataSync_permission",
+ "usedScene": {
+ "abilities": [
+ "MainAbility"
+ ],
+ "when":"inuse"
+ }
},
{
- "name": "ohos.permission.MEDIA_LOCATION",
- "reason": "$string:media_location_permission"
+ "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
},
{
- "name": "ohos.permission.DISTRIBUTED_DATASYNC",
- "reason": "$string:distributed_dataSync_permission"
+ "name": "ohos.permission.READ_IMAGEVIDEO",
+ "reason": "$string:read_image_video_permission",
+ "usedScene": {
+ "abilities": [
+ "MainAbility"
+ ],
+ "when":"inuse"
+ }
},
{
- "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
+ "name": "ohos.permission.WRITE_IMAGEVIDEO",
+ "reason": "$string:write_image_video_permission",
+ "usedScene": {
+ "abilities": [
+ "MainAbility"
+ ],
+ "when":"inuse"
+ }
}
],
"deliveryWithInstall": true,
diff --git a/product/default/src/main/resources/base/element/string.json b/product/default/src/main/resources/base/element/string.json
index 5a03f94b0cb61b27464bb0a6884bf2108ae3962e..bcae607b9d365abbb1e54b22f18b5983d3c4cdef 100644
--- a/product/default/src/main/resources/base/element/string.json
+++ b/product/default/src/main/resources/base/element/string.json
@@ -4,10 +4,6 @@
"name": "entry_MainAbility",
"value": "备忘录"
},
- {
- "name": "read_media_permission",
- "value": "Used to read media file information in external storage of users"
- },
{
"name": "media_location_permission",
"value": "Used for memo access to geographic location information in user media files"
@@ -17,8 +13,12 @@
"value": "Used for memo data exchange between different equipment"
},
{
- "name": "write_media_permission",
- "value": "Used to write media file information in external storage of users"
+ "name": "read_image_video_permission",
+ "value": "Used to read images or video files from the user's public directory"
+ },
+ {
+ "name": "write_image_video_permission",
+ "value": "Used to modify image or video files in the user's public directory"
}
]
}
\ No newline at end of file
diff --git a/product/default/src/main/resources/zh_CN/element/string.json b/product/default/src/main/resources/zh_CN/element/string.json
index 2629b77b0fb00545233503ebc8f0d489b88d3919..4d0096bca4561b08aa9cd14f13f42bf65504d41a 100644
--- a/product/default/src/main/resources/zh_CN/element/string.json
+++ b/product/default/src/main/resources/zh_CN/element/string.json
@@ -1,9 +1,5 @@
{
"string": [
- {
- "name": "read_media_permission",
- "value": "用于备忘录读取用户外部存储中的媒体文件信息"
- },
{
"name": "media_location_permission",
"value": "用于备忘录访问用户媒体文件中的地理位置信息"
@@ -13,8 +9,12 @@
"value": "用于备忘录进行不同设备间的数据交换"
},
{
- "name": "write_media_permission",
- "value": "用于备忘录记录用户外部存储中的图片文件信息"
+ "name": "read_image_video_permission",
+ "value": "用于备忘录读取用户公共目录的图片或视频文件"
+ },
+ {
+ "name": "write_image_video_permission",
+ "value": "用于备忘录修改用户公共目录的图片或视频文件"
}
]
}
\ No newline at end of file