adminLogin.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import _ from 'lodash';
  4. const jwt = require('jsonwebtoken');
  5. Vue.use(Vuex);
  6. const api = {
  7. adminLoginInfo: `/api/live/v0/users/admin`,
  8. };
  9. const state = () => ({});
  10. const mutations = {};
  11. const actions = {
  12. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  13. const res = await this.$axios.$get(`${api.adminLoginInfo}`, {
  14. skip,
  15. limit,
  16. ...info,
  17. });
  18. return res;
  19. },
  20. async create({ commit }, payload) {
  21. const res = await this.$axios.$post(`${api.adminLoginInfo}`, payload);
  22. return res;
  23. },
  24. async fetch({ commit }, payload) {
  25. const res = await this.$axios.$get(`${api.adminLoginInfo}/${payload}`);
  26. return res;
  27. },
  28. async update({ commit }, { id, ...data }) {
  29. const res = await this.$axios.$post(`${api.adminLoginInfo}/update/${id}`, data);
  30. return res;
  31. },
  32. async delete({ commit }, payload) {
  33. const res = await this.$axios.$delete(`${api.adminLoginInfo}/${payload}`);
  34. return res;
  35. },
  36. async login({ commit }, { user }) {
  37. const res = await this.$axios.$post(`${api.adminLoginInfo}/login`, user);
  38. if (res.errcode === 0) {
  39. localStorage.setItem('token', res.data);
  40. localStorage.setItem('type', 'FWJG');
  41. user = jwt.decode(res.data);
  42. console.log(user);
  43. if (user.code == 'HNHGLY' && user.role == '1') {
  44. commit('setUser', user, { root: true });
  45. return res;
  46. }
  47. }
  48. },
  49. async updatePwd({ commit }, { id, ...data }) {
  50. const res = await this.$axios.$post(`${api.adminLoginInfo}/password/${id}`, data);
  51. return res;
  52. },
  53. };
  54. export default {
  55. namespaced: true,
  56. state,
  57. mutations,
  58. actions,
  59. };