modal.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import i18 from '@/utils/i18.js'
  2. export default {
  3. // 消息提示
  4. msg(content) {
  5. content = i18(content);
  6. uni.showToast({
  7. title: content,
  8. icon: 'none'
  9. })
  10. },
  11. // 错误消息
  12. msgError(content) {
  13. content = i18(content);
  14. uni.showToast({
  15. title: content,
  16. icon: 'error'
  17. })
  18. },
  19. // 成功消息
  20. msgSuccess(content) {
  21. content = i18(content);
  22. uni.showToast({
  23. title: content,
  24. icon: 'success'
  25. })
  26. },
  27. // 隐藏消息
  28. hideMsg(content) {
  29. uni.hideToast()
  30. },
  31. // 弹出提示
  32. alert(content) {
  33. content = i18(content);
  34. uni.showModal({
  35. title: i18('提示'),
  36. content: content,
  37. showCancel: false
  38. })
  39. },
  40. // 确认窗体
  41. confirm(content) {
  42. content = i18(content);
  43. return new Promise((resolve, reject) => {
  44. uni.showModal({
  45. title: i18('提示'),
  46. content: content,
  47. cancelText: i18('取消'),
  48. confirmText: i18('确认'),
  49. success: function(res) {
  50. if (res.confirm) {
  51. resolve(res.confirm)
  52. }
  53. }
  54. })
  55. })
  56. },
  57. // 提示信息
  58. showToast(option) {
  59. option = i18(option);
  60. if (typeof option === "object") {
  61. uni.showToast(option)
  62. } else {
  63. uni.showToast({
  64. title: option,
  65. icon: "none",
  66. duration: 2500
  67. })
  68. }
  69. },
  70. // 打开遮罩层
  71. loading(content,bool) {
  72. content = i18(content);
  73. uni.showLoading({
  74. title: content,
  75. icon: 'none',
  76. mask:true
  77. });
  78. if(bool){
  79. let timer=null
  80. timer = setTimeout(() => {
  81. if (timer) {
  82. clearTimeout(timer);
  83. timer = null;
  84. uni.hideLoading()
  85. }
  86. }, 5000);
  87. }
  88. },
  89. // 关闭遮罩层
  90. closeLoading() {
  91. uni.hideLoading()
  92. }
  93. }