|
@@ -5,7 +5,8 @@ import { Notification } from 'element-ui';
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
Vue.use(Vuex);
|
|
|
const api = {
|
|
|
- interface: `/api/market/user/login`,
|
|
|
+ interface: `/api/auth/login`,
|
|
|
+ getUser: `/api/auth/token`,
|
|
|
updatePassword: '/api/user/pwd_edit',
|
|
|
};
|
|
|
const state = () => ({});
|
|
@@ -21,17 +22,17 @@ const actions = {
|
|
|
isWx: Boolean 是否是微信登陆
|
|
|
needNotice:Boolean 是否需要提示
|
|
|
*/
|
|
|
- async login({ commit }, { user, router, path = '/', needReturn = false, typeCheck = false, isWx = false, needNotice = true }) {
|
|
|
+ async login({ commit, dispatch }, { user, router, path = '/', needReturn = false, typeCheck = false, isWx = false, needNotice = true }) {
|
|
|
let res;
|
|
|
//wx登陆,openid存在,user中是openid和qrcode;正常登陆,user中是mobile和passwd
|
|
|
if (isWx) res = await this.$axios.$post(`${api.wxLogin}`, user);
|
|
|
else res = await this.$axios.$post(`${api.interface}`, user);
|
|
|
const setUser = (token, commit) => {
|
|
|
localStorage.setItem('token', token);
|
|
|
- commit('setUser', token, { root: true });
|
|
|
+ dispatch('toGetUser');
|
|
|
};
|
|
|
if (res.errcode == '0') {
|
|
|
- setUser(res.data, commit);
|
|
|
+ setUser(res.data.key, commit);
|
|
|
// Notification({
|
|
|
// title: '登录成功',
|
|
|
// message: `欢迎,${user.user_name}`,
|
|
@@ -50,8 +51,21 @@ const actions = {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ async toGetUser({ commit }, payload) {
|
|
|
+ let key = localStorage.getItem('token');
|
|
|
+ if (!key) {
|
|
|
+ console.log('游客身份');
|
|
|
+ }
|
|
|
+ let res = await this.$axios.$post(api.getUser, { key: key });
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ let user = jwt.decode(res.data.token);
|
|
|
+ commit('setUser', user, { root: true });
|
|
|
+ }
|
|
|
+ },
|
|
|
async update({ commit }, payload) {
|
|
|
- let res = await this.$axios.$post(`${api.updatePassword}`, { data: payload });
|
|
|
+ let res = await this.$axios.$post(`${api.updatePassword}`, {
|
|
|
+ data: payload,
|
|
|
+ });
|
|
|
return res;
|
|
|
},
|
|
|
async bind({ commit }, payload) {
|