index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { VantComponent } from '../common/component';
  2. import { WHITE } from '../common/color';
  3. VantComponent({
  4. props: {
  5. message: String,
  6. background: String,
  7. type: {
  8. type: String,
  9. value: 'danger'
  10. },
  11. color: {
  12. type: String,
  13. value: WHITE
  14. },
  15. duration: {
  16. type: Number,
  17. value: 3000
  18. },
  19. zIndex: {
  20. type: Number,
  21. value: 110
  22. },
  23. safeAreaInsetTop: {
  24. type: Boolean,
  25. value: false
  26. }
  27. },
  28. methods: {
  29. show() {
  30. const { duration, onOpened } = this.data;
  31. clearTimeout(this.timer);
  32. this.setData({
  33. show: true
  34. }, onOpened);
  35. if (duration > 0 && duration !== Infinity) {
  36. this.timer = setTimeout(() => {
  37. this.hide();
  38. }, duration);
  39. }
  40. },
  41. hide() {
  42. const { onClose } = this.data;
  43. clearTimeout(this.timer);
  44. this.setData({
  45. show: false
  46. }, onClose);
  47. },
  48. onTap(event) {
  49. const { onClick } = this.data;
  50. if (onClick) {
  51. onClick(event.detail);
  52. }
  53. }
  54. }
  55. });