diff --git a/example/pages/notice-bar/index.js b/example/pages/notice-bar/index.js index 65bf5936..be0e7e7f 100644 --- a/example/pages/notice-bar/index.js +++ b/example/pages/notice-bar/index.js @@ -1,28 +1,5 @@ Page({ data: { - bar1: { - text: '足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。', - scrollable: true, - delay: 1000 - }, - bar2: { - text: '足协杯战线连续第2年上演广州德比战', - color: '#fff', - backgroundColor: '#000' - }, - bar3: { - text: '足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。' - }, - bar4: { - text: '带icon的公告', - leftIcon: 'https://img.yzcdn.cn/public_files/2017/8/10/6af5b7168eed548100d9041f07b7c616.png' - }, - bar5: { - text: '足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。', - leftIcon: 'https://img.yzcdn.cn/public_files/2017/8/10/6af5b7168eed548100d9041f07b7c616.png', - mode: 'closeable', - scrollable: true, - speed: 10 - } + text: '足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。' } }); diff --git a/example/pages/notice-bar/index.json b/example/pages/notice-bar/index.json index d4c7e5b2..26286ca5 100644 --- a/example/pages/notice-bar/index.json +++ b/example/pages/notice-bar/index.json @@ -1,7 +1,7 @@ { "navigationBarTitleText": "NoticeBar 通告栏", "usingComponents": { - "van-notice-bar": "../../dist/notice-bar/index", - "van-panel": "../../dist/panel/index" + "demo-block": "../../components/demo-block/index", + "van-notice-bar": "../../dist/notice-bar/index" } } diff --git a/example/pages/notice-bar/index.wxml b/example/pages/notice-bar/index.wxml index 90f212ed..95c8febc 100644 --- a/example/pages/notice-bar/index.wxml +++ b/example/pages/notice-bar/index.wxml @@ -1,51 +1,15 @@ - - + - + - - - + + + - - - - - - - - - - - - - - - - - - - + + + + diff --git a/packages/notice-bar/README.md b/packages/notice-bar/README.md index 3f366ac0..20f0bcc5 100644 --- a/packages/notice-bar/README.md +++ b/packages/notice-bar/README.md @@ -1,95 +1,75 @@ ## NoticeBar 通告栏 ### 使用指南 + 在 index.json 中引入组件 ```json -{ - "usingComponents": { - "van-notice-bar": "path/to/vant-weapp/dist/notice-bar/index" - } +"usingComponents": { + "van-notice-bar": "path/to/vant-weapp/dist/notice-bar/index" } ``` -在 index.js 中声明组件数据 -```js -// 在 Page 中声明 NoticeBar 依赖的展示数据 -Page({ - data: { - text: 'xxx', - scrollable: 'xxx', - ... - } -}) -``` ### 代码演示 -`NoticeBar` 组件支持滚动和静止两种展示方式,通过 text 传入展示文案 -### 静止公告栏 +#### 基础用法 + ```html ``` -### 滚动通告栏 +#### 禁用滚动 +文字内容多于一行时,可通过`scrollable`参数控制是否开启滚动 + ```html ``` -### 延时滚动通告栏 -```html - -``` +#### 通告栏模式 +默认模式为空,支持`closeable`和`link`。 -### 改变滚动通告栏滚动速度 ```html + -``` - -### 自定义通告栏字体颜色和背景色 -```html - -``` - -### 添加左侧icon通告栏 -```html - -``` - -### 可关闭通告栏 -```html - + + + ``` -| 参数 | 说明 | 类型 | 默认值 | 可选值 | -|-----------|-----------|-----------|-------------|-------------| -| text | 通告栏展示文案 | String | - | | -| mode | 通告栏模式 | String | '' | `closeable` | -| delay | 滚动延时时间 | Number | 0 | | -| speed | 滚动速度 | Number | 40 | | -| scrollable | 是否可滚动 | Boolean | false | | -| leftIcon | 左侧图标 | String | - | | -| color | 通告栏字体颜色 | String | `#f60` | | -| backgroundColor | 通告栏背景色 | String | `#fff7cc` | +### API + +| 参数 | 说明 | 类型 | 默认值 | +|-----------|-----------|-----------|-------------| +| mode | 通告栏模式,可选值为 `closeable` `link` | `String` | `''` | +| delay | 动画延迟时间 (s) | `Number` | `1` | +| speed | 滚动速率 (px/s) | `Number` | `50` | +| scrollable | 是否在长度溢出时滚动播放 | `Boolean` | `true` | +| left-icon | 左侧图标图片 URL | `String` | - | +| color | 文本颜色 | `String` | `#f60` | +| background | 滚动条背景 | `String` | `#fff7cc` | +| open-type | 微信开放能力 | `String` | `navigate` | + +### Event + +| 事件名 | 说明 | 参数 | +|-----------|-----------|-----------| +| tap | 点击事件回调 | - | + + +### 外部样式类 + +| 类名 | 说明 | +|-----------|-----------| +| custom-class | 根节点样式类 | diff --git a/packages/notice-bar/index.js b/packages/notice-bar/index.js index 667b4db8..56b71673 100644 --- a/packages/notice-bar/index.js +++ b/packages/notice-bar/index.js @@ -1,8 +1,10 @@ -const VALID_MODE = ['closeable']; +const VALID_MODE = ['closeable', 'link']; const FONT_COLOR = '#f60'; const BG_COLOR = '#fff7cc'; Component({ + externalClasses: ['custom-class'], + properties: { text: { type: String, @@ -29,11 +31,11 @@ Component({ }, speed: { type: Number, - value: 40 + value: 50 }, scrollable: { type: Boolean, - value: false + value: true }, leftIcon: { type: String, @@ -166,6 +168,10 @@ Component({ show: false, timer: null }); + }, + + onTap(event) { + this.triggerEvent('tap', event); } } }); diff --git a/packages/notice-bar/index.wxml b/packages/notice-bar/index.wxml index 6ebc9be8..2f34abc1 100644 --- a/packages/notice-bar/index.wxml +++ b/packages/notice-bar/index.wxml @@ -1,7 +1,8 @@ @@ -24,7 +25,7 @@ url="{{ url }}" open-type="{{ openType }}" > - +