From 903d93a125aefb836842d0d2bd0c13d9e96c4bfa Mon Sep 17 00:00:00 2001 From: James-9696 Date: Thu, 19 Dec 2024 03:16:45 -0800 Subject: [PATCH 1/3] fix(statistic): [statistic] when precision is not set, the current value is displayed by default --- examples/sites/demos/apis/statistic.js | 4 ++-- .../pc/app/statistic/basic-usage-composition-api.vue | 3 +++ examples/sites/demos/pc/app/statistic/basic-usage.vue | 3 +++ packages/renderless/src/statistic/index.ts | 11 ++++++++--- packages/vue/src/statistic/package.json | 2 +- packages/vue/src/statistic/src/index.ts | 7 ++----- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/examples/sites/demos/apis/statistic.js b/examples/sites/demos/apis/statistic.js index 1a9a2dd449..33996e4bc2 100644 --- a/examples/sites/demos/apis/statistic.js +++ b/examples/sites/demos/apis/statistic.js @@ -7,7 +7,7 @@ export default { props: [ { name: 'value', - type: 'number', + type: 'number | string', defaultValue: '0', desc: { 'zh-CN': '数字显示内容', @@ -20,7 +20,7 @@ export default { { name: 'precision', type: 'number', - defaultValue: '0', + defaultValue: '', desc: { 'zh-CN': '精度值', 'en-US': 'Take precision value' diff --git a/examples/sites/demos/pc/app/statistic/basic-usage-composition-api.vue b/examples/sites/demos/pc/app/statistic/basic-usage-composition-api.vue index a9deedd168..6f6b252d7a 100644 --- a/examples/sites/demos/pc/app/statistic/basic-usage-composition-api.vue +++ b/examples/sites/demos/pc/app/statistic/basic-usage-composition-api.vue @@ -8,6 +8,9 @@ + + + diff --git a/examples/sites/demos/pc/app/statistic/basic-usage.vue b/examples/sites/demos/pc/app/statistic/basic-usage.vue index 7e8a97bfa7..488bfa886c 100644 --- a/examples/sites/demos/pc/app/statistic/basic-usage.vue +++ b/examples/sites/demos/pc/app/statistic/basic-usage.vue @@ -8,6 +8,9 @@ + + + diff --git a/packages/renderless/src/statistic/index.ts b/packages/renderless/src/statistic/index.ts index 9e44220151..8ff2ad8b3d 100644 --- a/packages/renderless/src/statistic/index.ts +++ b/packages/renderless/src/statistic/index.ts @@ -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' } diff --git a/packages/vue/src/statistic/package.json b/packages/vue/src/statistic/package.json index aeb89bb534..c7f685fef1 100644 --- a/packages/vue/src/statistic/package.json +++ b/packages/vue/src/statistic/package.json @@ -1,6 +1,6 @@ { "name": "@opentiny/vue-statistic", - "version": "3.18.0", + "version": "3.18.1", "description": "", "main": "lib/index.js", "module": "index.ts", diff --git a/packages/vue/src/statistic/src/index.ts b/packages/vue/src/statistic/src/index.ts index 4648208b36..85f5a060bd 100644 --- a/packages/vue/src/statistic/src/index.ts +++ b/packages/vue/src/statistic/src/index.ts @@ -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, From ccf9df81404ae4b8e59e657af76ee3d02f2a4d41 Mon Sep 17 00:00:00 2001 From: James-9696 Date: Thu, 19 Dec 2024 03:24:11 -0800 Subject: [PATCH 2/3] fix(statistic): [statistic] review code --- packages/vue/src/statistic/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vue/src/statistic/src/index.ts b/packages/vue/src/statistic/src/index.ts index 85f5a060bd..0dc71525b8 100644 --- a/packages/vue/src/statistic/src/index.ts +++ b/packages/vue/src/statistic/src/index.ts @@ -14,7 +14,7 @@ export const statisticProps = { precision: Number, formatter: Function, value: { - type: Number || String, + type: [Number, String], default: 0 }, prefix: String, From 6b245e8f301cb1adf653258343725c2470162a2f Mon Sep 17 00:00:00 2001 From: James-9696 Date: Thu, 19 Dec 2024 03:47:16 -0800 Subject: [PATCH 3/3] fix: modify e2e error --- examples/sites/demos/pc/app/statistic/statistic-slot.spec.ts | 3 ++- examples/sites/demos/pc/app/statistic/statistic-style.spec.ts | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/sites/demos/pc/app/statistic/statistic-slot.spec.ts b/examples/sites/demos/pc/app/statistic/statistic-slot.spec.ts index b86b41de21..f55a0625f6 100644 --- a/examples/sites/demos/pc/app/statistic/statistic-slot.spec.ts +++ b/examples/sites/demos/pc/app/statistic/statistic-slot.spec.ts @@ -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') }) diff --git a/examples/sites/demos/pc/app/statistic/statistic-style.spec.ts b/examples/sites/demos/pc/app/statistic/statistic-style.spec.ts index a1778c4088..1c7d2cc7ac 100644 --- a/examples/sites/demos/pc/app/statistic/statistic-style.spec.ts +++ b/examples/sites/demos/pc/app/statistic/statistic-style.spec.ts @@ -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/) })