u-icon.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-icon",
  5. beforeCreate() {
  6. },
  7. data() {
  8. return {};
  9. },
  10. emits: ["click"],
  11. mixins: [common_vendor.mpMixin, common_vendor.mixin, common_vendor.props$7],
  12. computed: {
  13. uClasses() {
  14. let classes = [];
  15. classes.push(this.customPrefix + "-" + this.name);
  16. if (this.customPrefix == "uicon") {
  17. classes.push("u-iconfont");
  18. } else {
  19. classes.push(this.customPrefix);
  20. }
  21. if (this.color && common_vendor.config.type.includes(this.color))
  22. classes.push("u-icon__icon--" + this.color);
  23. return classes;
  24. },
  25. iconStyle() {
  26. let style = {};
  27. style = {
  28. fontSize: common_vendor.addUnit(this.size),
  29. lineHeight: common_vendor.addUnit(this.size),
  30. fontWeight: this.bold ? "bold" : "normal",
  31. // 某些特殊情况需要设置一个到顶部的距离,才能更好的垂直居中
  32. top: common_vendor.addUnit(this.top)
  33. };
  34. if (this.color && !common_vendor.config.type.includes(this.color))
  35. style.color = this.color;
  36. return style;
  37. },
  38. // 判断传入的name属性,是否图片路径,只要带有"/"均认为是图片形式
  39. isImg() {
  40. return this.name.indexOf("/") !== -1;
  41. },
  42. imgStyle() {
  43. let style = {};
  44. style.width = this.width ? common_vendor.addUnit(this.width) : common_vendor.addUnit(this.size);
  45. style.height = this.height ? common_vendor.addUnit(this.height) : common_vendor.addUnit(this.size);
  46. return style;
  47. },
  48. // 通过图标名,查找对应的图标
  49. icon() {
  50. if (this.customPrefix !== "uicon") {
  51. return this.customIcons[this.customPrefix + "-" + this.name] || this.name;
  52. }
  53. return common_vendor.icons["uicon-" + this.name] || this.name;
  54. }
  55. },
  56. methods: {
  57. addStyle: common_vendor.addStyle,
  58. addUnit: common_vendor.addUnit,
  59. clickHandler(e) {
  60. this.$emit("click", this.index, e);
  61. this.stop && this.preventEvent(e);
  62. }
  63. }
  64. };
  65. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  66. return common_vendor.e({
  67. a: $options.isImg
  68. }, $options.isImg ? {
  69. b: _ctx.name,
  70. c: _ctx.imgMode,
  71. d: common_vendor.s($options.imgStyle),
  72. e: common_vendor.s($options.addStyle(_ctx.customStyle))
  73. } : {
  74. f: common_vendor.t($options.icon),
  75. g: common_vendor.n($options.uClasses),
  76. h: common_vendor.s($options.iconStyle),
  77. i: common_vendor.s($options.addStyle(_ctx.customStyle)),
  78. j: _ctx.hoverClass
  79. }, {
  80. k: _ctx.label !== ""
  81. }, _ctx.label !== "" ? {
  82. l: common_vendor.t(_ctx.label),
  83. m: _ctx.labelColor,
  84. n: $options.addUnit(_ctx.labelSize),
  85. o: _ctx.labelPos == "right" ? $options.addUnit(_ctx.space) : 0,
  86. p: _ctx.labelPos == "bottom" ? $options.addUnit(_ctx.space) : 0,
  87. q: _ctx.labelPos == "left" ? $options.addUnit(_ctx.space) : 0,
  88. r: _ctx.labelPos == "top" ? $options.addUnit(_ctx.space) : 0
  89. } : {}, {
  90. s: common_vendor.o((...args) => $options.clickHandler && $options.clickHandler(...args)),
  91. t: common_vendor.n("u-icon--" + _ctx.labelPos)
  92. });
  93. }
  94. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-1c933a9a"], ["__file", "C:/Users/Administrator/Desktop/srcaaa/node_modules/uview-plus/components/u-icon/u-icon.vue"]]);
  95. wx.createComponent(Component);