feat(flow): 泳道拓宽计划(空泳道策略 + 多槽位泳道,三视图同步);发布 v1.3.4

- 空泳道策略(F2 文档设置 →「泳道」):动作全部移走的泳道可保留(默认,序号不变)
  或自动移除;条形空行 / 圆周空环 / 流程空列与左侧栏占位行同步
- 泳道加宽(1–5 槽):双击条形视图左侧泳道编号 / 右键空白泳道 / 左侧栏「N 槽」徽标;
  条形分子行(浅色虚线分隔)、圆周同色加宽环带 + 槽位虚线、流程图分子列且泳道带
  随内容智能加宽;拖拽动作同时换道 + 换槽位;旧数据零迁移(row 语义改为槽位并自动钳制)
- 流程图智能排开:同源同层扇出连线在空隙内均匀铺开;同层节点水平重叠自动推开
- 显示修复:画布左栏标题按真实行高排版(灰色副标题不再被换行标题压住,
  持续换行到泳道高度不足);多槽位采用「槽位紧凑 + 泳道间拉开」的间隔
- 「时序创建和编辑」更名为「文档设置」(含对话框标题/帮助/文档);新增自动保存
  (默认 10 分钟,可选 1/5/10/30 或关闭;写入文件并同步 .bak)
- 授权临时冻结(kLicenseRequired=false):桌面版导出无需 .lic;关于页授权状态
  「开放授权版本」、EDC 版权、开发者与交流群(邮箱 liuyu65@126.com、微信 online-goose)
- 更新体验:直接升级到最新版本提示、下载过程保持屏幕常亮提示、
  下载/上传统一限速 320KB/s(客户端限速 + 发布脚本 --limit-rate 320k)
