From 4831c52a6de8dc6269b7588bb2e3ede6d35a8c33 Mon Sep 17 00:00:00 2001 From: yiqiang Date: Mon, 8 Aug 2022 16:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=81=E8=BD=AC=E4=B8=AD?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E5=9B=BE=E7=89=87=E6=97=B6=E6=B5=81=E8=BD=AC?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yiqiang --- .../components/NoteContentCompPortrait.ets | 2 +- .../src/main/ets/components/NoteListComp.ets | 2 +- .../src/main/ets/default/baseUtil/LogUtil.ets | 19 ++++---- .../ets/default/baseUtil/RdbStoreUtil.ets | 22 ++++++--- .../src/main/ets/MainAbility/MainAbility.ts | 45 ++++++++++--------- .../tablet/src/main/ets/pages/MyNoteHome.ets | 2 + product/tablet/src/main/module.json5 | 4 ++ .../main/resources/base/element/string.json | 4 ++ .../main/resources/zh_CN/element/string.json | 4 ++ 9 files changed, 63 insertions(+), 41 deletions(-) diff --git a/common/component/src/main/ets/components/NoteContentCompPortrait.ets b/common/component/src/main/ets/components/NoteContentCompPortrait.ets index 6a7bc46..9882102 100644 --- a/common/component/src/main/ets/components/NoteContentCompPortrait.ets +++ b/common/component/src/main/ets/components/NoteContentCompPortrait.ets @@ -443,7 +443,7 @@ export struct DeleteNoteComp { let context: any = getContext(this) let resource = { bundleName: "com.ohos.note", - moduleName: "phone", + moduleName: "tablet", id: $r('app.string.restore').id }; context.resourceManager.getString(resource, (error, value) => { diff --git a/common/component/src/main/ets/components/NoteListComp.ets b/common/component/src/main/ets/components/NoteListComp.ets index de5dcce..da8fbdd 100644 --- a/common/component/src/main/ets/components/NoteListComp.ets +++ b/common/component/src/main/ets/components/NoteListComp.ets @@ -894,7 +894,7 @@ export struct OperateNoteCompForPortrait { let context: any = getContext(this) let resource = { bundleName: "com.ohos.note", - moduleName: "phone", + moduleName: "tablet", id: $r('app.string.restore').id }; context.resourceManager.getString(resource, (error, value) => { diff --git a/common/utils/src/main/ets/default/baseUtil/LogUtil.ets b/common/utils/src/main/ets/default/baseUtil/LogUtil.ets index 637a0cb..8043a88 100644 --- a/common/utils/src/main/ets/default/baseUtil/LogUtil.ets +++ b/common/utils/src/main/ets/default/baseUtil/LogUtil.ets @@ -12,40 +12,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * Log Util - */ +import hilog from '@ohos.hilog' export class LogUtil { private static readonly IS_DEBUG_ON: boolean = false; - private static readonly CONTACTS_DOMAIN: string = "00902"; + private static readonly CONTACTS_DOMAIN: number = 0x0927; private static readonly SLASH: string = "/"; private static readonly COLON: string = ": "; constructor() { } private static prefix(tag: string) { - return this.CONTACTS_DOMAIN + this.SLASH + tag + this.COLON; + return this.SLASH + tag + this.COLON; } static debug(tag: string, msg: string, ...args: any[]) { if (this.IS_DEBUG_ON) { - console.info(this.prefix(tag) + msg, args); + hilog.info(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); } else { - console.debug(this.prefix(tag) + msg, args); + hilog.debug(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); } } static info(tag: string, msg: string, ...args: any[]) { - console.info(this.prefix(tag) + msg, args); + hilog.info(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); } static warn(tag: string, msg: string, ...args: any[]) { - console.warn(this.prefix(tag) + msg, args); + hilog.warn(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); } static error(tag: string, msg: string, ...args: any[]) { - console.error(this.prefix(tag) + msg, args); + hilog.error(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); } } \ No newline at end of file diff --git a/common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets b/common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets index 216b142..1a25f27 100644 --- a/common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets +++ b/common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets @@ -341,16 +341,24 @@ export default { } catch (err) { LogUtil.warn(TAG, "desPath has not existed, need to write") } - - let srcPath = globalThis.noteContext.distributedFilesDir + "/" + fileName - LogUtil.info(TAG, "srcPath : " + srcPath) - let size = fileio.statSync(srcPath).size - LogUtil.info(TAG, "srcPath size : " + size) - if (size > FileMaxSize) { - LogUtil.warn(TAG, "srcPath size more then FileMaxSize, return") + let srcPath + let size + try{ + srcPath = globalThis.noteContext.distributedFilesDir + "/" + fileName + LogUtil.info(TAG, "srcPath : " + srcPath) + size = fileio.statSync(srcPath).size + LogUtil.info(TAG, "srcPath size : " + size) + if (size > FileMaxSize) { + LogUtil.warn(TAG, "srcPath size more then FileMaxSize, return") + return + } + } + catch (err) { + LogUtil.warn(TAG, "desPath has not existed, need to write two") return } + let srcFd try { srcFd = fileio.openSync(srcPath, 0o0) diff --git a/product/tablet/src/main/ets/MainAbility/MainAbility.ts b/product/tablet/src/main/ets/MainAbility/MainAbility.ts index ef8eedf..e9ca97d 100644 --- a/product/tablet/src/main/ets/MainAbility/MainAbility.ts +++ b/product/tablet/src/main/ets/MainAbility/MainAbility.ts @@ -18,13 +18,15 @@ import deviceInfo from '@ohos.deviceInfo'; import AbilityConstant from '@ohos.application.AbilityConstant' import fileio from '@ohos.fileio' import inputMethod from '@ohos.inputmethod'; +import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil' +import { atob } from 'js-base64' globalThis.rdbStore = undefined export default class MainAbility extends Ability { private Tag = "MainAbility_Tablet" onCreate(want, launchParam) { - console.info(this.Tag + " onCreate, launchReason is " + launchParam.launchReason) - console.info(this.Tag + " onCreate, deviceType" + deviceInfo.deviceType) + LogUtil.info(this.Tag, " onCreate, launchReason is " + launchParam.launchReason) + LogUtil.info(this.Tag, " onCreate, deviceType" + deviceInfo.deviceType) if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { AppStorage.SetOrCreate('Expand', false) AppStorage.SetOrCreate('Choose', true) @@ -35,17 +37,17 @@ export default class MainAbility extends Ability { // 获取对端的迁移数据 let continueNote: string = want.parameters["ContinueNote"] let continueSection: number = want.parameters["ContinueSection"] - console.info(this.Tag + " continueSection : " + continueSection) + LogUtil.info(this.Tag, " continueSection : " + continueSection) AppStorage.SetOrCreate('ContinueNote', continueNote) AppStorage.SetOrCreate('ContinueSection', continueSection) // 来自手机的迁移 let continueChoose: boolean = want.parameters["ContinueChoose"] if (continueChoose) { - console.info(this.Tag + " continue from phone") + LogUtil.info(this.Tag, " continue from phone") AppStorage.SetOrCreate('ContinueFromPhone', true) } else { AppStorage.SetOrCreate('ContinueFromTablet', true) - console.info(this.Tag + " continue from tablet") + LogUtil.info(this.Tag, " continue from tablet") } this.context.restoreWindowStage(null) } @@ -53,43 +55,43 @@ export default class MainAbility extends Ability { } onDestroy() { - console.info(this.Tag + " onDestroy") + LogUtil.info(this.Tag, " onDestroy") } onWindowStageCreate(windowStage) { - console.info(this.Tag + " onWindowStageCreate") + LogUtil.info(this.Tag, " onWindowStageCreate") windowStage.setUIContent(this.context, "pages/MyNoteHome", null) } onWindowStageDestroy() { - console.info(this.Tag + " onWindowStageDestroy") + LogUtil.info(this.Tag, " onWindowStageDestroy") } onForeground() { - console.info(this.Tag + " onForeground") + LogUtil.info(this.Tag, " onForeground") } onBackground() { - console.info(this.Tag + " onBackground") + LogUtil.info(this.Tag, " onBackground") // 退出键盘 inputMethod.getInputMethodController().stopInput(); } onContinue(wantParam: { [key: string]: any }) { - console.info(this.Tag + " onContinue") + LogUtil.info(this.Tag, " onContinue") // 获取本端的迁移数据 let continueNote = AppStorage.Get('ContinueNote') if (continueNote == undefined || continueNote == null) { - console.info(this.Tag + " onContinue, continueNote is error, default [0]") + LogUtil.info(this.Tag, " onContinue, continueNote is error, default [0]") continueNote = JSON.stringify(AppStorage.Get('AllNoteArray')[0].toNoteObject()) } let continueSection = AppStorage.Get('ContinueSection') if (continueSection == undefined || continueSection == null) { - console.info(this.Tag + " onContinue, continueSection is error, default 3") + LogUtil.info(this.Tag, " onContinue, continueSection is error, default 3") continueSection = 3 } - console.info(this.Tag + " onContinue, continueSection : " + continueSection) + LogUtil.info(this.Tag, " onContinue, continueSection : " + continueSection) // 保存本端的迁移数据 wantParam["ContinueNote"] = continueNote @@ -99,7 +101,7 @@ export default class MainAbility extends Ability { } // save img to DisFileDir - console.info(this.Tag + " onContinue, 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) => { @@ -109,7 +111,7 @@ export default class MainAbility extends Ability { this.writeToDisFileDir(imgName) } }) - console.info(this.Tag + " onContinue end") + LogUtil.info(this.Tag, " onContinue end") return AbilityConstant.OnContinueResult.AGREE } @@ -118,14 +120,15 @@ export default class MainAbility extends Ability { if (html == undefined || html == null || html == "") { return srcArray } + let realHtml = atob(html) let imgReg = /]+>/g let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i - let imgArray = html.match(imgReg) + 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) { - console.info(this.Tag + " getSrcFromHtml, src[1] : " + src[1]) + LogUtil.info(this.Tag, " getSrcFromHtml, src[1] : " + src[1]) srcArray.push(src[1]) } } @@ -134,16 +137,16 @@ export default class MainAbility extends Ability { } writeToDisFileDir(fileName: string) { - console.info(this.Tag + " writeToDisFileDir, fileName : " + fileName) + 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) - console.info(this.Tag + " onContinue, writeToDisFileDir, copyFile successfully") + LogUtil.info(this.Tag, " onContinue, writeToDisFileDir, copyFile successfully" + desPath + " " + srcPath) } catch (err) { - console.warn(this.Tag + " onContinue, writeToDisFileDir, copyFile failed : " + err) + LogUtil.warn(this.Tag, " onContinue, writeToDisFileDir, copyFile failed : " + err) } } } \ No newline at end of file diff --git a/product/tablet/src/main/ets/pages/MyNoteHome.ets b/product/tablet/src/main/ets/pages/MyNoteHome.ets index 36a27b5..33be5c2 100644 --- a/product/tablet/src/main/ets/pages/MyNoteHome.ets +++ b/product/tablet/src/main/ets/pages/MyNoteHome.ets @@ -58,11 +58,13 @@ export struct MyNoteHomeComp { let permissionList: Array = [ "ohos.permission.READ_MEDIA", + "ohos.permission.WRITE_MEDIA", "ohos.permission.DISTRIBUTED_DATASYNC" ] if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { permissionList = [ "ohos.permission.READ_MEDIA", + "ohos.permission.WRITE_MEDIA", "ohos.permission.MEDIA_LOCATION", "ohos.permission.DISTRIBUTED_DATASYNC" ] diff --git a/product/tablet/src/main/module.json5 b/product/tablet/src/main/module.json5 index a6b07eb..87ab8da 100644 --- a/product/tablet/src/main/module.json5 +++ b/product/tablet/src/main/module.json5 @@ -28,6 +28,10 @@ "name": "ohos.permission.READ_MEDIA", "reason": "$string:read_media_permission" }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason": "$string:write_media_permission" + }, { "name": "ohos.permission.MEDIA_LOCATION", "reason": "$string:media_location_permission" diff --git a/product/tablet/src/main/resources/base/element/string.json b/product/tablet/src/main/resources/base/element/string.json index 85dc25a..2043623 100644 --- a/product/tablet/src/main/resources/base/element/string.json +++ b/product/tablet/src/main/resources/base/element/string.json @@ -11,6 +11,10 @@ { "name": "distributed_dataSync_permission", "value": "Used for memo data exchange between different equipment" + }, + { + "name": "write_media_permission", + "value": "Used to write media file information in external storage of users" } ] } \ No newline at end of file diff --git a/product/tablet/src/main/resources/zh_CN/element/string.json b/product/tablet/src/main/resources/zh_CN/element/string.json index 215a916..2629b77 100644 --- a/product/tablet/src/main/resources/zh_CN/element/string.json +++ b/product/tablet/src/main/resources/zh_CN/element/string.json @@ -11,6 +11,10 @@ { "name": "distributed_dataSync_permission", "value": "用于备忘录进行不同设备间的数据交换" + }, + { + "name": "write_media_permission", + "value": "用于备忘录记录用户外部存储中的图片文件信息" } ] } \ No newline at end of file -- Gitee