tip.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * 提示与加载工具类
  3. */
  4. export default class Tips {
  5. constructor() {
  6. this.isLoading = false;
  7. }
  8. /**
  9. * 弹出提示框
  10. */
  11. static success(title, duration = 1000) {
  12. setTimeout(() => {
  13. uni.showToast({
  14. title: title,
  15. icon: "success",
  16. mask: true,
  17. duration: duration
  18. });
  19. }, 300);
  20. if (duration > 0) {
  21. return new Promise((resolve, reject) => {
  22. setTimeout(() => {
  23. resolve();
  24. }, duration);
  25. });
  26. }
  27. }
  28. /**
  29. * 弹出确认窗口
  30. */
  31. static confirm(text,showCancel, payload = {}, title = "提示") {
  32. return new Promise((resolve, reject) => {
  33. uni.showModal({
  34. title: title,
  35. content: text,
  36. showCancel: showCancel,
  37. success: res => {
  38. if (res.confirm) {
  39. resolve(payload);
  40. } else if (res.cancel) {
  41. reject(payload);
  42. }
  43. },
  44. fail: res => {
  45. reject(payload);
  46. }
  47. });
  48. });
  49. }
  50. static toast(title, onHide, icon = "none") {
  51. setTimeout(() => {
  52. uni.showToast({
  53. title: title,
  54. icon: icon,
  55. mask: true,
  56. duration:1000
  57. });
  58. }, 300);
  59. // 隐藏结束回调
  60. if (onHide) {
  61. setTimeout(() => {
  62. onHide();
  63. }, 500);
  64. }
  65. }
  66. /**
  67. * 警告框
  68. */
  69. static alert(title) {
  70. uni.showToast({
  71. title: title,
  72. image: "../../static/alert.png",
  73. mask: true,
  74. duration: 1500
  75. });
  76. }
  77. /**
  78. * 错误框
  79. */
  80. static error(title, onHide) {
  81. uni.showToast({
  82. title: title,
  83. image: "../../static/error.png",
  84. mask: true,
  85. duration: 1500
  86. });
  87. // 隐藏结束回调
  88. if (onHide) {
  89. setTimeout(() => {
  90. onHide();
  91. }, 500);
  92. }
  93. }
  94. /**
  95. * 弹出加载提示
  96. */
  97. static loading(title = "加载中") {
  98. if (Tips.isLoading) {
  99. return;
  100. }
  101. Tips.isLoading = true;
  102. uni.showLoading({
  103. title: title,
  104. mask: true
  105. });
  106. }
  107. /**
  108. * 加载完毕
  109. */
  110. static loaded() {
  111. if (Tips.isLoading) {
  112. Tips.isLoading = false;
  113. uni.hideLoading();
  114. }
  115. }
  116. }
  117. /**
  118. * 静态变量,是否加载中
  119. */
  120. Tips.isLoading = false;