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-14 03:00:07 +08:00
|
|
|
commit: IStrictActivity
|
2025-01-13 21:51:37 +08:00
|
|
|
}>(),
|
2024-11-17 11:45:08 +08:00
|
|
|
|
2025-01-14 03:00:07 +08:00
|
|
|
commit_ref_name = computed(() => props.commit.ref_name.substring(props.commit.ref_name.lastIndexOf('/') + 1)),
|
|
|
|
|
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':
|
2025-01-14 03:00:07 +08:00
|
|
|
return ['fas', 'book-medical']
|
|
|
|
case 'delete_branch':
|
|
|
|
case 'delete_tag':
|
2025-01-13 21:51:37 +08:00
|
|
|
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} 年前`
|
|
|
|
},
|
2025-01-14 03:00:07 +08:00
|
|
|
calcHeight = (n: number) => `${n * 2.5}rem`
|
2024-11-17 11:45:08 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2025-01-14 03:00:07 +08:00
|
|
|
<div class="relative bg-transparent p-4 transition-all duration-500 group lg:hover:scale-105 lg:hover:rounded-xl lg:hover:shadow">
|
|
|
|
<!-- 标题部分 -->
|
|
|
|
<div class="relative flex items-center gap-4 text-lg">
|
2025-01-13 21:51:37 +08:00
|
|
|
<font-awesome-icon
|
2025-01-14 03:00:07 +08:00
|
|
|
class="h-8 w-10"
|
2025-01-13 21:51:37 +08:00
|
|
|
:icon="icon"
|
|
|
|
/>
|
2025-01-14 03:00:07 +08:00
|
|
|
<p v-if="commit.op_type === 'commit_repo' && commit.content">
|
|
|
|
推送到了仓库 {{ commit.repo.owner.login }}/{{ commit.repo.name }} 的 <span>{{ commit_ref_name }}</span> 分支
|
|
|
|
</p>
|
|
|
|
<p v-else-if="commit.op_type === 'commit_repo' && commit.content === null">
|
|
|
|
于 {{ commit.repo.owner.login }}/{{ commit.repo.name }} 创建了分支 {{ commit_ref_name }}
|
|
|
|
</p>
|
|
|
|
<p v-else-if="commit.op_type === 'create_repo'">
|
|
|
|
创建了仓库 {{ commit.repo.owner.login }}/{{ commit.repo.name }}
|
|
|
|
</p>
|
|
|
|
<span class="absolute top-0 right-0 hidden lg:block">{{ time }}</span>
|
2024-11-17 11:45:08 +08:00
|
|
|
</div>
|
2025-01-14 03:00:07 +08:00
|
|
|
<!-- 提交内容 -->
|
|
|
|
<div
|
|
|
|
v-if="commit.content"
|
|
|
|
class="ml-14 overflow-hidden transition-all duration-500 lg:invisible lg:opacity-0
|
|
|
|
lg:h-0 lg:group-hover:h-[999px] lg:group-hover:visible lg:group-hover:opacity-100"
|
|
|
|
:style="{ maxHeight: calcHeight(commit.content.Commits.length) }"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
v-for="content in commit.content.Commits"
|
|
|
|
:key="content.Sha1"
|
|
|
|
class="my-2 flex items-center gap-2"
|
|
|
|
>
|
2025-01-13 21:51:37 +08:00
|
|
|
<font-awesome-icon
|
2025-01-14 03:00:07 +08:00
|
|
|
class="h-4 w-5"
|
|
|
|
:icon="icon"
|
2025-01-13 21:51:37 +08:00
|
|
|
/>
|
2025-01-14 03:00:07 +08:00
|
|
|
<!-- SHA1 -->
|
|
|
|
<nuxt-link
|
|
|
|
:to="`https://cantyonion.site/git/${commit.repo.owner.login}/${commit.repo.name}/commit/${content.Sha1}`"
|
|
|
|
class="rounded bg-gray-200 px-2 transition-all hover:bg-gray-400"
|
|
|
|
style="font-family: 'LXGW WenKai Mono', monospace"
|
|
|
|
>{{ content.Sha1.substring(0, 10) }}</nuxt-link>
|
|
|
|
<!-- 提交信息 -->
|
|
|
|
<span class="truncate text-nowrap">{{ content.Message }}</span>
|
|
|
|
</div>
|
|
|
|
<!-- 比较链接 -->
|
|
|
|
<nuxt-link
|
|
|
|
v-if="commit.content.Commits.length > 1"
|
|
|
|
:to="`https://cantyonion.site/git/${commit.content.CompareURL}`"
|
|
|
|
class="text-blue-500 hover:text-blue-700"
|
|
|
|
style="font-family: 'LXGW WenKai Mono', monospace"
|
|
|
|
>比较 {{ commit.content.Commits.length }} 提交 >></nuxt-link>
|
2024-11-17 11:45:08 +08:00
|
|
|
</div>
|
2025-01-14 03:00:07 +08:00
|
|
|
<div class="absolute top-0 right-0 bottom-0 left-0 -z-10 transition-all duration-500 lg:group-hover:rounded-xl lg:group-hover:bg-white/10 lg:group-hover:backdrop-blur-2xl" />
|
2024-11-17 11:45:08 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
2025-01-13 21:51:37 +08:00
|
|
|
</style>
|