showToast.ts 912 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import { getRealPath } from '@dcloudio/uni-platform'
D
DCloud_LXH 已提交
2
import { elemInArray } from '../../helpers/protocol'
fxy060608's avatar
fxy060608 已提交
3 4 5

export const API_SHOW_TOAST = 'showToast'
export type API_TYPE_SHOW_TOAST = typeof uni.showToast
D
DCloud_LXH 已提交
6 7 8 9 10 11 12
export type API_TYPE_SHOW_TOAST_ICON = 'success' | 'loading' | 'none'
export const SHOW_TOAST_ICON: API_TYPE_SHOW_TOAST_ICON[] = [
  'success',
  'loading',
  'none',
]

fxy060608's avatar
fxy060608 已提交
13 14 15 16 17 18 19 20 21 22
export const ShowToastProtocol: ApiProtocol<API_TYPE_SHOW_TOAST> = {
  title: String,
  icon: String as any,
  image: String,
  duration: Number,
  mask: Boolean,
}
export const ShowToastOptions: ApiOptions<API_TYPE_SHOW_TOAST> = {
  formatArgs: {
    title: '',
D
DCloud_LXH 已提交
23 24
    icon(type, params) {
      params.icon = elemInArray(type, SHOW_TOAST_ICON)
fxy060608's avatar
fxy060608 已提交
25 26 27 28
    },
    image(value, params) {
      if (value) {
        params.image = getRealPath(value)
D
DCloud_LXH 已提交
29 30
      } else {
        params.image = ''
fxy060608's avatar
fxy060608 已提交
31 32 33 34 35 36
      }
    },
    duration: 1500,
    mask: false,
  },
}