import Taro from '@tarojs/taro'

/**
 * 保存登陆接口数据
 */


const KEY = 'login-sto';
const setLoginSto = (val: string) => {
    try {
        Taro.setStorageSync("Token", val)//存到本地
    } catch (e) {
        // Do something when catch error
    }
}

const getLoginSto = () => {
    try {
        let data = Taro.getStorageSync(KEY)
        return data
    } catch (e) {
        // Do something when catch error
        return ""
    }
}

const removeLoginSto = () => {

}
/**
 * 保存阅读记录
 */
const setReadLog = (val: { [key: string]: string }) => {
    let readLog = Taro.getStorageSync('readLog')
    if (!readLog) {
        readLog = {}
    } 
    Object.keys(val).forEach(key => {
        readLog[key] = val[key]
    })
    Taro.setStorageSync("readLog", readLog)
}
/**
 * 获取阅读记录
 */
const getReadLog = (bookId:any) => {
    let readLog = Taro.getStorageSync('readLog')
    if (!readLog) {
        return ""
    }else{
        return readLog[bookId]
    }
}
export { setLoginSto, getLoginSto, removeLoginSto, setReadLog,getReadLog }