dialog.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. export default dialog;