iconfont_component.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template id="iconfont">
  2. <div class="icon-wrap" :style="iconBgStyle">
  3. <i class="js-icon" :class="iconClass" :style="iconStyle"></i>
  4. </div>
  5. </template>
  6. <style>
  7. .icon-wrap {
  8. width: inherit;
  9. height: inherit;
  10. font-size: 100%;
  11. color: #000;
  12. display: flex;
  13. align-items: center;
  14. justify-content: center;
  15. }
  16. .icon-wrap .js-icon {
  17. font-size: 50%;
  18. line-height:1;
  19. }
  20. .icon-wrap .js-icon.gradient {
  21. -webkit-background-clip:text!important;
  22. -webkit-text-fill-color:transparent;
  23. }
  24. </style>
  25. <script>
  26. Vue.component('iconfont', {
  27. props: {
  28. icon: {
  29. type: String,
  30. default: ''
  31. },
  32. value: {
  33. type: Object,
  34. default: function () {
  35. return null;
  36. }
  37. }
  38. },
  39. computed: {
  40. iconClass(){
  41. var _class = ' ' + this.icon;
  42. if (this.value && this.value.iconColor.length > 1) _class += ' gradient';
  43. return _class;
  44. },
  45. iconBgStyle(){
  46. if (!this.value) return {};
  47. var style = {
  48. 'border-radius': this.value.bgRadius + '%',
  49. 'background': ''
  50. };
  51. if (this.value.iconBgImg) style['background'] += 'url('+ ns.img(this.value.iconBgImg) +') no-repeat bottom / contain'
  52. if (this.value.iconBgColor.length) {
  53. if (style.background) style.background += ',';
  54. if (this.value.iconBgColor.length == 1) {
  55. style.background += this.value.iconBgColor[0];
  56. } else {
  57. style['background'] += 'linear-gradient('+ this.value.iconBgColorDeg +'deg, '+ this.value.iconBgColor.join(',') +')';
  58. }
  59. }
  60. return style;
  61. },
  62. iconStyle(){
  63. if (!this.value) return {};
  64. var style = {
  65. fontSize: this.value.fontSize + '%'
  66. }
  67. if (this.value.iconColor.length == 1) {
  68. style.color = this.value.iconColor[0];
  69. } else {
  70. style['background'] = 'linear-gradient('+ this.value.iconColorDeg +'deg, '+ this.value.iconColor.join(',') +')';
  71. }
  72. return style;
  73. }
  74. },
  75. template: '#iconfont'
  76. })
  77. </script>