u-badge.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. const uni_modules_uviewPlus_components_uBadge_props = require("./props.js");
  3. const uni_modules_uviewPlus_libs_mixin_mpMixin = require("../../libs/mixin/mpMixin.js");
  4. const uni_modules_uviewPlus_libs_mixin_mixin = require("../../libs/mixin/mixin.js");
  5. const uni_modules_uviewPlus_libs_function_index = require("../../libs/function/index.js");
  6. const common_vendor = require("../../../../common/vendor.js");
  7. const _sfc_main = {
  8. name: "u-badge",
  9. mixins: [uni_modules_uviewPlus_libs_mixin_mpMixin.mpMixin, uni_modules_uviewPlus_components_uBadge_props.props, uni_modules_uviewPlus_libs_mixin_mixin.mixin],
  10. computed: {
  11. // 是否将badge中心与父组件右上角重合
  12. boxStyle() {
  13. let style = {};
  14. return style;
  15. },
  16. // 整个组件的样式
  17. badgeStyle() {
  18. const style = {};
  19. if (this.color) {
  20. style.color = this.color;
  21. }
  22. if (this.bgColor && !this.inverted) {
  23. style.backgroundColor = this.bgColor;
  24. }
  25. if (this.absolute) {
  26. style.position = "absolute";
  27. if (this.offset.length) {
  28. const top = this.offset[0];
  29. const right = this.offset[1] || top;
  30. style.top = uni_modules_uviewPlus_libs_function_index.addUnit(top);
  31. style.right = uni_modules_uviewPlus_libs_function_index.addUnit(right);
  32. }
  33. }
  34. return style;
  35. },
  36. showValue() {
  37. switch (this.numberType) {
  38. case "overflow":
  39. return Number(this.value) > Number(this.max) ? this.max + "+" : this.value;
  40. case "ellipsis":
  41. return Number(this.value) > Number(this.max) ? "..." : this.value;
  42. case "limit":
  43. return Number(this.value) > 999 ? Number(this.value) >= 9999 ? Math.floor(this.value / 1e4 * 100) / 100 + "w" : Math.floor(this.value / 1e3 * 100) / 100 + "k" : this.value;
  44. default:
  45. return Number(this.value);
  46. }
  47. }
  48. },
  49. methods: {
  50. addStyle: uni_modules_uviewPlus_libs_function_index.addStyle
  51. }
  52. };
  53. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  54. return common_vendor.e({
  55. a: _ctx.show && ((Number(_ctx.value) === 0 ? _ctx.showZero : true) || _ctx.isDot)
  56. }, _ctx.show && ((Number(_ctx.value) === 0 ? _ctx.showZero : true) || _ctx.isDot) ? {
  57. b: common_vendor.t(_ctx.isDot ? "" : $options.showValue),
  58. c: common_vendor.n(_ctx.isDot ? "u-badge--dot" : "u-badge--not-dot"),
  59. d: common_vendor.n(_ctx.inverted && "u-badge--inverted"),
  60. e: common_vendor.n(_ctx.shape === "horn" && "u-badge--horn"),
  61. f: common_vendor.n(`u-badge--${_ctx.type}${_ctx.inverted ? "--inverted" : ""}`),
  62. g: common_vendor.s($options.addStyle(_ctx.customStyle)),
  63. h: common_vendor.s($options.badgeStyle)
  64. } : {});
  65. }
  66. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-06cca9b7"]]);
  67. wx.createComponent(Component);