u-row-notice.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-row-notice",
  5. mixins: [common_vendor.mpMixin, common_vendor.mixin, common_vendor.props$19],
  6. data() {
  7. return {
  8. animationDuration: "0",
  9. // 动画执行时间
  10. animationPlayState: "paused",
  11. // 动画的开始和结束执行
  12. // nvue下,内容发生变化,导致滚动宽度也变化,需要标志为是否需要重新计算宽度
  13. // 不能在内容变化时直接重新计算,因为nvue的animation模块上一次的滚动不是刚好结束,会有影响
  14. nvueInit: true,
  15. show: true
  16. };
  17. },
  18. watch: {
  19. text: {
  20. immediate: true,
  21. handler(newValue, oldValue) {
  22. this.vue();
  23. if (!common_vendor.test.string(newValue)) {
  24. common_vendor.error("noticebar组件direction为row时,要求text参数为字符串形式");
  25. }
  26. }
  27. },
  28. fontSize() {
  29. this.vue();
  30. },
  31. speed() {
  32. this.vue();
  33. }
  34. },
  35. computed: {
  36. // 文字内容的样式
  37. textStyle() {
  38. let style = {};
  39. style.whiteSpace = "nowrap !important";
  40. style.color = this.color;
  41. style.fontSize = common_vendor.addUnit(this.fontSize);
  42. return style;
  43. },
  44. animationStyle() {
  45. let style = {};
  46. style.animationDuration = this.animationDuration;
  47. style.animationPlayState = this.animationPlayState;
  48. return style;
  49. },
  50. // 内部对用户传入的数据进一步分割,放到多个text标签循环,否则如果用户传入的字符串很长(100个字符以上)
  51. // 放在一个text标签中进行滚动,在低端安卓机上,动画可能会出现抖动现象,需要分割到多个text中可解决此问题
  52. innerText() {
  53. let result = [], len = 20;
  54. const textArr = this.text.split("");
  55. for (let i = 0; i < textArr.length; i += len) {
  56. result.push(textArr.slice(i, i + len).join(""));
  57. }
  58. return result;
  59. }
  60. },
  61. mounted() {
  62. this.init();
  63. },
  64. emits: ["click", "close"],
  65. methods: {
  66. init() {
  67. this.vue();
  68. if (!common_vendor.test.string(this.text)) {
  69. common_vendor.error("noticebar组件direction为row时,要求text参数为字符串形式");
  70. }
  71. },
  72. // vue版处理
  73. async vue() {
  74. let textWidth = 0;
  75. await common_vendor.sleep();
  76. textWidth = (await this.$uGetRect(".u-notice__content__text")).width;
  77. (await this.$uGetRect(".u-notice__content")).width;
  78. this.animationDuration = `${textWidth / common_vendor.getPx(this.speed)}s`;
  79. this.animationPlayState = "paused";
  80. setTimeout(() => {
  81. this.animationPlayState = "running";
  82. }, 10);
  83. },
  84. // nvue版处理
  85. async nvue() {
  86. },
  87. loopAnimation(textWidth, boxWidth) {
  88. },
  89. getNvueRect(el) {
  90. },
  91. // 点击通告栏
  92. clickHandler(index) {
  93. this.$emit("click");
  94. },
  95. // 点击右侧按钮,需要判断点击的是关闭图标还是箭头图标
  96. close() {
  97. this.$emit("close");
  98. }
  99. }
  100. };
  101. if (!Array) {
  102. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  103. _easycom_u_icon2();
  104. }
  105. const _easycom_u_icon = () => "../u-icon/u-icon.js";
  106. if (!Math) {
  107. _easycom_u_icon();
  108. }
  109. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  110. return common_vendor.e({
  111. a: _ctx.icon
  112. }, _ctx.icon ? {
  113. b: common_vendor.p({
  114. name: _ctx.icon,
  115. color: _ctx.color,
  116. size: "19"
  117. })
  118. } : {}, {
  119. c: common_vendor.f($options.innerText, (item, index, i0) => {
  120. return {
  121. a: common_vendor.t(item),
  122. b: index
  123. };
  124. }),
  125. d: common_vendor.s($options.textStyle),
  126. e: common_vendor.s($options.animationStyle),
  127. f: ["link", "closable"].includes(_ctx.mode)
  128. }, ["link", "closable"].includes(_ctx.mode) ? common_vendor.e({
  129. g: _ctx.mode === "link"
  130. }, _ctx.mode === "link" ? {
  131. h: common_vendor.p({
  132. name: "arrow-right",
  133. size: 17,
  134. color: _ctx.color
  135. })
  136. } : {}, {
  137. i: _ctx.mode === "closable"
  138. }, _ctx.mode === "closable" ? {
  139. j: common_vendor.o($options.close),
  140. k: common_vendor.p({
  141. name: "close",
  142. size: 16,
  143. color: _ctx.color
  144. })
  145. } : {}) : {}, {
  146. l: common_vendor.o((...args) => $options.clickHandler && $options.clickHandler(...args))
  147. });
  148. }
  149. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-462e724c"], ["__file", "D:/project/学吧/learn_applet/node_modules/uview-plus/components/u-row-notice/u-row-notice.vue"]]);
  150. wx.createComponent(Component);