@/api/user#getUnionid JavaScript Examples

The following examples show how to use @/api/user#getUnionid. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user.js    From scan-login-demo with MIT License 5 votes vote down vote up
actions = {
  logout({ commit, state }) {
    return new Promise((resolve, reject) => {
      resetRouter()
      removeWxLoginStatus()
      commit('RESET_STATE')
      resolve()
    })
  },
  changeName({ commit }, name) {
    commit('SET_BASE', { key: 'name', value: name })
  },
  changeOpenid({ commit }, openid) {
    commit('SET_BASE', { key: 'openid', value: openid })
  },
  changeUnionid({ commit }, unionid) {
    commit('SET_BASE', { key: 'unionid', value: unionid })
  },
  changeAvatar({ commit }, avatar) {
    commit('SET_BASE', { key: 'avatar', value: avatar })
  },
  getUserUnionid({ commit }, code) {
    const data = {
      code: code
    }
    return new Promise((resolve, reject) => {
      getUnionid(data)
        .then(res => {
          // 存UNIONID
          commit('SET_BASE', { key: 'unionid', value: res.data.unionid })
          commit('SET_BASE', { key: 'nickname', value: res.data.nickname })
          commit('SET_BASE', { key: 'openid', value: res.data.openid })
          commit('SET_BASE', { key: 'avatar', value: res.data.avatar })
          resolve(res)
        })
        .catch(error => {
          reject(error)
        })
    })
  },
  // 设置状态
  setWxLoginStatus({ commit }, query) {
    if (query === 0 || query === 1) {
      // 上线打开注释,本地调试注释掉,保持信息最新
      removeWxLoginStatus()
    }
    // 设置不同的登录状态
    commit('SET_WX_LOGIN_STATUS', saveWxLoginStatus(query))
  },
  // 登出
  fedLogOut() {
    // 删除token,登陆状态
    removeWxLoginStatus()
  }
}