From e801249e21bd141addef8ad02335765a4ee14513 Mon Sep 17 00:00:00 2001 From: www Date: Sun, 19 Apr 2026 19:44:27 +0800 Subject: [PATCH] fix: prefer github blob links in spider md dialog --- src/views/site/domainSpiderMdDialog.vue | 199 ++++++++++++++++++------ 1 file changed, 152 insertions(+), 47 deletions(-) diff --git a/src/views/site/domainSpiderMdDialog.vue b/src/views/site/domainSpiderMdDialog.vue index 2cd396d..10ab225 100644 --- a/src/views/site/domainSpiderMdDialog.vue +++ b/src/views/site/domainSpiderMdDialog.vue @@ -68,17 +68,52 @@ @@ -98,21 +133,20 @@ 聚合 {{ scope.row.aggregate_count || 0 }} / 详情 {{ scope.row.detail_count || 0 }} / 泛链 {{ scope.row.forge_count || 0 }} - + @@ -121,15 +155,15 @@ 本地成功 {{ - remoteStatus(scope.row) === 'success' + remoteOverallStatus(scope.row) === 'success' ? "远端成功" - : remoteStatus(scope.row) === 'failed' + : remoteOverallStatus(scope.row) === 'failed' ? "远端失败" - : remoteStatus(scope.row) === 'partial_failed' + : remoteOverallStatus(scope.row) === 'partial_failed' ? "远端部分失败" : "未推送远端" }} @@ -142,8 +176,8 @@ size="small" type="primary" plain - :disabled="!remoteMdFiles(scope.row).length" - @click="copyAllMdLinks(remoteMdFiles(scope.row))" + :disabled="!hasRemoteFiles(scope.row)" + @click="copyPreferredMdLinks(scope.row)" > 一键复制MD @@ -179,24 +213,34 @@ const formatDateTime = (value?: string) => { return `${year}-${month}-${day} ${hour}:${minute}:${second}`; }; +type RemoteProvider = "gitee" | "github"; + const remoteConfigured = computed(() => { - return Boolean(summary.value.github?.configured); + return Boolean(summary.value.gitee?.configured || summary.value.github?.configured); }); const remoteTitle = computed(() => { + if (summary.value.gitee?.configured && summary.value.github?.configured) { + return "当前已同时配置 Gitee 和 GitHub 自动推送,生成后会分别返回可复制链接"; + } + if (summary.value.gitee?.configured) { + return "当前已配置 Gitee 自动推送,生成后会返回 Gitee 可复制链接"; + } if (summary.value.github?.configured) { - return "当前已配置 GitHub 自动推送,生成后会自动返回可复制链接"; + return "当前已配置 GitHub 自动推送,生成后会返回 GitHub 可复制链接"; } - if (summary.value.github?.enabled) { - return "GitHub 推送已启用但未配完整,当前只能保留本地文件"; + if (summary.value.gitee?.enabled || summary.value.github?.enabled) { + return "远端推送已启用但未配完整,当前可能只保留本地文件"; } - return "当前未启用 GitHub 推送,生成后仅保留本地文件"; + return "当前未启用远端推送,生成后仅保留本地文件"; }); const remoteDescription = computed(() => { + const gitee = summary.value.gitee || {}; const github = summary.value.github || {}; + const giteeRepo = gitee.owner && gitee.repo ? `${gitee.owner}/${gitee.repo}` : "未配置"; const githubRepo = github.owner && github.repo ? `${github.owner}/${github.repo}` : "未配置"; - return `GitHub:${githubRepo} / ${github.branch || "-"} / ${github.root || "-"}`; + return `Gitee:${giteeRepo} / ${gitee.branch || "-"} / ${gitee.root || "-"};GitHub:${githubRepo} / ${github.branch || "-"} / ${github.root || "-"}`; }); const latestRunTitle = computed(() => { @@ -214,37 +258,72 @@ const latestRunDescription = computed(() => { const runRoot = String(row.run_root || "").trim() || "-"; const githubStatus = String(row.github_push_status || "").trim(); const githubError = String(row.github_push_error || "").trim(); - let pushed = "当前仅保留本地"; - const pushError = githubError; + const giteeStatus = String(row.gitee_push_status || "").trim(); + const giteeError = String(row.gitee_push_error || "").trim(); + const statusParts: string[] = []; + const errorParts: string[] = []; - if (githubStatus === "success") { - pushed = "已推送到 GitHub"; - } else if (githubStatus === "failed" || githubStatus === "partial_failed") { - pushed = githubStatus === "partial_failed" ? "本地生成成功,GitHub 部分推送后失败" : "本地生成成功,GitHub 推送失败"; - } + statusParts.push(`Gitee ${statusLabel(giteeStatus)}`); + statusParts.push(`GitHub ${statusLabel(githubStatus)}`); + if (giteeError) errorParts.push(`Gitee:${giteeError}`); + if (githubError) errorParts.push(`GitHub:${githubError}`); - return `目录:${runRoot};文件数:${fileCount};链接数:${totalLinks};状态:${pushed}${pushError ? `;错误:${pushError}` : ""}`; + return `目录:${runRoot};文件数:${fileCount};链接数:${totalLinks};状态:${statusParts.join(" / ")}${errorParts.length ? `;错误:${errorParts.join(";")}` : ""}`; }); -const remoteFiles = (row: SiteList.DomainSpiderMdRunSummaryItem) => { - return row.github_files || []; +const statusLabel = (status?: string) => { + if (status === "success") return "已推送"; + if (status === "failed") return "失败"; + if (status === "partial_failed") return "部分失败"; + return "仅本地"; }; -const remoteMdFiles = (row: SiteList.DomainSpiderMdRunSummaryItem) => { - return remoteFiles(row).filter(item => String(item?.file_name || "").toLowerCase().endsWith(".md")); +const remoteFiles = (row: SiteList.DomainSpiderMdRunSummaryItem, provider: RemoteProvider) => { + return provider === "github" ? (row.github_files || []) : (row.gitee_files || []); }; -const remoteStatus = (row: SiteList.DomainSpiderMdRunSummaryItem) => { - return String(row.github_push_status || "").trim(); +const remoteMdFiles = (row: SiteList.DomainSpiderMdRunSummaryItem, provider: RemoteProvider) => { + return remoteFiles(row, provider).filter(item => String(item?.file_name || "").toLowerCase().endsWith(".md")); +}; + +const hasRemoteFiles = (row: SiteList.DomainSpiderMdRunSummaryItem) => { + return Boolean(remoteMdFiles(row, "gitee").length || remoteMdFiles(row, "github").length); +}; + +const remoteStatus = (row: SiteList.DomainSpiderMdRunSummaryItem, provider: RemoteProvider) => { + return String(provider === "github" ? row.github_push_status : row.gitee_push_status || "").trim(); +}; + +const remoteOverallStatus = (row: SiteList.DomainSpiderMdRunSummaryItem) => { + const gitee = remoteStatus(row, "gitee"); + const github = remoteStatus(row, "github"); + const list = [gitee, github].filter(Boolean); + if (!list.length || list.every(item => !item || item === "local")) return ""; + if (list.includes("failed")) return "failed"; + if (list.includes("partial_failed")) return "partial_failed"; + if (list.includes("success")) return "success"; + return ""; +}; + +const getRemoteLink = (item: { download_url?: string; html_url?: string }, provider: RemoteProvider) => { + if (provider === "github") { + return String(item?.html_url || item?.download_url || "").trim(); + } + return String(item?.download_url || item?.html_url || "").trim(); }; const emptyRemoteDescription = (row: SiteList.DomainSpiderMdRunSummaryItem) => { + const giteeStatus = String(row.gitee_push_status || "").trim(); + const giteeError = String(row.gitee_push_error || "").trim(); const githubStatus = String(row.github_push_status || "").trim(); const githubError = String(row.github_push_error || "").trim(); + if (giteeStatus === "failed" || giteeStatus === "partial_failed") { + return `Gitee 推送失败:${giteeError || "请查看任务日志"}`; + } if (githubStatus === "failed" || githubStatus === "partial_failed") { return `GitHub 推送失败:${githubError || "请查看任务日志"}`; } - return "当前这轮还没有可复制的 GitHub 链接"; + return "当前这轮还没有可复制的远端链接"; }; const loadData = async () => { @@ -267,9 +346,9 @@ const copyText = async (text?: string) => { } }; -const copyAllMdLinks = async (items: Array<{ download_url?: string; html_url?: string }>) => { +const copyAllMdLinks = async (items: Array<{ download_url?: string; html_url?: string }>, provider: RemoteProvider) => { const lines = (items || []) - .map(item => String(item?.download_url || item?.html_url || "").trim()) + .map(item => getRemoteLink(item, provider)) .filter(Boolean); if (!lines.length) { ElMessage.warning("当前没有可复制的MD链接"); @@ -278,6 +357,20 @@ const copyAllMdLinks = async (items: Array<{ download_url?: string; html_url?: s await copyText(lines.join("\n")); }; +const copyPreferredMdLinks = async (row: SiteList.DomainSpiderMdRunSummaryItem) => { + const githubItems = remoteMdFiles(row, "github"); + if (githubItems.length) { + await copyAllMdLinks(githubItems, "github"); + return; + } + const giteeItems = remoteMdFiles(row, "gitee"); + if (giteeItems.length) { + await copyAllMdLinks(giteeItems, "gitee"); + return; + } + ElMessage.warning("当前没有可复制的MD链接"); +}; + const runGenerate = async () => { const res = await runDomainSpiderMdGenerate({}); const jobId = String(res.data?.job?.job_id || "").trim(); @@ -357,7 +450,19 @@ defineExpose({ .spider-md-dialog__expand-toolbar { display: flex; + align-items: center; justify-content: flex-end; margin-bottom: 8px; } + +.spider-md-dialog__provider-block + .spider-md-dialog__provider-block { + margin-top: 16px; +} + +.spider-md-dialog__provider-title { + margin-right: auto; + font-size: 13px; + font-weight: 600; + color: #303133; +}