222
schangxiang@126.com
2025-04-30 9bec4dcae002f36aa23231da11cb03a156b40110
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
import { computed, defineComponent } from 'vue'
import parse from 'style-to-object'
export default defineComponent({
  name: '图片',
  props: {
    src: {
      type: String,
      default: '',
    },
    draggable: {
      type: Boolean,
      default: false,
    },
    cursor: {
      type: String,
      default: '',
    },
    class: {
      type: String,
      default: '',
    },
    style: {
      type: [Object, String],
      default: () => ({}),
    },
    alt: {
      type: String,
    },
  },
  emits: ['click'],
  setup(props, { attrs, slots, emit }) {
    const VITE_STATIC_URL = process.env.VITE_STATIC_URL || ''
    const imgUrl = computed(() => {
      if (props.src.includes('/')) {
        return props.src
      }
      const imgName = props.src
      if (!imgName) return ''
      return `${VITE_STATIC_URL}/resources/assets/files/${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)}
          src={imgUrl.value}
          style={{ cursor: props.cursor, ...style.value }}
          class={props.class}
          alt={props.alt}
          {...attrs}
        />
      )
    }
  },
})