- docs/HELP.md 与帮助中心同步更新;新增 docs/ROADMAP.md 开发路线图
- flutter analyze 0 问题、40 项测试全过;演示截图更新(含泳道加宽与拥挤场景验证图)
This commit is contained in:
2026-10-10 09:21:45 +08:00
parent b902fa06c4
commit fe5e0be131
27 changed files with 1390 additions and 245 deletions
+144 -16
View File
@@ -9,10 +9,14 @@
library;
import 'dart:async';
import 'dart:convert';
import 'dart:math' as math;
import 'dart:typed_data';
import 'package:flutter/material.dart' hide Action;
import '../persistence/android_docs.dart';
import '../version.dart';
import '../layout/dep_routes.dart';
import '../layout/layout.dart';
import '../layout/flow_layout.dart';
@@ -27,7 +31,7 @@ class AppController extends ChangeNotifier {
/// 参数 [project]:初始项目;为 null 时使用 [Project.demo] 并标记为已修改
/// (因为演示数据尚未保存到文件)。
AppController({Project? project})
: _project = project ?? Project.demo(),
: _project = _syncLaneFloor(project ?? Project.demo()),
_dirty = project == null;
/// 当前项目数据(唯一可变引用,替换时整体赋值)。
@@ -36,11 +40,14 @@ class AppController extends ChangeNotifier {
/// 当前主题亮度(默认浅色 / 白底)。
Brightness _brightness = Brightness.light;
/// 是否已获得有效授权(有效时才允许导出 SVG / PNG)。
/// 是否已获得有效授权(有效时才允许导出 SVG / PNG / drawio)。
///
/// 1.3.4 起授权校验临时冻结([kLicenseRequired] = false):始终视为已授权,
/// 待功能丰富后再恢复校验。
bool _licensed = false;
/// 是否已授权。
bool get licensed => _licensed;
/// 是否已授权(授权冻结期间恒为 true)。
bool get licensed => !kLicenseRequired || _licensed;
/// 设置授权状态并刷新(启动时校验 / 重新读取 .lic 后调用)。
void setLicensed(bool value) {
@@ -154,6 +161,10 @@ class AppController extends ChangeNotifier {
}
/// 自动保存当前项目(内部方法,异常静默忽略以避免打断编辑)。
///
/// 同时承担两件事:
/// 1. 崩溃恢复快照(每 5 秒写入 Storage,与文档文件无关);
/// 2. 文档自动保存(按 [Project.autoSaveMinutes] 的间隔把文档写回文件)。
Future<void> _autosave() async {
try {
await Storage.instance.writeAutosave(
@@ -162,6 +173,54 @@ class AppController extends ChangeNotifier {
clean: !_dirty,
);
} catch (_) {}
await _autoSaveDocument();
}
/// 文档自动保存:启用、已保存过路径且有未保存修改时,按间隔写回文件。
///
/// - 间隔 = [Project.autoSaveMinutes](默认 10 分钟,1–240);
/// - 以 [_lastSavedAt] 为基准:任何一次手动 / 自动保存都会重置计时;
/// - 安卓写入公共 Documents,桌面写 `.seq.json` 并同步 `.bak` 备份。
Future<void> _autoSaveDocument() async {
final String? path = _filePath;
if (!_project.autoSaveEnabled || !_dirty || path == null) return;
final DateTime now = DateTime.now();
// 从未保存过时间戳(如刚打开文件):以“现在”为基准,等满一个间隔再自动保存。
if (_lastSavedAt == null) {
_lastSavedAt = now;
return;
}
final int minutes =
_project.autoSaveMinutes < 1 ? 1 : (_project.autoSaveMinutes > 240 ? 240 : _project.autoSaveMinutes);
if (now.difference(_lastSavedAt!).inSeconds < minutes * 60) return;
_lastSavedAt = now;
try {
if (AndroidDocs.isAvailable) {
await AndroidDocs.saveFile(
_baseName(path),
Uint8List.fromList(utf8.encode(_project.encode())),
mime: 'application/json',
);
} else {
await Storage.instance.saveProject(path, _project);
}
_dirty = false;
_status = '已自动保存 ${_baseName(path)}';
} catch (_) {
_status = '自动保存失败(可手动 Ctrl+S 重试)';
}
notifyListeners();
}
/// 设置自动保存(开关与间隔分钟;间隔钳制到 1–240)。
void setAutoSave({bool? enabled, int? minutes}) {
final bool e = enabled ?? _project.autoSaveEnabled;
final int m = (minutes ?? _project.autoSaveMinutes).clamp(1, 240);
if (e == _project.autoSaveEnabled && m == _project.autoSaveMinutes) return;
_project = _project.copyWith(autoSaveEnabled: e, autoSaveMinutes: m);
_dirty = true;
_status = e ? '自动保存:每 $m 分钟' : '自动保存:已关闭';
notifyListeners();
}
/// 退出前将自动保存标记为“干净”,表示已正常关闭无需恢复。
@@ -189,13 +248,28 @@ class AppController extends ChangeNotifier {
_undo.add(_project);
if (_undo.length > 200) _undo.removeAt(0);
_redo.clear();
_project = next;
_project = _syncLaneFloor(next);
_dirty = true;
if (status != null) _status = status;
_recomputeCritical();
notifyListeners();
}
/// 维护「保留空泳道」的保底泳道数 [Project.minLaneCount]:
/// - 开启时只增不减(动作被全部移走的泳道保留、序号不变);
/// - 关闭时收缩为当前实际使用的层数(空泳道自动移除)。
static Project _syncLaneFloor(Project p) {
int maxLayer = -1;
for (final Action a in p.actions) {
if (a.layer > maxLayer) maxLayer = a.layer;
}
final int want = p.keepEmptyLanes
? (p.minLaneCount > maxLayer + 1 ? p.minLaneCount : maxLayer + 1)
: maxLayer + 1;
if (want < 0 || want == p.minLaneCount) return p;
return p.copyWith(minLaneCount: want);
}
/// 撤销:弹出 [_undo] 顶部的快照并压入 [_redo],重算关键路径后刷新。
void undo() {
if (_undo.isEmpty) return;
@@ -258,6 +332,7 @@ class AppController extends ChangeNotifier {
_filePath = null;
_dirty = true;
_status = '新建项目';
_project = _syncLaneFloor(_project);
_recomputeCritical();
notifyListeners();
}
@@ -269,7 +344,7 @@ class AppController extends ChangeNotifier {
void loadProject(Project p, {String? path, bool dirty = false}) {
_undo.clear();
_redo.clear();
_project = p;
_project = _syncLaneFloor(p);
_filePath = path;
_dirty = dirty;
_status = path == null ? '已载入' : '已打开 ${_baseName(path)}';
@@ -422,6 +497,17 @@ class AppController extends ChangeNotifier {
notifyListeners();
}
/// 设置「保留空泳道」策略:动作全部移走后,泳道保留(序号不变)还是自动移除。
///
/// 切换为开启时以当前使用中的泳道为保底,避免把历史收缩掉的泳道“补”出来。
void setKeepEmptyLanes(bool value) {
if (_project.keepEmptyLanes == value) return;
_project = _syncLaneFloor(_project.copyWith(keepEmptyLanes: value));
_dirty = true;
_status = value ? '已开启:保留空泳道' : '已关闭:空泳道自动移除';
notifyListeners();
}
/// 切换依赖连线的显示/隐藏。
void toggleDeps() {
_project = _project.copyWith(
@@ -498,7 +584,7 @@ class AppController extends ChangeNotifier {
final BarLayout l = BarLayout(_project, vp);
// 内容逻辑范围:(0,0) → 右缘 + 60、最后一行底部 + 40。
final double contentW = l.plotRight + 60;
final double contentH = l.yFor(l.ordered.length) + 40;
final double contentH = l.plotBottom + 40;
z = math.min(vp.width / contentW, vp.height / contentH).clamp(0.25, 1.0);
// 关键修复:内容被缩小时按内容范围居中显示;内容本来就能放下时保持默认位置。
// (此前固定 pan = 0,缩小的画面会被钉在左上角。)
@@ -595,8 +681,6 @@ class AppController extends ChangeNotifier {
id = 'A$guard';
}
final int layer = _project.maxLayer + 1;
// 新动作默认排在最后一行(显式行序),避免其相位变化导致行位置跳动。
final int row = _project.actions.length;
final double start = (startAngle ?? 0).clamp(0, 359);
final Action a = Action(
id: id,
@@ -607,7 +691,7 @@ class AppController extends ChangeNotifier {
durationAngle: 45,
layer: layer,
color: kActionPalette[(_project.actions.length) % kActionPalette.length],
row: row,
row: 0, // 新动作进入全新泳道(1 槽)的槽位 0
);
_mutate(
_project.copyWith(
@@ -667,7 +751,7 @@ class AppController extends ChangeNotifier {
name: '${src.name} 副本',
startAngle: (src.startAngle + 10).clamp(0, 359),
layer: _project.maxLayer + 1,
row: _project.actions.length,
row: 0,
deps: const <Dependency>[],
);
_mutate(
@@ -750,28 +834,72 @@ class AppController extends ChangeNotifier {
/// 不再因「目标泳道在该时间段已有动作」而拒绝:换道是高频拖拽操作,一旦拒绝,
/// 动作会被“磁吸”回原泳道(表现为拖不动)。现允许放入并在状态栏提示时间重叠,
/// 由用户自行调整相位;[canPlaceInLane] 仍用于拖拽时的可视化提示。
/// 槽位保持原值(超出目标泳道槽位数时由布局钳制到末槽)。
void moveActionLane(String id, int targetLane) {
final Action? moving = _project.actionById(id);
if (moving == null) return;
final int lane = targetLane.clamp(0, 63);
if (lane == moving.layer) return;
updateAction(id, (Action x) => x.copyWith(layer: lane),
status: '移至轨道 L${lane + 1}');
}
/// 将动作 [id] 移动到([targetLane], [slot])——拖拽换道 / 换槽位。
///
/// 槽位钳制到目标泳道的槽位数范围;同槽时间重叠仅在状态栏提示,不阻止。
void moveActionTo(String id, int targetLane, int slot) {
final Action? moving = _project.actionById(id);
if (moving == null) return;
final int lane = targetLane.clamp(0, 63);
final int slots = _project.slotsOf(lane);
final int s = slot < 0 ? 0 : (slot >= slots ? slots - 1 : slot);
if (lane == moving.layer && s == _effectiveSlot(moving)) return;
final bool overlap = _project.actions.any((Action o) =>
o.id != id &&
o.layer == lane &&
_effectiveSlot(o) == s &&
angleRangesOverlap(moving.startAngle, moving.endAngle, o.startAngle, o.endAngle));
updateAction(id, (Action x) => x.copyWith(layer: lane, row: lane),
updateAction(id, (Action x) => x.copyWith(layer: lane, row: s),
status: overlap
? '移至轨道 L${lane + 1}(与该轨道动作时间重叠)'
: '移至轨道 L${lane + 1}');
? '移至 L${lane + 1} · 槽 ${s + 1}(有动作时间重叠)'
: '移至 L${lane + 1} · 槽 ${s + 1}');
}
/// 目标泳道 [lane] 是否能容纳动作 [id](不与其内动作时间重叠)。
bool canPlaceInLane(String id, int lane) {
/// 动作 [a] 在其泳道内的有效槽位(与布局层 [BarLayout.slotOf] 一致)。
int _effectiveSlot(Action a) {
final int slots = _project.slotsOf(a.layer);
if (slots <= 1) return 0;
final int r = a.row;
return r < 0 ? 0 : (r >= slots ? slots - 1 : r);
}
/// 设置泳道 [lane] 的槽位数(1–5)——「泳道加宽」:同一泳道可并列放置多个动作。
///
/// 缩窄时超出的动作不会被删除,其槽位在布局时钳制到末槽。
void setLaneSlots(int lane, int slots) {
final int n = slots.clamp(1, 5);
if (_project.slotsOf(lane) == n) return;
final Map<int, int> next = Map<int, int>.of(_project.laneSlots);
if (n <= 1) {
next.remove(lane);
} else {
next[lane] = n;
}
_mutate(
_project.copyWith(laneSlots: next),
status: n > 1 ? '泳道 L${lane + 1} 已加宽为 $n 槽(可并列 $n 个动作)' : '泳道 L${lane + 1} 恢复 1 槽',
);
}
/// 目标泳道 [lane](可选 [slot],默认取动作当前槽位)能否容纳动作 [id]。
bool canPlaceInLane(String id, int lane, {int? slot}) {
final Action? a = _project.actionById(id);
if (a == null) return false;
final int s = slot ?? _effectiveSlot(a);
return !_project.actions.any((Action o) =>
o.id != id &&
o.layer == lane &&
_effectiveSlot(o) == s &&
angleRangesOverlap(a.startAngle, a.endAngle, o.startAngle, o.endAngle));
}