Files
2026-08-08 18:28:49 +08:00

80 lines
4.1 KiB
PHP

<?php
$activeMenu = 'employee';
include APP_PATH . 'app/views/layouts/admin_header.php';
?>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><i class="fa fa-user-plus"></i> 添加员工</h3>
</div>
<form method="post" action="">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrfToken); ?>">
<div class="box-body">
<?php if (!empty($error)): ?>
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<div class="form-group">
<label>员工编号 <small class="text-muted">(自动生成)</small></label>
<input type="text" class="form-control" value="<?php echo htmlspecialchars($nextEmpNo); ?>" readonly style="background:#eee;">
</div>
<div class="form-group">
<label>姓名 <span class="text-danger">*</span></label>
<input type="text" name="emp_name" class="form-control" placeholder="如:张三" required>
</div>
<div class="form-group">
<label>密码 <span class="text-danger">*</span></label>
<input type="password" name="password" class="form-control" placeholder="默认密码 123456" value="123456" required>
</div>
<div class="form-group">
<label>权限 <span class="text-danger">*</span></label>
<select name="role" id="roleSelect" class="form-control" onchange="toggleCategory()">
<?php
$roleNames = \core\base\Controller::ROLE_NAMES;
$manageableRoles = $manageableRoles ?? [\core\base\Controller::ROLE_OPERATOR, \core\base\Controller::ROLE_ADMIN];
foreach ($manageableRoles as $r):
?>
<option value="<?php echo $r; ?>"><?php echo htmlspecialchars($roleNames[$r] ?? $r); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group" id="categoryGroup">
<label>管理类目 <span class="text-danger">*</span> <small class="text-muted">(管理员/操作员必须选择单一类目)</small></label>
<select name="category" class="form-control">
<?php
$catNames = \core\base\Controller::CATEGORY_NAMES;
foreach ($catNames as $key => $name):
?>
<option value="<?php echo $key; ?>"><?php echo htmlspecialchars($name); ?></option>
<?php endforeach; ?>
</select>
</div>
<script>
function toggleCategory() {
var role = document.getElementById('roleSelect').value;
var catGroup = document.getElementById('categoryGroup');
if (role === 'super_admin') {
catGroup.style.display = 'none';
} else {
catGroup.style.display = 'block';
}
}
// 页面加载时执行一次
toggleCategory();
</script>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> 保存</button>
<a href="<?php echo BASE_URL; ?>/Admin/employee" class="btn btn-default"><i class="fa fa-arrow-left"></i> 返回</a>
</div>
</form>
</div>
</div>
</div>
<?php include APP_PATH . 'app/views/layouts/admin_footer.php'; ?>