role.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { ref, computed } from 'vue';
  2. import { defineStore } from 'pinia';
  3. import { AxiosWrapper } from '@/util/axios-wrapper';
  4. import _ from 'lodash';
  5. import type { IQueryType, IQueryResult, IQueryParams } from '@/util/types.util';
  6. const axios = new AxiosWrapper();
  7. const api = {
  8. url: `/jcyjdtglpt/v1/api/role`,
  9. };
  10. export const RoleStore = defineStore('role', () => {
  11. const count = ref(0);
  12. const doubleCount = computed(() => count.value * 2);
  13. function increment() {
  14. count.value++;
  15. }
  16. const query = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
  17. let cond: IQueryType = {};
  18. if (skip) cond.skip = skip;
  19. if (limit) cond.limit = limit;
  20. cond = { ...cond, ...info };
  21. const res = await axios.$get(`${api.url}`, cond);
  22. return res;
  23. };
  24. const um = async (): Promise<IQueryResult> => {
  25. const res = await axios.$get(`${api.url}/um`);
  26. return res;
  27. };
  28. const am = async (): Promise<IQueryResult> => {
  29. const res = await axios.$get(`${api.url}/am`);
  30. return res;
  31. };
  32. const fetch = async (payload: any): Promise<IQueryResult> => {
  33. const res = await axios.$get(`${api.url}/${payload}`);
  34. return res;
  35. };
  36. const create = async (payload: any): Promise<IQueryResult> => {
  37. const res = await axios.$post(`${api.url}`, payload);
  38. return res;
  39. };
  40. const update = async (payload: any): Promise<IQueryResult> => {
  41. const id = _.get(payload, 'id', _.get(payload, '_id'));
  42. const res = await axios.$post(`${api.url}/${id}`, payload);
  43. return res;
  44. };
  45. const del = async (payload: any): Promise<IQueryResult> => {
  46. const res = await axios.$delete(`${api.url}/${payload}`);
  47. return res;
  48. };
  49. return {
  50. count,
  51. doubleCount,
  52. increment,
  53. query,
  54. um,
  55. am,
  56. fetch,
  57. create,
  58. update,
  59. del,
  60. };
  61. });