UnisKB/ui/src/components/card-checkbox/index.vue

95 lines
2.4 KiB
Vue
Raw Normal View History

2023-11-30 04:28:24 +00:00
<template>
2023-11-30 08:35:52 +00:00
<el-card
shadow="hover"
class="card-checkbox cursor"
:class="modelValue.includes(toModelValue) ? 'active' : ''"
@click="checked"
>
<div class="flex-between">
<div class="flex align-center">
<slot name="icon">
2024-01-19 09:51:27 +00:00
<AppAvatar v-if="data.type === '1'" class="mr-8 avatar-purple" shape="square" :size="32">
<img src="@/assets/icon_web.svg" style="width: 58%" alt="" />
</AppAvatar>
2024-07-15 10:08:02 +00:00
<AppAvatar v-else class="mr-12 avatar-blue" shape="square" :size="32">
2023-11-30 08:35:52 +00:00
<img src="@/assets/icon_document.svg" style="width: 58%" alt="" />
</AppAvatar>
</slot>
<slot></slot>
</div>
2023-12-04 03:54:58 +00:00
<el-checkbox v-bind:modelValue="modelValue.includes(toModelValue)"> </el-checkbox>
2023-11-30 08:35:52 +00:00
</div>
</el-card>
2023-11-30 04:28:24 +00:00
</template>
<script setup lang="ts">
2023-11-30 08:35:52 +00:00
import { computed } from 'vue'
2023-12-04 10:28:42 +00:00
defineOptions({ name: 'CardCheckbox' })
2023-11-30 04:28:24 +00:00
const props = defineProps<{
2023-11-30 08:35:52 +00:00
data: any
2023-11-30 04:28:24 +00:00
modelValue: Array<any>
valueField?: string
}>()
2023-11-30 08:35:52 +00:00
const toModelValue = computed(() => (props.valueField ? props.data[props.valueField] : props.data))
// const isChecked = computed({
// get: () => props.modelValue.includes(toModelValue.value)),
// set: (val) => val
// })
2023-11-30 04:28:24 +00:00
const emit = defineEmits(['update:modelValue'])
2023-11-30 08:35:52 +00:00
const checked = () => {
2023-11-30 04:28:24 +00:00
const value = props.modelValue ? props.modelValue : []
2023-11-30 08:35:52 +00:00
if (props.modelValue.includes(toModelValue.value)) {
2023-11-30 04:28:24 +00:00
emit(
'update:modelValue',
2023-11-30 08:35:52 +00:00
value.filter((item) => item !== toModelValue.value)
2023-11-30 04:28:24 +00:00
)
} else {
2023-11-30 08:35:52 +00:00
emit('update:modelValue', [...value, toModelValue.value])
2023-11-30 04:28:24 +00:00
}
}
</script>
<style lang="scss" scoped>
2023-11-30 08:35:52 +00:00
.card-checkbox {
&.active {
border: 1px solid var(--el-color-primary);
}
input.checkbox[type='checkbox'] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
height: 14px;
width: 14px;
position: relative;
&::after {
position: absolute;
top: 0;
background-color: white;
color: #000;
height: 13px;
width: 13px;
visibility: visible;
text-align: center;
box-sizing: border-box;
border: var(--el-border);
border-radius: var(--el-border-radius-small);
box-sizing: content-box;
content: '';
}
&:checked::after {
content: '✓';
color: #ffffff;
border-color: var(--el-color-primary);
background: var(--el-color-primary);
}
2023-11-30 04:28:24 +00:00
}
}
</style>