channel.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import _ from 'lodash';
  4. import { Notification } from 'element-ui';
  5. const jwt = require('jsonwebtoken');
  6. Vue.use(Vuex);
  7. Vue.use(Vuex);
  8. const api = {
  9. channelInfo: `/api/live/channel`,
  10. logininfo: `/api/live/channel/login`,
  11. };
  12. const state = () => ({});
  13. const mutations = {};
  14. const actions = {
  15. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  16. const res = await this.$axios.$get(`${api.channelInfo}`, {
  17. skip,
  18. limit,
  19. ...info,
  20. });
  21. return res;
  22. },
  23. async create({ commit }, payload) {
  24. const res = await this.$axios.$post(`${api.channelInfo}`, payload);
  25. return res;
  26. },
  27. async fetch({ commit }, payload) {
  28. const res = await this.$axios.$get(`${api.channelInfo}/${payload}`);
  29. return res;
  30. },
  31. async update({ commit }, { id, ...data }) {
  32. const res = await this.$axios.$post(`${api.channelInfo}/update/${id}`, data);
  33. return res;
  34. },
  35. async delete({ commit }, payload) {
  36. const res = await this.$axios.$delete(`${api.channelInfo}/${payload}`);
  37. return res;
  38. },
  39. async login({ commit, dispatch }, { user, router, path = '/', needReturn = false, typeCheck = false, isWx = false, needNotice = true }) {
  40. let res = await this.$axios.$post(`${api.logininfo}`, user);
  41. if (res.errcode == '0') {
  42. localStorage.setItem('user', JSON.stringify(res.data));
  43. commit('setUser', res.data, { root: true });
  44. Notification({
  45. title: '登录成功',
  46. type: 'success',
  47. duration: 2000,
  48. offset: 50,
  49. });
  50. return res;
  51. } else {
  52. Notification({
  53. title: '登录失败',
  54. message: `失败原因:${res.errmsg || '登陆失败'}`,
  55. type: 'error',
  56. });
  57. }
  58. },
  59. };
  60. export default {
  61. namespaced: true,
  62. state,
  63. mutations,
  64. actions,
  65. };