AGILE TEAM
Skip to content

jh-checkbox-group - 多选框组组件

平台统一的多选框组组件,支持静态选项、接口数据源、全选、按钮/边框风格,适用于权限、标签、多类型选择等场景

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

📦 组件位置

来源:@jhlc/common-core

ts
import "@jhlc/common-core";

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


基本用法

1️⃣ 静态选项(最常用)

vue
<template>
  <jh-checkbox-group
    v-model="form.roles"
    label="角色"
    datasource-type="static"
    :items="[
      { label: '管理员', value: 'admin' },
      { label: '编辑', value: 'editor' },
      { label: '访客', value: 'guest' }
    ]"
  />
</template>

<script setup lang="ts">
import { ref } from "vue";

const form = ref({ roles: ['admin'] });
</script>

2️⃣ 带全选

vue
<jh-checkbox-group v-model="form.perms" label="权限" :has-select-all="true" :items="permItems" />

has-select-all 开启「全选」选项。


3️⃣ 按钮风格 + 字符串格式

vue
<jh-checkbox-group
  v-model="form.tags"
  label="标签"
  type="button"
  data-format="string"
  :items="tagItems"
/>

data-format="string" 时 v-model 为逗号分隔字符串,"array" 时为数组。


Props 属性

基础属性

参数说明类型默认值
label标题名称string复选框组
showColon冒号,标题与输入框之间加英文冒号booleantrue
prop字段属性,用于表单校验,确定是哪个字段,选择字段后自动会设置数据绑定Array-
modelValue / v-model数据绑定Array | string | number-
type显示样式string-
tip描述性文案string-
status状态stringdefault
size尺寸stringdefault
labelWidth标签宽度,styleY样式,比如500px,100%,默认450pxstring-
maxWidth最大宽度,styleY样式,比如500px,100%,默认450pxstring450px
viewer阅读模式,阅读模式将输入框渲染为spanbooleanfalse
labelClass标签样式Array[]
appendText后缀string-
hasSelectAll可全选,提供全选选项工具boolean-

数据配置

参数说明类型默认值
dataFormat数据格式stringarray
dataType数据类型stringstring
datasourceType数据来源stringstatic
items选项Array-
_optionsDsId查询接口string-
_optionsDataAttr数据属性Array | string[""]
_optionsValueAttr值属性Array | string[""]
_optionsValueExpr值表达式Function-
_optionsLabelAttr标签属性Array | string[""]
_optionsLabelExpr标签表达式Function-
_fixQueryParam固定查询参数object{}
fetchDataCb数据获取回调Function-
_optionsQuery接口查询参数Array[]
_optionsQueryAttr查询参数字段Array-

⚠️ 禁用/只读用 status"disabled" / "readonly"),不是 disabled。 ⚠️ 没有 defaultValue 属性(声明层未声明,与单选组不同)。 ⚠️ 数据源:静态用 datasource-type="static" + items;接口用 datasource-type="interface" + _options* 系列属性。


Events 事件

事件名说明回调参数
update:modelValuev-model 更新时触发(value: array | string | number) => void

仅声明 update:modelValue,无 change 事件。值变化请用 v-model@update:model-value


常见场景

场景 1:角色多选(静态)

vue
<jh-checkbox-group
  v-model="form.roles"
  label="角色"
  datasource-type="static"
  :items="[{ label: '管理员', value: 'admin' }, { label: '编辑', value: 'editor' }]"
/>

场景 2:权限选择(带全选)

vue
<jh-checkbox-group v-model="form.perms" label="权限" :has-select-all="true" :items="permItems" />

场景 3:标签按钮组(字符串格式)

vue
<jh-checkbox-group
  v-model="form.tags"
  label="标签"
  type="button"
  data-format="string"
  :items="tagItems"
/>

场景 4:只读查看

vue
<jh-checkbox-group v-model="form.types" label="类型" status="readonly" :items="typeItems" />

注意事项

  1. 状态用 status,无 disabled

    • status="disabled" 禁用,status="readonly" 只读
  2. 绑定值格式用 dataFormat

    • "array"(默认推荐,v-model 为数组)或 "string"(逗号分隔字符串)
  3. 全选用 has-select-all

    • 设为 true 自动添加「全选」选项
  4. 值变化只通过 v-model

    • 组件仅声明 update:modelValue,没有独立 change 事件
  5. label 默认带冒号

    • showColon 默认 true,不需冒号传 :show-colon="false"
  6. 与单选组差异

    • jh-checkbox-group 多选,绑定值可为数组;jh-radio-group 单选
    • 多选组有 hasSelectAll/dataFormat,单选组有 defaultValue

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

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