From 0264b0b84b062fec0eb3fd9b53f7c1882a5e9b33 Mon Sep 17 00:00:00 2001 From: CodingGorit Date: Thu, 15 May 2025 15:40:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20InterfacePreviewKit=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InterfacePreviewKit/entry/oh-package.json5 | 7 ++- .../entry/src/main/ets/pages/GlobalData.ets | 62 +++++++++++++++++++ .../pages/InterfacePreviewNotInitialized.ets | 59 +----------------- 3 files changed, 70 insertions(+), 58 deletions(-) create mode 100644 InterfacePreviewKit/entry/src/main/ets/pages/GlobalData.ets diff --git a/InterfacePreviewKit/entry/oh-package.json5 b/InterfacePreviewKit/entry/oh-package.json5 index 248c3b7..eed7071 100644 --- a/InterfacePreviewKit/entry/oh-package.json5 +++ b/InterfacePreviewKit/entry/oh-package.json5 @@ -5,6 +5,11 @@ "main": "", "author": "", "license": "", - "dependencies": {} + // [Start add_hamock_dependecy] + "dependencies": { + // 版本号需根据hvigor及SDK的配套关系进行修改 + "@ohos/hamock": "1.0.0" + } + // [End add_hamock_dependecy] } diff --git a/InterfacePreviewKit/entry/src/main/ets/pages/GlobalData.ets b/InterfacePreviewKit/entry/src/main/ets/pages/GlobalData.ets new file mode 100644 index 0000000..efaaa24 --- /dev/null +++ b/InterfacePreviewKit/entry/src/main/ets/pages/GlobalData.ets @@ -0,0 +1,62 @@ +/* +* Copyright (c) 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. +*/ + +/* +* FAQ:预览告警“There are properties not initialized” +*/ + +// [Start global_data] +// [Start import_mock_setup_annotation] +import { MockSetup } from '@ohos/hamock'; +// [End import_mock_setup_annotation] + +export default class Fruit{ + public name: string; + + getName(): string{ + return this.name; + } + + constructor(name: string) { + this.name = name; + } + +} + +@Entry +@Component +struct GlobalData { + @State fruit:Fruit = AppStorage.get("fruit") as Fruit; + + // [Start mock_setup_annotation] + @MockSetup + mock(){ + this.fruit = new Fruit("apple"); + } + // [End mock_setup_annotation] + + build() { + Row() { + Column() { + Text(this.fruit.name) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} +// [End global_data] diff --git a/InterfacePreviewKit/entry/src/main/ets/pages/InterfacePreviewNotInitialized.ets b/InterfacePreviewKit/entry/src/main/ets/pages/InterfacePreviewNotInitialized.ets index 25b6d7e..1ff6203 100644 --- a/InterfacePreviewKit/entry/src/main/ets/pages/InterfacePreviewNotInitialized.ets +++ b/InterfacePreviewKit/entry/src/main/ets/pages/InterfacePreviewNotInitialized.ets @@ -17,64 +17,9 @@ * FAQ:预览告警“There are properties not initialized” */ -// DocsCode 1 -"dependencies": { - // 版本号需根据hvigor及SDK的配套关系进行修改 - "@ohos/hamock": "1.0.0" -} -// DocsCode 1 - -// DocsCode 2 -import { MockSetup } from '@ohos/hamock'; -// DocsCode 2 - -// DocsCode 3 -@MockSetup -mock(){ - this.fruit = new Fruit("apple"); -} -// DocsCode 3 - -// DocsCode 4 +// [Start interface_preview_not_initialized] import { MockSetup } from '@ohos/hamock'; -export default class Fruit{ - public name: string; - - getName(): string{ - return this.name; - } - - constructor(name: string) { - this.name = name; - } - -} -@Entry -@Component -struct GlobalData { - @State fruit:Fruit = AppStorage.get("fruit") as Fruit; - - @MockSetup - mock(){ - this.fruit = new Fruit("apple"); - } - - build() { - Row() { - Column() { - Text(this.fruit.name) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} -// DocsCode 4 - -// DocsCode 5 @Entry @Component struct Page { @@ -98,4 +43,4 @@ struct Page { .height('100%') } } -// DocsCode 5 \ No newline at end of file +// [End interface_preview_not_initialized] \ No newline at end of file -- Gitee From 322f85ab8cdad6378306ab5ee6223abf97fd0050 Mon Sep 17 00:00:00 2001 From: Gorit Date: Fri, 16 May 2025 09:47:06 +0000 Subject: [PATCH 2/2] =?UTF-8?q?feat=EF=BC=9A=E6=B3=A8=E9=87=8A=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gorit --- InterfacePreviewKit/entry/oh-package.json5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InterfacePreviewKit/entry/oh-package.json5 b/InterfacePreviewKit/entry/oh-package.json5 index eed7071..5016391 100644 --- a/InterfacePreviewKit/entry/oh-package.json5 +++ b/InterfacePreviewKit/entry/oh-package.json5 @@ -7,7 +7,7 @@ "license": "", // [Start add_hamock_dependecy] "dependencies": { - // 版本号需根据hvigor及SDK的配套关系进行修改 + // The version number needs to be modified according to the relationship between hvigor and the SDK "@ohos/hamock": "1.0.0" } // [End add_hamock_dependecy] -- Gitee