[Doc] Circle: update demo

This commit is contained in:
陈嘉涵 2019-07-06 11:42:49 +08:00
parent 8f0644e3ec
commit 22c1b14bc2
5 changed files with 27 additions and 18 deletions

View File

@ -64,7 +64,7 @@ export default {
| color | Progress bar color | `String` | `#1989fa` | | color | Progress bar color | `String` | `#1989fa` |
| layer-color | Layer color | `String` | `#fff` | | layer-color | Layer color | `String` | `#fff` |
| fill | Fill color | `String` | `none` | | fill | Fill color | `String` | `none` |
| speed | Animate speedrate/s| `Number` | - | | speed | Animate speedrate/s| `Number` | `0` |
| text | Text | `String` | - | | text | Text | `String` | - |
| stroke-width | Stroke width | `Number` | `40` | | stroke-width | Stroke width | `Number` | `40` |
| clockwise | Is clockwise | `Boolean` | `true` | | clockwise | Is clockwise | `Boolean` | `true` |

View File

@ -10,7 +10,8 @@ Vue.use(Circle);
## 代码演示 ## 代码演示
### 基础用法 ### 基础用法
通过 `rate` 指定目标进度,`v-model` 代表当前进度,`speed` 控制动画速度
`rate`属性表示进度条的目标进度,`v-model`表示动画过程中的实时进度。当`rate`发生变化时,`v-model`会以`speed`的速度变化,直至达到`rate`设定的值。
```html ```html
<van-circle <van-circle
@ -65,7 +66,7 @@ export default {
| color | 进度条颜色 | `String` | `#1989fa` | - | | color | 进度条颜色 | `String` | `#1989fa` | - |
| layer-color | 轨道颜色 | `String` | `#fff` | - | | layer-color | 轨道颜色 | `String` | `#fff` | - |
| fill | 填充颜色 | `String` | `none` | - | | fill | 填充颜色 | `String` | `none` | - |
| speed | 动画速度(单位为 rate/s| `Number` | - | - | | speed | 动画速度(单位为 rate/s| `Number` | `0` | - |
| text | 文字 | `String` | - | - | | text | 文字 | `String` | - | - |
| stroke-width | 进度条宽度 | `Number` | `40` | - | | stroke-width | 进度条宽度 | `Number` | `40` | - |
| clockwise | 是否顺时针增加 | `Boolean` | `true` | - | | clockwise | 是否顺时针增加 | `Boolean` | `true` | - |

View File

@ -8,18 +8,6 @@
size="120px" size="120px"
:text="currentRate1.toFixed(0) + '%'" :text="currentRate1.toFixed(0) + '%'"
/> />
<van-circle
v-model="currentRate2"
color="#07c160"
fill="#fff"
:rate="rate"
size="120px"
layer-color="#ebedf0"
:speed="100"
:stroke-width="60"
:clockwise="false"
:text="currentRate2.toFixed(0) + '%'"
/>
<div> <div>
<van-button <van-button
:text="$t('add')" :text="$t('add')"
@ -35,6 +23,21 @@
/> />
</div> </div>
</demo-block> </demo-block>
<demo-block :title="$t('customStyle')">
<van-circle
v-model="currentRate2"
color="#07c160"
fill="#fff"
:rate="rate"
size="120px"
layer-color="#ebedf0"
:speed="100"
:stroke-width="60"
:clockwise="false"
:text="currentRate2.toFixed(0) + '%'"
/>
</demo-block>
</demo-section> </demo-section>
</template> </template>
@ -44,10 +47,10 @@ const format = rate => Math.min(Math.max(rate, 0), 100);
export default { export default {
i18n: { i18n: {
'zh-CN': { 'zh-CN': {
title2: '样式定制' customStyle: '样式定制'
}, },
'en-US': { 'en-US': {
title2: 'Custom Style' customStyle: 'Custom Style'
} }
}, },

View File

@ -56,6 +56,7 @@ export default createComponent({
layerStyle() { layerStyle() {
let offset = (PERIMETER * (100 - this.value)) / 100; let offset = (PERIMETER * (100 - this.value)) / 100;
offset = this.clockwise ? offset : PERIMETER * 2 - offset; offset = this.clockwise ? offset : PERIMETER * 2 - offset;
return { return {
stroke: `${this.color}`, stroke: `${this.color}`,
strokeDashoffset: `${offset}px`, strokeDashoffset: `${offset}px`,
@ -80,6 +81,7 @@ export default createComponent({
this.endRate = format(this.rate); this.endRate = format(this.rate);
this.increase = this.endRate > this.startRate; this.increase = this.endRate > this.startRate;
this.duration = Math.abs(((this.startRate - this.endRate) * 1000) / this.speed); this.duration = Math.abs(((this.startRate - this.endRate) * 1000) / this.speed);
if (this.speed) { if (this.speed) {
cancelRaf(this.rafId); cancelRaf(this.rafId);
this.rafId = raf(this.animate); this.rafId = raf(this.animate);
@ -97,6 +99,7 @@ export default createComponent({
const progress = Math.min((now - this.startTime) / this.duration, 1); const progress = Math.min((now - this.startTime) / this.duration, 1);
const rate = progress * (this.endRate - this.startRate) + this.startRate; const rate = progress * (this.endRate - this.startRate) + this.startRate;
this.$emit('input', format(parseFloat(rate.toFixed(1)))); this.$emit('input', format(parseFloat(rate.toFixed(1))));
if (this.increase ? rate < this.endRate : rate > this.endRate) { if (this.increase ? rate < this.endRate : rate > this.endRate) {
this.rafId = raf(this.animate); this.rafId = raf(this.animate);
} }

View File

@ -9,13 +9,15 @@ exports[`renders demo correctly 1`] = `
</svg> </svg>
<div class="van-circle__text">30%</div> <div class="van-circle__text">30%</div>
</div> </div>
<div><button class="van-button van-button--primary van-button--small"><span class="van-button__text">增加</span></button> <button class="van-button van-button--danger van-button--small"><span class="van-button__text">减少</span></button></div>
</div>
<div>
<div class="van-circle" style="width: 120px; height: 120px;"><svg viewBox="0 0 1060 1060"> <div class="van-circle" style="width: 120px; height: 120px;"><svg viewBox="0 0 1060 1060">
<path d="M 530 530 m -500, 0 a 500, 500 0 1, 1 1000, 0 a 500, 500 0 1, 1 -1000, 0" class="van-circle__hover" style="fill: #fff; stroke: #ebedf0; stroke-width: 60px;"></path> <path d="M 530 530 m -500, 0 a 500, 500 0 1, 1 1000, 0 a 500, 500 0 1, 1 -1000, 0" class="van-circle__hover" style="fill: #fff; stroke: #ebedf0; stroke-width: 60px;"></path>
<path d="M 530 530 m -500, 0 a 500, 500 0 1, 1 1000, 0 a 500, 500 0 1, 1 -1000, 0" class="van-circle__layer" style="stroke: #07c160; stroke-dashoffset: 4082px; stroke-width: 61px;"></path> <path d="M 530 530 m -500, 0 a 500, 500 0 1, 1 1000, 0 a 500, 500 0 1, 1 -1000, 0" class="van-circle__layer" style="stroke: #07c160; stroke-dashoffset: 4082px; stroke-width: 61px;"></path>
</svg> </svg>
<div class="van-circle__text">30%</div> <div class="van-circle__text">30%</div>
</div> </div>
<div><button class="van-button van-button--primary van-button--small"><span class="van-button__text">增加</span></button> <button class="van-button van-button--danger van-button--small"><span class="van-button__text">减少</span></button></div>
</div> </div>
</div> </div>
`; `;