personal.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. personalInfo: `/api/live/v0/users/personal`,
  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.personalInfo}`, {
  14. skip,
  15. limit,
  16. ...info,
  17. });
  18. return res;
  19. },
  20. async create({ commit }, payload) {
  21. const res = await this.$axios.$post(`${api.personalInfo}`, payload);
  22. return res;
  23. },
  24. async fetch({ commit }, payload) {
  25. const res = await this.$axios.$get(`${api.personalInfo}/${payload}`);
  26. return res;
  27. },
  28. async update({ commit }, { id, ...data }) {
  29. const res = await this.$axios.$post(`${api.personalInfo}/update/${id}`, data);
  30. return res;
  31. },
  32. async delete({ commit }, payload) {
  33. const res = await this.$axios.$delete(`${api.personalInfo}/${payload}`);
  34. return res;
  35. },
  36. // 修改密码
  37. async updatePassword({ commit }, { id, ...data }) {
  38. const res = await this.$axios.$post(`${api.personalInfo}/password/${id}`, data);
  39. return res;
  40. },
  41. async perLogin({ commit }, { user }) {
  42. const res = await this.$axios.$post(`${api.personalInfo}/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. async upgradeUser({ commit }, payload) {
  51. const res = await this.$axios.$post(`${api.personalInfo}/upgrade`, payload);
  52. return res;
  53. },
  54. // 批量注册用户
  55. async import({ commit }, payload) {
  56. const res = await this.$axios.$post(`${api.personalInfo}/import`, payload);
  57. return res;
  58. },
  59. async export({ commit }, payload) {
  60. const res = await this.$axios.$post(`${api.personalInfo}/export`, payload);
  61. return res;
  62. },
  63. };
  64. export default {
  65. namespaced: true,
  66. state,
  67. mutations,
  68. actions,
  69. };