feat(my-ip): 测速历史记录——记录时间/线路/下载/上传/延迟,localStorage 最多20条可清空,方便多线路对比
This commit is contained in:
1 parent
e48d165741
commit
7992c83421
2 files changed
+176
No files matched your search
@@ -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>
|
||||
Reference in new issue
Block a user