Skip to content

Commit

Permalink
fix 指标组件,数值为小数时,配置小数位数无效 review by qiwei
Browse files Browse the repository at this point in the history
chenxianhuii committed Dec 20, 2023
1 parent df500b6 commit cccceac
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common/indicator/Indicator.vue
Original file line number Diff line number Diff line change
@@ -178,7 +178,7 @@ export default {
return this.separator.replace(/\d+/, '');
},
calDecimals() {
if (this.decimals > 0) {
if (this.decimals >= 0) {
return this.decimals;
}
if (this.numData.toString().split('.')[1]) {
@@ -262,7 +262,7 @@ export default {
});
},
isNumber(str) {
return /^\d+$/.test(str);
return /^\d+(\.\d*)?$/.test(str);
},
timing() {
this.getData();
20 changes: 20 additions & 0 deletions src/common/indicator/__tests__/Indicator.spec.js
Original file line number Diff line number Diff line change
@@ -73,4 +73,24 @@ describe('Indicator.vue', () => {
expect(wrapper.vm.titleData).toBe('楼房建筑高度');
expect(wrapper.vm.unitData).toBe('千米');
});

it('Decimals', () => {
wrapper = mount(SmIndicator, {
propsData: {
title: '建筑高度',
unit: '米',
num: '1588.66',
decimals: 1
}
});
const numItem = wrapper.findAll('.sm-component-count-to__numItem');
expect(numItem.length).toBe(7);
expect(numItem.at(0).text()).toBe('1');
expect(numItem.at(1).text()).toBe(',');
expect(numItem.at(2).text()).toBe('5');
expect(numItem.at(3).text()).toBe('8');
expect(numItem.at(4).text()).toBe('8');
expect(numItem.at(5).text()).toBe('.');
expect(numItem.at(6).text()).toBe('7');
});
});

0 comments on commit cccceac

Please sign in to comment.