83 lines
4.2 KiB
HTML
83 lines
4.2 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}{{ role.id is defined and role.id is not none and '编辑角色' or '添加角色' }} - 学生课程管理系统{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container-fluid py-4">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<div class="card shadow">
|
|
<div class="card-header bg-primary text-white">
|
|
<h5 class="mb-0">{{ role.id is defined and role.id is not none and '编辑角色' or '添加角色' }}</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="POST">
|
|
<div class="mb-3">
|
|
<label class="form-label">角色名称 <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" name="name" value="{{ role.name if role else '' }}" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">角色权限</label>
|
|
<div class="border rounded p-3 bg-light">
|
|
<!-- 全选/取消 按钮 -->
|
|
<div class="mb-3 d-flex gap-2">
|
|
<button type="button" class="btn btn-sm btn-outline-primary" onclick="checkAll(true)">全选</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="checkAll(false)">取消全选</button>
|
|
<button type="button" class="btn btn-sm btn-outline-info" onclick="checkViewAll(true)">仅选查看</button>
|
|
</div>
|
|
|
|
{% set role_permissions = role.permissions.split(',') if role and role.permissions else [] %}
|
|
|
|
{% for module_key, module_info in PERMISSIONS.items() %}
|
|
<div class="mb-3 border-bottom pb-2">
|
|
<strong class="text-primary">{{ module_info.label }}</strong>
|
|
<div class="ms-3 mt-1 d-flex flex-wrap gap-3">
|
|
{% for perm_key, perm_label in module_info.permissions.items() %}
|
|
<div class="form-check">
|
|
<input class="form-check-input perm-checkbox" type="checkbox"
|
|
name="permissions" value="{{ perm_key }}"
|
|
id="perm_{{ perm_key }}"
|
|
{{ 'checked' if perm_key in role_permissions }}>
|
|
<label class="form-check-label" for="perm_{{ perm_key }}">
|
|
{{ perm_label }}
|
|
</label>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">备注</label>
|
|
<textarea class="form-control" name="remark" rows="2">{{ role.remark if role and role.remark else '' }}</textarea>
|
|
</div>
|
|
|
|
<div class="d-flex gap-2">
|
|
<button type="submit" class="btn btn-primary">保存</button>
|
|
<a href="{{ url_for('role_list') }}" class="btn btn-secondary">取消</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function checkAll(checked) {
|
|
document.querySelectorAll('.perm-checkbox').forEach(cb => cb.checked = checked);
|
|
}
|
|
|
|
function checkViewAll(checked) {
|
|
document.querySelectorAll('.perm-checkbox').forEach(cb => {
|
|
if (cb.value.endsWith('_view')) {
|
|
cb.checked = checked;
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
{% endblock %}
|