import storage from "../util/storage";

export default {
  userToken: (state) => () => {
    return state.userToken ? state.userToken : storage.getCache(storage.type.USER_TOKEN)
  },
  userInfo: (state) => () => {
    return state.userInfo.nickname ? state.userInfo : storage.getCache(storage.type.USER_INFO)
  },
  isLogin: (state, getter) => {
    return getter.userToken() !== null ? true : false
  },
  openid: (state) => () => {
    return state.openid ? state.openid : storage.getCache(storage.type.OPENID)
  },
  hidedMobile: (state) => {
    let mobile = state.userInfo.mobile,
      hideLength = mobile.length > 4 ? 4 : mobile.length,
      startPos = parseInt(mobile.length / 3)

    if (mobile) {
      mobile = mobile.split('').map((v, k) => {
        if (k >= startPos && k < startPos + hideLength) {
          return '*'
        } else {
          return v
        }
      })
      mobile = mobile.join('')
    }

    return mobile
  },
  dict_datas: state => state.dict.dictDatas,
}
