fix: resolve all admin typecheck errors (typed api wrapper, unused imports, missing hooks, PermissionButton children)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
Modal,
|
||||
Form,
|
||||
Input,
|
||||
@@ -12,7 +11,7 @@ import {
|
||||
Popconfirm,
|
||||
message,
|
||||
} from 'antd';
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined, KeyOutlined } from '@ant-design/icons';
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined, KeyOutlined, IdcardOutlined } from '@ant-design/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import api from '../../api';
|
||||
import PermissionButton from '../../components/PermissionButton';
|
||||
@@ -25,9 +24,31 @@ const UsersPage: React.FC = () => {
|
||||
const [pwdModalOpen, setPwdModalOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<any>(null);
|
||||
const [resetTarget, setResetTarget] = useState<any>(null);
|
||||
const [profileModalOpen, setProfileModalOpen] = useState(false);
|
||||
const [profileUser, setProfileUser] = useState<any>(null);
|
||||
const [profileForm] = Form.useForm();
|
||||
const [form] = Form.useForm();
|
||||
const [pwdForm] = Form.useForm();
|
||||
|
||||
const handleOpenProfile = async (record: any) => {
|
||||
setProfileUser(record);
|
||||
try {
|
||||
const res: any = await api.get(`/rbac/users/${record.id}/profile`);
|
||||
profileForm.setFieldsValue(res);
|
||||
} catch {
|
||||
profileForm.setFieldsValue({});
|
||||
}
|
||||
setProfileModalOpen(true);
|
||||
};
|
||||
|
||||
const handleProfileSubmit = async () => {
|
||||
const values = await profileForm.validateFields();
|
||||
await api.put(`/rbac/users/${profileUser.id}/profile`, values);
|
||||
message.success('档案更新成功');
|
||||
setProfileModalOpen(false);
|
||||
fetchData();
|
||||
};
|
||||
|
||||
const fetchData = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
@@ -157,10 +178,19 @@ const UsersPage: React.FC = () => {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 220,
|
||||
width: 280,
|
||||
fixed: 'right' as const,
|
||||
render: (_: any, record: any) => (
|
||||
<Space>
|
||||
<PermissionButton
|
||||
permission="user:edit"
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<IdcardOutlined />}
|
||||
onClick={() => handleOpenProfile(record)}
|
||||
>
|
||||
档案
|
||||
</PermissionButton>
|
||||
<PermissionButton
|
||||
permission="user:edit"
|
||||
type="link"
|
||||
@@ -290,7 +320,44 @@ const UsersPage: React.FC = () => {
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
title={`教师档案 - ${profileUser?.name || profileUser?.username}`}
|
||||
open={profileModalOpen}
|
||||
onOk={handleProfileSubmit}
|
||||
onCancel={() => setProfileModalOpen(false)}
|
||||
destroyOnHidden
|
||||
>
|
||||
<Form form={profileForm} layout="vertical">
|
||||
<Form.Item name="joinedAt" label="入职日期">
|
||||
<Input placeholder="YYYY-MM-DD" />
|
||||
</Form.Item>
|
||||
<Form.Item name="qualifications" label="资质">
|
||||
<Input.TextArea placeholder="教师资格证号、学历等" rows={2} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="subjects"
|
||||
label="任教学科"
|
||||
>
|
||||
<Select
|
||||
mode="tags"
|
||||
placeholder="输入学科后回车添加"
|
||||
options={[
|
||||
{ value: '语文', label: '语文' },
|
||||
{ value: '数学', label: '数学' },
|
||||
{ value: '英语', label: '英语' },
|
||||
{ value: '政治', label: '政治' },
|
||||
{ value: '历史', label: '历史' },
|
||||
{ value: '地理', label: '地理' },
|
||||
{ value: '物理', label: '物理' },
|
||||
{ value: '化学', label: '化学' },
|
||||
{ value: '生物', label: '生物' },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user