diff --git a/example/pages/progress/index.wxml b/example/pages/progress/index.wxml
index 2c0bee20..d8433a4f 100644
--- a/example/pages/progress/index.wxml
+++ b/example/pages/progress/index.wxml
@@ -1,9 +1,9 @@
-
+
-
+
diff --git a/packages/progress/README.md b/packages/progress/README.md
index e79a74ac..ef357ecb 100644
--- a/packages/progress/README.md
+++ b/packages/progress/README.md
@@ -30,6 +30,8 @@
### 置灰
+设置`inactive`属性后进度条将置灰。
+
```html
```
@@ -55,17 +57,17 @@
### Props
-| 参数 | 说明 | 类型 | 默认值 | 版本 |
-| --- | --- | --- | --- | --- |
-| inactive | 是否置灰 | _boolean_ | `false` | - |
-| percentage | 进度百分比 | _number_ | `false` | - |
-| stroke-width | 进度条粗细,默认单位为`px` | _string \| number_ | `4px` | - |
-| show-pivot | 是否显示进度文字 | _boolean_ | `true` | - |
-| color | 进度条颜色 | _string_ | `#1989fa` | - |
-| text-color | 进度文字颜色 | _string_ | `#fff` | - |
-| track-color | 轨道颜色 | _string_ | `#e5e5e5` | 1.0.0 |
-| pivot-text | 文字显示 | _string_ | 百分比文字 | - |
-| pivot-color | 文字背景色 | _string_ | 与进度条颜色一致 | - |
+| 参数 | 说明 | 类型 | 默认值 |
+| --- | --- | --- | --- |
+| inactive | 是否置灰 | _boolean_ | `false` |
+| percentage | 进度百分比 | _number_ | `0` |
+| stroke-width | 进度条粗细,默认单位为`px` | _string \| number_ | `4px` |
+| show-pivot | 是否显示进度文字 | _boolean_ | `true` |
+| color | 进度条颜色 | _string_ | `#1989fa` |
+| text-color | 进度文字颜色 | _string_ | `#fff` |
+| track-color | 轨道颜色 | _string_ | `#e5e5e5` |
+| pivot-text | 文字显示 | _string_ | 百分比文字 |
+| pivot-color | 文字背景色 | _string_ | 与进度条颜色一致 |
### 外部样式类
diff --git a/packages/progress/index.less b/packages/progress/index.less
index b2370b96..9bec5dae 100644
--- a/packages/progress/index.less
+++ b/packages/progress/index.less
@@ -18,13 +18,12 @@
&__pivot {
position: absolute;
top: 50%;
- right: 0;
box-sizing: border-box;
- min-width: 2em;
+ min-width: 3.6em;
text-align: center;
word-break: keep-all;
border-radius: 1em;
- transform: translateY(-50%);
+ transform: translate(0, -50%);
.theme(color, '@progress-pivot-text-color');
.theme(padding, '@progress-pivot-padding');
.theme(font-size, '@progress-pivot-font-size');
diff --git a/packages/progress/index.ts b/packages/progress/index.ts
index 52fd87df..96d437e5 100644
--- a/packages/progress/index.ts
+++ b/packages/progress/index.ts
@@ -1,10 +1,14 @@
import { VantComponent } from '../common/component';
import { BLUE } from '../common/color';
+import { getRect } from '../common/utils';
VantComponent({
props: {
inactive: Boolean,
- percentage: Number,
+ percentage: {
+ type: Number,
+ observer: 'setLeft',
+ },
pivotText: String,
pivotColor: String,
trackColor: String,
@@ -25,4 +29,27 @@ VantComponent({
value: 4,
},
},
+
+ data: {
+ right: 0,
+ },
+
+ mounted() {
+ this.setLeft();
+ },
+
+ methods: {
+ setLeft() {
+ Promise.all([
+ getRect.call(this, '.van-progress'),
+ getRect.call(this, '.van-progress__pivot'),
+ ]).then(([portion, pivot]) => {
+ if (portion && pivot) {
+ this.setData({
+ right: (pivot.width * (this.data.percentage - 100)) / 100,
+ });
+ }
+ });
+ },
+ },
});
diff --git a/packages/progress/index.wxml b/packages/progress/index.wxml
index e5981f09..e81514d0 100644
--- a/packages/progress/index.wxml
+++ b/packages/progress/index.wxml
@@ -1,20 +1,20 @@
-
+
- {{ getters.text(pivotText, percentage) }}
+ {{ computed.pivotText(pivotText, percentage) }}
diff --git a/packages/progress/index.wxs b/packages/progress/index.wxs
index d6853452..5b1e8e6b 100644
--- a/packages/progress/index.wxs
+++ b/packages/progress/index.wxs
@@ -1,5 +1,36 @@
+/* eslint-disable */
+var utils = require('../wxs/utils.wxs');
+var style = require('../wxs/style.wxs');
+
+function pivotText(pivotText, percentage) {
+ return pivotText || percentage + '%';
+}
+
+function rootStyle(data) {
+ return style({
+ 'height': data.strokeWidth ? utils.addUnit(data.strokeWidth) : '',
+ 'background': data.trackColor,
+ });
+}
+
+function portionStyle(data) {
+ return style({
+ background: data.inactive ? '#cacaca' : data.color,
+ width: data.percentage ? data.percentage + '%' : '',
+ });
+}
+
+function pivotStyle(data) {
+ return style({
+ color: data.textColor,
+ right: data.right + 'px',
+ background: data.pivotColor ? data.pivotColor : data.inactive ? '#cacaca' : data.color,
+ });
+}
+
module.exports = {
- text: function(pivotText, percentage) {
- return pivotText || percentage + '%';
- }
+ pivotText: pivotText,
+ rootStyle: rootStyle,
+ portionStyle: portionStyle,
+ pivotStyle: pivotStyle,
};
diff --git a/packages/wxs/add-unit.wxs b/packages/wxs/add-unit.wxs
index 27a22d82..52f18b55 100644
--- a/packages/wxs/add-unit.wxs
+++ b/packages/wxs/add-unit.wxs
@@ -9,6 +9,4 @@ function addUnit(value) {
return REGEXP.test('' + value) ? value + 'px' : value;
}
-module.exports = {
- addUnit: addUnit
-};
+module.exports = addUnit;
diff --git a/packages/wxs/bem.wxs b/packages/wxs/bem.wxs
index 93b2777b..1efa129e 100644
--- a/packages/wxs/bem.wxs
+++ b/packages/wxs/bem.wxs
@@ -1,3 +1,4 @@
+/* eslint-disable */
var array = require('./array.wxs');
var object = require('./object.wxs');
var PREFIX = 'van-';
@@ -35,4 +36,4 @@ function bem(name, conf) {
return join(name, mods);
}
-module.exports.bem = bem;
+module.exports = bem;
diff --git a/packages/wxs/memoize.wxs b/packages/wxs/memoize.wxs
index 261ae67d..8f7f46dd 100644
--- a/packages/wxs/memoize.wxs
+++ b/packages/wxs/memoize.wxs
@@ -2,6 +2,7 @@
* Simple memoize
* wxs doesn't support fn.apply, so this memoize only support up to 2 args
*/
+/* eslint-disable */
function isPrimitive(value) {
var type = typeof value;
@@ -51,4 +52,4 @@ function memoize(fn) {
};
}
-module.exports.memoize = memoize;
+module.exports = memoize;
diff --git a/packages/wxs/style.wxs b/packages/wxs/style.wxs
new file mode 100644
index 00000000..aa565acc
--- /dev/null
+++ b/packages/wxs/style.wxs
@@ -0,0 +1,15 @@
+/* eslint-disable */
+var object = require('./object.wxs');
+
+function style(styles) {
+ return object.keys(styles)
+ .filter(function (key) {
+ return styles[key];
+ })
+ .map(function (key) {
+ return [key, [styles[key]]].join(':');
+ })
+ .join(';');
+}
+
+module.exports = style;
diff --git a/packages/wxs/utils.wxs b/packages/wxs/utils.wxs
index d5c9d8c2..f66d33a4 100644
--- a/packages/wxs/utils.wxs
+++ b/packages/wxs/utils.wxs
@@ -1,7 +1,7 @@
/* eslint-disable */
-var bem = require('./bem.wxs').bem;
-var memoize = require('./memoize.wxs').memoize;
-var addUnit = require('./add-unit.wxs').addUnit;
+var bem = require('./bem.wxs');
+var memoize = require('./memoize.wxs');
+var addUnit = require('./add-unit.wxs');
module.exports = {
bem: memoize(bem),