AGILE TEAM
Skip to content

jh-select - 字典选择组件

平台统一的字典选择组件,基于字典数据源的下拉选择,适用于状态、类型等需要从字典表选择的场景

📝 作者
朱祥
朱祥·025877
研究院
谢飞
谢飞·026789
信息化中心

📦 组件位置

ts
import "@jhlc/common-core";

组件已全局注册,可直接在模板中使用 <jh-select />


基本用法

1️⃣ 字典选择(最常用,logicType 配置式)

ts
import { BusLogicDataType } from "@jhlc/types/src/logical-data";

export const queryItems: BaseQueryItemDesc<any>[] = [
  {
    name: "status",
    label: "状态",
    logicType: BusLogicDataType.dict,
    logicValue: "sys_status",
  },
];

源码映射规则getFormItemByLogicType):

  • BusLogicDataType.dictSelectComponent
  • BusLogicDataType.companySelectComponent
  • ⚠️ BusLogicDataType.enumsInputComponent(普通输入框),并非 SelectComponent

2️⃣ 静态选项

vue
<jh-select
  v-model="form.type"
  datasource-type="static"
  :items="[
    { label: '是', value: 1 },
    { label: '否', value: 0 }
  ]"
/>

3️⃣ 多选模式

vue
<jh-select v-model="form.types" logicType="BusLogicDataType.dict" logicValue="sys_type" multiple />

Props 属性

基础属性

参数说明类型默认值
modelValue / v-model数据绑定string | number | array | boolean-
static静态仅用来展示和点击boolean-
enableRefreshDict是否启用字典刷新booleantrue
label标题名称string下拉选择框
showColon标题与输入框之间加英文冒号booleantrue
prop字段属性,用于表单校验确定字段,选择字段后自动设置数据绑定array-
placeholder占位提示string请选择或输入
tip描述性文案string-
status状态stringdefault
size尺寸stringdefault
labelWidth标签宽度(styleY 样式,如 500px、100%,默认 450px)string-
maxWidth最大宽度(styleY 样式,如 500px、100%,默认 450px)string450px
viewer阅读模式,将输入框渲染为 spanbooleanfalse
labelClass标签样式array[]
appendText后缀string-
ctrlHidden控件隐藏表达式string-
multiDataFormat数据格式(多选时数据存储格式)stringarray
collapseTag多选折叠,多选值是否折叠展示boolean-
teleported是否插入 bodybooleantrue

交互配置

参数说明类型默认值
filterable可模糊搜索boolean-
multiple可多选booleanfalse
clearable可清除boolean-
offset下拉选项偏移量number-
allowCreate创建新条目boolean-

数据配置

参数说明类型默认值
dataType数据类型stringstring
datasourceType数据来源stringstatic
items选项array-
_optionsDsId查询接口string-
remote后端搜索boolean-
remoteSearchKey搜索关键字array-
_optionsDataAttr数据属性array | string[""]
_optionsValueAttr值属性array | string[""]
_optionsValueExpr值表达式Function-
_optionsLabelAttr标签属性array | string[""]
_optionsLabelExpr标签表达式Function-
_fixQueryParam固定查询参数object{}
fetchDataCb数据获取回调Function-
_optionsQuery查询参数array[]
_optionsQueryAttr查询属性array-
cid组件实例标识string-

⚠️ 没有 dictType/disabled 属性。字典数据通过 BaseQuery/BaseForm 的 logicType: BusLogicDataType.dict + logicValue 自动加载;禁用用 status="disabled"(非 disabled)。


Events 事件

事件名说明回调参数
update:modelValuev-model 更新时触发(value) => void
change选中值改变时触发(value) => void
blur失去焦点时触发() => void
select选中选项时触发() => void
visibleChange下拉显示/隐藏切换() => void

常见场景

场景 1:状态选择(BaseQuery/BaseForm 配置式,推荐)

ts
{
  name: "status",
  label: "状态",
  logicType: BusLogicDataType.dict,
  logicValue: "sys_status",
}

通过 logicType=dict + logicValue(字典编码)自动加载选项。


场景 2:静态选项

vue
<jh-select
  v-model="form.gender"
  datasource-type="static"
  :items="[
    { label: '男', value: 1 },
    { label: '女', value: 2 }
  ]"
/>

场景 3:禁用/只读

vue
<jh-select v-model="form.status" :status="isView ? 'readonly' : 'default'" />

status 控制状态,不是 disabled


注意事项

  1. 字典选择走 logicType 配置式

    • 在 BaseQuery/BaseForm 中用 logicType: BusLogicDataType.dict + logicValue
    • 不要用不存在的 dict-type / dictType 属性
  2. v-model 类型

    • 单选: string | number | boolean
    • 多选: string[] | number[]
  3. 多选返回类型

    • dataType"array"/"string")控制
  4. label 冒号

    • showColon 默认 true,表单内 label 会带冒号;如需关闭传 :show-colon="false"

🎯 真实项目示例

示例 1:查询条件状态筛选

ts
export const queryItems: BaseQueryItemDesc<any>[] = [
  {
    name: "status",
    label: "状态",
    logicType: BusLogicDataType.dict,
    logicValue: "sys_status",
  },
];

示例 2:静态是/否选择

vue
<jh-select
  v-model="form.enabled"
  datasource-type="static"
  :items="[
    { label: '是', value: 1 },
    { label: '否', value: 0 }
  ]"
/>

推荐作为平台统一的选择组件使用!

字典选择通过 BaseQuery/BaseForm 的 logicType=dict + logicValue 配置式自动加载;静态选项用 datasourceType="static" + items。已全局注册,可直接使用 <jh-select />

You may not distribute, modify, or sell this software without permission.