organization.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { sendFetch, PageProps } from './index'
  2. import { ResPage, ResResult } from './type'
  3. import { organizationTypeEnum } from '@/store/organization'
  4. import * as URL from "./URL";
  5. import { ElMessage } from "element-plus";
  6. import { throttle, encodePwd } from "@/util";
  7. const error = throttle((msg: string) => ElMessage.error(msg), 2000);
  8. const success = throttle((msg: string) => ElMessage.success(msg), 2000);
  9. export type OrganizationType = {
  10. ancestors: string
  11. contact: string
  12. orderNum: number
  13. orgId: number
  14. parentId: number
  15. orgName: string
  16. password: string
  17. type?: organizationTypeEnum | null
  18. userName: string
  19. confirmPwd?: string,
  20. msgAuthCode?: string
  21. }
  22. export const addOrgFetch = async (params: Partial<OrganizationType>) => {
  23. const api = await sendFetch<ResResult>(URL.addOrganization, {
  24. method: "post",
  25. body: JSON.stringify(params),
  26. }, {
  27. useResult: true
  28. });
  29. if (api.code === 0) {
  30. success('添加成功')
  31. } else {
  32. if (api.code === 2008) {
  33. success(api.message)
  34. } else {
  35. error(api.message)
  36. throw (api.message)
  37. }
  38. }
  39. }
  40. export const alterOrgFetch = (params: Partial<OrganizationType>) =>
  41. sendFetch<PageProps<OrganizationType>>(URL.alterOrganization, {
  42. method: "post",
  43. body: JSON.stringify(params),
  44. });
  45. export const delOrgFetch = (params: Partial<OrganizationType>) =>
  46. sendFetch<PageProps<OrganizationType>>(URL.delOrganization, {
  47. method: "post",
  48. body: JSON.stringify(params),
  49. });
  50. export const getOrgListFetch = (params: PageProps<Partial<OrganizationType>>) =>
  51. sendFetch<ResPage<PageProps<OrganizationType>>>(URL.organizationPage, {
  52. method: "post",
  53. body: JSON.stringify(params),
  54. });
  55. export const getOrgListFetchList = () =>
  56. sendFetch<ResPage<PageProps<OrganizationType>>>(URL.organizationPageList, {
  57. method: "post",
  58. body: JSON.stringify({}),
  59. });
  60. export const registerOrganization = (params: any) => {
  61. const password = encodePwd(params.password)
  62. return sendFetch<ResResult>(URL.registerOrganization, {
  63. method: "post",
  64. body: JSON.stringify({ ...params, password, confirmPwd: password }),
  65. }, {
  66. noToken: true
  67. });
  68. }