feat(Notify): add new prop top (#3018)

fix #2764
This commit is contained in:
rex 2020-04-14 21:17:41 +08:00 committed by GitHub
parent 16be4f7171
commit e054aafa2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 20 deletions

View File

@ -1,6 +1,7 @@
# Notify 消息提示 # Notify 消息提示
### 引入 ### 引入
`app.json``index.json`中引入组件,详细介绍见[快速上手](#/quickstart#yin-ru-zu-jian) `app.json``index.json`中引入组件,详细介绍见[快速上手](#/quickstart#yin-ru-zu-jian)
```json ```json
@ -79,22 +80,23 @@ Notify({
### 方法 ### 方法
| 方法名 | 说明 | 参数 | 返回值 | | 方法名 | 说明 | 参数 | 返回值 |
|------|------|------|------| | ------------ | -------- | ------------------- | ----------- |
| Notify | 展示提示 | `options | message` | notify 实例 | | Notify | 展示提示 | `options | message` | notify 实例 |
| Notify.clear | 关闭提示 | `options` | `void` | | Notify.clear | 关闭提示 | `options` | `void` |
### Options ### Options
| 参数 | 说明 | 类型 | 默认值 | 版本 | | 参数 | 说明 | 类型 | 默认值 | 版本 |
|-----------|-----------|-----------|-------------|-------------| | ---------------- | ------------------------------------------------------ | ---------- | ------------ | ----- |
| type | 类型,可选值为 `primary` `success` `warning` | *string* | `danger` | 1.0.0 | | type | 类型,可选值为 `primary` `success` `warning` | _string_ | `danger` | 1.0.0 |
| message | 展示文案,支持通过`\n`换行 | *string* | 1.0.0 | - | | message | 展示文案,支持通过`\n`换行 | _string_ | 1.0.0 | - |
| duration | 展示时长(ms),值为 0 时notify 不会消失 | *number* | `3000` | - | | duration | 展示时长(ms),值为 0 时notify 不会消失 | _number_ | `3000` | - |
| selector | 自定义节点选择器 | *string* | `van-notify` | - | | selector | 自定义节点选择器 | _string_ | `van-notify` | - |
| color | 字体颜色 | *string* | `#fff` | - | | color | 字体颜色 | _string_ | `#fff` | - |
| background | 背景颜色 | *string* | - | - | | top | 顶部距离 | _number_ | `0` | - |
| context | 选择器的选择范围,可以传入自定义组件的 this 作为上下文 | *object* | 当前页面 | - | | background | 背景颜色 | _string_ | - | - |
| onClick | 点击时的回调函数 | *Function* | - | - | | context | 选择器的选择范围,可以传入自定义组件的 this 作为上下文 | _object_ | 当前页面 | - |
| onOpened | 完全展示后的回调函数 | *Function* | - | - | | onClick | 点击时的回调函数 | _Function_ | - | - |
| onClose | 关闭时的回调函数 | *Function* | - | - | | onOpened | 完全展示后的回调函数 | _Function_ | - | - |
| safeAreaInsetTop | 是否留出顶部安全距离(状态栏高度) | *boolean* | `false` | - | | onClose | 关闭时的回调函数 | _Function_ | - | - |
| safeAreaInsetTop | 是否留出顶部安全距离(状态栏高度) | _boolean_ | `false` | - |

View File

@ -26,7 +26,8 @@ VantComponent({
safeAreaInsetTop: { safeAreaInsetTop: {
type: Boolean, type: Boolean,
value: false value: false
} },
top: null
}, },
data: { data: {

View File

@ -1,8 +1,10 @@
<wxs src="../wxs/utils.wxs" module="utils" />
<van-transition <van-transition
name="slide-down" name="slide-down"
show="{{ show }}" show="{{ show }}"
custom-class="van-notify__container" custom-class="van-notify__container"
custom-style="z-index: {{ zIndex }};" custom-style="z-index: {{ zIndex }}; top: {{ utils.addUnit(top) }}"
bind:tap="onTap" bind:tap="onTap"
> >
<view <view
@ -12,7 +14,7 @@
<view <view
wx:if="{{ safeAreaInsetTop }}" wx:if="{{ safeAreaInsetTop }}"
style="height: {{ statusBarHeight }}px" style="height: {{ statusBarHeight }}px"
></view> />
<text>{{ message }}</text> <text>{{ message }}</text>
</view> </view>
</van-transition> </van-transition>

View File

@ -4,6 +4,7 @@ interface NotifyOptions {
type?: 'primary' | 'success' | 'danger' | 'warning'; type?: 'primary' | 'success' | 'danger' | 'warning';
color?: string; color?: string;
zIndex?: number; zIndex?: number;
top?: number;
message: string; message: string;
context?: any; context?: any;
duration?: number; duration?: number;
@ -22,6 +23,7 @@ const defaultOptions = {
background: '', background: '',
duration: 3000, duration: 3000,
zIndex: 110, zIndex: 110,
top: 0,
color: WHITE, color: WHITE,
safeAreaInsetTop: false, safeAreaInsetTop: false,
onClick: () => {}, onClick: () => {},