v24 第 6 轮:名册导入 / 两种备注 / 多段工作经历 / 家谱卡片与首字母检索修正

用户 2026-10-03 第二批(8 条)。逐条落点:

1. **名册导入**(新):支持 **vCard 3.0/4.0(.vcf)** 与 **CSV/TSV**(中英文表头都认)。
   新增 `app/ContactImport.php`(纯解析)+ `app/ContactImporter.php`(判重+落库)。
   判重按 **手机号(哈希,精确)→ 姓名(大小写无关)**;命中已有的人**只补空字段,
   绝不覆盖**(批量覆盖没法回退)。
   解析上要处理的三件事都处理了:**折行接回**(长名字/地址会被按字节折断)、
   转义还原(`\,` `\;` `\n`)、多值收全(TEL/EMAIL/ADR 可能出现多次)。
   UTF-16/GBK 的 vcf 也认(手机导出的常见编码)。
2. 成员详情页:右上角「移除」→ **「返回」**(回名册);「删除」移到页面**最下方**
   (在「开通登录账号」下面),并改成 `<details>` 两步确认 + 写清会连带删掉什么。
3. 编辑资料里的「这个人的一句话」**去掉** —— 那句话只能**本人**改。
   ⚠️ 落法是「这一栏只在改自己时出现」:用户要的是"别人不能替他写",
   而不是"这句没人能填";服务端也只在 `$isSelf` 时读表单,否则管理员一编辑就把它清空。
4. **工作单位 / 职务 / 职称可以有多段**(新表 `person_jobs`):表单是一组"经历行"
   (单位/职务/职称/起止年月/备注,可 +/×),详情页按"现在 + 历史"列出。
   `persons.org/title` 保留,语义变成"当前那段的快照"(列表页等只要"现在在哪儿"),
   升级时把老的 org/title 回填成一段经历。
5/备注分两种:「自我介绍」(`persons.note`,他本人写的、别人看得到)与
   **「我对他的私人备注」**(新表 `person_notes`,每人每对象一条,**只有写的人自己看得到**)。
   详情页有独立的一块;表单里只在"编辑别人"时出现。
6. 成员表单:**头像放到最前**、去掉「选择文件」按钮(点那张默认头像即选文件);
   表单标签统一 15px/600(原来 13–14px,和 12px 的灰字提示分不出层级)。
7. 名册列表:⋯ 前面加**「编辑」**按钮(改资料是高频动作,藏进 ⋯ 要点两下)。
8. 家谱:
   · **首字母检索 bug**:输入 `yy` 会搜出「岳父/洪勇」。根因是前端把
     **姓名与称呼的首字母拼成一串**再判子序列 —— 洪勇的称呼是"岳父" → `hy`+`yf`=`hyyf`
     → `yy` 跨字段命中。改成**逐字段独立判**(服务端本来就是逐字段判的,两边现在同口径)。
   · **卡片仍比头像宽**:头像是 **1:1(正方形)** 槽位,卡片里却写成 96×72 的长方形 +
     `object-fit: contain` → 照片被缩到 72 宽、左右各留 12px 白 → 看着"框比头像宽"。
     改成**正方形头像区 + `object-fit: cover`**(90×128 卡片,88×88 头像区)。
   · 右上角加**「我的家谱」**按钮(只在看别人的家谱时出现 —— 看自己的时候点它没意义)。

**测试新增**(都能变红,且做过反向验证):
- `_fb_import_test.py` 21 条:新人新建 / 手机号命中不重复建人 / **已有字段一个都不被覆盖** /
  缺的字段被补上 / 反复导入幂等 / 只给姓名也能命中 / 认不出的文件被明确拒绝,
  外加 ⑱ **"有单位但没有经历行"的人**(最容易漏的覆盖路径)。
- `_fb_roster_filter_test.js`(jsdom,用真实渲染出的 HTML)8 条:直击
  「输 yy 不该命中 岳父/洪勇」;反向验证时把实现改回拼接写法 → ① 立刻红。
- 改动过程中被测试抓出**两个真 bug**并已修:
  ① 导入时给"已有单位的人"也插经历 → `PersonJob::syncCurrent()` 回写把这人的单位**覆盖**了;
  ② `syncCurrent()` 在经历表为空时会把 `persons.org/title` **清空** ——
     而它被"编辑资料"这类常规路径调用一次就触发,属于**随手一保存就丢数据**。
     现在空表直接 return("经历表不是唯一的一份")。

