6 changed files with 125 additions and 5 deletions
@ -1,7 +1,10 @@ |
|||||
<template><span v-if="props.required" style="color: red">*</span> {{ props.label }}</template> |
<template> |
||||
|
<span :style="props.size ? 'font-size:' + props.size + 'px;' : ''"> <span v-if="props.required" style="color: red">*</span> {{ props.label }} </span> |
||||
|
</template> |
||||
<script setup lang="ts"> |
<script setup lang="ts"> |
||||
const props = defineProps({ |
const props = defineProps({ |
||||
required: { type: Boolean, default: false }, |
required: { type: Boolean, default: false }, |
||||
label: { type: String, default: '' }, |
label: { type: String, default: '' }, |
||||
|
size: { type: Number, default: undefined }, |
||||
}); |
}); |
||||
</script> |
</script> |
||||
|
@ -0,0 +1,105 @@ |
|||||
|
<template> |
||||
|
<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> |
||||
|
<div class="w-ext-radios"> |
||||
|
<template v-for="opt in props.options" :key="opt.value"> |
||||
|
<q-radio |
||||
|
v-model="modelValue" |
||||
|
:label="opt['label']" |
||||
|
:val="opt['value']" |
||||
|
:dense="props.dense" |
||||
|
:disable="fieldMethodsClass.getDisable(props, modelValue)" |
||||
|
/> |
||||
|
<w-textarea |
||||
|
v-if="opt['desc'] && modelValue === opt['value']" |
||||
|
v-model="descModelValue" |
||||
|
:label="opt['desc']['label'] || '选项说明'" |
||||
|
class="desc" |
||||
|
:rows="3" |
||||
|
:required-if="opt['desc']['requiredIf']" |
||||
|
:read-only-if="fieldMethodsClass.getDisable(props, modelValue)" |
||||
|
> |
||||
|
</w-textarea> |
||||
|
</template> |
||||
|
</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
<script setup lang="ts"> |
||||
|
import { FormFieldProps } from '@/platform/components/form/FormField.ts'; |
||||
|
import { ref, useAttrs } from 'vue'; |
||||
|
import { FormFieldMethods } from '../form/FormField'; |
||||
|
|
||||
|
const radioRef = ref(); |
||||
|
const attrs = useAttrs(); |
||||
|
const modelValue = defineModel<string | boolean | number>(); |
||||
|
const descModelValue = ref(''); |
||||
|
|
||||
|
interface FieldProps extends FormFieldProps { |
||||
|
dense?: boolean; |
||||
|
options: Array<() => void>; |
||||
|
} |
||||
|
const props = withDefaults(defineProps<FieldProps>(), { |
||||
|
showIf: true, |
||||
|
dense: true, |
||||
|
options: () => { |
||||
|
return []; |
||||
|
}, |
||||
|
}); |
||||
|
class FieldMethods extends FormFieldMethods { |
||||
|
updateValue = (value_) => { |
||||
|
if (props['onUpdateValue']) { |
||||
|
props['onUpdateValue']({ |
||||
|
value: value_, |
||||
|
form: props['form'], |
||||
|
}); |
||||
|
} |
||||
|
}; |
||||
|
validate = () => { |
||||
|
return radioRef.value.validate(); |
||||
|
}; |
||||
|
setValue = (value_) => { |
||||
|
modelValue.value = value_; |
||||
|
}; |
||||
|
getValue = () => { |
||||
|
return modelValue.value; |
||||
|
}; |
||||
|
clearValue = () => { |
||||
|
modelValue.value = undefined; |
||||
|
}; |
||||
|
} |
||||
|
const fieldMethodsClass = new FieldMethods(); |
||||
|
|
||||
|
const getDescValue = () => { |
||||
|
return descModelValue.value; |
||||
|
}; |
||||
|
const setDescValue = (val: any) => { |
||||
|
descModelValue.value = val; |
||||
|
}; |
||||
|
|
||||
|
defineExpose({ |
||||
|
validate: fieldMethodsClass.validate, |
||||
|
setValue: fieldMethodsClass.setValue, |
||||
|
getValue: fieldMethodsClass.getValue, |
||||
|
clearValue: fieldMethodsClass.clearValue, |
||||
|
getDescValue: getDescValue, |
||||
|
setDescValue: setDescValue, |
||||
|
}); |
||||
|
</script> |
||||
|
|
||||
|
<style lang="css"> |
||||
|
.w-ext-radio .w-ext-radios { |
||||
|
display: grid; |
||||
|
} |
||||
|
.w-ext-radio .desc { |
||||
|
padding-left: 18px; |
||||
|
padding-top: 5px; |
||||
|
padding-bottom: 5px; |
||||
|
padding-right: 5px; |
||||
|
} |
||||
|
.w-ext-radio .q-radio--dense .q-radio__label { |
||||
|
padding-left: 15px; |
||||
|
padding-top: 3px; |
||||
|
padding-bottom: 3px; |
||||
|
padding-right: 3px; |
||||
|
} |
||||
|
</style> |
Loading…
Reference in new issue