index.js 1.5 KB

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