initInfo.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { ProjectInfo } from "@/type";
  2. import { DEFAULT_SETTING } from "@/constants";
  3. export const initInfo = (info: ProjectInfo) => {
  4. // 配置
  5. info.setting = info?.setting
  6. ? JSON.parse(info.setting as unknown as string)
  7. : { ...DEFAULT_SETTING };
  8. info.tables.forEach((tableItem) => {
  9. // 名称多语言
  10. tableItem.table.langNameList = [
  11. { name: "en", value: tableItem.table?.enName || "" },
  12. { name: "zh-CN", value: tableItem.table?.cnName || "" },
  13. ];
  14. tableItem.table.langName = "";
  15. // 描述多语言
  16. tableItem.table.langDescriptionList = [
  17. { name: "en", value: tableItem.table?.enDescription || "" },
  18. { name: "zh-CN", value: tableItem.table?.cnDescription || "" },
  19. ];
  20. tableItem.table.langDescription = "";
  21. // 字段处理
  22. tableItem.tableColumnList.forEach((columnItem) => {
  23. // 名称多语言
  24. columnItem.langNameList = [
  25. { name: "en", value: columnItem?.enName || "" },
  26. { name: "zh-CN", value: columnItem?.cnName || "" },
  27. ];
  28. columnItem.langName = "";
  29. });
  30. tableItem.table.style = JSON.parse(
  31. tableItem.table.style as unknown as string
  32. );
  33. tableItem.tableColumnList = tableItem.tableColumnList.sort(
  34. (a, b) => a.isPreDefined ? -1 : (a.displayOrder || 0) - (b.displayOrder || 0)
  35. );
  36. });
  37. // json字符串转换
  38. info.relations.forEach((relationItem) => {
  39. relationItem.style = JSON.parse(relationItem.style as unknown as string);
  40. });
  41. info.topicAreas.forEach((topicAreaItem) => {
  42. topicAreaItem.style = JSON.parse(topicAreaItem.style as unknown as string);
  43. });
  44. info.remarkInfos.forEach((remarkItem) => {
  45. remarkItem.style = JSON.parse(remarkItem.style as unknown as string);
  46. });
  47. };