|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, watchEffect } from 'vue'; |
| 3 | +import { useRoute } from 'vue-router'; |
| 4 | +import { REPO_PATH } from './constants'; |
| 5 | +
|
| 6 | +defineProps({ |
| 7 | + isZn: Boolean, |
| 8 | +}); |
| 9 | +const route = useRoute(); |
| 10 | +const contributors = ref([]); |
| 11 | +const filterData = data => { |
| 12 | + const arr = []; |
| 13 | + data.forEach(item => { |
| 14 | + if (!!item.author?.login || !!item.author?.html_url || !!item.author?.avatar_url) { |
| 15 | + arr.push({ |
| 16 | + login: item.author.login, |
| 17 | + url: item.author.html_url, |
| 18 | + avatar: item.author.avatar_url, |
| 19 | + }); |
| 20 | + } |
| 21 | + }); |
| 22 | + contributors.value = arr.reduce((acc, curr) => { |
| 23 | + if (!acc.find(item => item.login === curr.login)) { |
| 24 | + acc.push(curr); |
| 25 | + } |
| 26 | + return acc; |
| 27 | + }, []); |
| 28 | +}; |
| 29 | +const getContributors = async () => { |
| 30 | + const path = route.path; |
| 31 | + const parts = path.split('/'); |
| 32 | + const name = parts[2]; |
| 33 | + const componentName = name.includes('-') ? name.replace('-cn', '') : name; |
| 34 | + const url = `https://api.github.com/repos/${REPO_PATH}/commits?path=/components/${componentName}`; |
| 35 | + try { |
| 36 | + const req = await fetch(url); |
| 37 | + const res = await req.json(); |
| 38 | + filterData(res); |
| 39 | + } catch (e) { |
| 40 | + return null; |
| 41 | + } |
| 42 | +}; |
| 43 | +watchEffect(() => { |
| 44 | + getContributors(); |
| 45 | +}); |
| 46 | +</script> |
| 47 | + |
| 48 | +<template> |
| 49 | + <ul v-if="contributors.length > 0" class="acss-1ppw8kl"> |
| 50 | + <li v-for="item in contributors" :key="item.login"> |
| 51 | + <a-tooltip :title="`${isZn ? '文档贡献者:' : 'contribotors: '}${item.login}`"> |
| 52 | + <a :href="item.url" target="_blank"> |
| 53 | + <a-avatar :src="item.avatar" size="small" /> |
| 54 | + </a> |
| 55 | + </a-tooltip> |
| 56 | + </li> |
| 57 | + </ul> |
| 58 | +</template> |
| 59 | + |
| 60 | +<style scoped> |
| 61 | +.acss-1ppw8kl { |
| 62 | + display: -webkit-box; |
| 63 | + display: -webkit-flex; |
| 64 | + display: -ms-flexbox; |
| 65 | + display: flex; |
| 66 | + -webkit-box-flex-wrap: wrap; |
| 67 | + -webkit-flex-wrap: wrap; |
| 68 | + -ms-flex-wrap: wrap; |
| 69 | + flex-wrap: wrap; |
| 70 | + margin-top: 120px !important; |
| 71 | + clear: both; |
| 72 | +} |
| 73 | +
|
| 74 | +.acss-1ppw8kl li { |
| 75 | + height: 24px; |
| 76 | +} |
| 77 | +
|
| 78 | +.acss-1ppw8kl li, |
| 79 | +.acss-1ppw8kl .ant-avatar + .ant-avatar { |
| 80 | + -webkit-transition: all 0.3s; |
| 81 | + transition: all 0.3s; |
| 82 | + -webkit-margin-end: -8px; |
| 83 | + margin-inline-end: -8px; |
| 84 | +} |
| 85 | +
|
| 86 | +.acss-1ppw8kl:hover li, |
| 87 | +.acss-1ppw8kl:hover .ant-avatar { |
| 88 | + -webkit-margin-end: 0; |
| 89 | + margin-inline-end: 0; |
| 90 | +} |
| 91 | +</style> |
0 commit comments