Showing
1 changed file
with
15 additions
and
4 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-08-30 11:34:19 | 2 | * @Date: 2022-08-30 11:34:19 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-06-06 15:17:01 | 4 | + * @LastEditTime: 2024-07-19 16:39:42 |
| 5 | * @FilePath: /data-table/src/components/RadioField/index.vue | 5 | * @FilePath: /data-table/src/components/RadioField/index.vue |
| 6 | * @Description: 单项选择控件 | 6 | * @Description: 单项选择控件 |
| 7 | --> | 7 | --> |
| ... | @@ -18,8 +18,9 @@ | ... | @@ -18,8 +18,9 @@ |
| 18 | style="width: 100%"> | 18 | style="width: 100%"> |
| 19 | <div v-for="x in item.component_props.options" :key="x.value" class="radio-wrapper"> | 19 | <div v-for="x in item.component_props.options" :key="x.value" class="radio-wrapper"> |
| 20 | <div v-if="item.component_props.readonly" class="readonly-show"> | 20 | <div v-if="item.component_props.readonly" class="readonly-show"> |
| 21 | - <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> | 21 | + <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> |
| 22 | <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> | 22 | <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> |
| 23 | + <span v-if="default_value === x.value && default_affix_value">{{ default_affix_value }}</span> | ||
| 23 | </div> | 24 | </div> |
| 24 | <van-radio v-else :name="x.value" icon-size="1rem" :checked-color="themeVars.radioColor" | 25 | <van-radio v-else :name="x.value" icon-size="1rem" :checked-color="themeVars.radioColor" |
| 25 | style="margin-bottom: 0.25rem">{{ x.title }}</van-radio> | 26 | style="margin-bottom: 0.25rem">{{ x.title }}</van-radio> |
| ... | @@ -89,8 +90,10 @@ const validatorMessage = (val, rule) => { | ... | @@ -89,8 +90,10 @@ const validatorMessage = (val, rule) => { |
| 89 | const rules = [{ validator, message: validatorMessage }]; | 90 | const rules = [{ validator, message: validatorMessage }]; |
| 90 | 91 | ||
| 91 | const emit = defineEmits(["active"]); | 92 | const emit = defineEmits(["active"]); |
| 92 | -const radio_value = ref(props.item.component_props.default); | 93 | +const radio_value = ref(''); |
| 93 | const affix_value = ref(''); | 94 | const affix_value = ref(''); |
| 95 | +const default_value = ref(''); | ||
| 96 | +const default_affix_value = ref(''); | ||
| 94 | 97 | ||
| 95 | const onChange = (item) => { | 98 | const onChange = (item) => { |
| 96 | clearAffix() | 99 | clearAffix() |
| ... | @@ -115,7 +118,15 @@ const clearAffix = () => { | ... | @@ -115,7 +118,15 @@ const clearAffix = () => { |
| 115 | }); | 118 | }); |
| 116 | } | 119 | } |
| 117 | onMounted(() => { | 120 | onMounted(() => { |
| 118 | - radio_value.value = props.item.component_props.default ? props.item.component_props.default : ''; | 121 | + radio_value.value = props.item.component_props.default; |
| 122 | + // 单选存在补充信息情况下处理 | ||
| 123 | + if (props.item.component_props.default !== null && props.item.component_props.default.includes(':')) { | ||
| 124 | + let parts = props.item.component_props.default.split(':'); | ||
| 125 | + let part1 = parts[0].trim(); // 去除前后空格 | ||
| 126 | + let part2 = parts[1].trim(); // 去除前后空格 | ||
| 127 | + default_value.value = part1; | ||
| 128 | + default_affix_value.value = part2; | ||
| 129 | + } | ||
| 119 | // 发送自定义数据结构 | 130 | // 发送自定义数据结构 |
| 120 | props.item.value = { key: props.item.key, value: radio_value.value, affix: affix_value.value, type: "radio" }; | 131 | props.item.value = { key: props.item.key, value: radio_value.value, affix: affix_value.value, type: "radio" }; |
| 121 | emit("active", props.item.value); | 132 | emit("active", props.item.value); | ... | ... |
-
Please register or login to post a comment