124 lines
2.4 KiB
TypeScript
124 lines
2.4 KiB
TypeScript
import type {
|
|
CustomerLevel,
|
|
ServiceMode,
|
|
} from "@/lib/types/backend";
|
|
import type { LibraryItemVM } from "@/lib/types/view-models";
|
|
|
|
export type ResourcePickerOption = LibraryItemVM & {
|
|
backendId: number;
|
|
};
|
|
|
|
export type ModelPickerOption = ResourcePickerOption & {
|
|
poseId?: number | null;
|
|
};
|
|
|
|
type ResourceBinding = {
|
|
backendId: number;
|
|
poseId?: number;
|
|
};
|
|
|
|
const RESOURCE_BINDINGS: Record<string, ResourceBinding> = {
|
|
"model-ava": {
|
|
backendId: 101,
|
|
poseId: 202,
|
|
},
|
|
"model-jian": {
|
|
backendId: 102,
|
|
poseId: 203,
|
|
},
|
|
"scene-loft": {
|
|
backendId: 404,
|
|
},
|
|
"scene-garden": {
|
|
backendId: 405,
|
|
},
|
|
"garment-coat-01": {
|
|
backendId: 303,
|
|
},
|
|
"garment-dress-03": {
|
|
backendId: 304,
|
|
},
|
|
};
|
|
|
|
export const CUSTOMER_LEVEL_LABELS: Record<CustomerLevel, string> = {
|
|
low: "低客单",
|
|
mid: "中客单",
|
|
};
|
|
|
|
export const SERVICE_MODE_LABELS: Record<ServiceMode, string> = {
|
|
auto_basic: "自动基础处理",
|
|
semi_pro: "半人工专业处理",
|
|
};
|
|
|
|
export const SERVICE_MODE_BY_CUSTOMER_LEVEL: Record<CustomerLevel, ServiceMode> =
|
|
{
|
|
low: "auto_basic",
|
|
mid: "semi_pro",
|
|
};
|
|
|
|
function getResourceBinding(resourceId: string) {
|
|
return RESOURCE_BINDINGS[resourceId] ?? null;
|
|
}
|
|
|
|
export function getServiceModeForCustomerLevel(
|
|
customerLevel: CustomerLevel,
|
|
): ServiceMode {
|
|
return SERVICE_MODE_BY_CUSTOMER_LEVEL[customerLevel];
|
|
}
|
|
|
|
export function mapModelOptions(items: LibraryItemVM[]): ModelPickerOption[] {
|
|
return items.flatMap((item) => {
|
|
if (typeof item.backendId === "number") {
|
|
return [
|
|
{
|
|
...item,
|
|
backendId: item.backendId,
|
|
poseId: item.poseId ?? null,
|
|
},
|
|
];
|
|
}
|
|
|
|
const binding = getResourceBinding(item.id);
|
|
|
|
if (!binding) {
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
{
|
|
...item,
|
|
backendId: binding.backendId,
|
|
poseId: binding.poseId ?? null,
|
|
},
|
|
];
|
|
});
|
|
}
|
|
|
|
export function mapResourceOptions(
|
|
items: LibraryItemVM[],
|
|
): ResourcePickerOption[] {
|
|
return items.flatMap((item) => {
|
|
if (typeof item.backendId === "number") {
|
|
return [
|
|
{
|
|
...item,
|
|
backendId: item.backendId,
|
|
},
|
|
];
|
|
}
|
|
|
|
const binding = getResourceBinding(item.id);
|
|
|
|
if (!binding) {
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
{
|
|
...item,
|
|
backendId: binding.backendId,
|
|
},
|
|
];
|
|
});
|
|
}
|