"use client"; import { DeleteOutlined, EditOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { Button, Divider, message, Drawer, Modal } from 'antd'; import React, { useState, useRef } from 'react'; import { PageContainer, FooterToolbar } from '@ant-design/pro-layout'; import ProTable from '@ant-design/pro-table'; import type { ProColumns, ActionType } from '@ant-design/pro-table'; import ProDescriptions from '@ant-design/pro-descriptions'; import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; // import CreateUserForm from './components/CreateUserForm'; // import UpdateUserForm from './components/UpdateUserForm'; // import type { UserInfo, UserListItem } from './data.d'; // import { // queryUserList, // updateUser, // addUser, // removeUser, // } from './service'; import md5 from 'md5'; import { UserInfo, UserListItem, queryUserList } from '@/lib/http/staff'; import Link from 'next/link'; const { confirm } = Modal; /** * 添加节点 * @param fields */ const handleAdd = async (fields: UserInfo) => { const hide = message.loading('正在添加'); try { fields.password = md5(fields.password) fields.user_alias = fields.user_name console.log("----------:", fields) // await addUser({ ...fields }); hide(); message.success('添加成功'); return true; } catch (error) { hide(); message.error('添加失败请重试!'); return false; } }; /** * 更新节点 * @param fields */ const handleUpdate = async (fields: UserInfo) => { const hide = message.loading('正在更新'); try { // fields.deptId = Number(fields.deptId) fields.password = md5(fields.password) // await updateUser(fields); hide(); message.success('更新成功'); return true; } catch (error) { hide(); message.error('更新失败请重试!'); return false; } }; /** * 删除节点 * @param selectedRows */ const handleRemove = async (selectedRows: UserListItem[]) => { const hide = message.loading('正在删除'); if (!selectedRows) return true; console.log("------>", selectedRows) try { // await removeUser({ // user_name: selectedRows.map((row) => row.user_name), // }); hide(); message.success('删除成功,即将刷新'); return true; } catch (error) { hide(); message.error('删除失败,请重试'); return false; } }; const UserList: React.FC = () => { const [createModalVisible, handleModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = useState(false); const [showDetail, setShowDetail] = useState(false); const actionRef = useRef(); const [currentRow, setCurrentRow] = useState(); const [selectedRowsState, setSelectedRows] = useState([]); const showDeleteConfirm = (item: UserListItem) => { confirm({ title: '是否删除记录?', icon: , content: '删除的记录不能恢复,请确认!', onOk() { handleRemove([item]).then(() => { actionRef.current?.reloadAndRest?.(); }); }, onCancel() { }, }); }; const columns: ProColumns[] = [ { title: '编号11', dataIndex: 'user_id', hideInSearch: true, }, { title: '账号', dataIndex: 'user_name', hideInSearch: true, // render: (dom, entity) => { // return { // setCurrentRow(entity); // setShowDetail(true); // }}>{dom}; // }, }, { title: '昵称', dataIndex: 'user_alias', hideInSearch: true, }, { title: '创建人', dataIndex: 'create_user', hideInSearch: true, // hideInTable: true, }, { title: '权限组', dataIndex: 'role_name', hideInSearch: true, }, { title: '创建时间', dataIndex: 'created_time', valueType: 'dateTime', hideInSearch: true, // hideInTable: true, }, { title: '操作', dataIndex: 'option', valueType: 'option', render: (_, record) => ( <> ), }, ]; return ( headerTitle="知识库列表" actionRef={actionRef} rowKey="user_id" search={{ labelWidth: 120, }} toolBarRender={() => [ , ]} params={{ current: 0 }} request={queryUserList} columns={columns} rowSelection={{ onChange: (_, selectedRows) => setSelectedRows(selectedRows), }} pagination={{ pageSize: 10 }} /> {selectedRowsState?.length > 0 && ( 已选择 {selectedRowsState.length} 项   } > )} {/* { const success = await handleAdd(value); if (success) { handleModalVisible(false); setCurrentRow(undefined); if (actionRef.current) { actionRef.current.reload(); } } }} onCancel={() => { handleModalVisible(false); if (!showDetail) { setCurrentRow(undefined); } }} createModalVisible={createModalVisible} /> */} {/* { const success = await handleUpdate(value); if (success) { handleUpdateModalVisible(false); setCurrentRow(undefined); if (actionRef.current) { actionRef.current.reload(); } } }} onCancel={() => { handleUpdateModalVisible(false); if (!showDetail) { setCurrentRow(undefined); } }} updateModalVisible={updateModalVisible} values={currentRow || {}} /> */} { setCurrentRow(undefined); setShowDetail(false) }} closable={false} > {currentRow?.user_id && ( column={2} title={currentRow?.user_name} request={async () => ({ data: currentRow || {}, })} params={{ id: currentRow?.user_id, }} columns={columns as ProDescriptionsItemProps[]} /> )} ); }; export default UserList;