Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
237456bc
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6005
Star
91
Fork
164
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
237456bc
编写于
8月 24, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(components): 通用属性 通用事件
上级
7cd60733
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
1119 addition
and
952 deletion
+1119
-952
pages.json
pages.json
+863
-854
pages/component/view/general-attribute.test.js
pages/component/view/general-attribute.test.js
+19
-0
pages/component/view/general-attribute.uvue
pages/component/view/general-attribute.uvue
+94
-0
pages/component/view/general-event.test.js
pages/component/view/general-event.test.js
+72
-0
pages/component/view/general-event.uvue
pages/component/view/general-event.uvue
+56
-77
pages/component/view/view.uvue
pages/component/view/view.uvue
+15
-4
pages/tabBar/component.uvue
pages/tabBar/component.uvue
+0
-17
未找到文件。
pages.json
浏览文件 @
237456bc
此差异已折叠。
点击以展开。
pages/component/view/general-attribute.test.js
0 → 100644
浏览文件 @
237456bc
const
PAGE_PATH
=
'
/pages/component/view/general-attribute
'
describe
(
'
general attribute
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
1000
)
})
it
(
'
screenshot
'
,
async
()
=>
{
const
image
=
await
program
.
screenshot
()
expect
(
image
).
toMatchImageSnapshot
()
})
it
(
'
validateGeneralAttributes
'
,
async
()
=>
{
const
button
=
await
page
.
$
(
'
.btn
'
)
await
button
.
tap
()
expect
(
await
button
.
text
()).
toBe
(
'
基础属性验证成功
'
)
})
})
pages/component/view/general-attribute.uvue
0 → 100644
浏览文件 @
237456bc
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt container">
<view :id="generalId" :class="generalClass" :name="generalName" :title="generalTitle" :data-test="generalData" style="background-color: aqua" ref="general-target"> </view>
<button class="btn uni-common-mt" @click="validateGeneralAttributes">{{ validateGeneralAttrText }}</button>
<view class="view-class" :hover-class="hoverClass" ref="view-target">
<text>按下 50 ms 后背景变红</text>
<text>抬起 400 ms 后背景恢复</text>
</view>
<view class="view-class" :hover-class="hoverClass" :hover-start-time="1000" :hover-stay-time="1000" ref="view-target">
<text>按下 1000 ms 后背景变红</text>
<text>抬起 1000 ms 后背景恢复</text>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script lang="uts">
export default {
data() {
return {
title: 'general-attribute',
generalId: 'general-id',
generalClass: 'general-class',
generalName: 'general-name',
generalTitle: 'general-title',
generalData: 'general-data',
validateGeneralAttrText: '验证基础属性',
hoverClass: 'hover-class',
validateViewAttrText: '验证 view 属性',
}
},
methods: {
validateGeneralAttributes() {
const generalTarget = this.$refs.get('general-target') as INode
const generalId = generalTarget.getAttribute('id')
if (generalId != this.generalId) {
this.validateGeneralAttrText = '基础属性 id 验证失败'
return
}
const classList = generalTarget.ext['classList'] as string[]
if (!classList.includes('general-class')) {
this.validateGeneralAttrText = '基础属性 class 验证失败'
return
}
const generalName = generalTarget.getAttribute('name')
if (generalName != this.generalName) {
this.validateGeneralAttrText = '基础属性 name 验证失败'
return
}
const generalTitle = generalTarget.getAttribute('title')
if (generalTitle != this.generalTitle) {
this.validateGeneralAttrText = '基础属性 title 验证失败'
return
}
const generalData = generalTarget.getAttribute('data-test')
if (generalData != this.generalData) {
this.validateGeneralAttrText = '基础属性 data-test 验证失败'
return
}
this.validateGeneralAttrText = '基础属性验证成功'
},
},
}
</script>
<style>
.general-class {
margin: 20px 0 0 50px;
width: 240px;
height: 100px;
background-color: antiquewhite;
}
.view-class {
margin: 20px 0 0 50px;
padding: 10px;
width: 240px;
height: 100px;
background-color: antiquewhite;
}
.view-class text {
text-align: center;
}
.hover-class {
background-color: red;
}
</style>
pages/component/view/general-event.test.js
0 → 100644
浏览文件 @
237456bc
const
PAGE_PATH
=
'
/pages/component/view/general-event
'
describe
(
'
event trigger sequence
'
,
()
=>
{
let
page
let
el
beforeAll
(
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
1000
)
el
=
await
page
.
$
(
'
.target
'
)
})
it
(
'
touch
'
,
async
()
=>
{
await
el
.
touchstart
({
touches
:
[
{
identifier
:
1
,
pageX
:
100
,
pageY
:
100
,
},
],
changedTouches
:
[
{
identifier
:
1
,
pageX
:
100
,
pageY
:
100
,
},
],
})
await
el
.
touchmove
({
touches
:
[
{
identifier
:
1
,
pageX
:
100
,
pageY
:
100
,
},
],
changedTouches
:
[
{
identifier
:
1
,
pageX
:
101
,
pageY
:
101
,
},
],
})
await
el
.
touchend
({
touches
:
[],
changedTouches
:
[
{
identifier
:
1
,
pageX
:
101
,
pageY
:
101
,
},
],
})
const
data
=
await
page
.
data
()
expect
(
data
.
onTouchStartTime
).
toBeLessThan
(
data
.
onTouchMoveTime
)
expect
(
data
.
onTouchMoveTime
).
toBeLessThan
(
data
.
onTouchEndTime
)
})
it
(
'
click
'
,
async
()
=>
{
await
el
.
tap
()
const
data
=
await
page
.
data
()
expect
(
data
.
onTapTime
).
toBeLessThan
(
data
.
onClickTime
)
})
it
(
'
longPress
'
,
async
()
=>
{
const
now
=
Date
.
now
()
await
el
.
longpress
()
const
data
=
await
page
.
data
()
expect
(
now
).
toBeLessThan
(
data
.
onLongPressTime
)
})
})
pages/component/
general-event
/general-event.uvue
→
pages/component/
view
/general-event.uvue
浏览文件 @
237456bc
...
...
@@ -5,111 +5,66 @@
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt container">
<view
class="target"
@click="onClick"
@touchstart="onTouchStart"
@touchmove="onTouchMove"
@touchend="onTouchEnd"
></view>
<view v-if="clickEvent !== null">
<text class="title1">click Event: </text>
<text>x: {{ clickEvent!.x }}, y: {{ clickEvent!.y }}</text>
</view>
<view class="target" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd" @tap="onTap" @click="onClick" @longpress="onLongPress"></view>
<view v-if="touchStartEvent !== null">
<text class="title1">touchStart Event: </text>
<text class="title2">touches: </text>
<template
v-for="(touch, index) in touchStartEvent!.touches"
:key="index"
>
<template v-for="(touch, index) in touchStartEvent!.touches" :key="index">
<text class="title3">touch[{{ index }}]:</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
<text
>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
>
<text
>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
</template>
<text class="title2 uni-common-mt">changedTouches: </text>
<template
v-for="(touch, index) in touchStartEvent!.changedTouches"
:key="index"
>
<template v-for="(touch, index) in touchStartEvent!.changedTouches" :key="index">
<text class="title3">touch[{{ index }}]:</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
<text
>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
>
<text
>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
</template>
</view>
<view v-if="touchMoveEvent !== null">
<text class="title1">touchMove Event: </text>
<text class="title2">touches: </text>
<template
v-for="(touch, index) in touchMoveEvent!.touches"
:key="index"
>
<template v-for="(touch, index) in touchMoveEvent!.touches" :key="index">
<text class="title3">touch[{{ index }}]:</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
<text
>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
>
<text
>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
</template>
<text class="title2 uni-common-mt">changedTouches: </text>
<template
v-for="(touch, index) in touchMoveEvent!.changedTouches"
:key="index"
>
<template v-for="(touch, index) in touchMoveEvent!.changedTouches" :key="index">
<text class="title3">touch[{{ index }}]:</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
<text
>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
>
<text
>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
</template>
</view>
<view v-if="touchEndEvent !== null">
<text class="title1">touchEnd Event: </text>
<text class="title2">touches: </text>
<template
v-if="touchEndEvent!.touches.length > 0"
v-for="(touch, index) in touchEndEvent!.touches"
:key="index"
>
<template v-if="touchEndEvent!.touches.length > 0" v-for="(touch, index) in touchEndEvent!.touches" :key="index">
<text class="title3">touch[{{ index }}]:</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
<text
>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
>
<text
>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
</template>
<text class="title2 uni-common-mt">changedTouches: </text>
<template
v-for="(touch, index) in touchEndEvent!.changedTouches"
:key="index"
>
<template v-for="(touch, index) in touchEndEvent!.changedTouches" :key="index">
<text class="title3">touch[{{ index }}]:</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
<text
>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
>
<text
>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
</template>
</view>
<view v-if="tapEvent !== null">
<text class="title1">tap Event: </text>
<text>x: {{ tapEvent!.x }}, y: {{ tapEvent!.y }}</text>
</view>
<view v-if="clickEvent !== null">
<text class="title1">click Event: </text>
<text>x: {{ clickEvent!.x }}, y: {{ clickEvent!.y }}</text>
</view>
</view>
</view>
<!-- #ifdef APP -->
...
...
@@ -121,25 +76,49 @@ export default {
data() {
return {
title: 'general-event',
clickEvent: null as MouseEvent | null
,
onTouchStartTime: 0
,
touchStartEvent: null as TouchEvent | null,
onTouchMoveTime: 0,
touchMoveEvent: null as TouchEvent | null,
onTouchEndTime: 0,
touchEndEvent: null as TouchEvent | null,
onTapTime: 0,
tapEvent: null as MouseEvent | null,
onClickTime: 0,
clickEvent: null as MouseEvent | null,
onLongPressTime: 0,
}
},
methods: {
onClick(e: MouseEvent){
this.clickEvent = e
},
onTouchStart(e: TouchEvent){
this.touchStartEvent = e
this.onTouchStartTime = Date.now()
console.warn('onTouchStart', this.onTouchStartTime)
},
onTouchMove(e: TouchEvent){
this.touchMoveEvent = e
this.onTouchMoveTime = Date.now()
console.warn('onTouchMove', this.onTouchMoveTime)
},
onTouchEnd(e: TouchEvent){
this.touchEndEvent = e
}
this.onTouchEndTime = Date.now()
console.warn('onTouchEnd', this.onTouchEndTime)
},
onTap(e: MouseEvent){
this.tapEvent = e
this.onTapTime = Date.now()
console.warn('onTap', this.onTapTime)
},
onClick(e: MouseEvent){
this.clickEvent = e
this.onClickTime = Date.now()
console.warn('onClick', this.onClickTime)
},
onLongPress(){
this.onLongPressTime = Date.now()
console.warn('onLongPress', this.onLongPressTime)
},
},
}
</script>
...
...
pages/component/view/view.uvue
浏览文件 @
237456bc
...
...
@@ -4,7 +4,7 @@
<!-- #endif -->
<view>
<page-head title="view"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-padding-wrap uni-common-mt
uni-common-mb
">
<view>
<text class="uni-hello-text">
Flex是Flexible
...
...
@@ -232,6 +232,8 @@
</view>
</view>
</view>
<button class="uni-common-mt" @click="goGeneralAttribute">更多属性测试</button>
<button class="uni-common-mt" @click="goGeneralEvent">更多事件测试</button>
</view>
</view>
<!-- #ifdef APP -->
...
...
@@ -240,9 +242,18 @@
</template>
<script>
export default {
data() {
return {}
},
methods: {
goGeneralAttribute(){
uni.navigateTo({
url: '/pages/component/view/general-attribute'
})
},
goGeneralEvent(){
uni.navigateTo({
url: '/pages/component/view/general-event'
})
},
}
}
</script>
...
...
pages/tabBar/component.uvue
浏览文件 @
237456bc
...
...
@@ -263,23 +263,6 @@ export default {
pages: [] as Page[]
}
*/
{
id: 'general-attr-event',
name: '通用属性和事件',
open: false,
pages: [
{
name: '通用属性',
url: 'general-attr',
enable: false,
},
{
name: '通用事件',
url: '/pages/component/general-event/general-event',
enable: true,
},
] as Page[],
},
] as ListItem[],
arrowUpIcon: '/static/icons/arrow-up.png',
arrowDownIcon: '/static/icons/arrow-down.png',
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录