menus.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { defineStore } from 'pinia'
  2. import { AxiosWrapper } from '@/utils/axios-wrapper'
  3. import { get } from 'lodash-es'
  4. const url = '/menus'
  5. const axios = new AxiosWrapper()
  6. export const MenusStore = defineStore('menus', () => {
  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 create = async (payload) => {
  20. const res = await axios.$post(`${url}`, payload)
  21. return res
  22. }
  23. const update = async (payload) => {
  24. const id = get(payload, 'id', get(payload, '_id'))
  25. const res = await axios.$post(`${url}/${id}`, payload)
  26. return res
  27. }
  28. const del = async (payload) => {
  29. const res = await axios.$delete(`${url}/${payload}`)
  30. return res
  31. }
  32. return {
  33. query,
  34. fetch,
  35. create,
  36. update,
  37. del
  38. }
  39. })