2024-11-17 11:45:08 +08:00
|
|
|
|
<script lang="ts" setup>
|
2025-01-13 21:51:37 +08:00
|
|
|
|
import { computed } from 'vue'
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
2025-01-13 21:51:37 +08:00
|
|
|
|
commit: IActivity<IContent>
|
|
|
|
|
}>(),
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
icon = computed(() => {
|
|
|
|
|
switch (props.commit.op_type) {
|
|
|
|
|
case 'merge_pull_request':
|
|
|
|
|
return ['fas', 'code-merge']
|
|
|
|
|
case 'create_repo':
|
|
|
|
|
return ['fab', 'git-alt']
|
|
|
|
|
case 'commit_repo':
|
|
|
|
|
default:
|
|
|
|
|
return ['fas', 'code-commit']
|
|
|
|
|
}
|
|
|
|
|
}),
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
time = computed(() => timeDifference(props.commit.created)),
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
timeDifference = (dateString: string): string => {
|
|
|
|
|
const targetDate = new Date(dateString),
|
|
|
|
|
currentDate = new Date(),
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
diffInMillis = currentDate.getTime() - targetDate.getTime(),
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
minutes = Math.floor(diffInMillis / (1000 * 60)),
|
|
|
|
|
hours = Math.floor(diffInMillis / (1000 * 60 * 60)),
|
|
|
|
|
days = Math.floor(diffInMillis / (1000 * 60 * 60 * 24)),
|
|
|
|
|
months = Math.floor(diffInMillis / (1000 * 60 * 60 * 24 * 30)),
|
|
|
|
|
years = Math.floor(diffInMillis / (1000 * 60 * 60 * 24 * 365))
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
if (minutes < 60) {
|
|
|
|
|
return `${minutes} 分钟前`
|
|
|
|
|
}
|
|
|
|
|
else if (hours < 24) {
|
|
|
|
|
return `${hours} 小时前`
|
|
|
|
|
}
|
|
|
|
|
else if (days < 30) {
|
|
|
|
|
return `${days} 天前`
|
|
|
|
|
}
|
|
|
|
|
else if (months < 12) {
|
|
|
|
|
return `${months} 个月前`
|
|
|
|
|
}
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
return `${years} 年前`
|
|
|
|
|
},
|
2024-11-17 11:45:08 +08:00
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
handleClick = () => {
|
|
|
|
|
window.open(props.commit.repo.html_url, '_self')
|
|
|
|
|
}
|
2024-11-17 11:45:08 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-01-13 21:51:37 +08:00
|
|
|
|
<div
|
|
|
|
|
class="group container relative flex h-36 w-full overflow-hidden rounded-2xl transition-all
|
2024-11-17 11:45:08 +08:00
|
|
|
|
hover:cursor-pointer hover:shadow-md"
|
2025-01-13 21:51:37 +08:00
|
|
|
|
@click="handleClick"
|
2024-11-17 11:45:08 +08:00
|
|
|
|
>
|
|
|
|
|
<!-- 提交图标 -->
|
2025-01-13 21:51:37 +08:00
|
|
|
|
<div
|
|
|
|
|
class="before:absolute relative before:top-0 before:right-0 before:bottom-0 flex h-36 before:w-2 w-36
|
2024-11-17 11:45:08 +08:00
|
|
|
|
items-center justify-center bg-pink-300 before:bg-pink-300 text-5xl text-white before:opacity-0
|
|
|
|
|
before:blur before:transition-all group-hover:before:opacity-100"
|
|
|
|
|
>
|
2025-01-13 21:51:37 +08:00
|
|
|
|
<font-awesome-icon
|
|
|
|
|
:icon="icon"
|
|
|
|
|
class="transition-all group-hover:scale-110"
|
|
|
|
|
/>
|
2024-11-17 11:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
<!-- 内容 -->
|
|
|
|
|
<div class="flex-1 overflow-hidden bg-white p-4">
|
|
|
|
|
<div class="mr-12 truncate text-2xl font-bold">
|
|
|
|
|
仓库:{{ commit.repo.name }}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="text-xl line-clamp-2">{{ commit.content.HeadCommit.Message }}</span>
|
|
|
|
|
<span class="absolute top-0 right-0 m-4 hidden rounded bg-gray-300 px-2 sm:block">
|
|
|
|
|
{{ commit.content.HeadCommit.Sha1.slice(0, 10) }}
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<span class="absolute right-0 bottom-0 m-4 rounded bg-gray-300 px-2">
|
2025-01-13 21:51:37 +08:00
|
|
|
|
<font-awesome-icon
|
|
|
|
|
:icon="['far', 'clock']"
|
|
|
|
|
class="mr-1 text-sm"
|
|
|
|
|
/>
|
2024-11-17 11:45:08 +08:00
|
|
|
|
{{ time }}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
|
</style>
|