更新
This commit is contained in:
parent
e05ac23cc3
commit
93ece610ff
@ -367,6 +367,61 @@ function isUsedTagType(isUsed) {
|
|||||||
return "info";
|
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) {
|
function normalizeRow(raw) {
|
||||||
const pick = (...keys) => {
|
const pick = (...keys) => {
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
@ -395,16 +450,21 @@ function normalizeRow(raw) {
|
|||||||
isUsedRaw === null || isUsedRaw === undefined || isUsedRaw === ""
|
isUsedRaw === null || isUsedRaw === undefined || isUsedRaw === ""
|
||||||
? null
|
? null
|
||||||
: Number(isUsedRaw);
|
: Number(isUsedRaw);
|
||||||
|
const token = pick("token", "Token");
|
||||||
|
const expireInfo = resolveAccessTokenExpireInfo(token);
|
||||||
return {
|
return {
|
||||||
id: pick("id", "Id", "ID"),
|
id: pick("id", "Id", "ID"),
|
||||||
type: pick("data_type", "dataType", "type"),
|
type: pick("data_type", "dataType", "type"),
|
||||||
account: pick("account", "Account"),
|
account: pick("account", "Account"),
|
||||||
password: pick("password", "Password"),
|
password: pick("password", "Password"),
|
||||||
token: pick("token", "Token"),
|
token,
|
||||||
remark: pick("remark", "Remark"),
|
remark: pick("remark", "Remark"),
|
||||||
extractStatus,
|
extractStatus,
|
||||||
extracted: extractStatus !== 0,
|
extracted: extractStatus !== 0,
|
||||||
isUsed: Number.isFinite(isUsedNum) ? isUsedNum : null,
|
isUsed: Number.isFinite(isUsedNum) ? isUsedNum : null,
|
||||||
|
accessTokenExpireAt: expireInfo.accessTokenExpireAt,
|
||||||
|
accessTokenExpireStatus: expireInfo.accessTokenExpireStatus,
|
||||||
|
accessTokenExpireText: expireInfo.accessTokenExpireText,
|
||||||
extractedAt: formatTime(pickNullable("extracted_time", "extractedAt")),
|
extractedAt: formatTime(pickNullable("extracted_time", "extractedAt")),
|
||||||
extractedPlatform: pickNullable("extracted_platform", "extractedPlatform"),
|
extractedPlatform: pickNullable("extracted_platform", "extractedPlatform"),
|
||||||
createdAt: formatTime(pick("create_time", "createdAt")),
|
createdAt: formatTime(pick("create_time", "createdAt")),
|
||||||
@ -614,7 +674,7 @@ async function handleBatchProbe() {
|
|||||||
skipped > 0 ? `(已跳过 ${skipped} 条无 Token)` : "";
|
skipped > 0 ? `(已跳过 ${skipped} 条无 Token)` : "";
|
||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(
|
await ElMessageBox.confirm(
|
||||||
`将对 ${rows.length} 条 Token进行检测,是否继续?`,
|
`将对 ${rows.length} 条 Token进行检测,是否继续?${skipHint}`,
|
||||||
"批量检测",
|
"批量检测",
|
||||||
{ type: "info", confirmButtonText: "开始", cancelButtonText: "取消" },
|
{ 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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -701,9 +812,10 @@ async function handleBatchProbe() {
|
|||||||
<div class="toolbar-right">
|
<div class="toolbar-right">
|
||||||
<el-button type="primary" @click="openAddDialog('single')">添加账号</el-button>
|
<el-button type="primary" @click="openAddDialog('single')">添加账号</el-button>
|
||||||
<el-button type="success" @click="openAddDialog('batch')">批量添加</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 @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>
|
<el-button @click="apiDocVisible = true">接口说明</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -734,14 +846,13 @@ async function handleBatchProbe() {
|
|||||||
<el-tag>{{ typeText(row.type) }}</el-tag>
|
<el-tag>{{ typeText(row.type) }}</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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">
|
<el-table-column prop="password" label="密码" min-width="160" show-overflow-tooltip :tooltip-options="tooltipOpts">
|
||||||
<template #default="{ row }">{{ row.password || '-' }}</template>
|
<template #default="{ row }">{{ row.password || '-' }}</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="Token" min-width="200" show-overflow-tooltip :tooltip-options="tooltipOpts">
|
<el-table-column label="Token" min-width="200" show-overflow-tooltip :tooltip-options="tooltipOpts">
|
||||||
<template #default="{ row }">{{ row.token || '-' }}</template>
|
<template #default="{ row }">{{ row.token || '-' }}</template>
|
||||||
</el-table-column>
|
</el-table-column> -->
|
||||||
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip :tooltip-options="tooltipOpts" />
|
|
||||||
<el-table-column label="提取状态" width="100">
|
<el-table-column label="提取状态" width="100">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="extractStatusTagType(row)">
|
<el-tag :type="extractStatusTagType(row)">
|
||||||
@ -756,7 +867,13 @@ async function handleBatchProbe() {
|
|||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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">
|
<el-table-column label="提取平台" width="120">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag
|
<el-tag
|
||||||
@ -769,6 +886,8 @@ async function handleBatchProbe() {
|
|||||||
<span v-else>-</span>
|
<span v-else>-</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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">
|
<el-table-column label="操作" width="300" fixed="right" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-button
|
<el-button
|
||||||
@ -1163,4 +1282,19 @@ async function handleBatchProbe() {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
word-break: break-all;
|
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>
|
</style>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user