u-icon.vue 776 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <image
  3. :src="resolvedSrc"
  4. :style="{ width: size + 'px', height: size + 'px' }"
  5. mode="aspectFit"
  6. @click="handleClick"
  7. />
  8. </template>
  9. <script lang="uts">
  10. import { iconMap } from '@/common/icon-map';
  11. export default {
  12. props: {
  13. name: String,
  14. src: String,
  15. size: Number,
  16. active: Boolean
  17. },
  18. computed: {
  19. resolvedSrc(): string {
  20. if (this.src) return this.src;
  21. if (this.name) {
  22. const key = this.active ? `${this.name}-active` : this.name;
  23. return iconMap[key] || iconMap[this.name] || '';
  24. }
  25. return '';
  26. }
  27. },
  28. methods: {
  29. handleClick() {
  30. this.$emit('click');
  31. }
  32. }
  33. };
  34. </script>
  35. <style>
  36. image {
  37. display: block;
  38. }
  39. </style>