diff --git a/packages/devui-vue/devui/statistic/src/statistic-types.ts b/packages/devui-vue/devui/statistic/src/statistic-types.ts index b70d8d5dc4..d183ec80ca 100644 --- a/packages/devui-vue/devui/statistic/src/statistic-types.ts +++ b/packages/devui-vue/devui/statistic/src/statistic-types.ts @@ -1,5 +1,5 @@ import type { PropType, ExtractPropTypes, CSSProperties } from 'vue' -import type { easingType } from './utils/animation' +// import type { easingType } from './utils/animation' export const statisticProps = { title: { type: String, @@ -21,14 +21,7 @@ export const statisticProps = { type: String, default: '' }, - showGroupSeparator: { - type: Boolean, - default: true - }, - titleStyle: { - type: Object as PropType - }, - contentStyle: { + valueStyle: { type: Object as PropType }, animationDuration: { @@ -44,19 +37,11 @@ export const statisticProps = { }, start: { type: Boolean, - default: false + default: true }, extra: { type: String, default: '' - }, - easing: { - type: String as PropType, - default: 'easeOutCubic' - }, - delay: { - type: Number, - default: 0 } } as const diff --git a/packages/devui-vue/devui/statistic/src/statistic.scss b/packages/devui-vue/devui/statistic/src/statistic.scss index ec9a59092d..a9d365492e 100644 --- a/packages/devui-vue/devui/statistic/src/statistic.scss +++ b/packages/devui-vue/devui/statistic/src/statistic.scss @@ -8,10 +8,8 @@ &-title { margin-bottom: 4px; - opacity: 0.7; font-size: 14px; } - &-content { font-size: 24px; display: flex; diff --git a/packages/devui-vue/devui/statistic/src/statistic.tsx b/packages/devui-vue/devui/statistic/src/statistic.tsx index 4de3a798fa..25f36c499a 100644 --- a/packages/devui-vue/devui/statistic/src/statistic.tsx +++ b/packages/devui-vue/devui/statistic/src/statistic.tsx @@ -24,9 +24,9 @@ export default defineComponent({ to: { value: to }, - delay: props.delay, + delay: 0, duration: props.animationDuration, - easing: props.easing, + easing: 'easeOutCubic', onUpdate: (keys: any) => { innerValue.value = keys.value }, @@ -37,14 +37,12 @@ export default defineComponent({ tween.value.start() } } - const statisticValue = computed(() => { return analysisValueType( innerValue.value, props.value, props.groupSeparator, - props.precision, - props.showGroupSeparator + props.precision ) }) onMounted(() => { @@ -52,7 +50,7 @@ export default defineComponent({ animation() } }) - + // 我们可以手动控制animation watch( () => props.start, (value) => { @@ -67,7 +65,7 @@ export default defineComponent({
{ctx.slots.title?.() || props.title}
-
+
{props.prefix || ctx.slots.prefix?.() ? ( {ctx.slots.prefix?.() || props.prefix} ) : null} @@ -76,7 +74,9 @@ export default defineComponent({ {ctx.slots.suffix?.() || props.suffix} ) : null}
- {ctx.slots.extra?.() || props.extra} + {props.extra || ctx.slots.extra?.() ? ( +
{ctx.slots.extra?.() || props.extra}
+ ) : null}
) } diff --git a/packages/devui-vue/devui/statistic/src/utils/animation.ts b/packages/devui-vue/devui/statistic/src/utils/animation.ts index 3b3eb192fa..9ab7230108 100644 --- a/packages/devui-vue/devui/statistic/src/utils/animation.ts +++ b/packages/devui-vue/devui/statistic/src/utils/animation.ts @@ -112,7 +112,6 @@ export class Tween { const tick = () => { this.update() this.timer = requestAnimationFrame(tick) - if (this.finished) { // 在判断 update中 结束后 停止 重绘 cancelAnimationFrame(this.timer) diff --git a/packages/devui-vue/devui/statistic/src/utils/separator.ts b/packages/devui-vue/devui/statistic/src/utils/separator.ts index 91178bccbc..17143eda8a 100644 --- a/packages/devui-vue/devui/statistic/src/utils/separator.ts +++ b/packages/devui-vue/devui/statistic/src/utils/separator.ts @@ -3,12 +3,11 @@ export type valueType = string | number export const separator = ( SeparatorString: string, // value groupSeparator: string, // 千分位分隔符 - showGroupSeparator: boolean // 是否展示千分位分隔符 ): string => { const res = SeparatorString.replace(/\d+/, function (n) { // 先提取整数部分 return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { - return $1 + `${showGroupSeparator ? groupSeparator : ''}` + return $1 + `${groupSeparator}` }) }) return res @@ -23,8 +22,7 @@ export const analysisValueType = ( value: valueType, // 动态value 值 propsValue: valueType, // 用户传入value groupSeparator: string, // 千位分隔符 - splitPrecisionNumber: number, // 分割精度, 小数点 - showGroupSeparator: boolean // 是否展示千分位分隔符 + splitPrecisionNumber: number // 分割精度, 小数点 ): string => { const fixedNumber = propsValue.toString().indexOf('.') !== -1 @@ -33,20 +31,12 @@ export const analysisValueType = ( if (typeof value === 'number') { if (isHasDot(value)) { return splitPrecisionNumber - ? separator( - value.toFixed(splitPrecisionNumber).toString(), - groupSeparator, - showGroupSeparator - ) - : separator(value.toFixed(fixedNumber).toString(), groupSeparator, showGroupSeparator) + ? separator(value.toFixed(splitPrecisionNumber).toString(), groupSeparator) + : separator(value.toFixed(fixedNumber).toString(), groupSeparator) } else { return splitPrecisionNumber - ? separator( - value.toFixed(splitPrecisionNumber).toString(), - groupSeparator, - showGroupSeparator - ) - : separator(value.toString(), groupSeparator, showGroupSeparator) + ? separator(value.toFixed(splitPrecisionNumber).toString(), groupSeparator) + : separator(value.toString(), groupSeparator) } } else { return value diff --git a/packages/devui-vue/docs/components/statistic/index.md b/packages/devui-vue/docs/components/statistic/index.md index 4ae329547d..73f41d010e 100644 --- a/packages/devui-vue/docs/components/statistic/index.md +++ b/packages/devui-vue/docs/components/statistic/index.md @@ -15,13 +15,15 @@ + :value="5201314"> + + :value="999999"> + @@ -29,38 +31,6 @@ ::: -### 在卡片中使用 - -在卡片中展示统计数值。 -:::demo - -```vue - -``` - -::: - ### 数值动画 我们可以通过设置 animation 属性 开启数值动画。可以在页面加载时开始动画,也可以手动控制 @@ -117,7 +87,7 @@ export default { ### 插槽的使用 -前缀和后缀插槽 +前缀插槽, 后缀插槽, 额外插槽 :::demo ```vue @@ -125,18 +95,53 @@ export default { - + + - - @@ -29,48 +31,6 @@ Used when it is necessary to display statistical data with description ::: -### Use in card - -Display statistics in cards. -:::demo - -```vue - -``` - -::: - ### Numerical animation We can start numerical animation by setting the animation attribute. You can start the animation when the page loads, or you can control it manually @@ -127,7 +87,7 @@ export default { ### Use of slots -Prefix and suffix slots +Prefix slot, suffix slot, extra slot :::demo ```vue @@ -135,20 +95,53 @@ Prefix and suffix slots -