modalUtil.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { showToast } from "@tarojs/taro";
  2. interface Option {
  3. /** 提示的内容 */
  4. title: string
  5. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  6. complete?: (res: TaroGeneral.CallbackResult) => void
  7. /** 提示的延迟时间 */
  8. duration?: number
  9. /** 接口调用失败的回调函数 */
  10. fail?: (res: TaroGeneral.CallbackResult) => void
  11. /** 图标
  12. *
  13. * 可选值:
  14. * - 'success': 显示成功图标,此时 title 文本最多显示 7 个汉字长度;
  15. * - 'error': 显示失败图标,此时 title 文本最多显示 7 个汉字长度;
  16. * - 'loading': 显示加载图标,此时 title 文本最多显示 7 个汉字长度;
  17. * - 'none': 不显示图标,此时 title 文本最多可显示两行 */
  18. icon?: 'success' | 'error' | 'loading' | 'none'
  19. /** 自定义图标的本地路径,image 的优先级高于 icon */
  20. image?: string
  21. /** 是否显示透明蒙层,防止触摸穿透 */
  22. mask?: boolean
  23. /** 接口调用成功的回调函数 */
  24. success?: (res: TaroGeneral.CallbackResult) => void
  25. }
  26. export default class ModalUtil {
  27. static toast(str: string, option: Omit<Option, "title"> = {}) {
  28. showToast({
  29. title: str || "未知错误",
  30. icon: "none",
  31. duration: 2000,
  32. ...option
  33. });
  34. }
  35. };