requirements-confirm-card.ts 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. import { Component, Input, Output, EventEmitter, OnInit, OnDestroy, ChangeDetectorRef, ChangeDetectionStrategy } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { FormsModule, ReactiveFormsModule, FormBuilder, FormGroup, Validators } from '@angular/forms';
  4. // 素材文件接口
  5. interface MaterialFile {
  6. id: string;
  7. name: string;
  8. type: 'text' | 'image' | 'cad';
  9. url?: string;
  10. content?: string;
  11. size?: string;
  12. uploadTime: Date;
  13. analysis?: MaterialAnalysis;
  14. }
  15. // 素材解析结果接口
  16. interface MaterialAnalysis {
  17. // 文本类解析
  18. atmosphere?: { description: string; rgb?: string; colorTemp?: string };
  19. residents?: { type: string; details: string };
  20. scenes?: { preference: string; requirements: string };
  21. keywords?: { positive: string[]; negative: string[] };
  22. // 图片类解析
  23. mainColors?: { rgb: string; percentage: number }[];
  24. colorTemperature?: string;
  25. materialRatio?: { material: string; percentage: number }[];
  26. spaceRatio?: number;
  27. // CAD类解析
  28. structuralElements?: { type: string; position: string; changeable: boolean }[];
  29. spaceMetrics?: { room: string; ratio: string; width: string }[];
  30. flowMetrics?: { area: string; width: string; compliance: boolean }[];
  31. }
  32. // 需求指标接口
  33. interface RequirementMetric {
  34. id: string;
  35. category: 'color' | 'space' | 'material';
  36. name: string;
  37. value: any;
  38. unit?: string;
  39. range?: { min: number; max: number };
  40. description?: string;
  41. }
  42. // 协作评论接口
  43. interface CollaborationComment {
  44. id: string;
  45. author: string;
  46. role: 'customer-service' | 'designer' | 'client';
  47. content: string;
  48. timestamp: Date;
  49. requirementId?: string;
  50. status: 'pending' | 'resolved';
  51. }
  52. // 需求项接口
  53. interface RequirementItem {
  54. id: string;
  55. title: string;
  56. description: string;
  57. priority: 'high' | 'medium' | 'low';
  58. status: 'pending' | 'confirmed' | 'rejected';
  59. tags?: string[];
  60. metrics?: RequirementMetric[];
  61. comments?: CollaborationComment[];
  62. lastUpdated: Date;
  63. showComments?: boolean;
  64. }
  65. @Component({
  66. selector: 'app-requirements-confirm-card',
  67. standalone: true,
  68. imports: [CommonModule, FormsModule, ReactiveFormsModule],
  69. templateUrl: './requirements-confirm-card.html',
  70. styleUrls: ['./requirements-confirm-card.scss'],
  71. changeDetection: ChangeDetectionStrategy.Default // 确保使用默认变更检测策略
  72. })
  73. export class RequirementsConfirmCardComponent implements OnInit, OnDestroy {
  74. @Input() projectId?: string;
  75. @Output() requirementConfirmed = new EventEmitter<RequirementItem>();
  76. @Output() progressUpdated = new EventEmitter<number>();
  77. // 表单
  78. materialForm!: FormGroup;
  79. commentForm!: FormGroup;
  80. materialUploadForm!: FormGroup;
  81. // 数据
  82. materialFiles: MaterialFile[] = [];
  83. materials: MaterialFile[] = [];
  84. requirementMetrics: RequirementMetric[] = [];
  85. collaborationComments: CollaborationComment[] = [];
  86. requirementItems: RequirementItem[] = [];
  87. // 状态
  88. activeTab: 'materials' | 'mapping' | 'collaboration' | 'progress' = 'materials';
  89. isUploading = false;
  90. isAnalyzing = false;
  91. dragOver = false;
  92. showConsistencyWarning = false;
  93. warningMessage = '';
  94. // 自动保存相关状态
  95. autoSaveEnabled = true;
  96. lastSaveTime?: Date;
  97. hasUnsavedChanges = false;
  98. isSaving = false;
  99. saveStatus: 'saved' | 'saving' | 'error' | 'unsaved' = 'saved';
  100. // 流程状态
  101. stageCompletionStatus = {
  102. materialAnalysis: false,
  103. requirementMapping: false,
  104. collaboration: false,
  105. progressReview: false
  106. };
  107. // 自动保存定时器
  108. private autoSaveTimer?: any;
  109. // 需求指标
  110. colorIndicators = {
  111. mainColor: { r: 255, g: 230, b: 180 },
  112. colorTemperature: 2700,
  113. colorRange: '暖色调',
  114. saturation: 70,
  115. brightness: 80,
  116. contrast: 60
  117. };
  118. spaceIndicators = {
  119. lineRatio: 60,
  120. blankRatio: 30,
  121. flowWidth: 0.9,
  122. aspectRatio: 1.6,
  123. ceilingHeight: 2.8,
  124. lightingLevel: 300
  125. };
  126. materialIndicators = {
  127. fabricRatio: 50,
  128. woodRatio: 30,
  129. metalRatio: 20,
  130. smoothness: 7,
  131. glossiness: 4,
  132. texture: 6
  133. };
  134. // 指标范围配置
  135. indicatorRanges = {
  136. color: {
  137. r: { min: 0, max: 255 },
  138. g: { min: 0, max: 255 },
  139. b: { min: 0, max: 255 },
  140. temperature: { min: 2000, max: 6500 },
  141. saturation: { min: 0, max: 100 },
  142. brightness: { min: 0, max: 100 },
  143. contrast: { min: 0, max: 100 }
  144. },
  145. space: {
  146. lineRatio: { min: 0, max: 100 },
  147. blankRatio: { min: 10, max: 80 },
  148. flowWidth: { min: 0.6, max: 1.5 },
  149. aspectRatio: { min: 1.0, max: 3.0 },
  150. ceilingHeight: { min: 2.4, max: 4.0 },
  151. lightingLevel: { min: 100, max: 800 }
  152. },
  153. material: {
  154. fabricRatio: { min: 0, max: 100 },
  155. woodRatio: { min: 0, max: 100 },
  156. metalRatio: { min: 0, max: 100 },
  157. smoothness: { min: 1, max: 10 },
  158. glossiness: { min: 1, max: 10 },
  159. texture: { min: 1, max: 10 }
  160. }
  161. };
  162. // 预设数据
  163. presetAtmospheres = [
  164. { name: '温馨暖调', rgb: '255,230,180', colorTemp: '2700-3000K', materials: ['木质', '布艺'] },
  165. { name: '现代冷调', rgb: '200,220,240', colorTemp: '5000-6000K', materials: ['金属', '玻璃'] },
  166. { name: '自然清新', rgb: '220,240,220', colorTemp: '4000-4500K', materials: ['竹木', '石材'] }
  167. ];
  168. // 一致性检查
  169. consistencyWarnings: string[] = [];
  170. historyStates: any[] = [];
  171. constructor(private fb: FormBuilder, private cdr: ChangeDetectorRef) {}
  172. ngOnInit() {
  173. this.initializeForms();
  174. this.initializeRequirements();
  175. this.loadPresetMetrics();
  176. // 启用自动保存
  177. this.autoSaveEnabled = true;
  178. // 定期检查阶段完成状态
  179. setInterval(() => {
  180. this.checkStageCompletion();
  181. }, 5000);
  182. }
  183. ngOnDestroy(): void {
  184. // 清理自动保存定时器
  185. if (this.autoSaveTimer) {
  186. clearTimeout(this.autoSaveTimer);
  187. }
  188. }
  189. private initializeForms() {
  190. this.materialForm = this.fb.group({
  191. textContent: ['', Validators.required],
  192. atmosphereDescription: [''],
  193. residentInfo: [''],
  194. scenePreferences: [''],
  195. title: [''],
  196. content: ['']
  197. });
  198. this.commentForm = this.fb.group({
  199. content: ['', Validators.required],
  200. requirementId: ['']
  201. });
  202. this.materialUploadForm = this.fb.group({
  203. file: [''],
  204. textContent: ['', Validators.required]
  205. });
  206. }
  207. private initializeRequirements() {
  208. this.requirementItems = [
  209. {
  210. id: 'color-atmosphere',
  211. title: '色彩氛围',
  212. description: '整体色调和氛围营造',
  213. priority: 'high',
  214. status: 'pending',
  215. lastUpdated: new Date()
  216. },
  217. {
  218. id: 'space-layout',
  219. title: '空间布局',
  220. description: '功能分区和动线设计',
  221. priority: 'high',
  222. status: 'pending',
  223. lastUpdated: new Date()
  224. },
  225. {
  226. id: 'material-selection',
  227. title: '材质选择',
  228. description: '主要材质和质感要求',
  229. priority: 'medium',
  230. status: 'pending',
  231. lastUpdated: new Date()
  232. }
  233. ];
  234. }
  235. private loadPresetMetrics() {
  236. this.requirementMetrics = [
  237. {
  238. id: 'main-color',
  239. category: 'color',
  240. name: '主色调',
  241. value: { r: 255, g: 230, b: 180 },
  242. description: '空间主要色彩'
  243. },
  244. {
  245. id: 'color-temp',
  246. category: 'color',
  247. name: '色温',
  248. value: 3000,
  249. unit: 'K',
  250. range: { min: 2700, max: 6500 },
  251. description: '照明色温范围'
  252. },
  253. {
  254. id: 'wood-ratio',
  255. category: 'material',
  256. name: '木质占比',
  257. value: 60,
  258. unit: '%',
  259. range: { min: 0, max: 100 },
  260. description: '木质材料使用比例'
  261. }
  262. ];
  263. }
  264. // 素材上传功能
  265. onFileSelected(event: Event, type: 'text' | 'image' | 'cad') {
  266. const input = event.target as HTMLInputElement;
  267. if (input.files) {
  268. Array.from(input.files).forEach(file => {
  269. this.uploadFile(file, type);
  270. });
  271. }
  272. }
  273. onFileDrop(event: DragEvent, type: 'text' | 'image' | 'cad') {
  274. event.preventDefault();
  275. this.dragOver = false;
  276. if (event.dataTransfer?.files) {
  277. Array.from(event.dataTransfer.files).forEach(file => {
  278. this.uploadFile(file, type);
  279. });
  280. }
  281. }
  282. onDragOver(event: DragEvent) {
  283. event.preventDefault();
  284. this.dragOver = true;
  285. }
  286. onDragLeave(event: DragEvent) {
  287. event.preventDefault();
  288. this.dragOver = false;
  289. }
  290. private uploadFile(file: File, type: 'text' | 'image' | 'cad') {
  291. this.isUploading = true;
  292. // 模拟文件上传
  293. setTimeout(() => {
  294. const materialFile: MaterialFile = {
  295. id: this.generateId(),
  296. name: file.name,
  297. type: type,
  298. url: URL.createObjectURL(file),
  299. size: this.formatFileSize(file.size),
  300. uploadTime: new Date()
  301. };
  302. this.materialFiles.push(materialFile);
  303. this.materials.push(materialFile);
  304. this.isUploading = false;
  305. // 自动解析
  306. this.analyzeMaterial(materialFile);
  307. }, 1000);
  308. }
  309. // 文本提交
  310. onTextSubmit(): void {
  311. if (this.materialUploadForm.valid) {
  312. const formValue = this.materialUploadForm.value;
  313. const textMaterial: MaterialFile = {
  314. id: this.generateId(),
  315. name: '文本需求',
  316. type: 'text',
  317. content: formValue.textContent,
  318. uploadTime: new Date(),
  319. size: this.formatFileSize(formValue.textContent?.length || 0)
  320. };
  321. this.materialFiles.push(textMaterial);
  322. this.materials.push(textMaterial);
  323. this.analyzeMaterial(textMaterial);
  324. this.materialUploadForm.reset();
  325. }
  326. }
  327. // 素材解析功能
  328. private analyzeMaterial(material: MaterialFile) {
  329. this.isAnalyzing = true;
  330. // 模拟解析过程
  331. setTimeout(() => {
  332. let analysis: MaterialAnalysis = {};
  333. switch (material.type) {
  334. case 'text':
  335. analysis = this.analyzeTextMaterial(material);
  336. break;
  337. case 'image':
  338. analysis = this.analyzeImageMaterial(material);
  339. break;
  340. case 'cad':
  341. analysis = this.analyzeCADMaterial(material);
  342. break;
  343. }
  344. material.analysis = analysis;
  345. this.isAnalyzing = false;
  346. this.updateRequirementsFromAnalysis(analysis);
  347. }, 2000);
  348. }
  349. private analyzeTextMaterial(material: MaterialFile): MaterialAnalysis {
  350. return {
  351. atmosphere: {
  352. description: '温馨暖调',
  353. rgb: '255,230,180',
  354. colorTemp: '2700-3000K'
  355. },
  356. residents: {
  357. type: '亲子家庭',
  358. details: '孩子年龄3-6岁'
  359. },
  360. scenes: {
  361. preference: '瑜伽爱好者',
  362. requirements: '需要瑜伽区收纳'
  363. },
  364. keywords: {
  365. positive: ['科技感', '温馨', '实用'],
  366. negative: ['复杂线条', '冷色调']
  367. }
  368. };
  369. }
  370. private analyzeImageMaterial(material: MaterialFile): MaterialAnalysis {
  371. return {
  372. mainColors: [
  373. { rgb: '255,230,180', percentage: 45 },
  374. { rgb: '200,180,160', percentage: 30 },
  375. { rgb: '180,160,140', percentage: 25 }
  376. ],
  377. colorTemperature: '3000K',
  378. materialRatio: [
  379. { material: '木质', percentage: 60 },
  380. { material: '布艺', percentage: 25 },
  381. { material: '金属', percentage: 15 }
  382. ],
  383. spaceRatio: 35
  384. };
  385. }
  386. private analyzeCADMaterial(material: MaterialFile): MaterialAnalysis {
  387. return {
  388. structuralElements: [
  389. { type: '承重柱', position: '客厅中央', changeable: false },
  390. { type: '门窗', position: '南墙', changeable: false }
  391. ],
  392. spaceMetrics: [
  393. { room: '客厅', ratio: '16:9', width: '4.2m' },
  394. { room: '卧室', ratio: '4:3', width: '3.6m' }
  395. ],
  396. flowMetrics: [
  397. { area: '主通道', width: '1.2m', compliance: true },
  398. { area: '次通道', width: '0.8m', compliance: false }
  399. ]
  400. };
  401. }
  402. private updateRequirementsFromAnalysis(analysis: MaterialAnalysis) {
  403. if (analysis.atmosphere?.rgb) {
  404. const colorMetric = this.requirementMetrics.find(m => m.id === 'main-color');
  405. if (colorMetric) {
  406. const [r, g, b] = analysis.atmosphere.rgb.split(',').map(Number);
  407. colorMetric.value = { r, g, b };
  408. }
  409. }
  410. if (analysis.materialRatio) {
  411. const woodRatio = analysis.materialRatio.find(m => m.material === '木质');
  412. if (woodRatio) {
  413. const woodMetric = this.requirementMetrics.find(m => m.id === 'wood-ratio');
  414. if (woodMetric) {
  415. woodMetric.value = woodRatio.percentage;
  416. }
  417. }
  418. }
  419. }
  420. // 需求确认功能
  421. confirmRequirement(requirementId: string) {
  422. // 检查是否可以进行需求确认操作
  423. if (!this.canProceedToNextStage('materialAnalysis')) {
  424. alert('请先完成素材分析阶段的所有必要操作');
  425. return;
  426. }
  427. const requirement = this.requirementItems.find(r => r.id === requirementId);
  428. if (requirement) {
  429. requirement.status = 'confirmed';
  430. requirement.lastUpdated = new Date();
  431. this.requirementConfirmed.emit(requirement);
  432. this.updateProgress();
  433. this.triggerAutoSave();
  434. // 检查阶段完成状态
  435. this.checkStageCompletion();
  436. }
  437. }
  438. rejectRequirement(requirementId: string, reason?: string) {
  439. // 检查是否可以进行需求拒绝操作
  440. if (!this.canProceedToNextStage('materialAnalysis')) {
  441. alert('请先完成素材分析阶段的所有必要操作');
  442. return;
  443. }
  444. const requirement = this.requirementItems.find(r => r.id === requirementId);
  445. if (requirement) {
  446. requirement.status = 'rejected';
  447. requirement.lastUpdated = new Date();
  448. if (reason) {
  449. this.addCommentToRequirement(requirementId, reason, 'system');
  450. }
  451. this.updateProgress();
  452. this.triggerAutoSave();
  453. // 检查阶段完成状态
  454. this.checkStageCompletion();
  455. }
  456. }
  457. // 协作功能
  458. addComment() {
  459. if (this.commentForm.valid) {
  460. const comment: CollaborationComment = {
  461. id: this.generateId(),
  462. author: '当前用户',
  463. role: 'designer',
  464. content: this.commentForm.value.content,
  465. timestamp: new Date(),
  466. requirementId: this.commentForm.value.requirementId,
  467. status: 'pending'
  468. };
  469. this.collaborationComments.push(comment);
  470. this.commentForm.reset();
  471. this.triggerAutoSave();
  472. // 检查阶段完成状态
  473. this.checkStageCompletion();
  474. }
  475. }
  476. resolveComment(commentId: string) {
  477. const comment = this.collaborationComments.find(c => c.id === commentId);
  478. if (comment) {
  479. comment.status = 'resolved';
  480. this.triggerAutoSave();
  481. // 检查阶段完成状态
  482. this.checkStageCompletion();
  483. }
  484. }
  485. // 进度管理
  486. private updateProgress() {
  487. const totalRequirements = this.requirementItems.length;
  488. const confirmedRequirements = this.requirementItems.filter(r => r.status === 'confirmed').length;
  489. const progress = totalRequirements > 0 ? (confirmedRequirements / totalRequirements) * 100 : 0;
  490. // 实时更新进度条
  491. this.updateProgressBar(progress);
  492. this.progressUpdated.emit(progress);
  493. // 检查是否完成所有需求
  494. if (progress === 100) {
  495. this.onRequirementCommunicationComplete();
  496. }
  497. }
  498. private updateProgressBar(progress: number): void {
  499. // 更新进度条显示
  500. const progressBar = document.querySelector('.progress-bar-fill') as HTMLElement;
  501. if (progressBar) {
  502. progressBar.style.width = `${progress}%`;
  503. }
  504. // 更新进度文本
  505. const progressText = document.querySelector('.progress-text') as HTMLElement;
  506. if (progressText) {
  507. progressText.textContent = `${Math.round(progress)}%`;
  508. }
  509. // 添加进度动画效果
  510. this.animateProgressUpdate(progress);
  511. }
  512. private animateProgressUpdate(progress: number): void {
  513. // 添加进度更新的视觉反馈
  514. const progressContainer = document.querySelector('.progress-container') as HTMLElement;
  515. if (progressContainer) {
  516. progressContainer.classList.add('progress-updated');
  517. setTimeout(() => {
  518. progressContainer.classList.remove('progress-updated');
  519. }, 500);
  520. }
  521. }
  522. // 需求沟通阶段完成处理
  523. private onRequirementCommunicationComplete(): void {
  524. console.log('需求沟通阶段完成,开始同步关键信息');
  525. this.syncKeyInfoToSolutionConfirmation();
  526. }
  527. // 同步关键信息到方案确认阶段
  528. private syncKeyInfoToSolutionConfirmation(): void {
  529. const keyInfo = {
  530. colorAtmosphere: {
  531. mainColor: this.colorIndicators.mainColor,
  532. colorTemperature: this.colorIndicators.colorTemperature,
  533. saturation: this.colorIndicators.saturation,
  534. brightness: this.colorIndicators.brightness
  535. },
  536. spaceStructure: {
  537. lineRatio: this.spaceIndicators.lineRatio,
  538. blankRatio: this.spaceIndicators.blankRatio,
  539. flowWidth: this.spaceIndicators.flowWidth
  540. },
  541. materialWeights: {
  542. fabricRatio: this.materialIndicators.fabricRatio,
  543. woodRatio: this.materialIndicators.woodRatio,
  544. metalRatio: this.materialIndicators.metalRatio,
  545. smoothness: this.materialIndicators.smoothness
  546. },
  547. presetAtmosphere: this.getSelectedPresetAtmosphere()
  548. };
  549. // 触发同步事件
  550. this.requirementConfirmed.emit({
  551. id: 'requirement-sync',
  552. title: '需求沟通完成',
  553. description: '关键信息已同步至方案确认阶段',
  554. priority: 'high',
  555. status: 'confirmed',
  556. lastUpdated: new Date(),
  557. metrics: this.convertToMetrics(keyInfo)
  558. });
  559. // 启动交付执行流程
  560. setTimeout(() => {
  561. this.startDeliveryExecution();
  562. }, 1000);
  563. }
  564. private getSelectedPresetAtmosphere(): any {
  565. // 根据当前颜色指标找到最匹配的预设氛围
  566. const currentRgb = `${this.colorIndicators.mainColor.r},${this.colorIndicators.mainColor.g},${this.colorIndicators.mainColor.b}`;
  567. return this.presetAtmospheres.find(preset => preset.rgb === currentRgb) || this.presetAtmospheres[0];
  568. }
  569. private convertToMetrics(keyInfo: any): RequirementMetric[] {
  570. return [
  571. {
  572. id: 'color-sync',
  573. category: 'color',
  574. name: '色彩氛围',
  575. value: keyInfo.colorAtmosphere
  576. },
  577. {
  578. id: 'space-sync',
  579. category: 'space',
  580. name: '空间结构',
  581. value: keyInfo.spaceStructure
  582. },
  583. {
  584. id: 'material-sync',
  585. category: 'material',
  586. name: '材质权重',
  587. value: keyInfo.materialWeights
  588. }
  589. ];
  590. }
  591. // 启动交付执行流程
  592. private startDeliveryExecution(): void {
  593. console.log('启动交付执行流程');
  594. // 显示执行启动提示
  595. this.showExecutionStartNotification();
  596. // 这里可以触发路由跳转或其他业务逻辑
  597. // 例如:this.router.navigate(['/project', this.projectId, 'execution']);
  598. }
  599. private showExecutionStartNotification(): void {
  600. // 显示执行流程启动的通知
  601. const notification = document.createElement('div');
  602. notification.className = 'execution-notification';
  603. notification.innerHTML = `
  604. <div class="notification-content">
  605. <svg viewBox="0 0 24 24" fill="currentColor">
  606. <path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/>
  607. </svg>
  608. <span>交付执行流程已启动</span>
  609. </div>
  610. `;
  611. document.body.appendChild(notification);
  612. setTimeout(() => {
  613. notification.remove();
  614. }, 3000);
  615. }
  616. getProgressPercentage(): number {
  617. if (this.requirementItems.length === 0) return 0;
  618. const confirmedCount = this.requirementItems.filter(r => r.status === 'confirmed').length;
  619. return Math.round((confirmedCount / this.requirementItems.length) * 100);
  620. }
  621. // 处理优先级更新
  622. onPriorityChange(requirementId: string, event: Event): void {
  623. const target = event.target as HTMLSelectElement;
  624. this.updateRequirementPriority(requirementId, target.value as 'high' | 'medium' | 'low');
  625. }
  626. // 检查需求是否有待处理评论
  627. hasUnreadComments(requirementId: string): boolean {
  628. return this.getCommentsForRequirement(requirementId).some(c => c.status === 'pending');
  629. }
  630. // 处理历史状态选择
  631. onHistoryStateChange(event: Event): void {
  632. const target = event.target as HTMLSelectElement;
  633. const index = +target.value;
  634. if (index >= 0) {
  635. this.restoreHistoryState(index);
  636. }
  637. }
  638. // 获取指定状态的需求数量
  639. getRequirementCountByStatus(status: 'confirmed' | 'pending' | 'rejected'): number {
  640. return (this.requirementItems || []).filter(r => r.status === status).length;
  641. }
  642. // 获取状态百分比
  643. getStatusPercentage(status: 'confirmed' | 'pending' | 'rejected'): number {
  644. const total = this.requirementItems.length;
  645. if (total === 0) return 0;
  646. const statusCount = this.getRequirementCountByStatus(status);
  647. return Math.round((statusCount / total) * 100);
  648. }
  649. // 指标映射功能
  650. updateMetricValue(metricId: string, value: any) {
  651. const metric = this.requirementMetrics.find(m => m.id === metricId);
  652. if (metric) {
  653. metric.value = value;
  654. this.checkConsistency();
  655. }
  656. }
  657. // 滑动条数值同步方法
  658. onSliderChange(key: string, value: number): void {
  659. console.log(`滑动条变化: ${key} = ${value}`);
  660. console.log('变化前的mainColor:', JSON.stringify(this.colorIndicators.mainColor));
  661. // 直接更新数据,不需要额外的updateIndicatorValue调用
  662. // 因为使用了双向绑定,数据已经自动更新
  663. if (key === 'r' || key === 'g' || key === 'b') {
  664. // 确保RGB值在有效范围内
  665. const range = this.getIndicatorRange(key);
  666. if (range) {
  667. const clampedValue = Math.max(range.min, Math.min(range.max, value));
  668. this.colorIndicators.mainColor[key as keyof typeof this.colorIndicators.mainColor] = clampedValue;
  669. console.log(`RGB值已更新: ${key} = ${clampedValue}`);
  670. console.log('变化后的mainColor:', JSON.stringify(this.colorIndicators.mainColor));
  671. }
  672. // 触发颜色指标更新
  673. this.updateColorIndicator('mainColor', this.colorIndicators.mainColor);
  674. } else {
  675. // 处理其他颜色指标
  676. this.updateIndicatorValue(key, value);
  677. }
  678. this.triggerAutoSave(); // 触发自动保存
  679. this.checkStageCompletion(); // 检查阶段完成状态
  680. // 强制触发变更检测
  681. this.cdr.detectChanges();
  682. console.log('滑动条变更检测已触发');
  683. }
  684. onInputChange(key: string, value: number): void {
  685. console.log(`输入框变化: ${key} = ${value}`);
  686. console.log('变化前的mainColor:', JSON.stringify(this.colorIndicators.mainColor));
  687. // 直接更新数据,不需要额外的updateIndicatorValue调用
  688. // 因为使用了双向绑定,数据已经自动更新
  689. if (key === 'r' || key === 'g' || key === 'b') {
  690. // 确保RGB值在有效范围内
  691. const range = this.getIndicatorRange(key);
  692. if (range) {
  693. const clampedValue = Math.max(range.min, Math.min(range.max, value));
  694. this.colorIndicators.mainColor[key as keyof typeof this.colorIndicators.mainColor] = clampedValue;
  695. console.log(`RGB值已更新: ${key} = ${clampedValue}`);
  696. console.log('变化后的mainColor:', JSON.stringify(this.colorIndicators.mainColor));
  697. }
  698. // 触发颜色指标更新
  699. this.updateColorIndicator('mainColor', this.colorIndicators.mainColor);
  700. } else {
  701. // 处理其他颜色指标
  702. this.updateIndicatorValue(key, value);
  703. }
  704. this.triggerAutoSave();
  705. // 强制触发变更检测
  706. this.cdr.detectChanges();
  707. console.log('输入框变更检测已触发');
  708. }
  709. validateInput(key: string, value: string): void {
  710. const numValue = parseFloat(value);
  711. if (isNaN(numValue)) {
  712. // 如果输入无效,恢复原值
  713. this.restoreIndicatorValue(key);
  714. return;
  715. }
  716. const range = this.getIndicatorRange(key);
  717. if (range) {
  718. const clampedValue = Math.max(range.min, Math.min(range.max, numValue));
  719. this.updateIndicatorValue(key, clampedValue);
  720. }
  721. }
  722. private updateIndicatorValue(key: string, value: number): void {
  723. console.log(`updateIndicatorValue调用: ${key} = ${value}`);
  724. // 更新颜色指标
  725. if (key in this.colorIndicators) {
  726. if (key === 'r' || key === 'g' || key === 'b') {
  727. // 创建新的mainColor对象以确保变更检测
  728. const oldColor = { ...this.colorIndicators.mainColor };
  729. this.colorIndicators.mainColor = {
  730. ...this.colorIndicators.mainColor,
  731. [key]: value
  732. };
  733. console.log(`RGB更新: ${key}从${oldColor[key as keyof typeof oldColor]}变为${value}`,
  734. '新mainColor:', this.colorIndicators.mainColor);
  735. this.updateColorIndicator('mainColor', this.colorIndicators.mainColor);
  736. } else {
  737. (this.colorIndicators as any)[key] = value;
  738. this.updateColorIndicator(key, value);
  739. }
  740. return;
  741. }
  742. // 更新空间指标
  743. if (key in this.spaceIndicators) {
  744. (this.spaceIndicators as any)[key] = value;
  745. this.updateSpaceIndicator(key, value);
  746. return;
  747. }
  748. // 更新材质指标
  749. if (key in this.materialIndicators) {
  750. (this.materialIndicators as any)[key] = value;
  751. this.updateMaterialIndicator(key, value);
  752. return;
  753. }
  754. }
  755. private restoreIndicatorValue(key: string): void {
  756. // 这里可以从历史状态或默认值恢复
  757. console.log(`恢复指标值: ${key}`);
  758. }
  759. private getIndicatorRange(key: string): { min: number; max: number } | null {
  760. // 检查颜色范围
  761. if (key === 'r' || key === 'g' || key === 'b') {
  762. return this.indicatorRanges.color[key as keyof typeof this.indicatorRanges.color];
  763. }
  764. if (key in this.indicatorRanges.color) {
  765. return (this.indicatorRanges.color as any)[key];
  766. }
  767. // 检查空间范围
  768. if (key in this.indicatorRanges.space) {
  769. return (this.indicatorRanges.space as any)[key];
  770. }
  771. // 检查材质范围
  772. if (key in this.indicatorRanges.material) {
  773. return (this.indicatorRanges.material as any)[key];
  774. }
  775. return null;
  776. }
  777. // 指标更新方法
  778. updateColorIndicator(type: string, value?: any): void {
  779. switch (type) {
  780. case 'mainColor':
  781. if (value && typeof value === 'object' && 'r' in value) {
  782. this.colorIndicators.mainColor = { ...value }; // 创建新对象以触发变更检测
  783. console.log('mainColor更新后:', this.colorIndicators.mainColor);
  784. }
  785. break;
  786. case 'colorTemperature':
  787. // 色温更新时不需要改变颜色值,只是触发一致性检查
  788. break;
  789. case 'saturation':
  790. // 饱和度更新时不需要改变颜色值,只是触发一致性检查
  791. break;
  792. }
  793. console.log(`更新颜色指示器 ${type}:`, value, '当前RGB:', this.getRgbString());
  794. this.checkConsistency();
  795. this.updatePreview();
  796. // 强制触发变更检测
  797. this.cdr.detectChanges();
  798. console.log('变更检测已触发');
  799. }
  800. updateSpaceIndicator(key: string, value: number) {
  801. if (key in this.spaceIndicators) {
  802. (this.spaceIndicators as any)[key] = value;
  803. this.checkConsistency();
  804. }
  805. }
  806. updateMaterialIndicator(key: string, value: number) {
  807. if (key in this.materialIndicators) {
  808. (this.materialIndicators as any)[key] = value;
  809. this.checkConsistency();
  810. this.normalizeMaterialRatios();
  811. }
  812. }
  813. // 材质比例归一化
  814. private normalizeMaterialRatios() {
  815. const total = this.materialIndicators.fabricRatio +
  816. this.materialIndicators.woodRatio +
  817. this.materialIndicators.metalRatio;
  818. if (total > 100) {
  819. const scale = 100 / total;
  820. this.materialIndicators.fabricRatio = Math.round(this.materialIndicators.fabricRatio * scale);
  821. this.materialIndicators.woodRatio = Math.round(this.materialIndicators.woodRatio * scale);
  822. this.materialIndicators.metalRatio = 100 - this.materialIndicators.fabricRatio - this.materialIndicators.woodRatio;
  823. }
  824. }
  825. // 预览更新
  826. private updatePreview() {
  827. // 移除直接DOM操作,依赖Angular的属性绑定
  828. console.log('updatePreview调用,当前RGB:', this.getRgbString());
  829. // 不再直接操作DOM,让Angular的变更检测处理
  830. }
  831. // 获取RGB字符串
  832. getRgbString(): string {
  833. const { r, g, b } = this.colorIndicators.mainColor;
  834. const rgbString = `rgb(${r}, ${g}, ${b})`;
  835. console.log('getRgbString调用:', rgbString, '完整mainColor对象:', this.colorIndicators.mainColor);
  836. return rgbString;
  837. }
  838. // 获取色温描述
  839. getColorTemperatureDescription(): string {
  840. const temp = this.colorIndicators.colorTemperature;
  841. if (temp < 3000) return '暖色调';
  842. if (temp < 4000) return '中性色调';
  843. if (temp < 5000) return '自然色调';
  844. return '冷色调';
  845. }
  846. applyPresetAtmosphere(preset: any) {
  847. const rgbMatch = preset.rgb.match(/(\d+),(\d+),(\d+)/);
  848. if (rgbMatch) {
  849. this.colorIndicators.mainColor = {
  850. r: parseInt(rgbMatch[1]),
  851. g: parseInt(rgbMatch[2]),
  852. b: parseInt(rgbMatch[3])
  853. };
  854. }
  855. const tempMatch = preset.colorTemp.match(/(\d+)/);
  856. if (tempMatch) {
  857. this.colorIndicators.colorTemperature = parseInt(tempMatch[1]);
  858. }
  859. if (preset.materials.includes('木质')) {
  860. this.materialIndicators.woodRatio = 60;
  861. this.materialIndicators.fabricRatio = 30;
  862. this.materialIndicators.metalRatio = 10;
  863. } else if (preset.materials.includes('金属')) {
  864. this.materialIndicators.metalRatio = 50;
  865. this.materialIndicators.woodRatio = 20;
  866. this.materialIndicators.fabricRatio = 30;
  867. }
  868. this.updatePreview();
  869. this.checkConsistency();
  870. }
  871. // 一致性检查
  872. private checkConsistency() {
  873. this.consistencyWarnings = [];
  874. if (this.colorIndicators.colorTemperature < 3000 &&
  875. this.colorIndicators.mainColor.r > 200 &&
  876. this.colorIndicators.mainColor.g < 150) {
  877. this.consistencyWarnings.push('暖调氛围与冷色调RGB值存在矛盾');
  878. }
  879. if (this.materialIndicators.fabricRatio > 70 && this.colorIndicators.colorTemperature > 5000) {
  880. this.consistencyWarnings.push('高布艺占比与冷色调可能不协调');
  881. }
  882. if (this.spaceIndicators.lineRatio > 80 && this.materialIndicators.woodRatio > 60) {
  883. this.consistencyWarnings.push('高直线条占比与高木质占比可能过于刚硬');
  884. }
  885. }
  886. // 协作批注功能
  887. addCommentToRequirement(requirementId: string, content: string, author: string = '当前用户'): void {
  888. const comment: CollaborationComment = {
  889. id: this.generateId(),
  890. author,
  891. role: 'designer',
  892. content,
  893. timestamp: new Date(),
  894. requirementId,
  895. status: 'pending'
  896. };
  897. this.collaborationComments.push(comment);
  898. this.updateProgress();
  899. }
  900. // 优先级排序功能
  901. updateRequirementPriority(requirementId: string, priority: 'high' | 'medium' | 'low'): void {
  902. const requirement = this.requirementItems.find(r => r.id === requirementId);
  903. if (requirement) {
  904. requirement.priority = priority;
  905. requirement.lastUpdated = new Date();
  906. this.sortRequirementsByPriority();
  907. }
  908. }
  909. sortRequirementsByPriority(): void {
  910. const priorityOrder = { 'high': 3, 'medium': 2, 'low': 1 };
  911. this.requirementItems.sort((a, b) => {
  912. return priorityOrder[b.priority] - priorityOrder[a.priority];
  913. });
  914. }
  915. // 历史记录功能
  916. saveCurrentState(): void {
  917. const currentState = {
  918. timestamp: new Date(),
  919. colorIndicators: { ...this.colorIndicators },
  920. spaceIndicators: { ...this.spaceIndicators },
  921. materialIndicators: { ...this.materialIndicators },
  922. requirementItems: this.requirementItems.map((r: RequirementItem) => ({ ...r })),
  923. author: '当前用户'
  924. };
  925. this.historyStates.push(currentState);
  926. if (this.historyStates.length > 10) {
  927. this.historyStates.shift();
  928. }
  929. }
  930. restoreHistoryState(index: number): void {
  931. if (index >= 0 && index < this.historyStates.length) {
  932. const state = this.historyStates[index];
  933. this.colorIndicators = { ...state.colorIndicators };
  934. this.spaceIndicators = { ...state.spaceIndicators };
  935. this.materialIndicators = { ...state.materialIndicators };
  936. this.requirementItems = state.requirementItems.map((r: RequirementItem) => ({ ...r }));
  937. this.updatePreview();
  938. this.checkConsistency();
  939. }
  940. }
  941. // 获取未解决的评论数量
  942. getUnresolvedCommentsCount(): number {
  943. return this.collaborationComments.filter(c => c.status === 'pending').length;
  944. }
  945. // 获取需求的评论
  946. getCommentsForRequirement(requirementId: string): CollaborationComment[] {
  947. return this.collaborationComments.filter(comment => comment.requirementId === requirementId) || [];
  948. }
  949. // 获取状态样式类
  950. getStatusClass(status: string): string {
  951. return status;
  952. }
  953. // 工具方法
  954. private generateId(): string {
  955. return Math.random().toString(36).substr(2, 9);
  956. }
  957. private formatFileSize(bytes: number): string {
  958. if (bytes === 0) return '0 Bytes';
  959. const k = 1024;
  960. const sizes = ['Bytes', 'KB', 'MB', 'GB'];
  961. const i = Math.floor(Math.log(bytes) / Math.log(k));
  962. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  963. }
  964. // 删除素材
  965. removeMaterial(materialId: string) {
  966. const index = this.materialFiles.findIndex(m => m.id === materialId);
  967. if (index > -1) {
  968. const material = this.materialFiles[index];
  969. if (material.url) {
  970. URL.revokeObjectURL(material.url);
  971. }
  972. this.materialFiles.splice(index, 1);
  973. }
  974. const materialsIndex = this.materials.findIndex(m => m.id === materialId);
  975. if (materialsIndex > -1) {
  976. this.materials.splice(materialsIndex, 1);
  977. }
  978. }
  979. // 切换标签页
  980. switchTab(tab: 'materials' | 'mapping' | 'collaboration' | 'progress') {
  981. this.activeTab = tab;
  982. }
  983. // 获取需求状态文本
  984. getRequirementStatusText(status: string): string {
  985. const statusMap: { [key: string]: string } = {
  986. 'pending': '待确认',
  987. 'confirmed': '已确认',
  988. 'rejected': '已拒绝'
  989. };
  990. return statusMap[status] || status;
  991. }
  992. // 获取优先级文本
  993. getPriorityText(priority: string): string {
  994. const priorityMap: { [key: string]: string } = {
  995. 'high': '高',
  996. 'medium': '中',
  997. 'low': '低'
  998. };
  999. return priorityMap[priority] || priority;
  1000. }
  1001. // 刷新进度(保留用于手动刷新,但不再强制要求)
  1002. refreshProgress(): void {
  1003. // 重新计算进度
  1004. this.updateProgress();
  1005. // 更新进度条显示
  1006. const progress = this.getProgressPercentage();
  1007. this.updateProgressBar(progress);
  1008. // 检查阶段完成状态
  1009. this.checkStageCompletion();
  1010. // 触发进度更新事件
  1011. this.progressUpdated.emit(progress);
  1012. console.log('进度已手动刷新:', progress + '%');
  1013. }
  1014. // 自动保存功能
  1015. private triggerAutoSave(): void {
  1016. if (!this.autoSaveEnabled) return;
  1017. this.hasUnsavedChanges = true;
  1018. this.saveStatus = 'unsaved';
  1019. // 清除之前的定时器
  1020. if (this.autoSaveTimer) {
  1021. clearTimeout(this.autoSaveTimer);
  1022. }
  1023. // 设置新的自动保存定时器(延迟1秒)
  1024. this.autoSaveTimer = setTimeout(() => {
  1025. this.performAutoSave();
  1026. }, 1000);
  1027. }
  1028. private async performAutoSave(): Promise<void> {
  1029. if (this.isSaving) return;
  1030. this.isSaving = true;
  1031. this.saveStatus = 'saving';
  1032. try {
  1033. // 收集所有需要保存的数据
  1034. const saveData = this.collectSaveData();
  1035. // 模拟保存操作(实际项目中这里会调用API)
  1036. await this.saveToServer(saveData);
  1037. this.hasUnsavedChanges = false;
  1038. this.saveStatus = 'saved';
  1039. this.lastSaveTime = new Date();
  1040. console.log('自动保存成功:', new Date().toLocaleTimeString());
  1041. } catch (error) {
  1042. this.saveStatus = 'error';
  1043. console.error('自动保存失败:', error);
  1044. } finally {
  1045. this.isSaving = false;
  1046. }
  1047. }
  1048. // 手动保存
  1049. async manualSave(): Promise<void> {
  1050. if (this.isSaving) return;
  1051. // 清除自动保存定时器
  1052. if (this.autoSaveTimer) {
  1053. clearTimeout(this.autoSaveTimer);
  1054. }
  1055. await this.performAutoSave();
  1056. }
  1057. private collectSaveData(): any {
  1058. return {
  1059. projectId: this.projectId,
  1060. colorIndicators: this.colorIndicators,
  1061. spaceIndicators: this.spaceIndicators,
  1062. materialIndicators: this.materialIndicators,
  1063. requirementItems: this.requirementItems,
  1064. requirementMetrics: this.requirementMetrics,
  1065. materialFiles: this.materialFiles,
  1066. collaborationComments: this.collaborationComments,
  1067. stageCompletionStatus: this.stageCompletionStatus,
  1068. lastUpdated: new Date()
  1069. };
  1070. }
  1071. private async saveToServer(data: any): Promise<void> {
  1072. // 模拟API调用延迟
  1073. return new Promise((resolve, reject) => {
  1074. setTimeout(() => {
  1075. // 模拟90%成功率
  1076. if (Math.random() > 0.1) {
  1077. resolve();
  1078. } else {
  1079. reject(new Error('网络错误'));
  1080. }
  1081. }, 500);
  1082. });
  1083. }
  1084. // 检查阶段完成状态
  1085. private checkStageCompletion(): void {
  1086. // 检查素材分析阶段 - 需要有素材文件且都已分析
  1087. this.stageCompletionStatus.materialAnalysis = this.materialFiles.length > 0 &&
  1088. this.materialFiles.every(m => m.analysis);
  1089. // 检查需求映射阶段 - 需要有确认的需求项,或者滑动条数据已调整且保存
  1090. const hasConfirmedRequirements = this.requirementItems.length > 0 &&
  1091. this.requirementItems.some(r => r.status === 'confirmed');
  1092. const hasAdjustedIndicators = this.hasIndicatorChanges();
  1093. this.stageCompletionStatus.requirementMapping = hasConfirmedRequirements ||
  1094. (hasAdjustedIndicators && this.saveStatus === 'saved');
  1095. // 检查协作验证阶段 - 需要有协作评论或需求评论
  1096. this.stageCompletionStatus.collaboration = this.collaborationComments.length > 0 ||
  1097. this.requirementItems.some(r => r.comments && r.comments.length > 0);
  1098. // 检查进度审查阶段 - 需要进度达到80%以上
  1099. this.stageCompletionStatus.progressReview = this.getProgressPercentage() >= 80;
  1100. console.log('阶段完成状态更新:', this.stageCompletionStatus);
  1101. }
  1102. // 检查指示器是否有变化
  1103. private hasIndicatorChanges(): boolean {
  1104. // 检查颜色指示器是否有变化(与默认值比较)
  1105. const defaultColorIndicators = {
  1106. mainColor: { r: 255, g: 230, b: 180 },
  1107. colorTemperature: 2700,
  1108. colorRange: '暖色调',
  1109. saturation: 70,
  1110. brightness: 80,
  1111. contrast: 60
  1112. };
  1113. const defaultSpaceIndicators = {
  1114. lineRatio: 60,
  1115. blankRatio: 30,
  1116. flowWidth: 0.9,
  1117. aspectRatio: 1.6,
  1118. ceilingHeight: 2.8,
  1119. lightingLevel: 300
  1120. };
  1121. const defaultMaterialIndicators = {
  1122. fabricRatio: 50,
  1123. woodRatio: 30,
  1124. metalRatio: 20,
  1125. smoothness: 7,
  1126. glossiness: 4,
  1127. texture: 6
  1128. };
  1129. // 检查颜色指示器变化
  1130. const colorChanged = JSON.stringify(this.colorIndicators) !== JSON.stringify(defaultColorIndicators);
  1131. // 检查空间指示器变化
  1132. const spaceChanged = JSON.stringify(this.spaceIndicators) !== JSON.stringify(defaultSpaceIndicators);
  1133. // 检查材质指示器变化
  1134. const materialChanged = JSON.stringify(this.materialIndicators) !== JSON.stringify(defaultMaterialIndicators);
  1135. return colorChanged || spaceChanged || materialChanged;
  1136. }
  1137. // 获取阶段状态文本
  1138. getStageStatusText(stage: keyof typeof this.stageCompletionStatus): string {
  1139. if (this.stageCompletionStatus[stage]) {
  1140. return '已完成';
  1141. } else {
  1142. // 检查是否为未开始状态
  1143. const stages = ['materialAnalysis', 'requirementMapping', 'collaboration', 'progressReview'];
  1144. const currentIndex = stages.indexOf(stage);
  1145. // 检查前面的阶段是否都已完成
  1146. let allPreviousCompleted = true;
  1147. for (let i = 0; i < currentIndex; i++) {
  1148. if (!this.stageCompletionStatus[stages[i] as keyof typeof this.stageCompletionStatus]) {
  1149. allPreviousCompleted = false;
  1150. break;
  1151. }
  1152. }
  1153. return allPreviousCompleted ? '进行中' : '未进行';
  1154. }
  1155. }
  1156. // 获取阶段状态类名
  1157. getStageStatusClass(stage: keyof typeof this.stageCompletionStatus): string {
  1158. if (this.stageCompletionStatus[stage]) {
  1159. return 'stage-completed';
  1160. } else {
  1161. // 检查是否为未开始状态
  1162. const stages = ['materialAnalysis', 'requirementMapping', 'collaboration', 'progressReview'];
  1163. const currentIndex = stages.indexOf(stage);
  1164. // 检查前面的阶段是否都已完成
  1165. let allPreviousCompleted = true;
  1166. for (let i = 0; i < currentIndex; i++) {
  1167. if (!this.stageCompletionStatus[stages[i] as keyof typeof this.stageCompletionStatus]) {
  1168. allPreviousCompleted = false;
  1169. break;
  1170. }
  1171. }
  1172. return allPreviousCompleted ? 'stage-in-progress' : 'stage-pending';
  1173. }
  1174. }
  1175. // 检查是否可以进入下一阶段
  1176. canProceedToNextStage(currentStage: keyof typeof this.stageCompletionStatus): boolean {
  1177. const stages = Object.keys(this.stageCompletionStatus) as (keyof typeof this.stageCompletionStatus)[];
  1178. const currentIndex = stages.indexOf(currentStage);
  1179. // 检查当前阶段之前的所有阶段是否都已完成
  1180. for (let i = 0; i <= currentIndex; i++) {
  1181. if (!this.stageCompletionStatus[stages[i]]) {
  1182. return false;
  1183. }
  1184. }
  1185. return true;
  1186. }
  1187. // 获取保存状态文本
  1188. getSaveStatusText(): string {
  1189. switch (this.saveStatus) {
  1190. case 'saved': return this.lastSaveTime ? `已保存 ${this.lastSaveTime.toLocaleTimeString()}` : '已保存';
  1191. case 'saving': return '保存中...';
  1192. case 'error': return '保存失败';
  1193. case 'unsaved': return '有未保存的更改';
  1194. default: return '';
  1195. }
  1196. }
  1197. // 获取保存状态图标
  1198. getSaveStatusIcon(): string {
  1199. switch (this.saveStatus) {
  1200. case 'saved': return '✓';
  1201. case 'saving': return '⟳';
  1202. case 'error': return '⚠';
  1203. case 'unsaved': return '●';
  1204. default: return '';
  1205. }
  1206. }
  1207. }