Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
01346ba8
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看板
提交
01346ba8
编写于
8月 08, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[provider]添加provider测试用例与示例
上级
b476b60b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
47 deletion
+48
-47
pages/API/provider/provider.test.js
pages/API/provider/provider.test.js
+25
-0
pages/API/provider/provider.uvue
pages/API/provider/provider.uvue
+23
-47
未找到文件。
pages/API/provider/provider.test.js
0 → 100644
浏览文件 @
01346ba8
const
PAGE_PATH
=
"
/pages/API/provider/provider
"
;
describe
(
"
provider
"
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
web
'
)
>
-
1
||
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
===
'
true
'
)
{
it
(
'
web
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
)
});
it
(
"
test getprovider
"
,
async
()
=>
{
await
page
.
callMethod
(
'
getProvider
'
);
await
page
.
waitFor
(
1000
);
let
providerIds
=
await
page
.
data
(
'
providerIds
'
)
expect
(
providerIds
[
0
]).
toEqual
(
'
wxpay
'
)
expect
(
providerIds
[
1
]).
toEqual
(
'
alipay
'
)
expect
(
providerIds
[
2
]).
toEqual
(
'
system
'
)
expect
(
providerIds
[
3
]).
toEqual
(
'
tencent
'
)
});
});
pages/API/provider/provider.uvue
浏览文件 @
01346ba8
...
@@ -22,10 +22,7 @@
...
@@ -22,10 +22,7 @@
</view>
</view>
</view>
</view>
<button class="btn-get-provider" type="primary" @click="getProviderSync">getProviderSync</button>
<button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button>
<button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button>
<button class="btn-get-provider" type="primary"
@click="getProviderObjectById">getProviderObjectById</button>
</view>
</view>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
</scroll-view>
</scroll-view>
...
@@ -50,25 +47,19 @@
...
@@ -50,25 +47,19 @@
{ service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] },
{ service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] },
{ service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] }
{ service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] }
] as ProviderItem[],
] as ProviderItem[],
provider
ObjList: [] as UniProvider
[]
provider
Ids: [] as string
[]
}
}
},
},
methods: {
methods: {
getProviderSync() {
this.serviceList.forEach((item : ProviderItem) => {
let provider = uni.getProviderSync({
service: item.service
} as GetProviderOptions)
this.updateProvider(item.service, provider.providerIds);
})
},
getProvider() {
getProvider() {
this.serviceList.forEach((item : ProviderItem) => {
this.serviceList.forEach((item : ProviderItem) => {
uni.getProvider({
uni.getProvider({
service: item.service,
service: item.service,
success: (e) => {
success: (e) => {
this.updateProvider(item.service, e.providerIds);
e.providerIds.forEach((value) => {
this.providerIds.push(value)
})
this.updateProvider(item.service, e.providerIds, e.providerObjects);
},
},
fail: (e) => {
fail: (e) => {
console.log("获取provider失败:", e);
console.log("获取provider失败:", e);
...
@@ -76,46 +67,31 @@
...
@@ -76,46 +67,31 @@
} as GetProviderOptions)
} as GetProviderOptions)
})
})
},
},
updateProvider(service : string, provider ?: string[] | null) {
updateProvider(service : string, provider ?: string[] | null
, uniProvider : UniProvider[]
) {
const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => {
const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => {
item.providerObj = []
item.providerObjMap = []
return item.service == service
return item.service == service
});
});
if (item != null && provider != null) {
if (item != null && provider != null) {
item.provider = provider
item.provider = provider
}
item.providerObj = uniProvider
},
item.providerObj.forEach((obj) => {
getProviderObjectById() {
// #ifdef APP-ANDROID
this.flag = true
if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装
this.getProvider()
var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled
let objList = []
console.log(isWeChatInstalled)
this.serviceList.forEach((value) => {
value.provider.forEach((provider) => {
let obj = uni.getProviderObjectById({
service: value.service,
provider: provider
})
if (obj != null) {
console.log(obj)
console.log(JSON.stringify(obj))
value.providerObj.push(obj)
// #ifdef APP-ANDROID
if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装
var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled
console.log(isWeChatInstalled)
}
// #endif
// #ifdef APP-IOS
const providerObjMap = this.getProviderObjectMap(obj)
console.log(providerObjMap)
value.providerObjMap.push(providerObjMap)
// #endif
}
}
// #endif
// #ifdef APP-IOS
const providerObjMap = this.getProviderObjectMap(obj)
console.log(providerObjMap)
value.providerObjMap.push(providerObjMap)
// #endif
})
})
}
)
}
},
},
// #ifdef APP-IOS
// #ifdef APP-IOS
getProviderObjectMap(provider : UniProvider) {
getProviderObjectMap(provider : UniProvider) {
...
@@ -176,4 +152,4 @@
...
@@ -176,4 +152,4 @@
.btn-get-provider {
.btn-get-provider {
margin-top: 30px;
margin-top: 30px;
}
}
</style>
</style>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录