搜索结果列表页面开发

This commit is contained in:
付民康
2025-03-12 18:41:20 +08:00
commit 7cebe8fc00
739 changed files with 88149 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
<script setup lang="ts">
import { useRouter } from 'vue-router';
import { useTimeFormat } from '@/utils/hooks/useTimeFormat';
const { formatTime } = useTimeFormat();
const router = useRouter();
defineProps<{
topicInfo: any;
validLinks: any[];
}>();
function triggerLink(link: any) {
if (link.linkName) router.push({ name: link.linkName, params: link.params });
}
</script>
<template>
<div class="topic-info">
<div class="topic-profile">
<div class="flex items-center">
<span class="text-G900 label">开发商</span>
<span class="text-G900 font-medium ml-3">{{topicInfo?.developer || '-'}}</span>
</div>
<div class="flex items-center mt-1">
<span class="text-G900 label">发布时间</span>
<span class="text-G900 font-medium ml-3">{{ formatTime(topicInfo?.released_time, 'YYYY-MM-DD') }}</span>
</div>
<div class="flex items-center mt-4">
<div class="flex items-center">
<Icon name="gt-organizations" class="mr-2"></Icon
><span class="text-G900 font-medium"><span v-if="topicInfo?.company">@</span>{{topicInfo?.company || '-'}}</span>
</div>
</div>
<div class="flex items-center mt-1">
<div class="flex items-center">
<Icon name="gt-connect" class="mr-2"></Icon
>
<span v-if="topicInfo?.websites?.length > 0"><a v-for="(item) in topicInfo?.websites" class="text-G900 font-medium" :href="item" target="_blank" :key="item">{{item}}</a></span>
<span v-else>-</span>
</div>
</div>
<!-- <div class="flex items-center mt-1">
<div class="flex items-center">
<Icon name="gt-link" class="mr-2"></Icon
><span class="text-G900 font-medium">Gitcode Azure 社区</span>
</div>
</div> -->
<!-- <div class="related-topic mt-8">
<div class="title font-medium text-G900">相关标签</div>
<div class="mt-4 flex flex-wrap">
<div
v-for="(link, idx) in validLinks"
:key="idx"
class="text-G900 mb-2 mr-2 topic-item"
@click="triggerLink(link)"
:class="{ ['cursor-pointer']: link.name }"
:title="link.name"
>
{{ link.name }}
</div>
</div>
</div> -->
</div>
</div>
</template>
<style scoped lang="scss">
@import 'devui-theme/styles-var/devui-var.scss';
.topic-info {
width: 332px;
padding: 16px 32px 0 0;
.topic-profile {
.label {
width: 56px;
}
}
}
.related-topic {
.topic-item {
background-color: var(--color-CG500);
color: #fff;
border-radius: 11px;
padding: 3px 10px;
height: 22px;
text-align: center;
font-size: 12px;
line-height: 16px;
max-width: 68px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-break: break-all;
span {
}
}
}
</style>

View File

View File

@@ -0,0 +1,120 @@
<template>
<div class="page-search-repo" >
<div v-loading="state.repoList?.length ? loading : false" >
<DataPanel :empty="!state.repoList?.length" :loading="state.repoList?.length ? false : loading" skeleton :card="false" >
<RepoItem v-for="(item, index) in state.repoList" :key="index" v-bind="item" @handleStar="toggleRepoStar">
<template #right>
<canvas height="60"></canvas>
</template>
</RepoItem>
</DataPanel>
</div>
<div class="page-search-repo-pagination" v-show="createdTotal > pager.pageSize">
<d-pagination
size="md"
:page-size-options="[10, 20, 50]"
:show-page-selector="false"
:can-view-total="true"
:can-change-page-size="true"
:max-items="5"
:total="createdTotal"
v-model:pageSize="pager.pageSize"
v-model:pageIndex="pager.pageIndex"
:max-page="500"
/>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, watch, reactive } from 'vue';
import RepoItem from '@/components/RepoItem/index.vue';
import { useUserInfo } from '@/views/User/hooks/useUserInfo';
import { dataHandler } from '@/components/RepoItem/datahandle';
import { emitEvent } from '@/utils/eventBus';
import { getTopicRepos, starRepo, unstarRepo } from '@/api/repo';
const props = defineProps<{ topicId: string, orderBy: string }>();
const pager = ref({
pageSize: 10,
pageIndex: 1
});
const { userInfo } = useUserInfo();
const loading = ref(false);
const toggleRepoStar = ({ id, isStar }) => {
if (!userInfo || !userInfo.username) {
emitEvent('login');
return false;
}
if (loading.value) return false;
loading.value = true;
if (isStar) {
unstarRepo({ repoId: id })
.then(() => {
getTopicReposList();
}).finally(() => {
loading.value = false;
});
} else {
starRepo({ repoId: id })
.then(() => {
getTopicReposList();
}).finally(() => {
loading.value = false;
});
}
};
const createdTotal = ref(0);
const state = reactive<{
repoList: any,
}>({
repoList: []
});
const getTopicReposList = async() => {
loading.value = true;
// 获取项目查询列表
const res = await getTopicRepos({
id: props.topicId,
order_by: props.orderBy.split(',')[0],
sort: props.orderBy.split(',')[1],
page: pager.value.pageIndex,
per_page: pager.value.pageSize
});
if (res.data) {
const { total, content } = res.data.data;
createdTotal.value = total || 0;
state.repoList = dataHandler(content) as any;
state.repoList.forEach((item:any, index: number) => {
Object.assign(item, {
title: content[index].name_with_namespace
});
});
}
loading.value = false;
};
watch(() => props.topicId, () => {
getTopicReposList();
}, { deep: true, flush: 'post' });
watch(() => props.orderBy, () => {
if (!props.topicId) {
return false;
}
getTopicReposList();
}, { deep: true, immediate: true, flush: 'post' });
watch(() => pager.value, () => {
getTopicReposList();
}, { deep: true, flush: 'post' });
</script>
<style scoped lang="scss">
.page-search-repo {
&-pagination {
padding-top: 20px;
padding-bottom: 20px;
display: flex;
justify-content: center;
}
}
</style>