From 93ece610ffce839deb568b2079b08a951f065241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=AB=E5=9C=B0=E5=83=A7?= <357099073@qq.com> Date: Wed, 6 May 2026 20:40:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/accountpool/cursor/index.vue | 150 +++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 8 deletions(-) diff --git a/src/views/accountpool/cursor/index.vue b/src/views/accountpool/cursor/index.vue index ed0d9ed..b8bfc34 100644 --- a/src/views/accountpool/cursor/index.vue +++ b/src/views/accountpool/cursor/index.vue @@ -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, +// }); +// } + @@ -701,9 +812,10 @@ async function handleBatchProbe() { 添加账号 批量添加 - 补号 + 补号 批量标记提取 - 批量检测 + 批量检测 + 接口说明 @@ -734,14 +846,13 @@ async function handleBatchProbe() { {{ typeText(row.type) }} - + @@ -756,7 +867,13 @@ async function handleBatchProbe() { - + + + + {{ row.accessTokenExpireText || "-" }} + + + - + +