UnisKB/ui/src/components/dynamics-form/items/radio/RadioCard.vue

84 lines
2.0 KiB
Vue
Raw Normal View History

2023-11-23 09:55:39 +00:00
<template>
<div class="radio_content" v-resize="resize" :style="radioContentStyle">
<el-card
2023-11-23 09:55:39 +00:00
v-for="item in option_list"
:key="item.value"
class="item"
shadow="never"
2023-11-23 09:55:39 +00:00
:class="[modelValue == item[valueField] ? 'active' : '']"
@click="selected(item[valueField])"
>
{{ item[textField] }}
</el-card>
2023-11-23 09:55:39 +00:00
</div>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'
2023-11-23 09:55:39 +00:00
import type { FormField } from '@/components/dynamics-form/type'
const props = defineProps<{
formValue?: any
formfieldList?: Array<FormField>
field: string
otherParams: any
formField: FormField
view?: boolean
// 选中的值
modelValue?: any
}>()
const selected = (activeValue: string | number) => {
emit('update:modelValue', activeValue)
}
const emit = defineEmits(['update:modelValue'])
const width = ref<number>()
const radioContentStyle = computed(() => {
if (width.value) {
if (width.value < 350) {
return { '--maxkb-radio-card-width': '316px' }
} else if (width.value > 770) {
return { '--maxkb-radio-card-width': '378px' }
} else {
return { '--maxkb-radio-card-width': '100%' }
}
}
return {}
})
const resize = (wh: any) => {
if (wh.height) {
width.value = wh.width
}
}
2023-11-23 09:55:39 +00:00
const textField = computed(() => {
return props.formField.text_field ? props.formField.text_field : 'key'
})
const valueField = computed(() => {
return props.formField.value_field ? props.formField.value_field : 'value'
})
const option_list = computed(() => {
return props.formField.option_list ? props.formField.option_list : []
})
</script>
<style lang="scss" scoped>
.radio_content {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
width: 100%;
2023-11-23 09:55:39 +00:00
.active {
border: 1px solid var(--el-color-primary);
2024-11-29 10:47:38 +00:00
color: var(--el-color-primary);
2023-11-23 09:55:39 +00:00
}
.item {
cursor: pointer;
height: 38px;
2023-11-23 09:55:39 +00:00
display: flex;
justify-content: center;
align-items: center;
width: var(--maxkb-radio-card-width, 100%);
margin: 4px;
2023-11-23 09:55:39 +00:00
}
}
</style>