fix(client): migrate digital storage keys

This commit is contained in:
baiyanyun
2026-06-07 18:21:24 +08:00
parent fa5522e32e
commit 09d65701a3
11 changed files with 64 additions and 46 deletions

View File

@@ -122,11 +122,12 @@ interface RoleContextValue {
const RoleContext = createContext<RoleContextValue | null>(null);
const STORAGE_KEY = 'sgrobot-console-role';
const STORAGE_KEY = 'qimingclaw:digital-console-role';
const LEGACY_STORAGE_KEY = 'sgrobot-console-role';
function getStoredRole(): ConsoleRole {
try {
const stored = localStorage.getItem(STORAGE_KEY);
const stored = localStorage.getItem(STORAGE_KEY) ?? localStorage.getItem(LEGACY_STORAGE_KEY);
if (stored && stored in ROLE_PROFILES) return stored as ConsoleRole;
} catch { /* localStorage blocked */ }
return 'sales';
@@ -137,7 +138,10 @@ export function RoleProvider({ children }: { children: ReactNode }) {
const setRole = useCallback((newRole: ConsoleRole) => {
setRoleState(newRole);
try { localStorage.setItem(STORAGE_KEY, newRole); } catch { /* noop */ }
try {
localStorage.setItem(STORAGE_KEY, newRole);
localStorage.removeItem(LEGACY_STORAGE_KEY);
} catch { /* noop */ }
}, []);
const profile = ROLE_PROFILES[role];