From 2aaabce8e309c80c5067e8d659cb958ca49858ef Mon Sep 17 00:00:00 2001 From: laoyang Date: Tue, 29 Sep 2026 22:34:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8A=82=E7=82=B9=E8=A1=A8=E5=8D=95=E5=86=85?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BF=AB=E6=8D=B7=E6=96=B0=E5=BB=BA=E5=8F=82?= =?UTF-8?q?=E4=B8=8E=E4=BA=BA=E6=88=90=E5=91=98=EF=BC=88=E6=89=B9=2029?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/style.css | 9 ++++ index.php | 1 + src/Controllers/UserController.php | 40 +++++++++++++++ templates/nodes/form.php | 78 ++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) diff --git a/assets/style.css b/assets/style.css index 86a823f..6cacd4b 100644 --- a/assets/style.css +++ b/assets/style.css @@ -1321,6 +1321,15 @@ video.video-thumb.video-thumb-mini { .member-pick-avatar { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; display: block; } +/* 快捷新建成员(批 29):参与人勾选区下的一行「名字输入 + 新建」 */ +.member-quickadd { + display: flex; align-items: center; gap: 8px; flex-wrap: wrap; + margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); +} +.member-quickadd input[type="text"] { flex: 1 1 200px; min-width: 0; } +.member-quickadd-msg { font-size: 12.5px; } +.member-quickadd-msg.is-ok { color: var(--ok, #1a7f37); } +.member-quickadd-msg.is-err { color: var(--danger, #c62828); } /* 联想选中后回填的详细地址(让人看见记下来的是什么) */ .loc-detail { margin-top: 6px; font-size: 12.5px; word-break: break-all; } diff --git a/index.php b/index.php index 4fa0c7d..324a423 100644 --- a/index.php +++ b/index.php @@ -145,6 +145,7 @@ $map = [ 'users/index' => [UserController::class, 'index'], 'users/create' => [UserController::class, 'create'], 'users/store' => [UserController::class, 'store'], + 'users/quickCreate' => [UserController::class, 'quickCreate'], 'users/edit' => [UserController::class, 'edit'], 'users/update' => [UserController::class, 'update'], 'users/destroy' => [UserController::class, 'destroy'], diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index a058a8c..fffabbc 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -100,6 +100,46 @@ class UserController redirect('users/index'); } + /** + * 节点表单内「快捷新建成员」(批 29):只填名字,建一个 guest 成员,JSON 应答。 + * 手机号 / 密码 / 头像都不收 —— 需要时去「成员管理」完善。AJAX 专用,不做页面跳转。 + */ + public function quickCreate(): void + { + $this->requireAdmin(); + csrf_check(); + + header('Content-Type: application/json; charset=utf-8'); + + $db = Database::get(); + $familyId = Auth::familyId(); + $name = trim((string)($_POST['name'] ?? '')); + + $fail = static function (int $code, string $error): void { + http_response_code($code); + echo json_encode(['ok' => false, 'error' => $error], JSON_UNESCAPED_UNICODE); + exit; + }; + if ($name === '') { + $fail(422, '名字不能为空'); + } + if (mb_strlen($name) > 50) { + $fail(422, '名字太长(最多 50 字)'); + } + $chk = $db->prepare('SELECT id FROM users WHERE family_id = ? AND name = ? LIMIT 1'); + $chk->execute([$familyId, $name]); + if ($chk->fetch()) { + $fail(409, '已有同名成员(直接勾选即可)'); + } + + $stmt = $db->prepare('INSERT INTO users (family_id, name) VALUES (?, ?)'); + $stmt->execute([$familyId, $name]); + + echo json_encode(['ok' => true, 'id' => (int)$db->lastInsertId(), 'name' => $name], + JSON_UNESCAPED_UNICODE); + exit; + } + public function edit(): void { $id = (int)($_GET['id'] ?? 0); diff --git a/templates/nodes/form.php b/templates/nodes/form.php index 3e90ffb..b2db086 100644 --- a/templates/nodes/form.php +++ b/templates/nodes/form.php @@ -257,6 +257,18 @@ $tripField = [

勾选后保存即生效;已选的人重新勾选不会清掉之前记的签到 / 心情。

+ + + +
+ + + +
+