user.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { defineStore } from 'pinia'
  2. import { AxiosWrapper } from '@/utils/axios-wrapper'
  3. import { get } from 'lodash-es'
  4. const url = '/user'
  5. const axios = new AxiosWrapper()
  6. export const UsersStore = defineStore('users', () => {
  7. const query = async ({ skip = 0, limit = undefined, ...info } = {}) => {
  8. let cond = {}
  9. if (skip) cond.skip = skip
  10. if (limit) cond.limit = limit
  11. cond = { ...cond, ...info }
  12. const res = await axios.$get(`${url}`, cond)
  13. return res
  14. }
  15. const fetch = async (payload) => {
  16. const res = await axios.$get(`${url}/${payload}`)
  17. return res
  18. }
  19. const detail = async (payload) => {
  20. const res = await axios.$get(`${url}/detail/${payload}`)
  21. return res
  22. }
  23. const create = async (payload) => {
  24. const res = await axios.$post(`${url}`, payload)
  25. return res
  26. }
  27. const update = async (payload) => {
  28. const id = get(payload, 'id', get(payload, '_id'))
  29. const res = await axios.$post(`${url}/${id}`, payload)
  30. return res
  31. }
  32. const del = async (payload) => {
  33. const res = await axios.$delete(`${url}/${payload}`)
  34. return res
  35. }
  36. return {
  37. query,
  38. fetch,
  39. detail,
  40. create,
  41. update,
  42. del
  43. }
  44. })