comfirm-view.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // 点击确定隐藏alert
  2. export function confirm(onClose) {
  3. if (onClose) {
  4. onClose()
  5. }
  6. }
  7. // 处理确定按钮点击
  8. export function handleConfirm(onClose) {
  9. confirm(onClose)
  10. }
  11. // 处理取消按钮点击
  12. export function handleCancel(onClose) {
  13. if (onClose) {
  14. onClose()
  15. }
  16. }
  17. // 默认标题
  18. export const defaultTitle = '提示'
  19. // 默认内容
  20. export const defaultContent = '这是一个提示'
  21. // 全局 comfirmView API 对象
  22. const comfirmViewAPI = {
  23. _show: false,
  24. _content: defaultContent,
  25. _title: defaultTitle,
  26. _onConfirm: null,
  27. _onCancel: null,
  28. _setShowCallback: null,
  29. show() {
  30. this._show = true
  31. if (this._setShowCallback) {
  32. this._setShowCallback(true)
  33. }
  34. },
  35. hide() {
  36. this._show = false
  37. if (this._setShowCallback) {
  38. this._setShowCallback(false)
  39. }
  40. },
  41. setContent(content) {
  42. this._content = content
  43. },
  44. setTitle(title) {
  45. this._title = title
  46. },
  47. setShowCallback(callback) {
  48. this._setShowCallback = callback
  49. },
  50. set onConfirm(callback) {
  51. console.log('comfirmView.onConfirm setter called, callback:', callback)
  52. this._onConfirm = callback
  53. },
  54. set onCancel(callback) {
  55. console.log('comfirmView.onCancel setter called, callback:', callback)
  56. this._onCancel = callback
  57. }
  58. }
  59. export default comfirmViewAPI