**战绩**:e2e **775/0** · 导入 21/0 · 第 5 轮专项 91/0 · 家谱 34/0 · 几何 428/0 ·
移动端 688/0 · 交互 97/0 · 升级 126/0。
线上:schema **v15**、指纹一致、`person_jobs`/`person_notes` 已建、
6 条老的"工作单位"全部回填成经历、13 个文件 md5 与本地一致、错误日志无新增。
This commit is contained in:
2026-10-03 19:27:14 +08:00
parent 218cdf74fc
commit b5725b449a
14 changed files with 1639 additions and 81 deletions
+349
View File
@@ -0,0 +1,349 @@
<?php
/**
* 联系人导入(v24 用户 2026-10-03 第 1 条)。
*
* 用户原话:「名册模块,需要增加一个导入功能,可以导入常见的联系人格式,例如 vcf 等。
* 导入时,如果名字或手机号在已有的名册中存在,则导入其他信息,
* 如果这些信息在系统中已经存在,则只导入其他信息。」
*
* 读法:**按姓名或手机号判重** ——
* · 命中已有的人 → 这条记录不进新人,只把"他缺的信息"补上(**绝不覆盖已有值**);
* · 没命中 → 新建一条。
*
* 支持格式(都能从手机/邮箱/通讯录导出):
* · **vCard 3.0 / 4.0**(.vcf)—— from iPhone / Android / Google Contacts / Outlook
* · **CSV**(.csv / .txt)—— 表头含 姓名/手机/电话/邮箱 之类即可(中英文表头都认)
*
* ⚠️ 只做"补充缺失字段",不做"覆盖":
* 导入是**批量**操作,一旦覆盖,用户就没法把它退回去(哪个字段被改过都看不出来)。
* 而"补上没填的"是安全的 —— 最坏情况也只是多了一条信息,不会丢掉原有内容。
*/
declare(strict_types=1);
namespace App;
final class ContactImport
{
/** vCard / CSV 认得的字段 → 我们的字段 */
private const HEADER_MAP = [
// 姓名
'name' => 'name', '姓名' => 'name', '名字' => 'name', 'fullname' => 'name',
'displayname' => 'name', 'fn' => 'name',
// 电话
'phone' => 'phone', 'tel' => 'phone', 'mobile' => 'phone', 'cell' => 'phone',
'telephone' => 'phone', '手机' => 'phone', '手机号' => 'phone', '电话' => 'phone',
'电话号码' => 'phone', '手机号码' => 'phone',
// 邮箱
'email' => 'email', 'mail' => 'email', '邮箱' => 'email', '电子邮件' => 'email',
'e-mail' => 'email',
// 单位/职务/职称
'org' => 'org', 'organization' => 'org', 'company' => 'org', '单位' => 'org',
'工作单位' => 'org', '公司' => 'org',
'title' => 'title', '职务' => 'title', '职称' => 'title', 'jobtitle' => 'title',
// 地址
'address' => 'address', 'adr' => 'address', '地址' => 'address', '住址' => 'address',
// 备注/生日(生日只认 YYYY-MM-DD,认不出就不导 —— 猜生日比不导更糟)
'note' => 'note', '备注' => 'note', 'memo' => 'note',
'birthday' => 'birthday', 'bday' => 'birthday', '生日' => 'birthday',
// 其他
'nickname' => 'nickname', '昵称' => 'nickname', '小名' => 'nickname',
'url' => 'url', 'website' => 'url', '网站' => 'url', '主页' => 'url',
];
/**
* 解析一份上传文件 → 记录数组。
*
* @return array<int,array> 每条:name/phone/phones[]/email/emails[]/org/title/address/note/birthday/url
*/
public static function parse(string $raw, string $filename = ''): array
{
$raw = self::toUtf8($raw);
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
// 判据用**内容**而不是扩展名:手机导出的 .vcf 有时被改名成 .txt,
// 而这种文件里的 BEGIN:VCARD 是最硬的信号。
if (stripos($raw, 'BEGIN:VCARD') !== false || $ext === 'vcf') {
return self::parseVcard($raw);
}
if ($ext === 'csv' || strpos($raw, ',') !== false || strpos($raw, "\t") !== false) {
return self::parseCsv($raw);
}
return [];
}
/**
* vCard 3.0 / 4.0。
*
* 三条要注意的:
* · **折行**:iCalendar/vCard 规范要求长行按"字节数"折行、续行以空格/制表开头
* —— 姓名与地址经常被折开,不接回去就会得到半个名字。
* · **转义**:文本值里的 `\,` `\;` `\n` 要还原(否则名字里会留下反斜杠)。
* · **多值**:TEL / EMAIL / ADR 都可能出现多次(手机 + 座机 + 工作邮箱),
* 全部收下来(第 1 个当主值)。
*/
public static function parseVcard(string $raw): array
{
$raw = str_replace(["\r\n", "\r"], "\n", $raw);
// ① 接回折行:以空格或制表开头的行是上一行的续行
$lines = [];
foreach (explode("\n", $raw) as $ln) {
if ($ln !== '' && ($ln[0] === ' ' || $ln[0] === "\t")) {
if ($lines) {
$lines[count($lines) - 1] .= substr($ln, 1);
}
continue;
}
$lines[] = $ln;
}
$out = [];
$cur = null;
foreach ($lines as $ln) {
$ln = trim($ln);
if ($ln === '') {
continue;
}
$up = strtoupper($ln);
if ($up === 'BEGIN:VCARD') {
$cur = ['name' => '', 'phone' => '', 'phones' => [], 'email' => '', 'emails' => [],
'org' => '', 'title' => '', 'address' => '', 'note' => '', 'birthday' => '',
'url' => '', 'nickname' => '', 'jobrank' => ''];
continue;
}
if ($up === 'END:VCARD') {
if ($cur !== null) {
$out[] = $cur;
}
$cur = null;
continue;
}
if ($cur === null) {
continue;
}
$pos = strpos($ln, ':');
if ($pos === false) {
continue;
}
$head = substr($ln, 0, $pos);
$val = substr($ln, $pos + 1);
// 属性名可能带参数:TEL;TYPE=CELL / EMAIL;TYPE=WORK / N;CHARSET=UTF-8
$name = strtoupper(trim(explode(';', $head)[0]));
$val = self::unescapeVcard($val);
switch ($name) {
case 'FN': // 格式化姓名(首选)
$cur['name'] = $val;
break;
case 'N': // 结构化姓名:姓;名;中间名;前缀;后缀 → 拼成"名 姓"更符合中文习惯
if ($cur['name'] === '') {
$parts = explode(';', $val);
$fam = trim((string)($parts[0] ?? ''));
$giv = trim((string)($parts[1] ?? ''));
$up2 = strtoupper(trim(explode(';', $head)[1] ?? ''));
// ⚠️ 中文 vCard 里 N 的姓/名顺序也是"姓;名",但显示要"姓名"连写,
// 不加空格 —— 加了会变成"杨 永全"。
$joined = $fam . $giv;
if ($joined !== '' && !preg_match('/[\x{4e00}-\x{9fa5}]/u', $joined)) {
$joined = trim($giv . ' ' . $fam); // 英文名习惯"名 姓"
}
$cur['name'] = $joined;
}
break;
case 'TEL':
if ($val !== '') {
$cur['phones'][] = $val;
if ($cur['phone'] === '') {
$cur['phone'] = $val;
}
}
break;
case 'EMAIL':
if ($val !== '') {
$cur['emails'][] = $val;
if ($cur['email'] === '') {
$cur['email'] = $val;
}
}
break;
case 'ORG':
if ($cur['org'] === '') {
// ORG 也可能是 "公司;部门" 结构
$cur['org'] = trim(str_replace(';', ' ', $val));
}
break;
case 'TITLE':
$cur['title'] = $val;
break;
case 'ROLE':
// ROLE 常放职务、TITLE 放职称(各家不同)—— 两个都收,空位才填
if ($cur['title'] === '') {
$cur['title'] = $val;
} else {
$cur['jobrank'] = $val;
}
break;
case 'ADR':
if ($cur['address'] === '') {
// ADR: 邮箱;扩展;街道;城市;省;邮编;国家 —— 只要街道+城市这段
$p = explode(';', $val);
$street = trim((string)($p[2] ?? ''));
$city = trim((string)($p[3] ?? ''));
$prov = trim((string)($p[4] ?? ''));
$cur['address'] = trim($prov . $city . $street);
}
break;
case 'NOTE':
if ($cur['note'] === '') {
$cur['note'] = $val;
}
break;
case 'BDAY':
$cur['birthday'] = self::normalizeBirthday($val);
break;
case 'NICKNAME':
$cur['nickname'] = $val;
break;
case 'URL':
if ($cur['url'] === '') {
$cur['url'] = $val;
}
break;
}
}
// 丢掉落不到"能建一条人"的(既没名字也没电话)—— 空卡片没有意义
return array_values(array_filter($out, static fn($r) => trim((string)$r['name']) !== ''
|| trim((string)$r['phone']) !== ''));
}
/**
* CSV / TSV。表头中英文都认(见 HEADER_MAP)。
*
* ⚠️ 分隔符靠**第一行的逗号与制表符数量**投票决定,不写死逗号:
* 从 Excel 另存为"文本文件"得到的是制表符分隔,写死逗号会把整行当成一列。
*/
public static function parseCsv(string $raw): array
{
$raw = str_replace(["\r\n", "\r"], "\n", $raw);
$raw = self::stripBom($raw);
$lines = array_values(array_filter(explode("\n", $raw), static fn($l) => trim($l) !== ''));
if (count($lines) < 2) {
return []; // 只有表头(或全空)→ 没有可导入的行
}
$head = $lines[0];
$delim = (substr_count($head, "\t") > substr_count($head, ',')) ? "\t" : ',';
$cols = array_map(static fn($s) => self::keyOf($s), str_getcsv($head, $delim, '"', '\\'));
$out = [];
for ($i = 1; $i < count($lines); $i++) {
$cells = str_getcsv($lines[$i], $delim, '"', '\\');
$rec = ['name' => '', 'phone' => '', 'phones' => [], 'email' => '', 'emails' => [],
'org' => '', 'title' => '', 'address' => '', 'note' => '', 'birthday' => '',
'url' => '', 'nickname' => '', 'jobrank' => ''];
$filled = false;
foreach ($cols as $idx => $key) {
if ($key === '') {
continue;
}
$v = trim((string)($cells[$idx] ?? ''));
if ($v === '') {
continue;
}
// 一个表头可能对应"多个电话"("手机;电话"这种合并列)
foreach (preg_split('/[;、|]/u', $v) as $piece) {
$piece = trim($piece);
if ($piece === '') {
continue;
}
if ($key === 'phone') {
$rec['phones'][] = $piece;
if ($rec['phone'] === '') {
$rec['phone'] = $piece;
}
} elseif ($key === 'email') {
$rec['emails'][] = $piece;
if ($rec['email'] === '') {
$rec['email'] = $piece;
}
} elseif ($key === 'birthday') {
$rec['birthday'] = self::normalizeBirthday($piece);
} elseif ($key === 'name' && $rec['name'] === '') {
$rec['name'] = $piece;
} elseif (isset($rec[$key]) && $rec[$key] === '') {
$rec[$key] = $piece;
}
}
$filled = true;
}
if ($filled && (trim((string)$rec['name']) !== '' || trim((string)$rec['phone']) !== '')) {
$out[] = $rec;
}
}
return $out;
}
/** 表头归一化:小写、去空格/下划线/全角括号注释 */
private static function keyOf(string $h): string
{
$h = self::stripBom(trim($h));
$h = mb_strtolower($h, 'UTF-8');
$h = preg_replace('/[\s_\-\/]+/u', '', $h) ?? $h;
// "手机号(必填)" 这类 → 只留"手机号"
$h = preg_replace('/[((].*?[))]/u', '', $h) ?? $h;
return self::HEADER_MAP[$h] ?? '';
}
/**
* 生日归一化:只认能**确定**的格式(YYYY-MM-DD / YYYYMMDD / YYYY/MM/DD)。
* ⚠️ 认不出就返回 ''(不导入)—— 生日猜错比不导更糟("1990-03-07" 猜成 "03-07" 会丢年份)。
*/
public static function normalizeBirthday(string $v): string
{
$v = trim($v);
if ($v === '') {
return '';
}
// vCard 的 BDAY 可能带 --MM-DD(只知道月日)或 X.500 时间戳;只认四位年
if (preg_match('/(\d{4})[-\/.]?(\d{1,2})[-\/.]?(\d{1,2})/', $v, $m)) {
$y = (int)$m[1];
$mo = (int)$m[2];
$d = (int)$m[3];
if ($y >= 1900 && $y <= (int)date('Y') && checkdate($mo, $d, $y)) {
return sprintf('%04d-%02d-%02d', $y, $mo, $d);
}
}
return '';
}
/** vCard 文本转义还原:\, \; \n \\ */
private static function unescapeVcard(string $v): string
{
$v = str_replace(['\\n', '\\N'], "\n", $v);
$v = str_replace(['\\,', '\\;', '\\\\'], [',', ';', '\\'], $v);
return trim($v);
}
/** 统一成 UTF-8(手机导出的 vcf 可能是 UTF-16 或 GBK) */
public static function toUtf8(string $raw): string
{
if ($raw === '') {
return '';
}
// UTF-16 BOM
if (strncmp($raw, "\xFF\xFE", 2) === 0) {
$raw = (string)mb_convert_encoding(substr($raw, 2), 'UTF-8', 'UTF-16LE');
} elseif (strncmp($raw, "\xFE\xFF", 2) === 0) {
$raw = (string)mb_convert_encoding(substr($raw, 2), 'UTF-8', 'UTF-16BE');
} elseif (strncmp($raw, "\xEF\xBB\xBF", 3) === 0) {
$raw = substr($raw, 3);
} elseif (!mb_check_encoding($raw, 'UTF-8')) {
// 不是合法 UTF-8 → 多半是 GBK(国内手机导出的常见情况)
$raw = (string)mb_convert_encoding($raw, 'UTF-8', 'GBK');
}
return $raw;
}
private static function stripBom(string $s): string
{
return strncmp($s, "\xEF\xBB\xBF", 3) === 0 ? substr($s, 3) : $s;
}
}
+284
View File
@@ -0,0 +1,284 @@
<?php
/**
* 把解析出来的联系人**落到名册里**(v24 用户 2026-10-03 第 1 条)。
*
* 与 App\ContactImport 的分工:
* · ContactImport —— 只管"文件 → 记录数组"(纯解析,不碰库);
* · 本类 —— 只管"记录数组 → 库里"(判重、补缺、建号、挂名册)。
* 分开的好处:解析器可以单独测(给一段 vCard 看输出),不需要库。
*
* 用户要求的两条规则(原话):
* 「导入时,如果名字或手机号在已有的名册中存在,则导入其他信息,
* 如果这些信息在系统中已经存在,则只导入其他信息。」
* 落成三条:
* ① **判重** 按 手机号(哈希,精确)→ 姓名(大小写无关,精确)依次找;
* ② 命中已有的人 → **只补空字段**,绝不覆盖(批量覆盖没法回退,见 ContactImport 的说明);
* ③ 没命中 → 新建一条,并加进导入者的名册。
*
* ⚠️ 判重范围是**整个家庭**(不只是我的名册):同一个家里"洪勇"只能有一条记录 ——
* 否则导入一次会造出一个重复的人,之后生日、关系、观影记录全都分成两半。
*/
declare(strict_types=1);
namespace App;
final class ContactImporter
{
/**
* @return array{added:int,updated:int,skipped:int,people:array<int,array{name:string,action:string,added:array}>}
*/
public static function run(int $familyId, int $meId, array $records, int $groupId = 0): array
{
$added = 0;
$updated = 0;
$skipped = 0;
$log = [];
// 现有的人一次取出来做索引(几十~几百人,比逐条查库快得多,也不会漏判)
// 索引键:phone_hash(精确)+ 姓名(小写)
$byPhone = [];
$byName = [];
foreach (Person::all($familyId, '', 'member', $meId) as $p) {
if (!empty($p['phone_hash'])) {
$byPhone[(string)$p['phone_hash']] = $p;
}
$n = mb_strtolower(trim((string)$p['name']), 'UTF-8');
if ($n !== '' && !isset($byName[$n])) {
$byName[$n] = $p;
}
}
foreach ($records as $r) {
$name = trim((string)($r['name'] ?? ''));
$phone = trim((string)($r['phone'] ?? ''));
if ($name === '' && $phone === '') {
$skipped++;
continue;
}
// ---- ① 判重:手机号优先(最精确),其次姓名 ----
$hit = null;
if ($phone !== '') {
$h = Crypto::hash($phone);
if (isset($byPhone[$h])) {
$hit = $byPhone[$h];
}
}
if ($hit === null && $name !== '') {
$k = mb_strtolower($name, 'UTF-8');
if (isset($byName[$k])) {
$hit = $byName[$k];
}
}
if ($hit !== null) {
// ---- ② 命中:只补空字段 ----
$filled = self::fillMissing($hit, $r, $meId);
if ($filled) {
$updated++;
$log[] = ['name' => (string)$hit['name'], 'action' => 'updated', 'added' => $filled];
} else {
$skipped++;
$log[] = ['name' => (string)$hit['name'], 'action' => 'same', 'added' => []];
}
continue;
}
// ---- ③ 没命中:新建 ----
$d = [
'name' => $name !== '' ? $name : $phone,
'phone' => $phone,
'email' => (string)($r['email'] ?? ''),
'address' => (string)($r['address'] ?? ''),
'org' => (string)($r['org'] ?? ''),
// 职务 + 职称合成一列(与 PersonJob::joinTitle 同一口径:
// 两个都有时用 " · " 分开,只有一个就只用那个)
'title' => PersonJob::joinTitle(
(string)($r['title'] ?? ''),
(string)($r['jobrank'] ?? '')
) ?? '',
'note' => (string)($r['note'] ?? ''),
'kind' => 'member',
'avatar' => '',
'birth_rank' => '',
'is_placeholder' => 0,
// 生日:解析器只给"能确定"的日期,给了就当阳历
'birthday_source' => 'solar',
'birthday_solar' => (string)($r['birthday'] ?? ''),
'birthday_lunar' => '',
'birthday_lunar_leap' => 0,
'birthday_id_card' => '',
];
try {
$pid = Person::create($familyId, $d);
} catch (\Throwable $ex) {
$skipped++;
continue;
}
// 补充联系方式(除主手机号之外的那些)
$extra = [];
$extraPhones = array_values(array_filter((array)($r['phones'] ?? []),
static fn($v) => trim((string)$v) !== '' && (string)$v !== $phone));
foreach ($extraPhones as $i => $v) {
$extra['phone'][] = ['label' => $i === 0 ? '其他' : '', 'value' => (string)$v];
}
$extraEmails = array_values(array_filter((array)($r['emails'] ?? []),
static fn($v) => trim((string)$v) !== '' && (string)$v !== (string)($r['email'] ?? '')));
foreach ($extraEmails as $i => $v) {
$extra['email'][] = ['label' => $i === 0 ? '其他' : '', 'value' => (string)$v];
}
if (($r['url'] ?? '') !== '') {
$extra['url'][] = ['label' => '', 'value' => (string)$r['url']];
}
if ($extra) {
Person::replaceContacts($pid, $extra);
}
// 工作经历(第 4 条那张表):导入来的单位/职务就是一段经历。
// ⚠️ 必须**同时**建这一段,否则详情页的"工作经历"永远是空的,
// 而 persons.org 里却有值 —— 两处对不上,用户会以为数据坏了。
if (trim((string)($r['org'] ?? '')) !== '' || trim((string)($r['title'] ?? '')) !== ''
|| trim((string)($r['jobrank'] ?? '')) !== '') {
PersonJob::replace($pid, [[
'org' => (string)($r['org'] ?? ''), 'title' => (string)($r['title'] ?? ''),
'rank_name' => (string)($r['jobrank'] ?? ''),
'start_ym' => '', 'end_ym' => '', 'note' => '',
]]);
}
// 进导入者的名册(谁导入的,就先出现在谁的名册里)
PersonRoster::ensure($familyId, $meId, $pid, $groupId > 0 ? $groupId : null, 'self');
// 建完把索引补上,避免同一个文件里出现两条同名时建出两个人
$byName[mb_strtolower($d['name'], 'UTF-8')] = ['id' => $pid, 'name' => $d['name']];
if ($phone !== '') {
$byPhone[Crypto::hash($phone)] = ['id' => $pid, 'name' => $d['name']];
}
$added++;
$log[] = ['name' => (string)$d['name'], 'action' => 'added', 'added' => ['新建']];
}
return ['added' => $added, 'updated' => $updated, 'skipped' => $skipped, 'people' => $log];
}
/**
* 把记录里**他没有的值**补上去;已有非空值一律不动。
*
* ⚠️ 写库只分两处:
* ① `persons` 上的标量列(邮箱/住址/单位/职务/生日)→ 一条 UPDATE;
* ② 多值(电话/邮箱/网址)→ 走 person_contacts 的整组替换(要把现有的并进去)。
* 第一版把"SQL 片段"与"中文标签"交替塞进同一个数组,读起来极易出错;
* 这里改成两个独立容器,各司其职。
*
* @return string[] 这次补上了哪些(中文标签,用来告诉用户"改了什么")
*/
private static function fillMissing(array $person, array $r, int $meId): array
{
$pid = (int)$person['id'];
$cols = []; // "`email` = ?" => 值
$labels = []; // 给人看的"补了什么"
// ---- ① persons 上的标量列:他空着才补 ----
$scalar = [
'email' => ['邮箱', (string)($r['email'] ?? ''), 200],
'address' => ['住址', (string)($r['address'] ?? ''), 200],
'org' => ['工作单位', (string)($r['org'] ?? ''), 120],
'note' => ['备注', (string)($r['note'] ?? ''), 2000],
];
foreach ($scalar as $col => $def) {
$label = $def[0];
$new = trim($def[1]);
$max = (int)$def[2];
if (trim((string)($person[$col] ?? '')) === '' && $new !== '') {
$cols["`$col` = ?"] = mb_substr($new, 0, $max, 'UTF-8');
$labels[] = $label;
}
}
// 职务与职称在库里是同一列 title(他那一列空着才补)
$newTitle = trim((string)($r['title'] ?? '') . ' ' . (string)($r['jobrank'] ?? ''));
if (trim((string)($person['title'] ?? '')) === '' && $newTitle !== '') {
$cols['`title` = ?'] = mb_substr($newTitle, 0, 120, 'UTF-8');
$labels[] = '职务/职称';
}
// 生日:他一个生日都没有时才补。有生日就绝不动 —— 生日是强身份信息,错了很难发现。
$hasBd = trim((string)Birthday::solarOf($person)) !== ''
|| trim((string)($person['birthday_lunar'] ?? '')) !== '';
if (!$hasBd && trim((string)($r['birthday'] ?? '')) !== '') {
$cols['`birthday` = ?'] = (string)$r['birthday'] . ' 00:00:00';
$labels[] = '生日';
}
if ($cols) {
$sql = [];
$args = [];
foreach ($cols as $frag => $val) {
$sql[] = $frag;
$args[] = $val;
}
$args[] = $pid;
Database::get()->prepare('UPDATE persons SET ' . implode(', ', $sql) . ' WHERE id = ?')
->execute($args);
}
// ---- ② 多值(电话/邮箱/网址):只在"这一类他一个都没有"时补 ----
// ⚠️ 判据是"这一类为空",不是逐条去重:person_contacts 里的手机号是**密文**,
// 没法拿明文比;而"他这一类本来就空着"是能确定的(也符合"只补空"的要求)。
$cur = Person::contactsOf($pid);
$add = [];
$mainPhone = trim((string)($r['phone'] ?? ''));
$mainMail = trim((string)($r['email'] ?? ''));
$extraPhones = array_values(array_filter((array)($r['phones'] ?? []),
static fn($v) => trim((string)$v) !== '' && trim((string)$v) !== $mainPhone));
$extraEmails = array_values(array_filter((array)($r['emails'] ?? []),
static fn($v) => trim((string)$v) !== '' && trim((string)$v) !== $mainMail));
if (!$cur['phone'] && $extraPhones) {
foreach ($extraPhones as $v) {
$add['phone'][] = ['label' => '', 'value' => (string)$v];
}
$labels[] = '电话';
}
if (!$cur['email'] && $extraEmails) {
foreach ($extraEmails as $v) {
$add['email'][] = ['label' => '', 'value' => (string)$v];
}
$labels[] = '邮箱';
}
if (!$cur['url'] && trim((string)($r['url'] ?? '')) !== '') {
$add['url'][] = ['label' => '', 'value' => (string)$r['url']];
$labels[] = '网址';
}
if ($add) {
// replaceContacts 是**整组替换** → 必须把现有的并进去,否则会把已有联系方式清掉
$merged = $cur;
foreach ($add as $k => $rows) {
foreach ($rows as $row) {
$merged[$k][] = $row;
}
}
Person::replaceContacts($pid, $merged);
}
// ---- ③ "工作经历"里空着、而这次**刚补上**了单位/职务 → 补一段经历 ----
// ⚠️⚠️ 两个硬条件,缺一不可:
// ① 这次确实补了(`$cols` 里刚写过 org 或 title)—— 他已经有的值不能碰;
// ② 经历表里本来就没有 —— 有经历时以经历表为准,不重复插。
// 为什么条件①这么关键:`PersonJob::replace()` 末尾会调
// `syncCurrent()` 把"最新那段"回写到 persons.org/title。若在这里对
// "已有单位的人"也插一段导入来的单位,syncCurrent 就会把
// **他原来的单位覆盖掉** —— 正好违反"只补空、不覆盖"。
// (这个 bug 是被 _fb_import_test.py 的 ⑩ 抓出来的。)
$justFilledOrg = isset($cols['`org` = ?']);
$justFilledTitle = isset($cols['`title` = ?']);
if (($justFilledOrg || $justFilledTitle) && !PersonJob::list($pid)) {
PersonJob::replace($pid, [[
// 用**刚存进去的值**(不是导入文件里的原值)——
// 这样 syncCurrent 回写时与库里一致,不会造成二次变动。
'org' => (string)($cols['`org` = ?'] ?? ''),
'title' => (string)($r['title'] ?? ''),
'rank_name' => (string)($r['jobrank'] ?? ''),
'start_ym' => '', 'end_ym' => '', 'note' => '',
]]);
}
return array_values(array_unique($labels));
}
}
+160
View File
@@ -0,0 +1,160 @@
<?php
/**
* 工作经历:单位 / 职务 / 职称,**可以有多段**(v24 用户 2026-10-03 第 4 条)。
*
* 用户原话:「工作单位、职称、职务,都是可以填写多个的,因为一个人的工作可能会变,
* 我们需要记住他工作和职务的变化。」
*
* 所以这里存的是**一条条经历**而不是三个字段:
* - 每段有 单位 / 职务 / 职称 / 起止年月 / 备注;
* - 没有结束年月的就是"当前"那一段(列表里排最前、标「现在」);
* - 有起止的按时间倒序排(最近的在上面)。
*
* ⚠️ `persons.org` / `persons.title` **保留**,但语义变成"当前单位/当前职称的快照":
* 名册列表、家谱、观影人标签这些地方只需要"现在在哪儿",不该为了一行文字去 JOIN
* 一张历史表;而且已有数据不会因为这次改动而消失。
* → 保存时由 syncCurrent() 自动把"最新那段"回写到那两个字段。
*/
declare(strict_types=1);
namespace App;
final class PersonJob
{
/** 一段经历:单位/职务/职称/起止/备注;timeline 里 sort 越小越靠前 */
public const MAX = 20; // 一个人最多留 20 段(再多也不会是真的工作史)
/** 某个人的工作经历(当前那段在前,其余按开始时间倒序) */
public static function list(int $personId): array
{
if ($personId <= 0) {
return [];
}
$st = Database::get()->prepare(
'SELECT * FROM person_jobs WHERE person_id = ?
ORDER BY (end_ym IS NULL) DESC, COALESCE(start_ym, "") DESC, id DESC'
);
$st->execute([$personId]);
return $st->fetchAll();
}
/**
* 整组替换(与 Person::replaceContacts 同一套做法:表单里就是一组行,
* 删行/改行/加行一起提交,最省心 —— 逐行增删要额外的行 id 体系)。
*
* ⚠️ 空行(单位、职务、职称都空)会被丢掉,不留垃圾行。
*/
public static function replace(int $personId, array $rows): void
{
if ($personId <= 0) {
return;
}
$db = Database::get();
$db->prepare('DELETE FROM person_jobs WHERE person_id = ?')->execute([$personId]);
$ins = $db->prepare(
'INSERT INTO person_jobs (person_id, org, title, rank_name, start_ym, end_ym, note)
VALUES (?,?,?,?,?,?,?)'
);
$n = 0;
foreach ($rows as $row) {
$org = mb_substr(trim((string)($row['org'] ?? '')), 0, 120, 'UTF-8');
$title = mb_substr(trim((string)($row['title'] ?? '')), 0, 120, 'UTF-8');
$rank = mb_substr(trim((string)($row['rank_name'] ?? '')), 0, 120, 'UTF-8');
$note = mb_substr(trim((string)($row['note'] ?? '')), 0, 200, 'UTF-8');
if ($org === '' && $title === '' && $rank === '') {
continue; // 整行空 → 丢掉
}
if ($n >= self::MAX) {
break;
}
$ins->execute([
$personId,
$org !== '' ? $org : null,
$title !== '' ? $title : null,
$rank !== '' ? $rank : null,
self::ym($row['start_ym'] ?? ''),
self::ym($row['end_ym'] ?? ''),
$note !== '' ? $note : null,
]);
$n++;
}
self::syncCurrent($personId);
}
/**
* 把"当前那一段"回写到 persons.org / persons.title(列表页等地方读的是那两个字段)。
*
* 取"当前"的规则:**没有结束年月的那一段**优先;都填了结束时间就取开始时间最晚的。
*
* 🔴🔴 **经历表为空时什么都不做**(绝不把 org/title 清空)。
* 这一条是实测踩出来的:老库里 `persons.org` 有值、但 `person_jobs` 还没有行
* (升级回填之前、或某次操作删光了经历)。此时如果按"取不到就置空"来写,
* 任何一次 `replace()` 都会把**用户填的单位抹掉** —— 而 replace 被调用在
* "编辑资料"“导入联系人”这类常规路径上,等于随手一保存就丢数据。
* 正确的语义是:**经历表是"更详细的那一份",不是"唯一的一份"** ——
* 它没内容时,就去尊重 org/title 里已有的值。
*/
public static function syncCurrent(int $personId): void
{
$list = self::list($personId);
if (!$list) {
return; // 见上面的说明:没有经历 ≠ 没有单位,别动
}
$cur = null;
foreach ($list as $r) {
if ($r['end_ym'] === null || $r['end_ym'] === '') {
$cur = $r;
break; // list() 已把"无结束"的排在最前
}
}
if ($cur === null) {
$cur = $list[0]; // 全是历史:取最近一段(list 已按开始时间倒序)
}
Database::get()->prepare('UPDATE persons SET org = ?, title = ? WHERE id = ?')
->execute([
$cur['org'] ?: null,
// ⚠️ title 列里放「职务」,rank_name 放「职称」——两个都要能显示,
// 列表页只显示 title,所以把职称拼在后面(有职务时"教授 · 博导"这样)。
self::joinTitle($cur['title'] ?? '', $cur['rank_name'] ?? ''),
$personId,
]);
}
/** 职务 + 职称 合成一个显示串(哪个空就只用另一个;都空返回 null) */
public static function joinTitle(?string $title, ?string $rank): ?string
{
$t = trim((string)$title);
$r = trim((string)$rank);
if ($t !== '' && $r !== '') {
return $t . ' · ' . $r;
}
$v = $t !== '' ? $t : $r;
return $v !== '' ? $v : null;
}
/**
* 从**旧的两个字段**造一段经历(升级回填用)。
* @return array 一行 ['org','title','rank_name','start_ym','end_ym','note']
*/
public static function rowFromLegacy(?string $org, ?string $title): ?array
{
$o = trim((string)$org);
$t = trim((string)$title);
if ($o === '' && $t === '') {
return null;
}
// 老数据的 title 是"职务 / 职称"随手填的,分不出哪个是哪个 →
// 整串放进 title(职务),rank_name 留空。不猜。
return ['org' => $o, 'title' => $t, 'rank_name' => '',
'start_ym' => '', 'end_ym' => '', 'note' => ''];
}
/** 'YYYY-MM' 归一化;不合法返回 null */
private static function ym($v): ?string
{
$v = trim((string)$v);
return preg_match('/^\d{4}-\d{2}$/', $v) ? $v : null;
}
}
+82
View File
@@ -0,0 +1,82 @@
<?php
/**
* 「我对某个人的私人备注」(v24 用户 2026-10-03 第 5 条)。
*
* 用户原话:「名册中,每个人的备注,都有两个,一个是他自己填写的,就好像他自己的
* 一个格言或者自我介绍;如果其他人打开这个人的信息,编辑备注,
* 是这个人对他的独有的备注,例如记录怎么跟这个人认识的等等。」
*
* 所以名册里有**两种**备注,别混:
*
* · `persons.note` —— **本人写的**自我介绍/格言(每人一份,本人可改)。
* 别人打开他的资料**看得到**(那是他愿意公开说的)。
* · `person_notes` —— **"我"对他写的**私人备注(怎么认识的、要注意什么…)。
* ⚠️ **只有写的人自己看得到** —— 它属于"我和他的关系",
* 不是这个人的属性。所以它不落 persons,
* 否则我写一句"这人借钱不还"全家都能看见。
*
* 这也正是为什么不复用 persons.note:一个字段存不下"两种语义 + 两种可见性"。
*/
declare(strict_types=1);
namespace App;
final class PersonNote
{
/** 我对这个人的私人备注(没写过返回 '') */
public static function get(int $personId, int $viewerId): string
{
if ($personId <= 0 || $viewerId <= 0) {
return '';
}
$st = Database::get()->prepare(
'SELECT note FROM person_notes WHERE person_id = ? AND viewer_id = ?'
);
$st->execute([$personId, $viewerId]);
$v = $st->fetchColumn();
return $v === false ? '' : (string)$v;
}
/**
* 写入/清空。**空串等于删除这条备注** —— 不留一行空记录,
* 否则"我写过又删掉"会留下一条 forever 的空行,日后分不清"没写过"与"删掉了"。
*/
public static function set(int $personId, int $viewerId, string $note): void
{
if ($personId <= 0 || $viewerId <= 0) {
return;
}
$note = trim($note);
if ($note === '') {
Database::get()->prepare(
'DELETE FROM person_notes WHERE person_id = ? AND viewer_id = ?'
)->execute([$personId, $viewerId]);
return;
}
Database::get()->prepare(
'INSERT INTO person_notes (person_id, viewer_id, note) VALUES (?,?,?)
ON DUPLICATE KEY UPDATE note = VALUES(note)'
)->execute([$personId, $viewerId, mb_substr($note, 0, 4000, 'UTF-8')]);
}
/**
* 一批人的私人备注(列表页要一次取完,别逐行查 —— N+1 在名册几十人时很明显)。
* @return array<int,string> person_id => note
*/
public static function mapFor(int $viewerId): array
{
if ($viewerId <= 0) {
return [];
}
$st = Database::get()->prepare(
'SELECT person_id, note FROM person_notes WHERE viewer_id = ? AND note IS NOT NULL AND note <> ""'
);
$st->execute([$viewerId]);
$out = [];
foreach ($st->fetchAll() as $r) {
$out[(int)$r['person_id']] = (string)$r['note'];
}
return $out;
}
}
+63 -3
View File
@@ -71,7 +71,7 @@ final class Schema
* ⚠️ 它**不再**作为"要不要跑升级"的判据 —— 见 fingerprint() 的说明。 * ⚠️ 它**不再**作为"要不要跑升级"的判据 —— 见 fingerprint() 的说明。
* 它仍然要手工维护,因为它给人看(排查时一眼知道代码到哪一版了)。 * 它仍然要手工维护,因为它给人看(排查时一眼知道代码到哪一版了)。
*/ */
public const VERSION = '14'; public const VERSION = '15';
/** /**
* 「源码指纹」:拿**本文件自身的内容**算一个哈希,作为"要不要跑升级"的判据。 * 「源码指纹」:拿**本文件自身的内容**算一个哈希,作为"要不要跑升级"的判据。
@@ -1035,8 +1035,68 @@ CREATE TABLE IF NOT EXISTS `ledger_shares` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='账本共享' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='账本共享'
SQL); SQL);
// 被容错跳过的数据步骤记进设置,系统设置页会把它显出来 —— // ---- 工作经历(版本 15,用户 2026-10-03 第 4 条)----
// 不然「升级没跑完」这件事只活在日志里,跟没发生一样。 // 用户原话:「工作单位、职称、职务,都是可以填写多个的,因为一个人的工作可能会变,
// 我们需要记住他工作和职务的变化。」
// 于是一个人不再只有"一个单位 + 一个职称",而是一串经历(见 App\PersonJob)。
// ⚠️ persons.org / title **保留不动**,语义变成"当前那一段的快照":
// 名册/家谱/观影标签这些地方只要"现在在哪儿",不该为一行字去 JOIN 历史表;
// 而且老数据也不会因为这次改动而消失。
$db->exec(<<<'SQL'
CREATE TABLE IF NOT EXISTS `person_jobs` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`person_id` INT UNSIGNED NOT NULL,
`org` VARCHAR(120) DEFAULT NULL COMMENT '单位',
`title` VARCHAR(120) DEFAULT NULL COMMENT '职务(如 主任 / 副院长)',
`rank_name` VARCHAR(120) DEFAULT NULL COMMENT '职称(如 副教授 / 高级工程师)',
`start_ym` CHAR(7) DEFAULT NULL COMMENT '起始年月 YYYY-MM(可空)',
`end_ym` CHAR(7) DEFAULT NULL COMMENT '结束年月;**空 = 现在还在**(列表里标「现在」)',
`note` VARCHAR(200) DEFAULT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_pj_person` (`person_id`, `end_ym`),
CONSTRAINT `fk_pj_person` FOREIGN KEY (`person_id`) REFERENCES `persons` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
COMMENT='工作经历:一个人可以有多段(单位/职务/职称/起止年月)'
SQL);
// 升级回填:老数据只有 persons.org / title 两个字段 → 造一段"没有起止"的当前经历。
// ⚠️ 只在**这个人还没有任何经历**时补,重复跑不会重复插(幂等)。
try {
$db->exec(
'INSERT INTO person_jobs (person_id, org, title, rank_name, start_ym, end_ym, note)
SELECT p.id, p.org, p.title, NULL, NULL, NULL, NULL
FROM persons p
WHERE (p.org IS NOT NULL AND p.org <> "" OR p.title IS NOT NULL AND p.title <> "")
AND NOT EXISTS (SELECT 1 FROM person_jobs j WHERE j.person_id = p.id)'
);
} catch (\Throwable $ex) {
self::$stepErrors[] = '工作经历回填:' . $ex->getMessage();
}
// ---- 「我对他的备注」(版本 15,用户 2026-10-03 第 5 条)----
// 用户原话:「名册中,每个人的备注,都有两个,一个是他自己填写的,就好像他自己的
// 一个格言或者自我介绍;如果其他人打开这个人的信息,编辑备注,
// 是这个人对他的独有的备注,例如记录怎么跟这个人认识的等等。」
//
// 所以两种备注分开放:
// · persons.note —— **本人写的**自我介绍(每个人自己一份,见 form 的说明);
// · person_notes —— **"我"对他写的**私人备注(每人每对象一份,别人看不到)。
// ⚠️ 不塞进 persons:那是"一个人的属性",而"我怎么认识他的"是**我和他之间**的事,
// 混在一起必然出现"我把备注写在别人身上、全家都看得见"。
$db->exec(<<<'SQL'
CREATE TABLE IF NOT EXISTS `person_notes` (
`person_id` INT UNSIGNED NOT NULL COMMENT '被写备注的那个人',
`viewer_id` INT UNSIGNED NOT NULL COMMENT '谁写的(只有他自己看得到)',
`note` TEXT DEFAULT NULL COMMENT '我对他的私人备注(怎么认识的、要注意什么…)',
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`person_id`, `viewer_id`),
CONSTRAINT `fk_pn_person` FOREIGN KEY (`person_id`) REFERENCES `persons` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_pn_viewer` FOREIGN KEY (`viewer_id`) REFERENCES `persons` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
COMMENT='「我对某个人的私人备注」:每人每对象一条,只有自己看得到'
SQL);
// ---- 账本盘点(版本 14,用户 2026-10-03 第 8 条)---- // ---- 账本盘点(版本 14,用户 2026-10-03 第 8 条)----
// 用户原话:「账本要增加盘点功能,因为某一个账目可能会变,要记住每一次变化, // 用户原话:「账本要增加盘点功能,因为某一个账目可能会变,要记住每一次变化,
// 用盘点来完成。我点击盘点,让我对一个账目的金额进行重新输入, // 用盘点来完成。我点击盘点,让我对一个账目的金额进行重新输入,
+109 -13
View File
@@ -457,6 +457,20 @@ textarea.input { min-height: 76px; resize: vertical; }
.kv-row dd { margin: 0; font-size: 14px; word-break: break-all; } .kv-row dd { margin: 0; font-size: 14px; word-break: break-all; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; letter-spacing: .5px; } .mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; letter-spacing: .5px; }
/* ---- 工作经历(详情页,用户 2026-10-03 第 4 条)----
一个人可以有多段,逐条列出来;"现在还在那儿"的那段排最前并带徽标。 */
.job-history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.job-history-item {
display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
word-break: normal; /* ⚠️ .kv-row dd 上有 break-all,这里要收回来,
否则"中国海洋大学"会被从中间断开 */
}
.job-history-item .job-org { font-weight: 600; }
.job-history-item .job-title { color: var(--brand-ink); }
.job-history-item .job-span { font-variant-numeric: tabular-nums; }
/* 「我对他的私人备注」那一块:淡一点,别和"公开资料"抢注意力 */
.my-note-card { background: #FCFAF6; }
/* ---------------- 提示 ---------------- */ /* ---------------- 提示 ---------------- */
.flash { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; } .flash { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash-item { .flash-item {
@@ -621,16 +635,19 @@ textarea.input { min-height: 76px; resize: vertical; }
· 卡片不再整张是链接:只有 .kin-nm 是 <a>,右下角是独立的 <button>, · 卡片不再整张是链接:只有 .kin-nm 是 <a>,右下角是独立的 <button>,
两者分开,避免"点按钮却进了成员页"的误触。 两者分开,避免"点按钮却进了成员页"的误触。
卡片尺寸与 JS 的 setCardDim({w,h}) 必须一致(库按它算间距与连线落点)。 */ 卡片尺寸与 JS 的 setCardDim({w,h}) 必须一致(库按它算间距与连线落点)。 */
/* 卡片尺寸:**框宽 = 头像宽**(用户 2026-10-03 第 8 条:「外面那个框,宽度和头像图片一致, /* 卡片尺寸:**框宽 = 头像宽**(用户 2026-10-03:「外面那个框,宽度和头像图片一致,
下面显示名字就行了」)。 下面显示名字就行了」)。
98 = 96(头像实际宽度,见 .kin-ph)+ 左右各 1px 边框 —— 即"边框刚好贴着头像", 🔴 头像槽位是 **1:1(正方形)**(见 App\ImageSlot::SLOTS['avatar'])
框里不再有多余的横向空白(原来是 118 宽、比头像宽出 22px)。 —— 所以"框宽 = 头像宽"其实要求框里的头像区**也是正方形**:
⚠️ 横向 padding 必须是 0,否则头像(width:100%)会被压窄。 之前写成 96×72 的长方形 + `object-fit: contain`,正方形照片被**缩到 72 宽**
⚠️ 这个 98×116 必须与 JS 里 setCardDim({w,h}) **保持一致**: 左右各留 ~12px 空白 → 看起来"框比头像宽很多"(用户第 8 条「还是比头像宽很多」)。
现在头像区取正方形,照片 `object-fit: cover` 铺满 —— 框就是头像本身那么大。
⚠️ 这个 90/128 必须与 JS 里 setCardDim({w,h}) **保持一致**:
库按它算卡片间距与连线落点,两边不一致连线就会歪。 */ 库按它算卡片间距与连线落点,两边不一致连线就会歪。 */
.kin-card { .kin-card {
--kin-w: 98px; --kin-w: 90px;
--kin-h: 116px; --kin-h: 128px;
--kin-ph: 88px; /* 头像区(正方形):卡宽 − 左右各 1px 边框 */
position: absolute; position: absolute;
display: flex; flex-direction: column; align-items: center; display: flex; flex-direction: column; align-items: center;
gap: 0; gap: 0;
@@ -678,17 +695,19 @@ textarea.input { min-height: 76px; resize: vertical; }
.kin-card:hover { .kin-card:hover {
box-shadow: var(--shadow-l); border-color: var(--brand-2); box-shadow: var(--shadow-l); border-color: var(--brand-2);
} }
/* 头像外框:**占满卡片内宽**(卡片 padding 横向为 0,所以这里 100% = 卡片内宽), /* 头像区:**正方形、铺满**(见上面 --kin-ph 的说明)。
长方形、object-fit: contain 不裁切。 用户 2026-10-03 第 8 条:「宽度和头像图片一致,下面显示名字就行了」。 */
用户 2026-10-03 第 8 条:「外面那个框,宽度和头像图片一致,下面显示名字就行了」
—— 框宽 == 头像宽,头像下面只有名字。 */
.kin-card .kin-ph { .kin-card .kin-ph {
width: 100%; height: 72px; border-radius: 8px 8px 0 0; overflow: hidden; width: var(--kin-ph); height: var(--kin-ph);
border-radius: 8px; overflow: hidden;
background: #F1E7D6; flex: 0 0 auto; background: #F1E7D6; flex: 0 0 auto;
display: block; display: block;
} }
/* 头像槽位是 1:1,所以这里的容器也是 1:1 —— cover 不会裁掉任何内容
(照片本来就是按 1:1 裁好的)。⚠️ 别改成 contain:那会在框里留出空白,
看起来就是"框比头像宽"。 */
.kin-card .kin-ph img { .kin-card .kin-ph img {
width: 100%; height: 100%; object-fit: contain; display: block; width: 100%; height: 100%; object-fit: cover; display: block;
} }
.kin-card .kin-ph:hover { box-shadow: inset 0 0 0 2px var(--brand-2); } .kin-card .kin-ph:hover { box-shadow: inset 0 0 0 2px var(--brand-2); }
/* 姓名:用户 2026-10-03 第 7 条起,点姓名 = **以他为中心**重画家谱 /* 姓名:用户 2026-10-03 第 7 条起,点姓名 = **以他为中心**重画家谱
@@ -907,11 +926,21 @@ textarea.input { min-height: 76px; resize: vertical; }
/* 卡片改成 div > a + details:表单不能套在链接里(非法 HTML,浏览器会把 DOM 拆开) */ /* 卡片改成 div > a + details:表单不能套在链接里(非法 HTML,浏览器会把 DOM 拆开) */
.person-main { display: block; color: var(--ink); } .person-main { display: block; color: var(--ink); }
.person-main:hover { text-decoration: none; } .person-main:hover { text-decoration: none; }
.person-more { display: none; }
/* 列表形态下「⋯ 调整分组」改到行的**右侧**(原来在卡片下方,列表里会撑高一行) */ /* 列表形态下「⋯ 调整分组」改到行的**右侧**(原来在卡片下方,列表里会撑高一行) */
.person-more { .person-more {
position: absolute; right: 8px; top: 50%; transform: translateY(-50%); position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
border: 0; background: none; border: 0; background: none;
} }
/* 用户 2026-10-03 第 7 条:⋯ **前面**多了一个「编辑」按钮,所以 ⋯ 要往左让位。
编辑按钮同样绝对定位在行右侧(在 ⋯ 左边 46px 处)—— 两个都贴着行的右边缘,
这样"改资料(常用)"在前、"更多操作(低频)"在后,手指/鼠标扫过去就是从左到右。 */
.person-edit {
position: absolute; right: 46px; top: 50%; transform: translateY(-50%);
padding: 3px 10px; font-size: 13px;
}
/* ⚠️ 预留出右侧两个按钮的位置,否则姓名/信息会钻到按钮底下 */
.people-grid .person .person-main { padding-right: 96px; }
.person-more > summary { .person-more > summary {
list-style: none; cursor: pointer; padding: 4px 10px; list-style: none; cursor: pointer; padding: 4px 10px;
font-size: 16px; color: var(--muted); border-radius: 8px; font-size: 16px; color: var(--muted); border-radius: 8px;
@@ -2144,6 +2173,73 @@ textarea.input { min-height: 76px; resize: vertical; }
.cmt-form { margin-top: 6px; } .cmt-form { margin-top: 6px; }
.task-danger { margin-top: 18px; display: flex; justify-content: flex-end; } .task-danger { margin-top: 18px; display: flex; justify-content: flex-end; }
/* ---- 「危险操作区」(成员详情页的删除,用户 2026-10-03 第 2 条)----
刻意做成**页面最下方一块低调的折叠区**:破坏性操作不该一眼看到、更不该一键完成。
视觉上只用一条虚线分隔 + 灰色摘要,不抢上面正常内容的注意力。 */
.danger-zone {
margin-top: 28px; padding-top: 14px;
border-top: 1px dashed var(--line);
}
.danger-zone > details > summary { cursor: pointer; font-size: 13px; }
.danger-zone .del-confirm {
margin-top: 10px; padding: 12px 14px;
border: 1px solid rgba(178, 45, 45, .25); border-radius: var(--radius-s);
background: #FDF6F4;
}
/* ---- 表单标签更醒目(用户 2026-10-03 第 6 条)----
「每一个输入的名字,都不够醒目,例如姓名、性别,这些字应该变大一点,加粗,
不能跟提示一样大小」—— 提醒(.tip)是 12px 的灰字,而标签原来是 13-14px,
两者太接近,扫一眼分不出"哪一行在哪"。这里把标签统一抬到 15px / 600 字重 /
深一点的墨色,与 .tip / .hint 明确拉开层级。 */
.form-grid > .field > label,
.form-grid > .field > .field-label {
font-weight: 600; font-size: 15px; color: var(--ink);
}
/* 「我的资料 / 编辑成员」那张表里也有不在 form-grid 直接子级的 label(嵌套块),
一并覆盖;用 :not(.job-lb) 排除工作经历行里的那些小标签(见下)。 */
.card .field > label:not(.job-lb):not(.check-item):not(.chk-inline) {
font-weight: 600; font-size: 15px; color: var(--ink);
}
/* ⚠️ 但 .tip / .hint / .small 这些"说明文字"必须保持小灰字,别被上面那条带大 */
.card .field > label.tip,
.card .field > label.hint,
.card .field > label.small { font-weight: 400; font-size: 12.5px; color: var(--muted); }
/* ---- 头像选择器(用户第 6 条:头像放最前 + 去掉「选择文件」按钮)----
点那张(默认)头像就是选文件 —— 图本身就是按钮,不再另起一行控件。
默认头像用 .avatar-default 叠一个"+"角标,提示这里可点。 */
.avatar-field { margin-bottom: 4px; }
.avatar-picker { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.avatar-picker #avatar-preview {
width: 96px; height: 96px; border-radius: 12px; object-fit: cover;
border: 1px solid var(--line); background: #F1E7D6; cursor: pointer;
transition: border-color .15s ease, box-shadow .15s ease;
}
.avatar-picker #avatar-preview:hover { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(168,74,40,.12); }
.avatar-picker #avatar-preview[data-has-avatar="0"] { border-style: dashed; }
.avatar-hint { line-height: 1.7; }
/* ---- 工作经历(用户第 4 条:可以有多个)---- */
.job-list { display: flex; flex-direction: column; gap: 8px; }
.job-row {
display: grid; gap: 8px; align-items: end;
/* 单位 / 职务 / 职称 各占一份,起止各一份窄的,最后是删除按钮 */
grid-template-columns: 1.4fr 1fr 1fr 130px 130px auto;
padding: 10px 12px; border: 1px solid var(--line-2);
border-radius: var(--radius-s); background: #FDFBF7;
}
.job-cell { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.job-lb { font-size: 12px; color: var(--muted); font-weight: 500; }
.job-cell .input { padding: 7px 9px; font-size: 14px; }
.job-del { align-self: end; }
@media (max-width: 860px) {
/* 窄屏:一段经历折成两列,别硬塞六列(会挤成没法填) */
.job-row { grid-template-columns: 1fr 1fr; }
.job-row .job-cell:first-child { grid-column: 1 / -1; }
.job-del { grid-column: 1 / -1; justify-self: end; }
}
@media (max-width: 860px) { @media (max-width: 860px) {
.kanban { grid-template-columns: 1fr; } .kanban { grid-template-columns: 1fr; }
.nf-grid { grid-template-columns: 1fr; } .nf-grid { grid-template-columns: 1fr; }
+20 -2
View File
@@ -38,13 +38,31 @@
return i === q.length; return i === q.length;
} }
/** 一个元素能不能被 q 命中 */ /** 一个元素能不能被 q 命中
*
* ⚠️⚠️ 首字母必须**逐字段独立匹配**,绝不能把多个字段的首字母拼成一串再判子序列。
* 这条是实测踩出来的(用户 2026-10-03:「我用 yy 搜索,为什么把岳父、洪勇搜索出来了?」):
* 名册行的 data-initials 原先是 initials(姓名 + 称呼) 的结果,
* 而"洪勇"在他这儿显示的称呼是"岳父" → `hy` + `yf` = **`hyyf`** → 输入 `yy` 命中。
* 用户抱怨的"把岳父搜出来"正是这个跨字段串:**每个字段单独看都不含 yy**,
* 拼在一起才撞出来。所以这里对每个字段分别判,任一段命中就算这个人命中。
* 同名同姓之外的"跨字段巧合"还有很多(张伟的称呼是"二姨"→ zw+ey=zwey,
* 输 we 就会误命中),逐字段判才是对的。
*
* 服务端那一半(App\Pinyin::matches)本来就是逐字段判的,两边现在口径一致。
*/
function hit(el, q) { function hit(el, q) {
if (!q) { return true; } if (!q) { return true; }
var hay = (el.getAttribute('data-search') || '').toLowerCase(); var hay = (el.getAttribute('data-search') || '').toLowerCase();
if (hay.indexOf(q) >= 0) { return true; } if (hay.indexOf(q) >= 0) { return true; }
// data-initials 里可能放了**多段**首字母(用空格分隔)—— 每段独立判子序列
var ini = (el.getAttribute('data-initials') || '').toLowerCase(); var ini = (el.getAttribute('data-initials') || '').toLowerCase();
return ini ? isSubSeq(q, ini) : false; if (!ini) { return false; }
var parts = ini.split(/\s+/);
for (var i = 0; i < parts.length; i++) {
if (parts[i] && isSubSeq(q, parts[i])) { return true; }
}
return false;
} }
function bindList(input) { function bindList(input) {
+25 -4
View File
@@ -73,12 +73,26 @@
if (!modal || !list || !chips) { return; } if (!modal || !list || !chips) { return; }
// 预计算每个人的首字母串,挂在 data-initials 上(列表再长也只是算一次) // 预计算每个人的首字母串,挂在 data-initials 上(列表再长也只是算一次)
// ⚠️⚠️ **每个字段单独算,用空格分隔,绝不拼成一串**。
// "姓名 + 称呼" 拼起来会造出**跨字段的巧合命中**:
// 用户 2026-10-03 实测「输 yy 把岳父搜出来」——洪勇的称呼是"岳父",
// `hy` + `yf` = `hyyf`,子序列 `yy` 正好跨过边界命中;
// 单独看 `hy` 与 `yf` 都不含 `yy`。逐字段判才是对的。
// 服务端(App\Pinyin::matches)本来就是逐字段判的,两边口径保持一致。
Array.prototype.forEach.call(list.querySelectorAll('.pp-item'), function (el) { Array.prototype.forEach.call(list.querySelectorAll('.pp-item'), function (el) {
var s = (el.getAttribute('data-name') || '') + (el.getAttribute('data-shown') || ''); var parts = [];
var n1 = el.getAttribute('data-name') || '';
var n2 = el.getAttribute('data-shown') || '';
[n1, n2].forEach(function (s) {
if (!s) { return; }
var ini = initialsOf ? initialsOf(s) : ''; var ini = initialsOf ? initialsOf(s) : '';
el.setAttribute('data-initials', ini.toLowerCase()); if (ini && parts.indexOf(ini.toLowerCase()) < 0) { parts.push(ini.toLowerCase()); }
});
el.setAttribute('data-initials', parts.join(' '));
// 徽标只显示**姓名的**首字母(称呼那串太杂,显示出来反而更乱)
var badge = el.querySelector('.pp-initials'); var badge = el.querySelector('.pp-initials');
if (badge && ini) { badge.textContent = ini; badge.hidden = false; } var first = initialsOf ? initialsOf(n1) : '';
if (badge && first) { badge.textContent = first; badge.hidden = false; }
}); });
function syncChips() { function syncChips() {
@@ -128,10 +142,17 @@
var q = (search.value || '').trim().toLowerCase(); var q = (search.value || '').trim().toLowerCase();
var shown = 0; var shown = 0;
Array.prototype.forEach.call(list.querySelectorAll('.pp-item'), function (el) { Array.prototype.forEach.call(list.querySelectorAll('.pp-item'), function (el) {
// ⚠️ 首字母按**空格分隔的多段**逐段独立判 —— 见上面写 data-initials 时的说明
// (把"姓名+称呼"拼成一串会让 `yy` 跨字段命中"洪勇/岳父")。
var inis = (el.getAttribute('data-initials') || '').split(/\s+/);
var iniHit = false;
for (var i = 0; i < inis.length; i++) {
if (inis[i] && isSubSeq(q, inis[i])) { iniHit = true; break; }
}
var hit = !q || var hit = !q ||
(el.getAttribute('data-name') || '').toLowerCase().indexOf(q) >= 0 || (el.getAttribute('data-name') || '').toLowerCase().indexOf(q) >= 0 ||
(el.getAttribute('data-shown') || '').toLowerCase().indexOf(q) >= 0 || (el.getAttribute('data-shown') || '').toLowerCase().indexOf(q) >= 0 ||
isSubSeq(q, el.getAttribute('data-initials') || ''); iniHit;
el.hidden = !hit; el.hidden = !hit;
if (hit) { shown++; } if (hit) { shown++; }
}); });
+162 -2
View File
@@ -16,6 +16,8 @@ use App\Auth;
use App\Birthday; use App\Birthday;
use App\Calendar; use App\Calendar;
use App\Cinema; use App\Cinema;
use App\ContactImport;
use App\ContactImporter;
use App\Crypto; use App\Crypto;
use App\Database; use App\Database;
use App\Douban; use App\Douban;
@@ -34,6 +36,8 @@ use App\MovieStats;
use App\Nickname; use App\Nickname;
use App\Person; use App\Person;
use App\PersonGroup; use App\PersonGroup;
use App\PersonJob;
use App\PersonNote;
use App\PersonQuery; use App\PersonQuery;
use App\PersonRoster; use App\PersonRoster;
use App\Pinyin; use App\Pinyin;
@@ -144,6 +148,41 @@ function read_birthday_input(array $existing = []): array
* @return string[][][] kind => 行列表(label/value,value 保留原样,空行不丢 —— * @return string[][][] kind => 行列表(label/value,value 保留原样,空行不丢 ——
* 交给 Person::replaceContacts 丢弃;校验失败重画表单时还要用它回填) * 交给 Person::replaceContacts 丢弃;校验失败重画表单时还要用它回填)
*/ */
/**
* 从表单读「工作经历」那组行(用户 2026-10-03 第 4 条)。
*
* 表单长这样(与「补充联系方式」同一套平行数组做法):
* job_org[] / job_title[] / job_rank[] / job_start[] / job_end[] / job_note[]
* 浏览器会按同一下标自动补齐,zip 起来最直观;空行由 PersonJob::replace 丢掉。
*
* start/end 用 `<input type="month">`,值就是 'YYYY-MM' —— 正好是库里存的格式,
* 不需要再做一次"日期 → 年月"的换算(少一处能写错的地方)。
*
* @return array<int,array{org:string,title:string,rank_name:string,start_ym:string,end_ym:string,note:string}>
*/
function read_jobs_input(): array
{
$org = (array)($_POST['job_org'] ?? []);
$title = (array)($_POST['job_title'] ?? []);
$rank = (array)($_POST['job_rank'] ?? []);
$start = (array)($_POST['job_start'] ?? []);
$end = (array)($_POST['job_end'] ?? []);
$note = (array)($_POST['job_note'] ?? []);
$n = max(count($org), count($title), count($rank), count($start), count($end), count($note));
$out = [];
for ($i = 0; $i < $n; $i++) {
$out[] = [
'org' => (string)($org[$i] ?? ''),
'title' => (string)($title[$i] ?? ''),
'rank_name' => (string)($rank[$i] ?? ''),
'start_ym' => (string)($start[$i] ?? ''),
'end_ym' => (string)($end[$i] ?? ''),
'note' => (string)($note[$i] ?? ''),
];
}
return $out;
}
function read_contacts_input(): array function read_contacts_input(): array
{ {
$out = []; $out = [];
@@ -803,6 +842,64 @@ switch ($r) {
redirect('people'); redirect('people');
break; break;
/**
* 名册导入(v24 用户 2026-10-03 第 1 条)。
*
* 用户原话:「需要增加一个导入功能,可以导入常见的联系人格式,例如 vcf 等。
* 导入时,如果名字或手机号在已有的名册中存在,则导入其他信息,
* 如果这些信息在系统中已经存在,则只导入其他信息。」
*
* 流程:上传文件 → ContactImport::parse()(纯解析)→ ContactImporter::run()(判重+落库)。
* 判重与"只补空不覆盖"的规则都在 ContactImporter 里,这里只负责收文件、报告结果。
*/
case 'people/import':
Auth::requireWrite();
$familyId = (int)Auth::familyId();
$me = (int)Auth::personId();
if ($method !== 'POST') {
View::render('people/import', [
'title' => '导入联系人',
'groups' => PersonGroup::orderFor($familyId, $me),
'report' => null,
], 'people');
break;
}
csrf_check();
$f = $_FILES['contacts'] ?? null;
if (!$f || (int)($f['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
flash('err', '没收到文件(或上传失败)。');
redirect('people/import');
}
// ⚠️ 不去校验扩展名/类型:手机导出的 vcf 常被改名成 .txt 或 .csv,
// 按扩展名拦会把正常文件挡在外面。判据用**内容**(见 ContactImport::parse)。
$raw = (string)file_get_contents((string)$f['tmp_name']);
if (trim($raw) === '') {
flash('err', '文件是空的。');
redirect('people/import');
}
$records = ContactImport::parse($raw, (string)($f['name'] ?? ''));
if (!$records) {
flash('err', '没从这份文件里认出任何联系人。支持 .vcf(vCard)与 .csv/.txt'
. '(表头含 姓名/手机/邮箱 即可)。');
redirect('people/import');
}
$groupId = (int)($_POST['group_id'] ?? 0);
$res = ContactImporter::run($familyId, $me, $records, $groupId);
$msg = '导入完成:新增 ' . $res['added'] . ' 人,补充信息 ' . $res['updated'] . ' 人';
if ($res['skipped'] > 0) {
$msg .= ',' . $res['skipped'] . ' 条无需改动';
}
flash('ok', $msg . '。');
View::render('people/import', [
'title' => '导入联系人',
'groups' => PersonGroup::orderFor($familyId, $me),
'report' => $res,
], 'people');
break;
/** /**
* 「从家里已有的人里挑」—— 添加成员的第二个入口。 * 「从家里已有的人里挑」—— 添加成员的第二个入口。
* *
@@ -1225,6 +1322,9 @@ switch ($r) {
'errors' => [], 'errors' => [],
'canEditAll' => true, 'canEditAll' => true,
'isSelf' => false, 'isSelf' => false,
// 工作经历先给一行空白(第 4 条),省得还要点「再加一段」
'jobRows' => [[]],
'myNote' => '',
], 'people'); ], 'people');
break; break;
@@ -1242,7 +1342,10 @@ switch ($r) {
'org' => trim((string)($_POST['org'] ?? '')), 'org' => trim((string)($_POST['org'] ?? '')),
'title' => trim((string)($_POST['title'] ?? '')), 'title' => trim((string)($_POST['title'] ?? '')),
'note' => trim((string)($_POST['note'] ?? '')), 'note' => trim((string)($_POST['note'] ?? '')),
'slogan' => trim((string)($_POST['slogan'] ?? '')), // 新增的人还没有"我的这一句话"(那是他自己的东西,由他之后自己填)
'slogan' => '',
// 工作经历(第 4 条):一组行,整组替换;见 PersonJob::replace
'jobs' => read_jobs_input(),
'avatar' => '', 'avatar' => '',
'kind' => 'member', 'kind' => 'member',
// ⚠️ 这两项必须显式从表单取回:表单里有,但漏了这一步就会被静默丢掉, // ⚠️ 这两项必须显式从表单取回:表单里有,但漏了这一步就会被静默丢掉,
@@ -1274,6 +1377,10 @@ switch ($r) {
'canEditAll' => true, 'canEditAll' => true,
'isSelf' => false, 'isSelf' => false,
'contacts' => $contacts, 'contacts' => $contacts,
// 校验失败要把用户刚填的工作经历**原样回显**(第 4 条),
// 私备注同理(第 5 条)—— 别让他重填一遍。
'jobRows' => (array)($d['jobs'] ?? []),
'myNote' => trim((string)($_POST['my_note'] ?? '')),
], 'people'); ], 'people');
exit; exit;
} }
@@ -1297,6 +1404,10 @@ switch ($r) {
'canEditAll' => true, 'canEditAll' => true,
'isSelf' => false, 'isSelf' => false,
'contacts' => $contacts, 'contacts' => $contacts,
// 校验失败要把用户刚填的工作经历**原样回显**(第 4 条),
// 私备注同理(第 5 条)—— 别让他重填一遍。
'jobRows' => (array)($d['jobs'] ?? []),
'myNote' => trim((string)($_POST['my_note'] ?? '')),
], 'people'); ], 'people');
exit; exit;
} }
@@ -1312,6 +1423,8 @@ switch ($r) {
} }
PersonRoster::ensure($familyId, (int)Auth::personId(), $id, $gid > 0 ? $gid : null, 'self'); PersonRoster::ensure($familyId, (int)Auth::personId(), $id, $gid > 0 ? $gid : null, 'self');
Person::replaceContacts($id, $contacts); Person::replaceContacts($id, $contacts);
// 工作经历:整组替换(第 4 条)。空的那组会把这段经历清空 —— 与联系人同一口径。
PersonJob::replace($id, (array)($d['jobs'] ?? []));
clear_old(); clear_old();
if ($avatarWarn !== '') { if ($avatarWarn !== '') {
flash('ok', '已把「' . $d['name'] . '」加进名册。头像没有保存:' . $avatarWarn); flash('ok', '已把「' . $d['name'] . '」加进名册。头像没有保存:' . $avatarWarn);
@@ -1355,6 +1468,10 @@ switch ($r) {
'phoneValue' => Crypto::decrypt((string)$p['phone_encrypted']), 'phoneValue' => Crypto::decrypt((string)$p['phone_encrypted']),
'idCardValue' => Crypto::decrypt((string)$p['id_card_encrypted']), 'idCardValue' => Crypto::decrypt((string)$p['id_card_encrypted']),
'contacts' => $editContacts, 'contacts' => $editContacts,
// 工作经历(第 4 条):库里已有的多段
'jobRows' => PersonJob::list($id),
// 我对他的私备注(第 5 条):**只有我自己**那一份
'myNote' => $isSelf ? '' : PersonNote::get($id, (int)Auth::personId()),
], 'people'); ], 'people');
break; break;
@@ -1374,6 +1491,8 @@ switch ($r) {
// 改别人(= 能写的人编名册):字段是完整的一套。 // 改别人(= 能写的人编名册):字段是完整的一套。
// 改自己(可能是访客):只允许动属于自己的那些 —— 与 Person::updateSelf 一一对应。 // 改自己(可能是访客):只允许动属于自己的那些 —— 与 Person::updateSelf 一一对应。
$canEditAll = Auth::canWrite(); $canEditAll = Auth::canWrite();
// 「我的这一句话」只能本人改(用户第 3 条)→ 非本人提交时沿用库里现有值。
$keepSlogan = (string)($p['slogan'] ?? '');
$d = [ $d = [
'name' => trim((string)($_POST['name'] ?? '')), 'name' => trim((string)($_POST['name'] ?? '')),
'gender' => (string)($_POST['gender'] ?? ''), 'gender' => (string)($_POST['gender'] ?? ''),
@@ -1384,7 +1503,13 @@ switch ($r) {
'org' => trim((string)($_POST['org'] ?? '')), 'org' => trim((string)($_POST['org'] ?? '')),
'title' => trim((string)($_POST['title'] ?? '')), 'title' => trim((string)($_POST['title'] ?? '')),
'note' => trim((string)($_POST['note'] ?? '')), 'note' => trim((string)($_POST['note'] ?? '')),
'slogan' => trim((string)($_POST['slogan'] ?? '')), // ⚠️ 用户 2026-10-03 第 3 条:这一句话**只能本人改** ——
// 表单里这一栏也只在 $isSelf 时出现。别人提交时这里读不到字段,
// 若直接 $_POST 取值会拿到空串 → **把本人的那句话清空**。
// 所以非本人一律沿用库里已有的值($keepSlogan)。
'slogan' => $isSelf ? trim((string)($_POST['slogan'] ?? '')) : $keepSlogan,
// 工作经历(第 4 条):一组行,整组替换;见 PersonJob::replace
'jobs' => read_jobs_input(),
'avatar' => (string)$p['avatar'], 'avatar' => (string)$p['avatar'],
'birth_rank' => $canEditAll ? trim((string)($_POST['birth_rank'] ?? '')) : ($p['birth_rank'] ?? ''), 'birth_rank' => $canEditAll ? trim((string)($_POST['birth_rank'] ?? '')) : ($p['birth_rank'] ?? ''),
'is_placeholder' => $canEditAll 'is_placeholder' => $canEditAll
@@ -1445,6 +1570,15 @@ switch ($r) {
exit; exit;
} }
Person::replaceContacts($id, $contacts); Person::replaceContacts($id, $contacts);
// 工作经历:整组替换(第 4 条)。空的那组会把这段经历清空 —— 与联系人同一口径。
PersonJob::replace($id, (array)($d['jobs'] ?? []));
// 「我对他的私人备注」(第 5 条):落在**写的人自己**名下(person_notes)。
// ⚠️ 两条守卫:
// ① 编辑自己时表单里没有这个字段(不需要"我对我的备注")→ 别把已有的清掉;
// ② 即使有,也不该对自己写(`$id !== 我`)。
if ((int)$id !== (int)Auth::personId() && array_key_exists('my_note', $_POST)) {
PersonNote::set($id, (int)Auth::personId(), (string)$_POST['my_note']);
}
if ((int)$p['id'] === (int)Auth::personId()) { if ((int)$p['id'] === (int)Auth::personId()) {
Auth::refreshAvatar((string)$d['avatar']); Auth::refreshAvatar((string)$d['avatar']);
// 姓名也可能改了 —— 不同步会话的话顶栏还是旧名字 // 姓名也可能改了 —— 不同步会话的话顶栏还是旧名字
@@ -1459,6 +1593,28 @@ switch ($r) {
redirect('people/show', ['id' => $id]); redirect('people/show', ['id' => $id]);
break; break;
/**
* 保存「我对他的私人备注」(用户 2026-10-03 第 5 条)。
*
* 独立成一个路由而不是塞进 people/update:这两件事的**可见性**不同 ——
* people/update 改的是"这个人的资料"(有写权限的人都能改),
* 而这条备注是"**我**和他之间的事",只有写的人自己看得到。
* 混在一起的话,"有写权限"就等于"能改别人对某人的私评",那是另一回事。
*/
case 'people/note':
Auth::requireLogin();
csrf_check();
$familyId = (int)Auth::familyId();
$me = (int)Auth::personId();
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0 || $id === $me || !isset(Person::map($familyId)[$id])) {
flash('err', '找不到这个人。');
redirect('people');
}
PersonNote::set($id, $me, (string)($_POST['note'] ?? ''));
flash('ok', '备注已保存(只有你自己看得到)。');
redirect('people/show', ['id' => $id]);
case 'people/show': case 'people/show':
$familyId = (int)Auth::familyId(); $familyId = (int)Auth::familyId();
$me = (int)Auth::personId(); $me = (int)Auth::personId();
@@ -1490,6 +1646,10 @@ switch ($r) {
// 「我叫他什么」—— 只有我自己能改,改了也只影响我看到的 // 「我叫他什么」—— 只有我自己能改,改了也只影响我看到的
'myNickname' => $id === $me ? '' : Nickname::get($me, $id), 'myNickname' => $id === $me ? '' : Nickname::get($me, $id),
'shown' => $id === $me ? (string)$p['name'] : (Nickname::display($me, $p) ?: (string)$p['name']), 'shown' => $id === $me ? (string)$p['name'] : (Nickname::display($me, $p) ?: (string)$p['name']),
// 工作经历(第 4 条):可以有多段,详情页整列出来
'jobs' => PersonJob::list($id),
// 我对他的私人备注(第 5 条):**只有我自己**那一份;看自己时为空
'myNote' => $id === $me ? '' : PersonNote::get($id, $me),
'birthdays' => Birthday::describe($p), 'birthdays' => Birthday::describe($p),
'birthdayNext'=> Birthday::nextOccurrences($p, date('Y-m-d'), 400), 'birthdayNext'=> Birthday::nextOccurrences($p, date('Y-m-d'), 400),
// 补充联系方式(vCard 对齐):kind=phone 的 value 是密文,模板里用 maskPhone 展示 // 补充联系方式(vCard 对齐):kind=phone 的 value 是密文,模板里用 maskPhone 展示
+11 -2
View File
@@ -148,6 +148,15 @@ $datumJson = json_encode(
会出现两个"回到我的家谱"(用户明确点名)。现在整页只有标题。 */ ?> 会出现两个"回到我的家谱"(用户明确点名)。现在整页只有标题。 */ ?>
<div class="page-head"> <div class="page-head">
<h1><?= $focusId === (int)$meId ? '我的家谱' : e((string)($people[$focusId]['name'] ?? '') . ' 的家谱') ?></h1> <h1><?= $focusId === (int)$meId ? '我的家谱' : e((string)($people[$focusId]['name'] ?? '') . ' 的家谱') ?></h1>
<div class="actions">
<?php /* 用户 2026-10-03:「在家谱的右上角,放一个按钮:我的家谱,
这样他无论正在查看以谁为中心的家谱,他都可以快速回到自己的家谱。」
⚠️ 只在**看别人的家谱**时出现 —— 看自己的家谱时这个按钮没有意义
(点了还是这一页),那种"点了没反应"的按钮最容易被当成坏了。 */ ?>
<?php if ($focusId !== (int)$meId): ?>
<a class="btn btn-ghost btn-sm" href="<?= e(url('kin')) ?>">我的家谱</a>
<?php endif; ?>
</div>
</div> </div>
<?php if (!$canChart): ?> <?php if (!$canChart): ?>
@@ -215,8 +224,8 @@ $datumJson = json_encode(
/* ⚠️ 卡片尺寸**必须与 CSS 里 .kin-card 的 --kin-w/--kin-h 一致**: /* ⚠️ 卡片尺寸**必须与 CSS 里 .kin-card 的 --kin-w/--kin-h 一致**:
库按这个尺寸算卡片间距与连线落点,两边一旦不一致,连线就会与卡片错位 库按这个尺寸算卡片间距与连线落点,两边一旦不一致,连线就会与卡片错位
(用户 2026-10-03 反馈过一次"线又错位了",就是尺寸/居中改动引起的)。 (用户 2026-10-03 反馈过一次"线又错位了",就是尺寸/居中改动引起的)。
98 = 96(头像宽)+ 左右各 1px 边框;见 app.css 的 .kin-card。 */ 90 = 88(头像区,正方形;见 --kin-ph)+ 左右各 1px 边框;见 app.css 的 .kin-card。 */
var KIN_W = 98, KIN_H = 116; var KIN_W = 90, KIN_H = 128;
chart.setCardHtml() chart.setCardHtml()
.setStyle('rect') .setStyle('rect')
+163 -37
View File
@@ -66,6 +66,39 @@ $ctHints = [
<div class="card card-pad"> <div class="card card-pad">
<div class="form-grid"> <div class="form-grid">
<?php
// 裁剪比例不是拍脑袋定的,而是由「这个位置显示成什么形状」决定(见 App\ImageSlot)。
// 前端拿这些 data-* 去生成裁剪框,服务端拿同一个槽位去最终裁切 —— 一处定义、两处使用。
$avSlot = \App\ImageSlot::get('avatar');
?>
<?php /* 用户 2026-10-03 第 6 条:**头像放在表单最前面**,并且**去掉「选择文件」按钮**
—— 直接点那张(默认)头像就是选文件,选完弹裁剪框。
好处:① 省掉一整行"选择文件 + 当前头像"的重复控件;
② 一眼就知道"这里能换头像"(按钮式的 file 控件反而看不出当前长什么样)。 */ ?>
<div class="field full avatar-field">
<label>头像</label>
<div class="avatar-picker">
<img id="avatar-preview" src="<?= e($avatarUrl) ?>" alt=""
title="点击更换头像"
data-has-avatar="<?= trim((string)($person['avatar'] ?? '')) !== '' ? '1' : '0' ?>">
<?php /* 真正吃文件的 input:视觉上藏起来,由上面的图片代它触发(label/JS 都行,
这里用 JS 点它,兼容性最好,也不依赖 for/id 配对)。 */ ?>
<input class="sr-only" 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);不裁就留空 = 居中裁切 */ ?>
<input type="hidden" name="avatar_crop" value="">
<span class="avatar-hint small muted">
点一下换头像;选完会弹裁剪框。<br>
头像是 1:1 正方形,多大都能传,保存时自动缩成 <?= (int)$avSlot['w'] ?>×<?= (int)$avSlot['h'] ?>。
</span>
</div>
</div>
<div class="field"> <div class="field">
<label for="name">姓名 *</label> <label for="name">姓名 *</label>
<input class="input" id="name" name="name" value="<?= e(old('name', $person['name'] ?? '')) ?>" required> <input class="input" id="name" name="name" value="<?= e(old('name', $person['name'] ?? '')) ?>" required>
@@ -119,14 +152,23 @@ $ctHints = [
<!-- 生日块已挪到表单最底部:大多数情况下生日由身份证号读出、三个都对, <!-- 生日块已挪到表单最底部:大多数情况下生日由身份证号读出、三个都对,
不需要动(用户原话:生日什么的应该放下面)。 --> 不需要动(用户原话:生日什么的应该放下面)。 -->
<?php /* 用户 2026-10-03 第 3 条:「编辑资料中,**这个人的**一句话,这个地方去掉,
每个人的一句话,**只能他自己修改**。如果他不修改,就是默认空的。」
→ 所以这一栏**只在改自己时出现**($isSelf):
别人编辑他时看不到、也改不了(那正是用户要"去掉"的场景);
而它确实得有个入口让他自己填,否则"只能他自己修改"就没有落点。
⚠️ 服务端同理:people/update 只在 $isSelf 时读 slogan,
否则"管理员编辑一次就把本人的那句话清空"。 */ ?>
<?php if ($isSelf): ?>
<div class="field full"> <div class="field full">
<label for="slogan">这个人的一句话</label> <label for="slogan">我的这一句话</label>
<input class="input" id="slogan" name="slogan" maxlength="200" <input class="input" id="slogan" name="slogan" maxlength="200"
value="<?= e(old('slogan', $person['slogan'] ?? '')) ?>" value="<?= e(old('slogan', $person['slogan'] ?? '')) ?>"
placeholder="可留空;留空时用家庭统一的那句"> placeholder="可留空,如:慢慢来,比较快">
<span class="tip">显示在这个人自己的首页标题下面。本人也可以在自己的资料页里改。</span> <span class="tip">只有你自己能改这句;显示在自己首页标题下面。留空就不显示。</span>
<?php if (!empty($errors['slogan'])): ?><span class="err"><?= e($errors['slogan']) ?></span><?php endif; ?> <?php if (!empty($errors['slogan'])): ?><span class="err"><?= e($errors['slogan']) ?></span><?php endif; ?>
</div> </div>
<?php endif; ?>
<?php if ($canEditAll): ?> <?php if ($canEditAll): ?>
<div class="field"> <div class="field">
@@ -145,16 +187,53 @@ $ctHints = [
<?php if (!empty($errors['email'])): ?><span class="err"><?= e($errors['email']) ?></span><?php endif; ?> <?php if (!empty($errors['email'])): ?><span class="err"><?= e($errors['email']) ?></span><?php endif; ?>
</div> </div>
<div class="field"> <?php /* 用户 2026-10-03 第 4 条:单位/职务/职称**可以有多段**(记录工作变化)。
<label for="org">工作单位</label> 所以这里是一组"经历行",而不是三个单值输入框。
<input class="input" id="org" name="org" ⚠️ 表单字段名是平行数组(job_org[] / job_title[] …),
value="<?= e(old('org', $person['org'] ?? '')) ?>" placeholder="可留空"> 服务端 read_jobs_input() + PersonJob::replace() 整组替换。 */ ?>
<div class="field full">
<label>工作经历</label>
<p class="small muted" style="margin:0 0 10px">
一个人可以有多段工作 —— 换过单位、提过职称都记下来。
<b>不填「结束年月」= 现在还在那儿</b>(列表里会标「现在」)。
</p>
<?php
// 回填优先级:老表单回显(old) → 库里已有的经历 → 完全空(新增时给一行空的)
$jobRows = $jobRows ?? [];
if (!$jobRows) {
$jobRows = [[]]; // 新增时给一行空白行,省得还要点"加一段"
}
?>
<div class="job-list" id="jobList">
<?php foreach ($jobRows as $jr): ?>
<div class="job-row">
<div class="job-cell">
<label class="job-lb">单位</label>
<input class="input" name="job_org[]" value="<?= e((string)($jr['org'] ?? '')) ?>" placeholder="如:中国海洋大学">
</div>
<div class="job-cell">
<label class="job-lb">职务</label>
<input class="input" name="job_title[]" value="<?= e((string)($jr['title'] ?? '')) ?>" placeholder="如:副院长">
</div>
<div class="job-cell">
<label class="job-lb">职称</label>
<input class="input" name="job_rank[]" value="<?= e((string)($jr['rank_name'] ?? '')) ?>" placeholder="如:副教授">
</div>
<div class="job-cell job-cell-sm">
<label class="job-lb">起</label>
<input class="input" type="month" name="job_start[]" value="<?= e((string)($jr['start_ym'] ?? '')) ?>">
</div>
<div class="job-cell job-cell-sm">
<label class="job-lb">止</label>
<input class="input" type="month" name="job_end[]" value="<?= e((string)($jr['end_ym'] ?? '')) ?>">
</div>
<button type="button" class="btn btn-ghost btn-sm job-del" title="删掉这一段">×</button>
</div>
<?php endforeach; ?>
</div>
<div class="btn-row" style="margin-top:8px">
<button type="button" class="btn btn-ghost btn-sm" id="jobAdd">+ 再加一段</button>
</div> </div>
<div class="field">
<label for="title">职务 / 职称</label>
<input class="input" id="title" name="title"
value="<?= e(old('title', $person['title'] ?? '')) ?>" placeholder="可留空">
</div> </div>
<?php if ($canEditAll): ?> <?php if ($canEditAll): ?>
@@ -176,11 +255,32 @@ $ctHints = [
value="<?= e(old('address', $person['address'] ?? '')) ?>" placeholder="可留空"> value="<?= e(old('address', $person['address'] ?? '')) ?>" placeholder="可留空">
</div> </div>
<?php /* 用户 2026-10-03 第 5 条:备注分两种 ——
① 这一栏是**这个人自己的**自我介绍/格言(他本人也能在个人设置里改,
别人打开他的资料能看到);
② 「我对他的私人备注」在下面单独一块(只有写的人自己看得到)。 */ ?>
<div class="field full"> <div class="field full">
<label for="note">备注</label> <label for="note">自我介绍(他自己写的)</label>
<textarea class="input" id="note" name="note" placeholder="爱吃辣、对芒果过敏、怕坐过山车……"><?= e(old('note', $person['note'] ?? '')) ?></textarea> <textarea class="input" id="note" name="note" placeholder="爱吃辣、对芒果过敏、怕坐过山车……"><?= e(old('note', $person['note'] ?? '')) ?></textarea>
<span class="tip">这是<b>他本人</b>的自我介绍,别人看得到。改的是同一份 —— 他也能在个人设置里改。</span>
</div> </div>
<?php /* 用户第 5 条:**我对他的私人备注** —— 只有我自己看得到(存在 person_notes 里)。
只在"编辑别人"时出现(自己看自己不需要"我对我的备注")。
⚠️ 它是独立的出口(自己的路由 + 自己的表),不与上面那份混在一起:
「他愿意公开说的」与「我对他的私下记录」是两件事、两种可见性。 */ ?>
<?php if ($isEdit && !$isSelf): ?>
<div class="field full">
<label for="myNote">我对 <?= e((string)$person['name']) ?> 的备注(只有我自己看得到)</label>
<textarea class="input" id="myNote" name="my_note" rows="2"
placeholder="怎么认识的、要注意什么、上次见面聊了什么……"><?= e((string)($myNote ?? '')) ?></textarea>
<span class="tip">
<b>只有你自己看得到</b>,别人(包括他本人)都看不到 ——
这里写的是"我和他之间的事",不是他的公开资料。
</span>
</div>
<?php endif; ?>
<!-- ==================== 补充联系方式(可多条,对齐 vCard) ==================== --> <!-- ==================== 补充联系方式(可多条,对齐 vCard) ==================== -->
<?php foreach (['phone', 'email', 'address', 'url'] as $ctKind): ?> <?php foreach (['phone', 'email', 'address', 'url'] as $ctKind): ?>
<div class="field full ct-block" data-ct-kind="<?= $ctKind ?>"> <div class="field full ct-block" data-ct-kind="<?= $ctKind ?>">
@@ -200,30 +300,6 @@ $ctHints = [
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
<?php
// 裁剪比例不是拍脑袋定的,而是由「这个位置显示成什么形状」决定(见 App\ImageSlot)。
// 前端拿这些 data-* 去生成裁剪框,服务端拿同一个槽位去最终裁切 —— 一处定义、两处使用。
$avSlot = \App\ImageSlot::get('avatar');
?>
<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);不裁就留空 = 居中裁切 */ ?>
<input type="hidden" name="avatar_crop" value="">
<span class="tip">选好图片后会弹出裁剪框,把要留的部分框住。<b>比例按它在页面上的形状定</b>(头像是 1:1 正方形)。多大都能传,保存时自动缩放成 <?= (int)$avSlot['w'] ?>×<?= (int)$avSlot['h'] ?>。</span>
</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 class="field full"> <div class="field full">
<label>生日</label> <label>生日</label>
@@ -306,3 +382,53 @@ $ctHints = [
</div> </div>
</div> </div>
</form> </form>
<script>
(function () {
/* ---- 头像:点图即选文件(用户 2026-10-03 第 6 条)----
真 input[type=file] 视觉上藏起来了(.sr-only),点图代它触发。
⚠️ 不要用 <label for> 包住图片来做这件事:一旦图被包进 label,
.avatar-picker 的 hover/光标语义会变,而且有的浏览器在 label 里
点 <img> 不会激活 file 控件(要额外 CSS 才能稳)。直接点 input 最省事。 */
var prev = document.getElementById('avatar-preview');
var file = document.getElementById('avatar');
if (prev && file) {
prev.addEventListener('click', function () { file.click(); });
prev.style.cursor = 'pointer';
}
/* ---- 工作经历:+/× 增删一段(用户第 4 条)----
⚠️ 模板里的行是**服务端渲染**的(首屏没有 JS 也能填、也能提交),
这里只加"再加一段 / 删掉这段"两个交互 —— 渐进增强,不是二选一。 */
var list = document.getElementById('jobList');
var addBtn = document.getElementById('jobAdd');
function bindDel(row) {
var del = row.querySelector('.job-del');
if (!del) { return; }
del.addEventListener('click', function () {
var all = list.querySelectorAll('.job-row');
if (all.length <= 1) {
// 只剩一行时"删"= 清空这一行(而不是消失),否则页面会没有输入框可填
row.querySelectorAll('input').forEach(function (i) { i.value = ''; });
return;
}
row.remove();
});
}
if (list) {
Array.prototype.forEach.call(list.querySelectorAll('.job-row'), bindDel);
if (addBtn) {
addBtn.addEventListener('click', function () {
var first = list.querySelector('.job-row');
if (!first) { return; }
var row = first.cloneNode(true);
row.querySelectorAll('input').forEach(function (i) { i.value = ''; });
list.appendChild(row);
bindDel(row);
var f = row.querySelector('input');
if (f) { f.focus(); }
});
}
}
})();
</script>
+95
View File
@@ -0,0 +1,95 @@
<?php
/**
* 名册导入(v24 用户 2026-10-03 第 1 条)。
*
* 页面就两件事:挑文件 → 看结果。所以做成**一页**(提交后同页出报告),
* 不跳到"导入历史"之类的第二页 —— 一次导入看完就该结束。
*
* @param array $groups 我能用的分组(导入进来的人可以先归到一组)
* @param array|null $report ContactImporter::run 的结果(null = 还没导入)
*/
$report = $report ?? null;
$canMove = \App\Auth::canWrite();
?>
<div class="page-head">
<h1>导入联系人</h1>
<span class="sub">从手机 / 邮箱导出的通讯录批量加进名册</span>
<div class="actions">
<a class="btn btn-ghost btn-sm" href="<?= e(url('people')) ?>">返回名册</a>
</div>
</div>
<div class="card card-pad">
<h2 class="cinema-h2">选一份文件</h2>
<p class="small muted" style="margin:0 0 14px">
支持 <b>.vcf</b>(vCard,iPhone / 安卓 / 谷歌联系人 / Outlook 都能导出)与
<b>.csv / .txt</b>(表头里有「姓名 / 手机 / 邮箱」之类就能认,中英文表头都行)。
<br>
导入规则:<b>手机号或姓名已经在名册里的,不会重复建人</b>,
只把「他还没有的信息」补上去(已有的一律不动);其余才新建。
</p>
<form method="post" action="<?= e(url('people/import')) ?>" enctype="multipart/form-data">
<?= csrf_field() ?>
<div class="form-grid">
<div class="field full">
<label for="imp-file">联系人文件 *</label>
<input class="input" type="file" id="imp-file" name="contacts"
accept=".vcf,.csv,.txt,text/vcard,text/csv,text/plain" required>
</div>
<div class="field">
<label for="imp-group">加进哪一组</label>
<select class="select" id="imp-group" name="group_id">
<option value="0">先不分类</option>
<?php foreach ($groups as $g): ?>
<option value="<?= (int)$g['id'] ?>"><?= e((string)$g['name']) ?></option>
<?php endforeach; ?>
</select>
<span class="tip">只影响<b>新建</b>的那些人;已有的人保持他原来的分组。</span>
</div>
</div>
<div class="btn-row">
<button class="btn" type="submit">开始导入</button>
</div>
</form>
</div>
<?php if ($report): ?>
<div class="card card-pad">
<h2 class="cinema-h2">
导入结果
<span class="hint">新增 <?= (int)$report['added'] ?> · 补充 <?= (int)$report['updated'] ?> · 无需改动 <?= (int)$report['skipped'] ?></span>
</h2>
<?php if (!$report['people']): ?>
<p class="empty-hint">文件里没有可导入的联系人。</p>
<?php else: ?>
<?php /* ⚠️ 报告的是"这条记录做了什么",逐条列出来:
批量操作最怕"导完不知道改了什么"(尤其"补充"这一类会动到已有的人)。 */ ?>
<div class="table-wrap">
<table class="table">
<thead><tr><th>联系人</th><th>结果</th><th>补上了什么</th></tr></thead>
<tbody>
<?php foreach ($report['people'] as $row): ?>
<?php
$act = (string)$row['action'];
$word = $act === 'added' ? '新建' : ($act === 'updated' ? '补充信息' : '无需改动');
$cls = $act === 'added' ? 'led-asset' : ($act === 'updated' ? 'led-asset' : '');
?>
<tr>
<td><?= e((string)$row['name']) ?></td>
<td class="<?= $cls ?>"><?= e($word) ?></td>
<td class="small muted">
<?= $row['added'] ? e(implode('、', (array)$row['added'])) : '—' ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<div class="btn-row" style="margin-top:14px">
<a class="btn btn-ghost" href="<?= e(url('people')) ?>">去看名册</a>
<a class="btn btn-ghost" href="<?= e(url('people/import')) ?>">再导一份</a>
</div>
</div>
<?php endif; ?>
+19 -1
View File
@@ -68,7 +68,11 @@ $renderGrid = function (array $list) use ($meId, $canMove, $groups): void {
?> ?>
<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-search="<?= e($pshow . ' ' . $pReal . ' ' . (string)($p['email'] ?? '') . ' ' . (string)($p['org'] ?? '') . ' ' . (string)($p['phone_plain'] ?? '')) ?>"
data-initials="<?= e(\App\Pinyin::initials($pReal . ' ' . $pNick)) ?>"> <?php /* ⚠️ 首字母**分字段**、用空格隔开(前端逐段独立判子序列)。
把"姓名+称呼"拼成一串会造出跨字段巧合:用户实测「输 yy 搜出岳父」
—— 洪勇的称呼是"岳父" → hy + yf = hyyf → yy 跨边界命中。
服务端 Pinyin::matches 本来就是逐字段判的,这样两边口径一致。 */ ?>
data-initials="<?= e(trim(\App\Pinyin::initials($pReal) . ' ' . \App\Pinyin::initials($pNick))) ?>">
<?php if ($canMove): ?> <?php if ($canMove): ?>
<span class="drag-handle" title="拖到我想要的位置 / 那一栏" aria-hidden="true">⠿</span> <span class="drag-handle" title="拖到我想要的位置 / 那一栏" aria-hidden="true">⠿</span>
<?php endif; ?> <?php endif; ?>
@@ -122,6 +126,14 @@ $renderGrid = function (array $list) use ($meId, $canMove, $groups): void {
<?php endif; ?> <?php endif; ?>
</div> </div>
</a> </a>
<?php /* 用户 2026-10-03 第 7 条:在 ⋯ 前面加一个「编辑」按钮,快速进这个人的编辑页。
为什么不做进 ⋯ 菜单里:改资料是**高频**操作(补生日、补电话),
藏进 ⋯ 里要点两下;而 ⋯ 里放的是"调整分组/移出名册"这类低频动作。
⚠️ 它是 <a>,且必须在 person-main 这个 <a> **外面**
—— a 套 a 是非法 HTML,浏览器会把 DOM 拆开。 */ ?>
<a class="btn btn-ghost btn-sm person-edit" data-no-drag
href="<?= e(url('people/edit', ['id' => $pid])) ?>"
title="编辑 <?= e($pshow) ?> 的资料">编辑</a>
<?php if ($canMove): ?> <?php if ($canMove): ?>
<details class="person-more" data-no-drag> <details class="person-more" data-no-drag>
<summary aria-label="调整分组">⋯</summary> <summary aria-label="调整分组">⋯</summary>
@@ -183,6 +195,12 @@ $renderBlock = function (int $gid, string $name, array $list) use ($renderGrid):
从家里已有的人里挑(<?= $pickable ?>) 从家里已有的人里挑(<?= $pickable ?>)
</a> </a>
<?php endif; ?> <?php endif; ?>
<?php if ($canMove): ?>
<?php /* 用户 2026-10-03 第 1 条:名册导入入口。
⚠️ 放在「添加成员」**左边**(次要动作在左、主要动作在右)——
日常还是一个个加,导入是换手机/换号时的一次性动作。 */ ?>
<a class="btn btn-ghost btn-sm" href="<?= e(url('people/import')) ?>">导入联系人</a>
<?php endif; ?>
<?php if (\App\Auth::isAdmin()): ?> <?php if (\App\Auth::isAdmin()): ?>
<a class="btn btn-sm" href="<?= e(url('people/new')) ?>">添加成员</a> <a class="btn btn-sm" href="<?= e(url('people/new')) ?>">添加成员</a>
<?php endif; ?> <?php endif; ?>
+90 -10
View File
@@ -55,14 +55,11 @@ $shortKind = \App\Birthday::KINDS;
<?= $isSelf ? '编辑我的资料' : '编辑资料' ?> <?= $isSelf ? '编辑我的资料' : '编辑资料' ?>
</a> </a>
<?php endif; ?> <?php endif; ?>
<?php if ($admin): ?> <?php /* 用户 2026-10-03 第 2 条:右上角那个「移除」换成**返回**(回名册列表)。
<form method="post" action="<?= e(url('people/destroy')) ?>" style="display:inline" 理由:详情页最常做的事是"看完回去",而"移除"是低频且危险的破坏性操作,
onsubmit="return confirm('确定要从名册里移除 <?= e($p['name']) ?> 吗?相关的账号与亲属关系也会一起删掉。')"> 不该占着右上角最顺手的位置。
<?= csrf_field() ?> 「删除」已移到页面最下方、放在「开通登录账号」下面(见文件末尾)。 */ ?>
<input type="hidden" name="id" value="<?= $pid ?>"> <a class="btn btn-ghost btn-sm" href="<?= e(url('people')) ?>">返回</a>
<button class="btn btn-danger btn-sm" type="submit">移除</button>
</form>
<?php endif; ?>
</div> </div>
</div> </div>
@@ -177,7 +174,36 @@ $shortKind = \App\Birthday::KINDS;
<dd><?= e((string)$r['value']) ?></dd> <dd><?= e((string)$r['value']) ?></dd>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
<?php if (!empty($p['org']) || !empty($p['title'])): ?> <?php /* 用户 2026-10-03 第 4 条:工作单位/职务/职称**可以有多段** —— 所以这里列出
完整的"工作经历"(当前那段标「现在」),而不是只显示一个"当前单位"。
⚠️ 老数据(只有 persons.org/title、没有经历行)也要照常显示:
那样的情况下退回显示原来那一行(见下面的 $jobs 为空分支)。 */ ?>
<?php if ($jobs): ?>
<div class="kv-row">
<dt>工作</dt>
<dd>
<ul class="job-history">
<?php foreach ($jobs as $j): ?>
<?php $isNow = ($j['end_ym'] === null || $j['end_ym'] === ''); ?>
<li class="job-history-item">
<?php if ($isNow): ?><span class="node-badge">现在</span><?php endif; ?>
<span class="job-org"><?= e((string)($j['org'] ?? '')) ?></span>
<?php $jt = \App\PersonJob::joinTitle($j['title'] ?? '', $j['rank_name'] ?? ''); ?>
<?php if ($jt !== null): ?><span class="job-title"><?= e($jt) ?></span><?php endif; ?>
<?php if (($j['start_ym'] ?? '') !== '' || ($j['end_ym'] ?? '') !== ''): ?>
<span class="small muted job-span">
<?= e((string)($j['start_ym'] ?? '')) ?> ~ <?= $isNow ? '现在' : e((string)($j['end_ym'] ?? '')) ?>
</span>
<?php endif; ?>
<?php if (($j['note'] ?? '') !== ''): ?>
<span class="small muted">(<?= e((string)$j['note']) ?>)</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</dd>
</div>
<?php elseif (!empty($p['org']) || !empty($p['title'])): ?>
<div class="kv-row"> <div class="kv-row">
<dt>工作</dt> <dt>工作</dt>
<dd><?= e(trim((string)$p['org'] . (($p['org'] ?? '') !== '' && ($p['title'] ?? '') !== '' ? ' · ' : '') . (string)$p['title'])) ?></dd> <dd><?= e(trim((string)$p['org'] . (($p['org'] ?? '') !== '' && ($p['title'] ?? '') !== '' ? ' · ' : '') . (string)$p['title'])) ?></dd>
@@ -198,8 +224,11 @@ $shortKind = \App\Birthday::KINDS;
<dd class="mono"><?= e((string)$r['value']) ?></dd> <dd class="mono"><?= e((string)$r['value']) ?></dd>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
<?php /* 用户 2026-10-03 第 5 条:备注分两种 ——
① 他本人写的「自我介绍」(谁都能看,就是他愿意公开说的那句);
② 我对他的私人备注(**只有我自己看得到**,见下面单独一块)。 */ ?>
<?php if (!empty($p['note'])): ?> <?php if (!empty($p['note'])): ?>
<div class="kv-row"><dt>备注</dt><dd><?= nl2br(e($p['note'])) ?></dd></div> <div class="kv-row"><dt>自我介绍</dt><dd><?= nl2br(e($p['note'])) ?></dd></div>
<?php endif; ?> <?php endif; ?>
<div class="kv-row"> <div class="kv-row">
<dt>最近登录</dt> <dt>最近登录</dt>
@@ -208,6 +237,31 @@ $shortKind = \App\Birthday::KINDS;
</dl> </dl>
</div> </div>
<?php /* ============ 我对他的私人备注(用户 2026-10-03 第 5 条)============
只有**写的人自己**看得到(存在 person_notes,按 viewer 区分)。
⚠️ 不是 person.note —— 那是"他愿意公开说的自我介绍"。
这一块属于"我和他之间的事"(怎么认识的、要注意什么),
所以它只出现在我的视角里,而且别人(包括他本人)看不到。 */ ?>
<?php if (!$isSelf): ?>
<div class="card card-pad my-note-card" style="margin-top:16px">
<h2 class="section-title">
我对 <?= e($pShown) ?> 的备注
<span class="hint">只有我自己看得到</span>
</h2>
<form method="post" action="<?= e(url('people/note')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= $pid ?>">
<label class="sr-only" for="pn-note">我对他的备注</label>
<textarea class="input" id="pn-note" name="note" rows="2"
placeholder="怎么认识的、要注意什么、上次见面聊了什么……"><?= e((string)$myNote) ?></textarea>
<div class="btn-row" style="margin-top:8px">
<button class="btn btn-sm" type="submit">保存备注</button>
<span class="small muted">别人看不到这一栏(包括他本人)</span>
</div>
</form>
</div>
<?php endif; ?>
<!-- ============ 我叫他/她什么(视角属性,只有我自己能改) ============ --> <!-- ============ 我叫他/她什么(视角属性,只有我自己能改) ============ -->
<?php if (!$isSelf): ?> <?php if (!$isSelf): ?>
<div class="card card-pad" style="margin-top:16px"> <div class="card card-pad" style="margin-top:16px">
@@ -507,6 +561,32 @@ $shortKind = \App\Birthday::KINDS;
</div> </div>
</div> </div>
<?php /* ==================== 危险操作:删除(用户 2026-10-03 第 2 条)====================
「删除」从右上角搬到了页面**最下方**、「开通登录账号」下面。
放在最后 + 用 <details> 两步确认:破坏性操作不该一眼就看到、更不该一键完成。
⚠️ 措辞改成了「从名册中删除」并写明会连带删掉什么 ——
原来那句"从名册里移除"听着像"只是从我的名册里移走",
实际会删账号与亲属关系,说法与后果不符。 */ ?>
<?php if ($admin): ?>
<div class="danger-zone">
<details class="del-wrap">
<summary class="link-quiet">删除这个人…</summary>
<div class="del-confirm">
<p class="small muted" style="margin:0 0 8px;flex:1 1 100%">
会把他从名册中删除,**并且**删掉他的登录账号与全部亲属关系连线(不可恢复)。
如果你只是想让他从<b>你的</b>名册里消失,用名册列表上的「⋯ → 从我的名册移走」。
</p>
<form method="post" action="<?= e(url('people/destroy')) ?>"
onsubmit="return confirm('确定要删除 <?= e($p['name']) ?> 吗?账号与亲属关系会一起删掉,无法恢复。')">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= $pid ?>">
<button class="btn btn-danger btn-sm" type="submit">确认删除</button>
</form>
</div>
</details>
</div>
<?php endif; ?>
<script> <script>
// 关系表单的「是哪一位」下拉有**两种含义**: // 关系表单的「是哪一位」下拉有**两种含义**:
// kind=parent → 对方是父亲/母亲(填的是对方) // kind=parent → 对方是父亲/母亲(填的是对方)