From d65dc024722519a3838bc513f73eb5b0afac13ca Mon Sep 17 00:00:00 2001 From: lvyuanyuan Date: Fri, 20 Sep 2024 21:45:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/common/constants/CommonConstant.ets | 46 +++++-------------- entry/src/main/ets/pages/WebIndex.ets | 10 ++-- entry/src/main/ets/view/LinkButton.ets | 8 ++-- .../main/resources/base/element/string.json | 16 +++++++ .../main/resources/en_US/element/string.json | 16 +++++++ .../main/resources/zh_CN/element/string.json | 16 +++++++ 6 files changed, 68 insertions(+), 44 deletions(-) diff --git a/entry/src/main/ets/common/constants/CommonConstant.ets b/entry/src/main/ets/common/constants/CommonConstant.ets index 2d2de21..1eafe46 100755 --- a/entry/src/main/ets/common/constants/CommonConstant.ets +++ b/entry/src/main/ets/common/constants/CommonConstant.ets @@ -17,136 +17,112 @@ * Common constants for all features. */ export class CommonConstants { - /** * User Center Link. */ static readonly USER_CENTER_URL = 'https://id1.cloud.huawei.com/AMW/portal/userCenter/index.html?' + - 'service=http://developer.huawei.com/consumer/cn/#/accountCenter/userCenter'; - + 'service=http://developer.huawei.com/consumer/cn/#/accountCenter/userCenter'; /** * About Links. */ static readonly USER_ABOUT_URL = 'https://id1.cloud.huawei.com/AMW/portal/userCenter/index.html?' + - 'service=http://developer.huawei.com/consumer/cn/#/accountCenter/about'; - + 'service=http://developer.huawei.com/consumer/cn/#/accountCenter/about'; /** * Font size of navigation text. */ static readonly NAVIGATOR_SIZE = '20fp'; - /** * Font size of page title text. */ static readonly TITLE_SIZE = '18fp'; - /** * Font size of button text. */ static readonly BUTTON_SIZE = '14fp'; - /** * Margin of divider. */ static readonly DIVIDER_MARGIN = 8; - /** * Height of divider. */ static readonly DIVIDER_HEIGHT = '2.2%'; - /** * Url of verify page. */ static readonly PAGE_VERIFY = 'pages/Verify'; - /** * Url of index page. */ static readonly PAGE_INDEX = 'pages/WebIndex'; - /** * Maximum of width. */ static readonly FULL_WIDTH = '100%'; - /** * Maximum of height. */ static readonly FULL_HEIGHT = '100%'; - /** * Width of back icon. */ static readonly BACK_WIDTH = '6.7%'; - /** * Height of back icon. */ static readonly BACK_HEIGHT = '3.1%'; - /** * Height of web component. */ static readonly WEB_HEIGHT = '60%'; - /** * Width of web component. */ static readonly WEB_WIDTH = '90%'; - /** * Height of page title text. */ static readonly PAGE_TITLE_HEIGHT = '3.1%'; - /** * Width of page title text. */ static readonly PAGE_TITLE_WIDTH = '25.6%'; - /** * Top margin of navigation. */ static readonly NAVIGATOR_MARGIN_TOP = '1.7%'; - /** * Left margin of navigation. */ static readonly NAVIGATOR_MARGIN_LEFT = '10%'; - /** * Deeper font weight than normal font. */ static readonly FONT_WEIGHT_DEEPER = 500; - /** * Top margin of app title. */ static readonly APP_TITLE_MARGIN_TOP = '15vp'; - /** * Left margin of app title. */ static readonly APP_TITLE_MARGIN_LEFT = '26vp'; - /** * Bottom margin of web. */ static readonly WEB_MARGIN_BOTTOM = '90vp'; - /** * Length of truncated. */ static readonly SUB_LENGTH: number = 300; -} -/** - * Type of cookie Operation. - */ -export enum CookieOperation { - GET_COOKIE = '读取cookie', - SET_COOKIE = '设置cookie', - DELETE_COOKIE = '删除cookie', - VERIFY_COOKIE = '验证cookie' + /** + * Type of cookie Operation. + */ + static readonly CookieOperation: string[] = [ + getContext(this).resourceManager.getStringSync($r('app.string.get_cookie').id), + getContext(this).resourceManager.getStringSync($r('app.string.set_cookie').id), + getContext(this).resourceManager.getStringSync($r('app.string.delete_cookie').id), + getContext(this).resourceManager.getStringSync($r('app.string.verify_cookie').id) + ]; } \ No newline at end of file diff --git a/entry/src/main/ets/pages/WebIndex.ets b/entry/src/main/ets/pages/WebIndex.ets index eecdeaf..cd52b1b 100755 --- a/entry/src/main/ets/pages/WebIndex.ets +++ b/entry/src/main/ets/pages/WebIndex.ets @@ -14,7 +14,7 @@ */ import { webview } from '@kit.ArkWeb'; -import { CommonConstants, CookieOperation } from '../common/constants/CommonConstant'; +import { CommonConstants } from '../common/constants/CommonConstant'; import { LinkButton } from '../view/LinkButton' import { showDialog } from '../common/utils/DialogUtil'; @@ -67,10 +67,10 @@ struct WebIndex { }) Row() { - LinkButton({ buttonType: CookieOperation.GET_COOKIE, isNeedDivider: true }) - LinkButton({ buttonType: CookieOperation.SET_COOKIE, isNeedDivider: true }) - LinkButton({ buttonType: CookieOperation.DELETE_COOKIE, isNeedDivider: true }) - LinkButton({ buttonType: CookieOperation.VERIFY_COOKIE, isNeedDivider: false }) + LinkButton({ buttonType: CommonConstants.CookieOperation[0], isNeedDivider: true }) + LinkButton({ buttonType: CommonConstants.CookieOperation[1], isNeedDivider: true }) + LinkButton({ buttonType: CommonConstants.CookieOperation[2], isNeedDivider: true }) + LinkButton({ buttonType: CommonConstants.CookieOperation[3], isNeedDivider: false }) } .justifyContent(FlexAlign.SpaceBetween) .width(CommonConstants.WEB_WIDTH) diff --git a/entry/src/main/ets/view/LinkButton.ets b/entry/src/main/ets/view/LinkButton.ets index 605fa16..a2478c9 100755 --- a/entry/src/main/ets/view/LinkButton.ets +++ b/entry/src/main/ets/view/LinkButton.ets @@ -16,7 +16,7 @@ import { webview } from '@kit.ArkWeb'; import { router } from '@kit.ArkUI'; import { showDialog } from '../common/utils/DialogUtil'; -import { CommonConstants, CookieOperation } from '../common/constants/CommonConstant'; +import { CommonConstants } from '../common/constants/CommonConstant'; /** * Link component. @@ -48,13 +48,13 @@ export struct LinkButton { operationMethod(): void { try { - if (this.buttonType === CookieOperation.GET_COOKIE) { + if (this.buttonType === CommonConstants.CookieOperation[0]) { let originCookie = webview.WebCookieManager.fetchCookieSync(CommonConstants.USER_CENTER_URL); showDialog(originCookie); - } else if (this.buttonType === CookieOperation.SET_COOKIE) { + } else if (this.buttonType === CommonConstants.CookieOperation[1]) { webview.WebCookieManager.configCookieSync(CommonConstants.USER_ABOUT_URL, 'info=测试cookie写入'); showDialog($r('app.string.write_success')); - } else if (this.buttonType === CookieOperation.DELETE_COOKIE) { + } else if (this.buttonType === CommonConstants.CookieOperation[2]) { webview.WebCookieManager.clearAllCookiesSync(); let deleteMessage = $r('app.string.delete_success'); showDialog(deleteMessage); diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index b76774b..3ceb57b 100755 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -51,6 +51,22 @@ { "name": "reason", "value": "Used to initiate network data requests." + }, + { + "name": "get_cookie", + "value": "Get Cookie" + }, + { + "name": "set_cookie", + "value": "Set Cookie" + }, + { + "name": "delete_cookie", + "value": "Delete Cookie" + }, + { + "name": "verify_cookie", + "value": "Verify Cookie" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index b76774b..3ceb57b 100755 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -51,6 +51,22 @@ { "name": "reason", "value": "Used to initiate network data requests." + }, + { + "name": "get_cookie", + "value": "Get Cookie" + }, + { + "name": "set_cookie", + "value": "Set Cookie" + }, + { + "name": "delete_cookie", + "value": "Delete Cookie" + }, + { + "name": "verify_cookie", + "value": "Verify Cookie" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 1453800..b5ac202 100755 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -51,6 +51,22 @@ { "name": "reason", "value": "Used to initiate network data requests." + }, + { + "name": "get_cookie", + "value": "读取cookie" + }, + { + "name": "set_cookie", + "value": "设置cookie" + }, + { + "name": "delete_cookie", + "value": "删除cookie" + }, + { + "name": "verify_cookie", + "value": "验证cookie" } ] } \ No newline at end of file -- Gitee