feat(g-sys-dict): 新增单选按钮渲染模式并优化渲染模式类型声明

This commit is contained in:
喵你个汪呀 2025-08-16 10:42:29 +08:00
parent a24580b036
commit c0666f146f

View File

@ -3,6 +3,8 @@
import { reactive, watch, PropType } from 'vue'; import { reactive, watch, PropType } from 'vue';
import { useUserInfo } from '/@/stores/userInfo'; import { useUserInfo } from '/@/stores/userInfo';
const renderTypeArray = ['tag', 'select', 'radio', 'checkbox', 'radio-button'] as const;
type RenderType = typeof renderTypeArray[number];
type DictItem = { type DictItem = {
[key: string]: any; [key: string]: any;
tagType?: string; tagType?: string;
@ -77,14 +79,14 @@ const props = defineProps({
}, },
/** /**
* 组件渲染方式 * 组件渲染方式
* @values 'tag', 'select', 'radio', 'checkbox' * @values 'tag', 'select', 'radio', 'checkbox', 'radio-button'
* @default 'tag' * @default 'tag'
*/ */
renderAs: { renderAs: {
type: String as PropType<'tag' | 'select' | 'radio' | 'checkbox'>, type: String as PropType<RenderType>,
default: 'tag', default: renderTypeArray[0],
validator(value: string) { validator(value: any) {
return ['tag', 'select', 'radio', 'checkbox'].includes(value); return renderTypeArray.includes(value);
}, },
}, },
/** /**
@ -233,5 +235,14 @@ watch(
</el-radio> </el-radio>
</el-radio-group> </el-radio-group>
</template> </template>
<!-- 渲染单选框按钮 -->
<template v-if="props.renderAs === 'radio-button'">
<el-radio-group v-model="state.value" v-bind="$attrs" @change="updateValue">
<el-radio-button v-for="(item, index) in state.dictData" :key="index" :value="item[propValue]">
{{ getDisplayText(item) }}
</el-radio-button>
</el-radio-group>
</template>
</template> </template>
<style scoped lang="scss"></style> <style scoped lang="scss"></style>