This commit is contained in:
扫地僧 2026-05-06 20:40:40 +08:00
parent e05ac23cc3
commit 93ece610ff

View File

@ -367,6 +367,61 @@ function isUsedTagType(isUsed) {
return "info";
}
function decodeJwtPayload(rawToken) {
const token = String(rawToken || "").trim();
if (!token) return null;
const pureToken = token.includes("::") ? token.split("::").pop().trim() : token;
const parts = pureToken.split(".");
if (parts.length < 2) return null;
try {
const base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), "=");
const json = decodeURIComponent(
atob(padded)
.split("")
.map((ch) => `%${ch.charCodeAt(0).toString(16).padStart(2, "0")}`)
.join(""),
);
return JSON.parse(json);
} catch {
return null;
}
}
function formatTimestamp(value) {
if (!value && value !== 0) return "";
const d = new Date(value);
if (Number.isNaN(d.getTime())) return "";
const p = (v) => String(v).padStart(2, "0");
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
}
function resolveAccessTokenExpireInfo(token) {
const payload = decodeJwtPayload(token);
const expRaw = payload?.exp;
const expSeconds = Number(expRaw);
if (!Number.isFinite(expSeconds) || expSeconds <= 0) {
return {
accessTokenExpireAt: "",
accessTokenExpireStatus: "unknown",
accessTokenExpireText: "无法解析",
};
}
const expireAt = formatTimestamp(expSeconds * 1000);
const expired = expSeconds * 1000 <= Date.now();
return {
accessTokenExpireAt: expireAt,
accessTokenExpireStatus: expired ? "expired" : "valid",
accessTokenExpireText: expired ? "已失效" : expireAt,
};
}
function accessTokenExpireTagType(status) {
if (status === "valid") return "success";
if (status === "expired") return "danger";
return "info";
}
function normalizeRow(raw) {
const pick = (...keys) => {
for (const key of keys) {
@ -395,16 +450,21 @@ function normalizeRow(raw) {
isUsedRaw === null || isUsedRaw === undefined || isUsedRaw === ""
? null
: Number(isUsedRaw);
const token = pick("token", "Token");
const expireInfo = resolveAccessTokenExpireInfo(token);
return {
id: pick("id", "Id", "ID"),
type: pick("data_type", "dataType", "type"),
account: pick("account", "Account"),
password: pick("password", "Password"),
token: pick("token", "Token"),
token,
remark: pick("remark", "Remark"),
extractStatus,
extracted: extractStatus !== 0,
isUsed: Number.isFinite(isUsedNum) ? isUsedNum : null,
accessTokenExpireAt: expireInfo.accessTokenExpireAt,
accessTokenExpireStatus: expireInfo.accessTokenExpireStatus,
accessTokenExpireText: expireInfo.accessTokenExpireText,
extractedAt: formatTime(pickNullable("extracted_time", "extractedAt")),
extractedPlatform: pickNullable("extracted_platform", "extractedPlatform"),
createdAt: formatTime(pick("create_time", "createdAt")),
@ -614,7 +674,7 @@ async function handleBatchProbe() {
skipped > 0 ? `(已跳过 ${skipped} 条无 Token` : "";
try {
await ElMessageBox.confirm(
`将对 ${rows.length} 条 Token进行检测是否继续`,
`将对 ${rows.length} 条 Token进行检测是否继续${skipHint}`,
"批量检测",
{ type: "info", confirmButtonText: "开始", cancelButtonText: "取消" },
);
@ -651,6 +711,57 @@ async function handleBatchProbe() {
}
}
// async function handleBatchProbeExpireTime() {
// if (!selectedRows.value.length) {
// ElMessage.warning("");
// return;
// }
// const rows = selectedRows.value.filter((r) => r?.token);
// if (!rows.length) {
// ElMessage.warning(" Token");
// return;
// }
// const skipped = selectedRows.value.length - rows.length;
// const validRows = rows.map((row) => ({
// ...row,
// ...resolveAccessTokenExpireInfo(row.token),
// }));
// const validCount = validRows.filter((row) => row.accessTokenExpireStatus === "valid").length;
// const expiredCount = validRows.filter((row) => row.accessTokenExpireStatus === "expired").length;
// const unknownCount = validRows.filter((row) => row.accessTokenExpireStatus === "unknown").length;
// tableData.value = tableData.value.map((item) => {
// const found = validRows.find((row) => row.id === item.id);
// return found
// ? {
// ...item,
// accessTokenExpireAt: found.accessTokenExpireAt,
// accessTokenExpireStatus: found.accessTokenExpireStatus,
// accessTokenExpireText: found.accessTokenExpireText,
// }
// : item;
// });
// const lines = validRows.slice(0, 20).map((row) => `ID ${row.id}${row.accessTokenExpireText}`);
// if (validRows.length > 20) {
// lines.push(`... ${validRows.length - 20} `);
// }
// if (skipped > 0) {
// lines.push(` Token ${skipped} `);
// }
// await ElMessageBox({
// title: "",
// message: h("div", { class: "cursor-probe-result cursor-expire-result" }, [
// h("div", ` ${validCount} ${expiredCount} ${unknownCount} `),
// h("pre", { class: "cursor-expire-result-pre" }, lines.join("\n")),
// ]),
// confirmButtonText: "",
// customClass: "cursor-probe-dialog",
// closeOnClickModal: true,
// });
// }
</script>
<template>
@ -701,9 +812,10 @@ async function handleBatchProbe() {
<div class="toolbar-right">
<el-button type="primary" @click="openAddDialog('single')">添加账号</el-button>
<el-button type="success" @click="openAddDialog('batch')">批量添加</el-button>
<el-button type="warning" @click="replenishVisible = true">补号</el-button>
<el-button @click="replenishVisible = true">补号</el-button>
<el-button @click="markExtractForSelected">批量标记提取</el-button>
<el-button type="info" plain @click="handleBatchProbe">批量检测</el-button>
<el-button plain @click="handleBatchProbe">批量检测</el-button>
<!-- <el-button type="info" plain @click="handleBatchProbeExpireTime">批量时间检测</el-button> -->
<el-button @click="apiDocVisible = true">接口说明</el-button>
</div>
</div>
@ -734,14 +846,13 @@ async function handleBatchProbe() {
<el-tag>{{ typeText(row.type) }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="account" label="账号" min-width="180" show-overflow-tooltip :tooltip-options="tooltipOpts" />
<!-- <el-table-column prop="account" label="账号" min-width="180" show-overflow-tooltip :tooltip-options="tooltipOpts" />
<el-table-column prop="password" label="密码" min-width="160" show-overflow-tooltip :tooltip-options="tooltipOpts">
<template #default="{ row }">{{ row.password || '-' }}</template>
</el-table-column>
<el-table-column label="Token" min-width="200" show-overflow-tooltip :tooltip-options="tooltipOpts">
<template #default="{ row }">{{ row.token || '-' }}</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip :tooltip-options="tooltipOpts" />
</el-table-column> -->
<el-table-column label="提取状态" width="100">
<template #default="{ row }">
<el-tag :type="extractStatusTagType(row)">
@ -756,7 +867,13 @@ async function handleBatchProbe() {
</el-tag>
</template>
</el-table-column>
<el-table-column prop="extractedAt" label="提取时间" width="180" />
<el-table-column label="accessToken失效时间" width="190" align="center">
<template #default="{ row }">
<el-tag :type="accessTokenExpireTagType(row.accessTokenExpireStatus)" size="small">
{{ row.accessTokenExpireText || "-" }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="提取平台" width="120">
<template #default="{ row }">
<el-tag
@ -769,6 +886,8 @@ async function handleBatchProbe() {
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column prop="extractedAt" label="提取时间" width="180" />
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip :tooltip-options="tooltipOpts" />
<el-table-column label="操作" width="300" fixed="right" align="center">
<template #default="{ row }">
<el-button
@ -1163,4 +1282,19 @@ async function handleBatchProbe() {
font-weight: 600;
word-break: break-all;
}
.cursor-probe-dialog .cursor-expire-result {
text-align: left;
}
.cursor-probe-dialog .cursor-expire-result-pre {
margin: 12px 0 0;
padding: 10px 12px;
max-height: 320px;
overflow: auto;
background: #f5f7fa;
border-radius: 6px;
font-size: 13px;
line-height: 1.6;
white-space: pre-wrap;
word-break: break-all;
}
</style>