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