index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. created() {
  29. const { statusBarHeight } = wx.getSystemInfoSync();
  30. this.setData({ statusBarHeight });
  31. },
  32. methods: {
  33. show() {
  34. const { duration, onOpened } = this.data;
  35. clearTimeout(this.timer);
  36. this.setData({
  37. show: true
  38. }, onOpened);
  39. if (duration > 0 && duration !== Infinity) {
  40. this.timer = setTimeout(() => {
  41. this.hide();
  42. }, duration);
  43. }
  44. },
  45. hide() {
  46. const { onClose } = this.data;
  47. clearTimeout(this.timer);
  48. this.setData({
  49. show: false
  50. }, onClose);
  51. },
  52. onTap(event) {
  53. const { onClick } = this.data;
  54. if (onClick) {
  55. onClick(event.detail);
  56. }
  57. }
  58. }
  59. });