feat(xiaoyi): wire the three-stage creation wizard
This commit is contained in:
parent
2539e56e19
commit
2e75cea60d
File diff suppressed because it is too large
Load Diff
@ -50,6 +50,8 @@ pub(super) struct UiState {
|
||||
pub(super) resource_query: String,
|
||||
pub(super) resource_image: Option<(String, egui::TextureHandle)>,
|
||||
pub(super) staged_new_project: bool,
|
||||
pub(super) staged_prior_draft: Option<Value>,
|
||||
pub(super) wizard_stage: Option<(egui::Id, wizard::CreationStage)>,
|
||||
pub(super) inline_errors: HashMap<String, String>,
|
||||
pub(super) scroll_to_field: Option<String>,
|
||||
pub(super) manual_edited_fields: HashSet<String>,
|
||||
@ -444,6 +446,14 @@ impl Workspace {
|
||||
self.creation_read_failed(pending.request, error, value["readError"] == "queue_busy");
|
||||
} else if self.creation_reads.desired.get(kind(&pending.request)) == Some(&pending.request.signature) {
|
||||
if let Some(items) = value["catalog"]["items"].as_array() {
|
||||
if kind(&pending.request) == "templates" {
|
||||
let selected = &self.creation_brief["templateSelection"];
|
||||
if let Some(row) = items.iter().find(|row| row["id"] == selected["id"]
|
||||
&& row["version"] == selected["version"] && row["contentHash"] == selected["contentHash"])
|
||||
{
|
||||
self.creation_dirty |= wizard::refresh_intake_schema_from_catalog(&mut self.creation_brief, row);
|
||||
}
|
||||
}
|
||||
self.creation_catalog.insert(kind(&pending.request).into(), items.clone());
|
||||
self.creation_reads.catalog_errors.remove(kind(&pending.request));
|
||||
} else {
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
//! Components for the native product creation flow. The owner dispatches navigation,
|
||||
//! image imports and saves.
|
||||
#![allow(dead_code, reason = "The creation flow wires these components in a separate change")]
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::jiansun::{stitch_kit, stitch_ui};
|
||||
#[cfg(test)]
|
||||
use crate::theme::Tokens;
|
||||
use crate::theme::agent_scale::{Type, control, icon, motion, radius, space};
|
||||
use egui::{Id, Ui};
|
||||
use crate::theme::agent_scale::{Type, control, motion, space};
|
||||
use egui::{Id, Response, Ui};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(crate) enum CreationStage {
|
||||
Source,
|
||||
Template,
|
||||
@ -21,46 +21,33 @@ pub(crate) fn resolve_initial_stage(new_project: bool, has_template: bool) -> Cr
|
||||
if !new_project && has_template { CreationStage::Details } else { CreationStage::Source }
|
||||
}
|
||||
|
||||
impl CreationStage {
|
||||
pub(crate) fn title(self) -> &'static str {
|
||||
match self {
|
||||
Self::Source => "资料来源",
|
||||
Self::Template => "选择模板",
|
||||
Self::Details => "填写产品资料",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Only earlier, completed stages are navigable. Forward actions live in the footer.
|
||||
pub(crate) fn wizard_stepper_ui(ui: &mut Ui, current: &mut CreationStage, source_done: bool, template_done: bool, reduce_motion: bool) -> bool {
|
||||
let stages = [CreationStage::Source, CreationStage::Template, CreationStage::Details];
|
||||
let before = *current;
|
||||
stitch_ui::scope_with_motion(ui, reduce_motion, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for (stage, label, done) in [
|
||||
(CreationStage::Source, "1. 资料来源", source_done),
|
||||
(CreationStage::Template, "2. 选择模板", template_done),
|
||||
(CreationStage::Details, "3. 填写产品资料", false),
|
||||
] {
|
||||
let active = stage == before;
|
||||
let enabled = done && stage < before;
|
||||
let tokens = Tokens::get(ui.ctx()).agent();
|
||||
let ink = if active { tokens.primary_text } else { tokens.text_dim };
|
||||
let text = egui::RichText::new(label).font(Type::Title.font_id()).color(ink);
|
||||
let button =
|
||||
if done && !active { egui::Button::image_and_text(crate::icons::image("check", icon::SM, ink), text) } else { egui::Button::new(text) };
|
||||
let fill = if active {
|
||||
tokens.primary_bg
|
||||
} else if enabled {
|
||||
tokens.card
|
||||
} else {
|
||||
egui::Color32::TRANSPARENT
|
||||
};
|
||||
let response = ui.add_enabled(
|
||||
active || enabled,
|
||||
button
|
||||
.fill(fill)
|
||||
.corner_radius(radius::CHIP)
|
||||
.sense(if active { egui::Sense::hover() } else { egui::Sense::click() })
|
||||
.min_size(egui::vec2(0.0, control::DEFAULT)),
|
||||
);
|
||||
response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, enabled && ui.is_enabled(), active, label));
|
||||
stitch_ui::focus_ring(ui, &response, radius::CHIP, stitch_ui::FocusRing::Control);
|
||||
if response.clicked() {
|
||||
*current = stage;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
let options = [
|
||||
("1. 资料来源", source_done),
|
||||
("2. 选择模板", before == CreationStage::Template || (template_done && before == CreationStage::Details)),
|
||||
("3. 填写产品资料", before == CreationStage::Details),
|
||||
];
|
||||
let id = ui.scope_id().with("creation-steps");
|
||||
let rail = ui.scope(|ui| {
|
||||
ui.visuals_mut().disabled_alpha = 0.8;
|
||||
stitch_ui::segmented_control(ui, id, &options, before as usize, reduce_motion)
|
||||
}).inner;
|
||||
if let Some(index) = rail.selected && stages[index] < before {
|
||||
*current = stages[index];
|
||||
}
|
||||
*current != before
|
||||
}
|
||||
|
||||
@ -90,7 +77,7 @@ pub(crate) fn stage_reveal_opacity(ctx: &egui::Context, id: Id, stage: CreationS
|
||||
/// Keep the help available from the small icon by pointer or keyboard focus.
|
||||
pub(crate) fn section_heading_with_tip(ui: &mut Ui, title: &str, tip: &str) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
stitch_kit::section_heading(ui, title);
|
||||
stitch_kit::label(ui, title, Type::Body, super::super::stitch_state::Tone::Active);
|
||||
if !tip.is_empty() {
|
||||
let response = crate::icons::agent_icon_button(ui, "info", control::STANDARD, false, "").accessible_name("查看说明");
|
||||
if response.has_focus() && !response.hovered() {
|
||||
@ -104,9 +91,9 @@ pub(crate) fn section_heading_with_tip(ui: &mut Ui, title: &str, tip: &str) {
|
||||
});
|
||||
}
|
||||
|
||||
const AXES: [(&str, &str); 3] = [("length", "长"), ("width", "宽"), ("height", "高")];
|
||||
pub(crate) const AXES: [(&str, &str); 3] = [("length", "长"), ("width", "宽"), ("height", "高")];
|
||||
|
||||
fn barcode_row(code: &str, variant_id: &Value, color: &Value, facts: &Value) -> Value {
|
||||
pub(crate) fn barcode_row(code: &str, variant_id: &Value, color: &Value, facts: &Value) -> Value {
|
||||
json!({
|
||||
"id": uuid::Uuid::new_v4().to_string(),
|
||||
"barcode": code, "variantId": variant_id, "colorName": field_text(color),
|
||||
@ -247,7 +234,7 @@ pub(crate) fn ensure_default_barcode(brief: &mut Value) -> bool {
|
||||
add(code, single_variant, &Value::Null);
|
||||
}
|
||||
if rows.is_empty() {
|
||||
let color = single_variant.get("colorName").unwrap_or(&brief["colorName"]);
|
||||
let color = single_variant.get("colorName").or_else(|| single_variant.get("name")).unwrap_or(&brief["colorName"]);
|
||||
rows.push(barcode_row("", &single_variant["id"], color, &Value::Null));
|
||||
}
|
||||
brief["barcodeEntries"] = json!(rows);
|
||||
@ -273,119 +260,107 @@ pub(crate) fn migrate_legacy_top_dimensions_to_barcode(brief: &mut Value) -> boo
|
||||
true
|
||||
}
|
||||
|
||||
/// Row edits, add and remove are applied to `brief["barcodeEntries"]`.
|
||||
/// The image intent carries a nonempty barcode and is handled by the owner.
|
||||
/// The owner uses committed barcode edits to update legacy bindings and images.
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct BarcodeCardAction {
|
||||
pub changed: bool,
|
||||
pub pick_image_for_barcode: Option<String>,
|
||||
/// Position in the list before removal.
|
||||
pub pending: bool,
|
||||
pub remove_index: Option<usize>,
|
||||
pub add_barcode: bool,
|
||||
}
|
||||
|
||||
/// Edit the wizard's draft rows. The owner reconciles them with persistent
|
||||
/// barcode bindings, intake values and scoped references before saving.
|
||||
pub(crate) fn barcode_cards_section_ui(
|
||||
pub(crate) fn barcode_cards_section_ui<'a>(
|
||||
ui: &mut Ui,
|
||||
scope: Id,
|
||||
width: f32,
|
||||
brief: &mut Value,
|
||||
material_options: &[Value],
|
||||
rows: &mut Vec<Value>,
|
||||
reduce_motion: bool,
|
||||
hint: impl Fn(&'static str) -> &'a str,
|
||||
mut related_fields: impl FnMut(&mut Ui, Id, &Value),
|
||||
) -> BarcodeCardAction {
|
||||
let mut action = BarcodeCardAction { changed: ensure_default_barcode(brief), ..Default::default() };
|
||||
if action.changed {
|
||||
migrate_legacy_top_dimensions_to_barcode(brief);
|
||||
}
|
||||
let Value::Object(fields) = brief else { return action };
|
||||
let Some(Value::Array(mut rows)) = fields.remove("barcodeEntries") else { return action };
|
||||
let width = width.min(ui.available_width());
|
||||
let removable = rows.len() > 1;
|
||||
let mut attached = std::collections::HashMap::new();
|
||||
for image in fields.get("images").and_then(Value::as_array).into_iter().flatten() {
|
||||
if let Some(code) = image["barcode"].as_str() {
|
||||
*attached.entry(code).or_insert(0usize) += 1;
|
||||
}
|
||||
}
|
||||
let variants = fields.get("variants").and_then(Value::as_array).map(Vec::as_slice).unwrap_or_default();
|
||||
stitch_ui::scope_with_motion(ui, reduce_motion, |ui| {
|
||||
ui.push_id(scope, |ui| {
|
||||
ui.set_width(width);
|
||||
stitch_kit::section_heading(ui, "产品条码");
|
||||
for (index, row) in rows.iter_mut().enumerate() {
|
||||
let Some(row) = row.as_object_mut() else { continue };
|
||||
let id = row.get("id").and_then(Value::as_str).map_or_else(|| scope.with(index), |key| scope.with(key));
|
||||
ui.push_id(id, |ui| {
|
||||
stitch_ui::surface_frame(ui.ctx(), stitch_ui::SurfaceRole::Task).show(ui, |ui| {
|
||||
action.changed |= edit_text(ui, id, row.entry("barcode").or_insert(Value::Null), "条码编码", "如 DNZ030516N717V01", reduce_motion);
|
||||
action.changed |= edit_text(ui, id, row.entry("colorName").or_insert(Value::Null), "花色", "填写花色", reduce_motion);
|
||||
if !variants.is_empty() || !material_options.is_empty() {
|
||||
let pick = stitch_ui::halo_select(ui, id.with("color"), ui.available_width(), "选择花色", reduce_motion, |ui| {
|
||||
variants.iter().chain(material_options).find(|option| {
|
||||
let name = option["colorName"].as_str().or_else(|| option["name"].as_str());
|
||||
name.is_some_and(|name| stitch_ui::menu_item(ui, name, true).clicked())
|
||||
})
|
||||
});
|
||||
if let Some(Some(choice)) = pick.inner {
|
||||
let name = choice.get("colorName").or_else(|| choice.get("name"));
|
||||
row.insert("colorName".into(), name.cloned().unwrap_or(Value::Null));
|
||||
let variant = variants.iter().find(|variant| {
|
||||
variant["id"] == choice["id"] || variant["colorMaterialId"].as_str().is_some_and(|material| choice["id"] == material)
|
||||
});
|
||||
row.insert("variantId".into(), variant.map(|row| row["id"].clone()).unwrap_or(Value::Null));
|
||||
action.changed = true;
|
||||
}
|
||||
}
|
||||
let dimensions = row.entry("dimensions").or_insert(Value::Null);
|
||||
if dimensions.is_null() {
|
||||
*dimensions = json!({});
|
||||
}
|
||||
if let Some(dimensions) = dimensions.as_object_mut() {
|
||||
action.changed |= dimensions_ui(ui, id, dimensions, reduce_motion);
|
||||
}
|
||||
let code = row.get("barcode").and_then(Value::as_str).unwrap_or("").trim();
|
||||
let linked = attached.get(code).copied().unwrap_or(0);
|
||||
let count = row.get("images").and_then(Value::as_array).map_or(linked, |images| images.len().max(linked));
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
stitch_kit::caption(ui, if count == 0 { "图片 · 未添加".into() } else { format!("图片 · 已添加 {count} 张") });
|
||||
let label = if count == 0 { "添加图片" } else { "更换图片" };
|
||||
if stitch_ui::action_button(ui, label, stitch_ui::ButtonRole::Secondary, !code.is_empty())
|
||||
.on_disabled_hover_text("请先填写条码编码")
|
||||
.clicked()
|
||||
{
|
||||
action.pick_image_for_barcode = Some(code.to_owned());
|
||||
}
|
||||
});
|
||||
action.changed |= edit_text(ui, id, row.entry("material").or_insert(Value::Null), "材质(选填)", "", reduce_motion);
|
||||
action.changed |= edit_text(ui, id, row.entry("boardType").or_insert(Value::Null), "板材类型(选填)", "", reduce_motion);
|
||||
if removable && stitch_ui::action_button(ui, "移除条码", stitch_ui::ButtonRole::QuietDanger, true).clicked() {
|
||||
let mut action = BarcodeCardAction::default();
|
||||
let mut used_codes: HashSet<_> = rows.iter().filter_map(|row| row["barcode"].as_str()).filter(|code| !code.is_empty()).map(str::to_owned).collect();
|
||||
let removable = rows.len() > 1 || rows.first().is_some_and(|row| row["barcode"].as_str().is_some_and(|code| !code.is_empty()));
|
||||
section_heading_with_tip(ui, "产品条码", "每个条码可填写自己的花色、规格与图片。");
|
||||
for (index, row) in rows.iter_mut().enumerate() {
|
||||
let id = scope.with(row["id"].as_str());
|
||||
ui.push_id(id, |ui| {
|
||||
if index > 0 {
|
||||
ui.add_space(space::SM);
|
||||
stitch_ui::divider(ui);
|
||||
}
|
||||
ui.add_space(space::XS);
|
||||
ui.horizontal(|ui| {
|
||||
stitch_kit::label(ui, format!("条码 {}", index + 1), Type::Body, super::super::stitch_state::Tone::Active);
|
||||
if removable {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if stitch_ui::action_button(ui, "移除条码", stitch_ui::ButtonRole::QuietDanger, true).clicked() {
|
||||
action.remove_index = Some(index);
|
||||
}
|
||||
});
|
||||
ui.add_space(space::XS);
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.add_space(space::XS);
|
||||
let old = field_text(&row["barcode"]);
|
||||
let draft_id = id.with("barcode-draft");
|
||||
let mut draft = ui.data(|data| data.get_temp::<String>(draft_id)).unwrap_or_else(|| old.clone());
|
||||
ui.columns(2, |columns| {
|
||||
let editor = super::super::creation::wizard_barcode_editor(&mut columns[0], id.with("code"), &mut draft);
|
||||
let code = draft.trim();
|
||||
if code != old {
|
||||
let issue = if used_codes.contains(code) { Some("此条码已录入当前项目") }
|
||||
else if code.is_empty() && !old.is_empty() { Some("请填写条码或移除本条") }
|
||||
else { None };
|
||||
if let Some(issue) = issue {
|
||||
stitch_ui::status_label(&mut columns[0], issue, stitch_ui::StatusTone::Warning);
|
||||
} else if editor.lost_focus() || (editor.has_focus() && columns[0].input(|input| input.key_pressed(egui::Key::Enter))) {
|
||||
used_codes.remove(&old);
|
||||
used_codes.insert(code.to_owned());
|
||||
row["barcode"] = json!(code);
|
||||
action.changed = true;
|
||||
}
|
||||
}
|
||||
action.pending |= row["barcode"] != code && action.remove_index != Some(index);
|
||||
ui_data_draft(&columns[0], draft_id, draft, &row["barcode"]);
|
||||
let color_hint = hint("colorName");
|
||||
action.changed |= edit_text(&mut columns[1], id, &mut row["colorName"], "花色",
|
||||
if color_hint.is_empty() { "如 原木色" } else { color_hint }, reduce_motion);
|
||||
});
|
||||
ui.add_space(space::XS);
|
||||
if let Some(dimensions) = row["dimensions"].as_object_mut() {
|
||||
action.changed |= dimensions_ui(ui, id, dimensions, reduce_motion, &hint);
|
||||
}
|
||||
action.add_barcode = stitch_ui::action_button(ui, "+ 添加条码", stitch_ui::ButtonRole::Secondary, true).clicked();
|
||||
ui.add_space(space::XS);
|
||||
ui.columns(2, |columns| {
|
||||
action.changed |= edit_text(&mut columns[0], id, &mut row["material"], "材质(选填)", hint("material"), reduce_motion);
|
||||
action.changed |= edit_text(&mut columns[1], id, &mut row["boardType"], "板材类型(选填)", hint("boardType"), reduce_motion);
|
||||
});
|
||||
ui.add_space(space::XS);
|
||||
related_fields(ui, id, row);
|
||||
});
|
||||
});
|
||||
if let Some(index) = action.remove_index {
|
||||
rows.remove(index);
|
||||
}
|
||||
if action.add_barcode {
|
||||
rows.push(barcode_row("", &Value::Null, &Value::Null, &Value::Null));
|
||||
}
|
||||
ui.add_space(space::SM);
|
||||
action.add_barcode = stitch_ui::action_button(ui, "添加条码", stitch_ui::ButtonRole::Secondary, rows.len() < 200).clicked();
|
||||
action.changed |= action.add_barcode || action.remove_index.is_some();
|
||||
fields.insert("barcodeEntries".into(), Value::Array(rows));
|
||||
action
|
||||
}
|
||||
|
||||
fn ui_data_draft(ui: &Ui, id: Id, draft: String, committed: &Value) {
|
||||
ui.data_mut(|data| {
|
||||
if committed == draft.trim() {
|
||||
data.remove::<String>(id);
|
||||
} else {
|
||||
data.insert_temp(id, draft);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn edit_text(ui: &mut Ui, id: Id, value: &mut Value, label: &str, hint: &str, reduced: bool) -> bool {
|
||||
stitch_kit::caption(ui, label);
|
||||
let mut text = field_text(value);
|
||||
let id = id.with(label);
|
||||
let id = super::super::creation::creation_editor_id(ui, id.with(label));
|
||||
let response = stitch_ui::halo_field(ui, id.with("halo"), None, reduced, |ui| {
|
||||
let editor = stitch_ui::text_input(&mut text, hint, false).id(id).frame(egui::Frame::NONE).margin(egui::Margin::ZERO);
|
||||
let editor = stitch_ui::text_input(&mut text, hint, false).id(id).frame(egui::Frame::NONE).margin(egui::Margin::ZERO)
|
||||
.desired_width(ui.available_width());
|
||||
ui.add(editor).accessible_name(label)
|
||||
});
|
||||
if response.changed() {
|
||||
@ -394,7 +369,10 @@ fn edit_text(ui: &mut Ui, id: Id, value: &mut Value, label: &str, hint: &str, re
|
||||
response.changed()
|
||||
}
|
||||
|
||||
fn dimensions_ui(ui: &mut Ui, id: Id, dimensions: &mut serde_json::Map<String, Value>, reduced: bool) -> bool {
|
||||
fn dimensions_ui<'a>(
|
||||
ui: &mut Ui, id: Id, dimensions: &mut serde_json::Map<String, Value>, reduced: bool,
|
||||
hint: &impl Fn(&'static str) -> &'a str,
|
||||
) -> bool {
|
||||
stitch_kit::caption(ui, "尺寸");
|
||||
let per_row = if ui.available_width() >= 320.0 { 4 } else { 2 };
|
||||
let fields = [AXES[0], AXES[1], AXES[2], ("unit", "单位")];
|
||||
@ -416,7 +394,7 @@ fn dimensions_ui(ui: &mut Ui, id: Id, dimensions: &mut serde_json::Map<String, V
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
changed |= edit_text(ui, id, value, label, "", reduced);
|
||||
changed |= edit_text(ui, id, value, label, hint(field), reduced);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -479,7 +457,10 @@ pub(crate) enum WizardFooterOutcome {
|
||||
Start,
|
||||
}
|
||||
|
||||
pub(crate) fn wizard_footer_ui(ui: &mut Ui, state: WizardFooterState) -> WizardFooterOutcome {
|
||||
pub(crate) fn wizard_footer_ui(
|
||||
ui: &mut Ui, state: WizardFooterState, show_production: bool,
|
||||
mut on_button: impl FnMut(WizardFooterOutcome, &Response),
|
||||
) -> WizardFooterOutcome {
|
||||
use WizardFooterOutcome::{Back, Cancel, EnterCanvas, Next, Start};
|
||||
use stitch_ui::ButtonRole::{Primary, Quiet, Secondary};
|
||||
|
||||
@ -491,19 +472,44 @@ pub(crate) fn wizard_footer_ui(ui: &mut Ui, state: WizardFooterState) -> WizardF
|
||||
CreationStage::Source => buttons.push(("下一步:选择模板", Primary, state.can_continue, Next)),
|
||||
CreationStage::Template => buttons.push(("下一步:填写产品资料", Primary, state.can_continue, Next)),
|
||||
CreationStage::Details => {
|
||||
buttons.extend([("进入模板画布", Secondary, state.can_enter_canvas, EnterCanvas), ("确认并开始制作", Primary, state.can_start, Start)])
|
||||
}
|
||||
}
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
let mut outcome = WizardFooterOutcome::None;
|
||||
for (label, role, enabled, intent) in buttons {
|
||||
if stitch_ui::action_button(ui, label, role, enabled).clicked() {
|
||||
outcome = intent;
|
||||
let prioritize_canvas = !show_production || (!state.can_start && state.can_enter_canvas);
|
||||
if prioritize_canvas && show_production {
|
||||
buttons.push((if state.can_continue { "继续整套制作" } else { "确认并开始制作" }, Secondary, state.can_start, Start));
|
||||
}
|
||||
buttons.push(("进入模板画布", if prioritize_canvas { Primary } else { Secondary }, state.can_enter_canvas, EnterCanvas));
|
||||
if show_production && !prioritize_canvas {
|
||||
buttons.push((if state.can_continue { "继续整套制作" } else { "确认并开始制作" }, Primary, state.can_start, Start));
|
||||
}
|
||||
}
|
||||
outcome
|
||||
})
|
||||
.inner
|
||||
}
|
||||
let mut outcome = WizardFooterOutcome::None;
|
||||
let mut draw = |ui: &mut Ui, (label, role, enabled, intent)| {
|
||||
let response = stitch_ui::action_button(ui, label, role, enabled);
|
||||
on_button(intent, &response);
|
||||
if response.clicked() {
|
||||
outcome = intent;
|
||||
}
|
||||
};
|
||||
if ui.available_width() >= 420.0 {
|
||||
ui.horizontal(|ui| {
|
||||
let split = if state.stage == CreationStage::Source { 1 } else { 2 };
|
||||
for button in &buttons[..split] {
|
||||
draw(ui, *button);
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
for button in buttons[split..].iter().rev() {
|
||||
draw(ui, *button);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for button in buttons {
|
||||
draw(ui, button);
|
||||
}
|
||||
});
|
||||
}
|
||||
outcome
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -632,7 +638,11 @@ mod tests {
|
||||
for width in [300.0, 720.0] {
|
||||
let mut h = Harness::builder().with_context_setup(setup).with_size(egui::vec2(width, 1100.0)).build_ui_state(
|
||||
|ui, state: &mut (Value, BarcodeCardAction)| {
|
||||
let action = barcode_cards_section_ui(ui, Id::unique("cards"), width, &mut state.0, &[], true);
|
||||
ensure_default_barcode(&mut state.0);
|
||||
let rows = state.0["barcodeEntries"].as_array_mut().unwrap();
|
||||
let action = barcode_cards_section_ui(ui, Id::unique("cards"), rows, true, |_| "", |_, _, _| {});
|
||||
if let Some(index) = action.remove_index { rows.remove(index); }
|
||||
if action.add_barcode { rows.push(barcode_row("", &Value::Null, &Value::Null, &Value::Null)); }
|
||||
if action != BarcodeCardAction::default() {
|
||||
state.1 = action;
|
||||
}
|
||||
@ -640,16 +650,12 @@ mod tests {
|
||||
(json!({"barcodeBindings":{"default":["0001"]},"images":[{"barcode":"0001"}]}), BarcodeCardAction::default()),
|
||||
);
|
||||
for label in
|
||||
["条码编码", "花色", "尺寸", "长", "宽", "高", "单位", "mm", "图片 · 已添加 1 张", "更换图片", "材质(选填)", "板材类型(选填)", "+ 添加条码"]
|
||||
["条码编码", "花色", "尺寸", "长", "宽", "高", "单位", "mm", "材质(选填)", "板材类型(选填)", "添加条码"]
|
||||
{
|
||||
let rect = h.query_all_by_label(label).next().unwrap_or_else(|| panic!("missing {label}")).rect();
|
||||
assert!(rect.left() >= 0.0 && rect.right() <= width, "{label}: {rect:?}");
|
||||
}
|
||||
assert!(h.query_by_label("移除条码").is_none());
|
||||
h.get_by_label("更换图片").click();
|
||||
h.run();
|
||||
assert_eq!(h.state().1.pick_image_for_barcode.as_deref(), Some("0001"));
|
||||
h.get_by_label("+ 添加条码").click();
|
||||
h.get_by_label("添加条码").click();
|
||||
h.run();
|
||||
assert!(h.state().1.add_barcode);
|
||||
assert_eq!(h.state().0["barcodeEntries"].as_array().unwrap().len(), 2);
|
||||
@ -693,7 +699,7 @@ mod tests {
|
||||
let mut h = Harness::builder().with_context_setup(setup).with_size(egui::vec2(300.0, 220.0)).build_ui_state(
|
||||
move |ui, result| {
|
||||
let state = WizardFooterState { stage, can_continue: false, can_enter_canvas: false, can_start: false };
|
||||
let action = stitch_ui::scope_with_motion(ui, true, |ui| wizard_footer_ui(ui, state)).inner;
|
||||
let action = stitch_ui::scope_with_motion(ui, true, |ui| wizard_footer_ui(ui, state, true, |_, _| {})).inner;
|
||||
if action != WizardFooterOutcome::None {
|
||||
*result = action;
|
||||
}
|
||||
@ -721,10 +727,11 @@ mod tests {
|
||||
let mut stage = CreationStage::Details;
|
||||
wizard_stepper_ui(ui, &mut stage, true, true, true);
|
||||
ui.add_space(space::MD);
|
||||
barcode_cards_section_ui(ui, Id::unique("sample"), ui.available_width(), brief, &[], true);
|
||||
ensure_default_barcode(brief);
|
||||
barcode_cards_section_ui(ui, Id::unique("sample"), brief["barcodeEntries"].as_array_mut().unwrap(), true, |_| "", |_, _, _| {});
|
||||
ui.add_space(space::MD);
|
||||
stitch_ui::scope_with_motion(ui, true, |ui| {
|
||||
wizard_footer_ui(ui, WizardFooterState { stage, can_continue: false, can_enter_canvas: true, can_start: true });
|
||||
wizard_footer_ui(ui, WizardFooterState { stage, can_continue: false, can_enter_canvas: true, can_start: true }, true, |_, _| {});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@ -35,7 +35,7 @@ impl Workspace {
|
||||
"materials"
|
||||
} else if self.library {
|
||||
"projects"
|
||||
} else if self.creation_open && self.creation_step < 3 {
|
||||
} else if self.editing_product_brief() {
|
||||
"brief"
|
||||
} else if app.session.active().is_none() {
|
||||
"projects"
|
||||
@ -68,6 +68,7 @@ impl Workspace {
|
||||
return;
|
||||
}
|
||||
if intent == Intent::Spu {
|
||||
self.creation_brief["source"] = json!("product_platform");
|
||||
self.creation_brief["identifierType"] = json!("spu");
|
||||
self.creation_brief["identifier"] = json!(text);
|
||||
self.creation_dirty = true;
|
||||
@ -345,19 +346,18 @@ impl Workspace {
|
||||
|
||||
// Header
|
||||
ui.horizontal(|ui| {
|
||||
stitch_kit::label(ui, "建项协作者", Type::Heading, Tone::Active);
|
||||
stitch_kit::label(ui, "建项协作者", Type::TitleLg, Tone::Active);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
stitch_kit::label(ui, format!("{ready_count}/{total_count} 项就绪"), Type::Meta, if missing.is_empty() { Tone::Success } else { Tone::Quiet });
|
||||
});
|
||||
});
|
||||
stitch_kit::caption(ui, "核对商品资料完整性、平台字段异常与企业规范,点击待补齐项可直接定位。");
|
||||
stitch_ui::divider(ui);
|
||||
|
||||
// Section A: Live Brief Readiness
|
||||
stitch_kit::label(ui, "资料核对清单", Type::Body, Tone::Active);
|
||||
let mut focus_target: Option<(String, String)> = None;
|
||||
if missing.is_empty() {
|
||||
stitch_kit::inline_notice(ui, "check", Tone::Success, "核心建项资料已齐备,可点击底部「确认并开始制作」。", |_| {});
|
||||
stitch_kit::inline_notice(ui, "check", Tone::Success, "核心建项资料已齐备。", |_| {});
|
||||
} else {
|
||||
egui::Frame::NONE
|
||||
.fill(t.field)
|
||||
@ -368,8 +368,8 @@ impl Workspace {
|
||||
ui.set_width((inner_w - 2.0 * space::SM - 2.0).max(120.0));
|
||||
ui.spacing_mut().item_spacing.y = space::XS;
|
||||
for item in &missing {
|
||||
let text = format!("补齐 {} · {}", item.label, item.message);
|
||||
if stitch_ui::menu_item(ui, &text, true).on_hover_text("点击定位并高亮该字段").clicked() {
|
||||
let text = format!("补齐 {}", item.label);
|
||||
if stitch_ui::menu_item(ui, &text, true).on_hover_text(&item.message).clicked() {
|
||||
focus_target = Some((item.field_key.clone(), item.message.clone()));
|
||||
}
|
||||
}
|
||||
@ -422,8 +422,9 @@ impl Workspace {
|
||||
// Section C: Structured Raw-Material Paste & Knowledge Query (explicit actions, zero keyword guessing)
|
||||
ui.add_space(space::XS);
|
||||
stitch_ui::divider(ui);
|
||||
stitch_kit::label(ui, "资料暂存与规范查询", Type::Body, Tone::Active);
|
||||
stitch_kit::caption(ui, "粘贴运营文案、卖点清单或规范问题后,按需选择下方操作。");
|
||||
super::creation_reads::wizard::section_heading_with_tip(
|
||||
ui, "资料暂存与规范查询", "可粘贴运营文案、卖点清单或规范问题。"
|
||||
);
|
||||
let pending_kb = self.workbench.pending.is_some();
|
||||
let draft_resp = stitch_ui::halo_field(ui, Id::unique("brief-copilot-draft"), None, self.reduce_motion, |ui| {
|
||||
ui.add_enabled(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user