备忘录升级API10

Signed-off-by: zhanghong <zhanghong121@huawei.com>
This commit is contained in:
zhanghong
2024-11-22 16:12:25 +08:00
parent 444cf7da2b
commit dd96860777
33 changed files with 1246 additions and 1063 deletions
+8
View File
@@ -136,6 +136,14 @@ hilog | grep 过滤信息
hilog | grep Label
```
## 5.约束与限制
1.本示例仅支持标准系统上运行,支持设备RK3568。
2.本示例已适配API10版本SDK,SDK版本号(API Version 10 4.0.10.16),镜像版本号(5.0.2.53)。
3.本示例需要使用DevEco Studio 5.0.0 Release(Build Version: 5.0.3.906, built on October 21, 2024)版本才可编译运行。
## 相关仓
系统应用
+2 -1
View File
@@ -21,7 +21,8 @@
"name": "default",
"signingConfig": "default",
"compileSdkVersion": 10,
"compatibleSdkVersion": 9
"compatibleSdkVersion": 10,
"runtimeOS": "OpenHarmony"
}
],
"signingConfigs": [
@@ -98,7 +98,7 @@ body {
background-color: white;
display: none;
justify-content: space-around;
padding-bottom: 6px;
padding-bottom: 50px;
}
.button-box div {
@@ -13,14 +13,20 @@
* limitations under the License.
*/
import {LogUtil} from '../baseUtil/LogUtil'
import photoAccessHelper from '@ohos.file.photoAccessHelper';
import common from '@ohos.app.ability.common';
import { LogUtil } from '../baseUtil/LogUtil';
const TAG: string = 'MediaLibraryAccess';
interface albumType {
count: number;
obj: photoAccessHelper.PhotoAsset | null;
}
const TAG = "MediaLibraryAccess"
export class MediaLibraryAccess {
static async getFirstObject(fetchOpt, context) {
let album = {
static async getFirstObject(fetchOpt: photoAccessHelper.FetchOptions, context: common.UIAbilityContext) {
let album: albumType = {
count: 0,
obj: null,
}
@@ -51,7 +57,7 @@ export class MediaLibraryAccess {
}
}
static async openAsset(mode: string, fileAsset: any) {
static async openAsset(mode: string, fileAsset: photoAccessHelper.PhotoAsset) {
LogUtil.info(TAG, 'openAsset start')
let fd = await fileAsset.open(mode);
LogUtil.info(TAG, `openAsset end. fd: ${fd}`)
@@ -64,7 +70,7 @@ export class MediaLibraryAccess {
return fd;
}
static async closeAsset(fd: number, fileAsset: any) {
static async closeAsset(fd: number, fileAsset: photoAccessHelper.PhotoAsset) {
LogUtil.info(TAG, 'closeAsset start')
if (fd <= 0) {
@@ -13,15 +13,15 @@
* limitations under the License.
*/
import {LogUtil} from './LogUtil'
import { LogUtil } from './LogUtil';
const TAG = "DateUtil"
const TAG: string = 'DateUtil';
/**
* 日期和时间均显示为2位数
* @param time
*/
function getUnifiedTime(time: number): any {
function getUnifiedTime(time: number): string | number {
return time > 9 ? time : "0" + time
}
@@ -33,7 +33,7 @@ export class DateUtil {
* 获取笔记标题的格式化时间
* @param date note modified time
*/
formateDateForNoteTitle(date: Date): string{
formateDateForNoteTitle(date: Date): string {
let nowDate = new Date()
let diffMin = Math.floor((nowDate.getTime() - date.getTime()) / 1000 / 60)
if (diffMin < 0) {
@@ -88,7 +88,7 @@ export class DateUtil {
* 获取笔记内容的格式化时间
* @param date note modified time
*/
formateDateForNoteContent(date: Date): string{
formateDateForNoteContent(date: Date): string {
// formatted time
let noteContentTime = ""
// note modified time
@@ -119,12 +119,12 @@ export class FolderUtil {
if (folderData === undefined || folderData === null) {
LogUtil.info(TAG, "isFolderMoveIn folderData undefined")
}
if (folderData!.uuid === undefined || folderData!.uuid === null) {
if (folderData.uuid! === undefined || folderData.uuid! === null) {
LogUtil.info(TAG, "isFolderMoveIn folderData uuid undefined")
folderData!.uuid = 'sys_def_unClassified_uuid';
folderData.uuid! == 'sys_def_unClassified_uuid';
}
LogUtil.info(TAG, "isFolderMoveIn folderDataUuid " + folderData!.uuid);
return (folderData!.uuid == SysDefFolderUuid.UnClassified || folderData!.folder_type == FolderType.CusDef);
LogUtil.info(TAG, "isFolderMoveIn folderDataUuid " + folderData.uuid!);
return (folderData.uuid! == SysDefFolderUuid.UnClassified || folderData!.folder_type == FolderType.CusDef);
}
/**
@@ -155,18 +155,18 @@ export class FolderUtil {
*/
getNoteCount(noteDataArray: NoteData[], folderUuid: string): number {
let count = 0;
const folderTextMap = {
"sys_def_allNotes_uuid": (noteData) => {
noteData.is_deleted == Delete.No ? ++count : count
const folderTextMap: Record<string, (noteData: NoteData) => void> = {
"sys_def_allNotes_uuid": (noteData: NoteData) => {
noteData.is_deleted == Delete.No ? ++count : count;
},
"sys_def_recentDeletes_uuid": (noteData) => {
noteData.is_deleted == Delete.Yes ? ++count : count
"sys_def_recentDeletes_uuid": (noteData: NoteData) => {
noteData.is_deleted == Delete.Yes ? ++count : count;
},
"sys_def_myFavorites_uuid": (noteData) => {
noteData.is_favorite == Favorite.Yes && noteData.is_deleted == Delete.No ? ++count : count
"sys_def_myFavorites_uuid": (noteData: NoteData) => {
noteData.is_favorite == Favorite.Yes && noteData.is_deleted == Delete.No ? ++count : count;
},
"sys_def_other_uuid": (noteData) => {
noteData.folder_uuid == folderUuid && noteData.is_deleted == Delete.No ? ++count : count
"sys_def_other_uuid": (noteData: NoteData) => {
noteData.folder_uuid == folderUuid && noteData.is_deleted == Delete.No ? ++count : count;
},
}
if (folderUuid == SysDefFolderUuid.AllNotes || folderUuid == SysDefFolderUuid.RecentDeletes || folderUuid == SysDefFolderUuid.MyFavorites) {
@@ -185,12 +185,12 @@ export class FolderUtil {
* @param selectedNoteArray - Selected note data list
* @return FolderData - return folder when note data list belong to the same folder, else return null
*/
getCommonFolder(folderDataArray: FolderData[], selectedNoteArray: NoteData[]): FolderData {
getCommonFolder(folderDataArray: FolderData[], selectedNoteArray: NoteData[]): FolderData | null {
if (selectedNoteArray.length == 0) {
return null
}
let folderData: FolderData = this.getFolderData(folderDataArray, selectedNoteArray[0].folder_uuid)
let currentFolderData = null
let currentFolderData: string | null = null;
selectedNoteArray.forEach((noteItem) => {
if (folderData != this.getFolderData(folderDataArray, noteItem.folder_uuid)) {
currentFolderData = this.getFolderData(folderDataArray, noteItem.folder_uuid).name
@@ -211,11 +211,12 @@ export class FolderUtil {
if (folderDataArray[index].folder_type == FolderType.CusDef && folderDataArray[index].name == inputStr) {
return true
} else {
let temp = GlobalResourceManager.getStringByResource(this.getFolderText(folderDataArray[index]))
let temp = GlobalResourceManager.getStringByResource(this.getFolderText(folderDataArray[index]) as Resource);
temp.then(result => {
if (result == inputStr) {
return true
}
return false;
})
}
}
@@ -13,34 +13,34 @@
* limitations under the License.
*/
import Rsm from '@ohos.resourceManager';
import {LogUtil} from './LogUtil'
import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
import { LogUtil } from './LogUtil';
const TAG = "Note_GlobalResourceManager"
const TAG: string = 'Note_GlobalResourceManager';
let context = getContext(this) as common.UIAbilityContext;
export class GlobalResourceManager {
public async getStringByResource(res: any): Promise<string> {
let json = JSON.parse(JSON.stringify(res));
let id = json.id;
public async getStringByResource(res: Resource): Promise<string> {
let json: Resource = JSON.parse(JSON.stringify(res));
let id: number = json.id;
LogUtil.info(TAG, "ResourceID = " + id)
return await this.getStringById(id);
}
public getStringById(id: number): Promise<string>{
public getStringById(id: number): Promise<string> {
let promise = new Promise<string>(resolve => {
let resourceMgr = Rsm.getResourceManager("com.example.note");
resourceMgr.then((result) => {
result.getString(id)
.then((resource) => {
resolve(resource);
LogUtil.info(TAG, 'getStringById resolve(resource) : ' + resolve(resource));
LogUtil.info(TAG, 'getStringById resource : ' + resource);
LogUtil.info(TAG, 'getStringById resource2 : ' + JSON.stringify(resource));
})
.catch((err) => {
LogUtil.info(TAG, 'getStringById err : ' + JSON.stringify(err));
});
});
let resourceMgr = context.resourceManager;
resourceMgr.getStringValue(id)
.then((resource) => {
resolve(resource);
LogUtil.info(TAG, 'getStringById resolve(resource) : ' + resolve(resource));
LogUtil.info(TAG, 'getStringById resource : ' + resource);
LogUtil.info(TAG, 'getStringById resource2 : ' + JSON.stringify(resource));
})
.catch((err: BusinessError) => {
LogUtil.error(TAG, 'getStringById err : ' + JSON.stringify(err));
});
});
LogUtil.info(TAG, 'getStringById promise: ' + JSON.stringify(promise));
return promise;
@@ -13,18 +13,24 @@
* limitations under the License.
*/
import {unSelectedNoteBgColorMap, selectedNoteBgColorMap} from '../model/NoteBaseData'
import FolderData from '../model/databaseModel/FolderData'
import NoteData from '../model/databaseModel/NoteData'
import {SysDefFolderUuid, FolderType, Favorite, Delete, TableName, NoteTableColumn,
} from '../model/databaseModel/EnumData'
import StyleConstants from '../constants/StyleConstants'
import {LogUtil} from './LogUtil'
import FolderUtil from './FolderUtil'
import RdbStoreUtil from './RdbStoreUtil'
import { unSelectedNoteBgColorMap, selectedNoteBgColorMap } from '../model/NoteBaseData';
import FolderData from '../model/databaseModel/FolderData';
import NoteData from '../model/databaseModel/NoteData';
import {
SysDefFolderUuid,
FolderType,
Favorite,
Delete,
TableName,
NoteTableColumn
} from '../model/databaseModel/EnumData';
import StyleConstants from '../constants/StyleConstants';
import { LogUtil } from './LogUtil';
import FolderUtil from './FolderUtil';
import RdbStoreUtil from './RdbStoreUtil';
import buffer from '@ohos.buffer';
const TAG = "NoteUtil"
const TAG: string = 'NoteUtil';
export class NoteUtil {
/**
@@ -105,18 +111,18 @@ export class NoteUtil {
*/
getNoteCount(noteDataArray: NoteData[], folderData: FolderData): number {
let count = 0;
const folderTextMap = {
"sys_def_allNotes_uuid": (noteData) => {
noteData.is_deleted == Delete.No ? ++count : count
const folderTextMap: Record<string, (noteData: NoteData) => void> = {
"sys_def_allNotes_uuid": (noteData: NoteData) => {
noteData.is_deleted == Delete.No ? ++count : count;
},
"sys_def_recentDeletes_uuid": (noteData) => {
noteData.is_deleted == Delete.Yes ? ++count : count
"sys_def_recentDeletes_uuid": (noteData: NoteData) => {
noteData.is_deleted == Delete.Yes ? ++count : count;
},
"sys_def_myFavorites_uuid": (noteData) => {
noteData.is_favorite == Favorite.Yes && noteData.is_deleted == Delete.No ? ++count : count
"sys_def_myFavorites_uuid": (noteData: NoteData) => {
noteData.is_favorite == Favorite.Yes && noteData.is_deleted == Delete.No ? ++count : count;
},
"sys_def_other_uuid": (noteData) => {
noteData.folder_uuid == folderData.uuid && noteData.is_deleted == Delete.No ? ++count : count
"sys_def_other_uuid": (noteData: NoteData) => {
noteData.folder_uuid == folderData.uuid && noteData.is_deleted == Delete.No ? ++count : count;
}
}
if (folderData.uuid == SysDefFolderUuid.AllNotes || folderData.folder_type == FolderType.FeatureDef) {
@@ -185,7 +191,7 @@ export class NoteUtil {
// delete note from db
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, allNoteDataArray[index].uuid)
RdbStoreUtil.delete(predicates_note, null)
RdbStoreUtil.delete(predicates_note, null!);
allNoteDataArray.splice(index, 1);
}
index++
@@ -203,25 +209,25 @@ export class NoteUtil {
LogUtil.info(TAG, "folderUuid " + folderUuid)
this.autoDeleteNote(allNoteDataArray)
let noteDataArray: NoteData[] = [];
let func = (noteData) => noteDataArray.push(noteData)
const folderTextMap = {
"sys_def_allNotes_uuid": (noteData) => {
noteData.is_deleted == Delete.No ? func(noteData) : null
let func = (noteData: NoteData) => noteDataArray.push(noteData);
const folderTextMap: Record<string, (noteData: NoteData) => void> = {
"sys_def_allNotes_uuid": (noteData: NoteData) => {
noteData.is_deleted == Delete.No ? func(noteData) : null;
},
"sys_def_recentDeletes_uuid": (noteData) => {
noteData.is_deleted == Delete.Yes ? func(noteData) : null
"sys_def_recentDeletes_uuid": (noteData: NoteData) => {
noteData.is_deleted == Delete.Yes ? func(noteData) : null;
},
"sys_def_myFavorites_uuid": (noteData) => {
noteData.is_favorite == Favorite.Yes && noteData.is_deleted == Delete.No ? func(noteData) : null
"sys_def_myFavorites_uuid": (noteData: NoteData) => {
noteData.is_favorite == Favorite.Yes && noteData.is_deleted == Delete.No ? func(noteData) : null;
},
"sys_def_other_uuid": (noteData) => {
noteData.folder_uuid == folderUuid && noteData.is_deleted == Delete.No ? func(noteData) : null
"sys_def_other_uuid": (noteData: NoteData) => {
noteData.folder_uuid == folderUuid && noteData.is_deleted == Delete.No ? func(noteData) : null;
},
}
if (folderUuid == SysDefFolderUuid.AllNotes || folderUuid == SysDefFolderUuid.RecentDeletes || folderUuid == SysDefFolderUuid.MyFavorites) {
allNoteDataArray.forEach(folderTextMap[folderUuid])
allNoteDataArray.forEach(folderTextMap[folderUuid]);
} else {
allNoteDataArray.forEach(folderTextMap["sys_def_other_uuid"])
allNoteDataArray.forEach(folderTextMap.sys_def_other_uuid);
}
// Sort priority: 1、Top or not 2、created time
noteDataArray.sort((noteItemLeft: NoteData, noteItemRight: NoteData) => {
@@ -241,14 +247,14 @@ export class NoteUtil {
* @param folderUuid
* @return NoteData
*/
getFirstNoteData(allNoteDataArray: NoteData[], folderUuid: string): NoteData {
getFirstNoteData(allNoteDataArray: NoteData[], folderUuid: string): NoteData | undefined {
let noteDataArray: NoteData[] = this.getNoteDataArray(allNoteDataArray, folderUuid);
LogUtil.info(TAG, "get noteDataArray size " + noteDataArray.length.toString())
LogUtil.info(TAG, "get noteDataArray size " + noteDataArray.length.toString());
if (noteDataArray.length == 0) {
LogUtil.info(TAG, "get noteDataArray empty")
return undefined;
LogUtil.info(TAG, "get noteDataArray empty");
return;
}
return noteDataArray == undefined ? null : noteDataArray[0]
return noteDataArray == undefined ? undefined : noteDataArray[0];
}
/**
@@ -268,37 +274,36 @@ export class NoteUtil {
deleteEmptyNote(selectedNoteData: NoteData, AllNoteArray: NoteData[], controllerShow: WebController): boolean {
if (selectedNoteData.title == "标题" && selectedNoteData.content_text == "") {
// delete note from db
noteUtil.removeNoteData(AllNoteArray, selectedNoteData.uuid)
LogUtil.info(TAG, "delete note:" + selectedNoteData.uuid)
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, selectedNoteData.uuid)
RdbStoreUtil.delete(predicates_note, null)
LogUtil.info(TAG, "delete note success:" + selectedNoteData.uuid)
return true
noteUtil.removeNoteData(AllNoteArray, selectedNoteData.uuid);
LogUtil.info(TAG, "delete note:" + selectedNoteData.uuid);
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable);
predicates_note.equalTo(NoteTableColumn.Uuid, selectedNoteData.uuid);
RdbStoreUtil.delete(predicates_note, null!);
LogUtil.info(TAG, "delete note success:" + selectedNoteData.uuid);
return true;
}
return false
return false;
}
refreshAll() {
let isRefresh = AppStorage.Get('isUpdate')
AppStorage.Set('isUpdate',!isRefresh)
let isRefresh: boolean = AppStorage.Get('isUpdate')!;
AppStorage.Set('isUpdate',!isRefresh);
}
/**
* Format conversion
* @param initContent
*/
contrastInitType(initContent:string):string {
let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
if(!base64regex.test(initContent)) {
const inputBuffer = buffer.from(initContent,'utf-8');
contrastInitType(initContent: string): string {
let base64regex = new RegExp('/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/');
if (!base64regex.test(initContent)) {
const inputBuffer = buffer.from(initContent, 'utf-8');
initContent = inputBuffer.toString('base64');
}
return initContent;
};
}
let noteUtil = new NoteUtil()
let noteUtil = new NoteUtil();
export default noteUtil as NoteUtil
export default noteUtil as NoteUtil;
@@ -13,126 +13,124 @@
* limitations under the License.
*/
import {LogUtil} from './LogUtil'
import {MediaLibraryAccess} from '../access/MediaLibraryAccess';
import { LogUtil } from './LogUtil';
import { MediaLibraryAccess } from '../access/MediaLibraryAccess';
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import fileio from '@ohos.fileio';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
import common from '@ohos.app.ability.common';
const TAG: string = 'OperationUtils';
let noteContext = AppStorage.Get<common.UIAbilityContext>('noteContext')!;
const TAG = "OperationUtils"
export class OperationUtils {
async copy(uri: string): Promise<string | undefined> {
let imagePath: string = '';
try {
let context = noteContext;
let fileAsset = await this.getFileAssetById(uri, context);
if (fileAsset == null || fileAsset == undefined) {
LogUtil.warn(TAG, "Failed to get fileAsset");
return;
}
let fd = await MediaLibraryAccess.openAsset('RW', fileAsset);
if (fd !== undefined && fd <= 0) {
LogUtil.warn(TAG, "fd is invaild");
return;
}
LogUtil.info(TAG, 'copyAsset read end!');
async copy(uri: string):Promise<string> {
try {
var context = globalThis.noteContext
let fileAsset = await this.getFileAssetById(uri, context);
if (fileAsset == null || fileAsset == undefined) {
LogUtil.warn(TAG, "Failed to get fileAsset")
return;
}
// 通过Uri拷贝图片到指定指定的包路径下
// 1、获取本地路径
let dir = context.filesDir;
// 2、生成本地文件名
let time = new Date().getTime();
imagePath = dir + '/' + time.toString() + '_note' + '.jpg';
// 3、拷贝
await fileio.copyFile(fd, imagePath);
// 4、关闭fd,Asset
await MediaLibraryAccess.closeAsset(fd!, fileAsset);
} catch (error) {
LogUtil.error(TAG, "create error: " + error);
}
LogUtil.debug(TAG, 'copy end');
return imagePath.toString();
}
let fd = await MediaLibraryAccess.openAsset('RW', fileAsset);
if (fd <= 0) {
LogUtil.warn(TAG, "fd is invaild")
return;
}
LogUtil.info(TAG, 'copyAsset read end!')
saveImageData(dataArray: Uint8Array, imageType: string): string {
let imagePath: string = '';
try {
let context = noteContext;
// 1、获取本地路径
let dir = context.filesDir;
let time = new Date().getTime();
imagePath = dir + '/' + time.toString() + '_note' + '.' + imageType;
let fd = fileio.openSync(imagePath, 0o100 | 0o2, 0o666);
// 3、把image数据写入本地图片文件中
fileio.writeSync(fd, dataArray.buffer);
} catch (error) {
LogUtil.error(TAG, "create error: " + error);
}
LogUtil.info(TAG, 'save image end');
return imagePath.toString();
}
// 通过Uri拷贝图片到指定指定的包路径下
// 1、获取本地路径
var dir = context.filesDir
// 2、生成本地文件名
var time = new Date().getTime()
var imagePath = dir + "/" + time.toString() + "_note" + ".jpg"
// 3、拷贝
await fileio.copyFile(fd, imagePath)
// 4、关闭安fd,Asset
await MediaLibraryAccess.closeAsset(fd, fileAsset);
} catch (error) {
LogUtil.info(TAG, "create error: " + error);
return;
}
LogUtil.debug(TAG, 'copy end');
saveImage(imageData: string, imageType: string): string {
let imagePath: string = '';
try {
let context = noteContext;
// 1、获取本地路径
let dir = context.filesDir;
// 2、生成本地文件名
let time = new Date().getTime();
imagePath = dir + '/' + time.toString() + '_note' + '.' + imageType;
let fd = fileio.openSync(imagePath, 0o100 | 0o2, 0o666);
let arrayBuffer = new ArrayBuffer(imageData.length);
let ia = new Uint8Array(arrayBuffer);
for (let i = 0; i < imageData.length; i++) {
ia[i] = imageData.charCodeAt(i);
}
// 3、把image数据写入本地图片文件中
fileio.writeSync(fd, ia.buffer);
} catch (error) {
LogUtil.error(TAG, "create error: " + error);
}
LogUtil.debug(TAG, 'save image end');
return imagePath.toString();
}
return imagePath.toString()
getIdByUri(uri: string): number {
let srcIndex = uri.lastIndexOf('/');
let srcEnd = uri.length;
let srcId = uri.substring(srcIndex + 1, srcEnd);
let numId = new Number(srcId);
LogUtil.debug(TAG, `getIdByUri numId: ${numId}`);
return numId.valueOf();
}
async getFileAssetById(imagePath: string, context: common.UIAbilityContext) {
LogUtil.info(TAG, 'getFileAssetById', imagePath);
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOpt: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates.equalTo('uri', imagePath)
}
saveImageData(dataArray: Uint8Array, imageType: string): string {
try {
var context = globalThis.noteContext
// 1、获取本地路径
var dir = context.filesDir
var time = new Date().getTime()
var imagePath = dir + "/" + time.toString() + "_note" + "." + imageType
let fd = fileio.openSync(imagePath, 0o100 | 0o2, 0o666)
// 3、把image数据写入本地图片文件中
fileio.writeSync(fd, dataArray.buffer)
} catch (error) {
LogUtil.info(TAG, "create error: " + error);
return;
}
LogUtil.info(TAG, 'save image end');
return imagePath.toString()
}
saveImage(imageData: string, imageType: string): string {
try {
var context = globalThis.noteContext
// 1、获取本地路径
var dir = context.filesDir
// 2、生成本地文件名
var time = new Date().getTime()
var imagePath = dir + "/" + time.toString() + "_note" + "." + imageType
let fd = fileio.openSync(imagePath, 0o100 | 0o2, 0o666)
let arrayBuffer = new ArrayBuffer(imageData.length)
let ia = new Uint8Array(arrayBuffer)
for(let i = 0; i < imageData.length; i++) {
ia[i] = imageData.charCodeAt(i)
}
// 3、把image数据写入本地图片文件中
fileio.writeSync(fd, ia.buffer)
} catch (error) {
LogUtil.info(TAG, "create error: " + error);
return;
}
LogUtil.debug(TAG, 'save image end');
return imagePath.toString()
}
getIdByUri(uri:string): number {
let srcIndex = uri.lastIndexOf('/');
let srcEnd = uri.length;
let srcId = uri.substring(srcIndex + 1, srcEnd);
let numId = new Number(srcId);
LogUtil.debug(TAG, `getIdByUri numId: ${numId}`);
return numId.valueOf();
}
async getFileAssetById(imagePath, context){
LogUtil.info(TAG, 'getFileAssetById', imagePath);
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOpt = {
fetchColumns: [],
predicates: predicates.equalTo('uri',imagePath)
}
try {
let result = await MediaLibraryAccess.getFirstObject(fetchOpt, context);
if (result == null) {
LogUtil.info(TAG, 'getFileAssetByUri fail');
return null;
}
return result.obj;
} catch (error) {
LogUtil.info(TAG, 'getFileAssetById error');
return null;
}
try {
let result = await MediaLibraryAccess.getFirstObject(fetchOpt, context);
if (result == null) {
LogUtil.info(TAG, 'getFileAssetByUri fail');
return null;
}
return result.obj;
} catch (error) {
LogUtil.error(TAG, 'getFileAssetById error');
return null;
}
}
}
let mOperationUtils = new OperationUtils();
export default mOperationUtils as OperationUtils;
@@ -25,48 +25,55 @@ import {
TableName,
FolderTableColumn,
NoteTableColumn,
SysDefFolderUuid
} from '../model/databaseModel/EnumData'
import relationalStore from '@ohos.data.relationalStore'
SysDefFolderUuid,
FolderType,
Delete,
Favorite,
NoteType,
Top
} from '../model/databaseModel/EnumData';
import relationalStore from '@ohos.data.relationalStore';
import util from '@ohos.util';
import { BusinessError, Callback } from '@ohos.base';
import common from '@ohos.app.ability.common';
const TAG = "RdbStoreUtil"
const TAG: string = 'RdbStoreUtil';
const FileMaxSize: number = 20 * 1024 * 1024
const FileMaxSize: number = 20 * 1024 * 1024;
let rdbStore = AppStorage.Get<relationalStore.RdbStore>('rdbStore');
/**
* db instance
*/
export default {
class RdbStoreUtil {
/**
* create db and table
*/
createRdbStore(context) {
createRdbStore(context: common.UIAbilityContext) {
try {
relationalStore.getRdbStore(context, SysDefData.dbInfo.db_name)
.then(async (store) => {
// add sys-def folder and note to AppStorage
let folderDataArray = []
let folderDataArray: FolderData[] = [];
let sysDefFolderArray = [SysDefData.sys_def_allNotes, SysDefData.sys_def_unClassified,
SysDefData.sys_def_myFavorites, SysDefData.sys_def_recentDeletes,
SysDefData.sys_def_personal, SysDefData.sys_def_life, SysDefData.sys_def_work]
SysDefData.sys_def_myFavorites, SysDefData.sys_def_recentDeletes,
SysDefData.sys_def_personal, SysDefData.sys_def_life, SysDefData.sys_def_work];
sysDefFolderArray.forEach((sysDefFolder) => {
let folderData = new FolderData(sysDefFolder.id, sysDefFolder.name, sysDefFolder.uuid, sysDefFolder.color,
sysDefFolder.folder_type, sysDefFolder.is_deleted, sysDefFolder.created_time,
sysDefFolder.modified_time)
folderDataArray.push(folderData)
let folderData = new FolderData(sysDefFolder.id as number, sysDefFolder.name as string, sysDefFolder.uuid as string, sysDefFolder.color as string,
sysDefFolder.folder_type as FolderType, sysDefFolder.is_deleted as Delete, sysDefFolder.created_time as number,
sysDefFolder.modified_time as number);
folderDataArray.push(folderData);
})
LogUtil.info(TAG, "folderDataArray[sysdef] : " + folderDataArray.length)
LogUtil.info(TAG, "folderDataArray[sysdef] : " + folderDataArray.length);
let noteDataArray = []
let noteDataArray: NoteData[] = [];
let sysDefNoteArray = [SysDefData.sys_def_note1, SysDefData.sys_def_note2,
SysDefData.sys_def_note3, SysDefData.sys_def_note4]
SysDefData.sys_def_note3, SysDefData.sys_def_note4];
sysDefNoteArray.forEach((sysDefNote) => {
let noteData = new NoteData(sysDefNote.id, sysDefNote.title, sysDefNote.uuid, sysDefNote.folder_uuid, sysDefNote.content_text,
sysDefNote.content_img, sysDefNote.note_type, sysDefNote.is_top, sysDefNote.is_favorite,
sysDefNote.is_deleted, sysDefNote.created_time, sysDefNote.modified_time, sysDefNote.deleted_time, sysDefNote.slider_value)
noteDataArray.push(noteData)
let noteData = new NoteData(sysDefNote.id as number, sysDefNote.title as string, sysDefNote.uuid as string, sysDefNote.folder_uuid as string, sysDefNote.content_text as string,
sysDefNote.content_img as string, sysDefNote.note_type as NoteType, sysDefNote.is_top as Top, sysDefNote.is_favorite as Favorite,
sysDefNote.is_deleted as Delete, sysDefNote.created_time as number, sysDefNote.modified_time as number, sysDefNote.deleted_time as number, sysDefNote.slider_value as number);
noteDataArray.push(noteData);
})
LogUtil.info(TAG, "noteDataArray[sysdef] : " + noteDataArray.length)
@@ -78,12 +85,12 @@ export default {
let isContinue = AppStorage.Get<boolean>('IsContinue');
LogUtil.info(TAG, "createRdbStore, isContinue is " + isContinue)
if (isContinue) {
let continueNote: string = AppStorage.Get('ContinueNote')
let continueSection = AppStorage.Get('ContinueSection')
let noteObj = JSON.parse(continueNote)
let noteData = new NoteData(noteObj.uuid, noteObj.title, noteObj.uuid, noteObj.folder_uuid,
let continueNote: string = AppStorage.Get('ContinueNote')!;
let continueSection: number = AppStorage.Get('ContinueSection')!;
let noteObj: NoteData = JSON.parse(continueNote);
let noteData: NoteData = new NoteData(noteObj.id, noteObj.title, noteObj.uuid, noteObj.folder_uuid,
noteObj.content_text, noteObj.content_img, noteObj.note_type, noteObj.is_top, noteObj.is_favorite,
noteObj.is_deleted, noteObj.created_time, noteObj.modified_time, noteObj.deleted_time, noteObj.slider_value)
noteObj.is_deleted, noteObj.created_time, noteObj.modified_time, noteObj.deleted_time, noteObj.slider_value);
// save img to FileDir
LogUtil.info(TAG, "createRdbStore, save img to FileDir")
@@ -108,7 +115,7 @@ export default {
noteData.folder_uuid = SysDefFolderUuid.UnClassified
noteDataArray.push(noteData)
AppStorage.SetOrCreate('AllNoteArray', noteDataArray)
this.insert(TableName.NoteTable, noteData.toNoteObject(), null)
this.insert(TableName.NoteTable, noteData.toNoteObject(), null!);
AppStorage.SetOrCreate('Folder', FolderUtil.getFolderData(folderDataArray, SysDefFolderUuid.UnClassified))
} else {
// 迁移过来的笔记在本地存在,则进行修改
@@ -121,7 +128,7 @@ export default {
}
let predicates_note = this.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.CreatedTime, noteData.created_time)
this.update(noteData.toNoteObject(), predicates_note, null)
this.update(noteData.toNoteObject(), predicates_note, null!);
AppStorage.SetOrCreate('Folder', FolderUtil.getFolderData(folderDataArray, folderUuid))
}
AppStorage.SetOrCreate('Note', noteData)
@@ -130,7 +137,7 @@ export default {
AppStorage.SetOrCreate<NoteData>('NewNote', noteData)
} else {
LogUtil.info(TAG, "createRdbStore, IsContinue false")
AppStorage.SetOrCreate('Folder', AppStorage.Get('AllFolderArray')[0])
AppStorage.SetOrCreate('Folder', (AppStorage.Get('AllFolderArray') as FolderData[])[0]);
let note = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.AllNotes)
AppStorage.SetOrCreate('Note', note)
if (note) {
@@ -141,49 +148,50 @@ export default {
AppStorage.SetOrCreate('DBQueryFinished', 1)
LogUtil.info(TAG, "createRdbStore, set DBQueryFinished 1")
LogUtil.info(TAG, "createRdbStore, store is " + store)
globalThis.rdbStore = store
rdbStore = store;
// create table
await globalThis.rdbStore.executeSql(TableSql.FolderTableSQL, null)
await globalThis.rdbStore.executeSql(TableSql.NoteTableSQL, null)
await globalThis.rdbStore.executeSql(TableSql.AttachmentTableSQL, null)
await globalThis.rdbStore.executeSql(TableSql.FormTableSQL, null)
rdbStore.executeSql(TableSql.FolderTableSQL.toString(), null);
rdbStore.executeSql(TableSql.NoteTableSQL.toString(), null);
rdbStore.executeSql(TableSql.AttachmentTableSQL.toString(), null);
rdbStore.executeSql(TableSql.FormTableSQL.toString(), null);
LogUtil.info(TAG, "create table success")
// insert system defined folder
await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_allNotes)
await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_unClassified)
await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_myFavorites)
await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_recentDeletes)
await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_personal)
await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_life)
await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_work)
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_allNotes);
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_unClassified);
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_myFavorites);
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_recentDeletes);
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_personal);
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_life);
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_work);
LogUtil.info(TAG, "insert system defined folder success")
// insert system defined note and attachment
await globalThis.rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note1)
await globalThis.rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note2)
await globalThis.rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note3)
await globalThis.rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note4)
await rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note1);
await rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note2);
await rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note3);
await rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note4);
LogUtil.info(TAG, "insert system defined note and attachment success")
})
} catch (err) {
LogUtil.warn(TAG, "createRdbStore, error : " + err)
}
},
}
/**
* query folders and notes from the database, then save them to the AppStorage.
*/
initAppStorage(context) {
let folderDataArray = []
let noteDataArray = []
initAppStorage(context: common.UIAbilityContext) {
let folderDataArray: FolderData[] = [];
let noteDataArray: NoteData[] = [];
try {
relationalStore.getRdbStore(context, SysDefData.dbInfo.db_name)
.then(async (store) => {
LogUtil.info(TAG, "initAppStorage, store is " + store)
globalThis.rdbStore = store
rdbStore = store;
// query folder
let columns_folder = []
let columns_folder: string[] = [];
let predicates_folder = new relationalStore.RdbPredicates(TableName.FolderTable)
let resultSet_folder = await globalThis.rdbStore.query(predicates_folder, columns_folder)
let resultSet_folder: relationalStore.ResultSet = await rdbStore.query(predicates_folder, columns_folder);
while (resultSet_folder.goToNextRow()) {
let id = resultSet_folder.getLong(resultSet_folder.getColumnIndex(FolderTableColumn.Id))
let name = resultSet_folder.getString(resultSet_folder.getColumnIndex(FolderTableColumn.Name))
@@ -199,9 +207,9 @@ export default {
resultSet_folder.close();
LogUtil.info(TAG, "folderDataArray[query] : " + folderDataArray.length)
// query note
let columns_note = []
let predicates_note = new relationalStore.RdbPredicates(TableName.NoteTable)
let resultSet_note = await globalThis.rdbStore.query(predicates_note, columns_note)
let columns_note: string[] = [];
let predicates_note = new relationalStore.RdbPredicates(TableName.NoteTable);
let resultSet_note: relationalStore.ResultSet = await rdbStore.query(predicates_note, columns_note);
while (resultSet_note.goToNextRow()) {
let id = resultSet_note.getLong(resultSet_note.getColumnIndex(NoteTableColumn.Id))
let title = resultSet_note.getString(resultSet_note.getColumnIndex(NoteTableColumn.Title))
@@ -232,12 +240,12 @@ export default {
if (folderDataArray === null || folderDataArray === undefined || folderDataArray.length === 0) {
LogUtil.info(TAG, "folderDataArray is null")
let sysDefFolderArray = [SysDefData.sys_def_allNotes, SysDefData.sys_def_unClassified,
SysDefData.sys_def_myFavorites, SysDefData.sys_def_recentDeletes,
SysDefData.sys_def_personal, SysDefData.sys_def_life, SysDefData.sys_def_work]
SysDefData.sys_def_myFavorites, SysDefData.sys_def_recentDeletes,
SysDefData.sys_def_personal, SysDefData.sys_def_life, SysDefData.sys_def_work];
sysDefFolderArray.forEach((sysDefFolder) => {
let folderData = new FolderData(sysDefFolder.id, sysDefFolder.name, sysDefFolder.uuid, sysDefFolder.color,
sysDefFolder.folder_type, sysDefFolder.is_deleted, sysDefFolder.created_time,
sysDefFolder.modified_time)
let folderData = new FolderData(sysDefFolder.id as number, sysDefFolder.name as string, sysDefFolder.uuid as string, sysDefFolder.color as string,
sysDefFolder.folder_type as FolderType, sysDefFolder.is_deleted as Delete, sysDefFolder.created_time as number,
sysDefFolder.modified_time as number);
folderDataArray.push(folderData)
})
LogUtil.info(TAG, "folderDataArray[query] : " + folderDataArray.length)
@@ -250,13 +258,13 @@ export default {
let isContinue = AppStorage.Get<boolean>('IsContinue');
LogUtil.info(TAG, "initAppStorage, isContinue is " + isContinue)
if (isContinue) {
let continueNote: string = AppStorage.Get('ContinueNote')
let continueSection = AppStorage.Get('ContinueSection')
let continueNote: string = AppStorage.Get('ContinueNote')!;
let continueSection: number = AppStorage.Get('ContinueSection')!;
let noteObj = JSON.parse(continueNote)
let noteData = new NoteData(noteObj.uuid, noteObj.title, noteObj.uuid, noteObj.folder_uuid,
let noteObj: NoteData = JSON.parse(continueNote);
let noteData: NoteData = new NoteData(noteObj.id, noteObj.title, noteObj.uuid, noteObj.folder_uuid,
noteObj.content_text, noteObj.content_img, noteObj.note_type, noteObj.is_top, noteObj.is_favorite,
noteObj.is_deleted, noteObj.created_time, noteObj.modified_time, noteObj.deleted_time, noteObj.slider_value)
noteObj.is_deleted, noteObj.created_time, noteObj.modified_time, noteObj.deleted_time, noteObj.slider_value);
// save img to FileDir
LogUtil.info(TAG, "initAppStorage, save img to FileDir")
@@ -281,7 +289,7 @@ export default {
noteData.folder_uuid = SysDefFolderUuid.UnClassified
noteDataArray.push(noteData)
AppStorage.SetOrCreate('AllNoteArray', noteDataArray)
this.insert(TableName.NoteTable, noteData.toNoteObject(), null)
this.insert(TableName.NoteTable, noteData.toNoteObject(), null!);
AppStorage.SetOrCreate('Folder', FolderUtil.getFolderData(folderDataArray, SysDefFolderUuid.UnClassified))
} else {
// 迁移过来的笔记在本地存在,则进行修改
@@ -294,7 +302,7 @@ export default {
}
let predicates_note = this.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.CreatedTime, noteData.created_time)
this.update(noteData.toNoteObject(), predicates_note, null)
this.update(noteData.toNoteObject(), predicates_note, null!);
AppStorage.SetOrCreate('Folder', FolderUtil.getFolderData(folderDataArray, folderUuid))
}
AppStorage.SetOrCreate('Note', noteData)
@@ -303,7 +311,7 @@ export default {
AppStorage.SetOrCreate<NoteData>('NewNote', noteData)
} else {
LogUtil.info(TAG, "initAppStorage, IsContinue false")
AppStorage.SetOrCreate('Folder', AppStorage.Get('AllFolderArray')[0])
AppStorage.SetOrCreate('Folder', (AppStorage.Get('AllFolderArray') as FolderData[])[0]);
let note = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.AllNotes)
AppStorage.SetOrCreate('Note', note)
if (note) {
@@ -317,17 +325,18 @@ export default {
} catch (err) {
LogUtil.error(TAG, "initAppStorage, error : " + err)
}
},
}
getImgNameFromHtml(noteData: NoteData): any {
let newModuleName = "file://" + globalThis.noteContext.filesDir
let imgNameArray = []
getImgNameFromHtml(noteData: NoteData): string[] {
let noteContext = AppStorage.Get<common.UIAbilityContext>('noteContext')!;
let newModuleName = 'file://' + noteContext.filesDir;
let imgNameArray: string[] = [];
if (noteData.content_text == undefined || noteData.content_text == null || noteData.content_text == "") {
LogUtil.info(TAG, "noteData.content_text is null or undefined")
return imgNameArray
}
let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
let html
let base64regex = new RegExp('/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/');
let html: string = '';
if (base64regex.test(noteData.content_text)) {
let base64 = new util.Base64Helper
html = base64.decodeSync(noteData.content_text).toString()
@@ -337,8 +346,8 @@ export default {
if (html == undefined || html == null || html == "") {
return imgNameArray
}
let imgReg = /<img[^>]+>/g
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i
let imgReg = new RegExp('/<img[^>]+>/g');
let srcReg = new RegExp('/src=[\'\"]?([^\'\"]*)[\'\"]?/i');
let imgArray = html.match(imgReg)
if (imgArray != null) {
let hasFirstImg: boolean = false
@@ -361,12 +370,12 @@ export default {
}
}
return imgNameArray
},
}
writeToFileDir(fileName: string) {
LogUtil.info(TAG, "writeToFileDir fileName : " + fileName)
let desPath = globalThis.noteContext.filesDir + "/" + fileName
let noteContext = AppStorage.Get<common.UIAbilityContext>('noteContext')!;
let desPath = noteContext.filesDir + '/' + fileName;
LogUtil.info(TAG, "desPath : " + desPath)
try {
fileio.accessSync(desPath)
@@ -375,10 +384,10 @@ export default {
} catch (err) {
LogUtil.warn(TAG, "desPath has not existed, need to write")
}
let srcPath
let size
let srcPath: string = '';
let size: number = 0;
try {
srcPath = globalThis.noteContext.distributedFilesDir + "/" + fileName
srcPath = noteContext.distributedFilesDir + '/' + fileName;
LogUtil.info(TAG, "srcPath : " + srcPath)
size = fileio.statSync(srcPath).size
LogUtil.info(TAG, "srcPath size : " + size)
@@ -393,7 +402,7 @@ export default {
}
let srcFd
let srcFd: number = 0;
try {
srcFd = fileio.openSync(srcPath, 0o0)
LogUtil.info(TAG, "open srcPath success : " + srcFd)
@@ -402,7 +411,7 @@ export default {
return
}
let desFd
let desFd: number = 0;
try {
desFd = fileio.openSync(desPath, 0o2 | 0o100, 0o400 | 0o200 | 0o040 | 0o020)
LogUtil.info(TAG, "open desPath success : " + srcFd)
@@ -420,7 +429,7 @@ export default {
} catch (err) {
LogUtil.warn(TAG, "read or write error : " + err)
}
},
}
/**
* insert
@@ -428,32 +437,32 @@ export default {
* @param valueBucket
* @param callback
*/
insert(tableName, valueBucket, callback) {
globalThis.rdbStore.insert(tableName, valueBucket).then((rowId) => {
insert(tableName: string, valueBucket: relationalStore.ValuesBucket, callback: Callback<number>) {
rdbStore!.insert(tableName, valueBucket).then((rowId: number) => {
LogUtil.info(TAG, "insert success, rowId is " + rowId)
if (callback != null) {
callback(rowId)
}
}).catch((err) => {
LogUtil.warn(TAG, "insert error : " + err)
}).catch((err: BusinessError) => {
LogUtil.error(TAG, 'insert error:' + err);
})
},
}
/**
* delete
* @param predicates
* @param callback
*/
delete(predicates, callback) {
globalThis.rdbStore.delete(predicates).then((affectedRowCount) => {
delete(predicates: relationalStore.RdbPredicates, callback: Callback<number>) {
rdbStore!.delete(predicates).then((affectedRowCount: number) => {
LogUtil.info(TAG, "delete success, affectedRowCount is " + affectedRowCount)
if (callback != null) {
callback(affectedRowCount)
}
}).catch((err) => {
}).catch((err: BusinessError) => {
LogUtil.warn(TAG, "delete error : " + err)
})
},
}
/**
* update
@@ -461,19 +470,20 @@ export default {
* @param predicates
* @param callback
*/
update(valueBucket, predicates, callback) {
if (!globalThis.rdbStore) {
update(valueBucket: relationalStore.ValuesBucket, predicates: relationalStore.RdbPredicates,
callback: Callback<number>) {
if (!rdbStore) {
return;
}
globalThis.rdbStore.update(valueBucket, predicates).then((affectedRowCount) => {
rdbStore!.update(valueBucket, predicates).then((affectedRowCount: number) => {
LogUtil.info(TAG, "update success, affectedRowCount is " + affectedRowCount)
if (callback != null) {
callback(affectedRowCount)
}
}).catch((err) => {
}).catch((err: BusinessError) => {
LogUtil.warn(TAG, "update error : " + err)
})
},
}
/**
* query
@@ -481,24 +491,24 @@ export default {
* @param predicates
* @param callback
*/
query(columns, predicates, callback) {
globalThis.rdbStore.query(predicates, columns).then((resultSet) => {
query(columns: string[], predicates: relationalStore.RdbPredicates, callback: Callback<relationalStore.ResultSet>) {
rdbStore!.query(predicates, columns).then((resultSet: relationalStore.ResultSet) => {
LogUtil.info(TAG, "query success, row count : " + resultSet.rowCount)
if (callback != null) {
callback(resultSet)
}
}).catch((err) => {
}).catch((err: BusinessError) => {
LogUtil.warn(TAG, "query error : " + err)
})
},
}
/**
* get RdbPredicates by table name
* @param tableName
*/
getRdbPredicates(tableName) {
getRdbPredicates(tableName: string) {
return new relationalStore.RdbPredicates(tableName)
},
}
updataNoteImage(noteData: NoteData): string {
let content_img = ""
@@ -514,4 +524,6 @@ export default {
LogUtil.info(TAG, "updataNoteImage, content_img : " + content_img)
return content_img
}
}
}
export default new RdbStoreUtil();
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import NoteData from '../model/databaseModel/NoteData'
import NoteData from '../model/databaseModel/NoteData';
export const circleColorArray: string[] = [
"#f86d05", // 深红
@@ -36,7 +36,7 @@ export const fontColorArray: string[] = [
"#182431", //黑色
]
export const unSelectedNoteBgColorMap = {
export const unSelectedNoteBgColorMap: Record<string, string> = {
"#f86d05": "#fff8eceb",
"#ff7500": "#f3d9c4",
"#ffbf00": "#f3e8c4",
@@ -48,7 +48,7 @@ export const unSelectedNoteBgColorMap = {
"#ffffff": "#ffffff"
}
export const selectedNoteBgColorMap = {
export const selectedNoteBgColorMap: Record<string, string> = {
"#f86d05": "#eec4b8",
"#ff7500": "#f1d8c7",
"#ffbf00": "#f3cdb1",
@@ -60,14 +60,14 @@ export const selectedNoteBgColorMap = {
"#ffffff": "#19007dff"
}
export const folderTextMap = {
export const folderTextMap: Record<string, Resource> = {
"sys_def_allNotes_uuid": $r('app.string.allNotes'),
"sys_def_unClassified_uuid": $r('app.string.unClassified'),
"sys_def_myFavorites_uuid": $r('app.string.myFavorites'),
"sys_def_recentDeletes_uuid": $r('app.string.recentDeletes'),
}
export const folderIconMap = {
export const folderIconMap: Record<string, Resource> = {
"sys_def_allNotes_uuid": $r('app.media.allNotes'),
"sys_def_unClassified_uuid": $r('app.media.unClassified'),
"sys_def_myFavorites_uuid": $r('app.media.favorite_cancel'),
@@ -101,7 +101,7 @@ let widthWeightOneSection: WidthWeightMessage = new WidthWeightMessage("0%", 0,
let widthWeightTwoSection = new WidthWeightMessage("0%", 0, "34%", 1, "66%", 1)
let widthWeightThreeSection = new WidthWeightMessage("16%", 1, "34%", 1, "50%", 1)
export const widthWeightMessageMap = {
export const widthWeightMessageMap: Record<number, WidthWeightMessage> = {
1: widthWeightOneSection,
2: widthWeightTwoSection,
3: widthWeightThreeSection
@@ -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,
@@ -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,
@@ -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
},
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_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
},
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
};
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_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
};
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
},
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
};
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
},
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
};
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
},
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
};
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_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": '<text>好好学习,天天向上</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
},
public sys_def_note1: relationalStore.ValuesBucket = {
"id": 1,
"title": "数学公式",
"uuid": "note1_uuid",
"folder_uuid": SysDefFolderUuid.UnClassified,
"content_text": '<text>好好学习,天天向上</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
},
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
};
sys_def_note3: {
"id": 3,
"title": "旅游心得",
"uuid": "note3_uuid",
"folder_uuid": SysDefFolderUuid.Work,
"content_text": '<div style="line-height:1.4;"><text>要想整个旅程无遗憾,关键是心态,首先要对即将到的目的地有一个正确的认识和恰当的期望。</text></div>',
"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_note3: relationalStore.ValuesBucket = {
"id": 3,
"title": "旅游心得",
"uuid": "note3_uuid",
"folder_uuid": SysDefFolderUuid.Work,
"content_text": '<div style="line-height:1.4;"><text>要想整个旅程无遗憾,关键是心态,首先要对即将到的目的地有一个正确的认识和恰当的期望。</text></div>',
"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
};
sys_def_note4: {
public sys_def_note4: relationalStore.ValuesBucket = {
"id": 4,
"title": "蛋糕做法",
"uuid": "note4_uuid",
"folder_uuid": SysDefFolderUuid.Life,
"content_text": '<div>' +
'<input name="checkbox" type="checkbox" onclick="onCheckChange(this)" class="note-checkbox" checked="checked">' +
'<span style="line-height:22.4px;" class="note-checkbox-txt">糖60g</span><br>' +
'<input name="checkbox" type="checkbox" onclick="onCheckChange(this)" class="note-checkbox">' +
'<span style="line-height:22.4px;" class="note-checkbox-txt">玉米油40g</span><br><div>' +
'<div><text style="line-height:22.4px;">&nbsp;1.&nbsp;&nbsp;&nbsp;添加鸡蛋、盐、糖、蛋糕粉<br>' +
'&nbsp;2.&nbsp;&nbsp;&nbsp;加入玉米油、牛奶,烤箱预热15分钟<br>' +
'&nbsp;3.&nbsp;&nbsp;&nbsp;加入葡萄干、核桃仁,烤箱定时40分钟<br><br></text></div></div></div>',
"content_text": '<span>&nbsp;</span>' +
'<input name="checkbox" type="checkbox" onclick="onCheckChange(this)" class="note-checkbox" checked="checked">' +
'<span style="line-height:22.4px;" class="note-checkbox-txt">糖60g</span><br>' +
'<span>&nbsp;</span>' +
'<input name="checkbox" type="checkbox" onclick="onCheckChange(this)" class="note-checkbox">' +
'<span style="line-height:22.4px;" class="note-checkbox-txt">玉米油40g</span><br><div>' +
'<div><text style="line-height:22.4px;">&nbsp;1.&nbsp;&nbsp;&nbsp;添加鸡蛋、盐、糖、蛋糕粉<br>' +
'&nbsp;2.&nbsp;&nbsp;&nbsp;加入玉米油、牛奶,烤箱预热15分钟<br>' +
'&nbsp;3.&nbsp;&nbsp;&nbsp;加入葡萄干、核桃仁,烤箱定时40分钟<br><br></text></div></div></div>',
"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
}
}
"slider_value": 0
};
}
export default new SysDefData();
@@ -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
+57
View File
@@ -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';
@@ -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,18 +292,19 @@ 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)
@@ -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,15 +766,16 @@ 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() {
try {
this.confirm("javascript:RICH_EDITOR.getFontSizes()");
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)}`);
@@ -944,7 +969,7 @@ export struct EditContentDialogPortrait {
this.selectFontColor = colorStr
this.confirm("javascript:RICH_EDITOR.setTextColor('" + this.selectFontColor + "')")
})
}, colorStr => colorStr)
}, (colorStr: string) => colorStr)
}
}
.height(48)
@@ -984,5 +1009,6 @@ export struct EditContentDialogPortrait {
.height(266)
.backgroundColor($r("app.color.color_ffffff"))
.borderRadius(36)
.offset({ y: -35 })
}
}
@@ -79,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)
@@ -102,7 +102,8 @@ export struct FolderListComp {
.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'))
@@ -123,14 +124,18 @@ 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,
@@ -145,7 +150,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)
}
@@ -164,9 +169,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)
@@ -194,10 +199,12 @@ struct FolderItemComp {
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,
@@ -205,10 +212,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,
@@ -233,19 +242,24 @@ struct FolderItemComp {
// update folder to db
let predicates_folder = RdbStoreUtil.getRdbPredicates(TableName.FolderTable)
predicates_folder.equalTo(FolderTableColumn.Uuid, this.folderItem.uuid)
RdbStoreUtil.update(this.folderItem.toFolderObject(), predicates_folder, null)
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,
@@ -266,7 +280,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!);
}
})
}
@@ -278,16 +292,16 @@ 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
let predicates_folder = RdbStoreUtil.getRdbPredicates(TableName.FolderTable)
predicates_folder.equalTo(FolderTableColumn.Uuid, this.folderItem.uuid)
RdbStoreUtil.delete(predicates_folder, null)
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
}
@@ -309,26 +323,32 @@ 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
this.AllFolderArray.push(folderData)
// insert folder to db
RdbStoreUtil.insert(TableName.FolderTable, folderData.toFolderObject(), null)
RdbStoreUtil.insert(TableName.FolderTable, folderData.toFolderObject(), null!);
this.isUpdate = true
}
@@ -343,9 +363,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()
})
@@ -360,9 +380,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()
})
@@ -378,9 +398,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()
})
@@ -437,7 +457,7 @@ 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
}
@@ -495,14 +515,14 @@ 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
}
@@ -531,17 +551,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);
})
)
)
}
}
@@ -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'
@@ -35,14 +36,24 @@ 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<common.UIAbilityContext>('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
@@ -62,7 +73,7 @@ export struct NoteContent {
if (!AppStorage.Has('remoteScrollTopPercent')) {
return
}
var scrollTopPercent = AppStorage.Get<number>('remoteScrollTopPercent')
let scrollTopPercent = AppStorage.Get<number>('remoteScrollTopPercent')!;
if (scrollTopPercent < 0) {
return
}
@@ -83,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 ) {
@@ -94,7 +105,7 @@ export struct NoteContent {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
LogUtil.info(TAG, 'update note success:' + this.selectedNoteData.uuid)
AppStorage.SetOrCreate<NoteData>('NewNote', this.selectedNoteData)
AppStorage.SetOrCreate<boolean>('needRefresh', true)
@@ -103,13 +114,13 @@ export struct NoteContent {
AppStorage.SetOrCreate<string>('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')
@@ -119,7 +130,7 @@ export struct NoteContent {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
LogUtil.info(TAG, 'callbackScheduledSave, update note success:' + this.selectedNoteData.uuid)
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
@@ -127,14 +138,14 @@ export struct NoteContent {
AppStorage.SetOrCreate<string>('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'
@@ -157,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) {
@@ -209,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)
@@ -273,8 +284,10 @@ export struct ToolBarComp {
@Consume('Issave') issave: number
@Consume('EditModel') editModel: boolean
controllerShow: webview.WebviewController = new webview.WebviewController();
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,
@@ -345,7 +358,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
// 清单
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.setTodo()")
@@ -361,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)
@@ -375,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<string, string>;
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 + "')"
@@ -419,7 +429,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("RICH_EDITOR.undo()")
})
@@ -434,7 +443,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("RICH_EDITOR.redo()")
})
@@ -472,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,
@@ -488,7 +498,7 @@ export struct NoteContentOverViewComp {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
@@ -499,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 })
}
@@ -507,14 +517,14 @@ export struct NoteContentOverViewComp {
this.selectedNoteData.folder_uuid = item.uuid
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!);
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
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)
@@ -535,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)
@@ -549,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)
@@ -577,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 }) {
@@ -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,15 +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<common.UIAbilityContext>('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 {
@@ -91,7 +105,7 @@ export struct NoteContentComp {
if (!AppStorage.Has('remoteScrollTopPercent')) {
return
}
var scrollTopPercent = AppStorage.Get<number>('remoteScrollTopPercent')
let scrollTopPercent = AppStorage.Get<number>('remoteScrollTopPercent')!;
if (scrollTopPercent < 0) {
return
}
@@ -111,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);
@@ -122,7 +136,7 @@ export struct NoteContentComp {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
LogUtil.info(TAG, 'update note success:' + this.selectedNoteData.uuid)
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
@@ -142,7 +156,7 @@ export struct NoteContentComp {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
LogUtil.info(TAG, 'update note success:' + this.selectedNoteData.uuid)
this.sectionStatus = this.lastSectionStatus
this.sectionStatus = mediaquery.matchMediaSync('(width < 2000)').matches ? 2 : 3
@@ -164,7 +178,7 @@ export struct NoteContentComp {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
LogUtil.info(TAG, 'callbackScheduledSave, update note success:' + this.selectedNoteData.uuid)
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
@@ -176,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];
@@ -259,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)
@@ -349,10 +363,12 @@ export struct NoteContentOverViewComp {
@Consume('SectionStatus') sectionStatus: number
@Consume('RefreshFlag') refreshFlag: number
@StorageLink('isUpdate') isUpdate: boolean = false
NoteDataMoveArray: FolderData[]
NoteDataMoveArray: FolderData[] = [];
controllerShow: webview.WebviewController = new webview.WebviewController();
editTitleDialogCtl: CustomDialogController = new CustomDialogController({
builder: EditTitleDialog({ confirm: this.confirm.bind(this) }),
editTitleDialogCtl: CustomDialogController | null = new CustomDialogController({
builder: EditContentDialog({ confirm: (newTitle: string) => {
this.confirm(newTitle);
} }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
@@ -385,7 +401,7 @@ export struct NoteContentOverViewComp {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
NoteUtil.refreshAll()
}
@@ -393,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 })
}
@@ -403,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 + "')"
)
@@ -417,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)
@@ -439,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<number>('ContinueSection', this.sectionStatus)
LogUtil.info(TAG, "NoteContentComp, set continue section success")
@@ -456,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)
@@ -496,8 +512,10 @@ export struct ToolBarComp {
@Consume('Issave') issave: number
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,
@@ -516,16 +534,16 @@ 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
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.delete(predicates_note, null)
RdbStoreUtil.delete(predicates_note, null!);
}
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)!;
try {
this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text! + "')");
} catch (error) {
@@ -539,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,
@@ -572,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) {
@@ -598,7 +617,7 @@ export struct ToolBarComp {
.height(24)
.width(24)
.onClick(() => {
this.noteDataDeleteDialogCtl.open()
this.noteDataDeleteDialogCtl!.open();
})
Image($r('app.media.recover'))
.height(24)
@@ -606,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 {
@@ -626,7 +645,7 @@ 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 + "')"
)
@@ -647,7 +666,6 @@ export struct ToolBarComp {
// 清单
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.setTodo()")
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
})
}.width(42)
@@ -661,9 +679,8 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
this.editContentDialogCtl.open()
this.editContentDialogCtl!.open();
})
}.width(42)
.height(42)
@@ -675,13 +692,12 @@ export struct ToolBarComp {
.height(24)
.width(24)
.onClick(async () => {
let permissionList: Array<string> = [
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)
@@ -690,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 + "')"
@@ -739,7 +754,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("RICH_EDITOR.undo()")
})
@@ -754,7 +768,6 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("RICH_EDITOR.redo()")
})
@@ -797,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 + "')"
)
@@ -815,7 +828,7 @@ export struct ToolBarComp {
.height(24)
.width(24)
.onClick(() => {
this.noteDataDeleteDialogCtl.open()
this.noteDataDeleteDialogCtl!.open();
})
}.width(72)
}
@@ -831,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 }) {
@@ -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,13 +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<common.UIAbilityContext>('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<void>;
getBreakPoint: () => void;
}
async function routePage() {
try {
await router.back()
@@ -53,8 +71,10 @@ async function routePage() {
// Note content component
@Component
export struct NoteContentCompPortrait {
@Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('NewNote')
@Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get("NewFolder")
@State scrollHeight: number = 0;
@State keyHeight: number = 0;
@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
@@ -62,12 +82,16 @@ export struct NoteContentCompPortrait {
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)
@@ -85,7 +109,7 @@ export struct NoteContentCompPortrait {
if (!AppStorage.Has('remoteScrollTopPercent')) {
return
}
var scrollTopPercent = AppStorage.Get<number>('remoteScrollTopPercent')
let scrollTopPercent = AppStorage.Get<number>('remoteScrollTopPercent')!;
if (scrollTopPercent < 0) {
return
}
@@ -109,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);
@@ -120,7 +144,7 @@ export struct NoteContentCompPortrait {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
LogUtil.info(TAG, 'update note success:' + this.selectedNoteData?.uuid)
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject())
@@ -143,7 +167,7 @@ export struct NoteContentCompPortrait {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
LogUtil.info(TAG, 'callbackScheduledSave, update note success:' + this.selectedNoteData?.uuid)
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject())
@@ -154,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];
@@ -198,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<string> = [
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)
@@ -216,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({
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<string,string>;
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 + "')")
@@ -256,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)
@@ -286,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)
@@ -333,7 +360,6 @@ export struct NoteContentCompPortrait {
}
.flexShrink(1)
.padding({ left: 24, right: 24 })
DeleteNoteComp()
}
.expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM])
@@ -344,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 {
@@ -361,9 +390,11 @@ 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,
@@ -387,7 +418,7 @@ export struct NoteContentOverViewComp {
this.selectedNoteData.modified_time = new Date().getTime()
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!);
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject())
AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
@@ -401,7 +432,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 })
}
@@ -416,7 +447,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 })
@@ -440,7 +471,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)
@@ -453,7 +484,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'))
@@ -493,21 +524,23 @@ 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!);
routePage()
} else {
NoteUtil.removeNoteData(this.AllNoteArray, this.selectedNoteData?.uuid)
// delete note from db
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid)
RdbStoreUtil.delete(predicates_note, null)
RdbStoreUtil.delete(predicates_note, null!);
routePage()
}
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,
@@ -555,7 +588,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()
}
@@ -574,7 +607,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)
@@ -585,7 +618,6 @@ export struct ToolBarComp {
.onClick(() => {
try {
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.undo()")
} catch (error) {
@@ -602,7 +634,6 @@ export struct ToolBarComp {
.onClick(() => {
try {
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
this.controllerShow.runJavaScript("javascript:RICH_EDITOR.redo()")
} catch (error) {
@@ -647,8 +678,10 @@ 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,
@@ -665,14 +698,14 @@ export struct DeleteNoteComp {
// 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!);
routePage()
} else {
NoteUtil.removeNoteData(this.AllNoteArray, this.selectedNoteData?.uuid)
// delete note from db
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid)
RdbStoreUtil.delete(predicates_note, null)
RdbStoreUtil.delete(predicates_note, null!);
NoteUtil.refreshAll()
routePage()
}
@@ -687,7 +720,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)
@@ -707,13 +740,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 {
@@ -749,8 +782,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 }) {
@@ -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'
@@ -35,11 +36,18 @@ 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 {
@@ -49,6 +57,11 @@ function routePage() {
}
}
interface TextSpan {
type: 0 | 1; // 0 表示正常文本,1 表示高亮关键词
text: string;
}
abstract class BasicDataSource<T> implements IDataSource {
private listeners: DataChangeListener[] = [];
@@ -155,6 +168,7 @@ class noteListData extends BasicDataSource<NoteData> {
// 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
@@ -178,6 +192,7 @@ export struct NoteListComp {
OperateNoteCompForPortrait()
}
.flexShrink(0)
.padding({ bottom: 90})
}
.height('100%')
.width('100%')
@@ -195,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
@@ -206,7 +221,7 @@ struct NoteOverViewComp {
@Consume('Search') search: boolean
@Consume('PortraitModel') portraitModel: boolean
controllerShow: webview.WebviewController = new webview.WebviewController();
@State noteNumber: number = undefined
@State noteNumber: number = 0;
@StorageLink('isUpdate') @Watch('notesNumberChange') isUpdate: boolean = false
@Consume('AsideWidth') asideWidth: number
@State isShow: boolean = false
@@ -320,8 +335,8 @@ struct NoteOverViewComp {
@Component
export struct NoteItemComp {
public noteItem: NoteData
public spans: any[]
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
@@ -332,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
@@ -534,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(
@@ -595,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({
@@ -607,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) ? {
@@ -657,8 +673,10 @@ export struct OperateNoteComp {
@Consume('selectedAll') selectedAll: boolean
@StorageLink('isUpdate') isUpdate: boolean = false
controllerShow: webview.WebviewController = new webview.WebviewController();
noteDataMoveDialogCtl: CustomDialogController = new CustomDialogController({
builder: NoteDataMoveDialog({ onConfirm: this.onMoveConfirm.bind(this) }),
noteDataMoveDialogCtl: CustomDialogController | null = new CustomDialogController({
builder: NoteDataMoveDialog({ onConfirm: (folderUuid: string) => {
this.onMoveConfirm(folderUuid);
} }),
alignment: DialogAlignment.Center,
autoCancel: false,
customStyle: true,
@@ -675,9 +693,9 @@ export struct OperateNoteComp {
// 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!);
})
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<string>('ContinueNote', continueNote)
@@ -691,8 +709,10 @@ 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,
@@ -706,7 +726,7 @@ export struct OperateNoteComp {
// 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!);
})
} else {
this.CheckedNoteArray.forEach((noteItem: NoteData) => {
@@ -714,13 +734,13 @@ export struct OperateNoteComp {
// delete note from db
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
RdbStoreUtil.delete(predicates_note, null)
RdbStoreUtil.delete(predicates_note, null!);
})
}
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 + "')")
}
@@ -760,7 +780,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)
@@ -769,7 +789,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)
@@ -782,13 +802,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 {
@@ -847,7 +867,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 {
@@ -901,7 +921,6 @@ export struct SearchComp {
focusControl.requestFocus('searchFocus')
this.search = false
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
AppStorage.SetOrCreate<boolean>('Search', this.search)
})
@@ -970,8 +989,10 @@ 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,
@@ -998,9 +1019,9 @@ export struct OperateNoteCompForPortrait {
// 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!);
})
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<string>('ContinueNote', continueNote)
@@ -1011,8 +1032,10 @@ 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,
@@ -1026,7 +1049,7 @@ export struct OperateNoteCompForPortrait {
// 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!);
})
} else {
this.CheckedNoteArray.forEach((noteItem: NoteData) => {
@@ -1034,13 +1057,13 @@ export struct OperateNoteCompForPortrait {
// delete note from db
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
RdbStoreUtil.delete(predicates_note, null)
RdbStoreUtil.delete(predicates_note, null!);
})
}
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<string>('ContinueNote', continueNote)
@@ -1091,7 +1114,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"))
@@ -1115,7 +1138,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"))
@@ -1143,13 +1166,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 {
+1 -2
View File
@@ -1,6 +1,5 @@
{
"hvigorVersion": "3.0.2",
"modelVersion": "5.0.0",
"dependencies": {
"@ohos/hvigor-ohos-plugin": "3.0.2"
}
}
-48
View File
@@ -1,48 +0,0 @@
#!/bin/bash
# ----------------------------------------------------------------------------
# Hvigor startup script, version 1.0.0
#
# Required ENV vars:
# ------------------
# NODE_HOME - location of a Node home dir
# or
# Add /usr/local/nodejs/bin to the PATH environment variable
# ----------------------------------------------------------------------------
HVIGOR_APP_HOME=$(dirname $(readlink -f $0))
HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
warn() {
echo ""
echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
error() {
echo ""
echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
fail() {
error "$@"
exit 1
}
# Determine node to start hvigor wrapper script
if [ -n "${NODE_HOME}" ];then
EXECUTABLE_NODE="${NODE_HOME}/bin/node"
if [ ! -x "$EXECUTABLE_NODE" ];then
fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
fi
else
EXECUTABLE_NODE="node"
which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
fi
# Check hvigor wrapper script
if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
fi
# start hvigor-wrapper script
exec "${EXECUTABLE_NODE}" \
"${HVIGOR_WRAPPER_SCRIPT}" "$@"
-57
View File
@@ -1,57 +0,0 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Hvigor startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
set NODE_EXE=node.exe
goto start
:start
@rem Find node.exe
if defined NODE_HOME goto findNodeFromNodeHome
%NODE_EXE% --version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:findNodeFromNodeHome
set NODE_HOME=%NODE_HOME:"=%
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
if exist "%NODE_EXE_PATH%" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:execute
@rem Execute hvigor
"%NODE_EXE%" %WRAPPER_MODULE_PATH% %*
:fail
exit /b 1
+1
View File
@@ -1,4 +1,5 @@
{
"modelVersion": "5.0.0",
"license": "ISC",
"devDependencies": {
"@ohos/hypium": "1.0.6"
@@ -15,210 +15,231 @@
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<relationalStore.RdbStore>('rdbStore', undefined);
export default class MainAbility extends UIAbility {
private Tag = "MainAbility_Tablet"
private Tag = 'MainAbility_Tablet';
onCreate(want, launchParam) {
AppStorage.SetOrCreate('context', this.context)
// @ts-ignore
LogUtil.info(this.Tag, " onCreate, launchReason is " + launchParam.launchReason + ", deviceType" + deviceInfo.deviceType)
if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
AppStorage.SetOrCreate<boolean>('Expand', false)
AppStorage.SetOrCreate<boolean>('Choose', true)
}
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// 设置迁移标记
AppStorage.SetOrCreate<boolean>('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<boolean>('Search', Search)
AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
AppStorage.SetOrCreate<number>('ContinueSection', continueSection)
// 使用新的key保存数据,防止迁移过来的数据在使用前被本地操作覆盖
AppStorage.SetOrCreate<number>('remoteScrollTopPercent', scrollTopPercent)
AppStorage.SetOrCreate<boolean>('isRemoteFocusOnSearch', isFocusOnSearch)
// 来自手机的迁移
let continueChoose: boolean = want.parameters["ContinueChoose"]
if (continueChoose) {
LogUtil.info(this.Tag, " continue from phone")
AppStorage.SetOrCreate<boolean>('ContinueFromPhone', true)
} else {
AppStorage.SetOrCreate<boolean>('ContinueFromTablet', true)
LogUtil.info(this.Tag, " continue from tablet")
}
this.context.restoreWindowStage(null)
}
globalThis.noteContext = this.context
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<boolean>('Expand', false);
AppStorage.SetOrCreate<boolean>('Choose', true);
}
onDestroy() {
LogUtil.info(this.Tag, " onDestroy")
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// 设置迁移标记
AppStorage.SetOrCreate<boolean>('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<boolean>('Search', Search);
AppStorage.SetOrCreate<string>('ContinueNote', continueNote);
AppStorage.SetOrCreate<number>('ContinueSection', continueSection);
// 使用新的key保存数据,防止迁移过来的数据在使用前被本地操作覆盖
AppStorage.SetOrCreate<number>('remoteScrollTopPercent', scrollTopPercent);
AppStorage.SetOrCreate<boolean>('isRemoteFocusOnSearch', isFocusOnSearch);
// 来自手机的迁移
let continueChoose: boolean = want.parameters["ContinueChoose"];
if (continueChoose) {
LogUtil.info(this.Tag, " continue from phone");
AppStorage.SetOrCreate<boolean>('ContinueFromPhone', true);
} else {
AppStorage.SetOrCreate<boolean>('ContinueFromTablet', true);
LogUtil.error(this.Tag, " continue from tablet");
}
this.context.restoreWindowStage(null);
}
AppStorage.SetOrCreate<common.UIAbilityContext>('noteContext', this.context);
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')
}
}
onDestroy() {
LogUtil.info(this.Tag, " onDestroy");
}
onWindowStageCreate(windowStage) {
windowStage.getMainWindow((err, data) => {
let windowClass = data;
try {
windowClass.on('windowSizeChange', (data) => {
this.screenBreakPoints(data.width);
})
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, " onWindowStageCreate")
windowStage.setUIContent(this.context, "pages/MyNoteHome", null)
} catch (exception) {
LogUtil.error(this.Tag, 'windowSizeChange fail');
}
// 窗口规避区域
windowClass.on('avoidAreaChange', ({type, area}) => {
if (type === window.AvoidAreaType.TYPE_SYSTEM) {
AppStorage.setOrCreate<number>('topHeight', area.topRect.height);
AppStorage.setOrCreate<number>('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);
})
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<boolean>('Search');
let continueNote = AppStorage.Get<string>('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<number>('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<number>('ScrollTopPercent');
if (scrollTopPercent == undefined || scrollTopPercent == null) {
LogUtil.info(this.Tag, " onContinue, scrollTopPercent is error, default 0");
scrollTopPercent = 0;
}
onForeground() {
LogUtil.info(this.Tag, " onForeground")
let isFocusOnSearch = AppStorage.Get<boolean>('isFocusOnSearch');
if (isFocusOnSearch == undefined || isFocusOnSearch == null) {
LogUtil.info(this.Tag, " onContinue, isFocusOnSearch is error, default true");
isFocusOnSearch = true;
}
onBackground() {
LogUtil.info(this.Tag, " onBackground")
// 退出键盘
// @ts-ignore
inputMethod.getController().stopInputSession();
// 保存本端的迁移数据
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;
}
onContinue(wantParam: { [key: string]: any }) {
LogUtil.info(this.Tag, " onContinue")
// 获取本端的迁移数据
let Search = AppStorage.Get<boolean>('Search')
let continueNote = AppStorage.Get<string>('ContinueNote')
if (continueNote == undefined || continueNote == null) {
LogUtil.info(this.Tag, " onContinue, continueNote is error, default [0]")
continueNote = JSON.stringify(AppStorage.Get('AllNoteArray')[0].toNoteObject())
}
// 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;
}
let continueSection = AppStorage.Get<number>('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<number>('ScrollTopPercent')
if (scrollTopPercent == undefined || scrollTopPercent == null) {
LogUtil.info(this.Tag, " onContinue, scrollTopPercent is error, default 0")
scrollTopPercent = 0
}
let isFocusOnSearch = AppStorage.Get<boolean>('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
getSrcFromHtml(html: string): any {
let srcArray = [];
if (html == undefined || html == null || html == "") {
return srcArray;
}
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 = /<img[^>]+>/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
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;
}
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 imgReg = /<img[^>]+>/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
}
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')
}
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');
}
}
}
@@ -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")
@@ -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<common.UIAbilityContext>('noteContext')!;
this.breakPoints = AppStorage.Get('breakPoint')!;
LogUtil.info(this.TAG, "aboutToAppear")
let isContinue = AppStorage.Get<boolean>('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<boolean>('NoteContentHomeExist', true)
@@ -28,15 +28,15 @@ import webview from '@ohos.web.webview';
@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
@@ -160,7 +160,7 @@ export struct NoteHomeComp {
let isContinue = AppStorage.Get<boolean>('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<boolean>('ContinueFromPhone')
@@ -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<boolean>('Choose') // 是否选择笔记进行打开
@Provide('ChooseNote') chooseNote: boolean = AppStorage.Get<boolean>('Choose')!; // 是否选择笔记进行打开
@Provide('Search') search: boolean = false // 是否处于搜索状态
@Provide('SearchResultList') searchResultList: NoteData[] = [] // 搜索得到的笔记列表
+28 -4
View File
@@ -31,22 +31,46 @@
},
{
"name": "ohos.permission.MEDIA_LOCATION",
"reason": "$string:media_location_permission"
"reason": "$string:media_location_permission",
"usedScene": {
"abilities": [
"MainAbility"
],
"when":"inuse"
}
},
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC",
"reason": "$string:distributed_dataSync_permission"
"reason": "$string:distributed_dataSync_permission",
"usedScene": {
"abilities": [
"MainAbility"
],
"when":"inuse"
}
},
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
},
{
"name": "ohos.permission.READ_IMAGEVIDEO",
"reason": "$string:read_image_video_permission"
"reason": "$string:read_image_video_permission",
"usedScene": {
"abilities": [
"MainAbility"
],
"when":"inuse"
}
},
{
"name": "ohos.permission.WRITE_IMAGEVIDEO",
"reason": "$string:write_image_video_permission"
"reason": "$string:write_image_video_permission",
"usedScene": {
"abilities": [
"MainAbility"
],
"when":"inuse"
}
}
],
"deliveryWithInstall": true,