|
@ -1,9 +1,14 @@ |
|
|
<template> |
|
|
<template> |
|
|
<div v-show="fieldMethodsClass.getShow(props, modelValue)" class="w-ext-radio"> |
|
|
<div v-show="fieldMethodsClass.getShow(props, modelValue)" class="w-ext-radio"> |
|
|
<w-label :required="fieldMethodsClass.getRequired(props, modelValue)" :label="attrs.label" :size="16"></w-label> |
|
|
<w-label :required="fieldMethodsClass.getRequired(props, modelValue)" :label="attrs.label" :size="16" :light="lightLabelComputed"> |
|
|
|
|
|
<template v-if="props.hideOptions" #after> |
|
|
|
|
|
<q-btn flat round color="primary" icon="expand" size="xs" @click="expandOptionsModelValue = !expandOptionsModelValue" /> |
|
|
|
|
|
</template> |
|
|
|
|
|
</w-label> |
|
|
<div class="w-ext-radios"> |
|
|
<div class="w-ext-radios"> |
|
|
<template v-for="opt in props.options" :key="opt.value"> |
|
|
<template v-for="opt in props.options" :key="opt.value"> |
|
|
<q-radio |
|
|
<q-radio |
|
|
|
|
|
v-show="!props.hideOptions || opt['value'] === modelValue || expandOptionsModelValue" |
|
|
v-model="modelValue" |
|
|
v-model="modelValue" |
|
|
:val="opt['value']" |
|
|
:val="opt['value']" |
|
|
:dense="props.dense" |
|
|
:dense="props.dense" |
|
@ -30,20 +35,23 @@ |
|
|
</div> |
|
|
</div> |
|
|
</template> |
|
|
</template> |
|
|
<script setup lang="ts"> |
|
|
<script setup lang="ts"> |
|
|
|
|
|
import { ref, useAttrs, computed, onMounted } from 'vue'; |
|
|
import { FormFieldProps } from '@/platform/components/form/FormField.ts'; |
|
|
import { FormFieldProps } from '@/platform/components/form/FormField.ts'; |
|
|
import { ref, useAttrs } from 'vue'; |
|
|
|
|
|
import { FormFieldMethods } from '../form/FormField'; |
|
|
import { FormFieldMethods } from '../form/FormField'; |
|
|
|
|
|
|
|
|
const radioRef = ref(); |
|
|
const radioRef = ref(); |
|
|
const attrs = useAttrs(); |
|
|
const attrs = useAttrs(); |
|
|
const modelValue = defineModel<string | boolean | number>(); |
|
|
const modelValue = defineModel<string | boolean | number>(); |
|
|
const descModelValue = ref(''); |
|
|
const descModelValue = ref(''); |
|
|
|
|
|
const expandOptionsModelValue = ref(false); |
|
|
|
|
|
|
|
|
interface FieldProps extends FormFieldProps { |
|
|
interface FieldProps extends FormFieldProps { |
|
|
dense?: boolean; |
|
|
dense?: boolean; |
|
|
options: Array<() => void>; |
|
|
options: Array<() => void>; |
|
|
selectedColor?: string; |
|
|
selectedColor?: string; |
|
|
selectedLabelColor?: string; |
|
|
selectedLabelColor?: string; |
|
|
|
|
|
hideOptions?: boolean; // 隐藏选项 |
|
|
|
|
|
lightNotHideOptionsLabel?: boolean; // 高亮非隐藏选项的label |
|
|
} |
|
|
} |
|
|
const props = withDefaults(defineProps<FieldProps>(), { |
|
|
const props = withDefaults(defineProps<FieldProps>(), { |
|
|
showIf: true, |
|
|
showIf: true, |
|
@ -53,6 +61,8 @@ const props = withDefaults(defineProps<FieldProps>(), { |
|
|
}, |
|
|
}, |
|
|
selectedColor: undefined, |
|
|
selectedColor: undefined, |
|
|
selectedLabelColor: undefined, |
|
|
selectedLabelColor: undefined, |
|
|
|
|
|
hideOptions: false, |
|
|
|
|
|
lightNotHideOptionsLabel: false, |
|
|
}); |
|
|
}); |
|
|
class FieldMethods extends FormFieldMethods { |
|
|
class FieldMethods extends FormFieldMethods { |
|
|
updateValue = (value_) => { |
|
|
updateValue = (value_) => { |
|
@ -84,14 +94,29 @@ const getDescValue = () => { |
|
|
const setDescValue = (val: any) => { |
|
|
const setDescValue = (val: any) => { |
|
|
descModelValue.value = val; |
|
|
descModelValue.value = val; |
|
|
}; |
|
|
}; |
|
|
|
|
|
const getExpandOptionsModelValue = () => { |
|
|
|
|
|
return expandOptionsModelValue.value; |
|
|
|
|
|
}; |
|
|
|
|
|
const setExpandOptionsModelValue = (val: boolean) => { |
|
|
|
|
|
expandOptionsModelValue.value = val; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const lightLabelComputed = computed(() => { |
|
|
|
|
|
if (props.lightNotHideOptionsLabel && !props.hideOptions) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
defineExpose({ |
|
|
defineExpose({ |
|
|
validate: fieldMethodsClass.validate, |
|
|
validate: fieldMethodsClass.validate, |
|
|
setValue: fieldMethodsClass.setValue, |
|
|
setValue: fieldMethodsClass.setValue, |
|
|
getValue: fieldMethodsClass.getValue, |
|
|
getValue: fieldMethodsClass.getValue, |
|
|
clearValue: fieldMethodsClass.clearValue, |
|
|
clearValue: fieldMethodsClass.clearValue, |
|
|
getDescValue: getDescValue, |
|
|
getDescValue, |
|
|
setDescValue: setDescValue, |
|
|
setDescValue, |
|
|
|
|
|
getExpandOptionsModelValue, |
|
|
|
|
|
setExpandOptionsModelValue, |
|
|
}); |
|
|
}); |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|