Files
laysite/app/view/studio-media.php
T

54 lines
3.6 KiB
PHP

<?php
use App\Content\View;
$e = View::escape(...);
?>
<header class="admin-heading"><div><h1>媒体库</h1><p>统一查找并引用静态文件、图片、图标和音视频。</p></div></header>
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
<form class="admin-form admin-panel" method="post" action="/admin/media" enctype="multipart/form-data">
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
<div class="form-grid media-upload-fields">
<label>文件<input type="file" name="file" accept="image/*,video/*,audio/*,.pdf,.woff,.woff2" required>
<small>支持常见图片、SVG 图标、音视频、PDF、WOFF/WOFF2,单文件最大 64 MB。</small>
</label>
<label>资源名称<input name="label" maxlength="160" placeholder="默认使用文件名"></label>
</div>
<div class="form-submit"><button type="submit" class="button button-primary">上传文件</button></div>
</form>
<section class="admin-panel media-library" data-media-library aria-labelledby="library-heading">
<h2 id="library-heading">资源列表</h2>
<div class="form-grid admin-form media-filters">
<label>搜索<input type="search" data-library-query placeholder="搜索名称或路径"></label>
<label>类型<select data-library-type><option value="">全部资源</option><option value="image/">图片与图标</option><option value="video/">视频</option><option value="audio/">音频</option><option value="other">其他文件</option></select></label>
</div>
<p data-library-count role="status"></p>
<div class="media-grid">
<?php foreach ($files as $file): ?>
<article class="media-card" data-library-card data-mime="<?= $e($file['mime']) ?>" data-search="<?= $e($file['label'] . ' ' . $file['url']) ?>">
<?php if (str_starts_with($file['mime'], 'image/')): ?>
<img src="<?= $e($file['url']) ?>" alt="" loading="lazy">
<?php else: ?>
<p class="media-file-type"><?= $e(strtolower(pathinfo($file['url'], PATHINFO_EXTENSION))) ?></p>
<?php endif ?>
<h3><?= $e($file['label']) ?></h3>
<small><?= $e((string) max(1, ceil($file['size'] / 1024))) ?> KB · <?= $file['name'] === '' ? '项目文件' : ($file['archived'] ? '已归档' : '上传文件') ?></small>
<div class="actions">
<?= View::fragment('admin-view-link', ['href' => $file['url'], 'icon' => 'external', 'label' => '打开媒体文件']) ?>
<button type="button" class="button button-outline" data-copy-asset="<?= $e($file['url']) ?>">复制路径</button>
</div>
<?php if ($file['name'] !== ''): ?>
<details><summary>管理文件</summary>
<form class="admin-form" method="post" action="/admin/media/<?= $e($file['name']) ?>">
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
<label>名称<input name="label" value="<?= $e($file['label']) ?>" maxlength="160" required></label>
<label class="media-archive"><input type="checkbox" name="archived" value="1" <?= $file['archived'] ? 'checked' : '' ?>>归档</label>
<small>归档从选取器隐藏文件,已有链接仍可访问。</small>
<button type="submit" class="button button-outline">保存</button>
</form>
</details>
<?php endif ?>
</article>
<?php endforeach ?>
</div>
</section>