import { useEffect, useState, useCallback } from "react"; import { Button, Select, Input, Table, Checkbox, App as AntApp } from "antd"; import { ReloadOutlined, PlusOutlined, ExportOutlined, SearchOutlined, } from "@ant-design/icons"; import type { ColumnsType } from "antd/es/table"; import { listUsers, type UserListVO } from "@/api/user"; import { USER_LIST_FIELDS, USER_LIST_MATCHES } from "@/utils/data"; import { fmtDateTime } from "@/utils/format"; import { useAppDispatch } from "@/store"; import { openTab } from "@/store/tabsSlice"; type Scope = "all" | "active" | "disabled"; export default function UserList() { const dispatch = useAppDispatch(); const { message } = AntApp.useApp(); const [scope, setScope] = useState("all"); const [field, setField] = useState("员工名"); const [match, setMatch] = useState("包含"); const [query, setQuery] = useState(""); const [loading, setLoading] = useState(false); const [rows, setRows] = useState([]); const [total, setTotal] = useState(0); const [selected, setSelected] = useState([]); const reload = useCallback( async (override?: { field?: string; match?: string; value?: string }) => { setLoading(true); try { const page = await listUsers({ field: override?.field ?? field, match: override?.match ?? match, value: override?.value ?? query, pageNum: 1, pageSize: 100, }); setRows(page.records ?? []); setTotal(page.total ?? 0); } catch { // interceptor already showed message } finally { setLoading(false); } }, [field, match, query] ); useEffect(() => { void reload(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const filtered = rows.filter((r) => { if (scope === "active") return !r.bDeleted; if (scope === "disabled") return r.bDeleted; return true; }); const onCreate = () => { dispatch( openTab({ id: "user-new", label: "用户信息单据 · 新建", screen: "userdetail", meta: { mode: "new" }, }) ); }; const onOpenUser = (u: UserListVO) => { dispatch( openTab({ id: `user-${u.iIncrement}`, label: `用户信息单据 · ${u.staffName ?? u.sUserName}`, screen: "userdetail", meta: { mode: "view", userId: u.iIncrement, snapshot: u }, }) ); }; const columns: ColumnsType = [ { title: "序号", dataIndex: "iIncrement", width: 60, render: (_, __, i) => {i + 1}, }, { title: "员工名", dataIndex: "staffName", width: 100, render: (v, r) => v ?? r.sUserName }, { title: "员工号", dataIndex: "sUserNo", width: 100 }, { title: "用户号", dataIndex: "sUserName", width: 100, render: (v) => {v} }, { title: "部门", dataIndex: "department", width: 120, render: (v) => v ?? "—" }, { title: "用户类型", dataIndex: "sUserType", width: 110 }, { title: "语言", dataIndex: "sLanguage", width: 70 }, { title: "作废", dataIndex: "bDeleted", width: 60, render: (v: boolean) => , }, { title: "登录日期", dataIndex: "tLastLoginDate", width: 150, render: (v) => {fmtDateTime(v)}, }, { title: "制单人", dataIndex: "sCreatedBy", width: 100 }, { title: "制单日期", dataIndex: "tCreateDate", width: 150, render: (v) => {fmtDateTime(v)}, }, ]; return (
setQuery(e.target.value)} onPressEnter={() => reload()} style={{ width: 180 }} />
{selected.length > 0 && ( <> 已选 {selected.length} 条 /{" "} )} 共 {total} 条记录
rowKey="iIncrement" columns={columns} dataSource={filtered} loading={loading} size="small" pagination={false} rowSelection={{ selectedRowKeys: selected, onChange: (keys) => setSelected(keys as number[]), }} onRow={(r) => ({ onDoubleClick: () => onOpenUser(r), style: { cursor: "pointer", color: r.bDeleted ? "var(--text-faint)" : "var(--text)" }, })} />
当前显示:共 {filtered.length} 条单据 共 {total} 条记录 双击行查看详情
); }