优化博客访问量显示

This commit is contained in:
2024-08-31 15:05:16 +08:00
parent 30e8e89422
commit 7d6e056e6b
2 changed files with 12 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
function formateTimes(times: number) {
if (times < 10000)// 一万以内直接显示
return times;
if (times < 10000 * 10000)// 一亿以内加上 万
return (times / 10000).toFixed(1) + '万'
return (times / 10000 / 10000).toFixed(1) + '亿'
}
export { formateTimes };

View File

@@ -2,6 +2,7 @@
import { request } from '@/lib/request'; import { request } from '@/lib/request';
import { onMounted, reactive, ref } from 'vue'; import { onMounted, reactive, ref } from 'vue';
import { timestampToString } from '../lib/timestampToString' import { timestampToString } from '../lib/timestampToString'
import { formateTimes } from '@/lib/formateTimes';
const loadStatus = ref(0); const loadStatus = ref(0);
const blogList = reactive([]); const blogList = reactive([]);
@@ -30,7 +31,8 @@ onMounted(async () => {
<div class="blog-container" v-for="item of blogList"> <div class="blog-container" v-for="item of blogList">
<a class="title" :href="`/blogContent/${item.uuid}`" target="_blank">{{ item.title }}</a> <a class="title" :href="`/blogContent/${item.uuid}`" target="_blank">{{ item.title }}</a>
<div class="description">{{ item.description }}</div> <div class="description">{{ item.description }}</div>
<div class="publish-time">{{ timestampToString(+item.publish_time) }} ---- {{item.visit_count}}次访问</div> <div class="publish-time">{{ timestampToString(+item.publish_time) }}
{{ formateTimes(item.visit_count) }} 次访问</div>
</div> </div>
</div> </div>
</div> </div>