export const getLocalStorageData = <T>(key: string): T => {
  try {
    const storedData = localStorage.getItem(key);
    return JSON.parse(storedData);
  } catch (error) {
    console.error(`获取 localStorage 数据失败 (${key}):`, error);
    return null;
  }
};

export const setLocalStorageData = <T>(key: string, data: T): void => {
  try {
    localStorage.setItem(key, JSON.stringify(data));
  } catch (error) {
    console.error(`设置 localStorage 数据失败 (${key}):`, error);
  }
};