diff --git a/pages/API/provider/provider.test.js b/pages/API/provider/provider.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..9329328e78f1b750511703a33b3819e405cb9fc9
--- /dev/null
+++ b/pages/API/provider/provider.test.js
@@ -0,0 +1,25 @@
+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')
+ });
+});
diff --git a/pages/API/provider/provider.uvue b/pages/API/provider/provider.uvue
index 4d8840c6bc327b2f15ba961fef569017ed7e9754..8f5db5060111ce0d0abb0dffe31b6cf9bfb7a4a9 100644
--- a/pages/API/provider/provider.uvue
+++ b/pages/API/provider/provider.uvue
@@ -22,10 +22,7 @@
-
-
@@ -50,25 +47,19 @@
{ service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] },
{ service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] }
] as ProviderItem[],
- providerObjList: [] as UniProvider[]
+ providerIds: [] as string[]
}
},
methods: {
- getProviderSync() {
- this.serviceList.forEach((item : ProviderItem) => {
- let provider = uni.getProviderSync({
- service: item.service
- } as GetProviderOptions)
-
- this.updateProvider(item.service, provider.providerIds);
- })
- },
getProvider() {
this.serviceList.forEach((item : ProviderItem) => {
uni.getProvider({
service: item.service,
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) => {
console.log("获取provider失败:", e);
@@ -76,46 +67,31 @@
} 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 => {
- item.providerObj = []
- item.providerObjMap = []
return item.service == service
});
if (item != null && provider != null) {
item.provider = provider
- }
- },
- getProviderObjectById() {
- this.flag = true
- this.getProvider()
- let objList = []
- 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
+ item.providerObj = uniProvider
+ item.providerObj.forEach((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
+
})
- })
+ }
},
+
// #ifdef APP-IOS
getProviderObjectMap(provider : UniProvider) {
@@ -176,4 +152,4 @@
.btn-get-provider {
margin-top: 30px;
}
-
+
\ No newline at end of file