# 11. JInput 输入框
URL: /%E6%96%87%E6%A1%A3/04.%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/01.%20%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91/03.%20%E7%BB%84%E4%BB%B6%E5%BA%93%E6%96%87%E6%A1%A3/03.%20%E8%A1%A8%E5%8D%95%E7%BB%84%E4%BB%B6/13.%20JInput%20%E8%BE%93%E5%85%A5%E6%A1%86

JInput 输入框组件使用指南


# JInput 输入框组件

> [!info] 支持查询条件增强的输入框组件，可自动添加模糊匹配前缀后缀。

## 基本用法

```vue
<template>
  <JInput v-model:value="username" placeholder="请输入用户名" />
</template>

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

const username = ref('');
</script>
```

## Props 属性

| 属性 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| value | `string` | `''` | 输入框值 |
| type | `string` | `JINPUT_QUERY_LIKE` | 查询类型 |
| placeholder | `string` | `''` | 占位符 |
| trim | `boolean` | `false` | 是否自动去除首尾空格 |

## 查询类型

JInput 通过 `type` 属性支持多种查询条件模式：

| 类型值 | 说明 | 输入转换示例 |
|--------|------|-------------|
| `JINPUT_QUERY_LIKE` | 模糊查询（默认） | `abc` → `*abc*` |
| `JINPUT_QUERY_NE` | 不等于 | `abc` → `!abc` |
| `JINPUT_QUERY_GE` | 大于等于 | `100` → `>=100` |
| `JINPUT_QUERY_LE` | 小于等于 | `100` → `<=100` |

## 在 BasicForm 中使用

```vue
<script setup lang="ts">
import { useForm } from '@/components/Form';

const [registerForm, { getFieldsValue }] = useForm({
  schemas: [
    {
      field: 'username',
      label: '用户名',
      component: 'JInput',
      componentProps: {
        type: 'like', // 模糊查询
      },
    },
    {
      field: 'amount',
      label: '金额',
      component: 'JInput',
      componentProps: {
        type: 'ge', // 大于等于
      },
    },
  ],
});
</script>
```

## 搜索表单示例

```vue
<template>
  <BasicForm @register="registerForm" />
</template>

<script setup lang="ts">
import { useForm } from '@/components/Form';

const [registerForm, { getFieldsValue }] = useForm({
  schemas: [
    {
      field: 'name',
      label: '姓名',
      component: 'JInput',
      componentProps: {
        placeholder: '支持模糊搜索',
      },
    },
    {
      field: 'code',
      label: '编码',
      component: 'JInput',
      componentProps: {
        type: 'ne', // 不等于
        placeholder: '排除指定编码',
      },
    },
  ],
  labelWidth: 100,
  showActionButtonGroup: true,
});

// 搜索时会自动转换值：输入 "test" 后，实际查询值为 "*test*"
</script>
```

## 使用场景

### 1. 模糊搜索

```vue
<JInput v-model:value="name" type="like" placeholder="姓名模糊搜索" />
<!-- 输入：张三  →  输出：*张三* -->
```

### 2. 范围查询

```vue
<JInput v-model:value="minPrice" type="ge" placeholder="最低价格" />
<!-- 输入：100  →  输出：>=100 -->

<JInput v-model:value="maxPrice" type="le" placeholder="最高价格" />
<!-- 输入：1000  →  输出：<=1000 -->
```

### 3. 自动去除空格

```vue
<JInput v-model:value="keyword" :trim="true" placeholder="关键词" />
```

## 相关文件

- 组件路径：`@/components/Form/src/jeecg/components/JInput.vue`
- 枚举定义：`@/enums/jeecgEnum.ts`

## 相关组件

- [[09. BasicForm 表单]] - 表单容器组件
- [[08. BasicTable 表格]] - 表格组件
- [[12. JPopup 弹出选择]] - 弹出选择组件
