messageUtils.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * 弹出系统内置的toast
  3. */
  4. function toast(title, mask = false, cb = null, icon = 'none', duration = 1500) {
  5. uni.showToast({
  6. title: title,
  7. icon: icon,
  8. mask: mask,
  9. duration: duration,
  10. success: () => {
  11. setTimeout(() => {
  12. cb && cb()
  13. }, duration)
  14. }
  15. })
  16. }
  17. /**
  18. * 弹出内置的加载框
  19. */
  20. function loading(title) {
  21. uni.showLoading({
  22. title: title,
  23. mask: true
  24. })
  25. }
  26. /**
  27. * 弹出系统内置的modal
  28. */
  29. function modal(title,
  30. content,
  31. confirmCb,
  32. showCancel = false,
  33. cancelCb = null,
  34. confirmText = "确定",
  35. cancelText = "取消") {
  36. uni.showModal({
  37. title: title,
  38. content: content,
  39. showCancel: showCancel,
  40. cancelText: cancelText,
  41. confirmText: confirmText,
  42. success: (res) => {
  43. if (res.cancel) {
  44. cancelCb && cancelCb()
  45. } else if (res.confirm) {
  46. confirmCb && confirmCb()
  47. }
  48. }
  49. })
  50. }
  51. /**
  52. * 关闭系统内置toast
  53. */
  54. function closeToast() {
  55. uni.hideToast()
  56. }
  57. /**
  58. * 关闭系统内置的加载框
  59. */
  60. function closeLoading() {
  61. uni.hideLoading()
  62. }
  63. export default {
  64. toast,
  65. loading,
  66. modal,
  67. closeToast,
  68. closeLoading
  69. }