2021-04-23 11:39:32 +08:00
|
|
|
---
|
2021-04-25 17:49:29 +08:00
|
|
|
title: Search Box 搜索框
|
2021-04-23 11:39:32 +08:00
|
|
|
description:
|
|
|
|
type: 0
|
|
|
|
group: ⚙ 组件
|
|
|
|
menuName: Search Box
|
|
|
|
icon:
|
|
|
|
---
|
|
|
|
|
|
|
|
## 基本用法
|
|
|
|
|
|
|
|
用于展示一个简单搜索框,通常需要搭配其他组件使用。比如 page 配置 `initApi` 后,可以用来实现简单数据过滤查找,`name` keywords 会作为参数传递给 page 的 `initApi`。
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type": "page",
|
2021-08-09 18:05:01 +08:00
|
|
|
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
|
2021-04-23 11:39:32 +08:00
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"type": "search-box",
|
|
|
|
"name": "keywords"
|
|
|
|
},
|
|
|
|
|
2022-05-18 10:03:56 +08:00
|
|
|
{
|
|
|
|
"type": "tpl",
|
|
|
|
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## 加强样式
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type": "page",
|
|
|
|
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"type": "search-box",
|
|
|
|
"name": "keywords",
|
|
|
|
"enhance": true
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"type": "tpl",
|
|
|
|
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## 可清除
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type": "page",
|
|
|
|
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"type": "search-box",
|
|
|
|
"name": "keywords",
|
|
|
|
"clearable": true
|
|
|
|
},
|
|
|
|
|
2021-04-23 11:39:32 +08:00
|
|
|
{
|
|
|
|
"type": "tpl",
|
|
|
|
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## mini 版本
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type": "page",
|
2021-08-09 18:05:01 +08:00
|
|
|
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
|
2021-04-23 11:39:32 +08:00
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"type": "search-box",
|
|
|
|
"name": "keywords",
|
|
|
|
"mini": true
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"type": "tpl",
|
|
|
|
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## 与 CRUD 搭配
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
{
|
|
|
|
"type": "crud",
|
2021-11-28 11:18:33 +08:00
|
|
|
"api": "/api/mock2/sample",
|
2021-04-23 11:39:32 +08:00
|
|
|
"syncLocation": false,
|
|
|
|
"headerToolbar": [
|
|
|
|
{
|
|
|
|
"type": "search-box",
|
|
|
|
"name": "keywords",
|
|
|
|
"align": "right",
|
|
|
|
"placeholder": "关键字检索"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"columns": [
|
|
|
|
{
|
|
|
|
"name": "id",
|
|
|
|
"label": "ID"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "engine",
|
|
|
|
"label": "Rendering engine"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "browser",
|
|
|
|
"label": "Browser"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "platform",
|
|
|
|
"label": "Platform(s)"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "version",
|
|
|
|
"label": "Engine version"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "grade",
|
|
|
|
"label": "CSS grade"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## 与 Service 搭配
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type": "page",
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"type": "service",
|
2021-08-09 18:05:01 +08:00
|
|
|
"api": "/api/mock2/page/initData?keywords=${keywords}",
|
2021-04-23 11:39:32 +08:00
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"type": "search-box",
|
|
|
|
"name": "keywords"
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"type": "tpl",
|
|
|
|
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## 属性表
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
| ---------------- | --------- | ------ | ---------------- |
|
|
|
|
| type | `string` | | `search-box` |
|
|
|
|
| className | `string` | | 外层 CSS 类名 |
|
|
|
|
| mini | `boolean` | | 是否为 mini 模式 |
|
|
|
|
| searchImediately | `boolean` | | 是否立即搜索 |
|