zs
2025-06-04 5a149d626ae8bc3fa4bddbb53f8caf40f51f6da6
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { computed, defineComponent, ref } from 'vue'
import parse from 'style-to-object'
export default defineComponent({
  name: '图标',
  props: {
    icon: {
      type: String,
      default: '',
    },
    width: {
      type: Number,
      default: 12,
    },
    height: {
      type: Number,
      default: 12,
    },
    draggable: {
      type: Boolean,
      default: false,
    },
    cursor: {
      type: String,
      default: '',
    },
    class: {
      type: String,
      default: '',
    },
    style: {
      type: [Object, String],
      default: () => ({}),
    },
  },
  emits: ['click'],
  setup(props, { attrs, slots, emit }) {
    const VITE_STATIC_URL = process.env.VITE_STATIC_URL || ''
    const imgUrl = computed(() => {
      let imgName = props.icon
      if (!imgName) return ''
      let baseDir = 'images'
      if (imgName.includes('files/')) {
        baseDir = 'files'
        imgName = imgName.split('/')[1]
      }
      return `${VITE_STATIC_URL}/resources/assets/${baseDir}/${imgName}.png`
    })
    const style = computed(() => {
      if (typeof props.style === 'string') {
        return parse(props.style)
      }
      return props.style
    })
 
    return () => {
      if (imgUrl.value.includes('undefined')) return null
 
      return (
        <img
          onClick={(evt: Event) => emit('click', evt)}
          width={props.width}
          height={props.height}
          src={imgUrl.value}
          style={{ cursor: props.cursor, ...style.value }}
          class={props.class}
          {...attrs}
        />
      )
    }
  },
})