uni-notice-bar.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "UniNoticeBar",
  5. emits: ["click", "getmore", "close"],
  6. props: {
  7. text: {
  8. type: String,
  9. default: ""
  10. },
  11. moreText: {
  12. type: String,
  13. default: ""
  14. },
  15. backgroundColor: {
  16. type: String,
  17. default: "#FFF9EA"
  18. },
  19. speed: {
  20. // 默认1s滚动100px
  21. type: Number,
  22. default: 100
  23. },
  24. color: {
  25. type: String,
  26. default: "#FF9A43"
  27. },
  28. fontSize: {
  29. type: Number,
  30. default: 14
  31. },
  32. moreColor: {
  33. type: String,
  34. default: "#FF9A43"
  35. },
  36. single: {
  37. // 是否单行
  38. type: [Boolean, String],
  39. default: false
  40. },
  41. scrollable: {
  42. // 是否滚动,添加后控制单行效果取消
  43. type: [Boolean, String],
  44. default: false
  45. },
  46. showIcon: {
  47. // 是否显示左侧icon
  48. type: [Boolean, String],
  49. default: false
  50. },
  51. showGetMore: {
  52. // 是否显示右侧查看更多
  53. type: [Boolean, String],
  54. default: false
  55. },
  56. showClose: {
  57. // 是否显示左侧关闭按钮
  58. type: [Boolean, String],
  59. default: false
  60. }
  61. },
  62. data() {
  63. const elId = `Uni_${Math.ceil(Math.random() * 1e6).toString(36)}`;
  64. const elIdBox = `Uni_${Math.ceil(Math.random() * 1e6).toString(36)}`;
  65. return {
  66. textWidth: 0,
  67. boxWidth: 0,
  68. wrapWidth: "",
  69. webviewHide: false,
  70. elId,
  71. elIdBox,
  72. show: true,
  73. animationDuration: "none",
  74. animationPlayState: "paused",
  75. animationDelay: "0s"
  76. };
  77. },
  78. computed: {
  79. isShowGetMore() {
  80. return this.showGetMore === true || this.showGetMore === "true";
  81. },
  82. isShowClose() {
  83. return (this.showClose === true || this.showClose === "true") && (this.showGetMore === false || this.showGetMore === "false");
  84. }
  85. },
  86. mounted() {
  87. this.$nextTick(() => {
  88. this.initSize();
  89. });
  90. },
  91. methods: {
  92. initSize() {
  93. if (this.scrollable) {
  94. let query = [];
  95. let textQuery = new Promise((resolve, reject) => {
  96. common_vendor.index.createSelectorQuery().in(this).select(`#${this.elId}`).boundingClientRect().exec((ret) => {
  97. this.textWidth = ret[0].width;
  98. resolve();
  99. });
  100. });
  101. let boxQuery = new Promise((resolve, reject) => {
  102. common_vendor.index.createSelectorQuery().in(this).select(`#${this.elIdBox}`).boundingClientRect().exec((ret) => {
  103. this.boxWidth = ret[0].width;
  104. resolve();
  105. });
  106. });
  107. query.push(textQuery);
  108. query.push(boxQuery);
  109. Promise.all(query).then(() => {
  110. this.animationDuration = `${this.textWidth / this.speed}s`;
  111. this.animationDelay = `-${this.boxWidth / this.speed}s`;
  112. setTimeout(() => {
  113. this.animationPlayState = "running";
  114. }, 1e3);
  115. });
  116. }
  117. },
  118. loopAnimation() {
  119. },
  120. clickMore() {
  121. this.$emit("getmore");
  122. },
  123. close() {
  124. this.show = false;
  125. this.$emit("close");
  126. },
  127. onClick() {
  128. this.$emit("click");
  129. }
  130. }
  131. };
  132. if (!Array) {
  133. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  134. _easycom_uni_icons2();
  135. }
  136. const _easycom_uni_icons = () => "../../../uni-icons/components/uni-icons/uni-icons.js";
  137. if (!Math) {
  138. _easycom_uni_icons();
  139. }
  140. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  141. return common_vendor.e({
  142. a: $data.show
  143. }, $data.show ? common_vendor.e({
  144. b: $props.showIcon === true || $props.showIcon === "true"
  145. }, $props.showIcon === true || $props.showIcon === "true" ? {
  146. c: common_vendor.p({
  147. type: "sound",
  148. color: $props.color,
  149. size: $props.fontSize * 1.5
  150. })
  151. } : {}, {
  152. d: common_vendor.t($props.text),
  153. e: $data.elId,
  154. f: $props.scrollable ? 1 : "",
  155. g: !$props.scrollable && ($props.single || $props.showGetMore) ? 1 : "",
  156. h: $props.color,
  157. i: $props.fontSize + "px",
  158. j: $props.fontSize * 1.5 + "px",
  159. k: $data.wrapWidth + "px",
  160. l: $data.animationDuration,
  161. m: $data.animationDuration,
  162. n: $data.webviewHide ? "paused" : $data.animationPlayState,
  163. o: $data.webviewHide ? "paused" : $data.animationPlayState,
  164. p: $data.animationDelay,
  165. q: $data.animationDelay,
  166. r: $data.elIdBox,
  167. s: $props.scrollable ? 1 : "",
  168. t: !$props.scrollable && ($props.single || $props.moreText) ? 1 : "",
  169. v: $props.scrollable ? 1 : "",
  170. w: !$props.scrollable && ($props.single || $props.moreText) ? 1 : "",
  171. x: $props.scrollable ? $props.fontSize * 1.5 + "px" : "auto",
  172. y: $options.isShowGetMore
  173. }, $options.isShowGetMore ? common_vendor.e({
  174. z: $props.moreText.length > 0
  175. }, $props.moreText.length > 0 ? {
  176. A: common_vendor.t($props.moreText),
  177. B: $props.moreColor,
  178. C: $props.fontSize + "px"
  179. } : {
  180. D: common_vendor.p({
  181. type: "right",
  182. color: $props.moreColor,
  183. size: $props.fontSize * 1.1
  184. })
  185. }, {
  186. E: common_vendor.o((...args) => $options.clickMore && $options.clickMore(...args))
  187. }) : {}, {
  188. F: $options.isShowClose
  189. }, $options.isShowClose ? {
  190. G: common_vendor.o($options.close),
  191. H: common_vendor.p({
  192. type: "closeempty",
  193. color: $props.color,
  194. size: $props.fontSize * 1.1
  195. })
  196. } : {}, {
  197. I: $props.backgroundColor,
  198. J: common_vendor.o((...args) => $options.onClick && $options.onClick(...args))
  199. }) : {});
  200. }
  201. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-c3453ea3"], ["__file", "F:/development/HbuildWorkspace/KPS/uni_modules/uni-notice-bar/components/uni-notice-bar/uni-notice-bar.vue"]]);
  202. wx.createComponent(Component);