用户故事:响应式设计 - 支持桌面与移动端

Epic: E0 - 项目基础设施
Story ID: E0-S6
版本: 1.0.0
日期: 2025-01-11
优先级:
预计工时: 5-7 天


用户故事

作为个人投资者,
我希望在手机上也能查看和管理我的资产配置,
以便随时随地了解资产状况,不受设备限制。


背景分析

当前状态

方面现状问题
窗口尺寸固定 1440×900,最小 1280×720不支持移动端
侧边栏固定 220px 宽度小屏幕占用过多空间
布局方式内联样式,固定像素值无响应式断点
导航模式左侧固定侧边栏移动端需要底部导航或抽屉

目标状态

设备类型屏幕宽度导航模式布局特点
桌面端≥1024px左侧固定侧边栏多列布局,保持现有体验
平板端768-1023px可折叠侧边栏自适应列数
移动端<768px底部导航栏单列布局,卡片堆叠

技术方案

1. 响应式断点定义

#![allow(unused)]
fn main() {
// src/utils/responsive.rs

/// 响应式断点
pub enum Breakpoint {
    Mobile,   // < 768px
    Tablet,   // 768-1023px
    Desktop,  // ≥ 1024px
}

/// 根据窗口宽度获取当前断点
pub fn get_breakpoint(width: u32) -> Breakpoint {
    match width {
        w if w < 768 => Breakpoint::Mobile,
        w if w < 1024 => Breakpoint::Tablet,
        _ => Breakpoint::Desktop,
    }
}
}

2. 布局架构改造

2.1 主布局组件

#![allow(unused)]
fn main() {
// src/components/layout/app_layout.rs

#[component]
pub fn AppLayout() -> Element {
    let window_size = use_window_size(); // 需要实现
    let breakpoint = get_breakpoint(window_size.width);
    
    rsx! {
        div {
            class: "app-container",
            style: "display: flex; flex-direction: column; height: 100vh;",
            
            match breakpoint {
                Breakpoint::Desktop | Breakpoint::Tablet => rsx! {
                    div {
                        style: "display: flex; flex: 1;",
                        Sidebar { collapsible: breakpoint == Breakpoint::Tablet }
                        main {
                            style: "flex: 1; overflow: auto;",
                            Outlet::<Route> {}
                        }
                    }
                },
                Breakpoint::Mobile => rsx! {
                    main {
                        style: "flex: 1; overflow: auto; padding-bottom: 60px;",
                        Outlet::<Route> {}
                    }
                    BottomNavBar {}
                }
            }
        }
    }
}
}

2.2 移动端底部导航栏(新增)

#![allow(unused)]
fn main() {
// src/components/layout/bottom_nav.rs

#[component]
pub fn BottomNavBar() -> Element {
    rsx! {
        nav {
            style: r#"
                position: fixed;
                bottom: 0;
                left: 0;
                right: 0;
                height: 60px;
                background: #1e1e2e;
                display: flex;
                justify-content: space-around;
                align-items: center;
                border-top: 1px solid #313244;
                z-index: 1000;
            "#,
            
            BottomNavItem { to: Route::HomePage {}, icon: "📊", label: "首页" }
            BottomNavItem { to: Route::AssetsPage {}, icon: "💰", label: "资产" }
            BottomNavItem { to: Route::HistoryPage {}, icon: "📅", label: "历史" }
            BottomNavItem { to: Route::PlansPage {}, icon: "🎯", label: "配置" }
            BottomNavItem { to: Route::AnalysisPage {}, icon: "📈", label: "收益" }
        }
    }
}
}

3. 组件响应式改造清单

3.1 布局组件(必须改造)

组件文件路径改造内容优先级
Sidebarlayout/sidebar.rs支持折叠、移动端隐藏P0
AppLayoutlayout/mod.rs添加断点检测、切换布局P0
BottomNavBarlayout/bottom_nav.rs新建 移动端导航P0

3.2 首页组件

组件文件路径改造内容优先级
StatCarddashboard/stat_card.rs移动端全宽显示P1
PieChartdashboard/pie_chart.rs调整图表尺寸P1
DeviationTabledashboard/deviation_table.rs移动端改为卡片列表P1
QuickActionsdashboard/quick_actions.rs移动端网格布局P2

3.3 资产管理组件

组件文件路径改造内容优先级
AssetListasset/asset_list.rs移动端单列P1
AssetItemasset/asset_item.rs紧凑布局P1
AssetFormasset/asset_form.rs全屏弹窗/页面P1
CategoryGroupasset/category_group.rs折叠卡片P2

3.4 盘点组件

组件文件路径改造内容优先级
SnapshotTimelinesnapshot/snapshot_timeline.rs垂直时间线P1
SnapshotCardsnapshot/snapshot_card.rs全宽卡片P1
SnapshotDetailsnapshot/snapshot_detail.rs堆叠布局P1
InventoryModesnapshot/inventory_mode.rs移动端优化P2

