import { setStorage, getStorage, removeStorage } from '@/common/utils/storage.js'

export default {
  //
  set_token: (state, token) => {
    state.token = token
    state.crossPagePam = new Date().getTime()
    if (token) {
      setStorage('token', token)
    } else {
      removeStorage('token')
    }
  },

  set_userId: (state, userId) => {
    state.userId = userId
    if (userId) {
      setStorage('userId', userId)
    } else {
      removeStorage('userId')
    }
  },

  set_mobile: (state, mobile) => {
    state.mobile = mobile
    if (mobile) {
      setStorage('mobile', mobile)
    } else {
      removeStorage('mobile')
    }
  },

  set_openId: (state, openId) => {
    state.openId = openId
    if (openId) {
      setStorage('openId', openId)
    } else {
      removeStorage('openId')
    }
  },

  set_name: (state, name) => {
    state.name = name
    if (name) {
      setStorage('name', name)
    } else {
      removeStorage('name')
    }
  },

  set_avatar: (state, avatar) => {
    state.avatar = avatar
    if (avatar) {
      setStorage('avatar', avatar)
    } else {
      removeStorage('avatar')
    }
  },

  set_city: (state, city) => {
    state.city = city
    if (city) {
      setStorage('city', city)
    } else {
      removeStorage('city')
    }
  },

  set_province: (state, province) => {
    state.province = province
    if (province) {
      setStorage('province', province)
    } else {
      removeStorage('province')
    }
  },

  setcrossPagePam: (state, crossPagePam) => {
    state.crossPagePam = crossPagePam
  }
}
