api.ts 1020 B

123456789101112131415161718192021222324252627282930
  1. import { iAccountGroup, iAccountGroupItem, iUserInfo } from "@/types/setting"
  2. import request from "@/utils/common/request"
  3. /**
  4. * 获取用户分组列表
  5. */
  6. export async function apiGetGroup(name: string = "") {
  7. const { data } = await request.get("/api/projectAccount/group", { name })
  8. const { roleDate = {}, accountData = [] } = data
  9. const newData: iAccountGroup = {}
  10. for (const key in roleDate) {
  11. if (Object.prototype.hasOwnProperty.call(roleDate, key)) {
  12. const element = roleDate[key]
  13. newData[key] = { value: element, children: [] }
  14. }
  15. }
  16. accountData.forEach((account: iUserInfo) => {
  17. if (newData[account.accountGroup]) {
  18. newData[account.accountGroup].children.push(account)
  19. }
  20. })
  21. const toArray: iAccountGroupItem[] = []
  22. for (const key in newData) {
  23. if (Object.prototype.hasOwnProperty.call(newData, key)) {
  24. const item = newData[key]
  25. item && (toArray.push(item))
  26. }
  27. }
  28. return { code: data.code, data: toArray }
  29. }