2026-10-02 09:28:07 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 资源(v12):挂在某人名下的附属信息(证件、照片、账号…)。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 两条交互上的讲究:
|
|
|
|
|
|
* ① **默认折叠**:一屏几十条正文会很长,列表只露标题行(原生 <details>,
|
|
|
|
|
|
* 没 JS 也能开合),点开才看正文与附件。
|
|
|
|
|
|
* ② **归属于谁**:每条都挂在一个具体的人名下(不是"家庭共享"),
|
|
|
|
|
|
* 所以列表上一定看得到"这是谁的",新建时必须选归属人。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param array $rows 我能看到的资源(带 perm / owner_nick)
|
|
|
|
|
|
* @param array $people 名册(新建时选归属人、共享给别人)
|
|
|
|
|
|
* @param array $attachs resource_id => 附件列表
|
|
|
|
|
|
* @param array $shares resource_id => 共享列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
$isEditing = !empty($editing);
|
|
|
|
|
|
$canWrite = \App\Auth::canWrite();
|
|
|
|
|
|
?>
|
|
|
|
|
|
<div class="page-head">
|
|
|
|
|
|
<h1>资源</h1>
|
|
|
|
|
|
<span class="sub">共 <?= count($rows) ?> 条</span>
|
|
|
|
|
|
<div class="actions">
|
|
|
|
|
|
<?php if ($canWrite): ?>
|
|
|
|
|
|
<button class="btn" type="button" id="resAddBtn"><?= $isEditing ? '收起' : '新建资源' ?></button>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<span class="link-quiet">只读账号</span>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<?php /* v24(用户 2026-10-02 第 18 条):新建资源页去掉「搜索资源」。
|
|
|
|
|
|
资源本来就不多,列表默认折叠、一眼能扫完;搜索框反而把「新建」按钮挤下去了。
|
|
|
|
|
|
真的找不着再靠浏览器的 Ctrl+F,不为一个短列表专门养一套搜索。 */ ?>
|
2026-10-02 09:28:07 +08:00
|
|
|
|
|
|
|
|
|
|
<?php if ($canWrite): ?>
|
|
|
|
|
|
<div class="card card-pad" id="resAddCard" <?= $isEditing ? '' : 'hidden' ?>>
|
|
|
|
|
|
<h2 class="cinema-h2"><?= $isEditing ? '编辑资源' : '新建资源' ?></h2>
|
|
|
|
|
|
<form method="post" enctype="multipart/form-data"
|
|
|
|
|
|
action="<?= e(url($isEditing ? 'resources/update' : 'resources/create')) ?>">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<?php if ($isEditing): ?>
|
|
|
|
|
|
<input type="hidden" name="id" value="<?= (int)$editing['id'] ?>">
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<div class="form-grid">
|
|
|
|
|
|
<div class="field">
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<label>归属于谁 *</label>
|
|
|
|
|
|
<?php /* v24 第 11 条:与全局选人组件统一(原来是下拉,名册一长就难找) */ ?>
|
|
|
|
|
|
<?php
|
|
|
|
|
|
$ppName = 'owner_id';
|
|
|
|
|
|
$ppPeople = $people;
|
|
|
|
|
|
$ppSelected = [(int)($editing['owner_id'] ?? (int)\App\Auth::personId())];
|
|
|
|
|
|
$ppMode = 'single';
|
|
|
|
|
|
$ppOpenBtn = '选择归属人';
|
|
|
|
|
|
$ppTitle = '资源归属于谁';
|
|
|
|
|
|
$ppEmptyText = '未选择';
|
|
|
|
|
|
require __DIR__ . '/../_person_picker.php';
|
|
|
|
|
|
?>
|
2026-10-02 09:28:07 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label for="rs-title">标题 *</label>
|
|
|
|
|
|
<input class="input" id="rs-title" name="title" required
|
|
|
|
|
|
value="<?= e($editing['title'] ?? '') ?>" placeholder="如:身份证 / 学位证">
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field full">
|
|
|
|
|
|
<label for="rs-content">正文</label>
|
|
|
|
|
|
<textarea class="input" id="rs-content" name="content" rows="3"
|
|
|
|
|
|
placeholder="编号、有效期、放在哪里…"><?= e($editing['content'] ?? '') ?></textarea>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field full">
|
|
|
|
|
|
<label for="rs-file">附件(可多选)</label>
|
|
|
|
|
|
<input class="input" type="file" id="rs-file" name="attach[]" multiple>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="btn-row">
|
|
|
|
|
|
<button class="btn" type="submit"><?= $isEditing ? '保存' : '新建' ?></button>
|
|
|
|
|
|
<?php if ($isEditing): ?>
|
|
|
|
|
|
<a class="btn btn-ghost" href="<?= e(url('resources')) ?>">取消</a>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="card card-pad">
|
|
|
|
|
|
<h2 class="cinema-h2">资源列表</h2>
|
|
|
|
|
|
<?php if (!$rows): ?>
|
|
|
|
|
|
<p class="empty-hint">
|
2026-10-03 08:18:05 +08:00
|
|
|
|
还没有资源。证件、照片、账号这些"挂在某人名下的东西"都可以记在这里。
|
2026-10-02 09:28:07 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<div class="res-list">
|
|
|
|
|
|
<?php foreach ($rows as $r): ?>
|
|
|
|
|
|
<?php $rid = (int)$r['id']; $as = $attachs[$rid] ?? []; $sh = $shares[$rid] ?? []; ?>
|
|
|
|
|
|
<details class="res-item">
|
|
|
|
|
|
<summary class="res-head">
|
|
|
|
|
|
<span class="res-title"><?= e((string)$r['title']) ?></span>
|
|
|
|
|
|
<?php /* 归属人标签:查询里"人"的字段没加前缀(owner_name / avatar / avatar_color),
|
|
|
|
|
|
只有昵称带 owner_ 前缀 —— 在这里拼成 person_chip 认的形状。 */ ?>
|
|
|
|
|
|
<?= person_chip([
|
|
|
|
|
|
'id' => (int)$r['owner_id'], 'name' => (string)$r['owner_name'],
|
|
|
|
|
|
'my_nickname' => (string)($r['owner_nick'] ?? ''),
|
|
|
|
|
|
'avatar' => $r['avatar'] ?? null, 'avatar_color' => $r['avatar_color'] ?? null,
|
|
|
|
|
|
]) ?>
|
|
|
|
|
|
<span class="node-badge"><?= e(\App\Resource::permWord((string)$r['perm'])) ?></span>
|
|
|
|
|
|
<?php if ($as): ?><span class="res-n"><?= count($as) ?> 个附件</span><?php endif; ?>
|
|
|
|
|
|
</summary>
|
|
|
|
|
|
<div class="res-body">
|
|
|
|
|
|
<?php if (!empty($r['content'])): ?>
|
|
|
|
|
|
<p class="info-text"><?= nl2br(e((string)$r['content'])) ?></p>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<p class="empty-hint">(没有正文)</p>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
$attRows = $as;
|
|
|
|
|
|
$attCanEdit = $canWrite && \App\Resource::canWrite($r, (int)\App\Auth::personId());
|
|
|
|
|
|
$attDelUrl = 'resources/attach_del';
|
|
|
|
|
|
$attDelField = 'id';
|
|
|
|
|
|
$attExtra = [];
|
|
|
|
|
|
require __DIR__ . '/../_attachments.php';
|
|
|
|
|
|
?>
|
2026-10-02 09:28:07 +08:00
|
|
|
|
|
|
|
|
|
|
<?php if ($sh): ?>
|
|
|
|
|
|
<div class="res-shares">
|
|
|
|
|
|
<span class="res-label">共享给</span>
|
|
|
|
|
|
<?php foreach ($sh as $s): ?>
|
|
|
|
|
|
<?= person_chip($s) ?>
|
|
|
|
|
|
<span class="node-badge"><?= ($s['perm'] ?? '') === 'write' ? '可读写' : '只读' ?></span>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
<?php if ($canWrite && \App\Resource::canWrite($r, (int)\App\Auth::personId())): ?>
|
|
|
|
|
|
<div class="res-ops">
|
|
|
|
|
|
<?php /* 补传附件 / 共享设置 / 编辑 / 删除 —— 每个都是独立的小表单,
|
|
|
|
|
|
不套在别的表单里(<form> 嵌套会让浏览器把外层切开)。 */ ?>
|
|
|
|
|
|
<form class="inline-form" method="post" enctype="multipart/form-data"
|
|
|
|
|
|
action="<?= e(url('resources/attach_add')) ?>">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<input type="hidden" name="id" value="<?= $rid ?>">
|
|
|
|
|
|
<input type="file" name="attach[]" multiple required>
|
|
|
|
|
|
<button class="btn btn-ghost btn-sm" type="submit">补传附件</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
|
<details class="res-share-add">
|
|
|
|
|
|
<summary class="link-quiet">共享设置</summary>
|
|
|
|
|
|
<form class="inline-form" method="post" action="<?= e(url('resources/share')) ?>">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<input type="hidden" name="id" value="<?= $rid ?>">
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
$ppName = 'person_id';
|
|
|
|
|
|
$ppPeople = array_values(array_filter($people,
|
|
|
|
|
|
fn($p) => (int)$p['id'] !== (int)$r['owner_id']));
|
|
|
|
|
|
$ppSelected = [];
|
|
|
|
|
|
$ppMode = 'single';
|
|
|
|
|
|
$ppOpenBtn = '选择要共享给谁';
|
|
|
|
|
|
$ppTitle = '共享给谁';
|
|
|
|
|
|
$ppEmptyText = '未选择';
|
|
|
|
|
|
require __DIR__ . '/../_person_picker.php';
|
|
|
|
|
|
?>
|
2026-10-02 09:28:07 +08:00
|
|
|
|
<select class="select" name="perm">
|
|
|
|
|
|
<option value="read">只读</option>
|
|
|
|
|
|
<option value="write">可读写</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
<button class="btn btn-sm" type="submit">共享</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
<?php foreach ($sh as $s): ?>
|
|
|
|
|
|
<form class="inline-form" method="post" action="<?= e(url('resources/unshare')) ?>">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<input type="hidden" name="id" value="<?= $rid ?>">
|
|
|
|
|
|
<input type="hidden" name="person_id" value="<?= (int)$s['person_id'] ?>">
|
|
|
|
|
|
<span class="cal-share-name"><?= e(person_name($s)) ?></span>
|
|
|
|
|
|
<button class="btn btn-ghost btn-sm" type="submit">取消共享</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
|
<a class="btn btn-ghost btn-sm" href="<?= e(url('resources', ['edit' => $rid])) ?>">编辑</a>
|
|
|
|
|
|
<form method="post" action="<?= e(url('resources/destroy')) ?>"
|
|
|
|
|
|
onsubmit="return confirm('删除「<?= e((string)$r['title']) ?>」?附件会一起删掉。')">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<input type="hidden" name="id" value="<?= $rid ?>">
|
|
|
|
|
|
<button class="btn btn-danger btn-sm" type="submit">删除</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</details>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<?php if ($canWrite): ?>
|
|
|
|
|
|
<script>
|
|
|
|
|
|
(function () {
|
|
|
|
|
|
var btn = document.getElementById('resAddBtn');
|
|
|
|
|
|
var card = document.getElementById('resAddCard');
|
|
|
|
|
|
if (!btn || !card) return;
|
|
|
|
|
|
btn.addEventListener('click', function () {
|
|
|
|
|
|
card.hidden = !card.hidden;
|
|
|
|
|
|
btn.textContent = card.hidden ? '新建资源' : '收起';
|
|
|
|
|
|
if (!card.hidden) { card.scrollIntoView({ block: 'nearest' }); }
|
|
|
|
|
|
});
|
|
|
|
|
|
})();
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<?php endif; ?>
|