12345678910111213141516171819202122232425262728293031323334 |
- import Vue from 'vue';
- import Vuex from 'vuex';
- import _ from 'lodash';
- const jwt = require('jsonwebtoken');
- Vue.use(Vuex);
- const api = {
- interface: `/api/train/login`,
- user: id => `/api/train/user/update/${id}`,
- };
- const state = () => ({});
- const mutations = {};
- const actions = {
- async login({ commit }, payload) {
- const res = await this.$axios.$post(`${api.interface}`, payload);
- let result = true;
- if (res.errcode === 0) {
- let info = jwt.decode(res.data);
- sessionStorage.setItem('user', JSON.stringify(info));
- commit('setUser', info, { root: true });
- } else result = res;
- return result;
- },
- async update({ commit }, { id, ...info }) {
- let res = await this.$axios.$post(`${api.user(id)}`, info);
- return res;
- },
- };
- export default {
- namespaced: true,
- state,
- mutations,
- actions,
- };
|