Skip to content

feat(mp-alipay): showToast api 支持 image 和 mask 属性 #5533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 92 additions & 1 deletion packages/uni-mp-alipay/__tests__/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ global.my = {
}),
}

import { request, showModal } from '../src/api/protocols'
import {
request,
showLoading,
showModal,
showToast,
} from '../src/api/protocols'

describe('api', () => {
test('api-request base', () => {
Expand Down Expand Up @@ -195,4 +200,90 @@ describe('api', () => {
expect(args.cancelColor).toBe(false)
expect(args.confirmColor).toBe(false)
})

test('api-alipay showLoading', () => {
global.my.canIUse = jest.fn().mockImplementation((api) => {
if (api === 'showLoading.object.mask') {
return true
}
return true
})

expect(showLoading.args).toEqual({
title: 'content',
mask: 'mask',
})
})

test('api-dingding showLoading', () => {
global.my.canIUse = jest.fn().mockImplementation((api) => {
if (api === 'showLoading.object.mask') {
return false
}
return true
})

expect(showLoading.args.mask).toBe(false)
expect(showLoading.args.title).toBe('content')
})

test('api-alipay showToast', () => {
global.my.canIUse = jest.fn().mockImplementation((api) => {
if (api === 'showToast') {
return true
}
return true
})

expect(typeof showToast).toBe('function')
const loadingArgs = showToast({ icon: 'loading' }) as any

expect(loadingArgs.name).toEqual('showLoading')
expect(loadingArgs.args).toEqual({
title: 'content',
mask: 'mask',
})

const toastArgs = showToast() as any

expect(toastArgs.name).toEqual('showToast')
expect(toastArgs.args).toEqual({
icon: 'type',
title: 'content',
mask: 'mask',
image: 'image',
})
})

test('api-dingding showToast', () => {
global.my.canIUse = jest.fn().mockImplementation((api) => {
if (
api === 'showLoading.object.mask' ||
api === 'showToast.object.image' ||
api === 'showToast.object.mask'
) {
return false
}
return true
})

expect(typeof showToast).toBe('function')
const loadingArgs = showToast({ icon: 'loading' }) as any

expect(loadingArgs.name).toEqual('showLoading')
expect(loadingArgs.args).toEqual({
title: 'content',
mask: false,
})

const toastArgs = showToast() as any

expect(toastArgs.name).toEqual('showToast')
expect(toastArgs.args).toEqual({
icon: 'type',
title: 'content',
mask: false,
image: false,
})
})
})
16 changes: 10 additions & 6 deletions packages/uni-mp-alipay/src/api/protocols.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasOwn, isArray, isPlainObject } from '@vue/shared'
import { extend, hasOwn, isArray, isPlainObject } from '@vue/shared'

import {
navigateTo as _navigateTo,
Expand Down Expand Up @@ -200,19 +200,22 @@ export function showModal({ showCancel = true }: UniApp.ShowModalOptions = {}) {
export function showToast({ icon = 'success' }: UniApp.ShowToastOptions = {}) {
const args = {
title: 'content',
icon: 'type',
image: false,
mask: false,
}
if (icon === 'loading') {
return {
name: 'showLoading',
args,
args: extend(
{ mask: my.canIUse('showLoading.object.mask') ? 'mask' : false },
args
),
}
}
return {
name: 'showToast',
args,
args: extend({ icon: 'type' }, args, {
mask: my.canIUse('showToast.object.mask') ? 'mask' : false,
image: my.canIUse('showToast.object.image') ? 'image' : false,
}),
}
}
export const showActionSheet = {
Expand All @@ -228,6 +231,7 @@ export const showActionSheet = {
export const showLoading = {
args: {
title: 'content',
mask: my.canIUse('showLoading.object.mask') ? 'mask' : false,
},
}
export const uploadFile = {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-compiler/src/template/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hyphenate, isFunction, isPlainObject, extend } from '@vue/shared'
import { extend, hyphenate, isFunction, isPlainObject } from '@vue/shared'
import {
SLOT_DEFAULT_NAME,
VIRTUAL_HOST_CLASS,
Expand Down
Loading