index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. var FONT_COLOR = '#ed6a0c';
  5. var BG_COLOR = '#fffbe8';
  6. component_1.VantComponent({
  7. props: {
  8. text: {
  9. type: String,
  10. value: ''
  11. },
  12. mode: {
  13. type: String,
  14. value: ''
  15. },
  16. url: {
  17. type: String,
  18. value: ''
  19. },
  20. openType: {
  21. type: String,
  22. value: 'navigate'
  23. },
  24. delay: {
  25. type: Number,
  26. value: 1
  27. },
  28. speed: {
  29. type: Number,
  30. value: 50
  31. },
  32. scrollable: {
  33. type: Boolean,
  34. value: true
  35. },
  36. leftIcon: {
  37. type: String,
  38. value: ''
  39. },
  40. color: {
  41. type: String,
  42. value: FONT_COLOR
  43. },
  44. backgroundColor: {
  45. type: String,
  46. value: BG_COLOR
  47. },
  48. wrapable: Boolean
  49. },
  50. data: {
  51. show: true
  52. },
  53. watch: {
  54. text: function () {
  55. this.set({}, this.init);
  56. }
  57. },
  58. created: function () {
  59. this.resetAnimation = wx.createAnimation({
  60. duration: 0,
  61. timingFunction: 'linear'
  62. });
  63. },
  64. destroyed: function () {
  65. this.timer && clearTimeout(this.timer);
  66. },
  67. methods: {
  68. init: function () {
  69. var _this = this;
  70. Promise.all([
  71. this.getRect('.van-notice-bar__content'),
  72. this.getRect('.van-notice-bar__wrap')
  73. ]).then(function (rects) {
  74. var contentRect = rects[0], wrapRect = rects[1];
  75. if (contentRect == null ||
  76. wrapRect == null ||
  77. !contentRect.width ||
  78. !wrapRect.width) {
  79. return;
  80. }
  81. var _a = _this.data, speed = _a.speed, scrollable = _a.scrollable, delay = _a.delay;
  82. if (scrollable && wrapRect.width < contentRect.width) {
  83. var duration = (contentRect.width / speed) * 1000;
  84. _this.wrapWidth = wrapRect.width;
  85. _this.contentWidth = contentRect.width;
  86. _this.duration = duration;
  87. _this.animation = wx.createAnimation({
  88. duration: duration,
  89. timingFunction: 'linear',
  90. delay: delay
  91. });
  92. _this.scroll();
  93. }
  94. });
  95. },
  96. scroll: function () {
  97. var _this = this;
  98. this.timer && clearTimeout(this.timer);
  99. this.timer = null;
  100. this.set({
  101. animationData: this.resetAnimation
  102. .translateX(this.wrapWidth)
  103. .step()
  104. .export()
  105. });
  106. setTimeout(function () {
  107. _this.set({
  108. animationData: _this.animation
  109. .translateX(-_this.contentWidth)
  110. .step()
  111. .export()
  112. });
  113. }, 20);
  114. this.timer = setTimeout(function () {
  115. _this.scroll();
  116. }, this.duration);
  117. },
  118. onClickIcon: function () {
  119. this.timer && clearTimeout(this.timer);
  120. this.timer = null;
  121. this.set({ show: false });
  122. },
  123. onClick: function (event) {
  124. this.$emit('click', event);
  125. }
  126. }
  127. });