toast.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export default class Toast{
  2. static show(icon, title, duration) {
  3. if (icon === 'loading') {
  4. wx.showToast({
  5. title: title,
  6. icon: 'loading',
  7. duration: duration ? duration : 2000,
  8. })
  9. } else if (icon === 'success') {
  10. wx.showToast({
  11. title: title,
  12. icon: 'success',
  13. duration: duration ? duration : 2000,
  14. })
  15. } else if (icon === 'warn') {
  16. wx.showToast({
  17. title: title,
  18. duration: duration ? duration : 2000,
  19. image: '../../image/global/loading_fail.png'
  20. })
  21. }
  22. }
  23. static showNormalLoading(text) {
  24. if (wx.showLoading) {
  25. wx.showLoading({
  26. title: text ? text : '加载中...',
  27. mask: true
  28. })
  29. } else {
  30. wx.showToast({
  31. title: text,
  32. icon: 'loading',
  33. duration: 2000,
  34. })
  35. }
  36. }
  37. static hidden() {
  38. wx.hideToast();
  39. if (wx.hideLoading) {
  40. wx.hideLoading();
  41. }
  42. }
  43. }