Skip to main content

CustomEnum 自定义枚举

类型定义

CustomEnum 类型定义

export type CustomEnum = {
enums: Array<{
label: string;
value: string;
}>;
value: string;
};

字段说明

字段类型必选描述
enumsArray<{ label: string; value: string }>枚举选项列表,每个选项包含 label(显示文本)和 value(实际值)。
valuestring当前选中的枚举值,必须与 enums 中某一项的 value 匹配。

示例

基础用法

const colorEnum: CustomEnum = {
enums: [
{ label: "红色", value: "red" },
{ label: "绿色", value: "green" },
{ label: "蓝色", value: "blue" },
],
value: "green", // 当前选中“绿色”
};

动态枚举

const statusEnum: CustomEnum = {
enums: [
{ label: "未开始", value: "pending" },
{ label: "进行中", value: "processing" },
{ label: "已完成", value: "completed" },
],
value: "processing", // 当前选中“进行中”
};

注意事项

  1. value 的匹配性
    • 必须与 enums 中某一项的 value 完全一致,否则可能导致逻辑错误。
  2. 动态更新
    • 修改 value 可切换选中状态,但需确保值存在于 enums 中。
  3. 扩展性
    • 如需支持更多字段(如禁用状态、图标等),可扩展 enums 项的类型。