modal.ts 1.8 KB

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