名册每人一份 · 分组两层 · 拖动排序 · 表单合一 · 裁剪可缩放

按用户十点反馈逐条落地(v5,Schema::VERSION = 5):

- 名册改成每人一份:新表 person_roster(owner_id, person_id, group_id,
  sort_order, source)。默认只看「我添加的 + 别人分享给我的」;
  source='seeded' 是升级时从老 persons.group_id 播进来的(先播数据再删列)。
- 排序不再手填:名册页直接拖动卡片(整版提交,一次 applyLayout 落库),
  无 JS 时卡片上的「调整分组」表单照旧可用。
- 分组分两层:管理员在「系统设置」维护公共分组(owner_id=0),
  用户在「个人设置」加自己的分组;显示顺序各人各定、互不影响。
- 名册可共享:把名片分享给别的用户(people/share);添加成员时若系统里
  已有这个人,可直接复用(people/pick),不必重复录入。
- 「编辑成员」与「改我自己的资料」合并为同一张表(templates/people/form.php),
  两个入口 href 完全相同,h1 按改谁切换文案;个人设置页只留
  资料入口 + 称呼 + 我的分组三块,删除 templates/settings/_profile.php。
- 系统设置收进头像下拉,顶栏只剩 首页/家谱/名册。
- 裁剪器加缩放(滑块 1-4x、Ctrl+滚轮、还原):缩放只改视图大小,
  落库的归一化矩形保持不变。
- 权限:管理员可以改任何人的权限(含自己),只拦「最后一位管理员」被降级。
- 去掉首页「我的一句话」后的链接、家谱说明段、以及「还没归到任何分组」提示。

迁移安全:数据回填(PersonRoster::seedFromPersons)先于删列执行、且不进
tryStep 容错;失败步骤记入 settings.schema_upgrade_warning 并在系统设置页提示。
线上已验证:schema_upgrade_warning 为空,person_roster/person_groups.owner_id
就位,persons.group_id / sort_order 已删。