3.5 配置方案组件

组件文件路径改造内容优先级
PlanListplan/plan_list.rs卡片列表P1
PlanCardplan/plan_card.rs紧凑布局P1
PlanEditorplan/plan_editor.rs全屏编辑P1

3.6 收益分析组件

组件文件路径改造内容优先级
PeriodSelectoranalysis/period_selector.rs下拉选择P1
ReturnCardanalysis/return_card.rs全宽显示P1
TrendChartanalysis/trend_chart.rs自适应宽度P1
AttributionTableanalysis/attribution_table.rs卡片化P2

3.7 通用组件

组件文件路径改造内容优先级
Modalcommon/modal.rs移动端全屏P0
Cardcommon/card.rs响应式内边距P1
Buttoncommon/button.rs移动端更大触控区P2
Inputcommon/input.rs移动端更大输入框P2

技术任务

Phase 1: 基础设施(P0)

任务 ID任务描述文件/路径预计工时
T6-1-1创建响应式工具模块src/utils/responsive.rs0.25d
T6-1-2实现窗口尺寸监听 Hooksrc/utils/use_window_size.rs0.5d
T6-1-3更新 Dioxus.toml 移除最小窗口限制Dioxus.toml0.1d
T6-1-4创建 AppLayout 组件src/components/layout/app_layout.rs0.5d
T6-1-5创建 BottomNavBar 组件src/components/layout/bottom_nav.rs0.5d
T6-1-6改造 Sidebar 支持折叠src/components/layout/sidebar.rs0.5d
T6-1-7改造 Modal 移动端全屏src/components/common/modal.rs0.25d

Phase 2: 核心页面适配(P1)

任务 ID任务描述文件/路径预计工时
T6-2-1首页 Dashboard 响应式src/pages/home.rs + dashboard/*0.5d
T6-2-2资产页响应式src/pages/assets.rs + asset/*0.5d
T6-2-3历史页响应式src/pages/history.rs + snapshot/*0.5d
T6-2-4配置页响应式src/pages/plans.rs + plan/*0.5d
T6-2-5收益页响应式src/pages/analysis.rs + analysis/*0.5d

Phase 3: 优化与测试(P2)

任务 ID任务描述文件/路径预计工时
T6-3-1通用组件触控优化src/components/common/*0.5d
T6-3-2表格移动端卡片化各表格组件0.5d
T6-3-3多设备测试与调整-0.5d

配置变更

Dioxus.toml

[application]
name = "asset-light"
default_platform = "desktop"

[desktop]
title = "asset-light - 个人资产管理"

[desktop.window]
title = "asset-light"
width = 1440
height = 900
# 移除最小尺寸限制以支持窗口缩放测试
# min_width = 1280  
# min_height = 720
resizable = true
decorations = true

验收标准

桌面端(≥1024px)

  • 侧边栏正常显示,布局与现有一致
  • 所有页面功能正常

平板端(768-1023px)

  • 侧边栏可折叠(点击汉堡按钮展开/收起)
  • 内容区自适应宽度
  • 表格/卡片自动调整列数

移动端(<768px)

  • 侧边栏隐藏,显示底部导航栏
  • 导航栏 5 个入口清晰可点击
  • 所有页面单列布局
  • 弹窗改为全屏页面
  • 触控区域足够大(最小 44×44px)
  • 无水平滚动条

通用

  • 窗口缩放时布局平滑过渡
  • 无样式错乱或重叠
  • 编译成功,无 warning

移动端 UI 示意

底部导航栏

┌────────────────────────────────────┐
│  📊     💰     📅     🎯     📈   │
│ 首页   资产   历史   配置   收益  │
└────────────────────────────────────┘

首页布局(移动端)

┌──────────────────────┐
│   总资产: ¥1,234,567  │
├──────────────────────┤
│  ┌────┐ ┌────┐      │
│  │现金│ │权益│ ...   │ ← 统计卡片横向滚动
│  └────┘ └────┘      │
├──────────────────────┤
│    [饼图 - 资产分布]   │
├──────────────────────┤
│  配置偏离 ▼           │
│  ├ 现金类 +5.2%       │
│  ├ 权益类 -3.1%       │
│  └ 固收类 -2.1%       │
├──────────────────────┤
│ 📊   💰   📅   🎯   📈 │ ← 底部导航
└──────────────────────┘

后续扩展

完成响应式改造后,可进一步:

  1. iOS/Android 打包:使用 Dioxus Mobile 或 Tauri 2.0
  2. PWA 支持:编译为 Web 版本,支持离线使用
  3. 手势交互:左滑删除、下拉刷新等移动端交互

参考资料


修订历史

版本日期作者变更说明
1.0.02025-01-11Leon创建响应式设计用户故事