chat-app/src/components/checkBox/index.vue

64 lines
1.4 KiB
Vue
Raw Normal View History

2024-12-30 06:47:02 +00:00
<template>
<div @click.stop="onCheck">
2024-12-30 06:47:02 +00:00
<tm-image :width="size" :height="size" :src="imageSrc"></tm-image>
</div>
</template>
<script setup>
import { defineProps, computed, defineEmits } from 'vue'
import circle from '@/static/image/checkBox/circle@2x.png'
import zu6039 from '@/static/image/checkBox/zu6039@2x.png'
import zu6040 from '@/static/image/checkBox/zu6040@2x.png'
import checkBoxDisabled from '@/static/image/checkBox/disabled.png'
2024-12-30 06:47:02 +00:00
const props = defineProps({
modelValue: {
type: String,
default: 'noChecked', // noChecked, checked, halfChecked, disabled
2024-12-30 06:47:02 +00:00
},
size: {
type: Number,
default: 28,
},
disabled: {
type: Boolean,
default: false,
},
})
2024-12-30 06:47:02 +00:00
const emit = defineEmits(['update:modelValue', 'change'])
2024-12-30 06:47:02 +00:00
const imageSrc = computed(() => {
if (props.disabled) {
return checkBoxDisabled
}
2024-12-30 06:47:02 +00:00
switch (props.modelValue) {
case 'noChecked':
return circle
case 'checked':
return zu6039
case 'halfChecked':
return zu6040
2024-12-30 06:47:02 +00:00
}
})
2024-12-30 06:47:02 +00:00
const onCheck = () => {
if (props.disabled) return
2024-12-30 06:47:02 +00:00
switch (props.modelValue) {
case 'noChecked':
emit('update:modelValue', 'checked')
emit('change', 'checked')
break
case 'checked':
emit('update:modelValue', 'noChecked')
emit('change', 'noChecked')
break
case 'halfChecked':
emit('update:modelValue', 'checked')
emit('change', 'checked')
break
2024-12-30 06:47:02 +00:00
}
}
2024-12-30 06:47:02 +00:00
</script>
<style scoped lang="less"></style>