u-icon.js 3.3 KB

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