Files
FamilyBook/templates/books/_settings_menu.php
T

49 lines
2.5 KiB
PHP
Raw Normal View History

<?php
/**
* 读书模块的「设置」下拉 —— 统计 / 导入笔记。
*
* 与其它模块同一套规矩(用户 2026-10-01 定的四条):
* ① 按钮**没有文字**、只有图标,图标是**三条横线**;
* ② 排在动作区**最右**(靠 .movie-set 的 margin-left:auto);
* ③ 条目文字前都有图标;
* ④ 除设置外其它按钮都有颜色。
*
* 用法(require 前 set 好):
* $bkSetCurrent 当前页 key('list'|'show'|'form'|'read'|'stats'|'import')
*/
$bkSetCurrent = (string)($bkSetCurrent ?? '');
$bkSetOn = static function (string $key) use ($bkSetCurrent): string {
return $bkSetCurrent === $key ? ' class="on"' : '';
};
$bkSetIcon = static function (string $name): string {
$paths = [
// 统计:柱状图
'stats' => '<path d="M3 13V9M6.5 13V5M10 13V7.5M13.5 13V3"/>',
// 导入笔记:一支笔写在纸上
'import' => '<path d="M9.5 2.5l4 4L5 15H2v-3z"/><path d="M8 4l4 4"/>',
// 微信读书授权(v24 第 24 批):钥匙
'weread' => '<path d="M6.8 9.2a2.6 2.6 0 1 0 0-.1z"/><path d="M8.6 7.4l5-5"/>'
. '<path d="M11.4 4.6l1.5 1.5M12.9 3.1l1.5 1.5"/>',
];
$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.6" stroke-linecap="round"'
. ' stroke-linejoin="round">' . $d . '</svg>';
};
?>
<details class="movie-set menu">
<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">
<a href="<?= e(url('books/stats')) ?>"<?= $bkSetOn('stats') ?>><?= $bkSetIcon('stats') ?><span>读书统计</span></a>
<a href="<?= e(url('books/notes_import')) ?>"<?= $bkSetOn('import') ?>><?= $bkSetIcon('import') ?><span>导入读书笔记</span></a>
<?php /* v24 第 24 批 用户第 5 条:微信读书(官方 API Key 授权,能直接读划线与想法) */ ?>
<a href="<?= e(url('books/weread')) ?>"<?= $bkSetOn('weread') ?>><?= $bkSetIcon('weread') ?><span>微信读书导入</span></a>
</div>
</details>
<?php
// ⚠️ 只 unset **本片段自己**定义的变量(前缀 bkSet*),宿主模板的变量一个都不能碰
unset($bkSetCurrent, $bkSetOn, $bkSetIcon);