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