Skip to content

数据源与字典系统

options 前缀协议

enum 类型通过 cellProps.options 的前缀区分数据来源:

前缀格式含义获取时机
dict:dict:orderStatus静态字典Schema 加载时即可用
api:api:fetchDeptList动态接口组件挂载时调用一次并缓存
remote:remote:searchUser远程搜索用户输入时实时调用

Schema 中保留 api: / remote: 前缀以保留语义(前端程序员一眼看出调用方式),但在 providers 层面统一为 functions 命名空间(详见 Runtime 接口)。

Runtime 解析映射:

options = "dict:xxx"     → 从 dicts 中查找
options = "api:xxx"      → 从 providers.functions[xxx] 获取,按 api 签名调用
options = "remote:xxx"   → 从 providers.functions[xxx] 获取,按 remote 签名调用

schema.dicts(Designer 预配置)

json
{
  "dicts": {
    "orderStatus": [
      { "label": "待处理", "value": "pending", "color": "warning" },
      { "label": "已完成", "value": "done", "color": "success" },
      { "label": "已取消", "value": "cancelled", "color": "info" }
    ]
  }
}

字典项结构:

字段类型必填说明
labelstring显示文本
valuestring / number数据值
colorstringElement Plus type(primary / success / warning / danger / info

字典解析优先级

dict:orderStatus
  → ① schema.dicts.orderStatus(Designer 预配置)
  → ② providers.dicts.orderStatus(Runtime 注入)
  → ③ 均未找到 → 控制台警告,渲染原始 value

远程搜索的 display 模式约定

远程搜索字段的数据层必须同时返回 value 和 label,避免列表场景 N 行数据触发 N 次反查请求:

json
{ "assignee": 42, "assigneeName": "张三" }

Schema 中通过 displayLabelKey: "assigneeName" 声明,display 模式直接读取渲染。

Released under the MIT License.