Newer
Older
XinYang_SanWei+RongYun / src / util / item.js
@张强云笔记本 张强云笔记本 on 21 Dec 2021 1 KB 更替代码

var loginSet = null

export const setItem = (name, val) => {
  localStorage.setItem(name, JSON.stringify(val))
}

export const isJSON = (str) => {
  if (typeof str === 'string') {
    try {
      var obj = JSON.parse(str)

      if (typeof obj === 'object' && obj) {
        return true
      } else {
        return false
      }
    } catch (e) {
      return false
    }
  }
}

export const getItem = (name) => {
  return localStorage.getItem(name)
}

export const removeItem = (name) => {
  localStorage.removeItem(name)
}

export const setSession = (name, val) => {
  sessionStorage.setItem(name, JSON.stringify(val))
}

export const getSession = (name) => {
  return sessionStorage.getItem(name)
}

export const removeSession = (name) => {
  sessionStorage.removeItem(name)
}
export const loginTime = () => {
  // 登录计时,6小时超过登录期限
  loginSet = setTimeout(function () {
    removeSession('logins')
    loginTimeout()
  }, 21600000)
  // 21600000
}

export const loginTimeout = () => {
  // 退出,取消计时
  if (!loginSet) {
    clearTimeout(loginSet)
  }
}