From 0643528f15f0e335222d8c45ec662543e4783cc2 Mon Sep 17 00:00:00 2001 From: Huanyue <1582884964@qq.com> Date: Mon, 14 Feb 2022 18:49:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dcircle=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E8=BF=9B=E5=BA=A6=E6=9D=A1=E8=BF=9B=E5=BA=A6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/progress/progress.tsx | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/progress/progress.tsx b/src/progress/progress.tsx index 7698ce1aa..8fabcd1eb 100644 --- a/src/progress/progress.tsx +++ b/src/progress/progress.tsx @@ -64,6 +64,7 @@ export default Vue.extend({ background: this.color && getBackgroundColor(this.color), }; }, + // 进度条的颜色 circlePathStyle(): Styles { const strokeColor = typeof this.color === 'object' ? '' : this.color; return { @@ -125,12 +126,37 @@ export default Vue.extend({ const defaultWidth = this.size === CIRCLE_SIZE.SMALL ? 4 : 6; return this.strokeWidth ? Number(this.strokeWidth) : defaultWidth; }, - strokeDashArr(): string { + + /** + * theme=circle 计算环形的周长 + */ + circleStrokePerimeter(): number { const radius = this.diameter / 2; const perimeter = Math.PI * 2 * (radius - this.circleStrokeWidth); + return perimeter; + }, + + /** + * theme=circle 计算环形进度条的长度 + */ + getPercentLength(): string { const percent = this.percentage / 100; - return `${perimeter * percent} ${perimeter * (1 - percent)}`; + return `${this.circleStrokePerimeter * percent}`; }, + /** + * theme=circle 环形进度条展示百分比 + */ + strokeDashArr(): string { + return `${this.getPercentLength} ${this.circleStrokePerimeter - Number(this.getPercentLength)}`; + }, + + /** + * theme=circle 进度条偏移 + */ + strokeDashOff(): string { + return `${this.getPercentLength}`; + }, + plumpStyles(): Styles { return {}; // return this.percentage > 10 ? { color: '#fff' } : { right: '-2.5rem' }; @@ -181,6 +207,7 @@ export default Vue.extend({ )} + {/* 进度条内展示百分比 */} {this.theme === PRO_THEME.PLUMP && (
)} + {/* 环形进度条部分 */} {this.theme === PRO_THEME.CIRCLE && (
{labelContent} @@ -220,6 +248,7 @@ export default Vue.extend({ class={`${name}__circle-inner`} transform={`matrix(0,-1,1,0,0,${this.diameter})`} stroke-dasharray={this.strokeDashArr} + stroke-dashoffset={this.strokeDashOff} style={this.circlePathStyle} /> From 8e4d5b4e844078180c8712ed2beae267c5dab5cb Mon Sep 17 00:00:00 2001 From: Uyarn Date: Thu, 17 Feb 2022 14:01:14 +0800 Subject: [PATCH 2/2] fix(progress): circle render incorrect when less than 5% --- src/progress/progress.tsx | 61 ++++++------------- test/ssr/__snapshots__/ssr.test.js.snap | 44 ++++++------- .../progress/__snapshots__/demo.test.js.snap | 44 ++++++------- .../progress/__snapshots__/index.test.js.snap | 5 +- test/unit/progress/index.test.js | 2 +- 5 files changed, 64 insertions(+), 92 deletions(-) diff --git a/src/progress/progress.tsx b/src/progress/progress.tsx index 8fabcd1eb..9faa486cf 100644 --- a/src/progress/progress.tsx +++ b/src/progress/progress.tsx @@ -64,7 +64,6 @@ export default Vue.extend({ background: this.color && getBackgroundColor(this.color), }; }, - // 进度条的颜色 circlePathStyle(): Styles { const strokeColor = typeof this.color === 'object' ? '' : this.color; return { @@ -126,37 +125,12 @@ export default Vue.extend({ const defaultWidth = this.size === CIRCLE_SIZE.SMALL ? 4 : 6; return this.strokeWidth ? Number(this.strokeWidth) : defaultWidth; }, - - /** - * theme=circle 计算环形的周长 - */ - circleStrokePerimeter(): number { + strokeDashArr(): string { const radius = this.diameter / 2; - const perimeter = Math.PI * 2 * (radius - this.circleStrokeWidth); - return perimeter; - }, - - /** - * theme=circle 计算环形进度条的长度 - */ - getPercentLength(): string { + const perimeter = Math.PI * 2 * radius; const percent = this.percentage / 100; - return `${this.circleStrokePerimeter * percent}`; - }, - /** - * theme=circle 环形进度条展示百分比 - */ - strokeDashArr(): string { - return `${this.getPercentLength} ${this.circleStrokePerimeter - Number(this.getPercentLength)}`; - }, - - /** - * theme=circle 进度条偏移 - */ - strokeDashOff(): string { - return `${this.getPercentLength}`; + return `${perimeter * percent} ${perimeter * (1 - percent)}`; }, - plumpStyles(): Styles { return {}; // return this.percentage > 10 ? { color: '#fff' } : { right: '-2.5rem' }; @@ -207,7 +181,6 @@ export default Vue.extend({
)} - {/* 进度条内展示百分比 */} {this.theme === PRO_THEME.PLUMP && (
)} - {/* 环形进度条部分 */} {this.theme === PRO_THEME.CIRCLE && (
{labelContent} @@ -238,19 +210,20 @@ export default Vue.extend({ class={`${name}__circle-outer`} style={this.circleStrokeStyle} /> - + {this.percentage > 0 && ( + + )}
)} diff --git a/test/ssr/__snapshots__/ssr.test.js.snap b/test/ssr/__snapshots__/ssr.test.js.snap index 8417100ec..faa494f9b 100644 --- a/test/ssr/__snapshots__/ssr.test.js.snap +++ b/test/ssr/__snapshots__/ssr.test.js.snap @@ -7965,7 +7965,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl
30%
- +
@@ -7976,7 +7976,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl
- +
@@ -7987,7 +7987,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl
75day
- +
@@ -8002,7 +8002,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl - + @@ -8015,7 +8015,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl - + @@ -8028,7 +8028,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl - + @@ -8042,7 +8042,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl
30%
- +
@@ -8053,7 +8053,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl
30%
- +
@@ -8064,7 +8064,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/circle.vue correctl
75%
- +
@@ -8081,7 +8081,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/custom.vue correctl
- +
@@ -8109,7 +8109,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/custom.vue correctl
30%
- +
@@ -8127,7 +8127,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/custom.vue correctl
44%
- +
@@ -8146,7 +8146,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/custom.vue correctl
<div>45days</div>
- +
@@ -8315,7 +8315,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/size.vue correctly
30%
- +
@@ -8327,7 +8327,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/size.vue correctly - + @@ -8339,7 +8339,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/size.vue correctly - + @@ -8351,7 +8351,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/size.vue correctly - + @@ -8364,7 +8364,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/size.vue correctly
30%
- +
@@ -8373,7 +8373,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/size.vue correctly
75%
- +
@@ -8408,7 +8408,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/status.vue correctl - + @@ -8438,7 +8438,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/status.vue correctl - + @@ -8478,7 +8478,7 @@ exports[`ssr snapshot test renders ./examples/progress/demos/status.vue correctl - + diff --git a/test/unit/progress/__snapshots__/demo.test.js.snap b/test/unit/progress/__snapshots__/demo.test.js.snap index 41e54f170..2be5a9189 100644 --- a/test/unit/progress/__snapshots__/demo.test.js.snap +++ b/test/unit/progress/__snapshots__/demo.test.js.snap @@ -50,7 +50,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="94.2477796076938 219.9114857512855" + stroke-dasharray="105.55751316061705 246.30086404143975" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -99,7 +99,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="314.1592653589793 0" + stroke-dasharray="351.85837720205683 0" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -150,7 +150,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="157.07963267948966 157.07963267948966" + stroke-dasharray="175.92918860102841 175.92918860102841" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -217,7 +217,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="314.1592653589793 0" + stroke-dasharray="351.85837720205683 0" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -280,7 +280,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="235.61944901923448 78.53981633974483" + stroke-dasharray="263.89378290154264 87.96459430051421" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -343,7 +343,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="157.07963267948966 157.07963267948966" + stroke-dasharray="175.92918860102841 175.92918860102841" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -402,7 +402,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="36" fill="none" r="34" - stroke-dasharray="60.31857894892403 140.74335088082273" + stroke-dasharray="67.85840131753953 158.33626974092556" stroke-linecap="round" stroke-width="4" transform="matrix(0,-1,1,0,0,72)" @@ -453,7 +453,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="94.2477796076938 219.9114857512855" + stroke-dasharray="105.55751316061705 246.30086404143975" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -505,7 +505,7 @@ exports[`Progress circle demo works fine 1`] = ` cy="80" fill="none" r="77" - stroke-dasharray="348.71678454846705 116.23892818282235" + stroke-dasharray="376.99111843077515 125.66370614359172" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,160)" @@ -555,7 +555,7 @@ exports[`Progress custom demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="263.89378290154264 50.265482457436704" + stroke-dasharray="295.5610368497277 56.2973403523291" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -652,7 +652,7 @@ exports[`Progress custom demo works fine 1`] = ` cy="100" fill="none" r="90" - stroke-dasharray="150.79644737231007 351.85837720205683" + stroke-dasharray="188.4955592153876 439.822971502571" stroke-linecap="round" stroke-width="20" transform="matrix(0,-1,1,0,0,200)" @@ -722,7 +722,7 @@ exports[`Progress custom demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="138.2300767579509 175.92918860102844" + stroke-dasharray="154.817685968905 197.04069123315185" stroke-linecap="round" stroke-width="6" style="stroke: #52CC8D;" @@ -795,7 +795,7 @@ exports[`Progress custom demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="138.2300767579509 175.92918860102844" + stroke-dasharray="154.817685968905 197.04069123315185" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -1319,7 +1319,7 @@ exports[`Progress size demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="94.2477796076938 219.9114857512855" + stroke-dasharray="105.55751316061705 246.30086404143975" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -1376,7 +1376,7 @@ exports[`Progress size demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="235.61944901923448 78.53981633974483" + stroke-dasharray="263.89378290154264 87.96459430051421" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -1433,7 +1433,7 @@ exports[`Progress size demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="157.07963267948966 157.07963267948966" + stroke-dasharray="175.92918860102841 175.92918860102841" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -1490,7 +1490,7 @@ exports[`Progress size demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="314.1592653589793 0" + stroke-dasharray="351.85837720205683 0" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -1544,7 +1544,7 @@ exports[`Progress size demo works fine 1`] = ` cy="36" fill="none" r="34" - stroke-dasharray="60.31857894892403 140.74335088082273" + stroke-dasharray="67.85840131753953 158.33626974092556" stroke-linecap="round" stroke-width="4" transform="matrix(0,-1,1,0,0,72)" @@ -1589,7 +1589,7 @@ exports[`Progress size demo works fine 1`] = ` cy="80" fill="none" r="77" - stroke-dasharray="348.71678454846705 116.23892818282235" + stroke-dasharray="376.99111843077515 125.66370614359172" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,160)" @@ -1707,7 +1707,7 @@ exports[`Progress status demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="251.32741228718348 62.83185307179585" + stroke-dasharray="281.48670176164546 70.37167544041135" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -1821,7 +1821,7 @@ exports[`Progress status demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="251.32741228718348 62.83185307179585" + stroke-dasharray="281.48670176164546 70.37167544041135" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" @@ -1970,7 +1970,7 @@ exports[`Progress status demo works fine 1`] = ` cy="56" fill="none" r="53" - stroke-dasharray="251.32741228718348 62.83185307179585" + stroke-dasharray="281.48670176164546 70.37167544041135" stroke-linecap="round" stroke-width="6" transform="matrix(0,-1,1,0,0,112)" diff --git a/test/unit/progress/__snapshots__/index.test.js.snap b/test/unit/progress/__snapshots__/index.test.js.snap index 0cac04dff..11a1640cf 100644 --- a/test/unit/progress/__snapshots__/index.test.js.snap +++ b/test/unit/progress/__snapshots__/index.test.js.snap @@ -229,9 +229,9 @@ exports[`Progress :props :strokeWidth :strokeWidth is String, equal to "50px" 1` exports[`Progress :props :theme :theme circle progress has t-progress__circle-outer and t-progress__circle-inner class 1`] = `
-
0%
+
10%
- +
@@ -262,7 +262,6 @@ exports[`Progress :props :theme :theme:circle 1`] = `
0%
-
diff --git a/test/unit/progress/index.test.js b/test/unit/progress/index.test.js index c85c6de89..ca6125039 100644 --- a/test/unit/progress/index.test.js +++ b/test/unit/progress/index.test.js @@ -49,7 +49,7 @@ describe('Progress', () => { it(':theme circle progress has t-progress__circle-outer and t-progress__circle-inner class', () => { const wrapper = mount({ render() { - return ; + return ; }, }); const outerClass = wrapper.element.querySelector('.t-progress__circle-outer');