图片可裁剪 · 名册按关系分组 · 个人设置独立 · 顶栏下拉菜单
① 上传图片一律可裁剪,比例由图位决定
新增 app/ImageSlot.php 统一配置(头像 1:1/512×512;题图 16:9 只留注释,
将来启用只加一行)。前端只挑区域、写回归一化矩形 "x,y,w,h",真正裁剪在服务端
Upload::fitRegion():夹回图内 → 在框内居中收缩到目标比例(不外扩)→ 钉住 sx+sw ≤ w。
比例解析单独写 parseRatioAttr():parseFloat('16:9') 得 16,会把题图裁成细长条且不报错。
② 名册按关系分组,顺序每人可自定
分类全家共用(person_groups,另一个人可以自己加分类);「自己的」只体现在顺序上
(user_settings.group_order,每人一份)。persons.group_id 故意不加外键(老库只能
ADD COLUMN),完整性由 PersonGroup 保证:删分类把人置回未分类,人不会从名册消失。
③ 设置分两级:系统设置 / 个人设置
个人设置拆成 templates/settings/me.php + _profile.php + _nicknames.php,
取代 templates/people/me.php(旧路由与旧表单仍兼容)。
④ 右上角「姓名/头像 + 下拉菜单」
原来是两个裸链接,窄屏会被 CSS 藏掉导致改密码/退出不可达;改成 <details> 零 JS 菜单
(app.js 只补「点外面 / Esc」)。菜单项:个人设置 / 系统设置(管理员)/ 修改密码 / 退出登录。
Schema 版本 3 → 4;安装与老库升级共用 PersonGroup::backfillMissing() 一条回填路径。
验证:php -l 全量;e2e 202/0(新增「关系分组」与「图片裁剪」两节);老库升级 49/0;
桌面几何 108/0;移动端几何 192/0(360/375/390/414);交互 76/0;
反向验证 31/31(逐条把修复改回旧写法,指定的目标断言必须变红);
部署后本地↔线上 72 个文件 sha256 逐字节一致。
This commit is contained in:
@@ -19,6 +19,7 @@ use App\Family;
|
||||
use App\Kinship;
|
||||
use App\Nickname;
|
||||
use App\Person;
|
||||
use App\PersonGroup;
|
||||
use App\Relations;
|
||||
use App\Schema;
|
||||
use App\Setting;
|
||||
@@ -100,6 +101,36 @@ function read_birthday_input(array $existing = []): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染「个人设置」页(settings/me)。
|
||||
*
|
||||
* 抽成函数是因为它有三处调用者:正常打开、以及资料表单校验失败时的两处
|
||||
* ("我的资料"和"改密码"各一次)—— 那三处的数据装配必须完全一致,
|
||||
* 否则校验失败重画的那次会缺东西(比如分组顺序整块消失),且不会有任何报错。
|
||||
*
|
||||
* @param array $person 当前登录者自己的名册记录
|
||||
* @param array $errors 字段名 => 错误文案
|
||||
*/
|
||||
function render_me_settings(array $person, array $errors = []): void
|
||||
{
|
||||
$familyId = (int)Auth::familyId();
|
||||
$me = (int)$person['id'];
|
||||
View::render('settings/me', [
|
||||
'title' => '个人设置',
|
||||
'person' => $person,
|
||||
'errors' => $errors,
|
||||
'familyMotto' => (string)(Family::find($familyId)['motto'] ?? ''),
|
||||
// 我怎么称呼别人(视角属性,只有我自己能定)
|
||||
'nicknames' => Nickname::mineWithNames($familyId, $me),
|
||||
'options' => Person::options($familyId, $me, $me),
|
||||
'birthdays' => Birthday::describe($person),
|
||||
// 名册分组:顺序是「我的」,分类是「全家的」
|
||||
'groups' => PersonGroup::orderFor($familyId, $me),
|
||||
'groupCounts' => PersonGroup::counts($familyId, 'member'),
|
||||
], 'settings');
|
||||
}
|
||||
|
||||
|
||||
switch ($r) {
|
||||
|
||||
// ==================== 登录 / 退出 ====================
|
||||
@@ -245,38 +276,79 @@ switch ($r) {
|
||||
}
|
||||
unset($row);
|
||||
|
||||
// 按关系分组分栏。顺序用**当前用户自己的**(没自定义过就是默认顺序);
|
||||
// 归到键 0 的那一堆是还没分类的人,模板单独放在最后一栏。
|
||||
$grouped = [];
|
||||
foreach ($rows as $row) {
|
||||
$grouped[(int)($row['group_id'] ?? 0)][] = $row;
|
||||
}
|
||||
|
||||
View::render('people/index', [
|
||||
'title' => '家庭名册',
|
||||
'people' => $rows,
|
||||
'grouped'=> $grouped,
|
||||
'groups' => PersonGroup::orderFor($familyId, $me),
|
||||
'q' => $q,
|
||||
'meId' => $me,
|
||||
], 'people');
|
||||
break;
|
||||
|
||||
// ==================== 我自己的资料 ====================
|
||||
// 点顶栏的头像/名字直接落到这里。访客也能改自己的资料 ——
|
||||
/**
|
||||
* 名册卡片上的「调整分组」。
|
||||
*
|
||||
* 单开一个路由而不是让人去「编辑成员」里改,是因为那个表单很长
|
||||
* (三个生日、身份证号、住址…),为了挪一个分组去翻半页是折磨。
|
||||
* 只改 group_id 一列,所以走 Person::setGroup(),不会碰到别的字段。
|
||||
*/
|
||||
case 'people/group':
|
||||
$familyId = (int)Auth::familyId();
|
||||
if (!Auth::canWrite()) {
|
||||
flash('err', '你的身份是访客,不能改名册里的分组。');
|
||||
redirect('people');
|
||||
}
|
||||
csrf_check();
|
||||
$pid = (int)($_POST['person_id'] ?? 0);
|
||||
$gid = (int)($_POST['group_id'] ?? 0);
|
||||
$p = Person::find($pid);
|
||||
if (!$p || (int)$p['family_id'] !== $familyId) {
|
||||
flash('err', '找不到这个人。');
|
||||
redirect('people');
|
||||
}
|
||||
// 分组必须也是这个家庭的 —— 否则可以把人挂到别人家的分组上,
|
||||
// 名册按 group_id 分栏时就永远看不见他了
|
||||
if ($gid > 0 && !isset(PersonGroup::byId($familyId)[$gid])) {
|
||||
flash('err', '找不到那个分组。');
|
||||
redirect('people');
|
||||
}
|
||||
Person::setGroup($pid, $gid > 0 ? $gid : null);
|
||||
flash('ok', $gid > 0
|
||||
? '已把「' . $p['name'] . '」归到「' . PersonGroup::name($familyId, $gid) . '」。'
|
||||
: '已把「' . $p['name'] . '」改成未分类。');
|
||||
redirect('people');
|
||||
break;
|
||||
|
||||
// ==================== 我自己的资料 / 个人设置 ====================
|
||||
// 顶栏头像点开 →「个人设置」。访客也能改自己的资料 ——
|
||||
// 「个人信息」是每个人自己的事,不该因为角色是 guest 就连名字都写不了。
|
||||
case 'people/me':
|
||||
// 「我的资料」已并进「个人设置」(设置分两个维度:系统设置 / 个人设置)。
|
||||
// 旧链接、老书签、以及别处写死的 people/me 一律跳过去,不再留第二个入口。
|
||||
redirect('settings/me');
|
||||
break;
|
||||
|
||||
case 'settings/me':
|
||||
Auth::requireLogin();
|
||||
$me = (int)Auth::personId();
|
||||
$p = Person::find($me);
|
||||
$p = Person::find((int)Auth::personId());
|
||||
if (!$p) {
|
||||
flash('err', '找不到你自己的名册记录。');
|
||||
redirect('home');
|
||||
}
|
||||
clear_old();
|
||||
View::render('people/me', [
|
||||
'title' => '我的资料',
|
||||
'person' => $p,
|
||||
'errors' => [],
|
||||
'familyMotto'=> (string)(Family::find((int)Auth::familyId())['motto'] ?? ''),
|
||||
'nicknames' => Nickname::mineWithNames((int)Auth::familyId(), $me),
|
||||
'options' => Person::options((int)Auth::familyId(), $me, $me),
|
||||
'birthdays' => Birthday::describe($p),
|
||||
], 'people');
|
||||
render_me_settings($p);
|
||||
break;
|
||||
|
||||
case 'people/me_save':
|
||||
case 'settings/me_save': // 表单现在提交到这里
|
||||
case 'people/me_save': // 兼容旧链接/旧标签页里还没刷新的表单
|
||||
Auth::requireLogin();
|
||||
csrf_check();
|
||||
$me = (int)Auth::personId();
|
||||
@@ -296,21 +368,15 @@ switch ($r) {
|
||||
] + read_birthday_input($p);
|
||||
|
||||
$errors = Person::validate($d);
|
||||
$up = Upload::avatar((int)Auth::familyId(), $_FILES['avatar'] ?? []);
|
||||
// 归一化裁剪框由前端浮层写进 avatar_crop;留空 = 没裁,退回居中
|
||||
$up = Upload::avatar((int)Auth::familyId(), $_FILES['avatar'] ?? [],
|
||||
(string)($_POST['avatar_crop'] ?? ''));
|
||||
if (!$up['ok'] && ($up['error'] ?? '') !== '') {
|
||||
$errors['avatar'] = $up['error'];
|
||||
}
|
||||
if ($errors) {
|
||||
set_old($_POST);
|
||||
View::render('people/me', [
|
||||
'title' => '我的资料',
|
||||
'person' => $p,
|
||||
'errors' => $errors,
|
||||
'familyMotto'=> (string)(Family::find((int)Auth::familyId())['motto'] ?? ''),
|
||||
'nicknames' => Nickname::mineWithNames((int)Auth::familyId(), $me),
|
||||
'options' => Person::options((int)Auth::familyId(), $me, $me),
|
||||
'birthdays' => Birthday::describe($p),
|
||||
], 'people');
|
||||
render_me_settings($p, $errors);
|
||||
exit;
|
||||
}
|
||||
if ($up['ok']) {
|
||||
@@ -327,7 +393,85 @@ switch ($r) {
|
||||
Auth::refreshAvatar((string)$d['avatar']);
|
||||
clear_old();
|
||||
flash('ok', '已保存。');
|
||||
redirect('people/me');
|
||||
redirect('settings/me');
|
||||
break;
|
||||
|
||||
// ==================== 分组顺序(只影响我自己) ====================
|
||||
case 'settings/groups/move':
|
||||
Auth::requireLogin();
|
||||
csrf_check();
|
||||
$familyId = (int)Auth::familyId();
|
||||
$me = (int)Auth::personId();
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$dir = ($_POST['dir'] ?? '') === 'up' ? 'up' : 'down';
|
||||
|
||||
$list = PersonGroup::orderFor($familyId, $me);
|
||||
$ids = array_map(fn($g) => (int)$g['id'], $list);
|
||||
$at = array_search($id, $ids, true);
|
||||
|
||||
if ($at === false) {
|
||||
flash('err', '找不到这个分组。');
|
||||
redirect('settings/me');
|
||||
}
|
||||
// 挪到边界就什么也不做(按钮在两端本来就是 disabled 的,
|
||||
// 但地址栏里手敲一次也能到这儿,别让它把顺序搞乱)
|
||||
$to = $dir === 'up' ? $at - 1 : $at + 1;
|
||||
if ($to >= 0 && $to < count($ids)) {
|
||||
[$ids[$at], $ids[$to]] = [$ids[$to], $ids[$at]];
|
||||
PersonGroup::saveOrder($familyId, $me, $ids);
|
||||
}
|
||||
redirect('settings/me');
|
||||
break;
|
||||
|
||||
// ==================== 关系分类的增删改名(全家共用) ====================
|
||||
// 分类写在共享的表里,所以是"能写"的人才能动;访客只读,给个明确的说法再回去,
|
||||
// 而不是甩一张 403 页面(他明明是点了自己设置里的按钮)。
|
||||
case 'settings/groups/add':
|
||||
Auth::requireLogin();
|
||||
csrf_check();
|
||||
if (!Auth::canWrite()) {
|
||||
flash('err', '你的身份是访客,不能改关系分类。');
|
||||
redirect('settings/me');
|
||||
}
|
||||
$res = PersonGroup::add((int)Auth::familyId(), (string)($_POST['name'] ?? ''));
|
||||
flash($res['ok'] ? 'ok' : 'err', $res['ok']
|
||||
? '已加上分类「' . trim((string)($_POST['name'] ?? '')) . '」。'
|
||||
: (string)($res['error'] ?? '加不上。'));
|
||||
redirect('settings/me');
|
||||
break;
|
||||
|
||||
case 'settings/groups/rename':
|
||||
Auth::requireLogin();
|
||||
csrf_check();
|
||||
if (!Auth::canWrite()) {
|
||||
flash('err', '你的身份是访客,不能改关系分类。');
|
||||
redirect('settings/me');
|
||||
}
|
||||
$res = PersonGroup::rename((int)Auth::familyId(), (int)($_POST['id'] ?? 0),
|
||||
(string)($_POST['name'] ?? ''));
|
||||
flash($res['ok'] ? 'ok' : 'err', $res['ok']
|
||||
? '分类名已改。'
|
||||
: (string)($res['error'] ?? '改不了。'));
|
||||
redirect('settings/me');
|
||||
break;
|
||||
|
||||
case 'settings/groups/delete':
|
||||
Auth::requireLogin();
|
||||
csrf_check();
|
||||
if (!Auth::canWrite()) {
|
||||
flash('err', '你的身份是访客,不能改关系分类。');
|
||||
redirect('settings/me');
|
||||
}
|
||||
$res = PersonGroup::delete((int)Auth::familyId(), (int)($_POST['id'] ?? 0));
|
||||
if ($res['ok']) {
|
||||
$n = (int)($res['moved'] ?? 0);
|
||||
flash('ok', $n > 0
|
||||
? '分类已删掉,那 ' . $n . ' 个人现在显示在「未分类」里,去名册重新归类即可。'
|
||||
: '分类已删掉(那一组本来也没人)。');
|
||||
} else {
|
||||
flash('err', (string)($res['error'] ?? '删不了。'));
|
||||
}
|
||||
redirect('settings/me');
|
||||
break;
|
||||
|
||||
// ==================== 别人怎么称呼(只有我自己能定) ====================
|
||||
@@ -348,8 +492,9 @@ switch ($r) {
|
||||
flash('ok', trim($nick) === ''
|
||||
? '已恢复成用姓名显示。'
|
||||
: '记下了:你叫他「' . trim($nick) . '」。这只影响你自己看到的称呼。');
|
||||
if ($back === 'people/me') {
|
||||
redirect('people/me');
|
||||
if ($back === 'settings/me' || $back === 'people/me') {
|
||||
// 两个写法都认:老表单发的是 people/me(那一页现在是跳转)
|
||||
redirect('settings/me');
|
||||
}
|
||||
redirect('people/show', ['id' => $target]);
|
||||
break;
|
||||
@@ -361,6 +506,7 @@ switch ($r) {
|
||||
'title' => '添加成员',
|
||||
'person' => null,
|
||||
'errors' => [],
|
||||
'groups' => PersonGroup::byId((int)Auth::familyId()),
|
||||
], 'people');
|
||||
break;
|
||||
|
||||
@@ -383,10 +529,13 @@ switch ($r) {
|
||||
// 表现是「排行填了没用、虚拟人物标记不生效」,且不会有任何报错。
|
||||
'birth_rank' => trim((string)($_POST['birth_rank'] ?? '')),
|
||||
'is_placeholder' => !empty($_POST['is_placeholder']) ? 1 : 0,
|
||||
// 关系分组:下拉里的「未分类」是空 value,于是这里落成 null
|
||||
'group_id' => !empty($_POST['group_id']) ? (int)$_POST['group_id'] : null,
|
||||
] + read_birthday_input();
|
||||
$errors = Person::validate($d);
|
||||
|
||||
$up = Upload::avatar((int)Auth::familyId(), $_FILES['avatar'] ?? []);
|
||||
$up = Upload::avatar((int)Auth::familyId(), $_FILES['avatar'] ?? [],
|
||||
(string)($_POST['avatar_crop'] ?? ''));
|
||||
if (!$up['ok'] && ($up['error'] ?? '') !== '') {
|
||||
$errors['avatar'] = $up['error'];
|
||||
}
|
||||
@@ -398,6 +547,7 @@ switch ($r) {
|
||||
'errors' => $errors,
|
||||
'phoneValue' => $d['phone'],
|
||||
'idCardValue'=> $d['id_card'],
|
||||
'groups' => PersonGroup::byId((int)Auth::familyId()),
|
||||
], 'people');
|
||||
exit;
|
||||
}
|
||||
@@ -414,6 +564,7 @@ switch ($r) {
|
||||
'errors' => ['phone' => '这个手机号已经在名册里了'],
|
||||
'phoneValue' => $d['phone'],
|
||||
'idCardValue'=> $d['id_card'],
|
||||
'groups' => PersonGroup::byId((int)Auth::familyId()),
|
||||
], 'people');
|
||||
exit;
|
||||
}
|
||||
@@ -436,6 +587,7 @@ switch ($r) {
|
||||
'errors' => [],
|
||||
'phoneValue' => Crypto::decrypt((string)$p['phone_encrypted']),
|
||||
'idCardValue' => Crypto::decrypt((string)$p['id_card_encrypted']),
|
||||
'groups' => PersonGroup::byId((int)Auth::familyId()),
|
||||
], 'people');
|
||||
break;
|
||||
|
||||
@@ -461,9 +613,11 @@ switch ($r) {
|
||||
'avatar' => (string)$p['avatar'],
|
||||
'birth_rank' => trim((string)($_POST['birth_rank'] ?? '')),
|
||||
'is_placeholder' => !empty($_POST['is_placeholder']) ? 1 : 0,
|
||||
'group_id' => !empty($_POST['group_id']) ? (int)$_POST['group_id'] : null,
|
||||
] + read_birthday_input($p);
|
||||
$errors = Person::validate($d);
|
||||
$up = Upload::avatar((int)Auth::familyId(), $_FILES['avatar'] ?? []);
|
||||
$up = Upload::avatar((int)Auth::familyId(), $_FILES['avatar'] ?? [],
|
||||
(string)($_POST['avatar_crop'] ?? ''));
|
||||
if (!$up['ok'] && ($up['error'] ?? '') !== '') {
|
||||
$errors['avatar'] = $up['error'];
|
||||
}
|
||||
@@ -475,6 +629,7 @@ switch ($r) {
|
||||
'errors' => $errors,
|
||||
'phoneValue' => $d['phone'],
|
||||
'idCardValue' => $d['id_card'],
|
||||
'groups' => PersonGroup::byId((int)Auth::familyId()),
|
||||
], 'people');
|
||||
exit;
|
||||
}
|
||||
@@ -492,6 +647,7 @@ switch ($r) {
|
||||
'errors' => ['phone' => '这个手机号已经被名册里的另一个人用了'],
|
||||
'phoneValue' => $d['phone'],
|
||||
'idCardValue' => $d['id_card'],
|
||||
'groups' => PersonGroup::byId((int)Auth::familyId()),
|
||||
], 'people');
|
||||
exit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user