mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
feat: Service组件支持隐藏错误提示 (#6431)
This commit is contained in:
parent
8c13e7202b
commit
585c61df6b
@ -677,6 +677,45 @@ ws.on('connection', function connection(ws) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 隐藏错误信息
|
||||||
|
|
||||||
|
> 2.8.1 及以上版本
|
||||||
|
|
||||||
|
默认会将接口返回的错误信息展示在 Service 的顶部区域,可以通过设置`"showErrorMsg": false`隐藏错误提示。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "service",
|
||||||
|
"api": "/api/mock2/page/initDataError",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "展示错误信息"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "icon",
|
||||||
|
"icon": "fa-solid fa-arrow-up"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
设置`"showErrorMsg": false`隐藏错误提示,仅保留 toast 提示
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "service",
|
||||||
|
"api": "/api/mock2/page/initDataError",
|
||||||
|
"showErrorMsg": false,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "不展示错误信息"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 属性表
|
## 属性表
|
||||||
|
|
||||||
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
@ -696,6 +735,7 @@ ws.on('connection', function connection(ws) {
|
|||||||
| interval | `number` | | 轮询时间间隔,单位 ms(最低 1000) |
|
| interval | `number` | | 轮询时间间隔,单位 ms(最低 1000) |
|
||||||
| silentPolling | `boolean` | `false` | 配置轮询时是否显示加载动画 |
|
| silentPolling | `boolean` | `false` | 配置轮询时是否显示加载动画 |
|
||||||
| stopAutoRefreshWhen | [表达式](../../docs/concepts/expression) | | 配置停止轮询的条件 |
|
| stopAutoRefreshWhen | [表达式](../../docs/concepts/expression) | | 配置停止轮询的条件 |
|
||||||
|
| showErrorMsg | `boolean` | `true` | 是否以Alert的形式显示api接口响应的错误信息,默认展示 | `2.8.1` |
|
||||||
|
|
||||||
## 事件表
|
## 事件表
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import {
|
|||||||
isEffectiveApi,
|
isEffectiveApi,
|
||||||
str2AsyncFunction
|
str2AsyncFunction
|
||||||
} from 'amis-core';
|
} from 'amis-core';
|
||||||
import {Spinner, SpinnerExtraProps} from 'amis-ui';
|
import {Spinner, SpinnerExtraProps, Alert2 as Alert} from 'amis-ui';
|
||||||
import {
|
import {
|
||||||
autobind,
|
autobind,
|
||||||
isObject,
|
isObject,
|
||||||
@ -138,6 +138,11 @@ export interface ServiceSchema extends BaseSchema, SpinnerExtraProps {
|
|||||||
messages?: SchemaMessage;
|
messages?: SchemaMessage;
|
||||||
|
|
||||||
name?: SchemaName;
|
name?: SchemaName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否以Alert的形式显示api接口响应的错误信息,默认展示
|
||||||
|
*/
|
||||||
|
showErrorMsg?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServiceProps
|
export interface ServiceProps
|
||||||
@ -162,7 +167,8 @@ export default class Service extends React.Component<ServiceProps> {
|
|||||||
static defaultProps: Partial<ServiceProps> = {
|
static defaultProps: Partial<ServiceProps> = {
|
||||||
messages: {
|
messages: {
|
||||||
fetchFailed: 'fetchFailed'
|
fetchFailed: 'fetchFailed'
|
||||||
}
|
},
|
||||||
|
showErrorMsg: true
|
||||||
};
|
};
|
||||||
|
|
||||||
static propsList: Array<string> = [];
|
static propsList: Array<string> = [];
|
||||||
@ -736,22 +742,20 @@ export default class Service extends React.Component<ServiceProps> {
|
|||||||
render,
|
render,
|
||||||
classPrefix: ns,
|
classPrefix: ns,
|
||||||
classnames: cx,
|
classnames: cx,
|
||||||
loadingConfig
|
loadingConfig,
|
||||||
|
showErrorMsg
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cx(`${ns}Service`, className)} style={style}>
|
<div className={cx(`${ns}Service`, className)} style={style}>
|
||||||
{store.error ? (
|
{store.error && showErrorMsg !== false ? (
|
||||||
<div className={cx(`Alert Alert--danger`)}>
|
<Alert
|
||||||
<button
|
level="danger"
|
||||||
className={cx('Alert-close')}
|
showCloseButton
|
||||||
onClick={() => store.updateMessage('')}
|
onClose={() => store.updateMessage('')}
|
||||||
type="button"
|
>
|
||||||
>
|
|
||||||
<span>×</span>
|
|
||||||
</button>
|
|
||||||
{store.msg}
|
{store.msg}
|
||||||
</div>
|
</Alert>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{this.renderBody()}
|
{this.renderBody()}
|
||||||
|
Loading…
Reference in New Issue
Block a user