Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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