import { USER_AUTH } from '@/utils/admin/ConstantConfig';

const getCache = function(key) {
    if (!key) {
        console.error(`未找到需要获取的键`);
        return;
    }
    const data = window.localStorage.getItem(key)
    if (data) {
        return JSON.parse(data);
    }
    return data;
}

const saveCache = function(key, val) {
    if ( !key || !val ) {
        console.error(`缺少指定的键或值`)
        return;
    }
    window.localStorage.setItem(key, JSON.stringify(val));
}

const removeCache = function(key) {
    if (!key) {
        console.error(`未找到需要删除的键`);
        return;
    }
    window.localStorage.removeItem(key)
}

const getUserAuth = function() {
    return getCache(USER_AUTH)
}

export {
    getCache, saveCache, removeCache, getUserAuth
}