添加更新时间

This commit is contained in:
辉鸭蛋
2024-10-12 21:41:27 +08:00
parent 30f67d05dc
commit 010e9a5b61

View File

@@ -2,16 +2,21 @@
<a-layout> <a-layout>
<a-layout-content :style="{ padding: '20px 50px' }"> <a-layout-content :style="{ padding: '20px 50px' }">
<a-space direction="vertical" size="large" fill> <a-space direction="vertical" size="large" fill>
<a-select <a-space>
v-model="selectedRepo" <a-select
placeholder="选择脚本仓库" v-model="selectedRepo"
style="width: 320px" placeholder="选择脚本仓库"
@change="fetchRepoData" style="width: 320px"
> @change="fetchRepoData"
<a-option v-for="(repo, index) in repoOptions" :key="index" :value="repo.value"> >
{{ repo.label }} <a-option v-for="(repo, index) in repoOptions" :key="index" :value="repo.value">
</a-option> {{ repo.label }}
</a-select> </a-option>
</a-select>
<a-typography-text v-if="repoUpdateTime">
更新时间{{ repoUpdateTime }}
</a-typography-text>
</a-space>
<a-tabs v-if="repoData.length"> <a-tabs v-if="repoData.length">
<a-tab-pane v-for="category in repoData" :key="category.name" :title="getCategoryDisplayName(category.name)"> <a-tab-pane v-for="category in repoData" :key="category.name" :title="getCategoryDisplayName(category.name)">
@@ -125,7 +130,7 @@ 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';
import { useClipboard } from '@vueuse/core'; import { useClipboard } from '@vueuse/core';
const baseRepo = "https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/build/tree.json"; const baseRepo = "https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/repo.json";
const mirrorUrls = [ const mirrorUrls = [
"{0}", "{0}",
"https://hub.gitmirror.com/{0}", "https://hub.gitmirror.com/{0}",
@@ -151,6 +156,9 @@ const filteredData = reactive({});
// 添加 loading 状态 // 添加 loading 状态
const loading = ref(false); const loading = ref(false);
// 添加新的响应式<E5BA94><E5BC8F><EFBFBD>
const repoUpdateTime = ref('');
const columns = [ const columns = [
{ {
title: '名称', title: '名称',
@@ -172,6 +180,7 @@ const fetchRepoData = async () => {
// 清空现有数据 // 清空现有数据
repoData.value = []; repoData.value = [];
repoUpdateTime.value = ''; // 清空更新时间
Object.keys(searchConditions).forEach(key => { Object.keys(searchConditions).forEach(key => {
searchConditions[key] = { searchConditions[key] = {
name: '', name: '',
@@ -186,16 +195,23 @@ const fetchRepoData = async () => {
try { try {
const response = await fetch(selectedRepo.value); const response = await fetch(selectedRepo.value);
const data = await response.json(); const repoInfo = await response.json();
// 从 indexes 中获取数据
repoData.value = repoInfo.indexes;
// 解析并设置更新时间
if (repoInfo.time) {
repoUpdateTime.value = formatDate(repoInfo.time);
}
// 为所有节点生成 path // 为所有节点生成 path
data.forEach(category => generatePaths(category)); repoData.value.forEach(category => generatePaths(category));
repoData.value = data;
initializeSearchConditions(); initializeSearchConditions();
// 初始化 tagColorMap // 初始化 tagColorMap
data.forEach(category => { repoData.value.forEach(category => {
traverseCategory(category, (item) => { traverseCategory(category, (item) => {
if (Array.isArray(item.tags)) { if (Array.isArray(item.tags)) {
item.tags.forEach(tag => { item.tags.forEach(tag => {
@@ -207,7 +223,7 @@ 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 { } finally {
loading.value = false; // 隐藏加载模态框 loading.value = false; // 隐藏加载模态框
@@ -326,8 +342,6 @@ const downloadScript = (script) => {
// 将数组转换为 JSON 字符串 // 将数组转换为 JSON 字符串
const jsonString = JSON.stringify(subscriptionData); const jsonString = JSON.stringify(subscriptionData);
// 将 JSON 字符串转换为 UTF-8 编码的 Base64
const base64String = btoa(encodeURIComponent(jsonString)); const base64String = btoa(encodeURIComponent(jsonString));
// 创建完整的 URL // 创建完整的 URL
@@ -409,6 +423,22 @@ const onTreeIconClick = (nodeData) => {
downloadScript({name: nodeData.title, path: nodeData.key}); downloadScript({name: nodeData.title, path: nodeData.key});
}; };
// 修改日期格式化函数
const formatDate = (timeString) => {
if (typeof timeString !== 'string' || timeString.length !== 14) {
return '无效的时间格式';
}
const year = timeString.slice(0, 4);
const month = timeString.slice(4, 6);
const day = timeString.slice(6, 8);
const hours = timeString.slice(8, 10);
const minutes = timeString.slice(10, 12);
const seconds = timeString.slice(12, 14);
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
onMounted(() => { onMounted(() => {
// 默认选中第一个仓库 // 默认选中第一个仓库
if (repoOptions.value.length > 0) { if (repoOptions.value.length > 0) {