organization.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {
  2. addTreeitem,
  3. axios,
  4. delTreeitem,
  5. editTreeitem,
  6. getTreeselect,
  7. } from "@/request";
  8. import { useUrlSearchParams } from "@vueuse/core";
  9. const params = useUrlSearchParams("history");
  10. console.log("params", params.deptId);
  11. const request = axios.create({
  12. baseURL: `${import.meta.env.VITE_SEVER_URL}/`,
  13. timeout: 1000,
  14. headers: {
  15. share: 1,
  16. 'Content-Type': 'application/json'
  17. },
  18. });
  19. export enum DeptType {
  20. corps = 1,
  21. detachment = 2,
  22. brigade = 3,
  23. }
  24. export type Organization = {
  25. ancestors: string;
  26. children?: Organization[];
  27. deptType: DeptType;
  28. id: string;
  29. leader: string;
  30. level: number;
  31. name: string;
  32. parentId: string;
  33. parentName: string;
  34. phone: string;
  35. remark: string;
  36. };
  37. export const getOrganizationTree = async (type?: string) =>
  38. (await axios.get<Organization[]>(getTreeselect, { headers: { share: 1 }, params: { type, deptId: params.deptId, ingoreRes: true, share: 1, } })).data;
  39. export const addOrganization = async (
  40. dept: Omit<Organization, "id">,
  41. deptIds: string[]
  42. ) => {
  43. await axios.post(addTreeitem, {
  44. superior: "sheq",
  45. ...dept,
  46. deptIdList: deptIds.join(","),
  47. });
  48. };
  49. export const setOrganization = async (
  50. dept: Organization,
  51. deptIds: string[]
  52. ) => {
  53. await axios.post(editTreeitem, {
  54. superior: "sheq",
  55. ...dept,
  56. deptIdList: deptIds.join(","),
  57. });
  58. };
  59. export const delOrganization = async (deptId: string) =>
  60. axios.post(delTreeitem + deptId);