modal.js 2.0 KB

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