加入镜像

This commit is contained in:
辉鸭蛋
2024-10-11 03:14:56 +08:00
parent ce56cbf212
commit efa302ee8d

View File

@@ -8,7 +8,9 @@
style="width: 320px" style="width: 320px"
@change="fetchRepoData" @change="fetchRepoData"
> >
<a-option value="https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/build/tree.json">BetterGI 中央仓库</a-option> <a-option v-for="(repo, index) in repoOptions" :key="index" :value="repo.value">
{{ repo.label }}
</a-option>
</a-select> </a-select>
<a-tabs v-if="repoData.length"> <a-tabs v-if="repoData.length">
@@ -91,6 +93,20 @@
</template> </template>
<a-descriptions :data="drawerData" layout="vertical" bordered /> <a-descriptions :data="drawerData" layout="vertical" bordered />
</a-drawer> </a-drawer>
<!-- 添加加载模态框 -->
<a-modal
:visible="loading"
:footer="false"
:closable="false"
:mask-closable="false"
:unmount-on-close="true"
>
<div style="text-align: center;">
<a-spin size="large" />
<p style="margin-top: 16px;">正在加载仓库数据...</p>
</div>
</a-modal>
</a-layout> </a-layout>
</template> </template>
@@ -98,6 +114,24 @@
import { ref, onMounted, reactive, computed } from 'vue'; import { ref, onMounted, reactive, computed } from 'vue';
import { Message, Popover, Typography } from '@arco-design/web-vue'; import { Message, Popover, Typography } from '@arco-design/web-vue';
const baseRepo = "https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/build/tree.json";
const mirrorUrls = [
"{0}",
"https://mirror.ghproxy.com/{0}",
"https://hub.gitmirror.com/{0}",
"https://ghproxy.cc/{0}",
"https://www.ghproxy.cc/{0}",
"https://ghproxy.cn/{0}",
"https://ghproxy.net/{0}"
];
const repoOptions = computed(() => {
return mirrorUrls.map((url, index) => ({
label: index === 0 ? "BetterGI 中央仓库" : `BetterGI 中央仓库 镜像 ${index}`,
value: url.replace("{0}", baseRepo)
}));
});
const selectedRepo = ref(''); const selectedRepo = ref('');
const repoData = ref([]); const repoData = ref([]);
const drawerVisible = ref(false); const drawerVisible = ref(false);
@@ -105,6 +139,9 @@ const drawerData = ref([]);
const searchConditions = reactive({}); const searchConditions = reactive({});
const filteredData = reactive({}); const filteredData = reactive({});
// 添加 loading 状态
const loading = ref(false);
const columns = [ const columns = [
{ {
title: '名称', title: '名称',
@@ -113,8 +150,8 @@ const columns = [
ellipsis: true, ellipsis: true,
tooltip: false // 关闭默认的 tooltip tooltip: false // 关闭默认的 tooltip
}, },
{ title: '作者', dataIndex: 'author' }, { title: '作者', dataIndex: 'author', width: 200 },
{ title: '版本', dataIndex: 'version' }, { title: '版本', dataIndex: 'version', width: 100 },
{ title: '标签', dataIndex: 'tags', slotName: 'tags' }, { title: '标签', dataIndex: 'tags', slotName: 'tags' },
{ title: '操作', slotName: 'operations' }, { title: '操作', slotName: 'operations' },
]; ];
@@ -122,6 +159,8 @@ const columns = [
const fetchRepoData = async () => { const fetchRepoData = async () => {
if (!selectedRepo.value) return; if (!selectedRepo.value) return;
loading.value = true; // 显示加载模态框
try { try {
const response = await fetch(selectedRepo.value); const response = await fetch(selectedRepo.value);
const data = await response.json(); const data = await response.json();
@@ -147,6 +186,8 @@ const fetchRepoData = async () => {
} catch (error) { } catch (error) {
Message.error('获取仓库数据失败'); Message.error('获取仓库数据失败');
console.error('Error fetching repo data:', error); console.error('Error fetching repo data:', error);
} finally {
loading.value = false; // 隐藏加载模态框
} }
}; };
@@ -167,6 +208,12 @@ const traverseCategory = (category, callback) => {
if (category.name === 'js') { if (category.name === 'js') {
category.children.forEach(child => { category.children.forEach(child => {
if (child.type === 'directory') { if (child.type === 'directory') {
// 处理 JS 脚本
if (child.description && child.description.includes('~|~')) {
const [nameSuffix, newDescription] = child.description.split('~|~');
child.name = `${child.name} - ${nameSuffix.trim()}`;
child.description = newDescription.trim();
}
callback(child); callback(child);
} else { } else {
traverseCategory(child, callback); traverseCategory(child, callback);
@@ -250,7 +297,7 @@ const getTagColor = (tag) => {
onMounted(() => { onMounted(() => {
// 默认选中第一个仓库 // 默认选中第一个仓库
selectedRepo.value = 'https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/build/tree.json'; selectedRepo.value = repoOptions.value[0].value;
fetchRepoData(); fetchRepoData();
}); });