From 79c02b0d4a2b2eda97a3f249e5c279e40c6fc17a Mon Sep 17 00:00:00 2001 From: zq <136432190602163.com> Date: Thu, 3 Jul 2025 16:42:26 +0800 Subject: [PATCH] =?UTF-8?q?radio=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=B1=9E=E6=80=A7=E5=8F=96=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/GuipRadio.vue | 54 ++++++++++++++++++++++++++++++++++---------- src/views/elementGroups.vue | 18 +++++++++++---- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/components/GuipRadio.vue b/src/components/GuipRadio.vue index 8a7baa0..e5b286c 100644 --- a/src/components/GuipRadio.vue +++ b/src/components/GuipRadio.vue @@ -1,18 +1,14 @@ @@ -55,6 +51,33 @@ export default { type: Array, default: () => [], }, + labelKey: { + type: String, + default: 'label' + }, + // 自定义value的字段名 + valueKey: { + type: String, + default: 'value' + }, + // 格式化label的函数 + formatter: { + type: Function, + default: null + } + }, + computed: { + processedOptions() { + return this.options.map(option => { + if (this.formatter) { + return { + ...option, + formattedLabel: this.formatter(option) + } + } + return option + }) + } }, data() { return { @@ -73,6 +96,13 @@ export default { this.$emit('input', value); // 更新 v-model this.$emit('change', value); // 触发 change 事件 }, + getLabel(option) { + if (this.formatter) return option.formattedLabel || this.formatter(option) + return option[this.labelKey] + }, + getValue(option) { + return option[this.valueKey] + }, }, }; diff --git a/src/views/elementGroups.vue b/src/views/elementGroups.vue index 3d5a520..28e52b7 100644 --- a/src/views/elementGroups.vue +++ b/src/views/elementGroups.vue @@ -14,6 +14,12 @@ @change="radioChange" :rules="rules.language" />
+ + +
+
@@ -609,10 +615,10 @@ export default { input3: '', }, languageOptions: [ - { label: 'JavaScript', value: 'js', selectedLabel: 'JavaScripthhhhhhhhhh' }, - { label: 'Python', value: 'py', selectedLabel: 'JavaScripthhhhhhhhhh' }, - { label: 'Java', value: 'java', disabled: true, selectedLabel: 'JavaScripthhhhhhhhhh' }, // 禁用选项 - { label: 'Go', value: 'go', selectedLabel: 'JavaScripthhhhhhhhhh' }, + { label: 'JavaScript', value: 'js', selectedLabel: 'JavaScripthhhhhhhhhh',id:'1',name:'麻辣烫' }, + { label: 'Python', value: 'py', selectedLabel: 'JavaScripthhhhhhhhhh',id:'10',name:'易烊千玺' }, + { label: 'Java', value: 'java', disabled: true, selectedLabel: 'JavaScripthhhhhhhhhh',id:'11',name:'王鹤di' }, // 禁用选项 + { label: 'Go', value: 'go', selectedLabel: 'JavaScripthhhhhhhhhh',id:'12',name:'王俊凯' }, ], rules: { username: [ @@ -872,6 +878,10 @@ export default { } }, methods: { + // 自定义的radio label 展示内容 + formatLabel(option) { + return `${option.name} (ID: ${option.id})`; + }, findItemById(valueKey, key) { // 自动查找选中项 return this.domainOptions.find(item => item[valueKey] === this.form[key]);