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

7 lines
10 KiB
JavaScript

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