index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var component_1 = require('../common/component');
  4. var color_1 = require('../common/color');
  5. var utils_1 = require('../common/utils');
  6. component_1.VantComponent({
  7. props: {
  8. message: String,
  9. background: String,
  10. type: {
  11. type: String,
  12. value: 'danger',
  13. },
  14. color: {
  15. type: String,
  16. value: color_1.WHITE,
  17. },
  18. duration: {
  19. type: Number,
  20. value: 3000,
  21. },
  22. zIndex: {
  23. type: Number,
  24. value: 110,
  25. },
  26. safeAreaInsetTop: {
  27. type: Boolean,
  28. value: false,
  29. },
  30. top: null,
  31. },
  32. data: {
  33. show: false,
  34. onOpened: null,
  35. onClose: null,
  36. onClick: null,
  37. },
  38. created: function () {
  39. var statusBarHeight = utils_1.getSystemInfoSync().statusBarHeight;
  40. this.setData({ statusBarHeight: statusBarHeight });
  41. },
  42. methods: {
  43. show: function () {
  44. var _this = this;
  45. var _a = this.data,
  46. duration = _a.duration,
  47. onOpened = _a.onOpened;
  48. clearTimeout(this.timer);
  49. this.setData({ show: true });
  50. wx.nextTick(onOpened);
  51. if (duration > 0 && duration !== Infinity) {
  52. this.timer = setTimeout(function () {
  53. _this.hide();
  54. }, duration);
  55. }
  56. },
  57. hide: function () {
  58. var onClose = this.data.onClose;
  59. clearTimeout(this.timer);
  60. this.setData({ show: false });
  61. wx.nextTick(onClose);
  62. },
  63. onTap: function (event) {
  64. var onClick = this.data.onClick;
  65. if (onClick) {
  66. onClick(event.detail);
  67. }
  68. },
  69. },
  70. });