数字翻牌动态数据

This commit is contained in:
ryker 2022-06-13 18:04:01 +08:00
parent 5abfcfdd1b
commit a5374ee746

View File

@ -6,13 +6,8 @@
</span> </span>
</template> </template>
<span :style="`color:${numberColor};font-size:${numberSize}px`"> <span :style="`color:${numberColor};font-size:${numberSize}px`">
<n-number-animation <n-number-animation :from="option.from" :to="option.to" :duration="dur * 1000" :show-separator="showSeparator"
:from="from" :precision="precision"></n-number-animation>
:to="to"
:duration="dur * 1000"
:show-separator="showSeparator"
:precision="precision"
></n-number-animation>
</span> </span>
<template #suffix> <template #suffix>
<span :style="`color:${suffixColor};font-size:${numberSize}px`"> <span :style="`color:${suffixColor};font-size:${numberSize}px`">
@ -23,8 +18,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { PropType, toRefs } from 'vue' import { PropType, toRefs, ref, reactive, watch } from 'vue'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { useChartDataFetch } from '@/hooks'
const props = defineProps({ const props = defineProps({
chartConfig: { chartConfig: {
@ -32,21 +29,44 @@ const props = defineProps({
required: true, required: true,
}, },
}) })
const option = reactive({
from: 0,
to: 0,
})
const { w, h } = toRefs(props.chartConfig.attr) const { w, h } = toRefs(props.chartConfig.attr)
const { let {
dur, dur,
showSeparator, showSeparator,
prefixText, prefixText,
prefixColor, prefixColor,
suffixText, suffixText,
suffixColor, suffixColor,
from,
to,
precision, precision,
numberSize, numberSize,
numberColor, numberColor,
} = toRefs(props.chartConfig.option) } = toRefs(props.chartConfig.option)
const updateNumber = (newData: number) => {
//
option.from = option.to
option.to = newData
}
watch(
() => props.chartConfig.option.from,
() => {
option.from = props.chartConfig.option.from
}, { immediate: true }
)
watch(
() => props.chartConfig.option.to,
() => {
option.to = props.chartConfig.option.to
}, { immediate: true }
)
useChartDataFetch(props.chartConfig, useChartEditStore, updateNumber)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@include go('decorates-number') { @include go('decorates-number') {