chore: commit时格式整理

This commit is contained in:
dingyongya
2022-02-16 17:22:55 +08:00
parent c2b9d36868
commit 7f3674d532
95 changed files with 823 additions and 852 deletions

View File

@@ -5,4 +5,4 @@ Component.install = (app: App) => {
app.component(Component.name, Component);
};
export default Component;
export default Component;

View File

@@ -1,6 +1,6 @@
<template>
<slot name="prefix"></slot>
<span ref="counterRef" style="font-family:sans-serif;" />
<span ref="counterRef" style="font-family: sans-serif" />
<slot name="suffix"></slot>
</template>
@@ -11,9 +11,9 @@ export default {
</script>
<script setup lang="ts">
import { onMounted, ref, watch } from 'vue'
import { CountUp } from 'countup.js'
import type { CountUpOptions } from 'countup.js'
import { onMounted, ref, watch } from "vue";
import { CountUp } from "countup.js";
import type { CountUpOptions } from "countup.js";
export interface LayCountupProps {
endVal?: number; //显示的值
@@ -30,51 +30,58 @@ export interface LayCountupProps {
const props = withDefaults(defineProps<LayCountupProps>(), {
endVal: 0,
option: () => {
return {}
}
return {};
},
});
const counterRef = ref<HTMLDivElement | null>(null);
const instance = ref<CountUp | null>(null);
const {decimalPlaces,useGrouping,separator,useEasing,duration,prefix,suffix} = props;
const {
decimalPlaces,
useGrouping,
separator,
useEasing,
duration,
prefix,
suffix,
} = props;
const defaultOptions: CountUpOptions = {
startVal: 0, // 开始数字
decimalPlaces: decimalPlaces ? decimalPlaces : 0, // 小数位数
useEasing: useEasing ? useEasing : true, // 使用缓动动画
useEasing: useEasing ? useEasing : true, // 使用缓动动画
duration: duration ? duration : 2, // 动画持续时间
useGrouping: useGrouping ? useGrouping : true, // 是否使用千位分隔符
separator:separator ? separator : ",", // 千位分隔符
decimal:".", // 小数点分隔符
separator: separator ? separator : ",", // 千位分隔符
decimal: ".", // 小数点分隔符
prefix: prefix ? prefix : "", // 前缀
suffix: suffix ? suffix : "", // 后缀
}
};
watch(
() => props.endVal,
() => {
update(props.endVal)
update(props.endVal);
}
);
onMounted(() => {
createCounter()
})
createCounter();
});
const createCounter = () => {
if (!counterRef.value) return
const opts: CountUpOptions = Object.assign(defaultOptions, props.option)
if (!counterRef.value) return;
const opts: CountUpOptions = Object.assign(defaultOptions, props.option);
instance.value = new CountUp(counterRef?.value, props.endVal, opts);
start();
}
};
const start = () => {
if (!instance.value) return
if (!instance.value) return;
instance?.value.start();
}
};
const update = (newEndVal: number) => {
if (!instance.value) return
if (!instance.value) return;
instance?.value.update(newEndVal);
}
};
</script>