63 lines
3.1 KiB
PHP
63 lines
3.1 KiB
PHP
<?php
|
|||
|
|
/**
|
||
|
|
* 纪念日模块的「设置」下拉(v24 用户 2026-10-03 第 9 条)
|
||
|
|
*
|
||
|
|
* 用户原话:「在新建纪念日和右侧,也增加设置按钮,可以设置纪念日的分类。」
|
||
|
|
*
|
||
|
|
* 分类清单是**家庭级**的(settings.anniv_kinds)—— 全家共用一套叫法,
|
||
|
|
* 不然「结婚纪念日」在两个人屏幕上是两套名字,看的时候对不上。
|
||
|
|
* 所以这里跟「模块主题色」一样:**能改的是所有人**,但改的是同一份。
|
||
|
|
*
|
||
|
|
* 用法(require 前 set 好):
|
||
|
|
* $kinds 当前分类清单
|
||
|
|
* $kindCounts 每个分类用了几条(显示"这个分类有没有在用")
|
||
|
|
*/
|
||
|
|
$daySetKinds = (array)($kinds ?? \App\Anniversary::PRESET_KINDS);
|
||
|
|
$daySetCounts = (array)($kindCounts ?? []);
|
||
|
|
$daySetCanWrite = \App\Auth::canWrite();
|
||
|
|
?>
|
||
|
|
<details class="movie-set menu ann-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 ann-set-list">
|
||
|
|
<div class="cal-set-h">纪念日分类(全家共用一套)</div>
|
||
|
|
|
||
|
|
<?php if (!$daySetKinds): ?>
|
||
|
|
<p class="small muted" style="margin:0 0 8px">一个分类都没有。下面加一个。</p>
|
||
|
|
<?php else: ?>
|
||
|
|
<ul class="ann-kind-list">
|
||
|
|
<?php foreach ($daySetKinds as $k): ?>
|
||
|
|
<li>
|
||
|
|
<span class="ann-kind-name"><?= e((string)$k) ?></span>
|
||
|
|
<span class="small muted"><?= (int)($daySetCounts[(string)$k] ?? 0) ?> 条在用</span>
|
||
|
|
<?php if ($daySetCanWrite): ?>
|
||
|
|
<form method="post" action="<?= e(url('days/kinds')) ?>" class="res-inline">
|
||
|
|
<?= csrf_field() ?>
|
||
|
|
<input type="hidden" name="del" value="<?= e((string)$k) ?>">
|
||
|
|
<button class="btn btn-ghost btn-sm" type="submit"
|
||
|
|
title="删掉这个分类(已用它的纪念日不变)">删</button>
|
||
|
|
</form>
|
||
|
|
<?php endif; ?>
|
||
|
|
</li>
|
||
|
|
<?php endforeach; ?>
|
||
|
|
</ul>
|
||
|
|
<?php endif; ?>
|
||
|
|
|
||
|
|
<?php if ($daySetCanWrite): ?>
|
||
|
|
<form method="post" action="<?= e(url('days/kinds')) ?>" class="led-set-form-in" style="margin-top:8px">
|
||
|
|
<?= csrf_field() ?>
|
||
|
|
<input class="input" name="add" maxlength="20" placeholder="新分类,如:相识纪念日">
|
||
|
|
<button class="btn btn-sm" type="submit">加分类</button>
|
||
|
|
</form>
|
||
|
|
<?php endif; ?>
|
||
|
|
|
||
|
|
<p class="small muted" style="margin:8px 0 0">
|
||
|
|
删掉一个分类**不会**改已用过它的纪念日 —— 只是新建时不再出现在下拉里。
|
||
|
|
</p>
|
||
|
|
</div>
|
||
|
|
</details>
|
||
|
|
<?php
|
||
|
|
// ⚠️ 只 unset **本片段自己定义**的那三个前缀变量。
|
||
|
|
// 绝不能再写 `unset($kinds, $kindCounts, $canWrite)` —— days/index.php 里
|
||
|
|
// 同样有 $canWrite(还有 $kinds),那样会把宿主模板的变量一起干掉,
|
||
|
|
// 后面每一处用到的地方都变成 Undefined variable(账本那个片段刚这么炸过一次)。
|
||
|
|
unset($daySetKinds, $daySetCounts, $daySetCanWrite);
|