Files
FootPrint/sync-server/www/assets/RecordsPage-tnlmi-lB.js
T

7 lines
8.0 KiB
JavaScript

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