index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. "use strict";
  2. var _component = require("../common/component");
  3. var _utils = require("../common/utils");
  4. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  5. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  6. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  7. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  8. function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  9. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  10. var _my = require("../../__antmove/api/index.js")(my);
  11. var wx = _my;
  12. (0, _component.VantComponent)({
  13. props: {
  14. text: {
  15. type: String,
  16. value: "",
  17. observer: function observer() {
  18. var _this = this;
  19. wx.nextTick(function () {
  20. _this.init();
  21. });
  22. }
  23. },
  24. mode: {
  25. type: String,
  26. value: ""
  27. },
  28. url: {
  29. type: String,
  30. value: ""
  31. },
  32. openType: {
  33. type: String,
  34. value: "navigate"
  35. },
  36. delay: {
  37. type: Number,
  38. value: 1
  39. },
  40. speed: {
  41. type: Number,
  42. value: 50,
  43. observer: function observer() {
  44. var _this2 = this;
  45. wx.nextTick(function () {
  46. _this2.init();
  47. });
  48. }
  49. },
  50. scrollable: {
  51. type: Boolean,
  52. value: true
  53. },
  54. leftIcon: {
  55. type: String,
  56. value: ""
  57. },
  58. color: String,
  59. backgroundColor: String,
  60. background: String,
  61. wrapable: Boolean
  62. },
  63. data: {
  64. show: true
  65. },
  66. created: function created() {
  67. this.resetAnimation = wx.createAnimation({
  68. duration: 1,
  69. timingFunction: "linear"
  70. });
  71. },
  72. destroyed: function destroyed() {
  73. this.timer && clearTimeout(this.timer);
  74. },
  75. methods: {
  76. init: function init() {
  77. var _this3 = this;
  78. Promise.all([_utils.getRect.call(this, ".van-notice-bar__content"), _utils.getRect.call(this, ".van-notice-bar__wrap")]).then(function (rects) {
  79. var _rects = _slicedToArray(rects, 2),
  80. contentRect = _rects[0],
  81. wrapRect = _rects[1];
  82. if (contentRect == null || wrapRect == null || !contentRect.width || !wrapRect.width) {
  83. return;
  84. }
  85. var _this3$data = _this3.data,
  86. speed = _this3$data.speed,
  87. scrollable = _this3$data.scrollable,
  88. delay = _this3$data.delay;
  89. if (scrollable || wrapRect.width < contentRect.width) {
  90. var duration = contentRect.width / speed * 1000;
  91. _this3.wrapWidth = wrapRect.width;
  92. _this3.contentWidth = contentRect.width;
  93. _this3.duration = duration;
  94. _this3.animation = wx.createAnimation({
  95. duration: duration,
  96. timingFunction: "linear",
  97. delay: delay
  98. });
  99. _this3.scroll();
  100. }
  101. });
  102. },
  103. scroll: function scroll() {
  104. var _this4 = this;
  105. this.timer && clearTimeout(this.timer);
  106. this.timer = null;
  107. this.setData({
  108. animationData: this.resetAnimation.translateX(this.wrapWidth).step()["export"]()
  109. });
  110. (0, _utils.requestAnimationFrame)(function () {
  111. _this4.setData({
  112. animationData: _this4.animation.translateX(-_this4.contentWidth).step()["export"]()
  113. });
  114. });
  115. this.timer = setTimeout(function () {
  116. _this4.scroll();
  117. }, this.duration);
  118. },
  119. onClickIcon: function onClickIcon(event) {
  120. if (this.data.mode === "closeable") {
  121. this.timer && clearTimeout(this.timer);
  122. this.timer = null;
  123. this.setData({
  124. show: false
  125. });
  126. this.$emit("close", event.detail);
  127. }
  128. },
  129. onClick: function onClick(event) {
  130. this.$emit("click", event);
  131. }
  132. }
  133. });