index.js 1.3 KB

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