微信小程序一键授权登录(授权手机号 和获取用户信息)
// 微信小程序一键授权登录(获取用户基本信息)
LoginMpWx({ commit }, data) {
return new Promise((resolve, reject) => {
LoginApi.loginMpWx({ form: data }, { isPrompt: false })
.then(response => {
const result = response.data
loginSuccess(commit, result)
resolve(response)
})
.catch(reject)
})
},
// 微信小程序一键授权登录(授权手机号)
LoginMpWxMobile({ commit }, data) {
return new Promise((resolve, reject) => {
LoginApi.loginMpWxMobile({ form: data }, { isPrompt: false })
.then(response => {
const result = response.data
loginSuccess(commit, result)
resolve(response)
})
.catch(reject)
})
},
// 退出登录
Logout({ commit }, data) {
const store = this
return new Promise((resolve, reject) => {
if (store.getters.userId > 0) {
// 删除缓存中的tokne和userId
storage.remove(USER_ID)
storage.remove(ACCESS_TOKEN)
storage.remove('userInfo')
// 记录到store全局变量
commit('SET_TOKEN', '')
commit('SET_USER_ID', null)
resolve()
}
})
}
}
}