Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
fe0aa991
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
350
Star
2
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
fe0aa991
编写于
10月 10, 2024
作者:
辛宝Otto
🥊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: 补充 props-emits 返回值测试
上级
b0bf1462
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
217 addition
and
46 deletion
+217
-46
pages/component-instance/methods/call-method-easycom-uni-modules-composition.test.js
...thods/call-method-easycom-uni-modules-composition.test.js
+31
-0
pages/component-instance/methods/call-method-easycom-uni-modules-composition.uvue
.../methods/call-method-easycom-uni-modules-composition.uvue
+45
-15
pages/component-instance/methods/call-method-easycom-uni-modules-options.test.js
...e/methods/call-method-easycom-uni-modules-options.test.js
+30
-0
pages/component-instance/methods/call-method-easycom-uni-modules-options.uvue
...ance/methods/call-method-easycom-uni-modules-options.uvue
+47
-15
uni_modules/test-props/utssdk/app-android/event.uts
uni_modules/test-props/utssdk/app-android/event.uts
+7
-0
uni_modules/test-props/utssdk/app-android/index.uts
uni_modules/test-props/utssdk/app-android/index.uts
+4
-0
uni_modules/test-props/utssdk/app-android/index.vue
uni_modules/test-props/utssdk/app-android/index.vue
+37
-4
uni_modules/test-props/utssdk/app-ios/index.vue
uni_modules/test-props/utssdk/app-ios/index.vue
+7
-12
uni_modules/test-props/utssdk/interface.uts
uni_modules/test-props/utssdk/interface.uts
+9
-0
未找到文件。
pages/component-instance/methods/call-method-easycom-uni-modules-composition.test.js
0 → 100644
浏览文件 @
fe0aa991
const
PAGE_PATH
=
"
/pages/component-instance/methods/call-method-easycom-uni-modules-composition
"
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
callMethodTest
'
,
async
()
=>
{
// a[[]] only issue 8582
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
web
'
))
{
expect
(
1
).
toBe
(
1
)
return
}
const
delay
=
()
=>
new
Promise
((
resolve
,
_
)
=>
{
setTimeout
(()
=>
{
resolve
(
''
)
},
1000
)
})
await
page
.
callMethod
(
'
onButtonClick
'
)
await
delay
()
const
resStr1
=
await
page
.
$
(
"
#isNumListValid
"
)
const
resStr2
=
await
page
.
$
(
"
#isObjListValid
"
)
expect
(
await
resStr1
.
text
()).
toBe
(
`true`
)
expect
(
await
resStr2
.
text
()).
toBe
(
`true`
)
})
pages/component-instance/methods/call-method-easycom-uni-modules-composition.uvue
浏览文件 @
fe0aa991
<template>
<view>
<call-easy-method-uni-modules ref="callEasyMethod1"></call-easy-method-uni-modules>
<!-- #ifdef APP -->
<view>---</view>
<test-props :numList="numList" :objList='objList' @buttonclick='onButtonClick' @numListChange='numListChange'
@objListChange='objListChange' style="width: 80px;height: 30px;background-color: lightblue"></test-props>
<test-props id="btn1" :numList="numList" :objList='objList' @buttonclick='onButtonClick'
@numListChange='numListChange' @objListChange='objListChange'
style="width: 80px;height: 30px;background-color: lightblue"></test-props>
<view style="flex-direction: row ;">
<text>isNumListValid: </text>
<text id='isNumListValid'>{{isNumListValid}}</text>
...
...
@@ -12,12 +14,14 @@
<text>isObjListValid: </text>
<text id='isObjListValid'>{{isObjListValid}}</text>
</view>
<!-- #endif -->
</view>
</template>
<script setup lang="uts">
import { testInOtherFile } from './call-method-easycom-uni-modules'
import { ref, isProxy, isRef } from 'vue'
import { PropsChangeEvent } from '@/uni_modules/test-props'
const delay = () : Promise<string> =>
new Promise((resolve, _) => {
...
...
@@ -28,12 +32,8 @@
const callEasyMethod1 = ref<CallEasyMethodUniModulesComponentPublicInstance | null>(null)
const isWatched = ref(false)
const changeTimes = ref(0)
const propsList = ref<number[]>([])
const numList = ref<number[]>([1]) // 传递 props
const objList = ref<
Array<{ id : string }>
>([])
const objList = ref<
any[]
>([])
const isNumListValid = ref(false)
const isObjListValid = ref(false)
...
...
@@ -69,13 +69,48 @@
return testInOtherFile(callEasyMethod1.value!, text)
}
// #ifdef APP-ANDROID
const numListChange = (res : Map<string, Map<string, any>>) => {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
isNumListValid.value = isArray && isLengthGt0
}
// #endif
// #ifdef APP-IOS
const numListChange = (res : any) => {
isNumListValid.value = res.detail as boolean
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
isNumListValid.value = isArray && isLengthGt0
}
// #endif
// #ifdef APP-ANDROID
const objListChange = (res : Map<string, Map<string, any>>) => {
const value = res['detail']!['value'] as any[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
isObjListValid.value = isArray && isLengthGt0
}
// #endif
// #ifdef APP-IOS
const objListChange = (res : any) => {
isObjListValid.value = res.detail as boolean
const value = res['detail']!['value'] as any[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
isObjListValid.value = isArray && isLengthGt0
}
// #endif
const onButtonClick = () => {
// 改变 props: 观察 props 返回值为非响应式值
numList.value = [3, 2, 1]
objList.value = [{ id: '3' }, { id: '4' }]
}
...
...
@@ -89,10 +124,6 @@
callMethod4()
await delay()
callMethod5()
await delay()
// 改变 props: 观察 props 返回值为非响应式值
numList.value = [3, 2, 1]
objList.value = [{ id: '3' }, { id: '4' }]
}
onReady(() => {
...
...
@@ -102,7 +133,6 @@
defineExpose({
callMethodTest,
callMethodInOtherFile,
isNumListValid,
isObjListValid
onButtonClick
})
</script>
pages/component-instance/methods/call-method-easycom-uni-modules-options.test.js
0 → 100644
浏览文件 @
fe0aa991
const
PAGE_PATH
=
"
/pages/component-instance/methods/call-method-easycom-uni-modules-options
"
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
callMethodTest
'
,
async
()
=>
{
// app only issue 8582
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
web
'
))
{
expect
(
1
).
toBe
(
1
)
return
}
const
delay
=
()
=>
new
Promise
((
resolve
,
_
)
=>
{
setTimeout
(()
=>
{
resolve
(
''
)
},
1000
)
})
await
page
.
callMethod
(
'
onButtonClick
'
)
await
delay
()
const
resStr1
=
await
page
.
$
(
"
#isNumListValid
"
)
const
resStr2
=
await
page
.
$
(
"
#isObjListValid
"
)
expect
(
await
resStr1
.
text
()).
toBe
(
`true`
)
expect
(
await
resStr2
.
text
()).
toBe
(
`true`
)
})
pages/component-instance/methods/call-method-easycom-uni-modules-options.uvue
浏览文件 @
fe0aa991
<template>
<view>
<call-easy-method-uni-modules ref="callEasyMethod1"></call-easy-method-uni-modules>
<!-- #ifdef APP -->
<view>---</view>
<test-props :numList="numList" :objList='objList' @buttonclick='onButtonClick' @numListChange='numListChange'
@objListChange='objListChange' style="width: 80px;height: 30px;background-color: lightblue"></test-props>
<test-props id="btn1" :numList="numList" :objList='objList' @buttonclick='onButtonClick'
@numListChange='numListChange' @objListChange='objListChange'
style="width: 80px;height: 30px;background-color: lightblue"></test-props>
<view style="flex-direction: row ;">
<text>isNumListValid: </text>
<text id='isNumListValid'>{{isNumListValid}}</text>
...
...
@@ -12,6 +15,7 @@
<text>isObjListValid: </text>
<text id='isObjListValid'>{{isObjListValid}}</text>
</view>
<!-- #endif -->
</view>
</template>
...
...
@@ -33,7 +37,7 @@
isWatched: false,
changeTimes: 0,
numList: [1] as number[], // 传递 props
objList: [] as
Array<{ id : string }>
,
objList: [] as
any[]
,
isNumListValid: false,
isObjListValid: false
}
...
...
@@ -55,10 +59,7 @@
this.callMethod4()
await delay()
this.callMethod5()
await delay()
// 改变 props: 观察 props 返回值为非响应式值
this.numList = [3, 2, 1]
this.objList = [{ id: '3' }, { id: '4' }]
},
callMethod1() {
// 调用组件的 foo1 方法
...
...
@@ -91,14 +92,45 @@
return testInOtherFile(this.callEasyMethod1!, text)
},
numListChange(res) {
this.isNumListValid = res.detail
},
objListChange(res) {
this.isObjListValid = res.detail
},
onButtonClick() {
}
// #ifdef APP-ANDROID
numListChange(res : Map<string, Map<string, any>>) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isNumListValid = isArray && isLengthGt0
},
// #endif
// #ifdef APP-IOS
numListChange(res : any) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isNumListValid = isArray && isLengthGt0
},
// #endif
// #ifdef APP-ANDROID
objListChange(res : Map<string, Map<string, any>>) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isObjListValid = isArray && isLengthGt0
},
// #endif
// #ifdef APP-IOS
objListChange(res : any) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isObjListValid = isArray && isLengthGt0
},
// #endif
onButtonClick() {
// 改变 props: 观察 props 返回值为非响应式值
console.log('button click');
this.numList = [3, 2, 1]
this.objList = [{ id: '3' }, { id: '4' }]
}
}
}
</script>
uni_modules/test-props/utssdk/app-android/event.uts
0 → 100644
浏览文件 @
fe0aa991
import { PropsChangeEvent, PropsChangeEventDetail } from './index.uts'
export class PropChangeEventImpl extends UniCustomEvent<PropsChangeEventDetail> implements PropsChangeEvent {
constructor(detail : PropsChangeEventDetail) {
super("propChange", detail);
}
}
uni_modules/test-props/utssdk/app-android/index.uts
0 → 100644
浏览文件 @
fe0aa991
import { IPropsChangeEvent,IPropsChangeEventDetail } from '../interface.uts'
export type PropsChangeEvent = IPropsChangeEvent
export type PropsChangeEventDetail = IPropsChangeEventDetail
uni_modules/test-props/utssdk/app-android/index.vue
浏览文件 @
fe0aa991
...
...
@@ -11,7 +11,8 @@
import
TextUtils
from
'
android.text.TextUtils
'
;
import
Button
from
'
android.widget.Button
'
;
import
View
from
'
android.view.View
'
;
import
{
IObjItem
,
IPropsChangeEvent
}
from
'
../interface.uts
'
import
{
PropChangeEventImpl
}
from
'
./event.uts
'
/**
* 引入三方库
* [可选实现,按需引入]
...
...
@@ -33,11 +34,11 @@
/**
* 组件名称,也就是开发者使用的标签
*/
name
:
"
uts-button
"
,
name
:
"
test-props
"
,
/**
* 组件涉及的事件声明,只有声明过的事件,才能被正常发送
*/
emits
:
[
'
buttonclick
'
],
emits
:
[
'
buttonclick
'
,
'
numListChange
'
,
'
objListChange
'
],
/**
* 属性声明,组件的使用者会传递这些属性值到组件
*/
...
...
@@ -45,6 +46,14 @@
"
buttontext
"
:
{
type
:
String
,
default
:
"
点击触发
"
},
numList
:
{
type
:
Array
as
PropType
<
number
[]
>
,
default
:
()
=>
[]
as
number
[]
},
objList
:
{
type
:
Array
as
PropType
<
IObjItem
[]
>
,
default
:
()
=>
[]
as
IObjItem
[]
}
},
/**
...
...
@@ -68,6 +77,30 @@
},
immediate
:
false
// 创建时是否通过此方法更新属性,默认值为false
},
numList
:
{
handler
(
newVal
:
number
[],
oldVal
:
number
[])
{
let
detail
=
new
Map
<
string
,
number
[]
>
()
detail
.
set
(
"
value
"
,
newVal
)
let
data
=
new
Map
<
string
,
any
>
()
data
.
set
(
"
detail
"
,
detail
)
// const event = new PropChangeEventImpl(newVal)
this
.
$emit
(
'
numListChange
'
,
data
)
},
immediate
:
true
},
objList
:
{
handler
(
newVal
:
any
[],
oldVal
:
any
[])
{
let
detail
=
new
Map
<
string
,
any
>
()
detail
.
set
(
"
value
"
,
newVal
)
let
data
=
new
Map
<
string
,
any
>
()
data
.
set
(
"
detail
"
,
detail
)
this
.
$emit
(
'
objListChange
'
,
data
)
},
immediate
:
true
}
},
/**
* 规则:如果没有配置expose,则methods中的方法均对外暴露,如果配置了expose,则以expose的配置为准向外暴露
...
...
@@ -192,4 +225,4 @@
<
style
>
</
style
>
\ No newline at end of file
</
style
>
uni_modules/test-props/utssdk/app-ios/index.vue
浏览文件 @
fe0aa991
...
...
@@ -86,25 +86,20 @@
},
numList
:
{
handler
(
newVal
:
number
[],
oldVal
:
number
[])
{
const
isNumber
=
(
val
:
number
)
:
boolean
=>
typeof
val
==
'
number
'
const
isEveryNumber
=
(
newVal
as
number
[]).
every
(
isNumber
)
const
isRawType
=
Array
.
isArray
(
newVal
)
&&
isEveryNumber
let
detail
=
new
Map
<
string
,
any
>
()
detail
.
set
(
"
value
"
,
newVal
)
let
data
=
new
Map
<
string
,
any
>
()
data
.
set
(
"
detail
"
,
isRawType
)
data
.
set
(
"
detail
"
,
detail
)
this
.
$emit
(
'
numListChange
'
,
data
)
},
immediate
:
true
},
objList
:
{
handler
(
newVal
:
any
[],
oldVal
:
any
[])
{
const
isObj
=
(
item
:
any
):
boolean
=>
item
instanceof
UTSJSONObject
const
isEveryObj
=
(
newVal
as
any
[]).
every
(
isObj
)
const
isRawType
=
Array
.
isArray
(
newVal
)
&&
isEveryObj
handler
(
newVal
:
any
[],
oldVal
:
any
[])
{
let
detail
=
new
Map
<
string
,
any
>
()
detail
.
set
(
"
value
"
,
newVal
)
let
data
=
new
Map
<
string
,
any
>
()
data
.
set
(
"
detail
"
,
isRawType
)
console
.
log
(
111
,
newVal
,
isEveryObj
,
isRawType
)
data
.
set
(
"
detail
"
,
detail
)
this
.
$emit
(
'
objListChange
'
,
data
)
},
immediate
:
true
...
...
uni_modules/test-props/utssdk/interface.uts
浏览文件 @
fe0aa991
export type IObjItem = {
id : string
}
export type IPropsChangeEventDetail = {
value : number
}
export interface IPropsChangeEvent extends UniVideoEvent {
detail : IPropsChangeEventDetail[]
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录