暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

document.model.ts 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // 文档类型枚举
  2. export enum DocumentType {
  3. UserRequirement = 'user_requirement', // 用户原始需求
  4. Requirement = 'requirement', // 需求文档
  5. Technical = 'technical', // 技术文档
  6. Implementation = 'implementation', // 业务实现
  7. Test = 'test' // 测试文档
  8. }
  9. // 文档类型显示名称映射
  10. export const DocumentTypeDisplayName: Record<DocumentType, string> = {
  11. [DocumentType.UserRequirement]: '用户原始需求',
  12. [DocumentType.Requirement]: '需求文档',
  13. [DocumentType.Technical]: '技术文档',
  14. [DocumentType.Implementation]: '业务实现',
  15. [DocumentType.Test]: '测试文档'
  16. };
  17. // 文档类型图标映射
  18. export const DocumentTypeIcon: Record<DocumentType, string> = {
  19. [DocumentType.UserRequirement]: 'description',
  20. [DocumentType.Requirement]: 'assignment',
  21. [DocumentType.Technical]: 'code',
  22. [DocumentType.Implementation]: 'architecture',
  23. [DocumentType.Test]: 'bug_report'
  24. };
  25. // 文档会话信息
  26. export interface DocumentSession {
  27. id: string; // 文档唯一ID (DocumentType值)
  28. sessionId: string; // 对应会话ID
  29. title: string; // 文档标题 (显示名称)
  30. content: string; // 从SSE获取的内容
  31. type: DocumentType; // 文档类型
  32. lastUpdated: Date; // 最后更新时间
  33. isLoading?: boolean; // 是否正在加载
  34. hasContent?: boolean; // 是否有内容
  35. }
  36. // 项目文档会话映射
  37. export interface ProjectDocumentSessions {
  38. projectId: string; // 项目ID
  39. documents: {
  40. [DocumentType.UserRequirement]?: string; // 用户原始需求会话ID
  41. [DocumentType.Requirement]?: string; // 需求文档会话ID
  42. [DocumentType.Technical]?: string; // 技术文档会话ID
  43. [DocumentType.Implementation]?: string; // 业务实现会话ID
  44. [DocumentType.Test]?: string; // 测试文档会话ID
  45. };
  46. }
  47. // 获取文档类型顺序(按照显示顺序)
  48. export function getDocumentTypeOrder(): DocumentType[] {
  49. return [
  50. DocumentType.UserRequirement,
  51. DocumentType.Requirement,
  52. DocumentType.Technical,
  53. DocumentType.Implementation,
  54. DocumentType.Test
  55. ];
  56. }
  57. // 从会话ID获取文档类型
  58. export function getDocumentTypeFromSessionId(sessionId: string, projectDocs: ProjectDocumentSessions): DocumentType | null {
  59. for (const docType of getDocumentTypeOrder()) {
  60. if (projectDocs.documents[docType] === sessionId) {
  61. return docType;
  62. }
  63. }
  64. return null;
  65. }
  66. // 创建空的文档会话数组(用于初始化)
  67. export function createEmptyDocumentSessions(projectId: string): DocumentSession[] {
  68. return getDocumentTypeOrder().map(docType => ({
  69. id: docType,
  70. sessionId: '',
  71. title: DocumentTypeDisplayName[docType],
  72. content: '',
  73. type: docType,
  74. lastUpdated: new Date(),
  75. isLoading: false,
  76. hasContent: false
  77. }));
  78. }