topfans/frontend/utils/castloveMintForm.js

156 lines
4.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** 铸爱 — 与网关 CreateMintOrderRequestDTO 对齐的本地表单快照(见 gateway/dto/asset_dto.go */
export const CRAFT_LENTICULAR_CN = '光栅卡'
/** 工艺名:与 craft-select 卡片「镭射卡」一致 */
export const CRAFT_LASER_CARD_CN = '镭射卡'
/** 铸爱大类标签(星卡 / 吧唧 / 海报) */
export const CAST_TAG_STAR_CARD = 'cast:star_card'
export const CAST_TAG_BADGE = 'cast:badge'
export const CAST_TAG_POSTER = 'cast:poster'
/** 工艺标签:写入 tags[],便于检索与后端扩展 */
export const CRAFT_TAG_LENTICULAR = 'craft:lenticular'
export const CRAFT_TAG_LASER = 'craft:laser'
/** @param {string} pageName */
export function buildCraftTags(pageName) {
const name = (pageName || '').trim()
const tags = []
if (name === CRAFT_LENTICULAR_CN || name === CRAFT_LASER_CARD_CN) {
tags.push(CAST_TAG_STAR_CARD)
}
if (name === CRAFT_LENTICULAR_CN) tags.push(CRAFT_TAG_LENTICULAR)
if (name === CRAFT_LASER_CARD_CN) tags.push(CRAFT_TAG_LASER)
return tags
}
const defaultBgBase =
'radial-gradient(ellipse at 50% 40%, #1a0a3b 0%, #0a0418 55%, #000 100%)'
const defaultBgMid =
'radial-gradient(ellipse 38% 28% at 50% 45%, rgba(255,212,255,0.9) 0%, rgba(183,109,255,0.55) 50%, rgba(26,10,59,0) 100%)'
export function defaultLenticularDots() {
return [
{ x: 18, y: 22, r: 1.4 },
{ x: 78, y: 30, r: 1.6 },
{ x: 28, y: 72, r: 1.3 },
{ x: 86, y: 78, r: 1.2 },
{ x: 58, y: 12, r: 1.1 },
{ x: 8, y: 50, r: 1.0 },
{ x: 92, y: 50, r: 1.2 },
{ x: 50, y: 88, r: 1.1 },
]
}
/** 光栅卡流程lenticular-create / thinking 写入的 bg+subject 预览载荷(见 persistLenticularPreviewMeta */
export const LENTICULAR_STUDIO_STORAGE_KEY = 'lenticular_studio_payload'
/** 单图工艺create → 镭射工坊Laser-Card 页)入口载荷 */
/**
* 仅背景 + 主体两图层无高光层与铸爱光栅预览result 等)一致
* @param {string} bgSrc 背景图本地路径或 URL
* @param {string} subjectSrc 主体图本地路径或 URL
*/
export function buildLenticularLayersTwo(bgSrc, subjectSrc) {
return [
{
id: 'base',
label: '背景',
depth: 0,
opacity: 1,
blendMode: 'normal',
parallaxFactor: 0.35,
background: bgSrc ? undefined : defaultBgBase,
dots: bgSrc ? undefined : defaultLenticularDots(),
src: bgSrc || undefined,
},
{
id: 'mid',
label: '主体',
depth: 0.55,
opacity: 0.92,
blendMode: 'screen',
parallaxFactor: 0.7,
background: subjectSrc ? undefined : defaultBgMid,
src: subjectSrc || undefined,
},
]
}
/** 兼容旧预览:单图仅贴在主体层,仍带高光层 */
export function buildLenticularLayers(uploadSrc) {
const mid = {
id: 'mid',
label: '主体',
depth: 0.55,
opacity: 0.92,
blendMode: 'screen',
parallaxFactor: 0.7,
background: uploadSrc ? undefined : defaultBgMid,
src: uploadSrc || undefined,
}
return [
{
id: 'base',
label: '背景',
depth: 0.0,
opacity: 1,
blendMode: 'normal',
parallaxFactor: 0.35,
background: defaultBgBase,
dots: defaultLenticularDots(),
},
mid,
{
id: 'fx',
label: '高光',
depth: 0.9,
opacity: 0.85,
blendMode: 'lighten',
parallaxFactor: 1.15,
background: 'transparent',
dots: [
{ x: 20, y: 16, r: 3, color: '#ffffff' },
{ x: 82, y: 22, r: 2.4, color: '#ffffff' },
{ x: 14, y: 78, r: 3.2, color: '#4cd7f6' },
],
},
]
}
/**
* 构建与 POST /api/v1/assets/mints 一致的字段子集 + 本地预览所需字段
* DTO: order_id, name, material_url, description, grade, tags, material_type, info
*/
export function buildCastloveFormSnapshot({
nftInfo,
materialTypes,
materialTypeIndex,
pageName,
uploadedImage,
uploadedImageBase64,
}) {
const info = (nftInfo || '').trim()
const material_type = materialTypes[materialTypeIndex] || '粉丝自制'
const lines = info.split(/\n/).map((l) => l.trim()).filter(Boolean)
const name =
lines.length > 0
? lines[0].slice(0, 80)
: pageName === CRAFT_LENTICULAR_CN
? '光栅卡作品'
: pageName === CRAFT_LASER_CARD_CN
? '镭射卡作品'
: pageName || '藏品'
const tags = buildCraftTags(pageName)
return {
image: uploadedImage,
imageBase64: uploadedImageBase64,
info,
material_type,
name,
description: '',
tags,
craft_name: pageName || '',
grade: 0,
}
}