feat(my-ip): 测速历史记录——记录时间/线路/下载/上传/延迟,localStorage 最多20条可清空,方便多线路对比

This commit is contained in:
personal827 committed 2026-11-01 11:20:45 +08:00
1 parent e48d165741
commit 7992c83421
2 files changed
+176

No files matched your search

+1
View File
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. See [standa
## Version 2026.10.30-it-tools-pro
### ✨ 新功能
- **测速历史记录(多线路对比)**:每次测速完成自动记录时间、所走线路(公网中转/IPv6 直连)、下载/上传速度与到站延迟,以表格展示在测速卡片下方(仅存本机浏览器 localStorage,最多 20 条,可一键清空);切换 IPv6 直连前后各测一次即可直接对照两条线路差距
- **文档翻译支持扫描件/图片自动 OCR**:非纯文字文档(扫描版 PDF、截图、照片、带文字图片)先自动 OCR 识别文字再整篇翻译,扫描版 PDF 逐页渲染识别(单文档最多 30 页),图片可直接上传翻译;结果标注「已OCR识别 N 页」,页面附处理说明
- **修复「改版后用户看到旧页面」缓存问题**:nginx 对 `index.html`/`sw.js`/`manifest` 强制 `Cache-Control: no-cache, must-revalidate`(每次重新校验,杜绝 PWA 预缓存赖旧),对内容哈希静态资源 `immutable` 长缓存(加载更快),部署后无需用户强刷即见新版
- **新增「本机IP查询」**(`/my-ip`,Network 分组,免费不授权):仅显示**用户端**公网 IPv4/IPv6 地址与所属地(多源容错、中文归属地、一键复制),不显示服务器地址;IPv6 不支持时明示「不支持 IPv6」并给出五步开启教程
+175
View File
@@ -268,6 +268,7 @@ async function runSpeedTest() {
upMbps.value = Math.round((sent * 8) / uel / 1e4) / 100;
spPct.value = 100;
sp.value = 'done';
pushSpeedRec(); // 记入本机测速历史,方便多线路对比
} catch (e: any) {
sp.value = 'error';
spMsg.value =
@@ -306,9 +307,65 @@ function grade(mbps: number): string {
return '🐢 较慢:建议检查网络或更换线路';
}
// ---------- 测速历史(存本机浏览器 localStorage,按线路对比,最多 20 条) ----------
const SPEED_HISTORY_KEY = 'itp_my_ip_speed_history';
interface SpeedRec {
t: number; // 时间戳
down: number; // 下载 Mbps
up: number; // 上传 Mbps
ms: number; // 到本站延迟
route: 'IPv6 直连' | '公网中转'; // 测试时所走线路
host: string; // 测试时的访问域名
}
const speedHistory = ref<SpeedRec[]>([]);
function loadSpeedHistory() {
try {
const arr = JSON.parse(localStorage.getItem(SPEED_HISTORY_KEY) || '[]');
speedHistory.value = Array.isArray(arr)
? arr.filter((r) => r && typeof r.down === 'number' && typeof r.t === 'number').slice(0, 20)
: [];
} catch {
speedHistory.value = [];
}
}
function saveSpeedHistory() {
try {
localStorage.setItem(SPEED_HISTORY_KEY, JSON.stringify(speedHistory.value.slice(0, 20)));
} catch {
/* 隐私模式下写入失败则仅本次会话展示 */
}
}
function pushSpeedRec() {
speedHistory.value.unshift({
t: Date.now(),
down: downMbps.value,
up: upMbps.value,
ms: serverMs.value ?? 0,
route: onV6Host ? 'IPv6 直连' : '公网中转',
host: location.host,
});
speedHistory.value = speedHistory.value.slice(0, 20);
saveSpeedHistory();
}
function clearSpeedHistory() {
speedHistory.value = [];
saveSpeedHistory();
}
function fmtTime(t: number): string {
const d = new Date(t);
const p = (n: number) => String(n).padStart(2, '0');
return `${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
}
onMounted(() => {
loadIps();
runAllLatency();
loadSpeedHistory();
});
</script>
@@ -429,6 +486,31 @@ onMounted(() => {
</div>
</div>
<div v-if="sp === 'error'" class="sp-error">{{ spMsg }}</div>
<!-- 测速历史(存本机浏览器,按线路对比) -->
<div v-if="speedHistory.length" class="sp-history">
<div class="sp-hist-head">
<span class="sp-hist-t">📋 测速历史(仅存于你的浏览器,共 {{ speedHistory.length }} 条,最多保留 20 条)</span>
<n-button size="small" quaternary @click="clearSpeedHistory()">清空历史</n-button>
</div>
<div class="sp-hist-table">
<div class="sp-hrow sp-hhead">
<span>时间</span>
<span>线路</span>
<span>下载 Mbps</span>
<span>上传 Mbps</span>
<span>延迟 ms</span>
</div>
<div v-for="r in speedHistory" :key="r.t" class="sp-hrow">
<span>{{ fmtTime(r.t) }}</span>
<span><em :class="r.route === 'IPv6 直连' ? 'tag-v6' : 'tag-v4'">{{ r.route }}</em></span>
<span class="c-down">{{ r.down }}</span>
<span class="c-up">{{ r.up }}</span>
<span class="c-ms">{{ r.ms }}</span>
</div>
</div>
<div class="sp-hist-tip">对比方法:在当前线路测一次 → 点横幅「切换 IPv6 直连」再测一次,两条线路的下载/上传/延迟直接在表里对照。</div>
</div>
</div>
<!-- 热门地点延迟 -->
@@ -794,11 +876,104 @@ onMounted(() => {
margin-top: 10px;
}
/* ---------- 测速历史 ---------- */
.sp-history {
margin-top: 14px;
border: 1px solid var(--n-border, rgba(128, 128, 128, 0.25));
border-radius: 10px;
padding: 10px 14px 12px;
background: rgba(128, 128, 128, 0.05);
}
.sp-hist-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
flex-wrap: wrap;
.sp-hist-t {
font-size: 14px;
font-weight: 600;
}
}
.sp-hist-table {
font-size: 13.5px;
.sp-hrow {
display: grid;
grid-template-columns: 1.1fr 1.1fr 1fr 1fr 0.9fr;
gap: 6px;
padding: 6px 4px;
align-items: center;
border-bottom: 1px dashed rgba(128, 128, 128, 0.2);
&:last-child {
border-bottom: none;
}
&.sp-hhead {
font-weight: 600;
opacity: 0.75;
font-size: 12.5px;
border-bottom: 1px solid rgba(128, 128, 128, 0.3);
}
.c-down {
color: #18a058;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.c-up {
color: #2080f0;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.c-ms {
font-variant-numeric: tabular-nums;
}
}
}
.tag-v4,
.tag-v6 {
font-style: normal;
font-size: 12px;
padding: 1px 8px;
border-radius: 999px;
white-space: nowrap;
}
.tag-v4 {
background: rgba(32, 128, 240, 0.14);
color: #2080f0;
}
.tag-v6 {
background: rgba(24, 165, 88, 0.15);
color: #18a058;
}
.sp-hist-tip {
margin-top: 8px;
font-size: 12.5px;
opacity: 0.7;
line-height: 1.6;
}
@media (max-width: 900px) {
.sec-head {
h3 {
width: 100%;
}
}
.sp-hist-table .sp-hrow {
grid-template-columns: 1fr 1fr 1fr 1fr 0.8fr;
font-size: 12.5px;
}
}
</style>