update: role_code
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { ApiRequestError, type Employee } from "../../services/api";
|
||||
import { ApiRequestError, type Employee, type Role } from "../../services/api";
|
||||
import { useApi, useAuth } from "../../context/AuthContext";
|
||||
import Icon from "../../components/common/Icon";
|
||||
import {
|
||||
@@ -39,6 +39,7 @@ export function UserManagementPage({
|
||||
const api = useApi();
|
||||
const { user } = useAuth();
|
||||
const [employees, setEmployees] = useState<Employee[]>([]);
|
||||
const [roles, setRoles] = useState<Role[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [editing, setEditing] = useState<Employee | null>(null);
|
||||
@@ -51,7 +52,12 @@ export function UserManagementPage({
|
||||
const load = async (): Promise<void> => {
|
||||
setLoading(true);
|
||||
try {
|
||||
setEmployees(await api.listPlatformEmployees());
|
||||
const [employeeList, roleList] = await Promise.all([
|
||||
api.listPlatformEmployees(),
|
||||
api.listPlatformRoles(),
|
||||
]);
|
||||
setEmployees(employeeList);
|
||||
setRoles(roleList);
|
||||
onConnectionChange(true);
|
||||
} catch (error) {
|
||||
onConnectionChange(false);
|
||||
@@ -95,7 +101,7 @@ export function UserManagementPage({
|
||||
onNotify({ tone: "error", message: "请输入密码" });
|
||||
return;
|
||||
}
|
||||
// 编辑自身或管理员时,前端二次拦截禁用 status / role_code 的修改
|
||||
// 编辑自身时,前端二次拦截禁用 status / role_code 的修改;管理员账号禁止停用/锁定
|
||||
if (editing) {
|
||||
const editingSelf = editing.user_id === user?.user_id;
|
||||
const targetIsAdmin = editing.role_code === "admin";
|
||||
@@ -107,10 +113,6 @@ export function UserManagementPage({
|
||||
onNotify({ tone: "error", message: "不能停用或锁定管理员账号" });
|
||||
return;
|
||||
}
|
||||
if (targetIsAdmin && form.role_code !== editing.role_code) {
|
||||
onNotify({ tone: "error", message: "不能降级管理员账号" });
|
||||
return;
|
||||
}
|
||||
if (editingSelf && form.role_code !== editing.role_code) {
|
||||
onNotify({ tone: "error", message: "不能降级自身管理员角色" });
|
||||
return;
|
||||
@@ -286,6 +288,27 @@ export function UserManagementPage({
|
||||
placeholder="请输入邮箱(可选)"
|
||||
/>
|
||||
</label>
|
||||
{editing && (
|
||||
<label className={formFieldClass}>
|
||||
<span>角色</span>
|
||||
<select
|
||||
className={formInputClass}
|
||||
value={form.role_code}
|
||||
disabled={editing.user_id === user?.user_id || roles.length === 0}
|
||||
onChange={(event) => setForm({ ...form, role_code: event.target.value as typeof form.role_code })}
|
||||
>
|
||||
{roles.length === 0 ? (
|
||||
<option value="" disabled>加载中…</option>
|
||||
) : (
|
||||
roles.map((role) => (
|
||||
<option key={role.role_code} value={role.role_code}>
|
||||
{role.role_name}
|
||||
</option>
|
||||
))
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{editing && (
|
||||
<label className={formFieldClass}>
|
||||
<span>状态</span>
|
||||
|
||||
Reference in New Issue
Block a user