v24 第 5 轮:十条清单(天气填城市 / 输入即筛选 / 看板列=看板 / 账本盘点折线图 / 纪念日分类)

用户 2026-10-03 的十条,逐条落点:

1. 天气改为**个人设置里填城市**(每人一份):新增 app/Geo.php,内置 197 个
   地级市坐标(离线、逐条核对,生成脚本 _tooling/_fb_geo_gen.py)。填坐标仍
   作为内置表没有时的出口;老的家庭级坐标保留为兜底,升级当天天气不会凭空消失。
2. 所有"找个人"的地方**输入即筛选**:新增 assets/js/filter.js(纯前端显隐,
   不发请求、回车不刷新)+ app/PersonQuery.php 把服务端判据收敛成一份
   (名册 / 挑人 / 高级搜索共用,避免三处实现漂移)。
3. 名册列表:有昵称就不重复显示本名、行变矮、补齐手机/阴历阳历生日(带年份)/
   邮箱/工作单位;「清除」与「搜索」同款同尺寸。
4/5. 日程:撤掉左侧日历本栏改满宽,功能(显隐/颜色/导入/默认视图)全收进
   右侧 ☰;**色块高度改为按起止时长**(旧实现一律 30 分钟,三小时的会跟
   十五分钟的同高);点日历空白处即建日程,开始时间=点的那一格。
6/10. 资源:搜索提到最上;按"最近改动/最新新增"排序,默认只显示最新 10 条并
   给「显示全部」出口。
7. 任务:看板的**列=用户自定义的看板**(不再是写死的待办/进行中),
   拖动/左右键=换看板(改 board_id,不动 status)。
8. 财务:概览在上账目在下、记一笔改右侧按钮、账本设置(共享/改名/新建/删除)
   收进 ☰、默认账本名「xxx的账本」、"挂在谁名下"默认自己且用标准选人框;
   **新增盘点**(新增 ledger_entry_snapshots 只增不改的历史表,旧值不被清空)
   + 上面画金额变化折线图(app/chart.php 服务端画 SVG,零依赖)。
9. 纪念日:手动添加的与名册生日派生的**分两块**、手动的在上;右侧设置可增删
   分类(家庭级,删分类不强改已用的历史)。

本轮另外修掉/加固的四类问题(都由新增的静态或运行时守卫兜住):
- index.php 少写 2 个 use 导入(Pinyin / UserSetting)→ 名册与个人设置
  返回 200 但正文是 Fatal;顺带修了一处早已存在的 Attachment 未导入。
  → 新增 _fb_import_check.py(1f 段)。
- 一次不精确替换弄丢了 app/Calendar.php 开头的 `<?php`,整份源码被当 HTML
  吐给浏览器,而 `php -l` 报"无语法错误"(纯文本输出确实合法)。
  → 新增 _fb_php_open_check.py(1e 段)。
- 模板片段 unset 了宿主模板的变量(账本片段 unset($canWrite))→ 正文里一片
  Undefined variable 而 HTTP 仍 200。同 _datetime.php 早年 $t 的坑。
  → 新增 _fb_fragment_scope_check.py(1g 段)+ _fb_batch_e.py 的 26 页无告警巡检。
- 窄屏下页头动作区不换行 → 周视图横向溢出且按钮被挤成三种高度(用户提过三次
  "按钮要同高")→ .page-head .actions 加 flex-wrap。

验证战绩(全绿):
  e2e 773/0 · 第 5 轮专项 91/0 · 结构升级 126/0 · 几何 428/0 · 移动端 684/0 ·
  交互 97/0 · 家谱 26/0 · 按钮 60/0;三轮反向验证各 3/3 抓到,还原后复绿。
线上:schema v14、指纹一致(9df6c9fccc6796db)、snapshots 表已建、197 城、
  8 个关键文件 md5 与本地逐字节一致、app/ 403 无源码泄漏、错误日志无新增。
