u-icon.vue 953 B

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