|
@@ -1,4 +1,3 @@
|
|
|
-// page-design.component.ts
|
|
|
import { Component, ChangeDetectorRef } from '@angular/core';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
import { CommonModule } from '@angular/common';
|
|
@@ -47,7 +46,7 @@ export class PageDesignComponent {
|
|
|
|
|
|
colorUsage: ColorUsage = new ColorUsage();
|
|
|
|
|
|
- // 新增的AI助手相关变量
|
|
|
+ // 新增的AI助手相关变量(完全保持不变)
|
|
|
aiMessages: { text: string | SafeHtml; isUser: boolean; isLoading?: boolean; isTrend?: boolean }[] = [
|
|
|
{ text: '您好!我是您的羽绒服设计助手。我可以根据您的喜好推荐颜色搭配,或者帮您分析当前设计的流行度。有什么我可以帮您的吗?', isUser: false }
|
|
|
];
|
|
@@ -101,7 +100,7 @@ export class PageDesignComponent {
|
|
|
private sanitizer: DomSanitizer
|
|
|
) {}
|
|
|
|
|
|
- // 原有设计界面的方法(保持不变)
|
|
|
+ // 原有设计界面的方法(仅修改颜色处理部分)
|
|
|
selectPart(part: string) {
|
|
|
this.activePart = part;
|
|
|
}
|
|
@@ -134,25 +133,35 @@ export class PageDesignComponent {
|
|
|
}
|
|
|
|
|
|
private darkenColor(color: string, percent: number): string {
|
|
|
- const num = parseInt(color.replace('#', ''), 16);
|
|
|
- const amt = Math.round(2.55 * percent);
|
|
|
- const R = (num >> 16) - amt;
|
|
|
- const G = (num >> 8 & 0x00FF) - amt;
|
|
|
- const B = (num & 0x0000FF) - amt;
|
|
|
+ // 更健壮的颜色变暗算法
|
|
|
+ const hex = color.replace('#', '');
|
|
|
|
|
|
- return '#' + (
|
|
|
- 0x1000000 +
|
|
|
- (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 +
|
|
|
- (G < 255 ? G < 1 ? 0 : G : 255) * 0x100 +
|
|
|
- (B < 255 ? B < 1 ? 0 : B : 255)
|
|
|
- ).toString(16).slice(1);
|
|
|
+ // 处理3位HEX格式
|
|
|
+ const fullHex = hex.length === 3
|
|
|
+ ? hex.split('').map(c => c + c).join('')
|
|
|
+ : hex.padEnd(6, '0').substring(0, 6);
|
|
|
+
|
|
|
+ // 解析RGB分量
|
|
|
+ const r = Math.max(0, Math.min(255, parseInt(fullHex.substring(0, 2), 16)));
|
|
|
+ const g = Math.max(0, Math.min(255, parseInt(fullHex.substring(2, 4), 16)));
|
|
|
+ const b = Math.max(0, Math.min(255, parseInt(fullHex.substring(4, 6), 16)));
|
|
|
+
|
|
|
+ // 计算变暗值
|
|
|
+ const amount = Math.round(2.55 * percent);
|
|
|
+ const newR = Math.max(0, r - amount);
|
|
|
+ const newG = Math.max(0, g - amount);
|
|
|
+ const newB = Math.max(0, b - amount);
|
|
|
+
|
|
|
+ // 转换回HEX
|
|
|
+ const toHex = (c: number) => c.toString(16).padStart(2, '0');
|
|
|
+ return `#${toHex(newR)}${toHex(newG)}${toHex(newB)}`;
|
|
|
}
|
|
|
|
|
|
getColorUsage(): { [key: string]: number } {
|
|
|
return this.colorUsage.getAll();
|
|
|
}
|
|
|
|
|
|
- // 新增的AI助手方法
|
|
|
+ // 新增的AI助手方法(完全保持不变)
|
|
|
toggleAIModal() {
|
|
|
this.showAIModal = !this.showAIModal;
|
|
|
if (this.showAIModal) {
|