index.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. });