organization.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. organizationInfo: `/api/live/v0/users/organization`,
  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.organizationInfo}`, {
  14. skip,
  15. limit,
  16. ...info,
  17. });
  18. return res;
  19. },
  20. async create({ commit }, payload) {
  21. const res = await this.$axios.$post(`${api.organizationInfo}`, payload);
  22. return res;
  23. },
  24. async fetch({ commit }, payload) {
  25. const res = await this.$axios.$get(`${api.organizationInfo}/${payload}`);
  26. return res;
  27. },
  28. async update({ commit }, { id, ...data }) {
  29. const res = await this.$axios.$post(`${api.organizationInfo}/update/${id}`, data);
  30. return res;
  31. },
  32. async delete({ commit }, payload) {
  33. const res = await this.$axios.$delete(`${api.organizationInfo}/${payload}`);
  34. return res;
  35. },
  36. // 修改密码
  37. async updatePassword({ commit }, { id, ...data }) {
  38. const res = await this.$axios.$post(`${api.organizationInfo}/password/${id}`, data);
  39. return res;
  40. },
  41. async orgLogin({ commit }, { user }) {
  42. const res = await this.$axios.$post(`${api.organizationInfo}/login`, user);
  43. if (res.errcode === 0) {
  44. localStorage.setItem('token', res.data);
  45. user = jwt.decode(res.data);
  46. commit('setUser', user, { root: true });
  47. }
  48. return res;
  49. },
  50. };
  51. export default {
  52. namespaced: true,
  53. state,
  54. mutations,
  55. actions,
  56. };