index.js 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. var FONT_COLOR = '#fff';
  3. var BG_COLOR = '#e64340';
  4. Component({
  5. properties: {
  6. content: String,
  7. color: {
  8. type: String,
  9. value: FONT_COLOR
  10. },
  11. backgroundColor: {
  12. type: String,
  13. value: BG_COLOR
  14. },
  15. isShow: {
  16. type: Boolean,
  17. value: false
  18. },
  19. duration: {
  20. type: Number,
  21. value: 3000
  22. }
  23. },
  24. methods: {
  25. show: function show() {
  26. var _this = this;
  27. var duration = this.data.duration;
  28. this._timer && clearTimeout(this._timer);
  29. this.setData({
  30. isShow: true
  31. });
  32. if (duration > 0 && duration !== Infinity) {
  33. this._timer = setTimeout(function () {
  34. _this.hide();
  35. }, duration);
  36. }
  37. },
  38. hide: function hide() {
  39. this._timer = clearTimeout(this._timer);
  40. this.setData({
  41. isShow: false,
  42. backgroundColor: BG_COLOR
  43. });
  44. }
  45. }
  46. });