unit.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/unit`,
  9. };
  10. export const UnitStore = defineStore('unit', () => {
  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 fetch = async (payload: any): Promise<IQueryResult> => {
  25. const res = await axios.$get(`${api.url}/${payload}`);
  26. return res;
  27. };
  28. const create = async (payload: any): Promise<IQueryResult> => {
  29. const res = await axios.$post(`${api.url}`, payload);
  30. return res;
  31. };
  32. const update = async (payload: any): Promise<IQueryResult> => {
  33. const id = _.get(payload, 'id', _.get(payload, '_id'));
  34. const res = await axios.$post(`${api.url}/${id}`, payload);
  35. return res;
  36. };
  37. const del = async (payload: any): Promise<IQueryResult> => {
  38. const res = await axios.$delete(`${api.url}/${payload}`);
  39. return res;
  40. };
  41. // account
  42. const tfe = async (payload: any): Promise<IQueryResult> => {
  43. const res = await axios.$post(`${api.url}/tfe`, payload);
  44. return res;
  45. };
  46. // account code password
  47. const erp = async (payload: any): Promise<IQueryResult> => {
  48. const res = await axios.$post(`${api.url}/erp`, payload);
  49. return res;
  50. };
  51. //password
  52. const rp = async (payload: any): Promise<IQueryResult> => {
  53. const res = await axios.$post(`${api.url}/rp`, payload);
  54. return res;
  55. };
  56. const login = async (payload: any): Promise<IQueryResult> => {
  57. const res = await axios.$post(`${api.url}/login`, payload);
  58. return res;
  59. };
  60. return {
  61. count,
  62. doubleCount,
  63. increment,
  64. query,
  65. fetch,
  66. create,
  67. update,
  68. del,
  69. tfe,
  70. erp,
  71. rp,
  72. login,
  73. };
  74. });