7 lines
9.6 KiB
JavaScript
7 lines
9.6 KiB
JavaScript
import{c as pe,j as e,a as x,r as t,u as he,b as ve,d as je,e as w,f as fe,I as ge,S as h,B as v,P as L,g as U,L as V,G as X,R as ye,h as $,i as be,k as Ne,T as ke,E as ee,l as _e,m as Ce,n as we,C as Se,o as Ee,p as qe,q as ze,s as Ie,t as De}from"./index-BFEQKHK8.js";/**
|
|
* @license lucide-react v0.475.0 - ISC
|
|
*
|
|
* This source code is licensed under the ISC license.
|
|
* See the LICENSE file in the root directory of this source tree.
|
|
*/const Te=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],Le=pe("Ellipsis",Te);function Pe({className:l,...a}){return e.jsx("div",{className:x("overflow-x-auto",l),...a})}function Qe({className:l,...a}){return e.jsx("table",{className:x("w-full border-collapse text-[13px]",l),...a})}function i({className:l,...a}){return e.jsx("th",{className:x("sticky top-0 z-10 border-b border-line bg-surface-2 px-3 py-2 text-left text-[12px] font-semibold text-ink-3 whitespace-nowrap",l),...a})}function r({className:l,...a}){return e.jsx("td",{className:x("border-b border-line px-3 py-2 align-middle text-ink-1",l),...a})}function Re({className:l,onClick:a,...n}){return e.jsx("tr",{className:x("group transition-colors",a&&"cursor-pointer hover:bg-surface-2",l),onClick:a,...n})}function Ke({trigger:l,children:a,align:n="end",className:k}){const[d,m]=t.useState(!1),c=t.useRef(null);return t.useEffect(()=>{if(!d)return;const p=j=>{c.current&&!c.current.contains(j.target)&&m(!1)},o=j=>{j.key==="Escape"&&m(!1)};return document.addEventListener("mousedown",p),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",o)}},[d]),e.jsxs("div",{className:"relative",ref:c,children:[e.jsx("div",{onClick:()=>m(p=>!p),children:l}),d&&e.jsx("div",{className:x("absolute z-40 mt-1 min-w-[160px] rounded-md border border-line bg-surface py-1 shadow-pop",n==="end"?"right-0":"left-0",k),children:typeof a=="function"?a(()=>m(!1)):a})]})}function se({className:l,danger:a,...n}){return e.jsx("button",{className:x("flex w-full items-center gap-2 px-3 py-1.5 text-left text-[13px] transition-colors",a?"text-danger hover:bg-danger-subtle":"text-ink-1 hover:bg-surface-3",l),...n})}const te=20;function Oe(){var F,M,G,A,W,Y,Z,H,J;const l=he(),a=ve(),[n,k]=je(),[d,m]=t.useState(n.get("q")??""),[c,p]=t.useState(""),[o,j]=t.useState(""),[f,ae]=t.useState(""),[g,le]=t.useState(""),[y,ne]=t.useState(""),[S,ie]=t.useState("date_desc"),[b,E]=t.useState(1),[re,q]=t.useState(null),[ce,_]=t.useState(!1),[N,z]=t.useState(null),[de,oe]=t.useState(null),[ue,I]=t.useState(!1);t.useEffect(()=>{n.get("new")==="1"&&(q(null),_(!0),n.delete("new"),k(n,{replace:!0}))},[n,k]);const xe=w({queryKey:["types"],queryFn:qe}),P=w({queryKey:["taxonomy-all"],queryFn:()=>ze()}),me=w({queryKey:["stats",void 0],queryFn:()=>Ie(void 0)}),Q=t.useMemo(()=>({q:d||void 0,types:c?[Number(c)]:void 0,levels:f?[f]:void 0,roles:g?[g]:void 0,statuses:y?[y]:void 0,year:o?Number(o):void 0,sort:S,page:b,page_size:te}),[d,c,o,f,g,y,S,b]),u=w({queryKey:["footprints",Q],queryFn:()=>De(Q)});t.useEffect(()=>{E(1)},[d,c,o,f,g,y]);const R=fe({mutationFn:s=>Ee(s),onSuccess:()=>{a("success","记录已删除"),l.invalidateQueries({queryKey:["footprints"]}),l.invalidateQueries({queryKey:["timeline"]}),l.invalidateQueries({queryKey:["stats"]}),z(null)}}),D=((F=u.data)==null?void 0:F.total)??0,K=Math.max(1,Math.ceil(D/te)),T=()=>{q(null),_(!0)},B=s=>{q(s),_(!0)},O=s=>{oe(s),I(!0)};return e.jsxs("div",{className:"px-3 py-4 sm:px-6 sm:py-5",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsx(ge,{className:"w-[220px]",placeholder:"搜索标题、内容、结果、标签…",value:d,onChange:s=>m(s.target.value)}),e.jsxs("div",{className:"grid w-full grid-cols-2 gap-2 sm:flex sm:w-auto sm:items-center sm:gap-2",children:[e.jsx(h,{className:"w-full sm:w-[130px]",value:c,onChange:s=>p(s.target.value),options:[{value:"",label:"全部类型"},...(((M=xe.data)==null?void 0:M.items)??[]).map(s=>({value:String(s.id),label:s.name}))]}),e.jsx(h,{className:"w-full sm:w-[110px]",value:o,onChange:s=>j(s.target.value),options:[{value:"",label:"全部年份"},...(((G=me.data)==null?void 0:G.years)??[]).map(s=>({value:String(s),label:s+" 年"}))]}),e.jsx(h,{className:"w-full sm:w-[110px]",value:f,onChange:s=>ae(s.target.value),options:[{value:"",label:"全部级别"},...(((A=P.data)==null?void 0:A.items)??[]).filter(s=>s.kind==="level").map(s=>({value:s.value,label:s.value}))]}),e.jsx(h,{className:"w-full sm:w-[100px]",value:g,onChange:s=>le(s.target.value),options:[{value:"",label:"全部角色"},...(((W=P.data)==null?void 0:W.items)??[]).filter(s=>s.kind==="role").map(s=>({value:s.value,label:s.value}))]}),e.jsx(h,{className:"w-full sm:w-[110px]",value:y,onChange:s=>ne(s.target.value),options:[{value:"",label:"全部状态"},{value:"draft",label:"草稿"},{value:"ongoing",label:"进行中"},{value:"submitted",label:"已提交待果"},{value:"finished",label:"已完结"}]}),e.jsx(h,{className:"w-full sm:w-[130px]",value:S,onChange:s=>ie(s.target.value),options:[{value:"date_desc",label:"时间从新到旧"},{value:"date_asc",label:"时间从旧到新"},{value:"updated_desc",label:"最近修改"},{value:"weight_desc",label:"重要度优先"}]})]}),e.jsxs("div",{className:"flex w-full items-center justify-between gap-2 sm:contents",children:[e.jsxs("span",{className:"num text-[12px] text-ink-3 sm:ml-auto",children:["共 ",D," 条"]}),e.jsxs(v,{variant:"primary",size:"md",onClick:T,children:[e.jsx(L,{size:14}),"新建"]})]})]}),e.jsxs("div",{className:"hidden rounded-lg border border-line bg-surface shadow-card md:block",children:[e.jsxs(Pe,{className:"max-h-[calc(100vh-260px)] overflow-y-auto",children:[e.jsxs(Qe,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(i,{className:"w-[32%]",children:"标题"}),e.jsx(i,{children:"类型"}),e.jsx(i,{children:"时间"}),e.jsx(i,{children:"级别"}),e.jsx(i,{children:"奖等"}),e.jsx(i,{children:"角色"}),e.jsx(i,{children:"状态"}),e.jsx(i,{className:"text-right",children:"附件"}),e.jsx(i,{children:"更新时间"}),e.jsx(i,{className:"w-[52px]"})]})}),e.jsx("tbody",{children:(((Y=u.data)==null?void 0:Y.items)??[]).map(s=>e.jsxs(Re,{onClick:()=>O(s.id),children:[e.jsx(r,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{backgroundColor:s.type_color}}),e.jsx("span",{className:"truncate font-medium",title:s.title,children:s.title})]})}),e.jsx(r,{className:"whitespace-nowrap text-ink-2",children:s.type_name}),e.jsx(r,{className:"num whitespace-nowrap text-ink-2",children:U(s.start_date,s.end_date)}),e.jsx(r,{children:e.jsx(V,{level:s.level})}),e.jsx(r,{children:e.jsx(X,{grade:s.award_grade})}),e.jsx(r,{children:e.jsx(ye,{role:s.role})}),e.jsx(r,{children:e.jsx($,{status:s.status})}),e.jsx(r,{className:"num text-right text-ink-2",children:s.attachment_count>0?s.attachment_count:""}),e.jsx(r,{className:"num whitespace-nowrap text-ink-3",children:be(s.updated_at)}),e.jsx(r,{onClick:C=>C.stopPropagation(),children:e.jsx(Ke,{trigger:e.jsx(v,{variant:"ghost",size:"icon-sm","aria-label":"更多操作",children:e.jsx(Le,{size:15})}),children:C=>e.jsxs(e.Fragment,{children:[e.jsxs(se,{onClick:()=>{C(),B(s.id)},children:[e.jsx(Ne,{size:13})," 编辑"]}),e.jsxs(se,{danger:!0,onClick:()=>{C(),z(s)},children:[e.jsx(ke,{size:13})," 删除"]})]})})})]},s.id))})]}),!u.isLoading&&!((Z=u.data)!=null&&Z.items.length)&&e.jsx(ee,{title:"没有匹配的记录",description:"调整筛选条件,或新建一条记录。",action:e.jsxs(v,{variant:"primary",onClick:T,children:[e.jsx(L,{size:14})," 新建记录"]})})]}),e.jsxs("div",{className:"divide-y divide-line rounded-lg border border-line bg-surface md:hidden",children:[(((H=u.data)==null?void 0:H.items)??[]).map(s=>e.jsxs("button",{onClick:()=>O(s.id),className:"block w-full px-3 py-3 text-left transition-colors active:bg-surface-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{backgroundColor:s.type_color}}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13.5px] font-medium text-ink-1",children:s.title}),s.attachment_count>0&&e.jsxs("span",{className:"num shrink-0 text-[11px] text-ink-3",children:[s.attachment_count," 附件"]})]}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[e.jsx(_e,{color:s.type_color,children:s.type_name}),e.jsx($,{status:s.status}),s.level&&e.jsx(V,{level:s.level}),s.award_grade&&e.jsx(X,{grade:s.award_grade})]}),e.jsx("div",{className:"num mt-1 text-[11.5px] text-ink-3",children:U(s.start_date,s.end_date)})]},s.id)),!u.isLoading&&!((J=u.data)!=null&&J.items.length)&&e.jsx(ee,{title:"没有匹配的记录",description:"调整筛选条件,或新建一条记录。",action:e.jsxs(v,{variant:"primary",onClick:T,children:[e.jsx(L,{size:14})," 新建记录"]})})]}),D>0&&e.jsxs("div",{className:"flex h-11 items-center justify-end gap-3 border-t border-line bg-surface px-4 text-[12px] text-ink-3",children:[e.jsxs("span",{className:"num",children:["第 ",b," / ",K," 页"]}),e.jsx(v,{variant:"secondary",size:"sm",disabled:b<=1,onClick:()=>E(s=>s-1),children:"上一页"}),e.jsx(v,{variant:"secondary",size:"sm",disabled:b>=K,onClick:()=>E(s=>s+1),children:"下一页"})]})]}),e.jsx(Ce,{open:ue,onClose:()=>I(!1),footprintId:de,onEdit:s=>{I(!1),B(s)}}),e.jsx(we,{open:ce,onClose:()=>_(!1),footprintId:re}),e.jsx(Se,{open:!!N,title:"删除记录",content:N?"确定删除「"+N.title+"」吗?该操作不可撤销。":"",onCancel:()=>z(null),onOk:()=>N&&R.mutate(N.id),loading:R.isPending})]})}export{Oe as RecordsPage};
|