|
@@ -0,0 +1,28 @@
|
|
|
+import Vue from 'vue';
|
|
|
+import Vuex from 'vuex';
|
|
|
+import _ from 'lodash';
|
|
|
+const jwt = require('jsonwebtoken');
|
|
|
+Vue.use(Vuex);
|
|
|
+const api = {
|
|
|
+ interface: `/api/m/main/admin/login`,
|
|
|
+};
|
|
|
+const state = () => ({});
|
|
|
+const mutations = {};
|
|
|
+
|
|
|
+const actions = {
|
|
|
+ async login({ commit }, payload) {
|
|
|
+ const res = await this.$axios.$post(`${api.interface}`, payload);
|
|
|
+ if (res.errcode === 0) {
|
|
|
+ localStorage.setItem('token', res.data);
|
|
|
+ const user = jwt.decode(res.data);
|
|
|
+ commit('setUser', user, { root: true });
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+};
|
|
|
+export default {
|
|
|
+ namespaced: true,
|
|
|
+ state,
|
|
|
+ mutations,
|
|
|
+ actions,
|
|
|
+};
|