fix base64 cause anr bug

Signed-off-by: yiqiang <tangyiqiang@huawei.com>
This commit is contained in:
yiqiang
2022-10-17 21:19:03 +08:00
parent f41db53f45
commit 9f73d4fc04
4 changed files with 46 additions and 19 deletions
@@ -51,8 +51,6 @@ export struct NoteContent {
LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData.uuid)
this.selectedNoteData.content_text = html
this.selectedNoteData.modified_time = new Date().getTime()
// updata note image
this.selectedNoteData.content_img = RdbStoreUtil.updataNoteImage(this.selectedNoteData)
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
@@ -64,6 +62,11 @@ export struct NoteContent {
AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
LogUtil.info(TAG, "callbackhtml, set continue note success")
},
callbackImagePath: (imgName) => {
// updata note image
LogUtil.info(TAG, 'note imgPath is:' + imgName)
this.selectedNoteData.content_img = imgName
},
callbackScheduledSave: (html) => {
LogUtil.info(TAG, 'callbackScheduledSave')
@@ -73,8 +76,6 @@ export struct NoteContent {
}
this.selectedNoteData.content_text = html
this.selectedNoteData.modified_time = new Date().getTime()
// updata note image
this.selectedNoteData.content_img = RdbStoreUtil.updataNoteImage(this.selectedNoteData)
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
@@ -129,7 +130,7 @@ export struct NoteContent {
.javaScriptProxy({
object: this.noteContent,
name: "callBackToApp", // html--> name.method
methodList: ["callbackhtml", "callbackScheduledSave", "callbackPasteImage"],
methodList: ["callbackhtml", "callbackScheduledSave", "callbackPasteImage", "callbackImagePath"],
controller:this.controllerShow
})
.onPageEnd((e) => {
@@ -59,8 +59,6 @@ export struct NoteContentComp {
LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData.uuid)
this.selectedNoteData.content_text = html
this.selectedNoteData.modified_time = new Date().getTime()
// updata note image
this.selectedNoteData.content_img = RdbStoreUtil.updataNoteImage(this.selectedNoteData)
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
@@ -71,13 +69,16 @@ export struct NoteContentComp {
LogUtil.info(TAG, "callbackhtml, set continue note success")
return "AceString"
},
callbackImagePath: (imgName) => {
// updata note image
LogUtil.info(TAG, 'note imgName is:' + imgName)
this.selectedNoteData.content_img = imgName
},
callbackhtmlSave: (html) => {
LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData.uuid)
this.selectedNoteData.content_text = html
this.selectedNoteData.modified_time = new Date().getTime()
// updata note image
this.selectedNoteData.content_img = RdbStoreUtil.updataNoteImage(this.selectedNoteData)
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
@@ -100,8 +101,6 @@ export struct NoteContentComp {
}
this.selectedNoteData.content_text = html
this.selectedNoteData.modified_time = new Date().getTime()
// updata note image
this.selectedNoteData.content_img = RdbStoreUtil.updataNoteImage(this.selectedNoteData)
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
@@ -166,7 +165,7 @@ export struct NoteContentComp {
.javaScriptProxy({
object: this.noteContent,
name: "callBackToApp", // html--> name.method
methodList: ["callbackhtml", "callbackhtmlSave", "callbackScheduledSave", "callbackGetSize", "callbackPasteImage"],
methodList: ["callbackhtml", "callbackhtmlSave", "callbackScheduledSave", "callbackGetSize", "callbackPasteImage", "callbackImagePath"],
controller:this.controllerShow
})
.onPageEnd((e) => {
@@ -17,7 +17,7 @@ import DateUtil from '@ohos/utils/src/main/ets/default/baseUtil/DateUtil'
import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil'
import FolderData from '@ohos/utils/src/main/ets/default/model/databaseModel/FolderData'
import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData'
import { atob, btoa } from 'js-base64'
import { atob } from 'js-base64'
import { TableName, NoteTableColumn, SysDefFolderUuid, Favorite, Delete
} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData'
import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants'
@@ -25,7 +25,6 @@ import { EditContentDialogPortrait, DeleteDialog, EditTitleDialog } from './CusD
import FolderUtil from '@ohos/utils/src/main/ets/default/baseUtil/FolderUtil'
import NoteUtil from '@ohos/utils/src/main/ets/default/baseUtil/NoteUtil'
import prompt from '@system.prompt'
import featureAbility from '@ohos.ability.featureAbility';
import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
import OperationUtils from '@ohos/utils/src/main/ets/default/baseUtil/OperationUtils'
import router from '@system.router'
@@ -60,8 +59,6 @@ export struct NoteContentCompPortrait {
LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData.uuid)
this.selectedNoteData.content_text = html
this.selectedNoteData.modified_time = new Date().getTime()
// updata note image
this.selectedNoteData.content_img = RdbStoreUtil.updataNoteImage(this.selectedNoteData)
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
@@ -71,6 +68,11 @@ export struct NoteContentCompPortrait {
AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
LogUtil.info(TAG, "callbackhtml, set continue note success")
},
callbackImagePath: (imgName) => {
// updata note image
LogUtil.info(TAG, 'note imgName is:' + imgName)
this.selectedNoteData.content_img = imgName
},
callbackScheduledSave: (html) => {
LogUtil.info(TAG, 'callbackScheduledSave')
@@ -80,8 +82,6 @@ export struct NoteContentCompPortrait {
}
this.selectedNoteData.content_text = html
this.selectedNoteData.modified_time = new Date().getTime()
// updata note image
this.selectedNoteData.content_img = RdbStoreUtil.updataNoteImage(this.selectedNoteData)
let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid)
RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null)
@@ -134,7 +134,7 @@ export struct NoteContentCompPortrait {
.javaScriptProxy({
object: this.noteContent,
name: "callBackToApp", // html--> name.method
methodList: ["callbackhtml", "callbackScheduledSave", "callbackPasteImage"],
methodList: ["callbackhtml", "callbackScheduledSave", "callbackPasteImage", "callbackImagePath"],
controller:this.controllerShow
})
.onPageEnd((e) => {
@@ -352,7 +352,9 @@ var callBackToApp;
function getHtmlContent() {
console.log('getHtmlContent');
var htmlString = RICH_EDITOR.getHtml();
let imgName = getImagePathFromContent(htmlString);
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
callBackToApp.callbackImagePath(imgName);
var str = callBackToApp.callbackhtml(htmlString);
console.log('getHtmlContent end');
}
@@ -360,15 +362,40 @@ function getHtmlContent() {
function saveHtmlContent() {
console.log('saveHtmlContent');
var htmlString = RICH_EDITOR.getHtml();
let imgName = getImagePathFromContent(htmlString);
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
callBackToApp.callbackImagePath(imgName);
var str = callBackToApp.callbackhtmlSave(htmlString);
console.log('saveHtmlContent end');
}
function getImagePathFromContent(contentInfo) {
let imgReg = /<img[^>]+>/g;
let imgName = "";
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
let imgArray = contentInfo.match(imgReg);
if (imgArray) {
for (let i = 0; i < imgArray.length; i++) {
let src = imgArray[i].match(srcReg);
if (src != null && src.length > 1) {
imgName = src[1];
if (imgName.indexOf('shuxue.png') >= 0 || imgName.indexOf('cake.png') >= 0) {
imgName = "/res/" + imgName;
}
break;
}
}
}
return imgName;
}
function scheduledSaveContent() {
console.info('scheduledSaveContent');
var htmlString = RICH_EDITOR.getHtml();
let imgName = getImagePathFromContent(htmlString);
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
callBackToApp.callbackImagePath(imgName);
var str = callBackToApp.callbackScheduledSave(htmlString);
console.info('scheduledSaveContent end');
}