dialog.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. let dialog = {};
  2. dialog.config = {
  3. cancelColor: '#888',
  4. confirmColor: '#3CC51F',
  5. title: '系统提示'
  6. }
  7. dialog.toast = (title, callfun = null, duration = 1000, mask = true, image = '', icon = 'none') => {
  8. uni.showToast({
  9. title: title,
  10. icon: icon,
  11. image: image,
  12. mask: mask,
  13. duration: duration
  14. });
  15. if (typeof(callfun) == 'function') {
  16. setTimeout(() => {
  17. callfun()
  18. }, duration)
  19. }
  20. };
  21. dialog.success = (title, callfun = null, duration = 1000) => {
  22. dialog.toast(title, callfun, duration, true, '/static/dialog/dialog_success.png')
  23. };
  24. dialog.error = (title, callfun = null, duration = 1000) => {
  25. dialog.toast(title, callfun, duration, true, '/static/dialog/dialog_fail.png')
  26. };
  27. dialog.warn = (title, callfun = null, duration = 1000) => {
  28. dialog.toast(title, callfun, duration, true, '/static/dialog/dialog_warn.png')
  29. };
  30. dialog.showLoading = (title = '加载中..', mask = true) => {
  31. uni.showLoading({
  32. title: title,
  33. mask: mask
  34. });
  35. };
  36. dialog.hideLoading = () => {
  37. uni.hideLoading();
  38. };
  39. ///弹出框
  40. dialog.alert = (opt) => {
  41. let def = {
  42. title: dialog.config.title,
  43. content: '',
  44. showCancel: false,
  45. cancelText: '取消',
  46. cancelColor: dialog.config.cancelColor,
  47. confirmText: '我知道了',
  48. confirmColor: dialog.config.confirmColor,
  49. }
  50. uni.showModal(Object.assign(def, opt));
  51. };
  52. ///确认对话框
  53. dialog.confirm = (opt) => {
  54. let def = {
  55. title: dialog.config.title,
  56. content: '',
  57. showCancel: true,
  58. cancelText: '取消',
  59. cancelColor: dialog.config.cancelColor,
  60. confirmText: '确定',
  61. confirmColor: dialog.config.confirmColor,
  62. }
  63. uni.showModal(Object.assign(def, opt));
  64. };
  65. //显示操作菜单
  66. dialog.actionSheet = (opt) => {
  67. let def = {
  68. itemColor: "#000000"
  69. }
  70. uni.showActionSheet(Object.assign(def, opt));
  71. };
  72. /**
  73. * 封装模态框
  74. */
  75. dialog.showModal = (content, showCancel = true, confirmColor) => {
  76. return new Promise((resolve, reject) => {
  77. uni.showModal({
  78. title: '提示',
  79. content,
  80. showCancel,
  81. confirmColor: confirmColor ? confirmColor : '#2979ff',
  82. success: (res) => {
  83. if (res.confirm) {
  84. resolve(res)
  85. }
  86. }
  87. });
  88. })
  89. }
  90. dialog.showModalAndBack = (content, confirmColor) => {
  91. uni.showModal({
  92. title: "提示",
  93. content: content,
  94. showCancel: false,
  95. confirmColor: confirmColor ? confirmColor : '#2979ff',
  96. success: (res) => {
  97. if (res.confirm) {
  98. uni.navigateBack({
  99. delta: 1
  100. })
  101. }
  102. }
  103. });
  104. }
  105. export default dialog;