Skip to content

Commit 4d20eff

Browse files
authored
fix(statistic): [statistic] when precision is not set, the current value is displayed by default (#2683)
* fix(statistic): [statistic] when precision is not set, the current value is displayed by default * fix(statistic): [statistic] review code * fix: modify e2e error
1 parent fcf3016 commit 4d20eff

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

examples/sites/demos/apis/statistic.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
props: [
88
{
99
name: 'value',
10-
type: 'number',
10+
type: 'number | string',
1111
defaultValue: '0',
1212
desc: {
1313
'zh-CN': '数字显示内容',
@@ -20,7 +20,7 @@ export default {
2020
{
2121
name: 'precision',
2222
type: 'number',
23-
defaultValue: '0',
23+
defaultValue: '',
2424
desc: {
2525
'zh-CN': '精度值',
2626
'en-US': 'Take precision value'

examples/sites/demos/pc/app/statistic/basic-usage-composition-api.vue

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<tiny-col :span="8">
99
<tiny-statistic :value="num" :precision="2"></tiny-statistic>
1010
</tiny-col>
11+
<tiny-col :span="8">
12+
<tiny-statistic :value="num"></tiny-statistic>
13+
</tiny-col>
1114
</tiny-row>
1215
</tiny-layout>
1316
</div>

examples/sites/demos/pc/app/statistic/basic-usage.vue

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<tiny-col :span="8">
99
<tiny-statistic :value="num" :precision="2"></tiny-statistic>
1010
</tiny-col>
11+
<tiny-col :span="8">
12+
<tiny-statistic :value="num"></tiny-statistic>
13+
</tiny-col>
1114
</tiny-row>
1215
</tiny-layout>
1316
</div>

examples/sites/demos/pc/app/statistic/statistic-slot.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { test, expect } from '@playwright/test'
33
test('插槽用法', async ({ page }) => {
44
page.on('pageerror', (exception) => expect(exception).toBeNull())
55
await page.goto('statistic#statistic-slot')
6+
const desc = page.locator('.tiny-statistic__description')
67
await page
78
.locator('div')
89
.filter({ hasText: /^使\(GB\)10,010,258GB$/ })
910
.first()
10-
await page.getByText('306,526存储平均值').click()
11+
await expect(desc.first()).toHaveCSS('font-weight', '500')
1112
})

examples/sites/demos/pc/app/statistic/statistic-style.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ test('样式用法', async ({ page }) => {
77
.locator('div')
88
.filter({ hasText: /^306,526$/ })
99
.first()
10-
await page.getByText('306,526失败').click()
1110
await expect(page.getByText(/^306,526$/).first()).toHaveClass(/tiny-statistic/)
1211
})

packages/renderless/src/statistic/index.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ export const getIntegerAndDecimal =
1515
if (!isNumber(props.value)) {
1616
return props.value
1717
}
18-
let displayValue = props.value ? String(props.value).split('.') : ''
18+
let displayValue = String(props.value).split('.')
1919
let integer = displayValue[0]?.replace(/\B(?=(\d{3})+(?!\d))/g, props.groupSeparator)
20-
let decimal = displayValue[1]?.padEnd(props.precision, '0').slice(0, props.precision > 0 ? props.precision : 0)
21-
// 处理当数字为0的情况
20+
let decimal = displayValue[1]?.padEnd(props.precision, '0')
21+
22+
// 当精度为0且大于0,进行精度截取
23+
if (props.precision >= 0) {
24+
decimal = decimal?.slice(0, props.precision > 0 ? props.precision : 0)
25+
}
26+
// 处理当没有显示值,数字默认为0
2227
if (!displayValue) {
2328
integer = '0'
2429
}

packages/vue/src/statistic/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentiny/vue-statistic",
3-
"version": "3.18.0",
3+
"version": "3.18.1",
44
"description": "",
55
"main": "lib/index.js",
66
"module": "index.ts",

packages/vue/src/statistic/src/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ export const statisticProps = {
1111
type: Object,
1212
default: () => $constants
1313
},
14-
precision: {
15-
type: Number,
16-
default: 0
17-
},
14+
precision: Number,
1815
formatter: Function,
1916
value: {
20-
type: Number,
17+
type: [Number, String],
2118
default: 0
2219
},
2320
prefix: String,

0 commit comments

Comments
 (0)