update admin

This commit is contained in:
2026-05-06 19:10:27 +08:00
parent e24b41f53c
commit e8f36222e7
25 changed files with 1103 additions and 354 deletions
@@ -0,0 +1,82 @@
<#import "admin-shell.ftl" as shell>
<@shell.page title="后台管理 - 用户与角色" active=active adminName=adminName>
<h2 class="ui header">用户与角色管理</h2>
<p class="small-muted">简单 RBAC:用户可绑定多个角色,拥有 ADMIN 角色的用户可以进入后台管理。</p>
<h3 class="ui dividing header">角色管理</h3>
<form class="ui form" method="post" action="/admin/roles">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="three fields">
<div class="field"><label>角色编码</label><input name="code" placeholder="如 ADMIN_AUDIT" required></div>
<div class="field"><label>角色名称</label><input name="name" placeholder="如 审计管理员" required></div>
<div class="field"><label>描述</label><input name="description" placeholder="角色用途说明"></div>
</div>
<button class="ui small primary button" type="submit">新增角色</button>
</form>
<table class="ui celled compact table">
<thead><tr><th>ID</th><th>编码</th><th>名称</th><th>状态</th><th>操作</th></tr></thead>
<tbody>
<#list roles as r>
<tr>
<td>${r.id}</td>
<td>${r.code!""}</td>
<td>${r.name!""}</td>
<td><#if r.enabled?? && r.enabled==1>启用<#else>停用</#if></td>
<td>
<form style="display:inline" method="post" action="/admin/roles/${r.id}/toggle">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<button class="ui tiny button" type="submit">切换启停</button>
</form>
</td>
</tr>
</#list>
</tbody>
</table>
<h3 class="ui dividing header">用户角色绑定</h3>
<table class="ui celled table">
<thead>
<tr>
<th>ID</th>
<th>用户名</th>
<th>邮箱</th>
<th>角色绑定</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<#list users as u>
<tr>
<td>${u.id}</td>
<td>${u.username!""}</td>
<td>${u.email!""}</td>
<td>
<form class="ui form" method="post" action="/admin/users/${u.id}/roles">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="inline fields">
<#list roles as r>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="roleIds" value="${r.id}"
<#if userRoleIds[u.id]?? && userRoleIds[u.id]?seq_contains(r.id)>checked</#if>>
<label>${r.code}</label>
</div>
</div>
</#list>
</div>
<button class="ui tiny primary button" type="submit">保存角色</button>
</form>
</td>
<td>
<a class="ui tiny button" href="/user?id=${u.id}" target="_blank">查看用户页</a>
</td>
</tr>
</#list>
</tbody>
</table>
<script>
$('.ui.checkbox').checkbox();
</script>
</@shell.page>