admin.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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: `/travel/v1/api/admin`
  9. };
  10. export const AdminStore = defineStore('admin', () => {
  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. const login = async (payload: any): Promise<IQueryResult> => {
  42. const res = await axios.$post(`${api.url}/login`, payload);
  43. return res;
  44. };
  45. //password
  46. const rp = async (payload: any): Promise<IQueryResult> => {
  47. const res = await axios.$post(`${api.url}/rp`, payload);
  48. return res;
  49. };
  50. return {
  51. count,
  52. doubleCount,
  53. increment,
  54. query,
  55. fetch,
  56. create,
  57. update,
  58. del,
  59. login,
  60. rp
  61. };
  62. });