初始化
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
@extends('admin.layout')
|
||||
|
||||
@section('title', '新建用户')
|
||||
@section('page-title', '新建用户')
|
||||
|
||||
@section('content')
|
||||
<div class="card" style="max-width: 760px;">
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ route('admin.users.store') }}">
|
||||
@csrf
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">姓名</label>
|
||||
<input type="text" name="name" value="{{ old('name') }}" class="input" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">邮箱(登录账号)</label>
|
||||
<input type="email" name="email" value="{{ old('email') }}" class="input" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">初始密码</label>
|
||||
<input type="password" name="password" class="input" required autocomplete="new-password">
|
||||
<p class="role-hint">至少 8 位。创建后可在用户编辑页随时重置。</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">角色</label>
|
||||
<select name="role" id="role-select" class="input">
|
||||
@foreach ($roles as $key => $cfg)
|
||||
<option value="{{ $key }}"
|
||||
{{ old('role', 'staff') === $key ? 'selected' : '' }}
|
||||
@if ($key === 'super_admin' && ! auth()->user()->isSuperAdmin()) disabled @endif>
|
||||
{{ $cfg['label'] }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<p class="role-hint">
|
||||
@if (! auth()->user()->isSuperAdmin())
|
||||
只能创建权限低于自身的角色;超级管理员角色仅限超级管理员创建。
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{{-- 内部员工:细粒度勾选 --}}
|
||||
<div id="perm-section" class="perm-group" @if (old('role', 'staff') !== 'staff') style="display:none;" @endif>
|
||||
<div class="perm-group-title">内部员工权限分配</div>
|
||||
<p class="role-hint">勾选该员工可执行的权限点,未勾选则无对应后台访问权。</p>
|
||||
@foreach ($groups as $gKey => $gLabel)
|
||||
<div class="perm-group" style="margin-bottom: var(--space-3);">
|
||||
<div class="perm-group-title">{{ $gLabel }}</div>
|
||||
<div class="perm-list">
|
||||
@foreach ($permissions as $permKey => $permCfg)
|
||||
@if ($permCfg['group'] === $gKey)
|
||||
<label class="perm-item">
|
||||
<input type="checkbox" name="permissions[]" value="{{ $permKey }}"
|
||||
{{ in_array($permKey, old('permissions', []), true) ? 'checked' : '' }}>
|
||||
{{ $permCfg['label'] }}
|
||||
</label>
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
<div class="row-actions" style="margin-top: var(--space-5);">
|
||||
<button type="submit" class="btn btn-primary">创建用户</button>
|
||||
<a href="{{ route('admin.users.index') }}" class="btn">返回</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var sel = document.getElementById('role-select');
|
||||
var sec = document.getElementById('perm-section');
|
||||
function sync() {
|
||||
sec.style.display = (sel.value === 'staff') ? '' : 'none';
|
||||
}
|
||||
sel.addEventListener('change', sync);
|
||||
sync();
|
||||
})();
|
||||
</script>
|
||||
@endsection
|
||||
@@ -0,0 +1,143 @@
|
||||
@extends('admin.layout')
|
||||
|
||||
@section('title', '编辑用户 - ' . $user->name)
|
||||
@section('page-title', '编辑用户:' . $user->name)
|
||||
|
||||
@section('content')
|
||||
<div class="card" style="max-width: 760px;">
|
||||
<div class="card-body">
|
||||
<div class="muted" style="margin-bottom: var(--space-4);">
|
||||
邮箱:{{ $user->email }}
|
||||
@if ($user->id === request()->user()->id)
|
||||
<span class="badge badge-role-user">当前账号</span>
|
||||
@endif
|
||||
<span class="badge badge-role-{{ $user->role }}">{{ $user->roleLabel() }}</span>
|
||||
</div>
|
||||
|
||||
@if (! $canManage)
|
||||
<div class="alert alert-warning">您的权限不高于该用户,无法修改其角色、权限或密码。</div>
|
||||
@endif
|
||||
|
||||
{{-- 角色 / 权限(仅具备分配权限且层级更高者可改) --}}
|
||||
@if ($canManage && auth()->user()->canPerm('users.assign_role'))
|
||||
<form method="POST" action="{{ route('admin.users.update', $user) }}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">角色</label>
|
||||
<select name="role" id="role-select" class="input">
|
||||
@foreach ($roles as $key => $cfg)
|
||||
<option value="{{ $key }}"
|
||||
{{ $user->role === $key ? 'selected' : '' }}
|
||||
@if ($key === 'super_admin' && ! request()->user()->isSuperAdmin()) disabled @endif>
|
||||
{{ $cfg['label'] }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<p class="role-hint">
|
||||
@if (! request()->user()->isSuperAdmin())
|
||||
超级管理员角色仅限超级管理员分配;您只能分配权限低于自身的角色。
|
||||
@else
|
||||
不同角色拥有不同的后台视图与权限,下方将实时显示该角色的默认权限。
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{{-- 各角色默认权限(只读,前端按所选角色切换显隐) --}}
|
||||
<div id="role-defaults">
|
||||
@foreach ($roles as $key => $cfg)
|
||||
<div class="perm-group role-default" data-role="{{ $key }}"
|
||||
style="background: var(--color-surface); {{ $user->role === $key ? '' : 'display:none;' }}">
|
||||
<div class="perm-group-title">{{ $cfg['label'] }} · 默认权限</div>
|
||||
<div class="perm-list">
|
||||
@if (($cfg['permissions'] ?? []) === ['*'])
|
||||
<div class="perm-item"><x-icon name="lock" :size="16"/> 全部权限(超级管理员)</div>
|
||||
@elseif (empty($cfg['permissions'] ?? []))
|
||||
<div class="perm-item muted">无(注册用户 / 待分配)</div>
|
||||
@else
|
||||
@foreach ($cfg['permissions'] as $p)
|
||||
<div class="perm-item"><x-icon name="check" :size="16"/> {{ $permissions[$p]['label'] ?? $p }}</div>
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
{{-- 内部员工:细粒度勾选 --}}
|
||||
<div id="perm-section" class="perm-group" @if ($user->role !== 'staff') style="display:none;" @endif>
|
||||
<div class="perm-group-title">内部员工权限分配</div>
|
||||
<p class="role-hint">勾选该员工可执行的权限点,未勾选则无对应后台访问权。</p>
|
||||
@foreach ($groups as $gKey => $gLabel)
|
||||
<div class="perm-group" style="margin-bottom: var(--space-3);">
|
||||
<div class="perm-group-title">{{ $gLabel }}</div>
|
||||
<div class="perm-list">
|
||||
@foreach ($permissions as $permKey => $permCfg)
|
||||
@if ($permCfg['group'] === $gKey)
|
||||
<label class="perm-item">
|
||||
<input type="checkbox" name="permissions[]" value="{{ $permKey }}"
|
||||
{{ in_array($permKey, $userPerms, true) ? 'checked' : '' }}>
|
||||
{{ $permCfg['label'] }}
|
||||
</label>
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
<div class="row-actions" style="margin-top: var(--space-5);">
|
||||
<button type="submit" class="btn btn-primary">保存角色与权限</button>
|
||||
<a href="{{ route('admin.users.index') }}" class="btn">返回</a>
|
||||
</div>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
{{-- 重置密码(仅具备重置权限且层级更高者可操作) --}}
|
||||
@if ($canManage && auth()->user()->canPerm('users.reset_password'))
|
||||
<hr style="margin: var(--space-6) 0; border-color: var(--color-border);">
|
||||
<div id="reset-password" class="perm-group">
|
||||
<div class="perm-group-title">重置密码</div>
|
||||
<p class="role-hint">可指定一个新密码,或留空由系统生成 12 位随机密码(生成后请妥善告知用户)。</p>
|
||||
<form method="POST" action="{{ route('admin.users.reset-password', $user) }}" class="space-y-4">
|
||||
@csrf
|
||||
<div class="form-group">
|
||||
<label class="form-label">新密码(可选)</label>
|
||||
<input type="password" name="password" class="input" autocomplete="new-password" placeholder="留空则生成随机密码">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">确认新密码</label>
|
||||
<input type="password" name="password_confirmation" class="input" autocomplete="new-password">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">重置密码</button>
|
||||
</form>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if ($canManage && auth()->user()->canPerm('users.assign_role'))
|
||||
<script>
|
||||
(function () {
|
||||
var sel = document.getElementById('role-select');
|
||||
var defaults = document.querySelectorAll('#role-defaults .role-default');
|
||||
var sec = document.getElementById('perm-section');
|
||||
function sync() {
|
||||
var v = sel.value;
|
||||
if (v === 'staff') {
|
||||
sec.style.display = '';
|
||||
defaults.forEach(function (el) { el.style.display = 'none'; });
|
||||
} else {
|
||||
sec.style.display = 'none';
|
||||
defaults.forEach(function (el) {
|
||||
el.style.display = (el.getAttribute('data-role') === v) ? '' : 'none';
|
||||
});
|
||||
}
|
||||
}
|
||||
sel.addEventListener('change', sync);
|
||||
sync();
|
||||
})();
|
||||
</script>
|
||||
@endif
|
||||
@endsection
|
||||
@@ -0,0 +1,58 @@
|
||||
@extends('admin.layout')
|
||||
|
||||
@section('title', '用户管理')
|
||||
@section('page-title', '用户管理')
|
||||
|
||||
@section('actions')
|
||||
@canPerm('users.create')
|
||||
<a href="{{ route('admin.users.create') }}" class="btn btn-primary"><x-icon name="plus" :size="16"/> 新建用户</a>
|
||||
@endcanPerm
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<form method="GET" class="filter-bar">
|
||||
<input type="text" name="q" value="{{ $q }}" class="input" placeholder="搜索姓名、邮箱...">
|
||||
<button type="submit" class="btn btn-primary">查询</button>
|
||||
</form>
|
||||
|
||||
<table class="data-table" style="margin-top:16px;">
|
||||
<thead><tr><th>姓名</th><th>邮箱</th><th>角色</th><th>积分 / 等级</th><th class="col-op">操作</th></tr></thead>
|
||||
<tbody>
|
||||
@forelse ($users as $u)
|
||||
@php
|
||||
$me = auth()->user();
|
||||
$canManage = $me->isSuperAdmin() || $me->roleLevel() > $u->roleLevel();
|
||||
@endphp
|
||||
<tr>
|
||||
<td>{{ $u->name }}</td>
|
||||
<td>{{ $u->email }}</td>
|
||||
<td>
|
||||
<span class="badge badge-role-{{ $u->role }}">{{ $u->roleLabel() }}</span>
|
||||
@if ($u->id === $me->id)<span class="muted">(当前)</span>@endif
|
||||
</td>
|
||||
<td class="muted">{{ $u->points ?? 0 }} · L{{ $u->level() }}</td>
|
||||
<td class="row-actions">
|
||||
@if ($canManage)
|
||||
@canPerm('users.assign_role')
|
||||
<a href="{{ route('admin.users.edit', $u) }}" class="btn btn-sm"><x-icon name="edit" :size="16"/> 角色/权限</a>
|
||||
@endcanPerm
|
||||
@canPerm('users.reset_password')
|
||||
<a href="{{ route('admin.users.edit', $u) }}#reset-password" class="btn btn-sm"><x-icon name="lock" :size="16"/> 重置密码</a>
|
||||
@endcanPerm
|
||||
@else
|
||||
<span class="muted">无权操作</span>
|
||||
@endif
|
||||
@canPerm('users.delete')
|
||||
@if ($canManage && $u->id !== $me->id)
|
||||
<form method="POST" action="{{ route('admin.users.destroy', $u) }}" onsubmit="return confirm('确认删除该用户?')">@csrf @method('DELETE')<button class="btn btn-sm btn-danger"><x-icon name="trash" :size="16"/></button></form>
|
||||
@endif
|
||||
@endcanPerm
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="5" class="muted">暂无用户。</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
{{ $users->links('pagination::bootstrap-5') }}
|
||||
@endsection
|
||||
Reference in New Issue
Block a user