From 1d7a20754663326a87fc275b82b2d077641b7c27 Mon Sep 17 00:00:00 2001 From: hdx Date: Mon, 25 Nov 2024 15:03:52 +0800 Subject: [PATCH] =?UTF-8?q?create-selector-query:=20=E9=80=82=E9=85=8D?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../create-selector-query.uvue | 22 +++++++++++++------ .../selector-query-child-multi.uvue | 18 ++++++++++++--- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/pages/API/create-selector-query/create-selector-query.uvue b/pages/API/create-selector-query/create-selector-query.uvue index b52fead8..56c18c57 100644 --- a/pages/API/create-selector-query/create-selector-query.uvue +++ b/pages/API/create-selector-query/create-selector-query.uvue @@ -90,13 +90,15 @@ fieldsResultContainNode: false, nodeResultContainNode: false } + }, + onLoad() { + uni.$on('childReady', this.onChildReady) + }, + onUnload() { + uni.$off('childReady', this.onChildReady) }, - onReady() { - const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance) - this.selectCount = instance2.$data['selectCount'] as number - this.selectAllCount = instance2.$data['selectAllCount'] as number - - this.testFields() + onReady() { + this.testFields() this.testNode() }, onResize() { @@ -109,7 +111,13 @@ } } */ }, - methods: { + methods: { + // 仅用于自动化测试 + onChildReady() { + const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance); + this.selectCount = instance2.$data['selectCount'] as number; + this.selectAllCount = instance2.$data['selectAllCount'] as number; + }, // 仅用于自动化测试 getRootNodeInfo(selector : string) { uni.createSelectorQuery().select(selector).boundingClientRect().exec((ret) => { diff --git a/pages/API/create-selector-query/selector-query-child-multi.uvue b/pages/API/create-selector-query/selector-query-child-multi.uvue index d618b55b..975578a2 100644 --- a/pages/API/create-selector-query/selector-query-child-multi.uvue +++ b/pages/API/create-selector-query/selector-query-child-multi.uvue @@ -21,7 +21,8 @@ viewCount: 0, selectCount: 0, selectAllCount: 0, - show: false + show: false, + testCounter: 0 } }, mounted() { @@ -29,14 +30,25 @@ this.text1 = JSON.stringify(ret, null, 2) if (ret.length == 1) { this.selectCount = ret.length - } + } + this.testCounter++ + this._dispatchEvent() }) uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => { this.text2 = JSON.stringify(ret, null, 2) if (ret.length == 1) { this.selectAllCount = (ret[0] as NodeInfo[]).length - } + } + this.testCounter++ + this._dispatchEvent() }) + }, + methods: { + _dispatchEvent() { + if (this.testCounter == 2) { + uni.$emit('childReady') + } + } } } -- GitLab