diff --git a/app/api/pay/route.ts b/app/api/pay/route.ts
index d52a7db..a102146 100644
--- a/app/api/pay/route.ts
+++ b/app/api/pay/route.ts
@@ -32,7 +32,7 @@ function buildPayHtml(
.join("\n");
const direct = options?.directToCashier;
return direct
- ? `
支付`
+ ? `支付`
: `
diff --git a/app/page.tsx b/app/page.tsx
index 0723104..c0406ef 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -123,23 +123,35 @@ export default function Home() {
const clearAllStorage = useCallback(() => {
try {
- if (typeof window !== "undefined" && window.localStorage) {
- window.localStorage.clear();
+ if (typeof window === "undefined") return;
+ const keys = ["userId", "paidType", "userName"];
+ keys.forEach((k) => {
+ try {
+ localStorage.removeItem(k);
+ } catch {
+ /* ignore */
+ }
+ });
+ try {
+ for (let i = localStorage.length - 1; i >= 0; i--) {
+ const key = localStorage.key(i);
+ if (key) localStorage.removeItem(key);
+ }
+ } catch {
+ /* ignore */
+ }
+ try {
+ sessionStorage.clear();
+ } catch {
+ /* ignore */
}
- removeStorage("userId");
- removeStorage("paidType");
- removeStorage("userName");
setPaidType(null);
setUserName(null);
setLoading(false);
- alert("本地存储已清空");
- // 移除 URL 中的 ?type=clean,避免刷新时重复触发
- if (typeof window !== "undefined" && window.history.replaceState) {
- window.history.replaceState({}, "", window.location.pathname);
- }
+ const path = window.location.pathname || "/";
+ window.location.replace(path);
} catch (error) {
console.error("清空存储失败:", error);
- alert("清空存储失败");
}
}, []);
@@ -174,7 +186,7 @@ export default function Home() {
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
- if (urlParams.get("type") === "clean") {
+ if (urlParams.get("type")?.trim() === "clean") {
clearAllStorage();
return;
}