yfx
2026-03-17 41d2fe31c18c0a82e0239035c2e50f10fa46c715
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<template>
  <view :class="rootClass" :style="rootStyle" @click="handleClick">
    <image v-if="isImage" class="oui-icon__image" :src="name" />
  </view>
</template>
 
<script setup lang="ts">
import { computed } from 'vue';
import type { CSSProperties } from 'vue';
import { addUnit, convertStyle, test } from '@/uni_modules/oui-utils';
import type { IconEmits } from './types';
import { iconProps } from './types';
 
defineOptions({
  name: 'oui-icon',
  options: {
    virtualHost: true,
    addGlobalClass: true,
    styleIsolation: 'apply-shared',
  },
});
 
const emit = defineEmits<IconEmits>();
 
const props = defineProps(iconProps);
 
const isImage = computed(() => {
  return test.def(props.name) && props.name?.includes('/');
});
 
const rootClass = computed(() => {
  const prefix = props.classPrefix;
  return [prefix, props.customClass, isImage.value ? 'oui-icon--image' : `${prefix}-${props.name}`];
});
 
const rootStyle = computed(() => {
  let style: CSSProperties = {
    color: props.color,
    fontSize: addUnit(props.size),
  };
 
  if (props.customStyle) {
    style = { ...style, ...convertStyle(props.customStyle) };
  }
 
  return style;
});
 
const handleClick = (event: any) => {
  emit('click', event);
};
</script>
 
<style scoped lang="scss">
@use './icons.scss';
</style>