yanjinhui
10 天以前 c5de0d98241f8c8349fa38851b77efcfc61e4d26
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
<script lang="ts" setup>
import { ElCheckbox } from 'element-plus'
import { Highlight } from '@/components/Highlight'
import { PropType, computed } from 'vue'
import { LinkItem } from './types'
 
const props = defineProps({
  text: {
    type: String,
    default: ''
  },
  link: {
    type: Array as PropType<LinkItem[]>,
    default: undefined
  }
})
 
const modelValue = defineModel<boolean>()
 
const highlightKeys = computed(() => {
  return props.link?.map((item) => item.text) || []
})
 
const keyClick = (key: string) => {
  const linkItem = props.link?.find((item) => item.text === key)
  if (linkItem?.url) {
    window.open(linkItem.url)
    return
  }
  if (linkItem?.onClick) {
    linkItem.onClick()
  }
}
</script>
 
<template>
  <div class="flex items-center">
    <ElCheckbox v-model="modelValue" class="mr-0px!" />
    <Highlight class="ml-10px" :keys="highlightKeys" @click="keyClick">{{ text }}</Highlight>
  </div>
</template>