Merge remote-tracking branch 'origin/feature/v1.2灵机空间-内容上传审核_rxd' into test

# Conflicts:
#	pnpm-lock.yaml
#	src/components/text-over-tips/index.vue
#	src/layouts/Basic.vue
#	src/main.ts
#	src/router/constants.ts
#	src/router/typeings.d.ts
#	src/utils/tools.ts
#	vite.config.ts
This commit is contained in:
rd
2025-08-14 15:27:10 +08:00
13 changed files with 76 additions and 71 deletions

View File

@ -397,7 +397,7 @@ export function getImageMainColor(imageUrl: string): Promise<string> {
const avgColor = {
r: Math.round(maxGroup.sumR / maxGroup.count),
g: Math.round(maxGroup.sumG / maxGroup.count),
b: Math.round(maxGroup.sumB / maxGroup.count),
b: Math.round(maxGroup.sumB / maxGroup.count)
};
resolve(`rgb(${avgColor.r},${avgColor.g},${avgColor.b})`);
@ -427,38 +427,28 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
if (a < 128) continue;
colors.push({
r,
g,
b,
r, g, b,
count: 1,
sumR: r,
sumG: g,
sumB: b,
sumR: r, sumG: g, sumB: b
});
}
// 如果没有颜色数据,返回默认白色
if (colors.length === 0) {
return [
{
count: 1,
sumR: 255,
sumG: 255,
sumB: 255,
},
];
return [{
count: 1,
sumR: 255, sumG: 255, sumB: 255
}];
}
// 开始中位数切分
let colorGroups = [
{
colors,
count: colors.length,
sumR: colors.reduce((sum, c) => sum + c.r, 0),
sumG: colors.reduce((sum, c) => sum + c.g, 0),
sumB: colors.reduce((sum, c) => sum + c.b, 0),
},
];
let colorGroups = [{
colors,
count: colors.length,
sumR: colors.reduce((sum, c) => sum + c.r, 0),
sumG: colors.reduce((sum, c) => sum + c.g, 0),
sumB: colors.reduce((sum, c) => sum + c.b, 0)
}];
for (let i = 0; i < levels; i++) {
const newGroups = [];
@ -470,12 +460,12 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
}
// 找出颜色范围最大的通道
const rMin = Math.min(...group.colors.map((c) => c.r));
const rMax = Math.max(...group.colors.map((c) => c.r));
const gMin = Math.min(...group.colors.map((c) => c.g));
const gMax = Math.max(...group.colors.map((c) => c.g));
const bMin = Math.min(...group.colors.map((c) => c.b));
const bMax = Math.max(...group.colors.map((c) => c.b));
const rMin = Math.min(...group.colors.map(c => c.r));
const rMax = Math.max(...group.colors.map(c => c.r));
const gMin = Math.min(...group.colors.map(c => c.g));
const gMax = Math.max(...group.colors.map(c => c.g));
const bMin = Math.min(...group.colors.map(c => c.b));
const bMax = Math.max(...group.colors.map(c => c.b));
const rRange = rMax - rMin;
const gRange = gMax - gMin;
@ -489,9 +479,15 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
}
// 按最大范围通道排序
type ColorChannel = 'r' | 'g' | 'b';
const safeSortChannel = sortChannel as ColorChannel;
group.colors.sort((a, b) => a[safeSortChannel] - b[safeSortChannel]);
group.colors.sort((a, b) => {
if (sortChannel === 'r') {
return a.r - b.r;
} else if (sortChannel === 'g') {
return a.g - b.g;
} else {
return a.b - b.b;
}
});
// 切分中位数
const mid = Math.floor(group.colors.length / 2);
@ -504,7 +500,7 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
count: group1.length,
sumR: group1.reduce((sum, c) => sum + c.r, 0),
sumG: group1.reduce((sum, c) => sum + c.g, 0),
sumB: group1.reduce((sum, c) => sum + c.b, 0),
sumB: group1.reduce((sum, c) => sum + c.b, 0)
});
newGroups.push({
@ -512,7 +508,7 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
count: group2.length,
sumR: group2.reduce((sum, c) => sum + c.r, 0),
sumG: group2.reduce((sum, c) => sum + c.g, 0),
sumB: group2.reduce((sum, c) => sum + c.b, 0),
sumB: group2.reduce((sum, c) => sum + c.b, 0)
});
}