hookehuyr

fix 单选存在补充信息情况下处理

<!--
* @Date: 2022-08-30 11:34:19
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-06-06 15:17:01
* @LastEditTime: 2024-07-19 16:39:42
* @FilePath: /data-table/src/components/RadioField/index.vue
* @Description: 单项选择控件
-->
......@@ -18,8 +18,9 @@
style="width: 100%">
<div v-for="x in item.component_props.options" :key="x.value" class="radio-wrapper">
<div v-if="item.component_props.readonly" class="readonly-show">
<div v-if="item.component_props.default === x.value" role="radio" class="van-radio van-radio--vertical" tabindex="0" aria-checked="true" data-v-04873bb2="" style="margin-bottom: 0.25rem;"><div class="van-radio__icon van-radio__icon--round van-radio__icon--checked" style="font-size: 1rem;"><i class="van-badge__wrapper van-icon van-icon-success" style="border-color: rgb(194, 145, 95); background-color: rgb(194, 145, 95);"><!----><!----><!----></i></div><span class="van-radio__label">{{ x.title }}</span></div>
<div v-if="default_value === x.value" role="radio" class="van-radio van-radio--vertical" tabindex="0" aria-checked="true" data-v-04873bb2="" style="margin-bottom: 0.25rem;"><div class="van-radio__icon van-radio__icon--round van-radio__icon--checked" style="font-size: 1rem;"><i class="van-badge__wrapper van-icon van-icon-success" style="border-color: rgb(194, 145, 95); background-color: rgb(194, 145, 95);"><!----><!----><!----></i></div><span class="van-radio__label">{{ x.title }}</span></div>
<div v-else role="radio" class="van-radio van-radio--vertical" tabindex="0" aria-checked="false" data-v-04873bb2="" style="margin-bottom: 0.25rem;"><div class="van-radio__icon van-radio__icon--round" style="font-size: 1rem;"><i class="van-badge__wrapper van-icon van-icon-success"><!----><!----><!----></i></div><span class="van-radio__label">{{ x.title }}</span></div>
<span v-if="default_value === x.value && default_affix_value">{{ default_affix_value }}</span>
</div>
<van-radio v-else :name="x.value" icon-size="1rem" :checked-color="themeVars.radioColor"
style="margin-bottom: 0.25rem">{{ x.title }}</van-radio>
......@@ -89,8 +90,10 @@ const validatorMessage = (val, rule) => {
const rules = [{ validator, message: validatorMessage }];
const emit = defineEmits(["active"]);
const radio_value = ref(props.item.component_props.default);
const radio_value = ref('');
const affix_value = ref('');
const default_value = ref('');
const default_affix_value = ref('');
const onChange = (item) => {
clearAffix()
......@@ -115,7 +118,15 @@ const clearAffix = () => {
});
}
onMounted(() => {
radio_value.value = props.item.component_props.default ? props.item.component_props.default : '';
radio_value.value = props.item.component_props.default;
// 单选存在补充信息情况下处理
if (props.item.component_props.default !== null && props.item.component_props.default.includes(':')) {
let parts = props.item.component_props.default.split(':');
let part1 = parts[0].trim(); // 去除前后空格
let part2 = parts[1].trim(); // 去除前后空格
default_value.value = part1;
default_affix_value.value = part2;
}
// 发送自定义数据结构
props.item.value = { key: props.item.key, value: radio_value.value, affix: affix_value.value, type: "radio" };
emit("active", props.item.value);
......