fix(xiaoyi): 修复建项拖放和模板资料交互
This commit is contained in:
parent
4fd6544c4c
commit
7e20c4defa
@ -236,20 +236,21 @@ impl PhotocraftApp {
|
||||
// Native file drops bypass normal widget hit testing. Keep the modal's
|
||||
// input barrier for Agent targets and native document routing alike,
|
||||
// including the frames in which its retained contents fade out.
|
||||
if ctx.memory(|memory| memory.top_modal_layer().is_some()) {
|
||||
return;
|
||||
}
|
||||
// The product reference drop target belongs to the Agent workspace.
|
||||
// Unrelated and unlocated drops continue through PhotoCraft's native
|
||||
// document/canvas routing below.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.composer_attachment_drop(ctx, &files, at) {
|
||||
if self.file_dialog_open() || !self.ui.dialogs.is_empty()
|
||||
|| ctx.memory(|memory| memory.top_modal_layer().is_some())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The product form owns image drops while a brief is open, even when
|
||||
// the pointer or a visible upload target is unavailable.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.creation_reference_drop(ctx, &files, at) {
|
||||
return;
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.composer_attachment_drop(ctx, &files, at) {
|
||||
return;
|
||||
}
|
||||
let target = self.drop_target(ctx, at);
|
||||
let mut slot = match target {
|
||||
DropTarget::Tabs(slot) => Some(slot),
|
||||
|
||||
@ -9,6 +9,7 @@ use std::collections::{HashMap, HashSet};
|
||||
const PICKER_HEIGHT: f32 = 280.0;
|
||||
const PICKER_ROW_HEIGHT: f32 = 36.0;
|
||||
const MATERIAL_THUMB_SIDE: f32 = 32.0;
|
||||
const REFERENCE_DROP_HINT: &str = "请将图片拖入素材上传框内";
|
||||
|
||||
fn rect_value(rect: egui::Rect) -> Value {
|
||||
json!([rect.min.x, rect.min.y, rect.width(), rect.height()])
|
||||
@ -165,32 +166,38 @@ impl PhotocraftApp {
|
||||
pub(crate) fn creation_reference_drop(
|
||||
&mut self, ctx: &egui::Context, files: &[egui::DroppedFileHandle], at: Option<egui::Pos2>,
|
||||
) -> bool {
|
||||
let Some(at) = at else { return false };
|
||||
if !self.ui.dialogs.is_empty() || !super::product_form_open(self) {
|
||||
if self.file_dialog_open() {
|
||||
return false;
|
||||
}
|
||||
let Some(w) = self.jiansun.as_ref() else { return false };
|
||||
let Some(doc) = self.session.active().map(|state| state.doc.id.0) else { return false };
|
||||
let target = std::iter::once(&w.creation_view_geometry["referenceDrop"])
|
||||
.chain(w.creation_view_geometry["imageSlots"].as_object().into_iter().flat_map(|slots| slots.values()))
|
||||
.find(|target| target["doc"].as_u64() == Some(doc) && target["accountId"] == w.account["id"]
|
||||
&& target["origin"] == w.origin && drop_contains(&target["rect"], at)
|
||||
&& ctx.layer_id_at(at).is_none_or(|layer| layer.order == egui::Order::Background));
|
||||
let product_form_open = super::product_form_open(self);
|
||||
let Some(w) = self.jiansun.as_mut() else { return false };
|
||||
let staged = w.creation_reads.staged_new_project && w.creation_open
|
||||
&& w.creation_step == 0 && !w.library && !w.material;
|
||||
if !product_form_open && !staged {
|
||||
return false;
|
||||
}
|
||||
let doc = self.session.active().map(|state| state.doc.id.0);
|
||||
let target = at.and_then(|at| {
|
||||
let layer = ctx.layer_id_at(at);
|
||||
w.creation_view_geometry["imageSlots"].as_object().into_iter().flat_map(|slots| slots.values())
|
||||
.chain(std::iter::once(&w.creation_view_geometry["referenceDrop"]))
|
||||
.find(|target| target["doc"] == json!(doc) && target["accountId"] == w.account["id"]
|
||||
&& target["origin"] == w.origin && target["viewport"].as_u64() == Some(ctx.viewport_id().0.value())
|
||||
&& drop_contains(&target["rect"], at)
|
||||
&& layer.is_none_or(|layer| layer.order == egui::Order::Background
|
||||
|| target["layer"].as_u64() == Some(layer.id.value())))
|
||||
});
|
||||
let Some(target) = target else {
|
||||
if drop_contains(&w.creation_view_geometry["product-form-viewport"], at)
|
||||
&& files.iter().any(|file| reference_image_path(file.path()))
|
||||
if files.iter().any(|file| file.path().extension().and_then(|ext| ext.to_str())
|
||||
.is_some_and(|ext| photocraft_codecs::from_extension(ext).is_some() || ext.eq_ignore_ascii_case("svg")))
|
||||
{
|
||||
if let Some(w) = self.jiansun.as_mut() {
|
||||
w.creation_reads.reference_import_error = if uses_template_images(&w.creation_brief) {
|
||||
"请将图片拖到图片框内"
|
||||
} else { "请将图片拖到「产品参考图」区域" }.into();
|
||||
}
|
||||
w.creation_reads.reference_import_error = REFERENCE_DROP_HINT.into();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
let slot = target["slot"].clone();
|
||||
let reject = if w.creation_doc != Some(doc) || w.busy.is_some() {
|
||||
let reject = if w.creation_doc != doc || w.busy.is_some() {
|
||||
Some("请等待当前操作完成,再添加参考图")
|
||||
} else if w.unknown {
|
||||
Some("原请求结果待核查,请先核查后再添加参考图")
|
||||
@ -202,7 +209,7 @@ impl PhotocraftApp {
|
||||
None
|
||||
};
|
||||
if let Some(error) = reject {
|
||||
if let Some(w) = self.jiansun.as_mut() { w.creation_reads.reference_import_error = error.into(); }
|
||||
w.creation_reads.reference_import_error = error.into();
|
||||
return true;
|
||||
}
|
||||
let paths = files.iter().map(|file| {
|
||||
@ -211,7 +218,7 @@ impl PhotocraftApp {
|
||||
valid.then(|| path.to_str().map(str::to_owned)).flatten()
|
||||
}).collect::<Option<Vec<_>>>();
|
||||
let Some(paths) = paths else {
|
||||
if let Some(w) = self.jiansun.as_mut() { w.creation_reads.reference_import_error = "请选择 PNG、JPG 或 WebP 格式的本机图片".into(); }
|
||||
w.creation_reads.reference_import_error = "请选择 PNG、JPG 或 WebP 格式的本机图片".into();
|
||||
return true;
|
||||
};
|
||||
if let Err(error) = self.import_reference_paths(paths, slot)
|
||||
@ -1017,7 +1024,8 @@ fn edit_named_with_error(
|
||||
Value::Number(number) => number.to_string(),
|
||||
_ => String::new(),
|
||||
};
|
||||
let mut field = stitch_ui::text_input(&mut text, hint, multiline);
|
||||
let hint = egui::RichText::new(hint).color(Tokens::get(ui.ctx()).agent().text_dim);
|
||||
let mut field = stitch_ui::text_input(&mut text, "", multiline).hint_text(hint);
|
||||
if multiline {
|
||||
field = field.desired_rows(3);
|
||||
}
|
||||
@ -1084,23 +1092,33 @@ fn intake_multiline(field: &Value) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
fn intake_help(field: &Value) -> Option<&str> {
|
||||
field["help"].as_str().map(str::trim).filter(|help| !help.is_empty())
|
||||
}
|
||||
|
||||
fn intake_hint<'a>(field: &'a Value, group: &[&Value]) -> &'a str {
|
||||
field["placeholder"].as_str().map(str::trim).filter(|hint| !hint.is_empty())
|
||||
.or_else(|| intake_help(field).filter(|help| {
|
||||
*help != "按本款确认资料填写;尺寸注明单位,暂无资料可留空。"
|
||||
&& group.iter().filter(|row| intake_help(row) == Some(*help)).take(2).count() < 2
|
||||
}))
|
||||
.unwrap_or(match field["type"].as_str() {
|
||||
fn intake_hint(field: &Value) -> &str {
|
||||
["placeholder", "hint", "example", "promptHint", "description", "help"].into_iter()
|
||||
.filter_map(|key| non_empty_str(&field[key]))
|
||||
.find(|hint| *hint != "按本款确认资料填写;尺寸注明单位,暂无资料可留空。")
|
||||
.unwrap_or(match field_kind(field).as_str() {
|
||||
Some("number") => "数字",
|
||||
Some("select") => "请选择",
|
||||
Some("image") => "拖放图片或点击选择",
|
||||
_ => "",
|
||||
})
|
||||
}
|
||||
|
||||
fn reveal_template_intake(ui: &mut Ui, id: egui::Id, open: bool, reduced: bool, contents: impl FnOnce(&mut Ui)) {
|
||||
let height_id = id.with("intake-height");
|
||||
stitch_ui::morph_surface(ui, id, open, reduced, |ui| {
|
||||
if open {
|
||||
contents(ui);
|
||||
let height = ui.min_rect().height();
|
||||
ui.data_mut(|data| data.insert_temp(height_id, height));
|
||||
} else if let Some(height) = ui.data(|data| data.get_temp::<f32>(height_id)) {
|
||||
// Field definitions can disappear when a template is cleared. Keep
|
||||
// the measured space while it collapses without mounting stale fields.
|
||||
ui.add_space(height);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum IntakeScope {
|
||||
Product,
|
||||
@ -1155,7 +1173,7 @@ fn intake_fields_with_errors(
|
||||
).size().y).fold(0.0_f32, f32::max);
|
||||
for field in row {
|
||||
changed |= intake_field(
|
||||
ui, scope, field_width, label_height, field, intake_hint(field, fields),
|
||||
ui, scope, field_width, label_height, field, intake_hint(field),
|
||||
values, reduced, barcode, inline_errors, scroll_to_field, manual_edited,
|
||||
);
|
||||
}
|
||||
@ -1572,6 +1590,17 @@ fn section_heading(ui: &mut Ui, title: &str, description: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn brief_step(ui: &mut Ui, title: &str, ready: bool, previous_ready: bool) {
|
||||
let (status, tone) = if ready { ("已就绪", Tone::Success) }
|
||||
else if previous_ready { ("当前步骤", Tone::Active) }
|
||||
else { ("待填写", Tone::Quiet) };
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
stitch_kit::section_heading(ui, title);
|
||||
stitch_kit::label(ui, status, Type::Meta, tone);
|
||||
});
|
||||
ui.add_space(space::SM);
|
||||
}
|
||||
|
||||
fn section_break(ui: &mut Ui) {
|
||||
ui.add_space(space::LG);
|
||||
stitch_ui::divider(ui);
|
||||
@ -2109,6 +2138,7 @@ impl Workspace {
|
||||
if let Some(rest) = field_key.strip_prefix("intake-barcode:")
|
||||
&& let Some((code, _)) = rest.split_once(':')
|
||||
{
|
||||
self.creation_reads.expanded_skus.remove(&format!("!{code}"));
|
||||
self.creation_reads.expanded_skus.insert(code.to_owned());
|
||||
for group in normalized_color_groups(&self.creation_brief) {
|
||||
if group.skus.iter().any(|sku| sku.barcode == code) {
|
||||
@ -2474,28 +2504,30 @@ impl Workspace {
|
||||
let width = ui.available_width();
|
||||
let editable = ui.is_enabled();
|
||||
|
||||
// Top Product Source Import Strip — quick lookup without hiding form fields.
|
||||
self.source_import_strip_ui(app, ui, field_scope, width);
|
||||
brief_section_break(ui);
|
||||
|
||||
// Block 1 — 商品核心档案与款式规格
|
||||
section_heading(ui, "商品核心档案与款式规格", "填写当前商品的真实参数与款式条码;手动修改会在重新拉取时保留。");
|
||||
ui.add_space(space::SM);
|
||||
self.core_identity_and_specs_ui(app, ui, field_scope, width);
|
||||
let barcode_pending = self.sku_matrix_ui(app, ui, field_scope, width);
|
||||
let template = selected_template(&self.creation_brief, &self.template_workflow, &self.creation["brief"]);
|
||||
brief_step(ui, "1. 选择模板", template_identity(&template), true);
|
||||
self.template_and_brand_block_ui(app, ui, width);
|
||||
brief_section_break(ui);
|
||||
|
||||
// Block 2 — 模板与视觉素材
|
||||
section_heading(ui, "模板与视觉素材", "选定品牌、品类与模板后,核对参与生成的商品图与场景参考图。");
|
||||
ui.add_space(space::SM);
|
||||
self.template_and_brand_block_ui(app, ui, width);
|
||||
ui.add_space(space::MD);
|
||||
let template = selected_template(&self.creation_brief, &self.template_workflow, &self.creation["brief"]);
|
||||
let template_ready = template_identity(&template);
|
||||
let archive_ready = brief_readiness(&self.creation_brief, &template).iter()
|
||||
.filter(|item| !matches!(item.field_key.as_str(), "brand" | "category" | "template" | "images"))
|
||||
.all(|item| item.ready);
|
||||
brief_step(ui, "2. 商品档案与款式", archive_ready, template_ready);
|
||||
self.core_identity_and_specs_ui(app, ui, field_scope, width);
|
||||
let barcode_pending = self.sku_matrix_ui(app, ui, field_scope, width);
|
||||
|
||||
brief_section_break(ui);
|
||||
let images_ready = has_selected_product_image(&self.creation_brief);
|
||||
brief_step(ui, "3. 视觉素材", images_ready, template_ready && archive_ready);
|
||||
self.references_ui(app, ui, width);
|
||||
brief_section_break(ui);
|
||||
|
||||
// Block 3 — 制作目标与要求
|
||||
section_heading(ui, "制作目标与要求", "选择需要生成的成品类型,并补充画面偏好或制作禁忌。");
|
||||
ui.add_space(space::SM);
|
||||
brief_step(ui, "4. 确认制作目标", false, template_ready && archive_ready && images_ready);
|
||||
self.output_tags_ui(ui);
|
||||
ui.add_space(space::SM);
|
||||
self.special_requirements_ui(ui, field_scope);
|
||||
@ -2670,11 +2702,10 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
// Row 2: Full-width Dimensions L × W × H + unit (never crushed!)
|
||||
if !dynamic {
|
||||
stitch_ui::morph_surface(ui, field_scope.with("dimensions-reveal"), !dynamic, self.reduce_motion, |ui| {
|
||||
ui.add_space(space::SM);
|
||||
self.dimensions_row_ui(ui, field_scope, width);
|
||||
}
|
||||
});
|
||||
|
||||
// Clean Platform Specs & Copy summary (materials, key attributes, selling points)
|
||||
let np = normalized_product_summary(&self.creation_brief);
|
||||
@ -2690,9 +2721,10 @@ impl Workspace {
|
||||
.filter(|field| field_kind(field) == "image").collect::<Vec<_>>();
|
||||
let product_fields = product_fields.as_array().into_iter().flatten()
|
||||
.filter(|field| field_kind(field) != "image" && !is_product_name_field(field)).collect::<Vec<_>>();
|
||||
if !product_fields.is_empty() {
|
||||
reveal_template_intake(ui, field_scope.with("product-intake-reveal"),
|
||||
!product_fields.is_empty() || !image_fields.is_empty(), self.reduce_motion, |ui| {
|
||||
ui.add_space(space::MD);
|
||||
stitch_kit::label(ui, "模板补充属性", Type::Meta, Tone::Quiet);
|
||||
stitch_kit::label(ui, "模板商品字段", Type::Body, Tone::Active);
|
||||
ui.add_space(space::XS);
|
||||
let mut values = self.creation_brief["intake"]["productValues"].clone();
|
||||
if !values.is_object() { values = json!({}); }
|
||||
@ -2712,11 +2744,11 @@ impl Workspace {
|
||||
self.creation_brief["intake"]["productValues"] = values;
|
||||
self.creation_dirty = true;
|
||||
}
|
||||
}
|
||||
for field in image_fields {
|
||||
ui.add_space(space::SM);
|
||||
self.image_slot_ui(app, ui, width, field, None);
|
||||
}
|
||||
for field in image_fields {
|
||||
ui.add_space(space::SM);
|
||||
self.image_slot_ui(app, ui, width, field, None);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn product_name_field_ui(&mut self, ui: &mut Ui, field_scope: egui::Id, field_width: f32) {
|
||||
@ -2725,6 +2757,9 @@ impl Workspace {
|
||||
if scroll {
|
||||
self.creation_reads.scroll_to_field = None;
|
||||
}
|
||||
let hint = self.creation_brief["intake"]["schema"]["productFields"].as_array().into_iter().flatten()
|
||||
.find(|field| is_product_name_field(field)).map(intake_hint).filter(|hint| !hint.is_empty())
|
||||
.unwrap_or("输入当前商品名称").to_owned();
|
||||
field_group(ui, field_width, "产品名称 *", |ui| {
|
||||
let field = ui.scope(|ui| {
|
||||
edit_named_with_error(
|
||||
@ -2733,7 +2768,7 @@ impl Workspace {
|
||||
&mut self.creation_brief["name"],
|
||||
field_width,
|
||||
false,
|
||||
"输入当前商品名称",
|
||||
&hint,
|
||||
"产品名称",
|
||||
error.as_deref(),
|
||||
scroll,
|
||||
@ -3116,7 +3151,10 @@ impl Workspace {
|
||||
}
|
||||
let code = sku.barcode.as_str();
|
||||
let is_detail = self.creation_brief["detailBarcode"] == code;
|
||||
let sku_open = self.creation_reads.expanded_skus.contains(code) || (has_barcode_schema && total_barcodes <= 2);
|
||||
let closed_key = format!("!{code}");
|
||||
let mut sku_open = self.creation_reads.expanded_skus.contains(code)
|
||||
|| (has_barcode_schema && (is_detail || total_barcodes <= 2)
|
||||
&& !self.creation_reads.expanded_skus.contains(&closed_key));
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::SM;
|
||||
let star_label = if is_detail { "详情主款" } else { "设为主款" };
|
||||
@ -3156,38 +3194,20 @@ impl Workspace {
|
||||
if expand_btn.clicked() {
|
||||
if sku_open {
|
||||
self.creation_reads.expanded_skus.remove(code);
|
||||
self.creation_reads.expanded_skus.insert(closed_key);
|
||||
} else {
|
||||
self.creation_reads.expanded_skus.remove(&closed_key);
|
||||
self.creation_reads.expanded_skus.insert(code.to_owned());
|
||||
}
|
||||
sku_open = !sku_open;
|
||||
}
|
||||
});
|
||||
if sku_open {
|
||||
let card_scope = scope.with(("norm-sku", code));
|
||||
stitch_ui::morph_surface(ui, card_scope.with("reveal"), sku_open, self.reduce_motion, |ui| {
|
||||
ui.add_space(space::XS);
|
||||
let card_scope = scope.with(("norm-sku", code));
|
||||
let mut values = self.creation_brief["intake"]["barcodeValues"][code].clone();
|
||||
if !values.is_object() { values = json!({}); }
|
||||
if !fields.is_empty()
|
||||
&& intake_fields_with_errors(
|
||||
ui,
|
||||
card_scope,
|
||||
inner_w,
|
||||
&fields,
|
||||
IntakeScope::Barcode,
|
||||
&mut values,
|
||||
self.reduce_motion,
|
||||
Some(code),
|
||||
&mut self.creation_reads.inline_errors,
|
||||
&mut self.creation_reads.scroll_to_field,
|
||||
&mut self.creation_reads.manual_edited_fields,
|
||||
)
|
||||
{
|
||||
self.creation_brief["intake"]["barcodeValues"][code] = values;
|
||||
self.creation_dirty = true;
|
||||
}
|
||||
for field in &images {
|
||||
self.image_slot_ui(app, ui, inner_w, field, Some(code));
|
||||
}
|
||||
if fields.is_empty() && images.is_empty() {
|
||||
if has_barcode_schema {
|
||||
self.barcode_intake_ui(app, ui, card_scope, inner_w, code, &fields, &images);
|
||||
} else {
|
||||
// Show platform SKU attributes / selling points when present.
|
||||
if let Some(row) = self.creation_brief["normalizedProduct"]["variants"]
|
||||
.as_array()
|
||||
@ -3205,7 +3225,7 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -3283,29 +3303,9 @@ impl Workspace {
|
||||
data.insert_temp(draft_id, draft);
|
||||
}
|
||||
});
|
||||
let mut values = self.creation_brief["intake"]["barcodeValues"][code.as_str()].clone();
|
||||
if !values.is_object() { values = json!({}); }
|
||||
if !fields.is_empty()
|
||||
&& intake_fields_with_errors(
|
||||
ui,
|
||||
card_scope,
|
||||
inner_w,
|
||||
&fields,
|
||||
IntakeScope::Barcode,
|
||||
&mut values,
|
||||
self.reduce_motion,
|
||||
Some(code.as_str()),
|
||||
&mut self.creation_reads.inline_errors,
|
||||
&mut self.creation_reads.scroll_to_field,
|
||||
&mut self.creation_reads.manual_edited_fields,
|
||||
)
|
||||
{
|
||||
self.creation_brief["intake"]["barcodeValues"][code.as_str()] = values;
|
||||
self.creation_dirty = true;
|
||||
}
|
||||
for field in &images {
|
||||
self.image_slot_ui(app, ui, inner_w, field, Some(code));
|
||||
}
|
||||
reveal_template_intake(ui, card_scope.with("reveal"), has_barcode_schema, self.reduce_motion, |ui| {
|
||||
self.barcode_intake_ui(app, ui, card_scope, inner_w, code, &fields, &images);
|
||||
});
|
||||
if fields.is_empty() {
|
||||
let facts = &self.creation_brief["platformFacts"]["barcodes"][code.as_str()];
|
||||
let mut parts = Vec::new();
|
||||
@ -3485,6 +3485,23 @@ impl Workspace {
|
||||
self.brief_footer_ui(app, ui, barcode_pending);
|
||||
}
|
||||
|
||||
pub(super) fn brief_setup_warning(&self) -> Option<(&'static str, &'static str, &'static str)> {
|
||||
if !self.key_saved {
|
||||
Some(("尚未连接个人 Key,请先配置个人 Key", "个人 Key 未连接", "配置个人 Key"))
|
||||
} else if !(self.model_ready && self.image_ready) {
|
||||
Some(("尚未配置对话或生图模型", "模型未配置", "选择模型"))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn open_brief_setup_settings(&mut self) {
|
||||
self.open_model_settings();
|
||||
if !self.key_saved {
|
||||
self.key_settings = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn brief_footer_ui(&mut self, app: &mut PhotocraftApp, ui: &mut Ui, barcode_pending: bool) {
|
||||
let template = selected_template(&self.creation_brief, &self.template_workflow, &self.creation["brief"]);
|
||||
let readiness = brief_readiness(&self.creation_brief, &template);
|
||||
@ -3493,7 +3510,7 @@ impl Workspace {
|
||||
let new_project = self.template_workflow["canvasFirst"] != true;
|
||||
let chosen_pending = template.is_null() && self.creation_reads.resource_set["id"].is_string();
|
||||
let scoped_pending = self.scoped_production_pending();
|
||||
let model_ok = self.model_ready && self.image_ready;
|
||||
let setup_warning = new_project.then(|| self.brief_setup_warning()).flatten();
|
||||
|
||||
let blocked = if self.unknown {
|
||||
Some(if scoped_pending { "可继续制作其余图位。" } else { "请先核查原请求,再进入模板画布。" }.to_owned())
|
||||
@ -3514,10 +3531,8 @@ impl Workspace {
|
||||
} else if !missing_items.is_empty() {
|
||||
let names: Vec<&str> = missing_items.iter().map(|i| i.label.as_str()).collect();
|
||||
Some(format!("待补齐:{}", names.join("、")))
|
||||
} else if new_project && !model_ok {
|
||||
Some("请先选择对话模型和生图模型。".to_owned())
|
||||
} else {
|
||||
None
|
||||
setup_warning.map(|(message, _, _)| message.to_owned())
|
||||
};
|
||||
|
||||
// Row 1: Clickable readiness checklist OR concise pre-launch summary + Model pill
|
||||
@ -3561,14 +3576,14 @@ impl Workspace {
|
||||
}
|
||||
stitch_kit::label(ui, parts.join(" · "), Type::Meta, Tone::Success);
|
||||
}
|
||||
if new_project && !model_ok {
|
||||
stitch_ui::status_chip(ui, "模型未配置", stitch_ui::StatusTone::Warning);
|
||||
let pick_model = stitch_ui::action_button(ui, "选择模型", stitch_ui::ButtonRole::Secondary, true);
|
||||
self.control_geometry("select-model", pick_model.rect);
|
||||
if pick_model.clicked() {
|
||||
self.open_model_settings();
|
||||
if let Some((message, chip, action)) = setup_warning {
|
||||
stitch_ui::status_chip(ui, chip, stitch_ui::StatusTone::Warning).on_hover_text(message);
|
||||
let configure = stitch_ui::action_button(ui, action, stitch_ui::ButtonRole::Secondary, true);
|
||||
self.control_geometry(if self.key_saved { "select-model" } else { "configure-personal-key" }, configure.rect);
|
||||
if configure.clicked() {
|
||||
self.open_brief_setup_settings();
|
||||
}
|
||||
} else if new_project && model_ok {
|
||||
} else if new_project {
|
||||
stitch_kit::label(ui, "模型已就绪", Type::Meta, Tone::Quiet);
|
||||
}
|
||||
});
|
||||
@ -3576,6 +3591,13 @@ impl Workspace {
|
||||
if let Some((key, msg)) = clicked_missing {
|
||||
self.focus_brief_field(&key, &msg);
|
||||
}
|
||||
if let Some((message, _, _)) = setup_warning {
|
||||
stitch_kit::label(ui, message, Type::Meta, Tone::Warning);
|
||||
}
|
||||
if self.creation_reads.reference_import_error == REFERENCE_DROP_HINT {
|
||||
let status = stitch_ui::status_label(ui, REFERENCE_DROP_HINT, stitch_ui::StatusTone::Warning);
|
||||
self.control_geometry("reference-import-error", status.rect);
|
||||
}
|
||||
|
||||
ui.add_space(space::XS);
|
||||
// Row 2: Live autosave indicator (left) + Clear CTA hierarchy (right)
|
||||
@ -3796,14 +3818,20 @@ impl Workspace {
|
||||
let files = &input.raw.hovered_files;
|
||||
!files.is_empty() && files.len() <= 8 && files.iter().all(|file| {
|
||||
if let Some(path) = &file.path {
|
||||
path.extension().and_then(|ext| ext.to_str()).is_some_and(|ext| ["png", "jpg", "jpeg", "webp"].iter().any(|allowed| ext.eq_ignore_ascii_case(allowed)))
|
||||
reference_image_path(path)
|
||||
} else {
|
||||
matches!(file.mime.as_str(), "image/png" | "image/jpeg" | "image/webp")
|
||||
}
|
||||
})
|
||||
});
|
||||
let enabled = self.busy.is_none() && !self.unknown;
|
||||
let drop_pointer = if supported && enabled { app.services.cursor_pos.as_mut().and_then(|cursor| cursor(ui.ctx())) } else { None };
|
||||
let drop_pointer = if supported && enabled {
|
||||
let to_local = ui.ctx().layer_transform_from_global(ui.layer_id()).unwrap_or_default();
|
||||
app.services.cursor_pos.as_mut().and_then(|cursor| cursor(ui.ctx()))
|
||||
.map(|point| to_local * point).filter(|point| ui.clip_rect().contains(*point))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let add_reference = if let Some((label, placeholder)) = labels {
|
||||
stitch_ui::labeled_file_drop_zone(ui, id, width, drop_pointer, enabled, self.reduce_motion, label, Some(placeholder))
|
||||
} else {
|
||||
@ -3943,17 +3971,38 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn barcode_intake_ui(&mut self, app: &mut PhotocraftApp, ui: &mut Ui, scope: egui::Id, width: f32,
|
||||
code: &str, fields: &[&Value], images: &[&Value],
|
||||
) {
|
||||
let mut values = self.creation_brief["intake"]["barcodeValues"][code].clone();
|
||||
if !values.is_object() { values = json!({}); }
|
||||
if !fields.is_empty() && intake_fields_with_errors(
|
||||
ui, scope, width, fields, IntakeScope::Barcode, &mut values, self.reduce_motion, Some(code),
|
||||
&mut self.creation_reads.inline_errors, &mut self.creation_reads.scroll_to_field,
|
||||
&mut self.creation_reads.manual_edited_fields,
|
||||
) {
|
||||
self.creation_brief["intake"]["barcodeValues"][code] = values;
|
||||
self.creation_dirty = true;
|
||||
}
|
||||
for field in images {
|
||||
self.image_slot_ui(app, ui, width, field, Some(code));
|
||||
}
|
||||
}
|
||||
|
||||
fn image_slot_ui(&mut self, app: &mut PhotocraftApp, ui: &mut Ui, width: f32, field: &Value, barcode: Option<&str>) {
|
||||
let slot = image_slot(&self.creation_brief["intake"]["templateId"], field, barcode);
|
||||
let label = intake_label(field);
|
||||
stitch_kit::label(ui, &label, Type::Meta, Tone::Quiet);
|
||||
let key = self.creation_field_scope(app).with(("reference-image-slot", slot.to_string()));
|
||||
let placeholder = field["placeholder"].as_str().unwrap_or("拖放图片或点击选择");
|
||||
let placeholder = intake_hint(field);
|
||||
let drop = self.reference_picker(app, ui, width, key, Some((&label, placeholder)), slot.clone());
|
||||
self.creation_view_geometry["imageSlots"][key.value().to_string()] = json!({
|
||||
"doc":self.creation_doc,"accountId":self.account["id"],"origin":self.origin,
|
||||
"rect":rect_value(drop.intersect(ui.clip_rect())),"slot":slot,"label":label,"placeholder":placeholder
|
||||
});
|
||||
if ui.is_enabled() && let Some(mut target) = self.reference_drop_geometry(app, ui, drop) {
|
||||
target["slot"] = slot.clone();
|
||||
target["label"] = json!(label);
|
||||
target["placeholder"] = json!(placeholder);
|
||||
self.creation_view_geometry["imageSlots"][key.value().to_string()] = target;
|
||||
}
|
||||
let rows = self.creation_brief["images"].as_array().cloned().unwrap_or_default();
|
||||
let mut remove = None;
|
||||
for (index, image) in rows.iter().enumerate().filter(|(_, image)| in_image_slot(image, &slot)) {
|
||||
@ -4004,7 +4053,32 @@ impl Workspace {
|
||||
self.creation_view_geometry["popups"]["source"] = json!({"open":false,"loading":false,"ready":true,"rect":null,"rows":[]});
|
||||
}
|
||||
|
||||
fn reference_drop_geometry(&self, app: &PhotocraftApp, ui: &Ui, rect: egui::Rect) -> Option<Value> {
|
||||
let visible = rect.intersect(ui.clip_rect());
|
||||
if !visible.is_positive() || !visible.is_finite() {
|
||||
return None;
|
||||
}
|
||||
let layer = ui.layer_id();
|
||||
let global = ui.ctx().layer_transform_to_global(layer).unwrap_or_default() * visible;
|
||||
Some(json!({
|
||||
"doc":app.session.active().map(|state| state.doc.id.0),
|
||||
"accountId":self.account["id"],"origin":self.origin,"rect":rect_value(global),
|
||||
"viewport":ui.ctx().viewport_id().0.value(),"layer":layer.id.value(),
|
||||
}))
|
||||
}
|
||||
|
||||
fn references_ui(&mut self, app: &mut PhotocraftApp, ui: &mut Ui, width: f32) {
|
||||
let gallery = ui.scope(|ui| self.visual_assets_gallery_ui(app, ui, width));
|
||||
if gallery.inner {
|
||||
if let Some(target) = self.reference_drop_geometry(app, ui, gallery.response.rect) {
|
||||
self.creation_view_geometry["referenceDrop"] = target;
|
||||
}
|
||||
} else {
|
||||
stitch_kit::caption(ui, "请在「商品档案与款式」中上传模板所需图片。");
|
||||
}
|
||||
}
|
||||
|
||||
fn visual_assets_gallery_ui(&mut self, app: &mut PhotocraftApp, ui: &mut Ui, width: f32) -> bool {
|
||||
self.poll_imported_reference_previews(app, ui.ctx());
|
||||
let t = Tokens::get(ui.ctx()).agent();
|
||||
let variants = brief_variants(&self.creation_brief);
|
||||
@ -4030,14 +4104,15 @@ impl Workspace {
|
||||
}
|
||||
let img_error = self.creation_reads.inline_errors.get("images").cloned();
|
||||
|
||||
let title = (!explicit || has_visible || has_norm_assets).then(|| {
|
||||
let show_gallery = !explicit || has_visible || has_norm_assets;
|
||||
if show_gallery {
|
||||
ui.set_min_width(width);
|
||||
let label = if explicit { "其他视觉素材" } else { "视觉素材库 *" };
|
||||
let resp = stitch_kit::label(ui, label, Type::Body, Tone::Active);
|
||||
if img_scroll {
|
||||
resp.scroll_to_me(Some(egui::Align::Center));
|
||||
}
|
||||
resp
|
||||
});
|
||||
}
|
||||
|
||||
// Role segmentation filter bar when there are assets or references.
|
||||
if has_norm_assets || has_visible {
|
||||
@ -4179,7 +4254,7 @@ impl Workspace {
|
||||
|
||||
let columns = if width >= 780.0 { 3 } else if width >= 560.0 { 2 } else { 1 };
|
||||
let card_width = (width - 12.0 * (columns - 1) as f32) / columns as f32;
|
||||
let grid = egui::Grid::new("creation-references").num_columns(columns).spacing(vec2(12.0, 12.0)).show(ui, |ui| {
|
||||
egui::Grid::new("creation-references").num_columns(columns).spacing(vec2(12.0, 12.0)).show(ui, |ui| {
|
||||
for (position, &index) in visible_indices.iter().enumerate() {
|
||||
let (image, owner) = &mut rows[index];
|
||||
let source = image["source"].as_str().unwrap_or("").to_owned();
|
||||
@ -4311,22 +4386,17 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
});
|
||||
if !explicit && let Some(title) = title {
|
||||
if !explicit {
|
||||
ui.add_space(space::XS);
|
||||
let drop_rect = self.add_reference_button(app, ui, width);
|
||||
if rows.is_empty() {
|
||||
self.control_geometry("reference-empty", drop_rect);
|
||||
}
|
||||
let target = title.rect.union(drop_rect);
|
||||
let visible = if rows.is_empty() { target } else { target.union(grid.response.rect) }.intersect(ui.clip_rect());
|
||||
self.creation_view_geometry["referenceDrop"] = json!({
|
||||
"doc":app.session.active().map(|state| state.doc.id.0),"accountId":self.account["id"],"origin":self.origin,"rect":rect_value(visible)
|
||||
});
|
||||
}
|
||||
for error in errors {
|
||||
stitch_ui::status_label(ui, &error, stitch_ui::StatusTone::Error);
|
||||
}
|
||||
if !self.creation_reads.reference_import_error.is_empty() {
|
||||
if !self.creation_reads.reference_import_error.is_empty() && self.creation_reads.reference_import_error != REFERENCE_DROP_HINT {
|
||||
let status = stitch_ui::status_label(ui, &self.creation_reads.reference_import_error, stitch_ui::StatusTone::Error);
|
||||
self.control_geometry("reference-import-error", status.rect);
|
||||
}
|
||||
@ -4349,6 +4419,7 @@ impl Workspace {
|
||||
Err(error) => self.error = error,
|
||||
}
|
||||
}
|
||||
show_gallery
|
||||
}
|
||||
|
||||
fn resource_template_select(&mut self, app: &mut PhotocraftApp, ui: &mut Ui, width: f32, selected: &Value, brand: &str, category: &str) {
|
||||
@ -5861,6 +5932,7 @@ mod tests {
|
||||
w.tx = tx;
|
||||
w.busy = None;
|
||||
w.unknown = false;
|
||||
w.key_saved = true;
|
||||
w.creation_brief = empty_brief();
|
||||
w.creation_brief["name"] = json!("实木多功能产品 · 用于核对窄窗口的完整产品名称");
|
||||
w.creation_brief["brandId"] = json!("brand");
|
||||
@ -5890,9 +5962,13 @@ mod tests {
|
||||
}
|
||||
|
||||
fn brief_frame(w: &mut Workspace, app: &mut PhotocraftApp, ctx: &egui::Context, width: f32, events: Vec<egui::Event>) -> egui::Rect {
|
||||
brief_frame_at_size(w, app, ctx, vec2(width, 2600.0), events)
|
||||
}
|
||||
|
||||
fn brief_frame_at_size(w: &mut Workspace, app: &mut PhotocraftApp, ctx: &egui::Context, size: egui::Vec2, events: Vec<egui::Event>) -> egui::Rect {
|
||||
let mut bounds = egui::Rect::NOTHING;
|
||||
let mut output = ctx.run_ui(
|
||||
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(width, 2600.0))), events, ..Default::default() },
|
||||
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)), events, ..Default::default() },
|
||||
|ui| {
|
||||
bounds = ui.available_rect_before_wrap();
|
||||
stitch_ui::scope(ui, |ui| w.brief_ui(app, ui));
|
||||
@ -6084,13 +6160,15 @@ mod tests {
|
||||
let a = json!({"id":"length","type":"number","help":"按本款确认资料填写;尺寸注明单位,暂无资料可留空。"});
|
||||
let b = json!({"id":"wood","type":"select","help":"请按确认资料填写。"});
|
||||
let c = json!({"id":"finish","type":"text","help":" 请按确认资料填写。 "});
|
||||
let group = [&explicit, &legacy_long, &legacy_short, &a, &b, &c];
|
||||
assert_eq!(intake_hint(&explicit, &group), "如:收拢深度 35 cm");
|
||||
assert_eq!(intake_hint(&legacy_long, &group), "如:远离火源");
|
||||
assert_eq!(intake_hint(&legacy_short, &group), "");
|
||||
assert_eq!(intake_hint(&a, &group), "数字");
|
||||
assert_eq!(intake_hint(&b, &group), "请选择");
|
||||
assert_eq!(intake_hint(&c, &group), "");
|
||||
assert_eq!(intake_hint(&explicit), "如:收拢深度 35 cm");
|
||||
assert_eq!(intake_hint(&legacy_long), "如:远离火源");
|
||||
assert_eq!(intake_hint(&legacy_short), "");
|
||||
assert_eq!(intake_hint(&a), "数字");
|
||||
assert_eq!(intake_hint(&b), "请按确认资料填写。");
|
||||
assert_eq!(intake_hint(&c), "请按确认资料填写。");
|
||||
for key in ["hint", "example", "promptHint", "description"] {
|
||||
assert_eq!(intake_hint(&json!({(key):"如:白蜡木"})), "如:白蜡木");
|
||||
}
|
||||
assert!(intake_multiline(&explicit));
|
||||
assert!(intake_multiline(&legacy_long));
|
||||
assert!(!intake_multiline(&legacy_short));
|
||||
@ -6258,7 +6336,11 @@ mod tests {
|
||||
w.creation_brief["identifier"] = json!("SPU-001");
|
||||
w.creation_brief["name"] = json!("可调工作台");
|
||||
set_intake(&mut w.creation_brief, &json!("visual-template"), &json!({"version":1,
|
||||
"productFields":[{"key":"product","kind":"image","label":"产品图片","placeholder":"拖入产品图或点击选择","imageRole":"product"}],
|
||||
"productFields":[
|
||||
{"id":"material","type":"text","label":"材质","promptHint":"例如:白蜡木"},
|
||||
{"id":"selling-points","type":"text","label":"核心卖点","description":"例如:台面可折叠,收纳后深度为 35 cm。"},
|
||||
{"key":"product","kind":"image","label":"产品图片","placeholder":"拖入产品图或点击选择","imageRole":"product"}
|
||||
],
|
||||
"barcodeFields":[{"key":"material","kind":"image","label":"材质图片","placeholder":"拖入材质图或点击选择","imageRole":"material"}]}));
|
||||
w.reduce_motion = true;
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(width, 1600.0))
|
||||
@ -6449,11 +6531,28 @@ mod tests {
|
||||
let ctx = egui::Context::default();
|
||||
for _ in 0..2 { brief_frame(&mut w, &mut app, &ctx, 850.0, vec![]); }
|
||||
let at = control_rect(&w, "reference-empty").center();
|
||||
let before = w.creation_brief.clone();
|
||||
let doc = app.session.active().unwrap().doc.id.0;
|
||||
app.jiansun = Some(w);
|
||||
|
||||
app.open_dropped(&ctx, vec![reference_drop("D:\\photos\\oak.png")], Some(at));
|
||||
let files = ["D:\\photos\\椅子-左视图.webp", "D:\\photos\\oak.png", "D:\\photos\\detail.jpg"];
|
||||
app.open_dropped(&ctx, files.into_iter().map(reference_drop).collect(), Some(at));
|
||||
|
||||
assert!(matches!(requests.try_recv(), Ok(Request::Action(method, _)) if method == "creation-import"));
|
||||
let Request::Action(method, input) = requests.try_recv().unwrap() else { panic!("expected reference import") };
|
||||
assert_eq!(method, "creation-import");
|
||||
assert_eq!(input["paths"], json!(files));
|
||||
assert_eq!(input["brief"], before);
|
||||
let images = files.iter().enumerate().map(|(i, path)| json!({
|
||||
"source":format!("local:{i:064x}"),"purpose":"product","name":path.rsplit('\\').next().unwrap(),
|
||||
})).collect::<Vec<_>>();
|
||||
let mut w = app.jiansun.take().unwrap();
|
||||
let receipt = json!({
|
||||
"doc":doc,"origin":w.origin,"accountId":w.account["id"],"images":images,
|
||||
});
|
||||
received(&mut w, &app, "creation-import", &receipt);
|
||||
assert_eq!(w.creation_brief["images"].as_array().unwrap().len(), 3);
|
||||
assert_eq!(w.creation_brief["name"], before["name"]);
|
||||
assert_eq!(app.session.active().unwrap().doc.id.0, doc);
|
||||
assert_eq!(app.session.documents().len(), 1);
|
||||
}
|
||||
|
||||
@ -6467,22 +6566,63 @@ mod tests {
|
||||
let ctx = egui::Context::default();
|
||||
for _ in 0..2 { brief_frame(&mut w, &mut app, &ctx, 850.0, vec![]); }
|
||||
let at = control_rect(&w, "name").center();
|
||||
w.creation_view_geometry["product-form-viewport"] = json!([0, 0, 850, 2100]);
|
||||
let before = w.creation_brief.clone();
|
||||
let doc = app.session.active().unwrap().doc.id.0;
|
||||
app.jiansun = Some(w);
|
||||
|
||||
app.open_dropped(&ctx, vec![reference_drop("D:\\photos\\oak.png")], Some(at));
|
||||
for point in [Some(at), Some(egui::pos2(0.0, 0.0)), None] {
|
||||
app.open_dropped(&ctx, vec![reference_drop("D:\\photos\\oak.png")], point);
|
||||
}
|
||||
|
||||
let workspace = app.jiansun.as_ref().unwrap();
|
||||
assert_eq!(app.session.active().unwrap().doc.id.0, doc);
|
||||
assert_eq!(app.session.documents().len(), 1);
|
||||
assert_eq!(workspace.creation_brief, before);
|
||||
assert!(workspace.creation_dirty);
|
||||
assert!(workspace.creation_reads.reference_import_error.contains("产品参考图"));
|
||||
assert_eq!(workspace.creation_reads.reference_import_error, REFERENCE_DROP_HINT);
|
||||
assert!(requests.try_recv().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn existing_assets_receive_drops_with_template_slots_on_the_form_layer() {
|
||||
let (mut w, mut app, requests) = brief_fixture();
|
||||
w.creation_open = true;
|
||||
w.library = false;
|
||||
set_intake(&mut w.creation_brief, &json!("image-template"), &json!({"version":1,"productFields":[
|
||||
{"key":"hero","kind":"image","label":"产品图片","imageRole":"product"},
|
||||
]}));
|
||||
let ctx = egui::Context::default();
|
||||
let layer = egui::LayerId::new(egui::Order::Middle, egui::Id::unique("brief-drop-layer"));
|
||||
for _ in 0..3 {
|
||||
let mut output = ctx.run_ui(egui::RawInput {
|
||||
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(900.0, 2600.0))),
|
||||
..Default::default()
|
||||
}, |ui| {
|
||||
egui::Area::new(layer.id).order(layer.order)
|
||||
.fixed_pos(egui::pos2(20.0, 20.0)).default_size(vec2(850.0, 2500.0))
|
||||
.show(ui.ctx(), |ui| {
|
||||
ui.set_min_size(vec2(850.0, 2500.0));
|
||||
w.creation_ui(&mut app, ui);
|
||||
});
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
}
|
||||
let at = control_rect(&w, "reference-0").center();
|
||||
assert_eq!(ctx.layer_id_at(at), Some(layer), "drop point {at:?} in {:?}", ctx.memory(|m| m.area_rect(layer.id)));
|
||||
assert!(drop_contains(&w.creation_view_geometry["product-form-viewport"], at));
|
||||
assert!(drop_contains(&w.creation_view_geometry["referenceDrop"]["rect"], at));
|
||||
let before = w.creation_brief.clone();
|
||||
app.jiansun = Some(w);
|
||||
app.open_dropped(&ctx, vec![reference_drop("D:\\photos\\chair.webp")], Some(at));
|
||||
let input = requests.try_iter().find_map(|request| match request {
|
||||
Request::Action(method, input) if method == "creation-import" => Some(input),
|
||||
_ => None,
|
||||
}).unwrap();
|
||||
assert_eq!(input["brief"], before);
|
||||
assert!(input["imageSlot"].is_null());
|
||||
assert_eq!(app.session.documents().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_drop_only_intercepts_the_visible_current_project_target() {
|
||||
let (mut w, mut app, requests) = brief_fixture();
|
||||
@ -6493,13 +6633,14 @@ mod tests {
|
||||
let at = control_rect(&w, "reference-add").center();
|
||||
app.jiansun = Some(w);
|
||||
let files = [reference_drop("D:\\photos\\oak.png")];
|
||||
assert!(!app.creation_reference_drop(&ctx, &files, None));
|
||||
assert!(!app.creation_reference_drop(&ctx, &files, Some(egui::pos2(1.0, 1.0))));
|
||||
assert!(app.creation_reference_drop(&ctx, &files, None));
|
||||
assert!(app.creation_reference_drop(&ctx, &files, Some(egui::pos2(1.0, 1.0))));
|
||||
app.jiansun.as_mut().unwrap().account = json!({"id":"another"});
|
||||
assert!(!app.creation_reference_drop(&ctx, &files, Some(at)), "old account geometry must not intercept a new account's drop");
|
||||
assert!(app.creation_reference_drop(&ctx, &files, Some(at)));
|
||||
app.jiansun.as_mut().unwrap().account = json!({"id":"qa"});
|
||||
app.session.execute("file.new", json!({"width":32,"height":32})).unwrap();
|
||||
assert!(!app.creation_reference_drop(&ctx, &files, Some(at)), "old document geometry must not capture a new document's drop");
|
||||
assert!(app.creation_reference_drop(&ctx, &files, Some(at)));
|
||||
assert_eq!(app.jiansun.as_ref().unwrap().creation_reads.reference_import_error, REFERENCE_DROP_HINT);
|
||||
assert!(requests.try_recv().is_err());
|
||||
}
|
||||
|
||||
@ -6623,30 +6764,33 @@ mod tests {
|
||||
let (mut w, mut app, requests) = brief_fixture();
|
||||
w.reduce_motion = true;
|
||||
let ctx = egui::Context::default();
|
||||
brief_frame(&mut w, &mut app, &ctx, width, vec![]);
|
||||
let bounds = brief_frame(&mut w, &mut app, &ctx, width, vec![]);
|
||||
let draw = |w: &mut Workspace, app: &mut PhotocraftApp, events| {
|
||||
brief_frame_at_size(w, app, &ctx, vec2(width, 3200.0), events)
|
||||
};
|
||||
draw(&mut w, &mut app, vec![]);
|
||||
let bounds = draw(&mut w, &mut app, vec![]);
|
||||
let field = control_rect(&w, "sku-color-input");
|
||||
assert!(bounds.contains_rect(field));
|
||||
brief_frame(&mut w, &mut app, &ctx, width, click_events(field.center()));
|
||||
brief_frame(&mut w, &mut app, &ctx, width, vec![egui::Event::Text("暖白色".into())]);
|
||||
draw(&mut w, &mut app, click_events(field.center()));
|
||||
draw(&mut w, &mut app, vec![egui::Event::Text("暖白色".into())]);
|
||||
let add = control_rect(&w, "sku-color-add");
|
||||
brief_frame(&mut w, &mut app, &ctx, width, click_events(add.center()));
|
||||
draw(&mut w, &mut app, click_events(add.center()));
|
||||
let white = variant_identity("manual-sku:暖白色");
|
||||
assert_eq!(w.creation_brief["variants"][2]["id"], white);
|
||||
let adv = control_rect(&w, "advanced-export-settings");
|
||||
brief_frame(&mut w, &mut app, &ctx, width, click_events(adv.center()));
|
||||
brief_frame(&mut w, &mut app, &ctx, width, vec![]);
|
||||
draw(&mut w, &mut app, click_events(adv.center()));
|
||||
draw(&mut w, &mut app, vec![]);
|
||||
let select = |w: &mut Workspace, app: &mut PhotocraftApp, output: &str, ids: &[&str]| {
|
||||
let trigger = control_rect(w, &format!("sku-output-{output}"));
|
||||
assert!(bounds.contains_rect(trigger));
|
||||
brief_frame(w, app, &ctx, width, click_events(trigger.center()));
|
||||
for _ in 0..25 { brief_frame(w, app, &ctx, width, vec![]); }
|
||||
assert!(bounds.contains_rect(trigger), "{output} trigger {trigger:?} outside {bounds:?}");
|
||||
draw(w, app, click_events(trigger.center()));
|
||||
for _ in 0..25 { draw(w, app, vec![]); }
|
||||
for id in ids {
|
||||
let option = control_rect(w, &format!("sku-output-{output}-{id}"));
|
||||
brief_frame(w, app, &ctx, width, click_events(option.center()));
|
||||
draw(w, app, click_events(option.center()));
|
||||
}
|
||||
brief_frame(w, app, &ctx, width, key_events(egui::Key::Escape));
|
||||
for _ in 0..25 { brief_frame(w, app, &ctx, width, vec![]); }
|
||||
draw(w, app, key_events(egui::Key::Escape));
|
||||
for _ in 0..25 { draw(w, app, vec![]); }
|
||||
};
|
||||
select(&mut w, &mut app, "detail", &["oak", "walnut"]);
|
||||
select(&mut w, &mut app, "main_images", &[&white]);
|
||||
@ -6722,10 +6866,10 @@ mod tests {
|
||||
let category = control_rect(&w, "category");
|
||||
assert!(control_rect(&w, "brief-title").bottom() < name.top(), "page title precedes the editable product fields");
|
||||
let template = control_rect(&w, "template");
|
||||
assert!(name.bottom() < brand.top(), "core product archive precedes template & visual assets block");
|
||||
assert!(brand.top() <= category.top());
|
||||
assert!(category.bottom() < template.top());
|
||||
assert!(template.bottom() < control_rect(&w, "reference-0").top(), "template selection precedes visual references");
|
||||
assert!(template.bottom() < name.top(), "template selection precedes product fields");
|
||||
assert!(name.bottom() < control_rect(&w, "reference-0").top(), "product fields precede the visual asset gallery");
|
||||
for control in ["name", "brand", "category", "dimensions", "identifier", "template"] {
|
||||
assert!((control_rect(&w, control).height() - 34.0).abs() < 0.8, "{control} has a consistent field height");
|
||||
}
|
||||
@ -7614,6 +7758,7 @@ mod tests {
|
||||
w.creation_catalog.insert("materials".into(), vec![]);
|
||||
w.configure_client_update(json!({"version":"1.0.0"}), true, |_| Ok(()));
|
||||
w.begin_staged_new_project(&app);
|
||||
w.key_saved = true;
|
||||
app.jiansun = Some(w);
|
||||
let mut h = egui_kittest::Harness::builder()
|
||||
.with_context_setup(crate::cjk_fonts::install_system_provider_for_tests)
|
||||
@ -7676,6 +7821,35 @@ mod tests {
|
||||
assert_eq!(h.query_all_by_label("小壹设置").count(), 1);
|
||||
assert!(h.query_by_label("对话模型").is_some());
|
||||
assert!(h.query_by_label("生图模型").is_some());
|
||||
assert!(!h.state().jiansun.as_ref().unwrap().key_settings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brief_key_warning_opens_the_personal_key_editor_from_both_surfaces() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
|
||||
for from_footer in [true, false] {
|
||||
let (mut h, requests) = brief_settings_harness(vec2(1440.0, 900.0));
|
||||
let w = h.state_mut().jiansun.as_mut().unwrap();
|
||||
w.key_saved = false;
|
||||
w.model_ready = true;
|
||||
w.image_ready = true;
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_label("选择模型").is_none());
|
||||
assert!(h.query_by_label("个人 Key 未连接").is_some());
|
||||
assert_eq!(h.query_all_by_label("尚未连接个人 Key,请先配置个人 Key").count(), 2);
|
||||
let footer = control_rect(h.state().jiansun.as_ref().unwrap(), "configure-personal-key");
|
||||
h.query_all_by_label("配置个人 Key")
|
||||
.find(|button| footer.contains(button.rect().center()) == from_footer).unwrap().click();
|
||||
h.run_steps(4);
|
||||
let w = h.state().jiansun.as_ref().unwrap();
|
||||
assert!(w.model_settings && w.key_settings);
|
||||
assert!(h.query_by_label("小壹设置").is_some());
|
||||
assert!(h.query_by_label("模型 API Key").is_some());
|
||||
assert!(requests.try_iter().any(|request| {
|
||||
matches!(request, Request::Action(method, input) if method == "client-update" && input["op"] == "check")
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -327,7 +327,6 @@ impl Workspace {
|
||||
let ready_count = readiness.iter().filter(|item| item.ready).count();
|
||||
let total_count = readiness.len();
|
||||
let np = creation::normalized_product_summary(&self.creation_brief);
|
||||
let model_ok = self.model_ready && self.image_ready;
|
||||
let new_project = self.template_workflow["canvasFirst"] != true;
|
||||
|
||||
egui::ScrollArea::vertical().id_salt("brief-copilot-body").auto_shrink([false, false]).show(ui, |ui| {
|
||||
@ -380,10 +379,10 @@ impl Workspace {
|
||||
self.focus_brief_field(&key, &msg);
|
||||
}
|
||||
|
||||
if new_project && !model_ok {
|
||||
stitch_kit::inline_notice(ui, "triangle-alert", Tone::Warning, "尚未配置对话或生图模型", |ui| {
|
||||
if stitch_ui::action_button(ui, "选择模型", stitch_ui::ButtonRole::Secondary, true).clicked() {
|
||||
self.open_model_settings();
|
||||
if new_project && let Some((message, _, action)) = self.brief_setup_warning() {
|
||||
stitch_kit::inline_notice(ui, "triangle-alert", Tone::Warning, message, |ui| {
|
||||
if stitch_ui::action_button(ui, action, stitch_ui::ButtonRole::Secondary, true).clicked() {
|
||||
self.open_brief_setup_settings();
|
||||
// The center pane may already have been drawn this pass.
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user