Yb-components Yb-components
首页
开发规范
yb-cli
  • 开发指南
  • 更新日志
  • 组件
关于
首页
开发规范
yb-cli
  • 开发指南
  • 更新日志
  • 组件
关于
  • 开发指南
  • 更新日志
  • 数据展示

    • YbTable 表格
    • YbCardList 卡片列表
    • YbTree 树
    • YbCascaderList 级联列表
    • YbSimpleTablePage 分页查询表格
    • YbSimpleCardPage 分页卡片列表
    • YbBasicProfile 基础详情数据展示
    • YbOutscrollLayout 固定在滚动区域外
    • YbOutscrollTree 固定在滚动区域外的Tree
    • YbInfoLayout 信息页布局
    • YbEditLayout 编辑页布局
  • 数据录入

    • YbRowsPopoverForm 浮层多行表单
    • YbFormily 配置式表单
    • YbForm 表单
    • YbRowsForm 多行表单
    • YbCollapseForm 折叠表单
    • YbQueryFilter 筛选表单
    • YbFilesSelect 文件选择器
    • YbRangeWrapper 范围结构
    • YbRangeDatepicker 日期范围
    • YbRange 范围
    • YbFormulaInput 简单运算公式输入
    • YbCron 表达式生成器
    • YbTreeSelect 树型选择器
    • YbInputgroupWrapper 复合组
      • YbThemeSelect 主题风格选择器
      • YbSelect 选择器
      • YbPaginationSelect 分页选择器
      • YbCodemirror 代码编辑器
      • YbCodemirrorSql SQL编辑器
      • YbCodemirrorJson JSON编辑器
      • YbCodemirrorXml XML编辑器
      • YbCombiDatepicker 组合时间
      • YbQuarterPicker 季度选择器
      • YbRangeQuarterPicker 季度范围选择器
      • YbConditionSelect 条件选择器
      • YbCheckboxGroup 多选框组
      • YbIconSelect 选择器
      • YbTagsInput 标签输入框
    • 其他组件

      • YbBallLoading 加载中
      • YbSymbolIcon 多色小图标
      • YbKeybuttonsPopover
      • YbPercentBattery 电池百分比
      • YbAffix 固钉
      • YbPagination 分页器
      • YbCollapse 折叠面板
      • YbScrollTool 滚动工具
    • 物料

      • YbMainSideMenu 侧栏菜单
      • YbLoadRemote 远程应用加载
      • YbLayoutPro 布局
      • YbMainPro 主页
      • YbAppMain 应用主页
      • YbAppLogin 普通登录页
      • YbAppPortal Portal登录页
    • 指令

      • v-fixed-in-scroller
    • Mixins

      • pageList_mixin
      • getScopedSlot_mixin
      • editFormPage_mixin
      • uploadProgressPage_mixin
      • rowActions_mixin
      • rowDeletes_mixin
      • drawerToRouterTab_mixin
    • 实验室

      • YbSwiper 轮播
    • 组件
    • 数据录入
    zougt
    2023-10-20

    YbInputgroupWrapper 复合组

    由于 el-input 复合型输入框模式只能支持中间是输入框, yb-inputgroup-wrapper 可以组合任意的组件在 prepend 和 append 位置

    # 基本使用

    px
    +0
    +0
    <template>
        <div style="width:500px">
            <yb-inputgroup-wrapper @appendClick="appendClick">
                <el-input-number
                    v-model="inputValue"
                    controls-position="right"
                    :min="0"
                >
                </el-input-number>
                <span slot="append">px</span>
            </yb-inputgroup-wrapper>
    
            <yb-inputgroup-wrapper>
                <span slot="prepend" class="el-icon-setting"></span>
                <el-input v-model="inputValue"> </el-input>
            </yb-inputgroup-wrapper>
            <yb-inputgroup-wrapper>
                <span slot="prepend" class="el-icon-star-on"></span>
                <el-input-number v-model="inputValue" :min="0"> </el-input-number>
                <span slot="append" class="el-icon-warning-outline"></span>
            </yb-inputgroup-wrapper>
            <yb-inputgroup-wrapper>
                <yb-tags-input slot="prepend" style="width:200px"/>
                <el-input-number v-model="inputValue" :min="0"> </el-input-number>
                <span slot="append" class="el-icon-warning-outline"></span>
            </yb-inputgroup-wrapper>
            <yb-inputgroup-wrapper>
                <span slot="prepend" class="el-icon-star-on"></span>
                <yb-tags-input />
                <span slot="append" class="el-icon-warning-outline"></span>
            </yb-inputgroup-wrapper>
        </div>
    </template>
    <script>
        export default {
            data() {
                return {
                    inputValue: 20,
                };
            },
            methods: {
                appendClick() {
                    console.log(9000);
                },
            },
        };
    </script>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    显示 复制 复制

    # 插槽使用

    prepend 插槽 定义在左边的内容,需要给定宽度
    默认 插槽 定义在中间的内容,宽度会自适应
    append 插槽 定义在右边的内容,需要给定宽度

    size="medium"
    • 北京
    • 上海
    • 南京
    • 成都
    • 深圳
    • 广州

    无数据

    size="small"
    • 指南
    • 组件
    • 资源
    size="mini"
    • 北京
    • 上海
    • 南京
    • 成都
    • 深圳
    • 广州

    无数据

    <template>
        <div style="width:500px">
            <div style="margin:10px 0;">size="medium"</div>
            <yb-inputgroup-wrapper size="medium">
                <!-- prepend 插槽 定义在左边的内容,需要给定宽度-->
                <el-input-number
                    style="width:160px"
                    slot="prepend"
                    :min="0"
                    v-model="numberValue"
                >
                </el-input-number>
                <!-- 默认 插槽 定义在中间的内容,宽度会自适应-->
                <el-select v-model="selectValue" clearable placeholder="请选择">
                    <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    >
                    </el-option>
                </el-select>
                <!-- append 插槽 定义在右边的内容,需要给定宽度-->
                <el-date-picker
                    slot="append"
                    style="width:200px"
                    v-model="dateValue"
                    type="date"
                    placeholder="选择日期"
                >
                </el-date-picker>
            </yb-inputgroup-wrapper>
            <div style="margin:10px 0;">size="small"</div>
            <yb-inputgroup-wrapper size="small">
                <el-date-picker
                    slot="prepend"
                    v-model="datetimeValue"
                    type="datetime"
                    placeholder="选择日期时间"
                    style="width:200px"
                >
                </el-date-picker>
    
                <el-cascader
                    v-model="cascaderValue"
                    :options="cascaderOptions"
                ></el-cascader>
            </yb-inputgroup-wrapper>
            <div style="margin:10px 0;">size="mini"</div>
            <yb-inputgroup-wrapper size="mini">
                <el-input-number
                    style="width:100px"
                    slot="prepend"
                    controls-position="right"
                    :min="0"
                    v-model="numberValue"
                >
                </el-input-number>
                <el-select v-model="selectValue" clearable placeholder="请选择">
                    <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    >
                    </el-option>
                </el-select>
                <el-input
                    style="width:200px"
                    slot="append"
                    placeholder="请输入内容"
                    v-model="inputValue"
                ></el-input>
            </yb-inputgroup-wrapper>
        </div>
    </template>
    <script>
        export default {
            data() {
                return {
                    datetimeValue: '',
                    numberValue: 3,
                    selectValue: 'Beijing',
                    inputValue: '录音员',
                    cascaderValue: '',
                    dateValue: '',
                    options: [
                        {
                            value: 'Beijing',
                            label: '北京',
                        },
                        {
                            value: 'Shanghai',
                            label: '上海',
                        },
                        {
                            value: 'Nanjing',
                            label: '南京',
                        },
                        {
                            value: 'Chengdu',
                            label: '成都',
                        },
                        {
                            value: 'Shenzhen',
                            label: '深圳',
                        },
                        {
                            value: 'Guangzhou',
                            label: '广州',
                        },
                    ],
                    cascaderOptions: [
                        {
                            value: 'zhinan',
                            label: '指南',
                            children: [
                                {
                                    value: 'shejiyuanze',
                                    label: '设计原则',
                                    children: [
                                        {
                                            value: 'yizhi',
                                            label: '一致',
                                        },
                                        {
                                            value: 'fankui',
                                            label: '反馈',
                                        },
                                        {
                                            value: 'xiaolv',
                                            label: '效率',
                                        },
                                        {
                                            value: 'kekong',
                                            label: '可控',
                                        },
                                    ],
                                },
                                {
                                    value: 'daohang',
                                    label: '导航',
                                    children: [
                                        {
                                            value: 'cexiangdaohang',
                                            label: '侧向导航',
                                        },
                                        {
                                            value: 'dingbudaohang',
                                            label: '顶部导航',
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            value: 'zujian',
                            label: '组件',
                            children: [
                                {
                                    value: 'basic',
                                    label: 'Basic',
                                    children: [
                                        {
                                            value: 'layout',
                                            label: 'Layout 布局',
                                        },
                                        {
                                            value: 'color',
                                            label: 'Color 色彩',
                                        },
                                        {
                                            value: 'typography',
                                            label: 'Typography 字体',
                                        },
                                        {
                                            value: 'icon',
                                            label: 'Icon 图标',
                                        },
                                        {
                                            value: 'button',
                                            label: 'Button 按钮',
                                        },
                                    ],
                                },
                                {
                                    value: 'form',
                                    label: 'Form',
                                    children: [
                                        {
                                            value: 'radio',
                                            label: 'Radio 单选框',
                                        },
                                        {
                                            value: 'checkbox',
                                            label: 'Checkbox 多选框',
                                        },
                                        {
                                            value: 'input',
                                            label: 'Input 输入框',
                                        },
                                        {
                                            value: 'input-number',
                                            label: 'InputNumber 计数器',
                                        },
                                        {
                                            value: 'select',
                                            label: 'Select 选择器',
                                        },
                                        {
                                            value: 'cascader',
                                            label: 'Cascader 级联选择器',
                                        },
                                        {
                                            value: 'switch',
                                            label: 'Switch 开关',
                                        },
                                        {
                                            value: 'slider',
                                            label: 'Slider 滑块',
                                        },
                                        {
                                            value: 'time-picker',
                                            label: 'TimePicker 时间选择器',
                                        },
                                        {
                                            value: 'date-picker',
                                            label: 'DatePicker 日期选择器',
                                        },
                                        {
                                            value: 'datetime-picker',
                                            label: 'DateTimePicker 日期时间选择器',
                                        },
                                        {
                                            value: 'upload',
                                            label: 'Upload 上传',
                                        },
                                        {
                                            value: 'rate',
                                            label: 'Rate 评分',
                                        },
                                        {
                                            value: 'form',
                                            label: 'Form 表单',
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            value: 'ziyuan',
                            label: '资源',
                            children: [
                                {
                                    value: 'axure',
                                    label: 'Axure Components',
                                },
                                {
                                    value: 'sketch',
                                    label: 'Sketch Templates',
                                },
                                {
                                    value: 'jiaohu',
                                    label: '组件交互文档',
                                },
                            ],
                        },
                    ],
                };
            },
        };
    </script>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    显示 复制 复制

    # 在表单中应用

    这里演示一个 formItem 放三个控件,绑定 formModel 的三个字段

    如果需要组合控件的绑定 formModel 的一个字段,以 object 作为值,可以自行包装成一个 v-model 的组件即可

    <template>
        <div>
            <yb-form
                ref="form"
                :formItems="formItems"
                :model="formModel"
                :spans="{span:24}"
                :label-width="labelWidth+'px'"
                @submit.native.prevent="onSubmit"
            >
                <template v-slot:field1="formItem">
                    <yb-inputgroup-wrapper size="small">
                        <el-input-number
                            style="width:100px"
                            slot="append"
                            controls-position="right"
                            :min="0"
                            v-model="formModel['field2']"
                        >
                        </el-input-number>
                        <el-select
                            v-model="formModel[formItem.prop]"
                            clearable
                            placeholder="请选择"
                            style="width:200px"
                            slot="prepend"
                        >
                            <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            >
                            </el-option>
                        </el-select>
                        <el-input
                            placeholder="请输入内容"
                            v-model="formModel['field3']"
                        ></el-input>
                    </yb-inputgroup-wrapper>
                </template>
                <template v-slot:buttons="formItem">
                    <el-button type="primary" native-type="submit"
                        >立即创建</el-button
                    >
                    <el-button>取消</el-button>
                </template>
            </yb-form>
        </div>
    </template>
    <script>
        export default {
            data() {
                const formItems = [
                    {
                        label: '组合控件',
                        prop: 'field1',
                        tooltip: '一个控件三个值',
                        rules: [
                            {
                                validator: (rule, value, callback) => {
                                    if (!this.formModel['field1']) {
                                        return callback('field1 不能为空');
                                    }
                                    if (!this.formModel['field2']) {
                                        return callback('field2 不能为空');
                                    }
                                    if (!this.formModel['field3']) {
                                        return callback('field3 不能为空');
                                    }
                                    callback();
                                },
                                trigger: 'change',
                            },
                        ],
                    },
                    {
                        label: '',
                        prop: 'field2',
                        rendered: false,
                    },
                    {
                        label: '',
                        prop: 'field3',
                        rendered: false,
                    },
                    {
                        label: '',
                        prop: 'buttons',
                    },
                ];
    
                const formModel = formItems.reduce((tol, item) => {
                    return {
                        ...tol,
                        [item.prop]:
                            typeof item.defaultValue !== 'undefined'
                                ? item.defaultValue
                                : null,
                    };
                }, {});
                return {
                    labelWidth: 100,
                    formItems,
                    formModel,
                    options: [
                        {
                            value: 'Beijing',
                            label: '北京',
                        },
                        {
                            value: 'Shanghai',
                            label: '上海',
                        },
                        {
                            value: 'Nanjing',
                            label: '南京',
                        },
                        {
                            value: 'Chengdu',
                            label: '成都',
                        },
                        {
                            value: 'Shenzhen',
                            label: '深圳',
                        },
                        {
                            value: 'Guangzhou',
                            label: '广州',
                        },
                    ],
                };
            },
            methods: {
                onSubmit() {
                    this.$refs['form']
                        .getForm()
                        .validate()
                        .then(() => {
                            console.log('验证成功', this.formModel);
                        })
                        .catch((err, errFields) => {
                            console.log('验证失败', err, errFields);
                        });
                },
            },
        };
    </script>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    显示 复制 复制

    # Props

    参数 说明 类型 可选值 默认值
    rightValue (旧 api)显示的后置内容,也可以用 append 插槽 string -- --
    size 控件大小,在表单中就可以不用设置了,由 formItem 传递 string medium / small / mini --

    # Slot

    name 说明
    prepend 前置内容
    default 自定义默认内容
    append 后置内容

    # Events

    事件名称 说明 参数
    prependClick 点击前置区域触发 e
    appendClick 点击后置区域触发 e
    上次更新: 2025/04/07, 10:08:49
    YbTreeSelect 树型选择器
    YbThemeSelect 主题风格选择器

    ← YbTreeSelect 树型选择器 YbThemeSelect 主题风格选择器→

    Theme by Vdoing | Copyright © 2021-2025 YB-GZ | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式