index.js 1.6 KB

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