Skip to content

Commit 249405b

Browse files
chouchoujiOtto-J
authored andcommitted
feat(mp-alipay): showToast api 支持 image 和 mask 属性
1 parent 6f471a1 commit 249405b

File tree

3 files changed

+103
-8
lines changed

3 files changed

+103
-8
lines changed

packages/uni-mp-alipay/__tests__/api.spec.ts

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ global.my = {
3434
}),
3535
}
3636

37-
import { request, showModal } from '../src/api/protocols'
37+
import {
38+
request,
39+
showLoading,
40+
showModal,
41+
showToast,
42+
} from '../src/api/protocols'
3843

3944
describe('api', () => {
4045
test('api-request base', () => {
@@ -195,4 +200,90 @@ describe('api', () => {
195200
expect(args.cancelColor).toBe(false)
196201
expect(args.confirmColor).toBe(false)
197202
})
203+
204+
test('api-alipay showLoading', () => {
205+
global.my.canIUse = jest.fn().mockImplementation((api) => {
206+
if (api === 'showLoading.object.mask') {
207+
return true
208+
}
209+
return true
210+
})
211+
212+
expect(showLoading.args).toEqual({
213+
title: 'content',
214+
mask: 'mask',
215+
})
216+
})
217+
218+
test('api-dingding showLoading', () => {
219+
global.my.canIUse = jest.fn().mockImplementation((api) => {
220+
if (api === 'showLoading.object.mask') {
221+
return false
222+
}
223+
return true
224+
})
225+
226+
expect(showLoading.args.mask).toBe(false)
227+
expect(showLoading.args.title).toBe('content')
228+
})
229+
230+
test('api-alipay showToast', () => {
231+
global.my.canIUse = jest.fn().mockImplementation((api) => {
232+
if (api === 'showToast') {
233+
return true
234+
}
235+
return true
236+
})
237+
238+
expect(typeof showToast).toBe('function')
239+
const loadingArgs = showToast({ icon: 'loading' }) as any
240+
241+
expect(loadingArgs.name).toEqual('showLoading')
242+
expect(loadingArgs.args).toEqual({
243+
title: 'content',
244+
mask: 'mask',
245+
})
246+
247+
const toastArgs = showToast() as any
248+
249+
expect(toastArgs.name).toEqual('showToast')
250+
expect(toastArgs.args).toEqual({
251+
icon: 'type',
252+
title: 'content',
253+
mask: 'mask',
254+
image: 'image',
255+
})
256+
})
257+
258+
test('api-dingding showToast', () => {
259+
global.my.canIUse = jest.fn().mockImplementation((api) => {
260+
if (
261+
api === 'showLoading.object.mask' ||
262+
api === 'showToast.object.image' ||
263+
api === 'showToast.object.mask'
264+
) {
265+
return false
266+
}
267+
return true
268+
})
269+
270+
expect(typeof showToast).toBe('function')
271+
const loadingArgs = showToast({ icon: 'loading' }) as any
272+
273+
expect(loadingArgs.name).toEqual('showLoading')
274+
expect(loadingArgs.args).toEqual({
275+
title: 'content',
276+
mask: false,
277+
})
278+
279+
const toastArgs = showToast() as any
280+
281+
expect(toastArgs.name).toEqual('showToast')
282+
expect(toastArgs.args).toEqual({
283+
icon: 'type',
284+
title: 'content',
285+
mask: false,
286+
image: false,
287+
})
288+
})
198289
})

packages/uni-mp-alipay/src/api/protocols.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hasOwn, isArray, isPlainObject } from '@vue/shared'
1+
import { extend, hasOwn, isArray, isPlainObject } from '@vue/shared'
22

33
import {
44
navigateTo as _navigateTo,
@@ -200,19 +200,22 @@ export function showModal({ showCancel = true }: UniApp.ShowModalOptions = {}) {
200200
export function showToast({ icon = 'success' }: UniApp.ShowToastOptions = {}) {
201201
const args = {
202202
title: 'content',
203-
icon: 'type',
204-
image: false,
205-
mask: false,
206203
}
207204
if (icon === 'loading') {
208205
return {
209206
name: 'showLoading',
210-
args,
207+
args: extend(
208+
{ mask: my.canIUse('showLoading.object.mask') ? 'mask' : false },
209+
args
210+
),
211211
}
212212
}
213213
return {
214214
name: 'showToast',
215-
args,
215+
args: extend({ icon: 'type' }, args, {
216+
mask: my.canIUse('showToast.object.mask') ? 'mask' : false,
217+
image: my.canIUse('showToast.object.image') ? 'image' : false,
218+
}),
216219
}
217220
}
218221
export const showActionSheet = {
@@ -228,6 +231,7 @@ export const showActionSheet = {
228231
export const showLoading = {
229232
args: {
230233
title: 'content',
234+
mask: my.canIUse('showLoading.object.mask') ? 'mask' : false,
231235
},
232236
}
233237
export const uploadFile = {

packages/uni-mp-compiler/src/template/codegen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hyphenate, isFunction, isPlainObject, extend } from '@vue/shared'
1+
import { extend, hyphenate, isFunction, isPlainObject } from '@vue/shared'
22
import {
33
SLOT_DEFAULT_NAME,
44
VIRTUAL_HOST_CLASS,

0 commit comments

Comments
 (0)