2026-09-30 11:06:22 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 家庭名册 —— 按「关系分组」分栏显示。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 两个刻意的设计:
|
|
|
|
|
|
* ① **分栏顺序由看的人自己定**($groups 已经是"按我的习惯排好"的顺序,
|
|
|
|
|
|
* 见 App\PersonGroup::orderFor)—— 所以我看到的「家人」在第一栏,
|
|
|
|
|
|
* 妈妈可以把「亲戚」挪到第一栏,两个人相安无事。
|
|
|
|
|
|
* ② 分类是全家共用的一套,所以**改一个人的分组是全家的信息**,
|
|
|
|
|
|
* 这里只有能写的人(管理员 / 家庭成员)才看得到那一行「调整分组」。
|
|
|
|
|
|
*
|
|
|
|
|
|
* ⚠️ 卡片结构是 div > a + details,**不能写成 a > form**:
|
|
|
|
|
|
* 表单套在链接里是非法 HTML,浏览器会把 DOM 拆开,表单里那个「移动」按钮
|
|
|
|
|
|
* 可能连提交机会都没有(或者把整张卡片点成跳转)。
|
|
|
|
|
|
*/
|
|
|
|
|
|
$canMove = \App\Auth::canWrite();
|
|
|
|
|
|
$total = 0;
|
|
|
|
|
|
foreach ($grouped as $list) {
|
|
|
|
|
|
$total += count($list);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 画一栏人。用闭包是因为"分好组的各栏"和"未分类"两处要画同一套卡片,
|
|
|
|
|
|
* 复制一遍迟早会改漏一处。
|
|
|
|
|
|
*/
|
|
|
|
|
|
$renderGrid = function (array $list) use ($groups, $meId, $canMove): void {
|
|
|
|
|
|
if (!$list) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
<div class="people-grid">
|
|
|
|
|
|
<?php foreach ($list as $p): ?>
|
|
|
|
|
|
<?php
|
|
|
|
|
|
// 显示名走「我怎么称呼他」:同一个孩子,爸爸看到"儿子"、妈妈看到"小宝"。
|
|
|
|
|
|
// ⚠️ 不要再读 $p['nickname'] —— 那是已废弃的旧列(全家共用一个小名)。
|
|
|
|
|
|
$pshow = (string)($p['shown'] ?? '');
|
|
|
|
|
|
if ($pshow === '') {
|
|
|
|
|
|
$pshow = (string)$p['name'];
|
|
|
|
|
|
}
|
|
|
|
|
|
$pNick = (string)($p['my_nickname'] ?? '');
|
|
|
|
|
|
$pid = (int)$p['id'];
|
|
|
|
|
|
?>
|
|
|
|
|
|
<div class="person">
|
|
|
|
|
|
<a class="person-main" href="<?= e(url('people/show', ['id' => $pid])) ?>">
|
|
|
|
|
|
<div class="ph"><img src="<?= e(avatar_url($p['avatar'])) ?>" alt=""></div>
|
|
|
|
|
|
<div class="pb">
|
|
|
|
|
|
<div class="pname">
|
|
|
|
|
|
<?= 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; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="pmeta">
|
|
|
|
|
|
<?php if (!empty($p['label']) && $p['label'] !== '我'): ?>
|
|
|
|
|
|
<span class="rel-label"><?= e($p['label']) ?></span>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<?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>';
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a>
|
|
|
|
|
|
<?php if ($canMove): ?>
|
|
|
|
|
|
<details class="person-more">
|
|
|
|
|
|
<summary>调整分组</summary>
|
|
|
|
|
|
<form method="post" action="<?= e(url('people/group')) ?>" class="person-move">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<input type="hidden" name="person_id" value="<?= $pid ?>">
|
|
|
|
|
|
<label class="sr-only" for="pg<?= $pid ?>">分组</label>
|
|
|
|
|
|
<select class="select" id="pg<?= $pid ?>" name="group_id">
|
|
|
|
|
|
<option value="">未分类</option>
|
|
|
|
|
|
<?php foreach ($groups as $g): $gid = (int)$g['id']; ?>
|
|
|
|
|
|
<option value="<?= $gid ?>"
|
|
|
|
|
|
<?= (int)($p['group_id'] ?? 0) === $gid ? 'selected' : '' ?>>
|
|
|
|
|
|
<?= e((string)$g['name']) ?>
|
|
|
|
|
|
</option>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
<button class="btn btn-ghost btn-sm" type="submit">移动</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</details>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php
|
|
|
|
|
|
};
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<div class="page-head">
|
|
|
|
|
|
<h1>家庭名册</h1>
|
2026-09-30 11:06:22 +08:00
|
|
|
|
<span class="sub">共 <?= $total ?> 人<?= $groups && $q === '' ? ',分 ' . count($groups) . ' 个关系分组' : '' ?></span>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<div class="actions">
|
|
|
|
|
|
<?php if (\App\Auth::isAdmin()): ?>
|
|
|
|
|
|
<a class="btn btn-sm" href="<?= e(url('people/new')) ?>">添加成员</a>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<form class="search" method="get" action="index.php">
|
|
|
|
|
|
<input type="hidden" name="r" value="people">
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<input class="input" name="q" value="<?= e($q) ?>" placeholder="按姓名、称呼或邮箱搜索">
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<button class="btn btn-ghost btn-sm" type="submit">搜索</button>
|
|
|
|
|
|
<?php if ($q !== ''): ?>
|
|
|
|
|
|
<a class="link-quiet" href="<?= e(url('people')) ?>">清除</a>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
|
<?php if (!$people): ?>
|
|
|
|
|
|
<div class="empty">
|
|
|
|
|
|
<b><?= $q !== '' ? '没有匹配的人' : '名册还是空的' ?></b>
|
|
|
|
|
|
<?= $q !== '' ? '换个词试试。' : '把家里人加进来,之后观影、旅行的同行人就可以直接从名册里选。' ?>
|
|
|
|
|
|
</div>
|
2026-09-30 11:06:22 +08:00
|
|
|
|
<?php elseif ($q !== ''): ?>
|
|
|
|
|
|
<?php /* 搜索时按"命中的人"平铺 —— 分栏会把一次搜索拆成一堆只有一两个人的碎块,反而更难看 */ ?>
|
|
|
|
|
|
<p class="small muted" style="margin:0 0 12px">
|
|
|
|
|
|
找到 <?= count($people) ?> 个匹配「<?= e($q) ?>」的人(搜索时不分组)。
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<?php $renderGrid($people); ?>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<?php else: ?>
|
2026-09-30 11:06:22 +08:00
|
|
|
|
<?php foreach ($groups as $g): ?>
|
|
|
|
|
|
<?php
|
|
|
|
|
|
$gid = (int)$g['id'];
|
|
|
|
|
|
$list = $grouped[$gid] ?? [];
|
|
|
|
|
|
// 空分组不画 —— 七个预置分类里家里可能只用到三个,
|
|
|
|
|
|
// 把空栏也摊出来会让名册看上去破破烂烂的
|
|
|
|
|
|
if (!$list) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
<section class="group-block">
|
|
|
|
|
|
<h2 class="group-head">
|
|
|
|
|
|
<span class="group-title"><?= e((string)$g['name']) ?></span>
|
|
|
|
|
|
<span class="group-n"><?= count($list) ?> 人</span>
|
|
|
|
|
|
</h2>
|
|
|
|
|
|
<?php $renderGrid($list); ?>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
|
|
|
|
|
|
<?php if (!empty($grouped[0])): ?>
|
|
|
|
|
|
<section class="group-block">
|
|
|
|
|
|
<h2 class="group-head">
|
|
|
|
|
|
<span class="group-title">未分类</span>
|
|
|
|
|
|
<span class="group-n"><?= count($grouped[0]) ?> 人</span>
|
|
|
|
|
|
</h2>
|
|
|
|
|
|
<p class="small muted" style="margin:-4px 0 12px">
|
|
|
|
|
|
这些人还没归到任何分组里。管理员可以在卡片下面直接选一个分组(或去「编辑成员」里改)。
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<?php $renderGrid($grouped[0]); ?>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
<?php endif; ?>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<?php endif; ?>
|