diff --git a/pages/component/global-events/touch-events.test.js b/pages/component/global-events/touch-events.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b17d2b1fea2090ec7cb04810545adf170ead99a1 --- /dev/null +++ b/pages/component/global-events/touch-events.test.js @@ -0,0 +1,44 @@ +const PAGE_PATH = '/pages/component/global-events/touch-events' + +describe('touch-events-test', () => { + + // 先屏蔽 android 及 web 平台 + if (process.env.uniTestPlatformInfo.startsWith('android') || process.env.uniTestPlatformInfo.startsWith('web')) { + it('other platform', () => { + expect(1).toBe(1) + }) + return + } + + let page + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor(500); + }) + + + it('touchStart-tagName-touchCount', async () => { + + let iconRect = await page.data('iconRect') + let x = iconRect.x + iconRect.width / 2.0 + let y = iconRect.y + iconRect.height / 2.0 + + // 点击图片 + await program.tap({ + x: x, + y: y, + duration: 100 + }) + + await page.waitFor(1500); + const touchTargets = await page.data('touchTargets') + const touchTargetsCount = await page.data('touchTargetsCount') + + console.log('touchTargets', touchTargets) + console.log('touchTargetsCount', touchTargetsCount) + + expect(touchTargets).toBe("IMAGEIMAGEIMAGEVIEW") + expect(touchTargetsCount).toBe(2) + }) + +}) diff --git a/pages/component/global-events/touch-events.uvue b/pages/component/global-events/touch-events.uvue index a29db6f8b115f48c1775cec33c693f84223f80d8..7987d0cee94119c5eef765d9c0bcc040596402e8 100644 --- a/pages/component/global-events/touch-events.uvue +++ b/pages/component/global-events/touch-events.uvue @@ -2,7 +2,7 @@ - + @@ -31,14 +31,28 @@ lastX: 0, lastY: 0, touchEvent: null as TouchEvent | null, - icon: null as UniElement | null + icon: null as UniElement | null, + touchTargets: "", + touchTargetsCount: 0, + iconRect : null as domRect | null } }, onReady() { - this.icon = uni.getElementById("icon") + this.icon = uni.getElementById("icon") + this.iconRect = this.icon.getBoundingClientRect() + // 加上导航栏及状态栏高度 + this.iconRect.y += uni.getSystemInfoSync().safeArea.top + 44 }, - methods: { - onTouchStart(e : TouchEvent) { + methods: { + onViewTouchStart(e : TouchEvent) { + this.touchTargets += e.target?.tagName + e.currentTarget?.tagName + this.touchTargetsCount++ + console.log(this.touchTargets, this.touchTargetsCount) + }, + onTouchStart(e : TouchEvent) { + this.touchTargetsCount++ + this.touchTargets += e.target?.tagName + e.currentTarget?.tagName + this.touchEvent = e if (!this.move) { this.move = true