OaAppIcon.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="oa-app-icon" :class="'oa-app-icon--' + size" :style="boxStyle">
  3. <image
  4. v-if="resolved.kind === 'ep'"
  5. class="oa-app-icon__glyph"
  6. :src="epSrc"
  7. mode="aspectFit"
  8. />
  9. <image
  10. v-else
  11. class="oa-app-icon__photo"
  12. :src="resolved.src"
  13. mode="aspectFit"
  14. />
  15. </view>
  16. </template>
  17. <script>
  18. import { resolveOaAppIcon, epIconDataUri } from '../utils/oa-app-icons.js'
  19. export default {
  20. name: 'OaAppIcon',
  21. props: {
  22. iconUrl: { type: String, default: '' },
  23. /** xs=28, sm=32, card=36, md=40, lg=48 */
  24. size: { type: String, default: 'sm' }
  25. },
  26. computed: {
  27. resolved() {
  28. return resolveOaAppIcon(this.iconUrl)
  29. },
  30. boxStyle() {
  31. if (this.resolved.kind === 'ep') {
  32. return { background: this.resolved.bg }
  33. }
  34. return {}
  35. },
  36. epSrc() {
  37. if (this.resolved.kind !== 'ep') return ''
  38. return epIconDataUri(this.resolved.icon, this.resolved.fg)
  39. }
  40. }
  41. }
  42. </script>
  43. <style scoped>
  44. .oa-app-icon {
  45. flex-shrink: 0;
  46. overflow: hidden;
  47. display: flex;
  48. align-items: center;
  49. justify-content: center;
  50. }
  51. .oa-app-icon--xs {
  52. width: 28px;
  53. height: 28px;
  54. border-radius: 7px;
  55. }
  56. .oa-app-icon--sm {
  57. width: 32px;
  58. height: 32px;
  59. border-radius: 8px;
  60. }
  61. .oa-app-icon--card {
  62. width: 36px;
  63. height: 36px;
  64. border-radius: 8px;
  65. }
  66. .oa-app-icon--md {
  67. width: 40px;
  68. height: 40px;
  69. border-radius: 10px;
  70. }
  71. .oa-app-icon--lg {
  72. width: 48px;
  73. height: 48px;
  74. border-radius: 12px;
  75. }
  76. .oa-app-icon__glyph {
  77. width: 16px;
  78. height: 16px;
  79. }
  80. .oa-app-icon--xs .oa-app-icon__glyph {
  81. width: 14px;
  82. height: 14px;
  83. }
  84. .oa-app-icon--card .oa-app-icon__glyph {
  85. width: 18px;
  86. height: 18px;
  87. }
  88. .oa-app-icon--md .oa-app-icon__glyph {
  89. width: 20px;
  90. height: 20px;
  91. }
  92. .oa-app-icon--lg .oa-app-icon__glyph {
  93. width: 24px;
  94. height: 24px;
  95. }
  96. .oa-app-icon__photo {
  97. width: 100%;
  98. height: 100%;
  99. display: block;
  100. }
  101. </style>