2021-02-28 13:42:51 +08:00
|
|
|
|
<template>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
<div>
|
|
|
|
|
<el-card shadow="hover" header="数字滚动演示">
|
|
|
|
|
<el-alert
|
|
|
|
|
title="感谢优秀的 `countup.js`,项目地址:https://github.com/inorganik/countUp.js"
|
|
|
|
|
type="success"
|
|
|
|
|
:closable="false"
|
|
|
|
|
class="mb15"
|
|
|
|
|
></el-alert>
|
|
|
|
|
<el-row :gutter="20">
|
|
|
|
|
<el-col :sm="6" class="mb15" v-for="(v, k) in topCardItemList" :key="k">
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<div class="countup-card-item countup-card-item-box" :style="{ background: `var(${v.color})` }">
|
2022-05-30 10:01:00 +08:00
|
|
|
|
<div class="countup-card-item-flex" ref="topCardItemRefs">
|
2021-03-15 12:44:58 +08:00
|
|
|
|
<div class="countup-card-item-title pb3">{{ v.title }}</div>
|
2022-05-30 10:01:00 +08:00
|
|
|
|
<div class="countup-card-item-title-num pb6"></div>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
<div class="countup-card-item-tip pb3">{{ v.tip }}</div>
|
2022-05-30 10:01:00 +08:00
|
|
|
|
<div class="countup-card-item-tip-num"></div>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</div>
|
|
|
|
|
<i :class="v.icon" :style="{ color: v.iconColor }"></i>
|
|
|
|
|
</div>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
<div class="flex-warp">
|
|
|
|
|
<div class="flex-warp-item">
|
|
|
|
|
<div class="flex-warp-item-box">
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<el-button type="primary" size="default" @click="refreshCurrent">
|
2021-12-04 13:32:14 +08:00
|
|
|
|
<el-icon>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<ele-RefreshRight />
|
2021-12-04 13:32:14 +08:00
|
|
|
|
</el-icon>
|
|
|
|
|
重置/刷新数值
|
|
|
|
|
</el-button>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</el-card>
|
|
|
|
|
</div>
|
2021-02-28 13:42:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-02-21 23:52:59 +08:00
|
|
|
|
import { reactive, toRefs, onMounted, nextTick, defineComponent } from 'vue';
|
2021-03-15 12:44:58 +08:00
|
|
|
|
import { CountUp } from 'countup.js';
|
2022-04-18 19:14:38 +08:00
|
|
|
|
|
2022-02-21 23:52:59 +08:00
|
|
|
|
export default defineComponent({
|
2021-04-01 11:13:38 +08:00
|
|
|
|
name: 'funCountup',
|
2021-03-15 12:44:58 +08:00
|
|
|
|
setup() {
|
|
|
|
|
const state = reactive({
|
2022-05-30 10:01:00 +08:00
|
|
|
|
topCardItemRefs: null as any,
|
2021-03-15 12:44:58 +08:00
|
|
|
|
topCardItemList: [
|
|
|
|
|
{
|
|
|
|
|
title: '今日访问人数',
|
|
|
|
|
titleNum: '123',
|
|
|
|
|
tip: '在场人数',
|
|
|
|
|
tipNum: '911',
|
2022-02-21 23:52:59 +08:00
|
|
|
|
color: '--el-color-primary',
|
2022-03-04 12:39:54 +08:00
|
|
|
|
iconColor: '#ffcb47',
|
2021-03-15 12:44:58 +08:00
|
|
|
|
icon: 'iconfont icon-jinridaiban',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '实验室总数',
|
|
|
|
|
titleNum: '123',
|
|
|
|
|
tip: '使用中',
|
|
|
|
|
tipNum: '611',
|
2022-02-21 23:52:59 +08:00
|
|
|
|
color: '--el-color-success',
|
2022-03-04 12:39:54 +08:00
|
|
|
|
iconColor: '#70cf41',
|
2021-03-15 12:44:58 +08:00
|
|
|
|
icon: 'iconfont icon-AIshiyanshi',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '申请人数(月)',
|
|
|
|
|
titleNum: '123',
|
|
|
|
|
tip: '通过人数',
|
|
|
|
|
tipNum: '911',
|
2022-03-04 12:39:54 +08:00
|
|
|
|
color: '--el-color-warning',
|
|
|
|
|
iconColor: '#dfae64',
|
2021-03-15 12:44:58 +08:00
|
|
|
|
icon: 'iconfont icon-shenqingkaiban',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '销售情况',
|
|
|
|
|
titleNum: '123',
|
|
|
|
|
tip: '销售数',
|
|
|
|
|
tipNum: '911',
|
2022-02-21 23:52:59 +08:00
|
|
|
|
color: '--el-color-danger',
|
2022-03-04 12:39:54 +08:00
|
|
|
|
iconColor: '#e56565',
|
2022-02-21 23:52:59 +08:00
|
|
|
|
icon: 'iconfont icon-ditu',
|
2021-03-15 12:44:58 +08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
// 初始化数字滚动
|
|
|
|
|
const initNumCountUp = () => {
|
|
|
|
|
nextTick(() => {
|
2022-05-30 10:01:00 +08:00
|
|
|
|
state.topCardItemRefs.forEach((v: HTMLDivElement) => {
|
|
|
|
|
new CountUp(v.querySelector('.countup-card-item-title-num') as HTMLDivElement, Math.random() * 10000).start();
|
|
|
|
|
new CountUp(v.querySelector('.countup-card-item-tip-num') as HTMLDivElement, Math.random() * 1000).start();
|
|
|
|
|
});
|
2021-03-15 12:44:58 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
// 重置/刷新数值
|
|
|
|
|
const refreshCurrent = () => {
|
|
|
|
|
initNumCountUp();
|
|
|
|
|
};
|
|
|
|
|
// 页面加载时
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
initNumCountUp();
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
refreshCurrent,
|
|
|
|
|
...toRefs(state),
|
|
|
|
|
};
|
|
|
|
|
},
|
2022-02-21 23:52:59 +08:00
|
|
|
|
});
|
2021-02-28 13:42:51 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.countup-card-item {
|
2021-03-15 12:44:58 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
height: 103px;
|
2021-09-10 23:24:58 +08:00
|
|
|
|
background: var(--el-text-color-secondary);
|
2021-03-15 12:44:58 +08:00
|
|
|
|
border-radius: 4px;
|
|
|
|
|
transition: all ease 0.3s;
|
|
|
|
|
&:hover {
|
|
|
|
|
box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
|
|
|
|
|
transition: all ease 0.3s;
|
|
|
|
|
}
|
2021-02-28 13:42:51 +08:00
|
|
|
|
}
|
|
|
|
|
.countup-card-item-box {
|
2021-03-15 12:44:58 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
position: relative;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
&:hover {
|
|
|
|
|
i {
|
|
|
|
|
right: 0px !important;
|
|
|
|
|
bottom: 0px !important;
|
|
|
|
|
transition: all ease 0.3s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i {
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: -10px;
|
|
|
|
|
bottom: -10px;
|
|
|
|
|
font-size: 70px;
|
|
|
|
|
transform: rotate(-30deg);
|
|
|
|
|
transition: all ease 0.3s;
|
|
|
|
|
}
|
|
|
|
|
.countup-card-item-flex {
|
|
|
|
|
padding: 0 20px;
|
2022-02-21 23:52:59 +08:00
|
|
|
|
color: var(--el-color-white);
|
2021-03-15 12:44:58 +08:00
|
|
|
|
.countup-card-item-title,
|
|
|
|
|
.countup-card-item-tip {
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
}
|
|
|
|
|
.countup-card-item-title-num {
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
}
|
|
|
|
|
.countup-card-item-tip-num {
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-28 13:42:51 +08:00
|
|
|
|
}
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</style>
|