1.3.5:更名 EDC|易得设计,空白启动首页 + 可扩展图元库识别,架构图大版本
- 品牌:更名 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/ 新目录结构
This commit is contained in:
+714
-101
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,429 @@
|
||||
/// 左上角品牌按钮 +「EDC|易得设计」设计合集菜单。
|
||||
///
|
||||
/// 点开左上角 logo:菜单从 logo **下方**下拉展开(不遮挡 logo)。
|
||||
/// 菜单由模块注册表驱动:首页入口 + 已开放模块(可进入/新建)+
|
||||
/// 未开放模块(灰色显示,无「规划中」字样)+ 底部「软件设置」。
|
||||
/// 具体动作由外壳(AppShell)通过 [BrandMenuButton.onCommand] 执行:
|
||||
/// 命令为 `_home` / `_settings` / 模块 id。
|
||||
library;
|
||||
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../model/models.dart';
|
||||
import '../modules/module_registry.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import '../version.dart';
|
||||
import 'app_logo.dart';
|
||||
|
||||
/// 品牌按钮:logo + 当前模块名,点击在下方弹出合集菜单。
|
||||
class BrandMenuButton extends StatelessWidget {
|
||||
/// 构造品牌按钮。
|
||||
const BrandMenuButton({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.onCommand,
|
||||
this.scale = 1.0,
|
||||
this.compact = false,
|
||||
});
|
||||
|
||||
/// 全局应用控制器。
|
||||
final AppController controller;
|
||||
|
||||
/// 菜单命令回调(`_home` / `_settings` / 模块 id)。
|
||||
final Future<void> Function(String cmd) onCommand;
|
||||
|
||||
/// 工具栏缩放系数(触屏平台整体缩小)。
|
||||
final double scale;
|
||||
|
||||
/// 紧凑布局(隐藏副标题)。
|
||||
final bool compact;
|
||||
|
||||
/// 当前模块名(首页显示「设计合集」)。
|
||||
String get _label {
|
||||
final EdcModule? m = moduleOf(controller.appMode);
|
||||
return m == null ? '设计合集' : '${m.name}设计';
|
||||
}
|
||||
|
||||
/// 构建按钮。
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
final BorderRadius radius = BorderRadius.circular(10);
|
||||
return Tooltip(
|
||||
message: 'EDC|易得设计:设计合集',
|
||||
child: Material(
|
||||
color: t.panel,
|
||||
borderRadius: radius,
|
||||
child: InkWell(
|
||||
onTap: () => _open(context),
|
||||
borderRadius: radius,
|
||||
hoverColor: t.accent.withValues(alpha: 0.08),
|
||||
child: Container(
|
||||
// 高度只由内容决定:去掉上下留白(按钮高度 = 内容高度)。
|
||||
padding: EdgeInsets.only(left: 9 * scale, right: 9 * scale),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: radius,
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
AppLogo(size: (compact ? 22 : 24) * scale),
|
||||
SizedBox(width: 7 * scale),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
_label,
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: (compact ? 12.5 : 13) * scale,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0.5 * scale,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
if (!compact)
|
||||
Text(
|
||||
'Easy Design Collection',
|
||||
style: TextStyle(
|
||||
color: t.dim,
|
||||
fontSize: 9.5 * scale,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 4 * scale),
|
||||
Icon(Icons.arrow_drop_down, color: t.sub, size: 17 * scale),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 弹出合集菜单(logo 下方下拉,不遮挡 logo)。
|
||||
Future<void> _open(BuildContext context) async {
|
||||
final RenderBox button = context.findRenderObject()! as RenderBox;
|
||||
final OverlayState overlay = Overlay.of(context);
|
||||
final RenderBox overlayBox =
|
||||
overlay.context.findRenderObject()! as RenderBox;
|
||||
final Offset tl = button.localToGlobal(Offset.zero, ancestor: overlayBox);
|
||||
final Offset br = button.localToGlobal(
|
||||
button.size.bottomRight(Offset.zero),
|
||||
ancestor: overlayBox);
|
||||
const double menuW = 204;
|
||||
final double left = tl.dx
|
||||
.clamp(8.0, math.max(8.0, overlayBox.size.width - menuW - 8));
|
||||
final double top = br.dy + 6;
|
||||
final Object? picked = await showGeneralDialog<Object>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '关闭菜单',
|
||||
barrierColor: Colors.black.withValues(alpha: 0.06),
|
||||
transitionDuration: const Duration(milliseconds: 150),
|
||||
pageBuilder: (BuildContext ctx, Animation<double> a1,
|
||||
Animation<double> a2) =>
|
||||
const SizedBox.shrink(),
|
||||
transitionBuilder: (BuildContext ctx, Animation<double> anim,
|
||||
Animation<double> sec, Widget child) {
|
||||
final Animation<double> curved =
|
||||
CurvedAnimation(parent: anim, curve: Curves.easeOutCubic);
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
Positioned(
|
||||
left: left,
|
||||
top: top,
|
||||
child: FadeTransition(
|
||||
opacity: curved,
|
||||
child: ScaleTransition(
|
||||
scale: Tween<double>(begin: 0.96, end: 1).animate(curved),
|
||||
alignment: Alignment.topLeft,
|
||||
child: _panel(ctx),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
if (picked is String && context.mounted) {
|
||||
await onCommand(picked);
|
||||
}
|
||||
}
|
||||
|
||||
/// 菜单底部「软件设置」入口。
|
||||
Widget _settingsItem(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
return InkWell(
|
||||
onTap: () => Navigator.of(context).pop('_settings'),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel2,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: t.line),
|
||||
),
|
||||
child: Icon(Icons.settings_outlined, size: 17, color: t.sub),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text('软件设置',
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
)),
|
||||
Text('外观 · 网格 · 更新',
|
||||
style: TextStyle(color: t.dim, fontSize: 10.5)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(Icons.chevron_right, size: 16, color: t.dim),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 菜单面板(品牌头部 + 首页 + 模块注册表 + 未开放模块 + 软件设置)。
|
||||
Widget _panel(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
final bool atHome = controller.appMode == AppMode.home;
|
||||
final String? curId = moduleOf(controller.appMode)?.id;
|
||||
final double maxH = math.max(
|
||||
180,
|
||||
MediaQuery.sizeOf(context).height - 120,
|
||||
);
|
||||
return Material(
|
||||
color: t.dialog,
|
||||
elevation: 14,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: Container(
|
||||
width: 204,
|
||||
constraints: BoxConstraints(maxHeight: maxH),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 6, 12, 8),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text('EDC|易得设计',
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
)),
|
||||
const Spacer(),
|
||||
Text('v$kAppVersion',
|
||||
style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Divider(height: 1, thickness: 1, color: t.line),
|
||||
const SizedBox(height: 6),
|
||||
// 首页(空白启动工作台)。
|
||||
_homeItem(context, atHome),
|
||||
const SizedBox(height: 6),
|
||||
Divider(height: 1, thickness: 1, color: t.line),
|
||||
const SizedBox(height: 4),
|
||||
// 已开放模块(可通过「设计合集」进入并新建文档)。
|
||||
for (final EdcModule m in kModules)
|
||||
if (m.available) _item(context, m, current: curId == m.id),
|
||||
const SizedBox(height: 6),
|
||||
Divider(height: 1, thickness: 1, color: t.line),
|
||||
// 未开放模块:仅灰色显示。
|
||||
for (final EdcModule m in kModules)
|
||||
if (!m.available) _soon(context, m),
|
||||
const SizedBox(height: 6),
|
||||
Divider(height: 1, thickness: 1, color: t.line),
|
||||
const SizedBox(height: 4),
|
||||
_settingsItem(context),
|
||||
const SizedBox(height: 4),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 「首页」条目。
|
||||
Widget _homeItem(BuildContext context, bool current) {
|
||||
final Tokens t = context.tok;
|
||||
return InkWell(
|
||||
onTap: () => Navigator.of(context).pop('_home'),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: current ? t.accent.withValues(alpha: 0.16) : t.panel2,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: current ? t.accent : t.line),
|
||||
),
|
||||
child:
|
||||
Icon(Icons.home_outlined, size: 17, color: current ? t.accent : t.sub),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'首页',
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: 12.5,
|
||||
fontWeight:
|
||||
current ? FontWeight.w700 : FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text('新建 · 打开 · 最近',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.dim, fontSize: 10.5)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (current) Icon(Icons.check_circle, size: 16, color: t.accent),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 已开放模块条目(点按 = 进入该模块并新建文档)。
|
||||
Widget _item(
|
||||
BuildContext context,
|
||||
EdcModule m, {
|
||||
required bool current,
|
||||
}) {
|
||||
final Tokens t = context.tok;
|
||||
return InkWell(
|
||||
onTap: () => Navigator.of(context).pop(m.id),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: current
|
||||
? t.accent.withValues(alpha: 0.16)
|
||||
: Color(m.accent).withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: current ? t.accent : t.line),
|
||||
),
|
||||
child: Icon(m.icon,
|
||||
size: 17, color: current ? t.accent : Color(m.accent)),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'${m.name}设计',
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: 12.5,
|
||||
fontWeight:
|
||||
current ? FontWeight.w700 : FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
m.blurb,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.dim, fontSize: 10.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (current) Icon(Icons.check_circle, size: 16, color: t.accent),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 未开放模块:仅灰色显示(不可点)。
|
||||
Widget _soon(BuildContext context, EdcModule m) {
|
||||
final Tokens t = context.tok;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 26,
|
||||
height: 26,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel2.withValues(alpha: 0.6),
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
border: Border.all(color: t.line.withValues(alpha: 0.6)),
|
||||
),
|
||||
child: Icon(m.icon, size: 15, color: t.dim.withValues(alpha: 0.75)),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(m.name,
|
||||
style: TextStyle(
|
||||
color: t.dim.withValues(alpha: 0.75),
|
||||
fontSize: 12,
|
||||
)),
|
||||
Text(m.blurb,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: t.dim.withValues(alpha: 0.55),
|
||||
fontSize: 10,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+467
-20
@@ -4,7 +4,7 @@
|
||||
// 向下通过 AppController 读写项目状态、通过 dart:io 访问文件系统。
|
||||
// 包含:
|
||||
// · 通用消息提示(showMessage);
|
||||
// · .seq.json 文件浏览/保存对话框(FileBrowserDialog / pickFile);
|
||||
// · .edc.json 文件浏览/保存对话框(FileBrowserDialog / pickFile);
|
||||
// · 动作编辑、依赖编辑、文档设置、帮助中心等业务对话框。
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
@@ -14,12 +14,15 @@ import 'package:flutter/material.dart' hide Action;
|
||||
import '../license/license_service.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../modules/module_registry.dart';
|
||||
import '../persistence/android_docs.dart';
|
||||
import '../persistence/storage.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import '../update/update_service.dart';
|
||||
import '../version.dart';
|
||||
import 'app_logo.dart';
|
||||
import 'update_dialog.dart';
|
||||
|
||||
// ===================== 对话框等比缩放 =====================
|
||||
|
||||
@@ -70,7 +73,7 @@ Future<void> showMessage(BuildContext context, String title, String message) {
|
||||
|
||||
// ===================== 文件浏览 / 保存对话框 =====================
|
||||
|
||||
/// 文件浏览对话框:用于打开或另存为文件(工程 `.seq.json`、导出 `.svg` / `.png`)。
|
||||
/// 文件浏览对话框:用于打开或另存为文件(设计文档 `.seq.json` / `.arch.json`、导出 `.svg` / `.png` / `.dxf`)。
|
||||
///
|
||||
/// [saveMode] 为 true 时进入保存流程,否则为打开流程;[suffix] 决定文件过滤
|
||||
/// 与保存时自动补全的后缀;[defaultName] 为保存模式的默认文件名。
|
||||
@@ -80,7 +83,7 @@ class FileBrowserDialog extends StatefulWidget {
|
||||
required this.saveMode,
|
||||
this.initialPath,
|
||||
this.defaultName,
|
||||
this.suffix = '.seq.json',
|
||||
this.suffix = '.edc.json',
|
||||
});
|
||||
|
||||
/// 是否为保存模式(true = 另存为,false = 打开)。
|
||||
@@ -89,7 +92,7 @@ class FileBrowserDialog extends StatefulWidget {
|
||||
final String? initialPath;
|
||||
/// 保存模式的默认文件名(如 `装配线节拍.svg`)。
|
||||
final String? defaultName;
|
||||
/// 文件后缀:过滤目录列表并自动补全用户输入(如 `.svg` / `.png` / `.seq.json`)。
|
||||
/// 文件后缀:过滤目录列表并自动补全用户输入(如 `.svg` / `.png` / `.edc.json`)。
|
||||
final String suffix;
|
||||
|
||||
/// 创建文件浏览对话框对应的状态对象。
|
||||
@@ -115,7 +118,7 @@ class _FileBrowserDialogState extends State<FileBrowserDialog> {
|
||||
final String base = widget.defaultName ??
|
||||
(widget.initialPath != null && widget.initialPath!.isNotEmpty
|
||||
? widget.initialPath!.split(RegExp(r'[\\/]')).last
|
||||
: '节拍方案${widget.suffix}');
|
||||
: '未命名设计${widget.suffix}');
|
||||
_name = TextEditingController(text: base);
|
||||
_bootstrap();
|
||||
}
|
||||
@@ -175,7 +178,7 @@ class _FileBrowserDialogState extends State<FileBrowserDialog> {
|
||||
String _ensureSuffix(String raw) {
|
||||
String n = raw.trim();
|
||||
if (n.isEmpty) return n;
|
||||
const List<String> known = <String>['.seq.json', '.json', '.svg', '.png'];
|
||||
const List<String> known = <String>['.arch.json', '.edc.json', '.seq.json', '.json', '.svg', '.png', '.dxf'];
|
||||
for (final String k in known) {
|
||||
if (n.toLowerCase().endsWith(k)) {
|
||||
if (k == widget.suffix) return n;
|
||||
@@ -193,7 +196,15 @@ class _FileBrowserDialogState extends State<FileBrowserDialog> {
|
||||
final List<FileSystemEntity> all = _dir.listSync();
|
||||
_entries = all.where((FileSystemEntity e) {
|
||||
if (e is Directory) return true;
|
||||
return e.path.toLowerCase().endsWith(widget.suffix.toLowerCase());
|
||||
final String p = e.path.toLowerCase();
|
||||
// 设计文档同时兼容旧的 .edc.json / .seq.json;其它后缀按后缀精确过滤。
|
||||
if (widget.suffix.toLowerCase().contains('json')) {
|
||||
return p.endsWith('.edc.json') ||
|
||||
p.endsWith('.seq.json') ||
|
||||
p.endsWith('.arch.json') ||
|
||||
p.endsWith('.json');
|
||||
}
|
||||
return p.endsWith(widget.suffix.toLowerCase());
|
||||
}).toList()
|
||||
..sort((FileSystemEntity a, FileSystemEntity b) {
|
||||
final bool ad = a is Directory;
|
||||
@@ -403,13 +414,13 @@ class _FileBrowserDialogState extends State<FileBrowserDialog> {
|
||||
/// 打开文件选择对话框并返回所选路径。
|
||||
///
|
||||
/// [save] 决定保存或打开模式;[suffix] 决定文件过滤与自动补全的后缀
|
||||
/// (`.seq.json` / `.svg` / `.png`);[defaultName] 为保存模式的默认文件名。
|
||||
/// (`.edc.json` / `.svg` / `.png`);[defaultName] 为保存模式的默认文件名。
|
||||
Future<String?> pickFile(
|
||||
BuildContext context, {
|
||||
required bool save,
|
||||
String? initialPath,
|
||||
String? defaultName,
|
||||
String suffix = '.seq.json',
|
||||
String suffix = '.edc.json',
|
||||
}) {
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
@@ -447,7 +458,7 @@ class _SaveLocationDialogState extends State<SaveLocationDialog> {
|
||||
super.initState();
|
||||
final Map<String, String> s = AndroidDocs.settings();
|
||||
_base = s['base'] ?? 'documents';
|
||||
_folder = TextEditingController(text: s['folder'] ?? 'SequenceDiagram');
|
||||
_folder = TextEditingController(text: s['folder'] ?? AndroidDocs.defaultFolder);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -513,7 +524,7 @@ class _SaveLocationDialogState extends State<SaveLocationDialog> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 安卓版文件对话框:保存到 / 打开自配置的公共目录(默认 Documents/SequenceDiagram)。
|
||||
/// 安卓版文件对话框:保存到 / 打开自配置的公共目录(默认 Documents/EDC,兼容旧目录 SequenceDiagram)。
|
||||
///
|
||||
/// - 保存模式:显示当前保存位置(可点「更改位置」修改),输入文件名自动补全后缀;
|
||||
/// - 打开模式:列出目录中匹配后缀的文件,点选返回文件名。
|
||||
@@ -580,7 +591,7 @@ class _AndroidFileDialogState extends State<AndroidFileDialog> {
|
||||
String _ensureSuffix(String raw) {
|
||||
String n = raw.trim();
|
||||
if (n.isEmpty) return n;
|
||||
const List<String> known = <String>['.seq.json', '.json', '.svg', '.png'];
|
||||
const List<String> known = <String>['.arch.json', '.edc.json', '.seq.json', '.json', '.svg', '.png', '.dxf'];
|
||||
for (final String k in known) {
|
||||
if (n.toLowerCase().endsWith(k)) {
|
||||
if (k == widget.suffix) return n;
|
||||
@@ -2036,6 +2047,442 @@ class _StationRowState extends State<_StationRow> {
|
||||
|
||||
/// 帮助中心对话框:以四个标签页展示快速开始、快捷键、
|
||||
/// 双视图说明以及单位与导出等信息。
|
||||
/// 软件设置:集中设置入口(外观 / 文档默认 / 架构图网格 / 更新)。
|
||||
///
|
||||
/// 从左上角「EDC|易得设计」菜单底部的「软件设置」打开;文档级的完整设置
|
||||
/// (单位 / 循环 / 相位等)仍在「文档设置」(F2 / 左侧栏)里。
|
||||
class SoftwareSettingsDialog extends StatefulWidget {
|
||||
/// 构造软件设置对话框。
|
||||
const SoftwareSettingsDialog({super.key, required this.controller});
|
||||
|
||||
/// 全局应用控制器。
|
||||
final AppController controller;
|
||||
|
||||
/// 创建状态对象。
|
||||
@override
|
||||
State<SoftwareSettingsDialog> createState() => _SoftwareSettingsDialogState();
|
||||
}
|
||||
|
||||
/// 软件设置对话框状态。
|
||||
class _SoftwareSettingsDialogState extends State<SoftwareSettingsDialog> {
|
||||
/// 控制器快捷访问。
|
||||
AppController get c => widget.controller;
|
||||
|
||||
/// 检查更新:发现新版本直接弹更新对话框。
|
||||
Future<void> _checkUpdate() async {
|
||||
c.setStatus('正在检查更新…');
|
||||
try {
|
||||
final UpdateInfo? info = await UpdateService.check();
|
||||
if (!mounted) return;
|
||||
if (info == null) {
|
||||
c.setStatus('已是最新版本(v$kAppVersion)');
|
||||
await showMessage(context, '检查更新', '当前已是最新版本(v$kAppVersion)。');
|
||||
return;
|
||||
}
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => UpdateDialog(controller: c, info: info),
|
||||
);
|
||||
} catch (e) {
|
||||
if (mounted) await showMessage(context, '检查更新失败', '$e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 渲染设置表单。
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
return Dialog(
|
||||
backgroundColor: t.dialog,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
child: scaledDialogBox(
|
||||
context,
|
||||
680,
|
||||
600,
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text('软件设置',
|
||||
style: TextStyle(
|
||||
fontSize: 17, fontWeight: FontWeight.w700, color: t.text)),
|
||||
const SizedBox(width: 14),
|
||||
Text('外观 / 文档默认 / 架构图网格 / 更新',
|
||||
style: TextStyle(fontSize: 11, color: t.dim)),
|
||||
const Spacer(),
|
||||
Text('v$kAppVersion', style: TextStyle(fontSize: 11, color: t.dim)),
|
||||
],
|
||||
),
|
||||
const Divider(height: 24),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
_section(t, '外观'),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: _optCard(
|
||||
t,
|
||||
active: c.brightness == Brightness.light,
|
||||
title: '浅色主题',
|
||||
subtitle: '白底 · 打印 / 工艺卡友好',
|
||||
onTap: () => c.setTheme(Brightness.light),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: _optCard(
|
||||
t,
|
||||
active: c.brightness == Brightness.dark,
|
||||
title: '深色主题',
|
||||
subtitle: '暗光环境护眼',
|
||||
onTap: () => c.setTheme(Brightness.dark),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
_section(t, '文档默认'),
|
||||
_rowSwitch(
|
||||
t,
|
||||
'保留空泳道',
|
||||
'动作全部移走的泳道保留(序号不变;关闭则自动移除)',
|
||||
c.project.keepEmptyLanes,
|
||||
(bool v) => c.setKeepEmptyLanes(v),
|
||||
),
|
||||
_rowSwitch(
|
||||
t,
|
||||
'自动保存',
|
||||
'保存过一次路径后按间隔写回文件(同步 .bak 备份)',
|
||||
c.project.autoSaveEnabled,
|
||||
(bool v) => c.setAutoSave(enabled: v),
|
||||
),
|
||||
if (c.project.autoSaveEnabled)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text('间隔', style: TextStyle(color: t.sub, fontSize: 11)),
|
||||
const SizedBox(width: 10),
|
||||
for (final int m in <int>[1, 5, 10, 30])
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: _chip(
|
||||
t,
|
||||
'$m 分钟',
|
||||
c.project.autoSaveMinutes == m,
|
||||
() => c.setAutoSave(minutes: m),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_section(t, '架构图网格'),
|
||||
_rowSwitch(
|
||||
t,
|
||||
'吸附网格',
|
||||
'识别 / 移动 / 缩放优先对位到网格',
|
||||
c.arch.gridSnap,
|
||||
(bool v) => c.setArchGrid(snap: v),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text('粒度', style: TextStyle(color: t.sub, fontSize: 11)),
|
||||
const SizedBox(width: 10),
|
||||
for (final double g in <double>[10, 20, 40, 80])
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: _chip(
|
||||
t,
|
||||
'${g.round()} px',
|
||||
c.arch.gridSize == g,
|
||||
() => c.setArchGrid(size: g),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
_section(t, '更新'),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text('当前版本 v$kAppVersion;检查到新版本可直接升级。',
|
||||
style: TextStyle(color: t.dim, fontSize: 11)),
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: _checkUpdate,
|
||||
child: const Text('检查更新'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('完成'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 小节标题。
|
||||
Widget _section(Tokens t, String s) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
s,
|
||||
style: TextStyle(
|
||||
color: t.text2,
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// 选项卡片(主题等二选一)。
|
||||
Widget _optCard(
|
||||
Tokens t, {
|
||||
required bool active,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? t.accent.withValues(alpha: 0.14) : t.panel2,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: active ? t.accent : t.line,
|
||||
width: active ? 1.3 : 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: active ? t.accent : t.text,
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(subtitle, style: TextStyle(color: t.dim, fontSize: 10.5)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 开关行。
|
||||
Widget _rowSwitch(
|
||||
Tokens t,
|
||||
String title,
|
||||
String desc,
|
||||
bool value,
|
||||
ValueChanged<bool> onChanged,
|
||||
) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(title,
|
||||
style: TextStyle(
|
||||
color: t.text, fontSize: 12, fontWeight: FontWeight.w600)),
|
||||
Text(desc,
|
||||
style: TextStyle(color: t.dim, fontSize: 10.5, height: 1.4)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Switch(
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 粒度 / 间隔小圆片。
|
||||
Widget _chip(Tokens t, String label, bool active, VoidCallback onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? t.accent.withValues(alpha: 0.16) : t.panel2,
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
border: Border.all(color: active ? t.accent : t.line),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: active ? t.accent : t.sub,
|
||||
fontSize: 10.5,
|
||||
fontWeight: active ? FontWeight.w700 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 通用文本编辑对话框(图形文字 / 连线标签共用)。
|
||||
///
|
||||
/// 返回新文本;取消返回 null。
|
||||
/// 「打开文档…」的文档类型选择:列出全部模块(未开放灰显不可选)。
|
||||
///
|
||||
/// 返回所选模块;用户取消返回 null。
|
||||
Future<EdcModule?> showDocumentTypeDialog(BuildContext context) async {
|
||||
return showDialog<EdcModule>(
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
final Tokens t = ctx.tok;
|
||||
return AlertDialog(
|
||||
backgroundColor: t.dialog,
|
||||
title: Text('打开文档',
|
||||
style: TextStyle(
|
||||
color: t.text, fontSize: 15, fontWeight: FontWeight.w700)),
|
||||
content: SizedBox(
|
||||
width: 400,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
for (final EdcModule m in kModules)
|
||||
InkWell(
|
||||
onTap: m.available ? () => Navigator.pop(ctx, m) : null,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
child: Opacity(
|
||||
opacity: m.available ? 1 : 0.5,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 8),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(m.accent).withValues(alpha: 0.14),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child:
|
||||
Icon(m.icon, size: 17, color: Color(m.accent)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(m.name,
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
)),
|
||||
Text(
|
||||
'文档后缀 ${m.suffix}'
|
||||
'${m.available ? '' : ' · 未开放'}',
|
||||
style: TextStyle(
|
||||
color: t.dim, fontSize: 10.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx), child: const Text('取消')),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> showTextEditDialog(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String initial,
|
||||
}) async {
|
||||
final TextEditingController ctrl = TextEditingController(text: initial);
|
||||
final String? result = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
final Tokens t = ctx.tok;
|
||||
return AlertDialog(
|
||||
backgroundColor: t.dialog,
|
||||
title: Text(title,
|
||||
style: TextStyle(
|
||||
color: t.text, fontSize: 15, fontWeight: FontWeight.w700)),
|
||||
content: SizedBox(
|
||||
width: 380,
|
||||
child: TextField(
|
||||
controller: ctrl,
|
||||
autofocus: true,
|
||||
minLines: 1,
|
||||
maxLines: 4,
|
||||
style: TextStyle(color: t.text, fontSize: 13),
|
||||
decoration: InputDecoration(
|
||||
hintText: '输入文字(可多行)',
|
||||
hintStyle: TextStyle(color: t.dim, fontSize: 12),
|
||||
filled: true,
|
||||
fillColor: t.panel2,
|
||||
border:
|
||||
OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
onSubmitted: (String v) => Navigator.of(ctx).pop(v),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(), child: const Text('取消')),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(ctrl.text),
|
||||
child: const Text('确定')),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
ctrl.dispose();
|
||||
return result;
|
||||
}
|
||||
|
||||
class HelpDialog extends StatelessWidget {
|
||||
const HelpDialog({super.key});
|
||||
|
||||
@@ -2084,7 +2531,7 @@ class HelpDialog extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
// 目标:完成方案的搭建与动作的增删改。
|
||||
_section(t, <List<String>>[
|
||||
<String>['我要新建方案', '顶部「新建」创建空白节拍;「打开」载入 .seq.json。'],
|
||||
<String>['我要新建方案', '顶部「新建」创建空白设计;「打开」按时序 / 架构模块分别载入 .seq.json / .arch.json(兼容旧版 .edc.json)。'],
|
||||
<String>['我要先看看示例', '首次启动载入 5 个动作的示例节拍(装配线节拍),可直接修改。'],
|
||||
<String>['我要新增动作', '双击画布空白处在点击相位新增;或左侧「新建」在 0° 新增(默认最外层)。'],
|
||||
<String>['我要删除动作', '选中后:左侧「删除」/ 行内删除图标 / Delete 键 / 右键菜单;至少保留一个动作 / 泳道。'],
|
||||
@@ -2129,7 +2576,7 @@ class HelpDialog extends StatelessWidget {
|
||||
<String>['我要导出 SVG', '顶部「导出」下拉菜单 →「导出 SVG」:矢量、分层、带语义 id 与 data-*,可直接进工艺卡 / MES。'],
|
||||
<String>['我要导出 PNG', '顶部「导出」下拉菜单 →「导出 PNG」:按 2 倍像素比导出当前视图为位图。'],
|
||||
<String>['我要导出 drawio', '流程图视图专用:顶部「导出」→「导出 drawio」,输出 diagrams.net(draw.io)可继续编辑的工程文件。'],
|
||||
<String>['我要保存 / 恢复', '「保存」写入 .seq.json 并生成 .bak;每 5 秒自动快照(异常退出可恢复);F2 文档设置中可开启「自动保存」(默认每 10 分钟一次,需先手动保存过一次路径)。'],
|
||||
<String>['我要保存 / 恢复', '「保存」按时序 / 架构模块分别写入 .seq.json / .arch.json 并生成 .bak;每 5 秒自动快照(异常退出可恢复);「软件设置」中可开启「自动保存」(默认每 10 分钟一次,需先手动保存过一次路径)。'],
|
||||
]),
|
||||
// 目标:调整界面与使用快捷键。
|
||||
_section(t, <List<String>>[
|
||||
@@ -2222,10 +2669,10 @@ class HelpDialog extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text('时序图设计 · Sequence Diagram Studio',
|
||||
Text('EDC|易得设计 · Easy Design Collection',
|
||||
style: TextStyle(color: t.text, fontSize: 15, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 4),
|
||||
Text('V1.3.4(${android ? '安卓版' : 'Windows 版'})',
|
||||
Text('V$kAppVersion(${android ? '安卓版' : 'Windows 版'})',
|
||||
style: TextStyle(color: t.dim, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
@@ -2243,9 +2690,9 @@ class HelpDialog extends StatelessWidget {
|
||||
// 注意:绝不能展示「期望授权串」——它等同于 .lic 内容,公开即可被绕过授权。
|
||||
row('本机 MAC', info.mac ?? '读取失败'),
|
||||
row('版权声明', 'Copyright © 2026 EDC(Easy Design Collection)呆头鹅。保留所有权利。'),
|
||||
row('产品简介', '面向 PLC 流程节拍 / 相位角设计的设计工具:条形 / 圆周 / 流程图三视图、'
|
||||
'FS / SS 依赖与关键路径、泳道加宽(多槽位)与空泳道策略、依赖走线可调、'
|
||||
'支持导出 SVG / PNG / drawio,成果可直接进工艺卡与 MES。'),
|
||||
row('产品简介', '设计合集(Easy Design Collection):时序图设计面向 PLC 流程节拍 / '
|
||||
'相位角设计(条形 / 圆周 / 流程图三视图、FS / SS 依赖与关键路径、泳道加宽);'
|
||||
'架构图设计支持手绘识别标准图形、正交连线与标签;支持导出 SVG / PNG / drawio。'),
|
||||
const SizedBox(height: 6),
|
||||
// 官网入口(点击导航到 sincos.cc)。
|
||||
Row(
|
||||
@@ -2316,7 +2763,7 @@ class HelpDialog extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
guideLine('本版面向应用商店分发,无需授权,全部功能可用。'),
|
||||
guideLine('保存 / 导出文件位于「文件管理」可见的公共目录(默认 Documents/SequenceDiagram,'
|
||||
guideLine('保存 / 导出文件位于「文件管理」可见的公共目录(默认 Documents/EDC,'
|
||||
'可在保存对话框中更改位置)。'),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
/// 首页(空白启动工作台):新建文档网格 + 打开文档 + 最近打开。
|
||||
///
|
||||
/// 触屏优先设计:大尺寸卡片与点按区(≥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';
|
||||
}
|
||||
Reference in New Issue
Block a user