|
@@ -0,0 +1,115 @@
|
|
|
+import Vue from 'vue';
|
|
|
+import Vuex from 'vuex';
|
|
|
+import _ from 'lodash';
|
|
|
+import { Notification } from 'element-ui';
|
|
|
+const jwt = require('jsonwebtoken');
|
|
|
+Vue.use(Vuex);
|
|
|
+const api = {
|
|
|
+ trainliveInfo: `/api/live/trainlive`,
|
|
|
+ logininfo: `/api/live/trainlive/login`,
|
|
|
+ userloginInfo: `/api/live/trainlive/user`,
|
|
|
+};
|
|
|
+const state = () => ({});
|
|
|
+const mutations = {};
|
|
|
+
|
|
|
+const actions = {
|
|
|
+ async query({ commit }, { skip = 0, limit = undefined, ...info } = {}) {
|
|
|
+ const res = await this.$axios.$get(api.trainliveInfo, {
|
|
|
+ skip,
|
|
|
+ limit,
|
|
|
+ ...info,
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async create({ commit }, payload) {
|
|
|
+ const res = await this.$axios.$post(`${api.trainliveInfo}`, payload);
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async fetch({ commit }, payload) {
|
|
|
+ const res = await this.$axios.$get(`${api.trainliveInfo}/${payload}`);
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async update({ commit }, { id, ...info } = {}) {
|
|
|
+ const res = await this.$axios.$post(`${api.trainliveInfo}/update/${id}`, {
|
|
|
+ ...info,
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async delete({ commit }, payload) {
|
|
|
+ const res = await this.$axios.$delete(`${api.trainliveInfo}/${payload}`);
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async login({ commit, dispatch }, { user, router, path = '/', needReturn = false, typeCheck = false, isWx = false, needNotice = true }) {
|
|
|
+ let res = await this.$axios.$post(`${api.logininfo}`, user);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ localStorage.setItem('user', JSON.stringify(res.data));
|
|
|
+ commit('setUser', res.data, { root: true });
|
|
|
+ Notification({
|
|
|
+ title: '登录成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 2000,
|
|
|
+ offset: 50,
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ } else {
|
|
|
+ Notification({
|
|
|
+ title: '登录失败',
|
|
|
+ message: `失败原因:${res.errmsg || '登陆失败'}`,
|
|
|
+ type: 'error',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 参加用户
|
|
|
+ async userCreate({ commit }, { id, ...info } = {}) {
|
|
|
+ const res = await this.$axios.$post(`${api.trainliveInfo}/user/${id}`, {
|
|
|
+ ...info,
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async userDelete({ commit }, { id, ...info } = {}) {
|
|
|
+ const res = await this.$axios.$delete(`${api.trainliveInfo}/user/${id}`, {
|
|
|
+ ...info,
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async userUpdate({ commit }, { id, ...info } = {}) {
|
|
|
+ const res = await this.$axios.$post(`${api.trainliveInfo}/user/update/${id}`, {
|
|
|
+ ...info,
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async userLogin({ commit }, { id, ...info } = {}) {
|
|
|
+ const res = await this.$axios.$post(`${api.userloginInfo}/login/${id}`, {
|
|
|
+ ...info,
|
|
|
+ });
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ localStorage.setItem('user', JSON.stringify(res.data));
|
|
|
+ commit('setUser', res.data, { root: true });
|
|
|
+ Notification({
|
|
|
+ title: '登录成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 2000,
|
|
|
+ offset: 50,
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ } else {
|
|
|
+ Notification({
|
|
|
+ title: '登录失败',
|
|
|
+ message: `失败原因:${res.errmsg || '登陆失败'}`,
|
|
|
+ type: 'error',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async userLogout({ commit }, { id } = {}) {
|
|
|
+ window.localStorage.removeItem('user');
|
|
|
+ const res = await this.$axios.$post(`${api.userloginInfo}/logout/${id}`);
|
|
|
+ commit('deleteUser');
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+export default {
|
|
|
+ namespaced: true,
|
|
|
+ state,
|
|
|
+ mutations,
|
|
|
+ actions,
|
|
|
+};
|