127 lines
6.5 KiB
PHP
127 lines
6.5 KiB
PHP
<?php
|
||||
|
|
/**
|
|||
|
|
* 账本模块的「设置」下拉(v24 用户 2026-10-03 第 7 条)
|
|||
|
|
*
|
|||
|
|
* 用户原话:「共享账本,改名等内容,都放在账本的设置中,也是一样的,
|
|||
|
|
* 在新建账目按钮旁边,加一个设置按钮,在里面对账本进行设置、共享等。」
|
|||
|
|
*
|
|||
|
|
* 所以原来那个「共享与账本」大卡片撤了,里面的东西全搬进这个 ☰:
|
|||
|
|
* 共享给谁 / 取消共享 / 账本改名 / 新建账本 / 删除这本账。
|
|||
|
|
* 外观与观影、任务的设置下拉一致(只留图标、排最右、条目带小图标)。
|
|||
|
|
*
|
|||
|
|
* ⚠️⚠️ 本片段是 `require` 进**另一个模板**里的,而 PHP 的 require 共享同一个作用域 ——
|
|||
|
|
* 所以这里**绝不能**定义 / 覆盖 / unset 宿主模板用到的名字(`$canWrite` / `$curId`…)。
|
|||
|
|
* 本条已实测踩到:片段结尾写了 `unset($canWrite, $curId)`,把宿主模板的
|
|||
|
|
* `$canWrite` 一起干掉了 → 后面每一行 `<?php if ($canWrite): ?>` 都变成
|
|||
|
|
* "Undefined variable"(页面在 debug 下会**直接把 Warning 打进正文**,
|
|||
|
|
* 看着像排版坏了一小段,其实是变量被偷走)。
|
|||
|
|
* 同理,_datetime.php 早年在任务页覆盖过 $t —— 同一个坑,别再踩第三次。
|
|||
|
|
* 所以下面所有局部变量一律加 `$ledSet` 前缀,并且只 unset **自己定义**的那些。
|
|||
|
|
*
|
|||
|
|
* 用法(require 前 set 好):
|
|||
|
|
* $cur 当前账本(含 name / my_perm)
|
|||
|
|
* $shares 当前账本的共享列表
|
|||
|
|
* $people 名册(共享给谁)
|
|||
|
|
*/
|
|||
|
|
$ledSetCanWrite = \App\Auth::canWrite() && \App\Ledger::canWrite($cur ?? []);
|
|||
|
|
$ledSetCurId = (int)($cur['id'] ?? 0);
|
|||
|
|
$ledSetIcon = static function (string $name): string {
|
|||
|
|
$paths = [
|
|||
|
|
'share' => '<circle cx="6" cy="6.2" r="2.4"/><circle cx="12.4" cy="9.6" r="2"/><path d="M2.2 13.4c0-1.9 1.7-3 3.8-3s3.8 1.1 3.8 3M9.6 13.4c0-1.5 1.3-2.4 2.8-2.4s2.8.9 2.8 2.4"/>',
|
|||
|
|
'rename'=> '<path d="M2.6 13.4l.6-3 7.4-7.4 2.4 2.4-7.4 7.4zM9.6 4l2.4 2.4"/>',
|
|||
|
|
'add' => '<path d="M8 3.2v9.6M3.2 8h9.6"/>',
|
|||
|
|
'del' => '<path d="M3.4 4.6h9.2M6.6 4.6V3.2h2.8v1.4M4.8 4.6l.7 8.8h5l.7-8.8"/>',
|
|||
|
|
];
|
|||
|
|
$d = $paths[$name] ?? '';
|
|||
|
|
if ($d === '') { return ''; }
|
|||
|
|
return '<svg class="mi" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"'
|
|||
|
|
. ' fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"'
|
|||
|
|
. ' stroke-linejoin="round">' . $d . '</svg>';
|
|||
|
|
};
|
|||
|
|
?>
|
|||
|
|
<details class="movie-set menu led-set">
|
|||
|
|
<summary class="btn btn-icon" title="账本设置" aria-label="账本设置"><svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"><path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/></svg></summary>
|
|||
|
|
<div class="menu-list led-set-list">
|
|||
|
|
|
|||
|
|
<?php if (!$ledSetCanWrite): ?>
|
|||
|
|
<div class="led-set-block">
|
|||
|
|
<p class="small muted" style="margin:0">这本账你只有只读权限,能看不能改。</p>
|
|||
|
|
</div>
|
|||
|
|
<?php else: ?>
|
|||
|
|
|
|||
|
|
<?php /* ---- 共享:给谁 + 权限 + 取消 ---- */ ?>
|
|||
|
|
<div class="led-set-block">
|
|||
|
|
<div class="cal-set-h">共享给谁(对方就能记能看)</div>
|
|||
|
|
<?php if (!empty($shares)): ?>
|
|||
|
|
<ul class="led-set-shares">
|
|||
|
|
<?php foreach ($shares as $s): ?>
|
|||
|
|
<li>
|
|||
|
|
<?= person_chip([
|
|||
|
|
'id' => (int)$s['person_id'], 'name' => (string)$s['name'],
|
|||
|
|
'avatar' => $s['avatar'] ?? null, 'avatar_color' => $s['avatar_color'] ?? null,
|
|||
|
|
]) ?>
|
|||
|
|
<span class="node-badge"><?= ($s['perm'] ?? 'read') === 'write' ? '可写' : '只读' ?></span>
|
|||
|
|
<form method="post" action="<?= e(url('ledger/unshare')) ?>" class="res-inline">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="ledger_id" value="<?= $ledSetCurId ?>">
|
|||
|
|
<input type="hidden" name="person_id" value="<?= (int)$s['person_id'] ?>">
|
|||
|
|
<button class="btn btn-ghost btn-sm" type="submit">取消</button>
|
|||
|
|
</form>
|
|||
|
|
</li>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</ul>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<p class="small muted" style="margin:0 0 6px">还没有共享给任何人。</p>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<form method="post" action="<?= e(url('ledger/share')) ?>" class="led-set-form-in">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="ledger_id" value="<?= $ledSetCurId ?>">
|
|||
|
|
<?php
|
|||
|
|
$ppName = 'person_id';
|
|||
|
|
$ppPeople = $people;
|
|||
|
|
$ppSelected = [];
|
|||
|
|
$ppMode = 'single';
|
|||
|
|
$ppOpenBtn = '选择共享给谁';
|
|||
|
|
$ppTitle = '账本共享给谁';
|
|||
|
|
$ppEmptyText= '未选择';
|
|||
|
|
require __DIR__ . '/../_person_picker.php';
|
|||
|
|
?>
|
|||
|
|
<select class="select" name="perm">
|
|||
|
|
<?php foreach (\App\Ledger::PERM as $pk => $pv): ?>
|
|||
|
|
<option value="<?= e($pk) ?>"><?= e($pv) ?></option>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</select>
|
|||
|
|
<button class="btn btn-sm" type="submit">共享</button>
|
|||
|
|
</form>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<?php /* ---- 改名 ---- */ ?>
|
|||
|
|
<div class="led-set-block">
|
|||
|
|
<div class="cal-set-h">账本名字</div>
|
|||
|
|
<form method="post" action="<?= e(url('ledger/book_rename')) ?>" class="led-set-form-in">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="ledger_id" value="<?= $ledSetCurId ?>">
|
|||
|
|
<input class="input" name="name" value="<?= e((string)($cur['name'] ?? '')) ?>" required>
|
|||
|
|
<button class="btn btn-sm" type="submit">改名</button>
|
|||
|
|
</form>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<?php /* ---- 新建 / 删除 ---- */ ?>
|
|||
|
|
<div class="led-set-block">
|
|||
|
|
<form method="post" action="<?= e(url('ledger/book_add')) ?>" class="led-set-form-in">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input class="input" name="name" placeholder="新账本名,如:孩子的教育金" required>
|
|||
|
|
<button class="btn btn-sm" type="submit">新建账本</button>
|
|||
|
|
</form>
|
|||
|
|
<form method="post" action="<?= e(url('ledger/book_del')) ?>" class="led-set-form-in" style="margin-top:6px">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="ledger_id" value="<?= $ledSetCurId ?>">
|
|||
|
|
<button class="btn btn-ghost btn-sm" type="submit"
|
|||
|
|
onclick="return confirm('删掉这本账?里面的账目会一起删掉。')">删除这本账</button>
|
|||
|
|
</form>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|
|||
|
|
</details>
|
|||
|
|
<?php
|
|||
|
|
unset($ledSetCanWrite, $ledSetCurId, $ledSetIcon);
|