This commit is contained in:
2026-10-03 15:01:38 +08:00
parent dbcf0c1bcd
commit e0562b8627
31 changed files with 2891 additions and 505 deletions
+29 -29
View File
@@ -31,50 +31,50 @@ $attDelUrl = $attDelUrl ?? '';
?>
<?php if ($attRows): ?>
<div class="att-wall">
<?php foreach ($attRows as $a): ?>
<?php foreach ($attRows as $attRow): ?>
<?php
$kind = \App\Attachment::kind($a);
$canPrev = \App\Attachment::previewable($a);
$view = media_url((string)$a['key']);
$dl = media_url((string)$a['key'], ['dl' => 1]);
$nm = (string)($a['name'] ?? '');
$sz = \App\Attachment::sizeWord($a['size'] ?? 0);
$attKind = \App\Attachment::kind($attRow);
$canPrev = \App\Attachment::previewable($attRow);
$attView = media_url((string)$attRow['key']);
$attDl = media_url((string)$attRow['key'], ['dl' => 1]);
$attNm = (string)($attRow['name'] ?? '');
$attSz = \App\Attachment::sizeWord($attRow['size'] ?? 0);
?>
<div class="att-cell">
<?php if ($canPrev): ?>
<a class="att-thumb att-kind-<?= e($kind) ?>"
href="<?= e($view) ?>"
data-prev="<?= e($kind === 'pdf' ? 'pdf' : ($kind === 'video' ? 'video' : 'image')) ?>"
data-src="<?= e($view) ?>"
data-dl="<?= e($dl) ?>"
data-name="<?= e($nm !== '' ? $nm : \App\Attachment::kindWord($kind)) ?>"
data-size="<?= e($sz) ?>"
title="<?= e($nm) ?>">
<?php if ($kind === 'image'): ?>
<img src="<?= e($view) ?>" alt="<?= e($nm) ?>" loading="lazy">
<?php elseif ($kind === 'video'): ?>
<a class="att-thumb att-kind-<?= e($attKind) ?>"
href="<?= e($attView) ?>"
data-prev="<?= e($attKind === 'pdf' ? 'pdf' : ($attKind === 'video' ? 'video' : 'image')) ?>"
data-src="<?= e($attView) ?>"
data-dl="<?= e($attDl) ?>"
data-name="<?= e($attNm !== '' ? $attNm : \App\Attachment::kindWord($attKind)) ?>"
data-size="<?= e($attSz) ?>"
title="<?= e($attNm) ?>">
<?php if ($attKind === 'image'): ?>
<img src="<?= e($attView) ?>" alt="<?= e($attNm) ?>" loading="lazy">
<?php elseif ($attKind === 'video'): ?>
<?php /* #t=0.1 让浏览器把第 0.1 秒那一帧当封面显示出来 ——
没有它视频位就是一块黑板,看不出这是段什么视频。 */ ?>
<video src="<?= e($view) ?>#t=0.1" preload="metadata" muted playsinline></video>
<video src="<?= e($attView) ?>#t=0.1" preload="metadata" muted playsinline></video>
<span class="att-play" aria-hidden="true">▶</span>
<?php else: ?>
<span class="att-doc att-doc-pdf">PDF</span>
<?php endif; ?>
</a>
<?php else: ?>
<a class="att-thumb att-kind-<?= e($kind) ?>" href="<?= e($dl) ?>"
title="<?= e($nm) ?>(点击下载)">
<span class="att-doc att-doc-<?= e($kind) ?>"><?= e(\App\Attachment::kindWord($kind)) ?></span>
<a class="att-thumb att-kind-<?= e($attKind) ?>" href="<?= e($attDl) ?>"
title="<?= e($attNm) ?>(点击下载)">
<span class="att-doc att-doc-<?= e($attKind) ?>"><?= e(\App\Attachment::kindWord($attKind)) ?></span>
</a>
<?php endif; ?>
<div class="att-meta">
<span class="att-fname" title="<?= e($nm) ?>"><?= e($nm !== '' ? $nm : \App\Attachment::kindWord($kind)) ?></span>
<span class="att-fsize"><?= e($sz) ?></span>
<a class="link-quiet att-dl" href="<?= e($dl) ?>">下载</a>
<span class="att-fname" title="<?= e($attNm) ?>"><?= e($attNm !== '' ? $attNm : \App\Attachment::kindWord($attKind)) ?></span>
<span class="att-fsize"><?= e($attSz) ?></span>
<a class="link-quiet att-dl" href="<?= e($attDl) ?>">下载</a>
<?php if ($attCanEdit && !empty($attDelUrl)): ?>
<form method="post" action="<?= e(url($attDelUrl)) ?>" class="att-del">
<?= csrf_field() ?>
<input type="hidden" name="<?= e($attDelField) ?>" value="<?= (int)$a['id'] ?>">
<input type="hidden" name="<?= e($attDelField) ?>" value="<?= (int)$attRow['id'] ?>">
<?php foreach ($attExtra as $ek => $ev): ?>
<input type="hidden" name="<?= e((string)$ek) ?>" value="<?= e((string)$ev) ?>">
<?php endforeach; ?>
@@ -85,8 +85,8 @@ $attDelUrl = $attDelUrl ?? '';
</div>
</div>
<?php endforeach; ?>
<?php /* ⚠️ 循环里用到的临时变量一律用完即清:宿主模板里很可能也有 $a / $kind /
$view / $dl / $nm / $sz(各模块页面都爱用这种短名),留着就是静默覆盖。 */ ?>
<?php unset($a, $kind, $canPrev, $view, $dl, $nm, $sz); ?>
<?php /* ⚠️ 循环里用到的临时变量一律用完即清:宿主模板里很可能也有 $attRow / $attKind /
$attView / $attDl / $attNm / $attSz(各模块页面都爱用这种短名),留着就是静默覆盖。 */ ?>
<?php unset($attRow, $attKind, $canPrev, $attView, $attDl, $attNm, $attSz); ?>
</div>
<?php endif; ?>
+10 -2
View File
@@ -64,8 +64,16 @@ $ppHasSel = count(array_filter($ppSelected)) > 0;
<b><?= e($ppTitle) ?></b>
<button type="button" class="pp-close" id="<?= e($ppId) ?>-close" title="关闭">×</button>
</div>
<input class="input pp-search" id="<?= e($ppId) ?>-search" type="text"
placeholder="输入名字或拼音首字母,如 yyq 找「杨永全」" autocomplete="off">
<?php /* ⚠️ 这个 div 原来是个 <form>,看着更"正规",实际有两个坑:
① 选人组件常被嵌在**别的表单里**(新建资源 / 记一笔 / 共享账本…),
HTML 不允许 form 嵌套 —— 浏览器会把外层表单切两半,
提交时丢字段("保存了但选的人没存上"就是这么来的);
② 在里面按回车会提交那个表单、整页刷新,而列表本来就实时筛过了。
改成 div:回车不再有任何副作用,筛选照样是即时的。 */ ?>
<div class="pp-searchline">
<input class="input pp-search" id="<?= e($ppId) ?>-search" type="text"
placeholder="输入名字或拼音首字母,如 yyq 找「杨永全」" autocomplete="off">
</div>
<div class="pp-list" id="<?= e($ppId) ?>-list">
<?php if (!$ppIsMulti && $ppAllowEmpty): ?>
<label class="pp-item pp-item-none" data-name="不选" data-shown="不选">
+114
View File
@@ -0,0 +1,114 @@
<?php
/**
* 日程模块的「设置」下拉(v24 用户 2026-10-03 第 4、5 条)
*
* 用户原话:「日程模块,左侧的日历本显示与否,去掉,让日历充满整个宽度。
* 在右侧,也加一个设置按钮,设置中,可以设置哪些日历本显示,
* 调整日历的颜色,导入日历等功能,都放在这个设置下。」
* 「在日程的设置中,可以设置默认显示的视图模式,月视图还是周视图还是日视图。
* 把日历本这个按钮的功能,收到设置中。」
*
* 所以这个 ☰ 是**原来左边那一栏 + 「日历本」按钮**的合并去处。
* 外观与观影 / 任务的设置下拉完全一致(只留图标、排最右、条目带小图标),
* 三处同一个手势,用户不用记第二套。
*
* 两件**个人偏好**(默认视图 / 显示哪些本子)就地用表单提交;
* 其余的(颜色、共享、导入、CalDAV)是**页面级**的操作,
* 跳到「日历本」管理页 —— 那里本来就有全套,没必要在这儿再写一遍。
*
* 用法(require 前 set 好):
* $setCurrent 当前页 key('view'),用来高亮
* $cals 我可见的日历本(带 perm / color);可能为空
* $view 当前视图(回跳时保持)
* $anchor 当前锚定日(周/日视图回跳时保持)
*/
$setCurrent = (string)($setCurrent ?? '');
$setOn = static function (string $key) use ($setCurrent): string {
return $setCurrent === $key ? ' class="on"' : '';
};
$setIcon = static function (string $name): string {
$paths = [
'view' => '<rect x="2" y="3.2" width="12" height="10.4" rx="1.6"/><path d="M2 6.4h12M5.4 1.6v3.2M10.6 1.6v3.2"/>',
'books' => '<path d="M2.6 3.2h4v9.6h-4zM9.4 3.2h4v9.6h-4z"/>',
'import' => '<path d="M8 2.6v7.2M5 6.8l3 3 3-3M3.2 13.4h9.6"/>',
'dav' => '<circle cx="8" cy="8" r="5.6"/><path d="M2.4 8h11.2M8 2.4c1.8 2 2.6 3.7 2.6 5.6S9.8 12 8 13.6C6.2 11.6 5.4 9.9 5.4 8S6.2 4.4 8 2.4z"/>',
];
$d = $paths[$name] ?? '';
if ($d === '') {
return '';
}
return '<svg class="mi" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"'
. ' fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"'
. ' stroke-linejoin="round">' . $d . '</svg>';
};
$myCals = (array)($cals ?? []);
$hiddenIds = array_map('intval', (array)($hiddenCals ?? []));
$curView = (string)($view ?? 'month');
$backView = $curView;
?>
<details class="movie-set menu cal-set">
<summary class="btn btn-icon" title="日程设置" aria-label="日程设置"><svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"><path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/></svg></summary>
<div class="menu-list cal-set-list">
<?php /* ---- 默认视图 + 显示哪些本子(个人偏好,就地提交)---- */ ?>
<form method="post" action="<?= e(url('calendar/prefs')) ?>" class="cal-set-form">
<?= csrf_field() ?>
<input type="hidden" name="back_view" value="<?= e($backView) ?>">
<div class="cal-set-block">
<div class="cal-set-h">默认打开时看</div>
<div class="cal-set-views">
<?php foreach (\App\Calendar::VIEWS as $vk => $vw): ?>
<label class="cal-set-view">
<input type="radio" name="view" value="<?= e($vk) ?>"
<?= \App\Calendar::defaultView((int)\App\Auth::personId()) === $vk ? 'checked' : '' ?>>
<span><?= e($vw) ?>视图</span>
</label>
<?php endforeach; ?>
</div>
</div>
<div class="cal-set-block">
<div class="cal-set-h">显示哪些日历本</div>
<?php /* ⚠️ 这个隐藏标记是**必须**的:HTML 里"一个都没勾"会让浏览器
整个省掉 `show[]` 键,服务端就分不清「用户想全关掉」与
「这次请求没打算改显隐」—— 没有它的话,将来任何只改默认视图的
提交都会把所有日历本静默藏掉。 */ ?>
<input type="hidden" name="show_present" value="1">
<?php if (!$myCals): ?>
<p class="small muted" style="margin:0">还没有日历本。</p>
<?php else: ?>
<?php foreach ($myCals as $c): $cid = (int)$c['id']; ?>
<label class="cal-set-book">
<input type="checkbox" name="show[]" value="<?= $cid ?>"
<?= in_array($cid, $hiddenIds, true) ? '' : 'checked' ?>>
<span class="color-preview" style="background: <?= e((string)$c['color']) ?>;"></span>
<span class="cal-name"><?= e((string)$c['name']) ?></span>
<?php if ((string)$c['kind'] !== 'custom'): ?>
<span class="node-badge">系统</span>
<?php elseif ((int)$c['shared'] === 1): ?>
<span class="node-badge"><?= ($c['perm'] ?? '') === 'write' ? '共享·可写' : '共享·只读' ?></span>
<?php endif; ?>
</label>
<?php endforeach; ?>
<?php endif; ?>
<p class="small muted" style="margin:6px 0 0">
观影、旅行、有截止时间的任务会自动出现在这里,不用另建本子。
</p>
</div>
<div class="cal-set-foot">
<button class="btn btn-sm" type="submit">保存显示设置</button>
</div>
</form>
<?php /* ---- 页面级操作:颜色/新建/共享/导入/CalDAV 都在「日历本」管理页 ---- */ ?>
<div class="cal-set-links">
<a href="<?= e(url('calendar/calendars')) ?>"<?= $setOn('books') ?>><?= $setIcon('books') ?><span>日历本 · 颜色 / 共享 / 导入</span></a>
<a href="<?= e(url('calendar/calendars')) ?>#caldav"><?= $setIcon('dav') ?><span>CalDAV 订阅(在手机日历里看)</span></a>
</div>
</div>
</details>
<?php
unset($setCurrent, $setOn, $setIcon, $myCals, $hiddenIds, $curView, $backView);
+112 -65
View File
@@ -1,20 +1,23 @@
<?php
/**
* 日程 · 月视图(v12)。
* 日程 · 月 / 周 / 天 三视图(v12,v24 第 4、5 条重排)。
*
* 参照群晖 Calendar 的外观:左边一列"我的日历本"(可勾选显隐),右边 7×6 的月网格,
* 有日程的日子在格子里露出彩色小条,点小条跳到对应模块(观影/旅程/任务)。
* ⚠️ v24 用户 2026-10-03 第 4 条:**左侧那一栏「我的日历本」撤掉了**,日历占满整宽。
* 原话:「日程模块,左侧的日历本显示与否,去掉,让日历充满整个宽度。
* 在右侧,也加一个设置按钮,设置中,可以设置哪些日历本显示,
* 调整日历的颜色,导入日历等功能,都放在这个设置下。」
* 所以那些功能全搬进了页头最右边那个 ☰ 里(见 _settings_menu.php)。
* 显隐改由**服务端**处理(Calendar::hiddenCalendars):藏掉的本子不参与取数,
* "+N 条"之类按可见条目算 —— 前端 display:none 会让这些数字对不上。
*
* 两条设计:
* ① **日历本显隐是纯前端的**(勾选框 + 给日程条加 data-cal):
* 不做成"勾一次刷一次页面",否则翻月、勾选都在等服务端。没有 JS 时全部照常显示。
* ② **观影 / 旅行 / 任务不复制进日历**,是从各自模块实时汇总出来的(Calendar::month),
* 所以改了观影日期,日历里立刻跟着变。反过来在日历里给观影本加日程 = 真的建一条观影记录。
* ⚠️ 用户第 5 条:在日历里点一下就建日程(开始时间 = 点的那一格)。
* 月视图的格子按天、周/日视图按半小时——
* 后者用鼠标在列里的纵向位置反算时刻(见页面底部那两段 JS)。
*
* @param string $ym 'Y-m'
* @param array $weeks 月网格(build_month_grid 产出)
* @param array $cals 我可见的日历本(含 perm)
* @param array $people 名册(共享给别人时用)
* @param array $cals 我可见的日历本(含 perm);$visCals 是其中显示着的 id
* @param string $newAt 点进来时预填的开始时间('Y-m-d H:i' 或 'Y-m-d')
*/
$canWrite = \App\Auth::canWrite();
$view = (string)($view ?? 'month');
@@ -24,6 +27,11 @@ $prevYm = date('Y-m', strtotime('-1 month', $ts));
$nextYm = date('Y-m', strtotime('+1 month', $ts));
$thisYm = date('Y-m');
$writable = array_values(array_filter($cals, static fn($c) => \App\Calendar::canWrite($c, (int)\App\Auth::personId())));
$visCals = array_map('intval', (array)($visCals ?? []));
$hiddenCals = array_map('intval', (array)($hiddenCals ?? []));
$newAt = (string)($newAt ?? '');
// 能不能"点一下建日程":只读账号点了没反应,所以连十字光标都不给(见 CSS 的 rt-writable)
$canNew = $canWrite && (bool)$writable;
// 三种看法各自的「上一段 / 下一段」:月按整月走,周按 7 天走,天按 1 天走
$step = $view === 'week' ? 7 : ($view === 'day' ? 1 : 0);
@@ -33,12 +41,6 @@ $todayD = date('Y-m-d');
$headText = $view === 'month' ? date('Y 年 n 月', $ts)
: ($view === 'week' ? date('Y 年 n 月 j 日', strtotime($anchor)) . ' 起这一周'
: date('Y 年 n 月 j 日', strtotime($anchor)));
$mkUrl = static function (string $v) use ($ym, $prevD, $nextD, $todayD, $prevYm, $nextYm, $thisYm) {
if ($v === 'month') {
return url('calendar', ['view' => 'month', 'ym' => $ym]);
}
return null; // 周/天要把具体哪天传进去,由调用方拼
};
?>
<div class="page-head">
<h1>日程</h1>
@@ -66,41 +68,22 @@ $mkUrl = static function (string $v) use ($ym, $prevD, $nextD, $todayD, $prevYm,
<?= $view === 'week' ? '下一周' : '后一天' ?>
</a>
<?php endif; ?>
<a class="btn btn-ghost" href="<?= e(url('calendar/calendars')) ?>">日历本</a>
<?php if ($canWrite && $writable): ?>
<button class="btn" type="button" id="calAddBtn">新建日程</button>
<?php endif; ?>
<?php /* 用户第 4、5 条:日历本 / 颜色 / 导入 / 默认视图 全收进这个 ☰ ——
它顶替了原来左边那一栏,所以排在**最右**(靠 .page-head .actions 的顺序)。 */ ?>
<?php $setCurrent = 'view'; require __DIR__ . '/_settings_menu.php'; ?>
</div>
</div>
<div class="cal-wrap">
<?php /* ---- 左:日历本 ---- */ ?>
<aside class="cal-side">
<h2 class="cinema-h2">我的日历本</h2>
<?php if (!$cals): ?>
<p class="empty-hint">还没有日历本。</p>
<?php else: ?>
<ul class="cal-list">
<?php foreach ($cals as $c): ?>
<li class="cal-item">
<label class="cal-toggle">
<input type="checkbox" class="cal-cb" data-cal="<?= (int)$c['id'] ?>" checked>
<span class="color-preview" style="background: <?= e((string)$c['color']) ?>;"></span>
<span class="cal-name"><?= e((string)$c['name']) ?></span>
</label>
<?php if ((int)$c['shared'] === 1): ?>
<span class="node-badge"><?= ($c['perm'] ?? '') === 'write' ? '共享·可写' : '共享·只读' ?></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php /* 观影/旅行/任务三路是**自动汇总**的,没有本子开关,这里说明一下来源 */ ?>
<p class="cal-note">观影、旅行、有截止时间的任务会自动出现在这里,不需要另建本子。</p>
<?php endif; ?>
</aside>
<?php /* ---- 右:月网格 ---- */ ?>
<div class="cal-wrap cal-wrap-full">
<?php /* ---- 右:月网格 / 时间网格 ----
用户第 4 条:左边那一栏「我的日历本」已经撤掉(功能搬进右上角 ☰),
所以这里直接就是主区域,`.cal-wrap-full` 把网格调成"只有一列"。 */ ?>
<div class="cal-main">
<?php /* 用户第 5 条:这张表单既服务「新建日程」按钮,也服务「点日历空白处」——
后者由 JS 现填开始时间,所以表单本身不再写死 09:00。 */ ?>
<?php if ($canWrite && $writable): ?>
<div class="card card-pad cal-add" id="calAddCard" hidden>
<h2 class="cinema-h2">新建日程</h2>
@@ -117,10 +100,17 @@ $mkUrl = static function (string $v) use ($ym, $prevD, $nextD, $todayD, $prevYm,
</select>
</div>
<?php /* v24 第 6 条:字段按 iCalendar / CalDAV 的 VEVENT 定(见 _event_fields.php)。
新建时「全天」默认**不勾**(用户原话),开始时间默认今天 09:00。 */ ?>
新建时「全天」默认**不勾**(用户原话)。开始时间默认:
带了 new_at 就用它(点日历的那一格),否则今天 09:00。 */ ?>
<?php
$evFields = ['starts_at' => ($ym === $thisYm ? date('Y-m-d') : $ym . '-01') . ' 09:00:00',
'ends_at' => ($ym === $thisYm ? date('Y-m-d') : $ym . '-01') . ' 10:00:00'];
// 点的位置优先;没点就"月视图当月 → 该月 1 号 / 本月 → 今天"的 09:00
$defDay = $newAt !== '' ? substr($newAt, 0, 10)
: (($ym === $thisYm ? date('Y-m-d') : $ym . '-01'));
$defHM = $newAt !== '' && strlen($newAt) > 10
? substr($newAt, 11, 5) : '09:00';
$defEndH = sprintf('%02d', (min(23, (int)substr($defHM, 0, 2) + 1)));
$evFields = ['starts_at' => $defDay . ' ' . $defHM . ':00',
'ends_at' => $defDay . ' ' . $defEndH . ':' . substr($defHM, 3, 2) . ':00'];
$evAllDay = false;
require __DIR__ . '/_event_fields.php';
?>
@@ -170,7 +160,8 @@ $mkUrl = static function (string $v) use ($ym, $prevD, $nextD, $todayD, $prevYm,
<?php endfor; ?>
</div>
<?php foreach (($cols ?? []) as $i => $c): ?>
<div class="tg-col<?= $c['is_today'] ? ' is-today' : '' ?>">
<div class="tg-col<?= $c['is_today'] ? ' is-today' : '' ?><?= $canNew ? ' rt-writable' : '' ?>"
data-new-at="<?= e((string)$c['date']) ?>">
<?php for ($h = 0; $h < 24; $h++): ?>
<span class="tg-line"></span>
<?php endfor; ?>
@@ -196,7 +187,11 @@ $mkUrl = static function (string $v) use ($ym, $prevD, $nextD, $todayD, $prevYm,
<div class="cal-grid">
<?php foreach ($weeks as $wk): ?>
<?php foreach ($wk as $cell): ?>
<div class="cal-cell<?= $cell['in_month'] ? '' : ' is-out' ?><?= $cell['is_today'] ? ' is-today' : '' ?>">
<?php /* 用户第 5 条:点格子里的空白 = 在这天建日程。
用 data-new-at 把日期带过去,由底部 JS 交给新建表单
(点了小条本身是"打开那条日程",由 <a> 自己处理,JS 会排除掉)。 */ ?>
<div class="cal-cell<?= $cell['in_month'] ? '' : ' is-out' ?><?= $cell['is_today'] ? ' is-today' : '' ?><?= $canNew ? ' rt-writable' : '' ?>"
data-new-at="<?= e((string)$cell['date']) ?>">
<div class="cal-dnum"><?= (int)$cell['day'] ?></div>
<div class="cal-evs">
<?php $n = 0; foreach ($cell['events'] as $ev): $n++; ?>
@@ -226,22 +221,11 @@ $mkUrl = static function (string $v) use ($ym, $prevD, $nextD, $todayD, $prevYm,
<script>
(function () {
/* 日历本显隐:只切 display,不重新请求 —— 翻月/勾选都是立刻的。
没有 JS 时全部照常显示(勾选框失效而已),不会丢内容。 */
var boxes = document.querySelectorAll('.cal-cb');
function apply() {
var off = {};
Array.prototype.forEach.call(boxes, function (b) {
if (!b.checked) { off[b.getAttribute('data-cal')] = true; }
});
Array.prototype.forEach.call(document.querySelectorAll('.cal-ev'), function (el) {
el.style.display = off[el.getAttribute('data-cal')] ? 'none' : '';
});
}
Array.prototype.forEach.call(boxes, function (b) { b.addEventListener('change', apply); });
apply();
var btn = document.getElementById('calAddBtn');
/* ---- 新建日程:按钮开合 + 「点日历空白处」预填开始时间 ----
⚠️ 上一版的「日历本显隐」JS 已经**整段删掉**:显隐改成服务端处理
(Calendar::hiddenCalendars,见路由里的说明),前端不再需要它。
留着会让人以为"改一下勾选就能切换",但那些勾选框已经不在这儿了。 */
var btn = document.getElementById('calAddBtn');
var card = document.getElementById('calAddCard');
var cancel = document.getElementById('calAddCancel');
if (btn && card) {
@@ -251,6 +235,69 @@ $mkUrl = static function (string $v) use ($ym, $prevD, $nextD, $todayD, $prevYm,
});
}
if (cancel && card) { cancel.addEventListener('click', function () { card.hidden = true; }); }
/* ---- 用户第 5 条:在日历里点一下 → 弹新建,开始时间 = 点的位置 ----
月视图:一格 = 一天 → 开始时间用那天 09:00("当日默认"比 00:00 更像个日程)。
周/日视图:按鼠标在**那一列里的纵向位置**反算时刻,最接近的半小时 ——
点在"下午三点那一段"就该得到 15:00,这是"点哪儿建哪儿"的全部意义。 */
var startField = document.querySelector('.field.ev-dt[data-dt]');
var startDate = startField ? startField.querySelector('input.dt-date') : null;
var startHour = startField ? startField.querySelector('select.dt-hour') : null;
var startMin = startField ? startField.querySelector('select.dt-minute') : null;
var startSec = startField ? startField.querySelector('select.dt-second') : null;
function setStart(dateStr, hh, mm) {
if (!startDate) return;
startDate.value = dateStr;
if (hh !== null && startHour) { startHour.value = hh; }
if (mm !== null && startMin) { startMin.value = mm; }
if (startSec) { startSec.value = '00'; }
}
function openNew(dateStr, hh, mm) {
if (!card) return;
card.hidden = false;
setStart(dateStr, hh, mm);
card.scrollIntoView({ block: 'nearest' });
// 标题是第一个输入框,直接把光标放过去 —— 点完就能打字
var t = document.getElementById('ev-title');
if (t) { t.focus(); }
}
/* 月视图格子 */
Array.prototype.forEach.call(document.querySelectorAll('.cal-cell[data-new-at]'), function (cell) {
cell.addEventListener('click', function (ev) {
// 点在小条上 = 想打开那条日程(<a> 的默认行为),不要抢
if (ev.target.closest && ev.target.closest('.cal-ev')) { return; }
if (!<?= $canWrite && $writable ? 'true' : 'false' ?>) { return; }
openNew(cell.getAttribute('data-new-at'), '09', '00');
});
});
/* 周/日视图的列:纵向位置 → 时刻。
列高 1056px = 24 小时(见 .tg-col 的 CSS),所以 1 分钟 = 1056/1440 px。 */
Array.prototype.forEach.call(document.querySelectorAll('.tg-col[data-new-at]'), function (col) {
col.addEventListener('click', function (ev) {
if (ev.target.closest && ev.target.closest('.tg-block')) { return; }
if (!<?= $canWrite && $writable ? 'true' : 'false' ?>) { return; }
var box = col.getBoundingClientRect();
var ratio = (ev.clientY - box.top) / Math.max(1, box.height);
var mins = Math.max(0, Math.min(24 * 60 - 30, Math.round(ratio * 1440 / 30) * 30));
var hh = String(Math.floor(mins / 60)).padStart(2, '0');
var mm = String(mins % 60).padStart(2, '0');
openNew(col.getAttribute('data-new-at'), hh, mm);
});
});
/* 从 ?new_at= 进来(比如别处链过来)→ 直接开弹窗并预填 */
var preset = <?= json_encode($newAt, JSON_UNESCAPED_UNICODE) ?>;
if (preset) {
var parts = String(preset).split(/[ T]/);
if (parts[0]) {
var hm = (parts[1] || '').split(':');
openNew(parts[0], hm[0] || '09', hm[1] || '00');
}
}
/* 「全天」勾上藏掉时刻那一段的逻辑在 _event_fields.php 里(两个页面共用一份) */
})();
</script>
+63
View File
@@ -0,0 +1,63 @@
<?php
/**
* 纪念日模块的「设置」下拉(v24 用户 2026-10-03 第 9 条)
*
* 用户原话:「在新建纪念日和右侧,也增加设置按钮,可以设置纪念日的分类。」
*
* 分类清单是**家庭级**的(settings.anniv_kinds)—— 全家共用一套叫法,
* 不然「结婚纪念日」在两个人屏幕上是两套名字,看的时候对不上。
* 所以这里跟「模块主题色」一样:**能改的是所有人**,但改的是同一份。
*
* 用法(require 前 set 好):
* $kinds 当前分类清单
* $kindCounts 每个分类用了几条(显示"这个分类有没有在用")
*/
$daySetKinds = (array)($kinds ?? \App\Anniversary::PRESET_KINDS);
$daySetCounts = (array)($kindCounts ?? []);
$daySetCanWrite = \App\Auth::canWrite();
?>
<details class="movie-set menu ann-set">
<summary class="btn btn-icon" title="纪念日设置" aria-label="纪念日设置"><svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"><path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/></svg></summary>
<div class="menu-list ann-set-list">
<div class="cal-set-h">纪念日分类(全家共用一套)</div>
<?php if (!$daySetKinds): ?>
<p class="small muted" style="margin:0 0 8px">一个分类都没有。下面加一个。</p>
<?php else: ?>
<ul class="ann-kind-list">
<?php foreach ($daySetKinds as $k): ?>
<li>
<span class="ann-kind-name"><?= e((string)$k) ?></span>
<span class="small muted"><?= (int)($daySetCounts[(string)$k] ?? 0) ?> 条在用</span>
<?php if ($daySetCanWrite): ?>
<form method="post" action="<?= e(url('days/kinds')) ?>" class="res-inline">
<?= csrf_field() ?>
<input type="hidden" name="del" value="<?= e((string)$k) ?>">
<button class="btn btn-ghost btn-sm" type="submit"
title="删掉这个分类(已用它的纪念日不变)">删</button>
</form>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if ($daySetCanWrite): ?>
<form method="post" action="<?= e(url('days/kinds')) ?>" class="led-set-form-in" style="margin-top:8px">
<?= csrf_field() ?>
<input class="input" name="add" maxlength="20" placeholder="新分类,如:相识纪念日">
<button class="btn btn-sm" type="submit">加分类</button>
</form>
<?php endif; ?>
<p class="small muted" style="margin:8px 0 0">
删掉一个分类**不会**改已用过它的纪念日 —— 只是新建时不再出现在下拉里。
</p>
</div>
</details>
<?php
// ⚠️ 只 unset **本片段自己定义**的那三个前缀变量。
// 绝不能再写 `unset($kinds, $kindCounts, $canWrite)` —— days/index.php 里
// 同样有 $canWrite(还有 $kinds),那样会把宿主模板的变量一起干掉,
// 后面每一处用到的地方都变成 Undefined variable(账本那个片段刚这么炸过一次)。
unset($daySetKinds, $daySetCounts, $daySetCanWrite);
+18 -6
View File
@@ -12,6 +12,15 @@
$e0 = $editing ?: [];
$v = static fn(string $k, $def = '') => $e0[$k] ?? $def;
$repeat = (string)($e0['repeat_type'] ?? 'solar');
// 用户 2026-10-03 第 9 条:分类下拉的选项来自**可配置**的分类清单
// (原来写死 PRESET_KINDS,用户要能自己增删 —— 见「纪念日设置」)。
$kinds = (array)($kinds ?? \App\Anniversary::PRESET_KINDS);
$curKind = (string)($e0['kind'] ?? '');
// 编辑一条用了**已被删掉的分类**的纪念日时,要把它自己也列进下拉,
// 否则保存一次就把它悄悄改成了第一个选项(用户没动它,值却变了)。
if ($curKind !== '' && !in_array($curKind, $kinds, true)) {
array_unshift($kinds, $curKind);
}
?>
<div class="page-head">
<h1><?= $editing ? '编辑纪念日' : '新建纪念日' ?></h1>
@@ -43,13 +52,16 @@ $repeat = (string)($e0['repeat_type'] ?? 'solar');
<div class="field">
<label for="an-kind">分类</label>
<input class="input" id="an-kind" name="kind" list="anKinds"
value="<?= e((string)$v('kind')) ?>" placeholder="如:结婚纪念日">
<datalist id="anKinds">
<?php foreach (\App\Anniversary::PRESET_KINDS as $k): ?>
<option value="<?= e($k) ?>"></option>
<?php /* 用 <select> 而不是 <input list=…>:分类现在是**用户自己维护的一套**,
下拉能保证选到的都是存在的分类;datalist 允许自由填,
填出来的新词不会进清单,下次别人也不知道有这个词。 */ ?>
<select class="select" id="an-kind" name="kind">
<option value="">不分类</option>
<?php foreach ($kinds as $k): ?>
<option value="<?= e((string)$k) ?>" <?= $curKind === (string)$k ? 'selected' : '' ?>><?= e((string)$k) ?></option>
<?php endforeach; ?>
</datalist>
</select>
<span class="tip">分类可以在「纪念日」页右侧的设置里增删。</span>
</div>
<div class="field">
+89 -49
View File
@@ -1,17 +1,21 @@
<?php
/**
* 纪念日(v24 用户第 13 条)
* 纪念日(v24 用户第 13 条;2026-10-03 第 9 条重排)
*
* 用户原话:「增加纪念日模块,可以根据阴历和阳历来设置纪念日,在纪念日模块中,
* 可以默认看到已经保存的名册中的人的各种生日,生日本身就是纪念日的一种。」
* 第 9 条原话:「纪念日中,手动添加的纪念日和来自其他模块的,例如生日的纪念日,
* 要分开,手动纪念日在上面。在新建纪念日和右侧,也增加设置按钮,
* 可以设置纪念日的分类。」
*
* 所以这一页两块:
* ① 临近的(今天起 60 天内)—— 一眼看到"该过什么日子了";
* ② 全部纪念日 —— 名册里每个人的生日(实时派生)+ 你自己加的,混在一起按日期排。
* 所以这一页三块,顺序按用户要求:
* ① 接下来的日子(未来 60 天,两类混在一起 —— 那块本来就是"该过什么日子了")
* ② **手动添加的**纪念日(在上)
* ③ 来自名册生日的(在下,实时派生、不能改删)
*
* @param array $rows 全部纪念日(含派生生日:source='birthday_solar'/'birthday_lunar')
* @param array $upcoming 接下来 60 天的
* @param array $people 名册(新建表单里选"与谁相关")
* @param array $custom 用户自建的
* @param array $derived 从名册生日派生的
* @param array $upcoming 接下来 60 天的
* @param array $kinds 分类清单(设置里维护)
* @param array $kindCounts 每个分类用了几条
*/
$canWrite = \App\Auth::canWrite();
$kindBadge = static function (array $r): string {
@@ -28,6 +32,48 @@ $srcWord = static function (array $r): string {
}
return \App\Anniversary::repeatWord((string)($r['repeat_type'] ?? 'solar'));
};
/* 画一张纪念日表。两块(手动 / 派生)共用同一个渲染 —— 复制一遍迟早改漏一处。 */
$renderTable = function (array $rows, bool $editable) use ($canWrite, $kindBadge, $srcWord): void {
if (!$rows) {
return;
}
?>
<div class="table-wrap">
<table class="table">
<thead>
<tr><th>日期</th><th>纪念日</th><th>分类</th><th>重复</th><th></th></tr>
</thead>
<tbody>
<?php foreach ($rows as $r): ?>
<tr>
<td class="nowrap"><?= (int)$r['month'] ?> 月 <?= (int)$r['day'] ?> 日</td>
<td>
<?= e((string)$r['title']) ?>
<?php if (!empty($r['is_leap'])): ?><span class="small muted">(闰月)</span><?php endif; ?>
</td>
<td><?= $kindBadge($r) ?></td>
<td class="small muted"><?= e($srcWord($r)) ?></td>
<td class="nowrap">
<?php if ($editable && $canWrite): ?>
<a class="link-quiet" href="<?= e(url('days/edit', ['id' => (int)$r['id']])) ?>">改</a>
<form method="post" action="<?= e(url('days/destroy')) ?>" class="res-inline">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$r['id'] ?>">
<button class="btn btn-ghost btn-sm" type="submit"
onclick="return confirm('删掉这条纪念日?')">删</button>
</form>
<?php else: ?>
<span class="small muted">来自名册</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php
};
?>
<div class="page-head">
<h1>纪念日</h1>
@@ -37,6 +83,8 @@ $srcWord = static function (array $r): string {
<a class="btn" href="<?= e(url('days/new')) ?>">新建纪念日</a>
<?php endif; ?>
<a class="btn btn-ghost" href="<?= e(url('calendar')) ?>">看日历</a>
<?php /* 用户第 9 条:设置按钮就在「新建纪念日」右边(☰,排最右) */ ?>
<?php $setCurrent = 'kinds'; require __DIR__ . '/_settings_menu.php'; ?>
</div>
</div>
@@ -59,47 +107,39 @@ $srcWord = static function (array $r): string {
<?php endif; ?>
</div>
<?php /* ==================== ② 手动添加的(在上,用户第 9 条)==================== */ ?>
<div class="card card-pad">
<h2 class="cinema-h2">全部纪念日(<?= count($rows) ?>)</h2>
<?php if (!$rows): ?>
<p class="empty-hint">还没有纪念日。先到名册里把家人的生日填上,这里就会自动出现。</p>
<h2 class="cinema-h2">
我自己添加的(<?= count($custom) ?>)
<span class="hint">只有这些能改能删</span>
</h2>
<?php if (!$custom): ?>
<p class="empty-hint">
还没有自己添加的纪念日。
<?php if ($canWrite): ?>
结婚纪念日、忌日、相识的日子…点右上角「新建纪念日」加一条。
<?php endif; ?>
</p>
<?php else: ?>
<div class="table-wrap">
<table class="table">
<thead>
<tr><th>日期</th><th>纪念日</th><th>分类</th><th>重复</th><th></th></tr>
</thead>
<tbody>
<?php foreach ($rows as $r): ?>
<tr>
<td class="nowrap"><?= (int)$r['month'] ?> 月 <?= (int)$r['day'] ?> 日</td>
<td>
<?= e((string)$r['title']) ?>
<?php if (!empty($r['is_leap'])): ?><span class="small muted">(闰月)</span><?php endif; ?>
</td>
<td><?= $kindBadge($r) ?></td>
<td class="small muted"><?= e($srcWord($r)) ?></td>
<td class="nowrap">
<?php if (($r['source'] ?? 'custom') === 'custom' && $canWrite): ?>
<a class="link-quiet" href="<?= e(url('days/edit', ['id' => (int)$r['id']])) ?>">改</a>
<form method="post" action="<?= e(url('days/destroy')) ?>" class="res-inline">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$r['id'] ?>">
<button class="btn btn-ghost btn-sm" type="submit"
onclick="return confirm('删掉这条纪念日?')">删</button>
</form>
<?php else: ?>
<span class="small muted">来自名册</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php $renderTable($custom, true); ?>
<?php endif; ?>
</div>
<?php /* ==================== ③ 来自名册的生日(在下)==================== */ ?>
<div class="card card-pad">
<h2 class="cinema-h2">
来自名册的(<?= count($derived) ?>)
<span class="hint">实时读出来的,改生日这里跟着变</span>
</h2>
<?php if (!$derived): ?>
<p class="empty-hint">
名册里还没有人填过生日。到「名册 → 编辑成员」把生日填上,这里就会自动出现。
</p>
<?php else: ?>
<?php $renderTable($derived, false); ?>
<p class="tip" style="margin-top:10px">
这一块是**实时派生**的 —— 改生日,这里跟着变,不用重复维护。
不需要在这里新建,也没法单独删(删掉生日就等于删了它)。
</p>
<?php endif; ?>
<p class="tip" style="margin-top:10px">
名册里那部分(生日)是**实时读出来的** —— 改生日,这里跟着变,不用重复维护。
所有纪念日都会作为**全天日程**出现在日历里。
</p>
</div>
+1
View File
@@ -113,6 +113,7 @@ $isLoggedIn = \App\Auth::check();
<script src="<?= e(asset('/assets/js/app.js')) ?>"></script>
<script src="<?= e(asset('/assets/js/person_picker.js')) ?>"></script>
<script src="<?= e(asset('/assets/js/filter.js')) ?>"></script>
<script src="<?= e(asset('/assets/js/preview.js')) ?>"></script>
</body>
</html>
+127
View File
@@ -0,0 +1,127 @@
<?php
/**
* 账本模块的「设置」下拉(v24 用户 2026-10-03 第 7 条)
*
* 用户原话:「共享账本,改名等内容,都放在账本的设置中,也是一样的,
* 在新建账目按钮旁边,加一个设置按钮,在里面对账本进行设置、共享等。」
*
* 所以原来那个「共享与账本」大卡片撤了,里面的东西全搬进这个 ☰:
* 共享给谁 / 取消共享 / 账本改名 / 新建账本 / 删除这本账。
* 外观与观影、任务的设置下拉一致(只留图标、排最右、条目带小图标)。
*
* ⚠️⚠️ 本片段是 `require` 进**另一个模板**里的,而 PHP 的 require 共享同一个作用域 ——
* 所以这里**绝不能**定义 / 覆盖 / unset 宿主模板用到的名字(`$canWrite` / `$curId`…)。
* 本条已实测踩到:片段结尾写了 `unset($canWrite, $curId)`,把宿主模板的
* `$canWrite` 一起干掉了 → 后面每一行 `<?php if ($canWrite): ?>` 都变成
* "Undefined variable"(页面在 debug 下会**直接把 Warning 打进正文**,
* 看着像排版坏了一小段,其实是变量被偷走)。
* 同理,_datetime.php 早年在任务页覆盖过 $t —— 同一个坑,别再踩第三次。
* 所以下面所有局部变量一律加 `$ledSet` 前缀,并且只 unset **自己定义**的那些。
*
* 用法(require 前 set 好):
* $cur 当前账本(含 name / my_perm)
* $shares 当前账本的共享列表
* $people 名册(共享给谁)
*/
$ledSetCanWrite = \App\Auth::canWrite() && \App\Ledger::canWrite($cur ?? []);
$ledSetCurId = (int)($cur['id'] ?? 0);
$ledSetIcon = static function (string $name): string {
$paths = [
'share' => '<circle cx="6" cy="6.2" r="2.4"/><circle cx="12.4" cy="9.6" r="2"/><path d="M2.2 13.4c0-1.9 1.7-3 3.8-3s3.8 1.1 3.8 3M9.6 13.4c0-1.5 1.3-2.4 2.8-2.4s2.8.9 2.8 2.4"/>',
'rename'=> '<path d="M2.6 13.4l.6-3 7.4-7.4 2.4 2.4-7.4 7.4zM9.6 4l2.4 2.4"/>',
'add' => '<path d="M8 3.2v9.6M3.2 8h9.6"/>',
'del' => '<path d="M3.4 4.6h9.2M6.6 4.6V3.2h2.8v1.4M4.8 4.6l.7 8.8h5l.7-8.8"/>',
];
$d = $paths[$name] ?? '';
if ($d === '') { return ''; }
return '<svg class="mi" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"'
. ' fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"'
. ' stroke-linejoin="round">' . $d . '</svg>';
};
?>
<details class="movie-set menu led-set">
<summary class="btn btn-icon" title="账本设置" aria-label="账本设置"><svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"><path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/></svg></summary>
<div class="menu-list led-set-list">
<?php if (!$ledSetCanWrite): ?>
<div class="led-set-block">
<p class="small muted" style="margin:0">这本账你只有只读权限,能看不能改。</p>
</div>
<?php else: ?>
<?php /* ---- 共享:给谁 + 权限 + 取消 ---- */ ?>
<div class="led-set-block">
<div class="cal-set-h">共享给谁(对方就能记能看)</div>
<?php if (!empty($shares)): ?>
<ul class="led-set-shares">
<?php foreach ($shares as $s): ?>
<li>
<?= person_chip([
'id' => (int)$s['person_id'], 'name' => (string)$s['name'],
'avatar' => $s['avatar'] ?? null, 'avatar_color' => $s['avatar_color'] ?? null,
]) ?>
<span class="node-badge"><?= ($s['perm'] ?? 'read') === 'write' ? '可写' : '只读' ?></span>
<form method="post" action="<?= e(url('ledger/unshare')) ?>" class="res-inline">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $ledSetCurId ?>">
<input type="hidden" name="person_id" value="<?= (int)$s['person_id'] ?>">
<button class="btn btn-ghost btn-sm" type="submit">取消</button>
</form>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p class="small muted" style="margin:0 0 6px">还没有共享给任何人。</p>
<?php endif; ?>
<form method="post" action="<?= e(url('ledger/share')) ?>" class="led-set-form-in">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $ledSetCurId ?>">
<?php
$ppName = 'person_id';
$ppPeople = $people;
$ppSelected = [];
$ppMode = 'single';
$ppOpenBtn = '选择共享给谁';
$ppTitle = '账本共享给谁';
$ppEmptyText= '未选择';
require __DIR__ . '/../_person_picker.php';
?>
<select class="select" name="perm">
<?php foreach (\App\Ledger::PERM as $pk => $pv): ?>
<option value="<?= e($pk) ?>"><?= e($pv) ?></option>
<?php endforeach; ?>
</select>
<button class="btn btn-sm" type="submit">共享</button>
</form>
</div>
<?php /* ---- 改名 ---- */ ?>
<div class="led-set-block">
<div class="cal-set-h">账本名字</div>
<form method="post" action="<?= e(url('ledger/book_rename')) ?>" class="led-set-form-in">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $ledSetCurId ?>">
<input class="input" name="name" value="<?= e((string)($cur['name'] ?? '')) ?>" required>
<button class="btn btn-sm" type="submit">改名</button>
</form>
</div>
<?php /* ---- 新建 / 删除 ---- */ ?>
<div class="led-set-block">
<form method="post" action="<?= e(url('ledger/book_add')) ?>" class="led-set-form-in">
<?= csrf_field() ?>
<input class="input" name="name" placeholder="新账本名,如:孩子的教育金" required>
<button class="btn btn-sm" type="submit">新建账本</button>
</form>
<form method="post" action="<?= e(url('ledger/book_del')) ?>" class="led-set-form-in" style="margin-top:6px">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $ledSetCurId ?>">
<button class="btn btn-ghost btn-sm" type="submit"
onclick="return confirm('删掉这本账?里面的账目会一起删掉。')">删除这本账</button>
</form>
</div>
<?php endif; ?>
</div>
</details>
<?php
unset($ledSetCanWrite, $ledSetCurId, $ledSetIcon);
+148 -98
View File
@@ -1,33 +1,53 @@
<?php
/**
* 财务 / 账本(v24 用户第 15 条)
* 财务 / 账本(v24 用户第 15 条;2026-10-03 第 7、8 条重排)。
*
* 用户原话:「先创建一个家庭,或者说,创建一个账本,这个账本,可以共享给某个人,
* 共享后,这个人就可以往这个账本加入账目,这样,双方都可以看到所有的账目,
* 最后计算出总数,这就是一个家庭的总账目。」
* 用户要求的页面结构(第 7 条原话):
* 「上面是概览,下面就是具体账目,添加账目的功能和新增日程之类的一样,
* 放在右侧的按钮。……共享账本,改名等内容,都放在账本的设置中,
* 也是一样的,在新建账目按钮旁边,加一个设置按钮,在里面对账本进行设置、共享等。
* 挂在谁名下,应该默认是自己,如果要更改,点一下,弹出选人框。」
*
* 页面结构就是照着这句话来的:
* 顶上一排账本(切换 / 新建)→ 汇总卡(资产 / 负债 / 净资产)→ 账目表 → 共享设置。
* 第 8 条(盘点):
* 「我点击盘点,让我对一个账目的金额进行重新输入,但是盘点之前的账目数目不能清空,
* 要记住,这样的话,每个账目的变化,就知道了……然后把这种变化,每个账目的
* 金额变化,还有总金额的变化,在账本列表上面,画出一个图,折线图这样的。」
* → 所以「账目」这块的最上面是**图**(整本账 + 每条有盘点记录的账目),
* 下面是账目表,每行带一个「盘点」入口。
*
* ⚠️ 金额全程以**分**参与计算(Ledger 里做的),这里只负责显示成元。
* 任何地方都不要拿元去加总。
*
* @param array $books 我能看到的账本(带 my_perm / entry_count)
* @param array $cur 当前账本
* @param array $entries 当前账本的账目
* @param array $summary ['asset','debt','net','by_kind','count'](单位:分)
* @param array $shares 当前账本的共享列表
* @param array $people 名册
* @param array $books 我能看到的账本(带 my_perm / entry_count)
* @param array $cur 当前账本
* @param array $entries 当前账本的账目
* @param array $summary ['asset','debt','net','by_kind','count'](单位:分)
* @param array $shares 当前账本的共享列表
* @param array $charts 有盘点历史的账目 → ['entry'=>行, 'series'=>[…] ]
* @param array $timeline 整本账的净资产时间线
* @param array $people 名册
*/
$canWrite = \App\Auth::canWrite() && \App\Ledger::canWrite($cur);
$curId = (int)$cur['id'];
$money = static fn($c): string => \App\Ledger::money($c);
$charts = $charts ?? [];
$timeline = $timeline ?? [];
// 用户第 8 条:「挂在谁名下,应该默认是自己」。这里的 $me 由 index.php 传进来(当前登录者)。
// ⚠️ 别用 `$me ?? 0` 再判 0 —— 那样一旦没传进来就会静默变成"不选",看着像默认值丢了。
$ledMe = (int)($me ?? 0);
?>
<div class="page-head">
<h1>财务</h1>
<span class="sub">家庭的账 · 共享后双方都能记、都能看</span>
<span class="sub"><?= e((string)$cur['name']) ?> · 共享后双方都能记、都能看</span>
<div class="actions">
<a class="btn btn-ghost" href="<?= e(url('ledger', ['book' => $curId])) ?>">刷新</a>
<?php /* 用户第 7 条:加账目 = 右侧按钮(与「新建日程」同一套) */ ?>
<?php if ($canWrite): ?>
<button class="btn" type="button" id="ledAddBtn">记一笔</button>
<?php else: ?>
<span class="link-quiet">只读</span>
<?php endif; ?>
<?php /* 用户第 7 条:共享 / 改名 / 新建 / 删除 全在账本设置里(☰) */ ?>
<?php $setCurrent = 'book'; require __DIR__ . '/_settings_menu.php'; ?>
</div>
</div>
@@ -42,6 +62,7 @@ $money = static fn($c): string => \App\Ledger::money($c);
</div>
<?php endif; ?>
<?php /* ==================== ① 概览 ==================== */ ?>
<div class="card card-pad led-sum">
<div class="led-sum-head">
<h2 class="cinema-h2" style="margin:0"><?= e((string)$cur['name']) ?></h2>
@@ -79,7 +100,7 @@ $money = static fn($c): string => \App\Ledger::money($c);
</div>
<?php if ($canWrite): ?>
<div class="card card-pad">
<div class="card card-pad led-add" id="ledAddCard" hidden>
<h2 class="cinema-h2">记一笔</h2>
<form method="post" action="<?= e(url('ledger/entry_add')) ?>">
<?= csrf_field() ?>
@@ -104,13 +125,22 @@ $money = static fn($c): string => \App\Ledger::money($c);
<span class="tip">负债(贷款/信用卡)也填正数,系统按类别算成负债。</span>
</div>
<div class="field">
<label for="le-person">挂在谁名下</label>
<select class="select" id="le-person" name="person_id">
<option value="0">不指定</option>
<?php foreach ($people as $p): ?>
<option value="<?= (int)$p['id'] ?>"><?= e(person_name($p)) ?></option>
<?php endforeach; ?>
</select>
<?php /* 用户第 7 条:「挂在谁名下,应该默认是自己,如果要更改,点一下,弹出选人框」
—— 用全局选人组件(与观影选人同一套,含拼音首字母联想)。 */ ?>
<label>挂在谁名下</label>
<?php
$ppName = 'person_id';
$ppPeople = $people;
// 默认就是**我自己**(用户第 8 条)。单选组件按 $ppSelected 勾选并渲染 chip,
// 传 [0] 的话会渲染成"未选择"——所以必须传真实 id。
$ppSelected = $ledMe > 0 ? [$ledMe] : [];
$ppMode = 'single';
$ppOpenBtn = '更换归属人';
$ppTitle = '这笔账挂在谁名下';
$ppEmptyText= '不指定';
$ppAllowEmpty = true;
require __DIR__ . '/../_person_picker.php';
?>
</div>
<div class="field full">
<label for="le-note">备注</label>
@@ -122,6 +152,46 @@ $money = static fn($c): string => \App\Ledger::money($c);
</div>
<?php endif; ?>
<?php /* ==================== ② 变化图(用户第 8 条)==================== */ ?>
<?php if ($charts || count($timeline) > 1): ?>
<div class="card card-pad led-charts">
<h2 class="cinema-h2">
金额变化
<span class="hint">每次「盘点」记一个点,旧数字不会被清掉</span>
</h2>
<div class="ck-grid">
<?php if (count($timeline) > 1): ?>
<div class="ck-card">
<div class="ck-head">
<b>整本账 · 净资产</b>
<span class="small muted"><?= count($timeline) ?> 个时间点</span>
</div>
<?= chart_line($timeline, '净资产', 'asset', 320) ?>
</div>
<?php endif; ?>
<?php foreach ($charts as $ch): ?>
<?php $en = $ch['entry']; $ek = (string)$en['kind']; ?>
<div class="ck-card">
<div class="ck-head">
<b><?= e((string)$en['title']) ?></b>
<span class="small muted">
<?= \App\Ledger::kindIcon($ek) ?> <?= e(\App\Ledger::kindWord($ek)) ?>
· <?= count($ch['series']) ?> 个点
</span>
</div>
<?= chart_line($ch['series'], (string)$en['title'], \App\Ledger::isDebt($ek) ? 'debt' : 'asset', 320) ?>
</div>
<?php endforeach; ?>
</div>
<?php if (!$charts): ?>
<p class="small muted" style="margin:8px 2px 0">
还没有任何盘点记录 —— 下面账目表里每行都有「盘点」,盘过之后这里就会出现它自己的曲线。
</p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php /* ==================== ③ 账目 ==================== */ ?>
<div class="card card-pad">
<h2 class="cinema-h2">账目(<?= count($entries) ?>)</h2>
<?php if (!$entries): ?>
@@ -134,7 +204,7 @@ $money = static fn($c): string => \App\Ledger::money($c);
</thead>
<tbody>
<?php foreach ($entries as $en): ?>
<?php $ek = (string)$en['kind']; $debt = \App\Ledger::isDebt($ek); ?>
<?php $ek = (string)$en['kind']; $debt = \App\Ledger::isDebt($ek); $eid = (int)$en['id']; ?>
<tr>
<td class="nowrap">
<span class="led-kind-chip<?= $debt ? ' is-debt' : '' ?>">
@@ -158,11 +228,50 @@ $money = static fn($c): string => \App\Ledger::money($c);
<td class="nowrap">
<?php if ($canWrite): ?>
<details class="led-edit">
<summary class="link-quiet">改</summary>
<summary class="link-quiet">操作</summary>
<?php /* ---- 盘点(用户第 8 条):重新输一个金额,旧值进历史 ---- */ ?>
<form method="post" action="<?= e(url('ledger/reconcile')) ?>" class="node-form led-recon">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $curId ?>">
<input type="hidden" name="id" value="<?= $eid ?>">
<h4 class="led-form-h">盘点这笔(旧金额会记进历史)</h4>
<div class="nf-grid">
<div class="field">
<label>盘点后的金额(元)</label>
<input class="input" name="amount" inputmode="decimal" required
value="<?= e(\App\Ledger::amountYuan((int)$en['amount_cents'])) ?>">
</div>
<div class="field">
<label>盘点备注</label>
<input class="input" name="note" placeholder="如:2026 年初盘点">
</div>
</div>
<div class="btn-row"><button class="btn btn-sm" type="submit">盘点</button></div>
<?php if (\App\Ledger::history($eid)): ?>
<details class="led-hist">
<summary class="link-quiet">看历史(<?= count(\App\Ledger::history($eid)) ?> 次)</summary>
<ul class="led-hist-list">
<?php foreach (\App\Ledger::history($eid) as $hs): ?>
<li>
<span class="nowrap"><?= e(substr((string)$hs['created_at'], 0, 10)) ?></span>
<b><?= e($money((int)$hs['amount_cents'])) ?></b>
<?php if (($hs['note'] ?? '') !== ''): ?>
<span class="muted small"><?= e((string)$hs['note']) ?></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</details>
<?php endif; ?>
</form>
<?php /* ---- 改 / 删(改 = 修正录错了,与"盘点"是两件事,见 Ledger::reconcile)---- */ ?>
<form method="post" action="<?= e(url('ledger/entry_update')) ?>" class="node-form">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $curId ?>">
<input type="hidden" name="id" value="<?= (int)$en['id'] ?>">
<input type="hidden" name="id" value="<?= $eid ?>">
<h4 class="led-form-h">更正这笔(当作当初就录错了,不留历史)</h4>
<div class="nf-grid">
<div class="field">
<label>类别</label>
@@ -188,12 +297,12 @@ $money = static fn($c): string => \App\Ledger::money($c);
<input class="input" name="note" value="<?= e((string)($en['note'] ?? '')) ?>">
</div>
</div>
<div class="btn-row"><button class="btn btn-sm" type="submit">保存</button></div>
<div class="btn-row"><button class="btn btn-sm" type="submit">保存更正</button></div>
</form>
<form method="post" action="<?= e(url('ledger/entry_del')) ?>" class="res-inline">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $curId ?>">
<input type="hidden" name="id" value="<?= (int)$en['id'] ?>">
<input type="hidden" name="id" value="<?= $eid ?>">
<button class="btn btn-ghost btn-sm" type="submit"
onclick="return confirm('删掉这笔账目?')">删除</button>
</form>
@@ -215,74 +324,15 @@ $money = static fn($c): string => \App\Ledger::money($c);
<?php endif; ?>
</div>
<div class="card card-pad">
<h2 class="cinema-h2">共享与账本</h2>
<div class="led-shares">
<span class="res-label">已共享给</span>
<?php if (!$shares): ?>
<span class="small muted">还没有共享给任何人。</span>
<?php endif; ?>
<?php foreach ($shares as $s): ?>
<span class="led-share-chip">
<?= person_chip([
'id' => (int)$s['person_id'], 'name' => (string)$s['name'],
'avatar' => $s['avatar'] ?? null, 'avatar_color' => $s['avatar_color'] ?? null,
]) ?>
<span class="node-badge"><?= ($s['perm'] ?? 'read') === 'write' ? '可写' : '只读' ?></span>
<?php if ($canWrite): ?>
<form method="post" action="<?= e(url('ledger/unshare')) ?>" class="res-inline">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $curId ?>">
<input type="hidden" name="person_id" value="<?= (int)$s['person_id'] ?>">
<button class="btn btn-ghost btn-sm" type="submit">取消</button>
</form>
<?php endif; ?>
</span>
<?php endforeach; ?>
</div>
<?php if ($canWrite): ?>
<div class="led-ops">
<?php
$ppName = 'person_id';
$ppPeople = $people;
$ppSelected = [];
$ppMode = 'single';
$ppOpenBtn = '选择共享给谁';
$ppTitle = '账本共享给谁';
$ppEmptyText = '未选择';
?>
<form class="inline-form" method="post" action="<?= e(url('ledger/share')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $curId ?>">
<?php require __DIR__ . '/../_person_picker.php'; ?>
<select class="select" name="perm">
<?php foreach (\App\Ledger::PERM as $pk => $pv): ?>
<option value="<?= e($pk) ?>"><?= e($pv) ?></option>
<?php endforeach; ?>
</select>
<button class="btn btn-sm" type="submit">共享</button>
</form>
<form class="inline-form" method="post" action="<?= e(url('ledger/book_rename')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $curId ?>">
<input class="input" name="name" value="<?= e((string)$cur['name']) ?>" required>
<button class="btn btn-ghost btn-sm" type="submit">账本改名</button>
</form>
<form class="inline-form" method="post" action="<?= e(url('ledger/book_add')) ?>">
<?= csrf_field() ?>
<input class="input" name="name" placeholder="新账本名,如:孩子的教育金" required>
<button class="btn btn-ghost btn-sm" type="submit">新建账本</button>
</form>
<form class="inline-form" method="post" action="<?= e(url('ledger/book_del')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="ledger_id" value="<?= $curId ?>">
<button class="btn btn-ghost btn-sm" type="submit"
onclick="return confirm('删掉这本账?里面的账目会一起删掉。')">删除这本账</button>
</form>
</div>
<?php endif; ?>
</div>
<script>
(function () {
var btn = document.getElementById('ledAddBtn');
var card = document.getElementById('ledAddCard');
if (!btn || !card) return;
btn.addEventListener('click', function () {
card.hidden = !card.hidden;
btn.textContent = card.hidden ? '记一笔' : '收起';
if (!card.hidden) { card.scrollIntoView({ block: 'nearest' }); }
});
})();
</script>
+101 -54
View File
@@ -42,10 +42,33 @@ $renderGrid = function (array $list) use ($meId, $canMove, $groups): void {
// ⚠️ 一律走 person_name():它按 shown → my_nickname → name 的顺序取,
// 这里自己拼一次迟早漏掉 my_nickname(v14 前就是漏的,于是设了称呼也不显示)。
$pshow = person_name($p);
// 用户 2026-10-03 第 3 条:「如果有昵称,就不要显示真实姓名了」。
// 所以这里只在**没有昵称/称呼**、显示名就是本名时,本名才等于 $pshow(不重复画)。
$pNick = (string)($p['my_nickname'] ?? '');
$pReal = (string)$p['name'];
$pid = (int)$p['id'];
// 用户第 3 条:行高要矮。姓名行右边的徽标只留最必要的几个,
// 「已开通 / 访客 / 家谱 / 待确认」这些收成小徽标(有就显示,没有就不占位)。
// ⚠️「家谱」那枚必须带 title 说明来历 —— 不然"我没加过他,他怎么在我名册里"
// 会让人以为数据坏了(v7 加它就是为了回答这个问题,别在改版时弄丢)。
$metaBits = [];
if ($pid === (int)$meId) { $metaBits[] = ['我', '']; }
$r = $p['account_role'] ?? '';
if ($r === 'admin' && ($p['account_status'] ?? '') === 'active') {
$metaBits[] = ['管理员', ''];
} elseif ($r === 'guest') {
$metaBits[] = ['访客', ''];
} elseif (!empty($p['account_id'])) {
$metaBits[] = ['已开通', ''];
}
if (($p['roster_source'] ?? '') === 'kin') {
$metaBits[] = ['家谱', '他在你的家谱树上(配偶/父母/子女/祖孙…),自动加入你的名册'];
}
if (!empty($p['is_placeholder'])) { $metaBits[] = ['待确认', '']; }
?>
<div class="person" data-person="<?= $pid ?>" <?= $canMove ? 'draggable="true"' : '' ?>>
<div class="person" data-person="<?= $pid ?>" <?= $canMove ? 'draggable="true"' : '' ?>
data-search="<?= e($pshow . ' ' . $pReal . ' ' . (string)($p['email'] ?? '') . ' ' . (string)($p['org'] ?? '') . ' ' . (string)($p['phone_plain'] ?? '')) ?>"
data-initials="<?= e(\App\Pinyin::initials($pReal . ' ' . $pNick)) ?>">
<?php if ($canMove): ?>
<span class="drag-handle" title="拖到我想要的位置 / 那一栏" aria-hidden="true">⠿</span>
<?php endif; ?>
@@ -55,49 +78,48 @@ $renderGrid = function (array $list) use ($meId, $canMove, $groups): void {
<div class="ph"><img src="<?= e(avatar_url($p['avatar'])) ?>" alt="" draggable="false"></div>
<div class="pb">
<div class="pname">
<?php /* ⚠️ 姓名必须是 .pname 里的**第一段裸文本**,不要包 <span>。
① 现有的 e2e 断言就是按这个形状读「这一行显示的是谁」
(person_names():只认 <div class="pname"> 内的第一段文本)——
包一层 span 会让它读到空串,6 条断言齐刷刷变红,
而页面看着完全正常(这种"改样式把测试打挂"最难查);
② 包起来也没有任何用处:.pname 本身已经带字重与字号,
下面的关系标签/徽标都在姓名**之后**,不需要靠 span 定位。 */ ?>
<?= e($pshow) ?>
<?php if ($pid === (int)$meId): ?><span class="badge badge-me">我</span><?php endif; ?>
<?php if (!empty($p['is_placeholder'])): ?><span class="badge">待确认</span><?php endif; ?>
<?php /* 用户第 4 条:与我的关系放姓名右边(列表里一眼能看到) */ ?>
<?php if (!empty($p['label']) && $p['label'] !== '我'): ?>
<span class="rel-label"><?= e($p['label']) ?></span>
<?php endif; ?>
<?php foreach ($metaBits as [$b, $bTitle]): ?>
<span class="badge<?= $b === '我' ? ' badge-me' : ($b === '已开通' ? ' badge-open' : '') ?>"
<?= $bTitle !== '' ? 'title="' . e($bTitle) . '"' : '' ?>><?= e($b) ?></span>
<?php endforeach; ?>
</div>
<?php /* 用户第 4 条:中间显示几个重要信息 —— 手机号 / 生日。
关系标签已挪到姓名行,这里只放"事实性"的两项。 */ ?>
<div class="pfacts">
<?php if (($p['phone_plain'] ?? '') !== ''): ?>
<span class="pfact" title="手机号">
<span class="pfact-k">手机</span><?= e((string)$p['phone_plain']) ?>
</span>
<?php endif; ?>
<?php if (($p['birthday_show'] ?? '') !== ''): ?>
<span class="pfact" title="<?= e((string)$p['birthday_kind']) ?>生日">
<span class="pfact-k"><?= e((string)$p['birthday_kind']) ?></span><?= e((string)$p['birthday_show']) ?>
</span>
<?php endif; ?>
</div>
<div class="pmeta">
<?php
$r = $p['account_role'] ?? '';
if ($r === 'admin' && ($p['account_status'] ?? '') === 'active') {
echo '<span class="badge badge-admin">管理员</span>';
} elseif ($r === 'guest') {
echo '<span class="badge">访客</span>';
} elseif (!empty($p['account_id'])) {
echo '<span class="badge badge-open">已开通</span>';
}
// 我叫他别的名字时,把本名再用小字附上,免得自己都认不出这人是谁
if ($pNick !== '' && $pNick !== (string)$p['name']) {
echo ' · <span class="muted">' . e((string)$p['name']) . '</span>';
}
// v7:因家谱关系自动进名册的人,标出来历 ——
// 不然"我没加过他,他怎么在我名册里"会让人怀疑数据坏了
if (($p['roster_source'] ?? '') === 'kin') {
echo ' <span class="badge" title="他在你的家谱树上(配偶/父母/子女/祖孙…),自动加入你的名册">家谱</span>';
}
?>
</div>
<?php
// 用户第 3 条:一行放齐「手机号 / 阴历+阳历生日(带年份)/ 邮箱 / 工作单位」。
// 没填的项**整个 <span> 都不画** —— 留一个空标签只会让每行都长一截。
// 生日优先阳历、其次农历,用 [阳历]/[农历] 小字标明是哪一个。
$facts = [];
if (($p['phone_plain'] ?? '') !== '') {
$facts[] = ['手机', (string)$p['phone_plain']];
}
if (($p['birthday_show'] ?? '') !== '') {
$facts[] = [(string)$p['birthday_kind'], (string)$p['birthday_show']];
}
if (trim((string)($p['email'] ?? '')) !== '') {
$facts[] = ['邮箱', (string)$p['email']];
}
if (trim((string)($p['org'] ?? '')) !== '') {
$facts[] = ['单位', (string)$p['org']];
}
?>
<?php if ($facts): ?>
<div class="pfacts">
<?php foreach ($facts as [$k, $v]): ?>
<span class="pfact"><span class="pfact-k"><?= e($k) ?></span><?= e($v) ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</a>
<?php if ($canMove): ?>
@@ -138,7 +160,7 @@ $renderGrid = function (array $list) use ($meId, $canMove, $groups): void {
/** 一栏(含空栏)。空栏平时收起来,拖动时由 JS 加 is-dragging 露出来当落点。 */
$renderBlock = function (int $gid, string $name, array $list) use ($renderGrid): void {
?>
<section class="group-block<?= $list ? '' : ' is-empty' ?>" data-group="<?= $gid ?>">
<section class="group-block<?= $list ? '' : ' is-empty' ?>" data-group="<?= $gid ?>" data-filter-group>
<h2 class="group-head">
<span class="group-title"><?= e($name) ?></span>
<span class="group-n"><span class="n"><?= count($list) ?></span> 人</span>
@@ -170,18 +192,22 @@ $renderBlock = function (int $gid, string $name, array $list) use ($renderGrid):
<?php /* 用户第 4 条:这句拖动提示**去掉**(用户直接点名要删)。
功能本身不变,只是不再占版面。 */ ?>
<form class="search" method="get" action="index.php">
<?php /* 用户 2026-10-03 第 2 条:**输入即筛选**,不需要按回车。
第 3 条:搜索后的「清除」按钮要与搜索保持一致(同款 .btn 尺寸、同一行)。
⚠️ 这里仍然是个 form(没有 JS 时按回车照样能搜)——有 JS 时 filter.js 会把
提交拦下来,改成即时筛,避免整页刷新把焦点弹走。 */ ?>
<form class="search" method="get" action="index.php" data-roster-search>
<input type="hidden" name="r" value="people">
<?php /* 用户第 4 条:除了姓名/称呼/邮箱的模糊搜索,还支持**姓名首字母**
(yyq / yy / y 都能搜到「杨永全」)。后端在 Person::roster 里按
"汉字转首字母后再比对"实现,所以这里只要说清楚用法。 */ ?>
<input class="input" name="q" value="<?= e($q) ?>"
<input class="input" name="q" id="rosterSearch" data-filter="#rosterBox"
data-filter-empty="#rosterEmpty" data-filter-clear=".js-roster-clear"
value="<?= e($q) ?>" autocomplete="off"
placeholder="姓名 / 称呼 / 邮箱 / 手机号,或姓名首字母(如 yyq)">
<button class="btn btn-ghost btn-sm" type="submit">搜索</button>
<?php if ($q !== ''): ?>
<a class="link-quiet" href="<?= e(url('people')) ?>">清除</a>
<?php endif; ?>
<button class="btn btn-ghost btn-sm js-roster-clear<?= $q === '' ? ' is-hidden' : '' ?>"
type="button" data-href="<?= e(url('people')) ?>">清除</button>
</form>
<p class="small muted search-count" id="rosterCount" style="margin:-8px 0 10px"></p>
<p class="small muted" id="rosterEmpty" hidden>没有匹配的人。</p>
<?php if (!$people): ?>
<div class="empty">
@@ -209,14 +235,12 @@ $renderBlock = function (int $gid, string $name, array $list) use ($renderGrid):
<?php endif; ?>
<?php endif; ?>
</div>
<?php elseif ($q !== ''): ?>
<?php /* 搜索时按"命中的人"平铺 —— 分栏会把一次搜索拆成一堆只有一两个人的碎块,反而更难看 */ ?>
<p class="small muted" style="margin:0 0 12px">
找到 <?= count($people) ?> 个匹配「<?= e($q) ?>」的人(搜索时不分组)。
</p>
<?php $renderGrid($people); ?>
<?php else: ?>
<div class="roster<?= $canMove ? ' is-droppable' : '' ?>"
<?php /* ⚠️ 搜索与否**都走同一张列表**(v24 用户第 2 条之后)。
原来搜索时会把分组拆掉、平铺成一堆卡片,看着"搜的时候样式变了";
现在一律按分组呈现,filter.js 会把没命中的行藏起来,
整栏都不剩人时连栏一起收 —— 搜索结果与平时长得一样,只少了不匹配的。 */ ?>
<div class="roster<?= $canMove ? ' is-droppable' : '' ?>" id="rosterBox"
data-reorder="<?= e(url('people/reorder')) ?>"
data-csrf="<?= e(csrf_token()) ?>">
<?php foreach ($groups as $g): ?>
@@ -238,3 +262,26 @@ $renderBlock = function (int $gid, string $name, array $list) use ($renderGrid):
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($q !== '' || $canMove): ?>
<script>
(function () {
/* 「清除」按钮:有 JS 时不动页面、只清空输入并立刻重筛
(data-href 是没有 JS 时的兜底:直接跳回不带 q 的名册)。 */
var btn = document.querySelector('.js-roster-clear');
var input = document.getElementById('rosterSearch');
if (!btn || !input) { return; }
function syncClear() {
btn.classList.toggle('is-hidden', (input.value || '').trim() === '');
}
input.addEventListener('input', syncClear);
btn.addEventListener('click', function () {
// filter.js 里已经挂了"点它就清空重筛",这里只负责同步按钮显隐;
// 没有 filter.js(极老浏览器)时退化成跳转。
if (!window.__fbFilterLoaded) { window.location.href = btn.getAttribute('data-href'); }
setTimeout(syncClear, 0);
});
syncClear();
})();
</script>
<?php endif; ?>
+16 -2
View File
@@ -44,7 +44,18 @@
</select>
</div>
<ul class="pick-list">
<?php /* 用户 2026-10-03 第 2 条:所有"找个人"的地方都要**输入即筛选**。
这一页也是找人的地方(家里已有的人可能有几十个),
所以同样挂上 filter.js —— 行上带 data-search / data-initials。 */ ?>
<div class="search pick-search">
<label class="sr-only" for="pickFilter">筛选</label>
<input class="input" id="pickFilter" type="text" autocomplete="off"
data-filter="#pickList" data-filter-empty="#pickEmpty"
placeholder="输入名字或拼音首字母筛选,如 yyq">
</div>
<p class="small muted" id="pickEmpty" hidden>没有匹配的人。</p>
<ul class="pick-list" id="pickList">
<?php foreach ($people as $p): $pid = (int)$p['id']; ?>
<?php
// 显示名优先用「我怎么称呼他」:别人录的名字未必是我对他的叫法
@@ -52,8 +63,11 @@
if ($shown === '') {
$shown = (string)$p['name'];
}
$pReal = (string)$p['name'];
?>
<li class="pick-row">
<li class="pick-row"
data-search="<?= e($shown . ' ' . $pReal . ' ' . (string)($p['email'] ?? '')) ?>"
data-initials="<?= e(\App\Pinyin::initials($pReal)) ?>">
<label class="pick-item">
<input type="checkbox" name="ids[]" value="<?= $pid ?>">
<img class="pick-ph" src="<?= e(avatar_url($p['avatar'])) ?>" alt="">
+64 -5
View File
@@ -28,9 +28,41 @@ $canWrite = \App\Auth::canWrite();
</div>
</div>
<?php /* v24(用户 2026-10-02 第 18 条):新建资源页去掉「搜索资源」。
资源本来就不多,列表默认折叠、一眼能扫完;搜索框反而把「新建」按钮挤下去了。
真的找不着再靠浏览器的 Ctrl+F,不为一个短列表专门养一套搜索。 */ ?>
<?php /* v24(用户 2026-10-02 第 18 条):**新建资源页**去掉「搜索资源」——
资源本来就不多,搜索框反而把「新建」按钮挤下去了。
⚠️ 但 2026-10-03 第 6 / 10 条把搜索**请回列表页**了,而且是"上来就是搜索":
资源会越攒越多(第 10 条原话:「可能会非常多」),没有搜索就只能滚动。
两件事不矛盾:新建那块仍然干净,搜索长在**列表**上。
区别在于现在是页面顶部的**第一块**,不是夹在新建表单里的一个输入框。 */ ?>
<div class="card card-pad res-search-card">
<form class="search res-search" method="get" action="index.php">
<input type="hidden" name="r" value="resources">
<input type="hidden" name="sort" value="<?= e($sort) ?>">
<label class="sr-only" for="resKw">搜索资源</label>
<input class="input" id="resKw" name="keyword" value="<?= e($keyword) ?>"
placeholder="搜标题 / 正文,如「身份证」" autocomplete="off">
<button class="btn btn-ghost btn-sm" type="submit">搜索</button>
<?php if ($keyword !== ''): ?>
<a class="btn btn-ghost btn-sm" href="<?= e(url('resources')) ?>">清除</a>
<?php endif; ?>
</form>
<?php /* 排序:最新新增 / 最近改动。用链接而不是下拉,一眼看出当前按什么排的。 */ ?>
<div class="res-sortbar">
<span class="small muted">排序</span>
<span class="seg">
<a class="seg-btn<?= $sort === 'used' ? ' is-on' : '' ?>"
href="<?= e(url('resources', ['sort' => 'used', 'keyword' => $keyword])) ?>">最近改动</a>
<a class="seg-btn<?= $sort === 'new' ? ' is-on' : '' ?>"
href="<?= e(url('resources', ['sort' => 'new', 'keyword' => $keyword])) ?>">最新新增</a>
</span>
<?php if (!$showAll && $totalAll > count($rows)): ?>
<a class="link-quiet res-showall" href="<?= e(url('resources', ['sort' => $sort, 'keyword' => $keyword, 'all' => 1])) ?>">
显示全部 <?= (int)$totalAll ?> 条
</a>
<?php endif; ?>
</div>
</div>
<?php if ($canWrite): ?>
<div class="card card-pad" id="resAddCard" <?= $isEditing ? '' : 'hidden' ?>>
@@ -82,10 +114,27 @@ $canWrite = \App\Auth::canWrite();
<?php endif; ?>
<div class="card card-pad">
<h2 class="cinema-h2">资源列表</h2>
<h2 class="cinema-h2">
资源列表
<?php
// ⚠️ 提示语要说清"为什么只有这些":
// · 搜索时只有几条是**因为搜索**(不是被截断)→ 别在这儿提"只显示最新 10 条",
// 否则用户会以为"搜出来的结果又被砍了";
// · 没搜索又确实多于 10 条,才提示截断,并给出"显示全部"。
?>
<?php if ($keyword !== ''): ?>
<span class="hint">匹配「<?= e($keyword) ?>」的 <?= count($rows) ?> 条</span>
<?php elseif (!$showAll && $totalAll > count($rows)): ?>
<span class="hint">只显示最新的 <?= (int)$limit ?> 条(共 <?= (int)$totalAll ?> 条)</span>
<?php else: ?>
<span class="hint">共 <?= count($rows) ?> 条</span>
<?php endif; ?>
</h2>
<?php if (!$rows): ?>
<p class="empty-hint">
还没有资源。证件、照片、账号这些"挂在某人名下的东西"都可以记在这里。
<?= $keyword !== ''
? '没有匹配「' . e($keyword) . '」的资源,换个词试试。'
: '还没有资源。证件、照片、账号这些"挂在某人名下的东西"都可以记在这里。' ?>
</p>
<?php else: ?>
<div class="res-list">
@@ -188,6 +237,16 @@ $canWrite = \App\Auth::canWrite();
</details>
<?php endforeach; ?>
</div>
<?php /* 用户第 10 条:截断的地方要留一个明确的出口,别让人以为"就只有这 10 条"。 */ ?>
<?php if (!$showAll && $totalAll > count($rows)): ?>
<div class="res-more">
<a class="btn btn-ghost btn-sm"
href="<?= e(url('resources', ['sort' => $sort, 'keyword' => $keyword, 'all' => 1])) ?>">
显示全部 <?= (int)$totalAll ?> 条
</a>
<span class="small muted">只按「<?= $sort === 'new' ? '最新新增' : '最近改动' ?>」取了前 <?= (int)$limit ?> 条 —— 找不到就直接搜。</span>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
+4 -23
View File
@@ -25,29 +25,10 @@
<b>没写的人才用这里的这句</b>。所以这是一句"兜底",不是全家的统一口号。
</span>
</div>
<?php /* 用户 2026-10-03 第 3 条:首页要显示"今天的天气",所以得有地方填坐标。
用 Open-Meteo(不需要 key)。只填经纬度,不填城市名 ——
经纬度是"位置",城市名只是给人看的备注。 */ ?>
<div class="field">
<label for="weather_place">天气 · 地点名</label>
<input class="input" id="weather_place" name="weather_place"
value="<?= e((string)($weatherPlace ?? '')) ?>" placeholder="如:青岛">
<span class="tip">只用于显示,随便写。</span>
</div>
<div class="field">
<label for="weather_lat">天气 · 纬度</label>
<input class="input" id="weather_lat" name="weather_lat"
value="<?= e((string)($weatherLat ?? '')) ?>" placeholder="如:36.067">
</div>
<div class="field">
<label for="weather_lon">天气 · 经度</label>
<input class="input" id="weather_lon" name="weather_lon"
value="<?= e((string)($weatherLon ?? '')) ?>" placeholder="如:120.383">
<span class="tip">
<b>三个都留空就不显示天气</b>(首页不会因此出错 —— 不猜城市,猜错比不显示更糟)。
坐标可以在地图网站上右键查。
</span>
</div>
<?php /* ⚠️ 天气的坐标输入框**从这里撤了**(用户 2026-10-03 第 1 条)。
原话是「让用户在个人设置中填写自己的城市」——
地点是**每个人自己**的事(一家人可能分处两地),而且应该是"填城市名",
不该让用户去查经纬度。现在在「个人设置 → 天气 · 我所在的城市」里。 */ ?>
</div>
<div class="btn-row">
<button class="btn" type="submit">保存</button>
+65
View File
@@ -46,6 +46,71 @@ $rosterCount = $rosterCount ?? 0;
<div class="stack-gap"></div>
<?php require __DIR__ . '/_nicknames.php'; ?>
<!-- ==================== 天气地点(用户 2026-10-03 第 1 条)==================== -->
<?php /* 原话:「天气这个这样吧,让用户在个人设置中填写自己的城市。」
所以地点从系统设置搬到了这里 —— 而且改成**城市名**,不是经纬度:
填坐标是我们要解决的实现细节(App\Geo 内置 197 个地级市离线查),
不该甩给用户。内置表里没有的(镇 / 村 / 海外)才需要填坐标。 */ ?>
<div class="card card-pad" id="weather" style="margin-top:20px">
<h2 class="section-title">
天气 · 我所在的城市
<span class="hint">只影响你自己首页上的那一格</span>
</h2>
<p class="small muted" style="margin:0 0 16px">
填个城市名就行(如「青岛」)。首页那句问候旁边会显示这儿的天气 ——
<b>每人一份</b>,孩子在外地读书,他填他的、你看你的。
<br>留空就是不显示天气(不影响别的东西)。
</p>
<form method="post" action="<?= e(url('settings/weather')) ?>">
<?= csrf_field() ?>
<div class="form-grid">
<div class="field">
<label for="w-city">城市</label>
<input class="input" id="w-city" name="city" maxlength="30"
value="<?= e((string)($weatherCity ?? '')) ?>"
placeholder="如:青岛 / 山东青岛 / 内蒙古包头" autocomplete="off">
</div>
<div class="field">
<label for="w-lat">纬度(可选)</label>
<input class="input" id="w-lat" name="lat" value="<?= e((string)($weatherLat ?? '')) ?>"
placeholder="内置表里没有的地方才需要">
</div>
<div class="field">
<label for="w-lon">经度(可选)</label>
<input class="input" id="w-lon" name="lon" value="<?= e((string)($weatherLon ?? '')) ?>"
placeholder="如 120.38">
</div>
</div>
<div class="btn-row">
<button class="btn" type="submit">保存天气地点</button>
</div>
</form>
<?php if (!empty($weatherAt)): ?>
<p class="small muted" style="margin:12px 0 0">
现在按 <b><?= e((string)$weatherAt['place']) ?></b>
(<?= e((string)$weatherAt['lat']) ?> , <?= e((string)$weatherAt['lon']) ?>)取天气。
<?php if (($weatherCity ?? '') !== ''): ?>
不是这里?换个写法试试,比如加上省份:「山东青岛」。
<?php endif; ?>
</p>
<?php elseif (($weatherCity ?? '') !== ''): ?>
<p class="small muted" style="margin:12px 0 0">
<b class="warn-label">这个城市名没认出坐标</b>(首页就看不到天气了)。
换个写法试试(如「山东青岛」),或者直接填经纬度。
</p>
<?php endif; ?>
</div>
<?php
// 内置表里有几个城市,直接说清楚 —— 用户不用猜"到底支持哪些"
$fbCityN = count(\App\Geo::CITIES);
?>
<p class="small muted" style="margin:10px 2px 0">
内置了 <b><?= (int)$fbCityN ?></b> 个城市(全国地级市 + 直辖市),一般常用的都在里面。
</p>
<!-- ==================== 我的分组 ==================== -->
<div class="card card-pad" style="margin-top:20px">
<h2 class="section-title">
+71 -50
View File
@@ -1,27 +1,52 @@
<?php
/**
* 任务 · 看板(v12):待办 / 进行中 / 已完成 三列。
* 任务 · 看板(v12;v24 用户 2026-10-03 第 7 条重做列的含义)。
*
* 拖动:卡片是 HTML5 draggable,松手时把「拖到哪一列、放在谁后面」写进一个隐藏表单再提交
* —— **没有 JS 时每列下方的 ← → 按钮同样能搬**(渐进增强:功能是有的,拖动只是更顺手)。
* ⚠️ 第 7 条原话:「任务模块跟我想的不同,每个人自定义的看板,不是显示在现在的看板上面,
* 而是**直接代替现在的待办和进行中**,是看板,而不是看板的分类。」
*
* ⚠️ 看板里只有父任务:子任务是挂在父任务下面的(点卡片进详情看/勾),
* 混进看板会变成一堆没有上下文的小条目,"还剩几件"反而看不清。
* 于是这一页的样子变了:
* · 以前:顶上一条「看板切换」,下面是固定两列「待办 / 进行中」;
* · 现在:**一列 = 一个看板**(你自己建的那些),全都在同一屏上,
* 拖动/左右箭头 = **把卡搬到另一个看板**。
*
* @param array $board ['todo'=>[], 'doing'=>[], 'done'=>[]]
* 三条保留的纪律:
* · **已完成的任务不在看板上**(用户第 10 条:直接消失)→ 去「任务设置 → 已完成」看;
* · 拖动是渐进增强:每张卡下面还有 ← → 按钮,没有 JS / 手机上照样能搬;
* · 看板里只有父任务:子任务挂在父任务下面(点卡片进详情看/勾)。
*
* @param array $cols 看板 id => 该列的任务(键 0 = 没有看板归属的兜底列)
* @param array $boards 看板清单(顺序即列顺序)
* @param array $people 名册(选负责人 / 共享给别人)
*/
$canWrite = \App\Auth::canWrite();
// ⚠️ v24 第 10 条:看板上只有「待办 / 进行中」两列 —— 已完成的任务从看板消失,
// 要看去「任务设置 → 已完成」按分类看/搜。留着第三列就不是"直接消失"了。
$cols = [['todo', '待办'], ['doing', '进行中']];
$boards = $boards ?? [];
$boards = $boards ?? [];
$cols = $cols ?? [];
$categories = $categories ?? [];
$curBoard = (int)($curBoard ?? 0);
/* 列清单:先按 boards 的顺序,最后补上兜底列(键 0,且只在真有任务时才画)。
⚠️ 兜底列的标题不能叫「未分类」——「分类」在任务模块里是另一回事(task_categories),
叫「未分类」会让人以为是按分类分的列。这里它表示"还没归到任何看板",叫「其他」。 */
$colList = [];
foreach ($boards as $b) {
$bid = (int)$b['id'];
$colList[] = ['id' => $bid, 'name' => (string)$b['name'], 'rows' => $cols[$bid] ?? []];
}
if (!empty($cols[0])) {
$colList[] = ['id' => 0, 'name' => '其他', 'rows' => $cols[0]];
}
// 一个看板都没有(也不该发生:ensureDefaultBoard 保证至少一个)→ 给一句人话
if (!$colList) {
$colList[] = ['id' => 0, 'name' => '任务', 'rows' => $cols[0] ?? []];
}
$firstColId = (int)($colList[0]['id'] ?? 0);
$lastColIdx = count($colList) - 1;
?>
<div class="page-head">
<h1>任务</h1>
<span class="sub">共 <?= (int)$total ?> 项未完成</span>
<span class="sub">
<?= (int)$total ?> 项在做<?= count($boards) > 1 ? ',' . count($boards) . ' 个看板' : '' ?>
</span>
<div class="actions">
<?php if ($canWrite): ?>
<button class="btn" type="button" id="taskAddBtn">新建任务</button>
@@ -32,15 +57,6 @@ $curBoard = (int)($curBoard ?? 0);
</div>
</div>
<?php if (count($boards) > 1): ?>
<div class="seg kb-boards">
<?php foreach ($boards as $b): ?>
<a class="seg-btn<?= (int)$b['id'] === $curBoard ? ' is-on' : '' ?>"
href="<?= e(url('tasks', ['board' => (int)$b['id']])) ?>"><?= e((string)$b['name']) ?></a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($canWrite): ?>
<div class="card card-pad" id="taskAddCard" hidden>
<h2 class="cinema-h2">新建任务</h2>
@@ -86,13 +102,12 @@ $curBoard = (int)($curBoard ?? 0);
<?php endforeach; ?>
</select>
</div>
<?php /* 用户第 7 条:看板 = 任务"归属哪摊事",新建时直接选(不再是顶上的切换条) */ ?>
<div class="field">
<label for="tk-board">看板</label>
<select class="select" id="tk-board" name="board_id">
<?php foreach ($boards as $b): ?>
<option value="<?= (int)$b['id'] ?>" <?= (int)$b['id'] === $curBoard ? 'selected' : '' ?>>
<?= e((string)$b['name']) ?>
</option>
<option value="<?= (int)$b['id'] ?>"><?= e((string)$b['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
@@ -118,29 +133,29 @@ $curBoard = (int)($curBoard ?? 0);
</div>
<?php endif; ?>
<?php /* 拖动的提交目标:JS 把 id / 目标列 / 参照顺序填进来再 submit。
<?php /* 拖动的提交目标:JS 把 id / 目标**看板** / 参照顺序填进来再 submit。
放在看板**外面**,避免被任何一张卡片的 form 套住。 */ ?>
<form method="post" action="<?= e(url('tasks/move')) ?>" id="taskMoveForm" class="hidden-form">
<?= csrf_field() ?>
<input type="hidden" name="id" id="mvId">
<input type="hidden" name="status" id="mvStatus">
<input type="hidden" name="board" id="mvBoard">
<input type="hidden" name="before" id="mvBefore">
</form>
<div class="kanban">
<?php foreach ($cols as [$key, $label]): ?>
<section class="kb-col" data-status="<?= e($key) ?>">
<div class="kanban" data-cols="<?= count($colList) ?>">
<?php foreach ($colList as $ci => $col): $cid = (int)$col['id']; ?>
<section class="kb-col" data-board="<?= $cid ?>">
<header class="kb-head">
<b><?= e($label) ?></b>
<span class="kb-n"><?= count($board[$key] ?? []) ?></span>
<b><?= e((string)$col['name']) ?></b>
<span class="kb-n"><?= count($col['rows']) ?></span>
</header>
<div class="kb-body" data-status="<?= e($key) ?>">
<?php foreach (($board[$key] ?? []) as $t): ?>
<div class="kb-body" data-board="<?= $cid ?>">
<?php foreach ($col['rows'] as $t): ?>
<?php
$tid = (int)$t['id'];
$total = (int)($t['child_total'] ?? 0);
$kids = (int)($t['child_total'] ?? 0);
$doneN = (int)($t['child_done'] ?? 0);
$overdue = \App\Task::isOverdue($t['due_at'] ?? null) && $key !== 'done';
$overdue = \App\Task::isOverdue($t['due_at'] ?? null);
?>
<div class="kb-card<?= $overdue ? ' is-overdue' : '' ?>" data-id="<?= $tid ?>"
draggable="<?= $canWrite ? 'true' : 'false' ?>">
@@ -166,10 +181,10 @@ $curBoard = (int)($curBoard ?? 0);
<span class="node-badge" title="分类"><?= e((string)$t['category_name']) ?></span>
<?php endif; ?>
</div>
<?php if ($total > 0): ?>
<?php if ($kids > 0): ?>
<div class="kb-sub">
<span class="kb-bar"><i style="width: <?= (int)round($doneN * 100 / max(1, $total)) ?>%"></i></span>
<span class="kb-sub-n"><?= $doneN ?>/<?= $total ?></span>
<span class="kb-bar"><i style="width: <?= (int)round($doneN * 100 / max(1, $kids)) ?>%"></i></span>
<span class="kb-sub-n"><?= $doneN ?>/<?= $kids ?></span>
</div>
<?php endif; ?>
<div class="kb-foot">
@@ -182,11 +197,11 @@ $curBoard = (int)($curBoard ?? 0);
<?php endif; ?>
<?php if ($canWrite): ?>
<span class="kb-move">
<?php if ($key !== 'todo'): ?>
<?php if ($ci > 0): ?>
<button class="btn btn-ghost btn-sm" type="button"
data-move="left" data-id="<?= $tid ?>">←</button>
<?php endif; ?>
<?php if ($key !== 'done'): ?>
<?php if ($ci < $lastColIdx): ?>
<button class="btn btn-ghost btn-sm" type="button"
data-move="right" data-id="<?= $tid ?>">→</button>
<?php endif; ?>
@@ -195,7 +210,7 @@ $curBoard = (int)($curBoard ?? 0);
</div>
</div>
<?php endforeach; ?>
<?php if (!($board[$key] ?? [])): ?>
<?php if (!$col['rows']): ?>
<p class="empty-hint kb-empty">这一列是空的</p>
<?php endif; ?>
</div>
@@ -216,22 +231,28 @@ $curBoard = (int)($curBoard ?? 0);
}
if (addCancel && addCard) { addCancel.addEventListener('click', function () { addCard.hidden = true; }); }
/* ---- 左右搬(不需要拖也能用)---- */
var order = ['todo', 'doing', 'done'];
/* ---- 左右搬(不需要拖也能用)----
⚠️ 列的集合**从 DOM 现取**,不要写死数组:看板是用户自己建的,
"待办/进行中/已完成"那套常量在这儿已经不成立了。 */
var form = document.getElementById('taskMoveForm');
if (!form) return;
function submitMove(id, status, before) {
var colIds = Array.prototype.map.call(
document.querySelectorAll('.kb-body[data-board]'),
function (b) { return b.getAttribute('data-board'); }
);
function submitMove(id, board, before) {
document.getElementById('mvId').value = id;
document.getElementById('mvStatus').value = status;
document.getElementById('mvBoard').value = board;
document.getElementById('mvBefore').value = before || '';
form.submit();
}
Array.prototype.forEach.call(document.querySelectorAll('[data-move]'), function (btn) {
btn.addEventListener('click', function () {
var card = btn.closest('.kb-card');
var from = card.closest('.kb-body').getAttribute('data-status');
var i = order.indexOf(from) + (btn.getAttribute('data-move') === 'right' ? 1 : -1);
submitMove(card.getAttribute('data-id'), order[i], '');
var from = card.closest('.kb-body').getAttribute('data-board');
var i = colIds.indexOf(from) + (btn.getAttribute('data-move') === 'right' ? 1 : -1);
if (i < 0 || i >= colIds.length) { return; }
submitMove(card.getAttribute('data-id'), colIds[i], '');
});
});
@@ -285,9 +306,9 @@ $curBoard = (int)($curBoard ?? 0);
var box = kids[i].getBoundingClientRect();
if (ev.clientY < box.top + box.height / 2) { after = kids[i]; break; }
}
submitMove(dragging.getAttribute('data-id'), body.getAttribute('data-status'),
submitMove(dragging.getAttribute('data-id'), body.getAttribute('data-board'),
after ? after.getAttribute('data-id') : '');
});
});
})();
</script>
</script>