add easy-mock

This commit is contained in:
Pan
2017-06-26 15:43:11 +08:00
parent c528bd8ad0
commit 472cbb6d65
11 changed files with 89 additions and 156 deletions

View File

@@ -1,49 +1,18 @@
import { loginByEmail, logout, getInfo } from '@/api/login';
import { login, logout, getInfo } from '@/api/login';
import Cookies from 'js-cookie';
const user = {
state: {
user: '',
status: '',
email: '',
code: '',
uid: undefined,
auth_type: '',
token: Cookies.get('Admin-Token'),
name: '',
avatar: '',
introduction: '',
roles: [],
setting: {
articlePlatform: []
}
roles: []
},
mutations: {
SET_AUTH_TYPE: (state, type) => {
state.auth_type = type;
},
SET_CODE: (state, code) => {
state.code = code;
},
SET_TOKEN: (state, token) => {
state.token = token;
},
SET_UID: (state, uid) => {
state.uid = uid;
},
SET_EMAIL: (state, email) => {
state.email = email;
},
SET_INTRODUCTION: (state, introduction) => {
state.introduction = introduction;
},
SET_SETTING: (state, setting) => {
state.setting = setting;
},
SET_STATUS: (state, status) => {
state.status = status;
},
SET_NAME: (state, name) => {
state.name = name;
},
@@ -52,25 +21,18 @@ const user = {
},
SET_ROLES: (state, roles) => {
state.roles = roles;
},
LOGIN_SUCCESS: () => {
console.log('login success')
},
LOGOUT_USER: state => {
state.user = '';
}
},
actions: {
// 邮箱登录
LoginByEmail({ commit }, userInfo) {
// 登录
Login({ commit }, userInfo) {
const email = userInfo.email.trim();
return new Promise((resolve, reject) => {
loginByEmail(email, userInfo.password).then(response => {
login(email, userInfo.password).then(response => {
const data = response.data;
Cookies.set('Admin-Token', response.data.token);
Cookies.set('Admin-Token', data.token);
commit('SET_TOKEN', data.token);
commit('SET_EMAIL', email);
resolve();
}).catch(error => {
reject(error);
@@ -87,8 +49,6 @@ const user = {
commit('SET_ROLES', data.role);
commit('SET_NAME', data.name);
commit('SET_AVATAR', data.avatar);
commit('SET_UID', data.uid);
commit('SET_INTRODUCTION', data.introduction);
resolve(response);
}).catch(error => {
reject(error);