index.js 1.2 KB

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