index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Component, triggerEventOnly, getValueFromProps, } from '../_util/simply';
  2. import { ToastDefaultProps } from './props';
  3. Component(ToastDefaultProps, {
  4. closeMask: function () {
  5. if (this.timer) {
  6. clearTimeout(this.timer);
  7. }
  8. this.setData({ show: false });
  9. this.timer = null;
  10. triggerEventOnly(this, 'close');
  11. },
  12. handleShowToast: function () {
  13. var _this = this;
  14. this.setData({ show: true });
  15. var duration = getValueFromProps(this, 'duration');
  16. if (duration > 0) {
  17. var timer = setTimeout(function () {
  18. _this.closeMask();
  19. }, duration);
  20. this.timer = timer;
  21. }
  22. },
  23. handleClickMask: function () {
  24. var _a = getValueFromProps(this, [
  25. 'showMask',
  26. 'maskCloseable',
  27. ]), showMask = _a[0], maskCloseable = _a[1];
  28. if (showMask && maskCloseable) {
  29. this.closeMask();
  30. }
  31. },
  32. }, {
  33. show: false,
  34. }, undefined, {
  35. timer: null,
  36. didUpdate: function (prev) {
  37. var visible = getValueFromProps(this, 'visible');
  38. if (!prev.visible && visible) {
  39. this.handleShowToast();
  40. }
  41. else if (!visible && this.data.show) {
  42. this.closeMask();
  43. }
  44. },
  45. didMount: function () {
  46. var visible = getValueFromProps(this, 'visible');
  47. if (visible) {
  48. this.handleShowToast();
  49. }
  50. },
  51. });