Files
laoyang 870a63df5a 首页任务浮层:补 ref_id,修复「编辑」按钮不显示 (#72)
用户 Console 提供决定性线索:
  AntD 日期控件已挂上 5 处
⇒ 前端控件、资源加载全部正常,问题不在那里。

真根因:
entry_popup.js 的 paintDetail() 里
  ed.hidden = !(isEvent && data.edit);
「编辑」按钮要求 data.source === event。

而 fb_entry_json() 算 source:
  $evKind = $ev[\x27kind\x27] ?? \x27custom\x27;      // 任务卡没传,默认 custom
  $evRef  = (int)($ev[\x27ref_id\x27] ?? 0);        // 任务卡没传 ⇒ 0
  $evOwn  = ($evKind === \x27custom\x27 && $evRef > 0);   // ⇒ false
  \x27source\x27 => $evOwn ? \x27event\x27 : \x27derived\x27,      // ⇒ derived

⇒ 编辑按钮恒不显示 ⇒ 用户点开任务只能看到只读面板
⇒ 压根没有进 _edit_form.php 的入口
⇒ 永远看不到「截止时间」(那控件只在那张表里)

讽刺的是:_card_tasks.php 是唯一给 panel 的卡片(注释还强调"只有任务会给"),
却也是唯一没给 ref_id 的调用方。

修法:第一个参数补 \x27ref_id\x27 => (int)$t[\x27id\x27]

不补 kind 的理由:fb_entry_json 的 kind 判据只用来区分
「日历里真正属于某本日历的条目」vs「从别的模块派生的」。
对任务来说它只关心"能不能在这里改",答案是能(有 tasks/edit),
走默认 \x27custom\x27 就对了。

副作用检查:del 仍为空(任务没有 calendar/event_del 那种路由,
面板里另有删除入口),所以「删除」按钮不显示 —— 这是正确的。
「编辑」只要 isEvent && data.edit 两者都满足就显示。

实测:
  改后(带 ref_id):source = event  ✅ 编辑显示  ref=49
  改前(不带)     :source = derived ❌ 编辑不显示(即 bug)
2026-11-05 17:35:54 +08:00

106 lines
7.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 首页卡片 · 近期任务(v62 从 templates/home.php 拆出来的)。
*
* 用户原话(v24 第 24 批 第 3 条):「右侧显示任务模块里面的数据,显示当前正在
* 进行当中的所有的任务,除了显示任务的标题之外,还要显示他的状态。比如说正在
* 进行中待确认等等。除了这之外,还要显示他所处的看板的名称。」
*
* 🔴 v53 第 2 条:待办也放进来,放在进行中的**下面**(不是混排)。
* ⚠️ 每行前面有复选框,点了就地完成(AJAX,不跳页);表单与脚本在 home.php 末尾
* 各一份 —— 那份**必须留着**,别跟着卡片一起删。
* ⚠️ 标题的颜色跟着**看板色**(不是任务模块的主题色),见 v32 第 4 条那条注释。
*
* 🔴🔴 v78(用户 2026-10-22):「首页点击一个任务后,除了展示信息,应该有相应的功能,
* 可以修改状态:待办、进行中,可以挪动分组,可以拖动上传附件,可以添加评论,
* 添加子任务等。其目地,是为了让用户不离开首页,就能对任务进行简单的处理。」
* ⇒ 每一行除 `data-fb-entry`(浮层要的基础信息)外,再给一个 `panel` 地址:
* 浮层拿到它就把正文换成**可操作的面板**(`templates/tasks/_panel.php`),
* 地址是 `tasks/panel?id=`,动作全走既有路由(见 helpers.php 的 task_panel_*)。
* 面板取不到(404 / 网络)时,浮层会退回 `rows` 那份只读信息 —— 不会白屏。
*/
?>
<div class="hc-body" data-tk-home-host>
<?php /* 🔴 工单 #20(用户 2026-10-28):「首页,近期任务,如果勾选了完成,
应该刷新一下这个列表,把完成的删掉。」
⇒ 勾完要把这一行**从列表里摘掉**(原来只改徽章文字,见 home.php 那段脚本)。
⚠️ 但"删到一条不剩"时卡里不能是一片空白 —— 下面这句 `empty-hint` 由服务端渲染,
前端删完不会自己冒出来,所以脚本要能在空的时候把它补上。
`data-tk-empty` 就是给脚本找它的钩子(不靠文案匹配,文案改一个字就失效)。
🔴🔴 把任务标成完成在首页有**两个入口**,两个都要删行:
① 每行前面那颗复选框 → 脚本在 `home.php` 末尾
② **点整行弹浮层** → 面板里的「状态」三段按钮 → `assets/js/task_panel.js`
真正干活的是 `assets/js/app.js` 的 `window.fbHomeTaskDrop()`,两个入口共用。
⚠️ 第一版只改了 ①,用户点的是 ②,于是"改完还是不消失"——
而我的判据只测了 ①,所以 20/0 全绿也是假绿。
**需求有几个入口,就要有几份判据。** */ ?>
<p class="empty-hint" data-tk-empty<?= $tasks ? ' hidden' : '' ?>>没有进行中的任务,也没有待办。</p>
<?php if ($tasks): ?>
<ul class="dash-list tk-list">
<?php foreach ($tasks as $t): ?>
<?php $late = \App\Task::isOverdue($t['due_at'] ?? null); ?>
<?php $tkColor = \App\Task::boardColorById((int)\App\Auth::familyId(),
(int)($t['board_id'] ?? 0) ?: null); ?>
<li class="dash-row tk-row" data-task-row="<?= (int)$t['id'] ?>"
style="--tk-c: <?= e($tkColor) ?>;">
<?php
$tkId = (int)$t['id']; $tkStatus = (string)($t['status'] ?? 'todo');
$tkBack = 'home'; $tkStatic = !\App\Auth::canWrite();
require __DIR__ . '/../_task_check.php';
?>
<span class="dash-dot" style="background: <?= e($late ? 'var(--red)' : 'var(--tk-c)') ?>;"></span>
<a class="dash-what" href="<?= e(url('tasks/show', ['id' => (int)$t['id']])) ?>"
title="<?= e((string)$t['title']) ?>"
data-fb-entry='<?= fb_entry_json([
'title' => (string)$t['title'],
'status_word' => \App\Task::statusWord((string)($t['status'] ?? 'todo')),
'note' => (string)($t['note'] ?? ''),
/* 🔴🔴 2026-11-05(用户:「网页端,在首页上修改一个日程,
没有填写截止日期的地方」):
根因:`fb_entry_json()` 用 `kind === 'custom' && ref_id > 0`
算 `$evOwn`,而这里**只传了 edit 地址、没传 ref_id**
⇒ `$evOwn = false` ⇒ `source = 'derived'`
⇒ 浮层底栏的「编辑」「删除」两颗按钮**都不显示**
⇒ 用户点开任务只能看到只读面板,压根没有进编辑表单的入口
⇒ 永远看不到「截止时间」(那控件只在 _edit_form.php 里)。
⚠️ 只补 `ref_id`,**不补 kind**:`fb_entry_json` 的判据是
`kind === 'custom'`,而这个值只用来区分
「日历里真正属于某本日历的条目」vs「从别的模块派生的」。
对任务来说它只关心"能不能在这里改",答案是**能**
(有 `tasks/edit`),所以让它走默认的 'custom' 就对了。
⚠️ 补了之后 `del` 也会变非空 —— 这是**正确的**,
任务本来就能删,只是之前被同一个 bug 一起藏掉了。 */
'ref_id' => (int)$t['id'],
/* v78:浮层把正文换成这块面板(可就地改状态/看板/子任务/附件/评论) */
'panel' => url('tasks/panel', ['id' => (int)$t['id']]),
], url('tasks/show', ['id' => (int)$t['id']]),
\App\Auth::canWrite() ? url('tasks/edit', ['id' => (int)$t['id']]) : '',
[['截止', ($t['due_at'] ?? '') !== '' ? substr((string)$t['due_at'], 0, 16) : ''],
['看板', trim((string)($t['board_name'] ?? ''))]]) ?>'
style="color: <?= e($late ? 'var(--red)' : $tkColor) ?>;">
<?= e((string)$t['title']) ?>
</a>
<span class="kb-st is-<?= e((string)($t['status'] ?? 'todo')) ?> is-static">
<?= e(\App\Task::statusWord((string)($t['status'] ?? 'todo'))) ?>
</span>
<?php if (trim((string)($t['board_name'] ?? '')) !== ''): ?>
<?php $bColor = \App\Task::boardColor($t['board_color'] ?? null, (string)$t['board_name']); ?>
<span class="tk-board" style="--bc: <?= e($bColor) ?>;">
<i class="tk-board-dot" aria-hidden="true"></i><?= e((string)$t['board_name']) ?>
</span>
<?php endif; ?>
<?php if ((int)($t['child_total'] ?? 0) > 0): ?>
<span class="dash-tag"><?= (int)$t['child_done'] ?>/<?= (int)$t['child_total'] ?></span>
<?php endif; ?>
<?php if (($t['due_at'] ?? '') !== ''): ?>
<span class="tk-due"><?= e(\App\Task::dueWord($t['due_at'] ?? null)) ?></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>