fix: prefer github blob links in spider md dialog
This commit is contained in:
@@ -68,17 +68,52 @@
|
||||
<template #default="scope">
|
||||
<div class="spider-md-dialog__expand">
|
||||
<el-empty
|
||||
v-if="!remoteFiles(scope.row).length"
|
||||
v-if="!hasRemoteFiles(scope.row)"
|
||||
:description="emptyRemoteDescription(scope.row)"
|
||||
/>
|
||||
<template v-else>
|
||||
<div v-if="remoteMdFiles(scope.row, 'gitee').length" class="spider-md-dialog__provider-block">
|
||||
<div class="spider-md-dialog__expand-toolbar">
|
||||
<el-button size="small" type="primary" plain @click="copyAllMdLinks(remoteMdFiles(scope.row))">一键复制MD链接</el-button>
|
||||
<div class="spider-md-dialog__provider-title">Gitee 链接</div>
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
plain
|
||||
@click="copyAllMdLinks(remoteMdFiles(scope.row, 'gitee'), 'gitee')"
|
||||
>
|
||||
一键复制 Gitee MD
|
||||
</el-button>
|
||||
</div>
|
||||
<el-table :data="remoteMdFiles(scope.row)" border size="small">
|
||||
<el-table :data="remoteMdFiles(scope.row, 'gitee')" border size="small">
|
||||
<el-table-column prop="file_name" label="文件" min-width="180" />
|
||||
<el-table-column prop="download_url" label="MD链接" min-width="420" show-overflow-tooltip />
|
||||
<el-table-column label="MD链接" min-width="420" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ getRemoteLink(row, "gitee") }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<div v-if="remoteMdFiles(scope.row, 'github').length" class="spider-md-dialog__provider-block">
|
||||
<div class="spider-md-dialog__expand-toolbar">
|
||||
<div class="spider-md-dialog__provider-title">GitHub 链接</div>
|
||||
<el-button
|
||||
size="small"
|
||||
type="success"
|
||||
plain
|
||||
@click="copyAllMdLinks(remoteMdFiles(scope.row, 'github'), 'github')"
|
||||
>
|
||||
一键复制 GitHub MD
|
||||
</el-button>
|
||||
</div>
|
||||
<el-table :data="remoteMdFiles(scope.row, 'github')" border size="small">
|
||||
<el-table-column prop="file_name" label="文件" min-width="180" />
|
||||
<el-table-column label="MD链接" min-width="420" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ getRemoteLink(row, "github") }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -98,21 +133,20 @@
|
||||
聚合 {{ scope.row.aggregate_count || 0 }} / 详情 {{ scope.row.detail_count || 0 }} / 泛链 {{ scope.row.forge_count || 0 }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="推送状态" min-width="110">
|
||||
<el-table-column label="推送状态" min-width="180">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
size="small"
|
||||
:type="remoteStatus(scope.row) === 'success' ? 'success' : (remoteStatus(scope.row) === 'failed' || remoteStatus(scope.row) === 'partial_failed' ? 'danger' : 'info')"
|
||||
:type="remoteStatus(scope.row, 'gitee') === 'success' ? 'success' : (remoteStatus(scope.row, 'gitee') === 'failed' || remoteStatus(scope.row, 'gitee') === 'partial_failed' ? 'danger' : 'info')"
|
||||
>
|
||||
{{
|
||||
remoteStatus(scope.row) === 'success'
|
||||
? "已推送"
|
||||
: remoteStatus(scope.row) === 'failed'
|
||||
? "推送失败"
|
||||
: remoteStatus(scope.row) === 'partial_failed'
|
||||
? "部分失败"
|
||||
: "仅本地"
|
||||
}}
|
||||
Gitee:{{ statusLabel(remoteStatus(scope.row, "gitee")) }}
|
||||
</el-tag>
|
||||
<el-tag
|
||||
size="small"
|
||||
style="margin-left:8px;"
|
||||
:type="remoteStatus(scope.row, 'github') === 'success' ? 'success' : (remoteStatus(scope.row, 'github') === 'failed' || remoteStatus(scope.row, 'github') === 'partial_failed' ? 'danger' : 'info')"
|
||||
>
|
||||
GitHub:{{ statusLabel(remoteStatus(scope.row, "github")) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -121,15 +155,15 @@
|
||||
<el-tag size="small" type="success">本地成功</el-tag>
|
||||
<el-tag
|
||||
size="small"
|
||||
:type="remoteStatus(scope.row) === 'success' ? 'success' : (remoteStatus(scope.row) === 'failed' || remoteStatus(scope.row) === 'partial_failed' ? 'danger' : 'info')"
|
||||
:type="remoteOverallStatus(scope.row) === 'success' ? 'success' : (remoteOverallStatus(scope.row) === 'failed' || remoteOverallStatus(scope.row) === 'partial_failed' ? 'danger' : 'info')"
|
||||
style="margin-left:8px;"
|
||||
>
|
||||
{{
|
||||
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
|
||||
</el-button>
|
||||
@@ -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;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user