<template>
|
<el-radio-group
|
v-model="currentValue"
|
class="product-type-switch"
|
@change="handleChange"
|
>
|
<el-radio-button
|
v-for="opt in options"
|
:key="opt.label"
|
:label="opt.label"
|
>
|
{{ opt.text }}
|
</el-radio-button>
|
</el-radio-group>
|
</template>
|
|
<script setup>
|
import { ref, watch } from 'vue'
|
|
const props = defineProps({
|
modelValue: {
|
type: [Number, String],
|
default: 1, // 默认选中第一个
|
},
|
// 可配置选项,默认是原组件的「原材料 / 半成品 / 成品」
|
options: {
|
type: Array,
|
default: () => [
|
{ label: 1, text: '原材料' },
|
{ label: 3, text: '半成品' },
|
{ label: 2, text: '成品' },
|
],
|
},
|
})
|
|
const emit = defineEmits(['update:modelValue', 'change'])
|
|
const currentValue = ref(props.modelValue)
|
|
watch(
|
() => props.modelValue,
|
(newVal) => {
|
currentValue.value = newVal
|
}
|
)
|
|
const handleChange = (value) => {
|
emit('update:modelValue', value)
|
emit('change', value)
|
}
|
</script>
|
|
<style scoped>
|
.product-type-switch {
|
display: inline-flex;
|
}
|
|
.product-type-switch :deep(.el-radio-button__inner) {
|
background-color: rgba(26, 88, 176, 0.3);
|
color: rgba(184, 200, 224, 0.8);
|
border-color: rgba(255, 255, 255, 0.2);
|
border-radius: 0;
|
padding: 6px 20px;
|
font-size: 14px;
|
transition: all 0.3s;
|
}
|
|
.product-type-switch :deep(.el-radio-button:first-child .el-radio-button__inner) {
|
border-top-left-radius: 4px;
|
border-bottom-left-radius: 4px;
|
}
|
|
.product-type-switch :deep(.el-radio-button:last-child .el-radio-button__inner) {
|
border-top-right-radius: 4px;
|
border-bottom-right-radius: 4px;
|
}
|
|
.product-type-switch :deep(.el-radio-button:not(:last-child) .el-radio-button__inner) {
|
border-right: 1px solid rgba(255, 255, 255, 0.2);
|
}
|
|
.product-type-switch :deep(.el-radio-button__original-radio:checked + .el-radio-button__inner) {
|
background: linear-gradient(180deg, #3378ff 0%, #00a4ed 100%);
|
color: #ffffff;
|
border-color: rgba(51, 120, 255, 0.8);
|
box-shadow: none;
|
}
|
|
.product-type-switch :deep(.el-radio-button__inner:hover) {
|
color: rgba(184, 200, 224, 1);
|
border-color: rgba(255, 255, 255, 0.3);
|
}
|
|
.product-type-switch :deep(.el-radio-button__original-radio:checked + .el-radio-button__inner:hover) {
|
background: linear-gradient(180deg, #4e8aff 0%, #4ee4ff 100%);
|
color: #ffffff;
|
}
|
</style>
|