|
@@ -12,29 +12,35 @@
|
|
|
* ⛔ 复制两份队列实现——分派口径与候选人口径必须是一把尺子。
|
|
* ⛔ 复制两份队列实现——分派口径与候选人口径必须是一把尺子。
|
|
|
*/
|
|
*/
|
|
|
import { useState } from "react";
|
|
import { useState } from "react";
|
|
|
-import { ArrowRight, Check, Clock3, Info, Shuffle, UserRoundCheck } from "lucide-react";
|
|
|
|
|
|
|
+import { ArrowRight, Check, ClipboardList, Clock3, Search, Shuffle, UserRoundCheck, UsersRound, X } from "lucide-react";
|
|
|
import { Link, useLocation, useSearchParams } from "react-router";
|
|
import { Link, useLocation, useSearchParams } from "react-router";
|
|
|
import { Button } from "../components/ui/button";
|
|
import { Button } from "../components/ui/button";
|
|
|
import { FilterSelect } from "../components/ui/filter-select";
|
|
import { FilterSelect } from "../components/ui/filter-select";
|
|
|
import { FieldHint } from "../components/ui/field-hint";
|
|
import { FieldHint } from "../components/ui/field-hint";
|
|
|
-import { OpsDrawer, OpsNotice, OpsTag } from "../components/OperationsKit";
|
|
|
|
|
-import { WorkspaceEmpty, WorkspaceHeading, WorkspacePanel, WorkspaceSearch } from "../components/RoleWorkspaceKit";
|
|
|
|
|
|
|
+import { OpsDrawer, OpsNotice } from "../components/OperationsKit";
|
|
|
|
|
+import { WorkspaceEmpty, WorkspaceHeading } from "../components/RoleWorkspaceKit";
|
|
|
|
|
+import { SearchInput } from "../components/ui/search-input";
|
|
|
|
|
+import { TicketState } from "../components/ticketState";
|
|
|
|
|
+import { WorkOrderLedgerList } from "../components/work-order/WorkOrderLedgerList";
|
|
|
import { useDemoIdentity } from "../lib/demo-session";
|
|
import { useDemoIdentity } from "../lib/demo-session";
|
|
|
-import { classifyTicketError, fmtTime, TICKET_PAGE_SIZE, usePendingQueue } from "../lib/ticket";
|
|
|
|
|
|
|
+import { classifyTicketError, TICKET_PAGE_SIZE, usePendingQueue } from "../lib/ticket";
|
|
|
import {
|
|
import {
|
|
|
- TICKET_TYPES, statusLabel, ticketAssign, ticketDispatchAuto, ticketPendingQueue, typeLabel,
|
|
|
|
|
|
|
+ TICKET_TYPES, ticketAssign, ticketDispatchAuto, ticketPendingQueue, typeLabel,
|
|
|
type AssignCandidate, type DispatchResult, type PendingQueueItem,
|
|
type AssignCandidate, type DispatchResult, type PendingQueueItem,
|
|
|
} from "../lib/api/ticket";
|
|
} from "../lib/api/ticket";
|
|
|
import { useSubmit } from "../lib/useLoad";
|
|
import { useSubmit } from "../lib/useLoad";
|
|
|
-import { ServerListPager } from "../components/ListPager";
|
|
|
|
|
|
|
+import { ListPager } from "../components/ListPager";
|
|
|
|
|
+import "../styles/operations.css";
|
|
|
|
|
+import "../styles/orders.css";
|
|
|
import "../styles/work-orders.css";
|
|
import "../styles/work-orders.css";
|
|
|
|
|
+import "../styles/work-order-ledger.css";
|
|
|
|
|
|
|
|
export function TeamQueuePage() {
|
|
export function TeamQueuePage() {
|
|
|
const identity = useDemoIdentity();
|
|
const identity = useDemoIdentity();
|
|
|
if (identity?.role !== "teamLead" || !identity.maintenanceTeamId) {
|
|
if (identity?.role !== "teamLead" || !identity.maintenanceTeamId) {
|
|
|
return <WorkspaceEmpty title="请切换到运维团队主账号" description="待分派队列与分派操作由团队主在服务端权限内使用。" />;
|
|
return <WorkspaceEmpty title="请切换到运维团队主账号" description="待分派队列与分派操作由团队主在服务端权限内使用。" />;
|
|
|
}
|
|
}
|
|
|
- return <section className="role-workspace page-fill">
|
|
|
|
|
|
|
+ return <section className="role-workspace order-page work-order-ledger page-fill">
|
|
|
<WorkspaceHeading title="待分派工单" description={`为 ${identity.name} 的待分派工单安排接单人,候选人按工单类型、负责范围和账号状态筛选。`} aside={<Link className="workspace-link" to="/work-orders">查看团队工单 <ArrowRight size={15} /></Link>} />
|
|
<WorkspaceHeading title="待分派工单" description={`为 ${identity.name} 的待分派工单安排接单人,候选人按工单类型、负责范围和账号状态筛选。`} aside={<Link className="workspace-link" to="/work-orders">查看团队工单 <ArrowRight size={15} /></Link>} />
|
|
|
<QueueBoard teamId={identity.maintenanceTeamId} teamName={identity.name} canAutoDispatch />
|
|
<QueueBoard teamId={identity.maintenanceTeamId} teamName={identity.name} canAutoDispatch />
|
|
|
</section>;
|
|
</section>;
|
|
@@ -66,7 +72,8 @@ export function QueueBoard({ teamId, teamName, showTeamColumn = false, canAutoDi
|
|
|
const total = queue.data?.total ?? 0;
|
|
const total = queue.data?.total ?? 0;
|
|
|
const fail = queue.error ? classifyTicketError(queue.error) : null;
|
|
const fail = queue.error ? classifyTicketError(queue.error) : null;
|
|
|
const lateCount = rows.filter((item) => item.overdue_7d).length;
|
|
const lateCount = rows.filter((item) => item.overdue_7d).length;
|
|
|
- const teams = [...new Set(rows.map((row) => row.team_name ?? "未分派团队"))];
|
|
|
|
|
|
|
+ const teams = new Set(rows.map((row) => row.assign_team_id).filter(Boolean)).size;
|
|
|
|
|
+ const from = location.pathname + location.search;
|
|
|
|
|
|
|
|
const submit = useSubmit();
|
|
const submit = useSubmit();
|
|
|
const [action, setAction] = useState<PendingQueueItem | "auto" | null>(null);
|
|
const [action, setAction] = useState<PendingQueueItem | "auto" | null>(null);
|
|
@@ -125,53 +132,61 @@ export function QueueBoard({ teamId, teamName, showTeamColumn = false, canAutoDi
|
|
|
}
|
|
}
|
|
|
const failure = submit.error ? classifyTicketError(submit.error) : null;
|
|
const failure = submit.error ? classifyTicketError(submit.error) : null;
|
|
|
|
|
|
|
|
|
|
+ const metrics = [
|
|
|
|
|
+ { title: "待分派工单", value: total, description: q || type ? "符合当前筛选" : teamName || "账号可见范围", icon: ClipboardList },
|
|
|
|
|
+ { title: "超期 / 临期", value: lateCount, description: "当前页 · 7 日内到期或已超期", icon: Clock3, tone: lateCount ? "warning" : undefined },
|
|
|
|
|
+ ...(showTeamColumn ? [{ title: "涉及团队", value: teams, description: "当前页 · 已归属团队", icon: UsersRound }] : []),
|
|
|
|
|
+ ];
|
|
|
|
|
+ const fallback = queue.loading
|
|
|
|
|
+ ? <div className="order-empty" role="status">正在读取待分派队列…</div>
|
|
|
|
|
+ : fail
|
|
|
|
|
+ ? <TicketState fail={fail} onRetry={queue.reload} />
|
|
|
|
|
+ : !rows.length ? <div className="order-empty"><h3>{q || type ? "没有匹配的待分派工单" : "暂无待分派工单"}</h3></div> : null;
|
|
|
|
|
+
|
|
|
return <>
|
|
return <>
|
|
|
- <div className="workspace-metrics">
|
|
|
|
|
- <div className="workspace-metric"><span>待分派工单</span><strong>{queue.loading ? "—" : fail ? "—" : total}</strong><small>{teamName ? `${teamName} · 未指定责任人` : "权限范围内 · 未指定责任人"}</small></div>
|
|
|
|
|
- <div className={`workspace-metric ${lateCount ? "warning" : ""}`}><span>超期/临期</span><strong>{queue.loading ? "—" : fail ? "—" : lateCount}</strong><small>7 日内到期或已超期 · 当页口径</small></div>
|
|
|
|
|
- {showTeamColumn && <div className="workspace-metric"><span>涉及团队</span><strong>{queue.loading ? "—" : fail ? "—" : teams.length}</strong><small>当页口径</small></div>}
|
|
|
|
|
|
|
+ <div className="work-order-ledger-summary work-order-queue-summary" role="group" aria-label="待分派队列统计" data-count={metrics.length}>
|
|
|
|
|
+ {metrics.map(({ title, value, description, icon: Icon, tone }, index) => (
|
|
|
|
|
+ <div className={`work-order-metric${index === 0 ? " work-order-metric-total" : ""}`} key={title} data-tone={tone}>
|
|
|
|
|
+ <span className="work-order-metric-icon"><Icon size={18} aria-hidden="true" /></span>
|
|
|
|
|
+ <span className="work-order-metric-body"><span>{title}</span><strong>{queue.loading ? "…" : fail ? "—" : value.toLocaleString("zh-CN")}</strong><small>{description}</small></span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ))}
|
|
|
</div>
|
|
</div>
|
|
|
- {!!lateCount && <div className="workspace-alert"><Clock3 size={17} /><span>有 {lateCount} 张待分派工单已超期或 7 日内到期,请优先安排。</span></div>}
|
|
|
|
|
- <section className="workspace-panel work-order-list-shell list-shell-fill" aria-label="待分派队列">
|
|
|
|
|
- <header className="work-order-list-heading">
|
|
|
|
|
- <Button variant="outline" disabled={queue.loading || !total || !canAutoDispatch} title={canAutoDispatch ? "按未完成数量平均分派本团队待分派工单" : "自动平均分派按团队执行,仅团队主账号可用"} onClick={() => { setAction("auto"); setTip(""); setSummary(null); }}><Shuffle size={16} />按未完成数量平均分派</Button>
|
|
|
|
|
- </header>
|
|
|
|
|
- <div className="workspace-toolbar">
|
|
|
|
|
- <WorkspaceSearch placeholder="搜索工单号、工单ID或标题" value={q} onChange={(value) => filter("q", value)} />
|
|
|
|
|
|
|
+ <section className="order-list-shell list-shell-fill" aria-label="待分派队列">
|
|
|
|
|
+ <div className="ops-toolbar order-filters work-order-queue-filters">
|
|
|
|
|
+ <label className="ops-search order-search">
|
|
|
|
|
+ <Search size={17} aria-hidden="true" />
|
|
|
|
|
+ <SearchInput aria-label="搜索待分派工单" placeholder="搜索工单号、工单ID或标题" value={q} onCommit={(value) => filter("q", value)} />
|
|
|
|
|
+ {q && <button type="button" aria-label="清空搜索" onClick={() => filter("q", "")}><X size={15} /></button>}
|
|
|
|
|
+ </label>
|
|
|
<FilterSelect icon="type" aria-label="工单类型" value={type} onChange={(event) => filter("type", event.target.value)}>
|
|
<FilterSelect icon="type" aria-label="工单类型" value={type} onChange={(event) => filter("type", event.target.value)}>
|
|
|
<option value="">全部类型</option>
|
|
<option value="">全部类型</option>
|
|
|
{TICKET_TYPES.map((t) => <option key={t} value={t}>{typeLabel(t)}</option>)}
|
|
{TICKET_TYPES.map((t) => <option key={t} value={t}>{typeLabel(t)}</option>)}
|
|
|
</FilterSelect>
|
|
</FilterSelect>
|
|
|
{(q || type) && <Button variant="ghost" size="sm" onClick={() => setParams({})}>重置筛选</Button>}
|
|
{(q || type) && <Button variant="ghost" size="sm" onClick={() => setParams({})}>重置筛选</Button>}
|
|
|
|
|
+ <Button className="work-order-queue-auto" size="sm" variant="outline" disabled={queue.loading || !total || !canAutoDispatch} title={canAutoDispatch ? "分派本团队全部待分派工单,不受当前筛选影响" : "仅团队主账号可自动平均分派"} onClick={() => { setAction("auto"); setTip(""); setSummary(null); }}><Shuffle size={15} />自动平均分派</Button>
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="measured-table-scroll workspace-table-wrap"><table className="workspace-table">
|
|
|
|
|
- <thead><tr><th>工单 / 客户</th><th>类型与状态</th>{showTeamColumn && <th>团队</th>}<th>事项摘要</th><th>创建时间</th><th>操作</th></tr></thead>
|
|
|
|
|
- <tbody>
|
|
|
|
|
- {rows.map((item) => <tr key={item.ticket_id}>
|
|
|
|
|
- <td><Link className="workspace-link" to={`/work-orders/${encodeURIComponent(item.ticket_id)}`} state={{ from: location.pathname + location.search }}>{item.ticket_no ?? "未编号"}</Link><small>{item.customer_name ?? "-"}</small></td>
|
|
|
|
|
- <td><OpsTag tone="brand">{typeLabel(item.ticket_type)}</OpsTag><small>{statusLabel(item.status, item.ticket_type)}</small></td>
|
|
|
|
|
- {showTeamColumn && <td>{item.team_name ?? <span className="table-placeholder">未分派团队</span>}</td>}
|
|
|
|
|
- <td className="wrap"><span>{item.title ?? "-"}</span>{item.overdue_7d && <small className="workspace-danger">超期/临期(7 日内)</small>}</td>
|
|
|
|
|
- <td>{fmtTime(item.created_at)}</td>
|
|
|
|
|
- <td><div className="workspace-actions"><button className="workspace-link" onClick={() => void openAssign(item)}><UserRoundCheck size={15} />指定成员</button><Link className="workspace-link" to={`/work-orders/${encodeURIComponent(item.ticket_id)}`} state={{ from: location.pathname + location.search }}>详情</Link></div></td>
|
|
|
|
|
- </tr>)}
|
|
|
|
|
- </tbody>
|
|
|
|
|
- </table>
|
|
|
|
|
- {queue.loading && <div className="workspace-empty"><h3>正在读取待分派队列…</h3></div>}
|
|
|
|
|
- {fail && <div className="workspace-empty"><Clock3 size={26} aria-hidden /><h3>{fail.kind === "wiring" ? "接口待后端接线" : fail.kind === "permission" ? "当前账号无权查看" : "队列读取失败"}</h3><p>{fail.message}</p></div>}
|
|
|
|
|
- {!queue.loading && !fail && !rows.length && <WorkspaceEmpty title="当前队列已清空" description="已分派的工单可在全部工单中继续跟进。" />}
|
|
|
|
|
- </div>
|
|
|
|
|
- <ServerListPager total={total} page={page} pageSize={TICKET_PAGE_SIZE} unit="张" className="list-pager work-order-ledger-pager" onPageChange={(next) => setParams((cur) => { const u = new URLSearchParams(cur); u.set("page", String(next)); return u; }, { replace: true })} />
|
|
|
|
|
- <p className="workspace-note"><Info size={15} />共 {total} 张待分派,当页显示 {rows.length} 张。自动平均分派作用于团队全部待分派工单,不受列表筛选影响;无符合条件成员的工单留在队列。</p>
|
|
|
|
|
|
|
+ <WorkOrderLedgerList
|
|
|
|
|
+ rows={rows}
|
|
|
|
|
+ from={from}
|
|
|
|
|
+ label="待分派工单"
|
|
|
|
|
+ fallback={fallback}
|
|
|
|
|
+ ownerColumn={showTeamColumn ? "team" : "none"}
|
|
|
|
|
+ showNextStep={false}
|
|
|
|
|
+ renderRowAction={(item) => <button type="button" className="ops-table-action" onClick={() => void openAssign(item)}><UserRoundCheck size={15} />指定成员</button>}
|
|
|
|
|
+ />
|
|
|
|
|
+ {!queue.loading && !fail && <ListPager total={total} page={page - 1} pageSize={TICKET_PAGE_SIZE} unit="张" onPageChange={(next) => setParams((current) => {
|
|
|
|
|
+ const updated = new URLSearchParams(current);
|
|
|
|
|
+ if (next) updated.set("page", String(next + 1));
|
|
|
|
|
+ else updated.delete("page");
|
|
|
|
|
+ return updated;
|
|
|
|
|
+ }, { replace: true })} />}
|
|
|
</section>
|
|
</section>
|
|
|
- <WorkspacePanel title="候选人接单负荷" description="点「指定成员」时按该工单现算候选人与未完成数;自动分派仍按服务端最少者优先。">
|
|
|
|
|
- <p className="workspace-note"><Info size={15} />首屏不再预装全页候选人(避免十余次 UDS);打开指定成员抽屉即可看到该单可接人选与手头量。</p>
|
|
|
|
|
- </WorkspacePanel>
|
|
|
|
|
{action && <OpsDrawer title={action === "auto" ? "确认自动平均分派" : "指定接单成员"} subtitle={teamName ?? "权限范围内"} onClose={() => setAction(null)}>
|
|
{action && <OpsDrawer title={action === "auto" ? "确认自动平均分派" : "指定接单成员"} subtitle={teamName ?? "权限范围内"} onClose={() => setAction(null)}>
|
|
|
<div className="workspace-form">
|
|
<div className="workspace-form">
|
|
|
{action === "auto" ? <>
|
|
{action === "auto" ? <>
|
|
|
<Shuffle size={28} className="text-primary" />
|
|
<Shuffle size={28} className="text-primary" />
|
|
|
- <h3>分派本团队的 {total} 张待分派工单</h3>
|
|
|
|
|
|
|
+ <h3>分派本团队的待分派工单</h3>
|
|
|
<p className="text-sm leading-7 text-muted-foreground">服务端每张选择符合类型与可派条件的成员,优先分给未完成工单最少者;没有合适成员的工单留在队列。若团队分派方式不是「自动平均分派」,服务端会拒绝并说明原因。</p>
|
|
<p className="text-sm leading-7 text-muted-foreground">服务端每张选择符合类型与可派条件的成员,优先分给未完成工单最少者;没有合适成员的工单留在队列。若团队分派方式不是「自动平均分派」,服务端会拒绝并说明原因。</p>
|
|
|
{summary && <p className="text-sm leading-7">上轮回执:分派 {summary.dispatched.length} 张 / 扫描 {summary.scanned} 张 / 跳过 {summary.skipped.length} 张。</p>}
|
|
{summary && <p className="text-sm leading-7">上轮回执:分派 {summary.dispatched.length} 张 / 扫描 {summary.scanned} 张 / 跳过 {summary.skipped.length} 张。</p>}
|
|
|
</> : <>
|
|
</> : <>
|