feat(认证): 延长本地密钥存活时间并添加访问标签持久化

修改认证密钥的本地存储时间为72小时以符合文档要求
在AnalyticsVisitView中添加访问标签的本地存储功能,持久化用户选择的标签
This commit is contained in:
anghunk
2026-01-22 15:59:28 +08:00
parent b8f01d0911
commit a2aa350054
3 changed files with 28 additions and 1 deletions

View File

@@ -135,6 +135,7 @@ const overview = ref<VisitOverviewResponse>({
}); });
const items = ref<VisitPageItem[]>([]); const items = ref<VisitPageItem[]>([]);
const visitTab = ref<"pv" | "latest">("pv"); const visitTab = ref<"pv" | "latest">("pv");
const visitTabStorageKey = "cwd-analytics-visit-tab";
const injectedDomainFilter = inject<Ref<string> | null>("domainFilter", null); const injectedDomainFilter = inject<Ref<string> | null>("domainFilter", null);
const domainFilter = injectedDomainFilter ?? ref(""); const domainFilter = injectedDomainFilter ?? ref("");
@@ -212,6 +213,29 @@ function getVisitOrderParam(): "pv" | "latest" | undefined {
return undefined; return undefined;
} }
function loadVisitTabFromStorage() {
if (typeof window === "undefined") {
return;
}
try {
const value = window.localStorage.getItem(visitTabStorageKey);
if (value === "pv" || value === "latest") {
visitTab.value = value;
}
} catch {
}
}
function saveVisitTabToStorage(value: "pv" | "latest") {
if (typeof window === "undefined") {
return;
}
try {
window.localStorage.setItem(visitTabStorageKey, value);
} catch {
}
}
async function loadData() { async function loadData() {
loading.value = true; loading.value = true;
listLoading.value = true; listLoading.value = true;
@@ -273,6 +297,7 @@ function changeVisitTab(tab: "pv" | "latest") {
return; return;
} }
visitTab.value = tab; visitTab.value = tab;
saveVisitTabToStorage(tab);
loadVisitPagesOnly(); loadVisitPagesOnly();
} }
@@ -338,6 +363,7 @@ function handleResize() {
} }
onMounted(() => { onMounted(() => {
loadVisitTabFromStorage();
loadData(); loadData();
window.addEventListener("resize", handleResize); window.addEventListener("resize", handleResize);
}); });

View File

@@ -381,6 +381,7 @@ POST /api/verify-admin
**风控说明** **风控说明**
- 本地密钥存活时间 72 小时
- 同一 IP 连续验证失败 3 次后,该 IP 将被锁定 30 分钟 - 同一 IP 连续验证失败 3 次后,该 IP 将被锁定 30 分钟
- 失败次数记录有效期为 1 小时 - 失败次数记录有效期为 1 小时

View File

@@ -1,5 +1,5 @@
const STORAGE_KEY = 'cwd_admin_auth'; const STORAGE_KEY = 'cwd_admin_auth';
const EXPIRY_MS = 12 * 60 * 60 * 1000; // 12 hours const EXPIRY_MS = 72 * 60 * 60 * 1000; // 72 hours
// Simple obfuscation (not real encryption, but sufficient for local storage requirement if no sensitive data other than the key itself which is already shared) // Simple obfuscation (not real encryption, but sufficient for local storage requirement if no sensitive data other than the key itself which is already shared)
// Requirement says "Local storage key credential needs to be encrypted". // Requirement says "Local storage key credential needs to be encrypted".