Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(statistic): [statistic] when precision is not set, the current value is displayed by default #2683

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/sites/demos/apis/statistic.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
props: [
{
name: 'value',
type: 'number',
type: 'number | string',
defaultValue: '0',
desc: {
'zh-CN': '数字显示内容',
Expand All @@ -20,7 +20,7 @@ export default {
{
name: 'precision',
type: 'number',
defaultValue: '0',
defaultValue: '',
desc: {
'zh-CN': '精度值',
'en-US': 'Take precision value'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<tiny-col :span="8">
<tiny-statistic :value="num" :precision="2"></tiny-statistic>
</tiny-col>
<tiny-col :span="8">
<tiny-statistic :value="num"></tiny-statistic>
</tiny-col>
</tiny-row>
</tiny-layout>
</div>
Expand Down
3 changes: 3 additions & 0 deletions examples/sites/demos/pc/app/statistic/basic-usage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<tiny-col :span="8">
<tiny-statistic :value="num" :precision="2"></tiny-statistic>
</tiny-col>
<tiny-col :span="8">
<tiny-statistic :value="num"></tiny-statistic>
</tiny-col>
</tiny-row>
</tiny-layout>
</div>
Expand Down
3 changes: 2 additions & 1 deletion examples/sites/demos/pc/app/statistic/statistic-slot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { test, expect } from '@playwright/test'
test('插槽用法', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('statistic#statistic-slot')
const desc = page.locator('.tiny-statistic__description')
await page
.locator('div')
.filter({ hasText: /^存储总量已使用容量\(GB\)10,010,258GB$/ })
.first()
await page.getByText('306,526存储平均值').click()
await expect(desc.first()).toHaveCSS('font-weight', '500')
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ test('样式用法', async ({ page }) => {
.locator('div')
.filter({ hasText: /^进行中306,526$/ })
.first()
await page.getByText('306,526失败').click()
await expect(page.getByText(/^进行中306,526$/).first()).toHaveClass(/tiny-statistic/)
})
11 changes: 8 additions & 3 deletions packages/renderless/src/statistic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ export const getIntegerAndDecimal =
if (!isNumber(props.value)) {
return props.value
}
let displayValue = props.value ? String(props.value).split('.') : ''
let displayValue = String(props.value).split('.')
let integer = displayValue[0]?.replace(/\B(?=(\d{3})+(?!\d))/g, props.groupSeparator)
let decimal = displayValue[1]?.padEnd(props.precision, '0').slice(0, props.precision > 0 ? props.precision : 0)
// 处理当数字为0的情况
let decimal = displayValue[1]?.padEnd(props.precision, '0')

// 当精度为0且大于0,进行精度截取
if (props.precision >= 0) {
decimal = decimal?.slice(0, props.precision > 0 ? props.precision : 0)
}
// 处理当没有显示值,数字默认为0
if (!displayValue) {
integer = '0'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/statistic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentiny/vue-statistic",
"version": "3.18.0",
"version": "3.18.1",
"description": "",
"main": "lib/index.js",
"module": "index.ts",
Expand Down
7 changes: 2 additions & 5 deletions packages/vue/src/statistic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ export const statisticProps = {
type: Object,
default: () => $constants
},
precision: {
type: Number,
default: 0
},
precision: Number,
formatter: Function,
value: {
type: Number,
type: [Number, String],
default: 0
},
prefix: String,
Expand Down
Loading