68c2f5d8f1
- 品牌:更名 EDC|易得设计(exe/安卓/仓库 EasyDesignCollection;旧地址 301 兼容老客户端更新) - 首页:空白启动 + 六模块「新建文档」选择 + 最近打开;品牌菜单重做 - 架构图:手绘识别统一图形;Visio 式可扩展图元库(导入 / 存为图元 / 分类折叠 / 手绘匹配 / 多笔回溯组合);识别后图形尺寸编辑(宽高长径 + 画布标注 + 双击改值); IT 系统图元;mm 标尺(右轴数值 / 实线游标 / A0 默认画布);图层、F8 正交 / F10 极轴、 对齐均布;连线端点换绑重吸附;DXF / SVG / PNG 导出;缩小时画布溢出到侧栏的裁剪修复 - 时序图:分文件保存(*.seq.json / *.arch.json;旧 .edc.json 兼容) - 路径:运行时目录迁移 %APPDATA%/EDC;素材库 library/;安卓 Documents/EDC - 清理:参数化草图入口冻结;Windows Ink 原生桥移除;dist/ 退役 - 构建:exe + APK 双端同步(1.3.5+26);发布脚本切换 release/ 新目录结构
415 lines
14 KiB
Dart
415 lines
14 KiB
Dart
/// 首页(空白启动工作台):新建文档网格 + 打开文档 + 最近打开。
|
||
///
|
||
/// 触屏优先设计:大尺寸卡片与点按区(≥44px)、整页可滚动、不依赖悬停;
|
||
/// 手指 / 触控笔 / 鼠标三种输入一致可用(与画布体验保持一致)。
|
||
library;
|
||
|
||
import 'package:flutter/material.dart';
|
||
|
||
import '../modules/module_registry.dart';
|
||
import '../persistence/recent_store.dart';
|
||
import '../state/app_controller.dart';
|
||
import '../theme/tokens.dart';
|
||
import '../version.dart';
|
||
import 'app_logo.dart';
|
||
import 'update_icon.dart';
|
||
|
||
/// 首页视图。
|
||
class HomeView extends StatefulWidget {
|
||
/// 构造首页;各回调由外壳(AppShell)注入,负责实际的文档流程。
|
||
const HomeView({
|
||
super.key,
|
||
required this.controller,
|
||
required this.onNewModule,
|
||
required this.onOpenDocument,
|
||
required this.onOpenRecent,
|
||
required this.onOpenSettings,
|
||
required this.onOpenHelp,
|
||
});
|
||
|
||
/// 全局控制器(只读展示用)。
|
||
final AppController controller;
|
||
|
||
/// 新建某模块文档。
|
||
final void Function(EdcModule module) onNewModule;
|
||
|
||
/// 「打开文档…」(先选类型再选文件)。
|
||
final VoidCallback onOpenDocument;
|
||
|
||
/// 打开最近文件。
|
||
final void Function(EdcModule module, RecentDoc doc) onOpenRecent;
|
||
|
||
/// 软件设置。
|
||
final VoidCallback onOpenSettings;
|
||
|
||
/// 帮助中心。
|
||
final VoidCallback onOpenHelp;
|
||
|
||
/// 创建状态。
|
||
@override
|
||
State<HomeView> createState() => _HomeViewState();
|
||
}
|
||
|
||
/// 首页状态:异步加载最近打开列表。
|
||
class _HomeViewState extends State<HomeView> {
|
||
List<RecentDoc> _recent = const <RecentDoc>[];
|
||
|
||
/// 初始化:加载最近打开。
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_loadRecent();
|
||
}
|
||
|
||
Future<void> _loadRecent() async {
|
||
final List<RecentDoc> list = await RecentStore.load();
|
||
if (!mounted) return;
|
||
setState(() => _recent = list);
|
||
}
|
||
|
||
Future<void> _clearRecent() async {
|
||
await RecentStore.clear();
|
||
if (!mounted) return;
|
||
setState(() => _recent = const <RecentDoc>[]);
|
||
}
|
||
|
||
Future<void> _removeRecent(RecentDoc doc) async {
|
||
await RecentStore.remove(doc.path);
|
||
if (!mounted) return;
|
||
setState(() {
|
||
_recent = <RecentDoc>[
|
||
for (final RecentDoc r in _recent)
|
||
if (r.path != doc.path) r,
|
||
];
|
||
});
|
||
}
|
||
|
||
/// 构建。
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final Tokens t = context.tok;
|
||
return Scaffold(
|
||
backgroundColor: t.bg,
|
||
body: SafeArea(
|
||
child: Center(
|
||
child: ConstrainedBox(
|
||
constraints: const BoxConstraints(maxWidth: 980),
|
||
child: SingleChildScrollView(
|
||
padding: const EdgeInsets.fromLTRB(28, 26, 28, 30),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
_header(t),
|
||
const SizedBox(height: 22),
|
||
_sectionTitle(t, '新建文档', '选择要设计的文档类型'),
|
||
const SizedBox(height: 12),
|
||
Wrap(
|
||
spacing: 14,
|
||
runSpacing: 14,
|
||
children: <Widget>[
|
||
for (final EdcModule m in kModules)
|
||
_moduleCard(t, m),
|
||
],
|
||
),
|
||
const SizedBox(height: 24),
|
||
_sectionTitle(t, '打开已有文档', '支持 .seq.json / .arch.json(兼容旧版 .edc.json)'),
|
||
const SizedBox(height: 12),
|
||
Row(
|
||
children: <Widget>[
|
||
FilledButton.icon(
|
||
onPressed: widget.onOpenDocument,
|
||
icon: const Icon(Icons.folder_open, size: 18),
|
||
label: const Text('打开文档…'),
|
||
style: FilledButton.styleFrom(
|
||
minimumSize: const Size(148, 46),
|
||
backgroundColor: t.accent2,
|
||
),
|
||
),
|
||
const SizedBox(width: 14),
|
||
Expanded(
|
||
child: Text(
|
||
'也可以把文档文件拖到窗口打开(桌面版);'
|
||
'安卓版从公共目录选择。',
|
||
style: TextStyle(color: t.dim, fontSize: 11.5),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 24),
|
||
Row(
|
||
children: <Widget>[
|
||
Expanded(
|
||
child: _sectionTitle(
|
||
t, '最近打开', '点按继续上次的设计'),
|
||
),
|
||
if (_recent.isNotEmpty)
|
||
TextButton(
|
||
onPressed: _clearRecent,
|
||
style: TextButton.styleFrom(
|
||
minimumSize: const Size(64, 36),
|
||
),
|
||
child: Text('清空',
|
||
style:
|
||
TextStyle(color: t.dim, fontSize: 12)),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 8),
|
||
if (_recent.isEmpty)
|
||
Container(
|
||
width: double.infinity,
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: 16, vertical: 18),
|
||
decoration: BoxDecoration(
|
||
color: t.panel.withValues(alpha: 0.55),
|
||
borderRadius: BorderRadius.circular(12),
|
||
border: Border.all(color: t.line),
|
||
),
|
||
child: Text(
|
||
'还没有打开过文档。从上面选一个类型开始吧。',
|
||
style: TextStyle(color: t.dim, fontSize: 12),
|
||
),
|
||
)
|
||
else
|
||
for (final RecentDoc r in _recent) _recentRow(t, r),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 顶部:品牌 + 设置 / 帮助 / 检查更新。
|
||
Widget _header(Tokens t) {
|
||
return Row(
|
||
children: <Widget>[
|
||
const AppLogo(size: 46),
|
||
const SizedBox(width: 14),
|
||
Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Text(
|
||
'EDC|易得设计',
|
||
style: TextStyle(
|
||
color: t.text,
|
||
fontSize: 24,
|
||
fontWeight: FontWeight.w800,
|
||
letterSpacing: 1.2,
|
||
),
|
||
),
|
||
Text(
|
||
'工程总体设计合集(Easy Design Collection) v$kAppVersion',
|
||
style: TextStyle(color: t.dim, fontSize: 11.5),
|
||
),
|
||
],
|
||
),
|
||
const Spacer(),
|
||
_iconAction(t, Icons.settings_outlined, '软件设置', widget.onOpenSettings),
|
||
const SizedBox(width: 8),
|
||
_iconAction(t, Icons.help_outline, '帮助中心', widget.onOpenHelp),
|
||
const SizedBox(width: 8),
|
||
UpdateIcon(size: 36, color: t.sub),
|
||
],
|
||
);
|
||
}
|
||
|
||
/// 圆形图标按钮(触屏 ≥ 44px 点按区)。
|
||
Widget _iconAction(
|
||
Tokens t, IconData icon, String tip, VoidCallback onTap) {
|
||
return Tooltip(
|
||
message: tip,
|
||
child: InkWell(
|
||
onTap: onTap,
|
||
borderRadius: BorderRadius.circular(12),
|
||
child: Container(
|
||
width: 44,
|
||
height: 44,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(
|
||
color: t.panel,
|
||
borderRadius: BorderRadius.circular(12),
|
||
border: Border.all(color: t.line),
|
||
),
|
||
child: Icon(icon, size: 20, color: t.sub),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 分区标题。
|
||
Widget _sectionTitle(Tokens t, String title, String subtitle) {
|
||
return Row(
|
||
crossAxisAlignment: CrossAxisAlignment.end,
|
||
children: <Widget>[
|
||
Text(
|
||
title,
|
||
style: TextStyle(
|
||
color: t.text,
|
||
fontSize: 15,
|
||
fontWeight: FontWeight.w700,
|
||
),
|
||
),
|
||
const SizedBox(width: 10),
|
||
Padding(
|
||
padding: const EdgeInsets.only(bottom: 1.5),
|
||
child: Text(subtitle,
|
||
style: TextStyle(color: t.dim, fontSize: 11)),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
|
||
/// 模块卡片(未开放:灰显 + 角标,不可点)。
|
||
Widget _moduleCard(Tokens t, EdcModule m) {
|
||
final bool ok = m.available;
|
||
return InkWell(
|
||
onTap: ok ? () => widget.onNewModule(m) : null,
|
||
borderRadius: BorderRadius.circular(15),
|
||
child: Opacity(
|
||
opacity: ok ? 1 : 0.5,
|
||
child: Container(
|
||
width: 216,
|
||
height: 118,
|
||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 12),
|
||
decoration: BoxDecoration(
|
||
color: t.panel,
|
||
borderRadius: BorderRadius.circular(15),
|
||
border: Border.all(
|
||
color: ok ? t.line : t.line2,
|
||
width: ok ? 1.1 : 1,
|
||
),
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Row(
|
||
children: <Widget>[
|
||
Container(
|
||
width: 34,
|
||
height: 34,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(
|
||
color: Color(m.accent).withValues(alpha: 0.16),
|
||
borderRadius: BorderRadius.circular(9),
|
||
),
|
||
child: Icon(m.icon, size: 19, color: Color(m.accent)),
|
||
),
|
||
const Spacer(),
|
||
if (!ok)
|
||
Container(
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: 7, vertical: 2),
|
||
decoration: BoxDecoration(
|
||
color: t.panel2,
|
||
borderRadius: BorderRadius.circular(6),
|
||
border: Border.all(color: t.line2),
|
||
),
|
||
child: Text(
|
||
'未开放',
|
||
style: TextStyle(color: t.dim, fontSize: 10),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const Spacer(),
|
||
Text(
|
||
m.name,
|
||
style: TextStyle(
|
||
color: t.text,
|
||
fontSize: 14,
|
||
fontWeight: FontWeight.w700,
|
||
),
|
||
),
|
||
const SizedBox(height: 2),
|
||
Text(
|
||
m.blurb,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(color: t.dim, fontSize: 10.5),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 最近打开行(整行 ≥ 48px 点按区)。
|
||
Widget _recentRow(Tokens t, RecentDoc r) {
|
||
final EdcModule? m = moduleById(r.moduleId);
|
||
final Color accent = m == null ? t.accent2 : Color(m.accent);
|
||
final DateTime at = r.at;
|
||
final String when =
|
||
'${at.year}-${_two(at.month)}-${_two(at.day)} ${_two(at.hour)}:${_two(at.minute)}';
|
||
return Padding(
|
||
padding: const EdgeInsets.only(bottom: 8),
|
||
child: InkWell(
|
||
onTap: m == null ? null : () => widget.onOpenRecent(m, r),
|
||
borderRadius: BorderRadius.circular(11),
|
||
child: Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||
decoration: BoxDecoration(
|
||
color: t.panel,
|
||
borderRadius: BorderRadius.circular(11),
|
||
border: Border.all(color: t.line),
|
||
),
|
||
child: Row(
|
||
children: <Widget>[
|
||
Container(
|
||
width: 32,
|
||
height: 32,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(
|
||
color: accent.withValues(alpha: 0.14),
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
child: Icon(m?.icon ?? Icons.description_outlined,
|
||
size: 17, color: accent),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Expanded(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Text(
|
||
r.name,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(
|
||
color: t.text,
|
||
fontSize: 12.5,
|
||
fontWeight: FontWeight.w600,
|
||
),
|
||
),
|
||
Text(
|
||
'${m?.name ?? r.moduleId} · ${r.path}',
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(color: t.dim, fontSize: 10.5),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
const SizedBox(width: 10),
|
||
Text(when, style: TextStyle(color: t.dim, fontSize: 10.5)),
|
||
const SizedBox(width: 6),
|
||
InkWell(
|
||
onTap: () => _removeRecent(r),
|
||
borderRadius: BorderRadius.circular(8),
|
||
child: const Padding(
|
||
padding: EdgeInsets.all(6),
|
||
child: Icon(Icons.close, size: 15),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
static String _two(int v) => v < 10 ? '0$v' : '$v';
|
||
}
|