uni-icons.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <!-- #ifdef APP-NVUE -->
  3. <text :style="{ color: color, 'font-size': size + 'px' }" class="uni-icons" @click="_onClick">{{unicode}}</text>
  4. <!-- #endif -->
  5. <!-- #ifndef APP-NVUE -->
  6. <text :style="{ color: color, 'font-size': size + 'px' }" class="uni-icons" :class="['uniui-'+type,customPrefix,customPrefix?type:'']" @click="_onClick"></text>
  7. <!-- #endif -->
  8. </template>
  9. <script>
  10. import icons from './icons.js';
  11. // #ifdef APP-NVUE
  12. var domModule = weex.requireModule('dom');
  13. import iconUrl from './uniicons.ttf'
  14. domModule.addRule('fontFace', {
  15. 'fontFamily': "uniicons",
  16. 'src': "url('"+iconUrl+"')"
  17. });
  18. // #endif
  19. /**
  20. * Icons 图标
  21. * @description 用于展示 icons 图标
  22. * @tutorial https://ext.dcloud.net.cn/plugin?id=28
  23. * @property {Number} size 图标大小
  24. * @property {String} type 图标图案,参考示例
  25. * @property {String} color 图标颜色
  26. * @property {String} customPrefix 自定义图标
  27. * @event {Function} click 点击 Icon 触发事件
  28. */
  29. export default {
  30. name: 'UniIcons',
  31. emits:['click'],
  32. props: {
  33. type: {
  34. type: String,
  35. default: ''
  36. },
  37. color: {
  38. type: String,
  39. default: '#333333'
  40. },
  41. size: {
  42. type: [Number, String],
  43. default: 16
  44. },
  45. customPrefix:{
  46. type: String,
  47. default: ''
  48. }
  49. },
  50. data() {
  51. return {
  52. icons: icons.glyphs
  53. }
  54. },
  55. computed:{
  56. unicode(){
  57. let code = this.icons.find(v=>v.font_class === this.type)
  58. if(code){
  59. return unescape(`%u${code.unicode}`)
  60. }
  61. return ''
  62. }
  63. },
  64. methods: {
  65. _onClick() {
  66. this.$emit('click')
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss">
  72. /* #ifndef APP-NVUE */
  73. @import './uniicons.css';
  74. @font-face {
  75. font-family: uniicons;
  76. src: url('./uniicons.ttf') format('truetype');
  77. }
  78. /* #endif */
  79. .uni-icons {
  80. font-family: uniicons;
  81. text-decoration: none;
  82. text-align: center;
  83. }
  84. </style>