验证:php -l 48 文件;本地 e2e 277/0、老库升级 81/0、桌面几何 108/0、
移动端几何 180/0、交互 96/0;反向验证 38 条注入 + 2 条缩放注入全部命中;
部署静态断言 53/0,站点自检 7/7(--resolve 锁本机走 443,探针真的进 PHP)。
This commit is contained in:
2026-09-30 13:24:26 +08:00
parent 1c460a0e83
commit ed38a40c08
21 changed files with 1780 additions and 594 deletions
-153
View File
@@ -1,153 +0,0 @@
<?php
/**
* 「我的资料」表单(个人设置的第一块)。
*
* 只放**属于我自己的**东西:
* · 我的姓名、性别、头像、联系方式、备注
* · 我的三个生日(身份证生日只读,由证件推导)
* · 我的 slogan(没填就用家庭统一的那句)
* 排行、排序号、虚拟人物标记、以及会牵动身份证生日的身份证号,
* 都属于"管理员编名册",不在这里(这也是为了不让一次自助提交悄悄改掉这些)。
*
* 作为独立片段是因为「个人设置」页还要接上称呼、分组顺序、分类管理三块,
* 全塞一个文件里会变成没人愿意读的六百行。
*/
$p = $person;
$avatarUrl = avatar_url($p['avatar'] ?? null);
$bdSource = old('birthday_source', 'solar');
$idBd = trim((string)($p['birthday_id_card'] ?? ''));
// 裁剪比例由「这个位置显示成什么形状」决定,前后端共用同一份配置(见 App\ImageSlot)
$avSlot = \App\ImageSlot::get('avatar');
?>
<form method="post" enctype="multipart/form-data" action="<?= e(url('settings/me_save')) ?>">
<?= csrf_field() ?>
<div class="card card-pad">
<div class="form-grid">
<div class="field">
<label for="name">姓名 *</label>
<input class="input" id="name" name="name" value="<?= e(old('name', $p['name'])) ?>" required>
<?php if (!empty($errors['name'])): ?><span class="err"><?= e($errors['name']) ?></span><?php endif; ?>
</div>
<div class="field">
<label for="gender">性别</label>
<select class="select" id="gender" name="gender">
<?php $g = old('gender', $p['gender'] ?? ''); ?>
<option value="" <?= $g === '' ? 'selected' : '' ?>>不填</option>
<option value="m" <?= $g === 'm' ? 'selected' : '' ?>>男</option>
<option value="f" <?= $g === 'f' ? 'selected' : '' ?>>女</option>
</select>
</div>
<div class="field full">
<label for="slogan">我的一句话</label>
<input class="input" id="slogan" name="slogan" maxlength="200"
value="<?= e(old('slogan', $p['slogan'] ?? '')) ?>"
placeholder="留空就用家庭统一的那句:<?= e($familyMotto !== '' ? $familyMotto : '(还没设)') ?>">
<span class="tip">显示在你自己的首页标题下面。</span>
<?php if (!empty($errors['slogan'])): ?><span class="err"><?= e($errors['slogan']) ?></span><?php endif; ?>
</div>
<!-- ==================== 我的三个生日 ==================== -->
<div class="field full">
<label>我的生日</label>
<p class="small muted" style="margin:0 0 12px">
身份证上的那个由证件推导,<b>系统永远不会改它</b>;
下面两个是"实际过的阳历生日"和"长辈记的农历生日"。
改其中任意一个,另一个会自动跟着变。
</p>
<div class="field" style="margin-bottom:12px">
<label>身份证生日(只读)</label>
<span class="bd-readonly"><?= $idBd !== '' ? e($idBd) : '名册里还没填身份证号' ?></span>
</div>
<div class="bd-source">
<label for="bdSource">我这次改的是</label>
<select class="select" id="bdSource" name="birthday_source" style="width:auto">
<option value="solar" <?= $bdSource === 'solar' ? 'selected' : '' ?>>阳历(公历)</option>
<option value="lunar" <?= $bdSource === 'lunar' ? 'selected' : '' ?>>农历(阴历)</option>
</select>
<span class="small muted">选中的那一边为准,另一边自动算</span>
</div>
<div class="bd-pane" id="bdSolarWrap">
<p class="bd-pane-k">阳历生日</p>
<?php
$dtName = 'birthday_solar';
$dtValue = old('birthday_solar', \App\Birthday::pretty(\App\Birthday::solarOf($p)));
$dtId = 'birthday_solar_date';
$dtRequired = false;
require __DIR__ . '/../_datetime.php';
?>
<?php if (!empty($errors['birthday_solar'])): ?><span class="err"><?= e($errors['birthday_solar']) ?></span><?php endif; ?>
</div>
<div class="bd-pane" id="bdLunarWrap">
<p class="bd-pane-k">农历生日</p>
<?php
$dtName = 'birthday_lunar';
$dtValue = old('birthday_lunar', (string)($p['birthday_lunar'] ?? ''));
$dtId = 'birthday_lunar_date';
$dtRequired = false;
require __DIR__ . '/../_datetime.php';
?>
<label class="check-item" style="margin-top:8px">
<input type="checkbox" name="birthday_lunar_leap" value="1"
<?= old('birthday_lunar_leap', $p['birthday_lunar_leap'] ?? 0) ? 'checked' : '' ?>>
<span>这个月是<b>闰月</b>(如「闰六月」)</span>
</label>
<?php if (!empty($errors['birthday_lunar'])): ?><span class="err"><?= e($errors['birthday_lunar']) ?></span><?php endif; ?>
</div>
</div>
<div class="field">
<label for="email">邮箱</label>
<input class="input" id="email" name="email" type="email"
value="<?= e(old('email', $p['email'] ?? '')) ?>">
<?php if (!empty($errors['email'])): ?><span class="err"><?= e($errors['email']) ?></span><?php endif; ?>
</div>
<div class="field">
<label for="address">住址</label>
<input class="input" id="address" name="address"
value="<?= e(old('address', $p['address'] ?? '')) ?>">
</div>
<div class="field full">
<label for="note">备注</label>
<textarea class="input" id="note" name="note"><?= e(old('note', $p['note'] ?? '')) ?></textarea>
</div>
<div class="field">
<label for="avatar">换头像</label>
<input class="input" id="avatar" name="avatar" type="file" accept="image/*"
data-crop-ratio="<?= e((string)$avSlot['ratio']) ?>"
data-crop-w="<?= (int)$avSlot['w'] ?>"
data-crop-h="<?= (int)$avSlot['h'] ?>"
data-crop-label="<?= e((string)$avSlot['label']) ?>"
data-crop-hint="<?= e((string)$avSlot['hint']) ?>"
data-crop-preview="#avatar-preview">
<?php /* 用户挑的裁剪框(归一化 0..1,相对原图)。不裁/没 JS 就留空 = 居中裁切 */ ?>
<input type="hidden" name="avatar_crop" value="">
<span class="tip">
选好图片后会弹出裁剪框,把要留的部分框住。<b>比例按它在页面上的形状定</b>
(头像是 1:1 正方形)。上限 5MB。
</span>
<?php if (!empty($errors['avatar'])): ?><span class="err"><?= e($errors['avatar']) ?></span><?php endif; ?>
</div>
<div class="field">
<label>当前头像</label>
<img id="avatar-preview" src="<?= e($avatarUrl) ?>" alt=""
style="width:88px;height:88px;border-radius:12px;object-fit:cover;border:1px solid var(--line)">
</div>
</div>
<div class="btn-row">
<button class="btn" type="submit">保存我的资料</button>
</div>
</div>
</form>
+63 -43
View File
@@ -3,23 +3,23 @@
* 个人设置 —— 「我自己的」设置。
*
* 与「系统设置」(?r=settings,仅管理员)的分工:
* · 系统设置改一次**全家都变**:家庭 slogan、附件存储、运行环境;
* · 个人设置只影响**我自己看到的样子**:我的资料、我怎么称呼别人、
* 名册里分组的先后顺序、以及关系分类的增删改名。
* · 系统设置改一次**全家都变**:slogan 兜底、附件存储、运行环境、**公共分组**;
* · 个人设置只影响**我自己看到的样子**:我怎么称呼家人、我自己的分组。
*
* ⚠️ 关于「顺序」与「分类」这两个都不在系统设置里,理由是:
* 分类是全家共用的一套(老杨的同事,对全家来说都是同事),所以它写在共享的表里;
* 但**哪一组排前面纯属个人习惯** —— 爸爸把「家人」排第一、妈妈把「亲戚」排第一,
* 这种偏好存在 user_settings 里,跟 family 级的 settings 严格分开,
* 免得"改一个人的偏好"误伤到全家。
* ⚠️ 「我的资料」表单**不在这页**(用户明确要求合并):
* 「编辑成员」和「改自己的资料」本来就是一件事,所以只剩
* `templates/people/form.php` 那一张表单,两个入口都指过去 ——
* 这页顶部那个按钮,和名册卡片上的「编辑资料」,落到的完全是同一个页面。
*/
$groupCounts = $groupCounts ?? [];
$groupTotal = count($groups);
$rosterCount = $rosterCount ?? 0;
?>
<div class="page-head">
<h1>个人设置</h1>
<span class="sub">只影响你自己看到的样子</span>
<div class="actions">
<a class="btn btn-sm" href="<?= e(url('people/edit', ['id' => (int)$person['id']])) ?>">编辑我的资料</a>
<a class="btn btn-ghost btn-sm" href="<?= e(url('people/show', ['id' => (int)$person['id']])) ?>">看我的详情页</a>
<?php if (\App\Auth::isAdmin()): ?>
<a class="btn btn-ghost btn-sm" href="<?= e(url('settings')) ?>">系统设置</a>
@@ -27,36 +27,58 @@ $groupTotal = count($groups);
</div>
</div>
<h2 class="section-title" id="me-profile">我的资料 <span class="hint">姓名、头像、生日、联系方式</span></h2>
<?php require __DIR__ . '/_profile.php'; ?>
<div class="card card-pad">
<h2 class="section-title">我的资料 <span class="hint">姓名、头像、生日、联系方式</span></h2>
<p class="small muted" style="margin:0 0 14px">
<?= e((string)$person['name']) ?>
<?php if (trim((string)($person['slogan'] ?? '')) !== ''): ?>
· 「<?= e((string)$person['slogan']) ?>」
<?php endif; ?>
<br>
资料的编辑表单只有一张,和「编辑成员」是同一个页面 —— 从这里进去改的就是你自己。
</p>
<div class="btn-row" style="margin-top:0">
<a class="btn" href="<?= e(url('people/edit', ['id' => (int)$person['id']])) ?>">编辑我的资料</a>
<a class="btn btn-ghost" href="<?= e(url('auth/password')) ?>">改登录密码</a>
</div>
</div>
<div class="stack-gap"></div>
<?php require __DIR__ . '/_nicknames.php'; ?>
<!-- ==================== 名册分组的先后顺序 ==================== -->
<!-- ==================== 我的分组 ==================== -->
<div class="card card-pad" style="margin-top:20px">
<h2 class="section-title">
名册分组顺序
<span class="hint">只影响你自己看到的顺序</span>
我的分组
<span class="hint">公共的 + 我自己加的</span>
</h2>
<p class="small muted" style="margin:0 0 16px">
名册是按「关系分组」分栏显示的。分组本身是全家共用的一套,
但<b>哪一组排前面是你自己的习惯</b> —— 你在这里调,别人看到的顺序不变。
<?php if ($groupTotal > 1): ?><br>用 ▲ ▼ 把它挪到你要的位置,挪一下就存一次。<?php endif; ?>
名册是按「关系分组」分栏显示的。这里有两层:
<b>公共分组</b>由管理员在「系统设置」里维护(全家都能用);
你要是觉得不够,就在下面<b>加只给自己看的分组</b>,别人看不到、也不受影响。
<br>
列表里 <b>{{ 公共 }}</b> 标的是大家共用的那几个。
哪一组排前面也是你自己的习惯,用 ▲ ▼ 调 —— 别人看到的顺序不变。
<br>
你的名册现在有 <b><?= (int)$rosterCount ?></b> 人。
</p>
<?php if (!$groups): ?>
<p class="small muted" style="margin:0">还没有分组。</p>
<p class="small muted" style="margin:0 0 14px">还没有分组。加一个吧。</p>
<?php else: ?>
<ol class="order-list">
<?php foreach ($groups as $i => $g): $gid = (int)$g['id']; ?>
<?php foreach ($groups as $i => $g): $gid = (int)$g['id']; $own = (int)$g['owner_id']; ?>
<li class="order-row">
<span class="order-no"><?= $i + 1 ?></span>
<span class="order-name"><?= e((string)$g['name']) ?></span>
<span class="order-name">
<?= e((string)$g['name']) ?>
<?php if ($own === 0): ?><span class="badge">公共</span><?php else: ?><span class="badge badge-open">我的</span><?php endif; ?>
</span>
<span class="order-count"><?= (int)($groupCounts[$gid] ?? 0) ?> 人</span>
<form method="post" action="<?= e(url('settings/groups/move')) ?>" class="order-move">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= $gid ?>">
<input type="hidden" name="scope" value="me">
<button class="btn btn-ghost btn-sm" type="submit" name="dir" value="up"
title="上移一组" <?= $i === 0 ? 'disabled' : '' ?>>▲</button>
<button class="btn btn-ghost btn-sm" type="submit" name="dir" value="down"
@@ -66,38 +88,29 @@ $groupTotal = count($groups);
<?php endforeach; ?>
</ol>
<?php endif; ?>
</div>
<!-- ==================== 关系分类的增删改名 ==================== -->
<div class="card card-pad" 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>
删掉一个分类<b>不会删掉人</b>:那一组人会变成「未分类」,在名册里提醒你重新归类。
</p>
<form method="post" action="<?= e(url('settings/groups/add')) ?>" class="inline-form">
<form method="post" action="<?= e(url('settings/groups/add')) ?>" class="inline-form" style="margin-top:16px">
<?= csrf_field() ?>
<label class="sr-only" for="newGroup">新分类名</label>
<input class="input" id="newGroup" name="name" maxlength="20" placeholder="例如:邻居、球友、老同学">
<button class="btn btn-sm" type="submit">加一个分类</button>
<input type="hidden" name="scope" value="me">
<label class="sr-only" for="newMyGroup">新分组名</label>
<input class="input" id="newMyGroup" name="name" maxlength="20" placeholder="例如:球友、老同学">
<button class="btn btn-sm" type="submit">加一个我自己的分组</button>
</form>
<?php if ($groups): ?>
<ul class="group-manage">
<?php foreach ($groups as $g): $gid = (int)$g['id']; ?>
<?php
// 只有我自己建的分组才给改名 / 删除 —— 公共分组要在系统设置里改(那是管理员的事),
// 免得有人在自己设置里把"家人"改成别的、影响全家。
$mineGroups = array_values(array_filter($groups, fn($g) => (int)$g['owner_id'] > 0));
?>
<?php if ($mineGroups): ?>
<ul class="group-manage" style="margin-top:14px">
<?php foreach ($mineGroups as $g): $gid = (int)$g['id']; ?>
<li class="group-manage-row">
<form method="post" action="<?= e(url('settings/groups/rename')) ?>" class="group-rename">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= $gid ?>">
<label class="sr-only" for="gname<?= $gid ?>">分类名</label>
<input type="hidden" name="scope" value="me">
<label class="sr-only" for="gname<?= $gid ?>">分组名</label>
<input class="input" id="gname<?= $gid ?>" name="name" maxlength="20"
value="<?= e((string)$g['name']) ?>">
<button class="btn btn-ghost btn-sm" type="submit">改名</button>
@@ -109,6 +122,7 @@ $groupTotal = count($groups);
<form method="post" action="<?= e(url('settings/groups/delete')) ?>" class="del-confirm">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= $gid ?>">
<input type="hidden" name="scope" value="me">
<span class="small muted">这组的人会变成「未分类」,确定?</span>
<button class="btn btn-ghost btn-sm danger" type="submit">确认删除</button>
</form>
@@ -117,4 +131,10 @@ $groupTotal = count($groups);
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if (\App\Auth::isAdmin()): ?>
<p class="small muted" style="margin:16px 0 0">
公共分组在「<a href="<?= e(url('settings')) ?>#public-groups">系统设置</a>」里维护。
</p>
<?php endif; ?>
</div>