@qfei-design/make-app-approval 0.2.12 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
1
  import type { IColumn } from "@qfei-design/canvas-table";
2
+ import type { ApprovalListTab } from "./types.js";
2
3
  export declare const approvalRowHeadWidth = 64;
3
- export declare const getApprovalColumns: (containerWidth: number) => IColumn[];
4
+ export declare const getApprovalColumns: (containerWidth: number, tab?: ApprovalListTab) => IColumn[];
@@ -1,6 +1,6 @@
1
1
  import type { ApprovalUIComponents } from "./ui-components.js";
2
2
  /** 包与宿主之间的数据约定,不是 BPM 后端接口 DTO。 */
3
- export type ApprovalListTab = "pending" | "approved";
3
+ export type ApprovalListTab = "pending" | "approved" | "initiated";
4
4
  export type ApprovalListItem = Readonly<{
5
5
  /** 后端提供的稳定列表行标识,不使用申请单号或数组下标。 */
6
6
  id: string;
@@ -8,6 +8,8 @@ export type ApprovalListItem = Readonly<{
8
8
  recordId: string;
9
9
  taskId?: string;
10
10
  processInstanceId?: string;
11
+ /** 已发起使用实例定位;旧宿主不传时仍按任务入口处理。 */
12
+ referenceType?: "task" | "instance";
11
13
  /** 宿主展示值;Make Workflow 接入时使用 recordId 原字符串。 */
12
14
  applicationNo: string;
13
15
  applicationType: string;
@@ -62,6 +64,8 @@ export type ApprovalDiagnostic = Readonly<{
62
64
  }>;
63
65
  export type ApprovalLogger = (event: ApprovalDiagnostic) => void;
64
66
  export type MyApprovalsPageProps = Readonly<{
67
+ /** 默认保留两个任务页签;完成实例 provider 接入后显式加入 initiated。 */
68
+ tabs?: readonly ApprovalListTab[];
65
69
  /** 应用、用户、环境任一变化都必须改变;变化后清空旧数据和筛选。 */
66
70
  scopeKey: string;
67
71
  /** 由宿主响应式上下文选择,默认保留桌面行为。 */
package/dist/list.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var ue=Object.create;var ne=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var me=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var ve=(e,t,c,E)=>{if(t&&typeof t=="object"||typeof t=="function")for(let z of fe(t))!ge.call(e,z)&&z!==c&&ne(e,z,{get:()=>t[z],enumerable:!(E=he(t,z))||E.enumerable});return e};var be=(e,t,c)=>(c=e!=null?ue(me(e)):{},ve(t||!e||!e.__esModule?ne(c,"default",{value:e,enumerable:!0}):c,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),l=require("react"),we=require("./index.cjs"),ce=e=>typeof e=="object"&&e!==null,ke=e=>ce(e)?["id","entityKey","recordId"].every(t=>typeof e[t]=="string"&&e[t].trim().length>0)&&["applicationNo","applicationType","applicantName","applicationTime"].every(t=>typeof e[t]=="string")&&["taskId","processInstanceId"].every(t=>e[t]===void 0||typeof e[t]=="string"&&e[t].trim().length>0)&&["completionTime","completionResult"].every(t=>e[t]===void 0||typeof e[t]=="string")&&(typeof e.processStatus=="string"||e.processStatus===null):!1,Q=(e,t)=>{if(!ce(e)||!Array.isArray(e.rows)||!e.rows.every(ke)||typeof e.total!="number"||!Number.isSafeInteger(e.total)||e.total<0||e.rows.length>t||e.rows.length>e.total||new Set(e.rows.map(c=>c.id)).size!==e.rows.length)throw new Error("Invalid approval page contract");return{rows:e.rows,total:e.total}},P=(e,t)=>{try{e?e(t):t.phase==="error"?console.warn("[make-app-approval]",t):console.info("[make-app-approval]",t)}catch{console.warn("[make-app-approval] diagnostic sink failed")}},ye=({initialPage:e,query:t,provider:c,components:E,onOpen:z,onReload:B,logger:L})=>{const[g,k]=l.useState(e),[v,I]=l.useState(2),[h,j]=l.useState("idle"),p=l.useRef(void 0),[R,T]=l.useState(!1),d=l.useRef(void 0);l.useEffect(()=>()=>{d.current?.abort()},[]);const y=async()=>{if(d.current||g.rows.length>=g.total)return;const s=new AbortController;d.current=s,j("loading");const i={operation:"list",tab:t.tab,page:v,pageSize:t.pageSize};P(L,{...i,phase:"start"});try{const x=Q(await c.loadPage({...t,page:v},{signal:s.signal}),t.pageSize);if(s.signal.aborted)return;if(x.total<g.total){P(L,{...i,phase:"skip",rowCount:x.rows.length}),B();return}const u=new Set(g.rows.map(N=>N.id));if(!x.rows.length||x.rows.some(N=>u.has(N.id)))throw new Error("Invalid append page");k({rows:[...g.rows,...x.rows],total:x.total}),I(N=>N+1),j("idle"),P(L,{...i,phase:"success",rowCount:x.rows.length})}catch{s.signal.aborted||(j("error"),P(L,{...i,phase:"error"}))}finally{d.current===s&&(d.current=void 0)}},M=s=>{const{scrollHeight:i,scrollTop:x,clientHeight:u}=s.currentTarget;h==="idle"&&i-x-u<120&&y()},{Button:V}=E;return a.jsxs("div",{className:"make-app-approval-mobile-list",onScroll:M,onTouchStart:s=>{p.current=s.currentTarget.scrollTop<=0&&s.touches.length===1&&h!=="loading"?{start:s.touches[0].clientY,distance:0}:void 0},onTouchMove:s=>{!p.current||s.touches.length!==1||(p.current.distance=s.touches[0].clientY-p.current.start,T(p.current.distance>=60))},onTouchEnd:()=>{const s=(p.current?.distance??0)>=60;p.current=void 0,T(!1),s&&B()},onTouchCancel:()=>{p.current=void 0,T(!1)},"aria-label":"审批卡片列表","aria-busy":h==="loading",children:[R&&a.jsx("p",{role:"status",className:"make-app-approval-mobile-feedback",children:"松开刷新"}),g.rows.map(s=>a.jsxs("button",{type:"button",className:"make-app-approval-mobile-card",onClick:()=>z(s),"aria-label":`打开 ${s.applicationNo} 的审批详情`,children:[a.jsx("strong",{children:s.applicationType||"审批申请"}),a.jsxs("span",{className:"make-app-approval-mobile-card-line",children:[a.jsx("span",{children:"申请单ID:"}),a.jsx("span",{children:s.applicationNo})]}),t.tab==="approved"&&a.jsxs("span",{className:"make-app-approval-mobile-card-line",children:[a.jsx("span",{children:"审批结果:"}),a.jsx("span",{children:s.completionResult||"—"})]}),a.jsxs("span",{className:"make-app-approval-mobile-card-footer",children:[a.jsxs("span",{className:"make-app-approval-mobile-person",children:[a.jsx("span",{className:"make-app-approval-mobile-avatar","aria-hidden":"true",children:s.applicantName.slice(-2)}),a.jsx("span",{children:s.applicantName||"—"})]}),a.jsx("span",{children:t.tab==="approved"?`完成于 ${s.completionTime||"—"}`:`申请于 ${s.applicationTime||"—"}`})]})]},s.id)),!g.rows.length&&a.jsx("p",{className:"make-app-approval-mobile-feedback",children:"暂无审批记录"}),h==="error"?a.jsxs("div",{role:"alert",className:"make-app-approval-mobile-feedback",children:["部分审批记录加载失败",a.jsx(V,{htmlType:"button",variant:"text",onClick:()=>{y()},children:"重试加载"})]}):h==="loading"?a.jsx("p",{role:"status",className:"make-app-approval-mobile-feedback",children:"加载中"}):g.rows.length<g.total?a.jsx(V,{htmlType:"button",variant:"text",onClick:()=>{y()},children:"加载更多"}):g.rows.length>0&&a.jsx("p",{className:"make-app-approval-mobile-feedback",children:"没有更多了"})]})},xe={applicationNo:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1d212a" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-fingerprint-pattern" aria-hidden="true"><path d="M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4"></path><path d="M14 13.12c0 2.38 0 6.38-1 8.88"></path><path d="M17.29 21.02c.12-.6.43-2.3.5-3.02"></path><path d="M2 12a10 10 0 0 1 18-6"></path><path d="M2 16h.01"></path><path d="M21.8 16c.2-2 .131-5.354 0-6"></path><path d="M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2"></path><path d="M8.65 22c.21-.66.45-1.32.57-2"></path><path d="M9 6.8a6 6 0 0 1 9 5.2v2"></path></svg>',applicationType:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1d212a" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-type" aria-hidden="true"><path d="M12 4v16"></path><path d="M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"></path><path d="M9 20h6"></path></svg>',applicantName:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1d212a" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-user-round" aria-hidden="true"><circle cx="12" cy="8" r="5"></circle><path d="M20 21a8 8 0 0 0-16 0"></path></svg>',applicationTime:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1d212a" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-calendar-clock" aria-hidden="true"><path d="M16 14v2.2l1.6 1"></path><path d="M16 2v3"></path><path d="M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338"></path><path d="M3 9h5.859"></path><path d="M8 2v3"></path><circle cx="16" cy="16" r="6"></circle></svg>'},Se=Object.fromEntries(Object.entries(xe).map(([e,t])=>[e,`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`])),te=64,ae=[{key:"applicationNo",title:"申请单ID",width:260},{key:"applicationType",title:"业务表单",width:180},{key:"applicantName",title:"申请人",width:170},{key:"applicationTime",title:"申请时间",width:220}],je=ae.reduce((e,t)=>e+t.width,te),ie=e=>{const t=Math.max(0,e-je)/ae.length;return ae.map(c=>({...c,width:c.width+t,showEllipsis:!0,sortable:!1,prefixRender:()=>({icon:Se[c.key]})}))},Ne=e=>e==null||e==="UNSUBMITTED"?"状态未知":we.getApprovalStatusDisplay(e).label,Re=({table:e,query:t,initialPage:c,loadPage:E,onChange:z,retryViewport:B,onReload:L,logger:g})=>{const k=new Map,v=new Set;let I=[];const h=new WeakMap,j=new Set;let p=c,R=c.total,T=0,d=!1,y=!1,M;const V=o=>Number.isSafeInteger(o)&&o>=0&&o*t.pageSize<R,s=(o,r,f)=>P(g,{operation:"list",phase:r,tab:t.tab,page:o+1,pageSize:t.pageSize,rowCount:f}),i=()=>{d||z({total:R,rows:I,failed:y||j.size>0,loading:k.size>0})},x=o=>{o.finished||(o.finished=!0,o.removeAbort(),k.get(o.page)===o&&k.delete(o.page),e.markPageLoadFailed(o.page,o.request),o.controller.abort(),s(o.page,"cancel"))},u=o=>{T=o;const r=e.getPagesInView()??[],f=new Set([T,...r].flatMap(b=>[b-1,b,b+1]).filter(V));for(const b of k.values())f.has(b.page)||x(b);for(const b of j)f.has(b)||j.delete(b)},N=(o,r,f)=>{const b=r.rows.map(S=>{const F={...S,statusLabel:Ne(S.processStatus)};return h.set(F,S),F});if(!e.setVirtualPageData(b,o,r.total,f)){s(o,"skip");return}R=r.total;try{I=Q({rows:e.getTableData()??[],total:R},Number.MAX_SAFE_INTEGER).rows.map(S=>h.get(S)??S)}catch(S){y=!0,I=[],p=void 0,M&&clearTimeout(M),M=void 0;for(const F of k.values())x(F);throw S}p&&p.total!==R&&(p=void 0),j.delete(o);for(const S of k.values())V(S.page)||x(S);!V(o)&&o>0&&e.scrollToRow(Math.max(0,R-1)),s(o,"success",r.rows.length)},D=()=>{if(d||M)return;const o=[...k.values()].filter(r=>!r.running&&!r.finished).sort((r,f)=>Math.abs(r.page-T)-Math.abs(f.page-T)||r.page-f.page);for(const r of o){if(v.size>=2)break;r.running=!0,v.add(r),s(r.page,"start"),(async()=>{try{const f=await E({...t,page:r.page+1},{signal:r.controller.signal});if(d||r.finished||r.controller.signal.aborted)return;const b=Q(f,t.pageSize);r.finished=!0,r.removeAbort(),k.delete(r.page),N(r.page,b,r.request)}catch{!d&&!r.controller.signal.aborted&&(j.add(r.page),s(r.page,"error"),e.markPageLoadFailed(r.page,r.request))}finally{r.finished||(r.finished=!0,r.removeAbort(),k.get(r.page)===r&&k.delete(r.page)),v.delete(r),i(),D()}})()}i()},H=()=>{M&&clearTimeout(M),M=setTimeout(()=>{M=void 0,D()},120)};return{load(o,r){if(r.useRequestIdentity(),d||y||r.signal.aborted||!V(o)){e.markPageLoadFailed(o,r),s(o,"skip");return}const f=k.get(o);if(f?.request===r&&!f.finished)return;if(f&&x(f),u(o),o===0&&p){const S=p;p=void 0;try{N(0,S,r)}catch{j.add(o),e.markPageLoadFailed(o,r),s(o,"error")}i();return}const b={page:o,request:r,controller:new AbortController,running:!1,finished:!1,removeAbort:()=>{}},O=()=>{x(b),i()};r.signal.addEventListener("abort",O,{once:!0}),b.removeAbort=()=>r.signal.removeEventListener("abort",O),k.set(o,b),H(),i()},viewportChanged(){if(d)return;const o=e.getPagesInView();o?.length&&(u(o[0]),k.size&&H(),i())},retry(){if(!d){if(y){L();return}j.size!==0&&(j.clear(),B(),i())}},dispose(){d=!0,M&&clearTimeout(M),M=void 0;for(const o of k.values())x(o);I=[],j.clear(),p=void 0}}},le=40,Te=e=>{const t=l.useRef(void 0);return e.initialPage?a.jsx(Ce,{...e,initialPage:e.initialPage,restoreScroll:t.current?.query===e.query?t.current.position:void 0,rememberScroll:c=>{t.current={query:e.query,position:c}}}):a.jsx("div",{className:"make-app-approval-canvas",role:"group","aria-label":"审批记录表格"})},Ce=({components:{Button:e},initialPage:t,query:c,provider:E,themeKey:z,onOpen:B,onReload:L,logger:g,restoreScroll:k,rememberScroll:v})=>{const I=l.useRef(null),h=l.useRef(null),j=l.useRef(null),[p,R]=l.useState(!1),[T,d]=l.useState(0),[y,M]=l.useState({...t,failed:!1,loading:!1}),V=l.useRef(t.rows),s=l.useRef(k),i=l.useRef({provider:E,onOpen:B,onReload:L,logger:g,rememberScroll:v});i.current={provider:E,onOpen:B,onReload:L,logger:g,rememberScroll:v};const x=l.useRef(()=>{});return l.useEffect(()=>{const u=I.current;if(!u)return;let N=!1,D,H,o,r,f,b=t.total;P(i.current.logger,{operation:"table",phase:"start"});const O=()=>{N||(R(!0),P(i.current.logger,{operation:"table",phase:"error"}))};return import("@qfei-design/canvas-table").then(S=>{if(N)return;const F=()=>{const m=h.current,A=m?.getScrollState();m&&A&&S.globalEventBus.emitWithNamespace("scroll:change",m.tableId,A)},K=(m=!1)=>{if(!N)try{const{width:A,height:W}=u.getBoundingClientRect();if(A<=0||W<=0||!m&&f?.width===A&&f.height===W)return;const $=getComputedStyle(u),re={rowHeight:le,headerHeight:40,fontSize:14,fontFamily:$.fontFamily||"Arial, sans-serif",...$.color?{textColor:$.color}:{},...$.getPropertyValue("--make-approval-bg").trim()?{rowBgColor:$.getPropertyValue("--make-approval-bg").trim()}:{},...$.getPropertyValue("--make-approval-header").trim()?{headerBgColor:$.getPropertyValue("--make-approval-header").trim()}:{},...$.getPropertyValue("--make-approval-border").trim()?{borderColor:$.getPropertyValue("--make-approval-border").trim()}:{}},pe=Math.max(Math.ceil(300/c.pageSize),Math.ceil(W*3/le/c.pageSize)+2)*c.pageSize,oe={enabled:!0,totalRowCount:b,pageSize:c.pageSize,maxCachedRows:pe};if(h.current){const w=f?.width!==A?ie(A):void 0;if(h.current.updateProps({canvasWidth:A,canvasHeight:W,style:re,virtualOptions:oe,...w?{columns:w}:{}}),w){const C=h.current.getScrollState(),Y=Math.max(0,w.reduce((U,q)=>U+q.width,te)-A);C&&C.scrollX>Y&&h.current.scrollTo(Y,C.scrollY,!1)}f={width:A,height:W},F();return}h.current=new S.CanvasTableComponent(u,{columns:ie(A),canvasWidth:A,canvasHeight:W,style:re,rowKey:"id",showSN:{enabled:!0,width:te,formatter:(w,C)=>C+1},virtualOptions:oe,selectable:{enabled:!1},rowSortable:{enabled:!1},editApplyMode:"controlled",customEdit:w=>{w.cancel()},emptyStateOptions:{text:"暂无审批记录"},bodyRowHeadSuffixOptions:{enabled:!0,width:20,render:({group:w,x:C,height:Y,rowData:U})=>{const q=U?.id,_=new S.RectShape({name:"approval-open",x:C,y:Y/2-10,cursor:"pointer",tooltip:"查看审批详情",attrs:{width:20,height:20,fill:"transparent",stroke:"transparent"}});_.addChild(new S.ImgShape({name:"approval-open-icon",x:3,y:3,attrs:{width:14,height:14,img:"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="${$.color||"#64748b"}" stroke-width="1.8"><path d="M8 3H3v5m13-5h5v5M3 16v5h5m13-5v5h-5"/></svg>`)}})),_.on("mousedown",ee=>ee.stopPropagation?.()),_.on("click",ee=>{ee.stopPropagation?.();const se=V.current.find(de=>de.id===q);se&&i.current.onOpen(se)}),w.addChild(_)}}});const X=h.current;f={width:A,height:W};const Z=Re({table:X,query:c,initialPage:t,retryViewport:F,onReload:()=>i.current.onReload(),loadPage:(w,C)=>i.current.provider.loadPage(w,C),logger:w=>P(i.current.logger,w),onChange:w=>{N||(b=w.total,V.current=w.rows,M(C=>C.total===w.total&&C.failed===w.failed&&C.loading===w.loading&&C.rows.length===w.rows.length&&C.rows.every((Y,U)=>Y===w.rows[U])?C:w))}});j.current=Z,H=S.globalEventBus.onWithNamespace("data:load",X.tableId,(w,C)=>Z.load(w,C)),o=S.globalEventBus.onWithNamespace("scroll:change",X.tableId,()=>Z.viewportChanged()),s.current&&X.scrollTo(s.current.scrollX,s.current.scrollY),R(!1),P(i.current.logger,{operation:"table",phase:"success"})}catch{O()}};x.current=()=>K(!0);const n=()=>K();D=new ResizeObserver(n),D.observe(u),window.addEventListener("resize",n),r=()=>window.removeEventListener("resize",n),K()}).catch(O),()=>{N=!0,D?.disconnect(),r?.(),x.current=()=>{},h.current&&(s.current=h.current.getScrollState(),s.current&&i.current.rememberScroll(s.current)),H?.(),o?.(),j.current?.dispose(),j.current=null,h.current?.destroy(),h.current=null,P(i.current.logger,{operation:"table",phase:"destroy"})}},[t,c,T]),l.useEffect(()=>{x.current()},[z]),a.jsxs("div",{className:"make-app-approval-table-frame","aria-busy":y.loading,children:[a.jsx("div",{ref:I,className:"make-app-approval-canvas",role:"group","aria-label":"审批记录表格"}),p&&a.jsxs("div",{className:"make-app-approval-overlay",role:"alert",children:["表格加载失败 ",a.jsx(e,{htmlType:"button",variant:"default",onClick:()=>{R(!1),d(u=>u+1)},children:"重新加载表格"})]}),!p&&y.failed&&a.jsxs("div",{className:"make-app-approval-table-feedback",role:"alert",children:["部分审批记录加载失败 ",a.jsx(e,{htmlType:"button",variant:"default",onClick:()=>j.current?.retry(),children:"重试加载"})]}),!p&&!y.failed&&y.loading&&a.jsxs("div",{className:"make-app-approval-table-loading",role:"status","aria-label":"正在加载审批记录","aria-live":"polite",children:[a.jsx("span",{className:"make-app-approval-loading-spinner","aria-hidden":"true"}),a.jsx("span",{children:"加载中"})]}),a.jsxs("ul",{className:"make-app-approval-accessible-rows","aria-label":"审批记录文字视图",children:[y.total===0&&a.jsx("li",{children:"暂无审批记录"}),y.rows.map(u=>a.jsxs("li",{children:[a.jsxs("span",{children:[u.applicationNo,",",u.applicationType,",",u.applicantName,",",u.applicationTime,"。"]}),a.jsxs(e,{htmlType:"button",variant:"text",onClick:()=>B(u),children:["打开 ",u.applicationNo||u.applicationType," 的审批详情"]})]},u.id))]})]})},Me=[],Pe=(e,t,c,E)=>{const[z,B]=l.useState(0),[L,g]=l.useState(),k=l.useRef({provider:e,logger:E});k.current={provider:e,logger:E};const v=l.useMemo(()=>({}),[t,c,z]);l.useEffect(()=>{const h=new AbortController,{provider:j,logger:p}=k.current,R={operation:"list",tab:t.tab,page:t.page,pageSize:t.pageSize};P(p,{...R,phase:"start"});let T=!1;return(async()=>{try{if(await Promise.resolve(),h.signal.aborted)return;const d=await j.loadPage(t,{signal:h.signal});if(h.signal.aborted)return;const y=Q(d,t.pageSize);T=!0,g({...y,token:v,status:"success"}),P(p,{...R,phase:"success",rowCount:y.rows.length})}catch{if(h.signal.aborted)return;T=!0,g({token:v,status:"error",rows:Me,total:0}),P(p,{...R,phase:"error"})}})(),()=>{h.abort(),T||P(p,{...R,phase:"cancel"})}},[t,v]);const I=L?.token===v?L:void 0;return{initialPage:I?.status==="success"?I:void 0,total:I?.total??0,status:I?.status??"loading",reload:()=>B(h=>h+1)}},J={keyword:"",applicantId:"",processStatus:"",startDate:"",endDate:""},Ie=[{value:"pending",label:"待处理"},{value:"approved",label:"已完成"}],G=e=>{if(e==="")return!0;if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;const t=new Date(`${e}T00:00:00Z`);return Number.isFinite(t.getTime())&&t.toISOString().slice(0,10)===e},ze=({components:e,provider:t,onOpenApproval:c,applicantOptions:E=[],pageSize:z=20,refreshKey:B,themeKey:L,logger:g,className:k,presentation:v="desktop"})=>{const{Input:I,Select:h,DateRangePicker:j,Button:p,Tabs:R}=e,T=l.useId(),[d,y]=l.useState(J),[M,V]=l.useState(0),[s,i]=l.useState(""),[x,u]=l.useState(""),[N,D]=l.useState({...J,tab:"pending",page:1,pageSize:z}),{initialPage:H,status:o,reload:r}=Pe(t,N,B,g),f=l.useRef(!1),b=l.useRef(!0);l.useEffect(()=>(b.current=!0,()=>{b.current=!1}),[]);const O=o==="loading",S=async n=>{if(!f.current){f.current=!0,u(""),P(g,{operation:"open",phase:"start"});try{await c(n),P(g,{operation:"open",phase:"success"})}catch{b.current&&u("审批详情打开失败,请重试"),P(g,{operation:"open",phase:"error"})}finally{f.current=!1}}},F=n=>{n!==N.tab&&(i(""),u(""),D(m=>({...m,tab:n,page:1})))},K=n=>{y(m=>({...m,...n})),v==="mobile"&&(i(""),u(""),D(m=>({...m,...n,page:1})))};return a.jsx("section",{className:["make-app-approval",v==="mobile"&&"make-app-approval--mobile",k].filter(Boolean).join(" "),"aria-label":"我的审批",children:a.jsxs(R,{items:Ie,value:N.tab,onChange:F,ariaLabel:"审批分类",children:[a.jsxs("form",{className:"make-app-approval-filters",onSubmit:n=>{if(n.preventDefault(),v==="mobile"){i(""),u(""),D(m=>({...m,keyword:d.keyword.trim(),page:1}));return}if(!G(d.startDate)||!G(d.endDate)){i("请选择有效日期");return}if(d.startDate&&d.endDate&&d.startDate>d.endDate){i("开始日期不能晚于结束日期");return}i(""),u(""),D(m=>({...m,...d,keyword:d.keyword.trim(),page:1}))},children:[a.jsxs("div",{className:"make-app-approval-filter-field",children:[v==="mobile"&&a.jsx(p,{htmlType:"submit",variant:"text",ariaLabel:"搜索申请单ID",children:a.jsxs("svg",{"aria-hidden":"true",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[a.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5"}),a.jsx("path",{d:"m16 16 5 5"})]})}),a.jsx(I,{id:`${T}-keyword`,ariaLabel:"申请单ID",placeholder:"搜索申请单ID",value:d.keyword,onChange:n=>{y(m=>({...m,keyword:n})),v==="mobile"&&!n&&D(m=>({...m,keyword:"",page:1}))}})]}),a.jsx("div",{className:"make-app-approval-date-control",children:a.jsx(j,{id:`${T}-period`,ariaLabel:"申请时间",placeholder:["开始日期","结束日期"],value:[d.startDate,d.endDate],onChange:([n,m])=>{if(v==="mobile"&&(!G(n)||!G(m)||n&&m&&n>m)){i("请选择有效日期范围");return}if(v==="mobile"&&!!n!=!!m){y(A=>({...A,startDate:n,endDate:m}));return}K({startDate:n,endDate:m})}},M)}),a.jsx("div",{className:"make-app-approval-filter-field",children:a.jsx(h,{id:`${T}-applicant`,ariaLabel:"申请人",purpose:"applicant",value:d.applicantId??"",options:[{value:"",label:"全部申请人"},...E.filter(n=>n.value!=="")],onChange:n=>K({applicantId:n})})}),v!=="mobile"&&a.jsxs("div",{className:"make-app-approval-filter-actions",children:[a.jsx(p,{htmlType:"submit",variant:"primary",children:"查询"}),a.jsx(p,{htmlType:"button",variant:"default",onClick:()=>{y(J),V(n=>n+1),i(""),u(""),D(n=>({...n,...J,page:1}))},children:"重置"}),a.jsx(p,{htmlType:"button",variant:"default",disabled:O,loading:O,onClick:r,children:"刷新"})]})]}),s&&a.jsx("p",{role:"alert",className:"make-app-approval-error",children:s}),x&&a.jsx("p",{role:"alert",className:"make-app-approval-error",children:x}),a.jsxs("div",{className:"make-app-approval-results","aria-busy":O,children:[v==="mobile"?H&&a.jsx(ye,{initialPage:H,query:N,provider:t,onReload:r,components:e,onOpen:n=>{S(n)},logger:g},JSON.stringify([N,B,H])):a.jsx(Te,{components:e,initialPage:H,query:N,provider:t,onOpen:n=>{S(n)},onReload:r,themeKey:L,logger:g}),O&&a.jsx("div",{className:"make-app-approval-overlay",role:"status",children:"正在加载审批记录…"}),o==="error"&&a.jsxs("div",{className:"make-app-approval-overlay",role:"alert",children:[a.jsx("span",{children:"审批列表加载失败,请重试"}),a.jsx(p,{htmlType:"button",variant:"default",onClick:r,children:"重试"})]})]})]})})},Ae=e=>{const t=e.pageSize??20;if(!e.scopeKey.trim())throw new Error("MyApprovalsPage requires scopeKey");for(const c of["Input","Select","DateRangePicker","Button","Tabs"])if(!e.components?.[c])throw new Error(`MyApprovalsPage requires components.${c}`);if(!Number.isSafeInteger(t)||t<1||t>200)throw new Error("pageSize must be an integer from 1 to 200");return a.jsx(ze,{...e,pageSize:t},JSON.stringify([e.scopeKey,t]))};exports.MyApprovalsPage=Ae;
1
+ "use strict";var ge=Object.create;var ne=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,ke=Object.prototype.hasOwnProperty;var ye=(e,t,i,R)=>{if(t&&typeof t=="object"||typeof t=="function")for(let z of be(t))!ke.call(e,z)&&z!==i&&ne(e,z,{get:()=>t[z],enumerable:!(R=ve(t,z))||R.enumerable});return e};var xe=(e,t,i)=>(i=e!=null?ge(we(e)):{},ye(t||!e||!e.__esModule?ne(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),c=require("react"),Se=require("./index.cjs"),de=e=>typeof e=="object"&&e!==null,je=e=>de(e)?["id","entityKey","recordId"].every(t=>typeof e[t]=="string"&&e[t].trim().length>0)&&["applicationNo","applicationType","applicantName","applicationTime"].every(t=>typeof e[t]=="string")&&["taskId","processInstanceId"].every(t=>e[t]===void 0||typeof e[t]=="string"&&e[t].trim().length>0)&&["completionTime","completionResult"].every(t=>e[t]===void 0||typeof e[t]=="string")&&(e.referenceType===void 0||e.referenceType==="task"||e.referenceType==="instance")&&(e.referenceType!=="instance"||typeof e.processInstanceId=="string"&&e.processInstanceId.trim().length>0)&&(typeof e.processStatus=="string"||e.processStatus===null):!1,Q=(e,t)=>{if(!de(e)||!Array.isArray(e.rows)||!e.rows.every(je)||typeof e.total!="number"||!Number.isSafeInteger(e.total)||e.total<0||e.rows.length>t||e.rows.length>e.total||new Set(e.rows.map(i=>i.id)).size!==e.rows.length)throw new Error("Invalid approval page contract");return{rows:e.rows,total:e.total}},A=(e,t)=>{try{e?e(t):t.phase==="error"?console.warn("[make-app-approval]",t):console.info("[make-app-approval]",t)}catch{console.warn("[make-app-approval] diagnostic sink failed")}},ae=e=>e==null||e==="UNSUBMITTED"?"状态未知":Se.getApprovalStatusDisplay(e).label,Ne=({initialPage:e,query:t,provider:i,components:R,onOpen:z,onReload:M,logger:E})=>{const[v,x]=c.useState(e),[w,P]=c.useState(2),[d,j]=c.useState("idle"),h=c.useRef(void 0),[S,L]=c.useState(!1),N=c.useRef(void 0);c.useEffect(()=>()=>{N.current?.abort()},[]);const p=async()=>{if(N.current||v.rows.length>=v.total)return;const s=new AbortController;N.current=s,j("loading");const f={operation:"list",tab:t.tab,page:w,pageSize:t.pageSize};A(E,{...f,phase:"start"});try{const u=Q(await i.loadPage({...t,page:w},{signal:s.signal}),t.pageSize);if(s.signal.aborted)return;if(u.total<v.total){A(E,{...f,phase:"skip",rowCount:u.rows.length}),M();return}const m=new Set(v.rows.map(T=>T.id));if(!u.rows.length||u.rows.some(T=>m.has(T.id)))throw new Error("Invalid append page");x({rows:[...v.rows,...u.rows],total:u.total}),P(T=>T+1),j("idle"),A(E,{...f,phase:"success",rowCount:u.rows.length})}catch{s.signal.aborted||(j("error"),A(E,{...f,phase:"error"}))}finally{N.current===s&&(N.current=void 0)}},C=s=>{const{scrollHeight:f,scrollTop:u,clientHeight:m}=s.currentTarget;d==="idle"&&f-u-m<120&&p()},{Button:D}=R;return a.jsxs("div",{className:"make-app-approval-mobile-list",onScroll:C,onTouchStart:s=>{h.current=s.currentTarget.scrollTop<=0&&s.touches.length===1&&d!=="loading"?{start:s.touches[0].clientY,distance:0}:void 0},onTouchMove:s=>{!h.current||s.touches.length!==1||(h.current.distance=s.touches[0].clientY-h.current.start,L(h.current.distance>=60))},onTouchEnd:()=>{const s=(h.current?.distance??0)>=60;h.current=void 0,L(!1),s&&M()},onTouchCancel:()=>{h.current=void 0,L(!1)},"aria-label":"审批卡片列表","aria-busy":d==="loading",children:[S&&a.jsx("p",{role:"status",className:"make-app-approval-mobile-feedback",children:"松开刷新"}),v.rows.map(s=>a.jsxs("button",{type:"button",className:"make-app-approval-mobile-card",onClick:()=>z(s),"aria-label":`打开 ${s.applicationNo} 的审批详情`,children:[a.jsx("strong",{children:s.applicationType||"审批申请"}),a.jsxs("span",{className:"make-app-approval-mobile-card-line",children:[a.jsx("span",{children:"申请单ID:"}),a.jsx("span",{children:s.applicationNo})]}),t.tab==="approved"&&a.jsxs("span",{className:"make-app-approval-mobile-card-line",children:[a.jsx("span",{children:"审批结果:"}),a.jsx("span",{children:s.completionResult||"—"})]}),t.tab==="initiated"&&a.jsxs("span",{className:"make-app-approval-mobile-card-line",children:[a.jsx("span",{children:"流程状态:"}),a.jsx("span",{children:ae(s.processStatus)})]}),a.jsxs("span",{className:"make-app-approval-mobile-card-footer",children:[a.jsxs("span",{className:"make-app-approval-mobile-person",children:[a.jsx("span",{className:"make-app-approval-mobile-avatar","aria-hidden":"true",children:s.applicantName.slice(-2)}),a.jsx("span",{children:s.applicantName||"—"})]}),a.jsx("span",{children:t.tab==="approved"?`完成于 ${s.completionTime||"—"}`:`申请于 ${s.applicationTime||"—"}`})]})]},s.id)),!v.rows.length&&a.jsx("p",{className:"make-app-approval-mobile-feedback",children:"暂无审批记录"}),d==="error"?a.jsxs("div",{role:"alert",className:"make-app-approval-mobile-feedback",children:["部分审批记录加载失败",a.jsx(D,{htmlType:"button",variant:"text",onClick:()=>{p()},children:"重试加载"})]}):d==="loading"?a.jsx("p",{role:"status",className:"make-app-approval-mobile-feedback",children:"加载中"}):v.rows.length<v.total?a.jsx(D,{htmlType:"button",variant:"text",onClick:()=>{p()},children:"加载更多"}):v.rows.length>0&&a.jsx("p",{className:"make-app-approval-mobile-feedback",children:"没有更多了"})]})},Te={applicationNo:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1d212a" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-fingerprint-pattern" aria-hidden="true"><path d="M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4"></path><path d="M14 13.12c0 2.38 0 6.38-1 8.88"></path><path d="M17.29 21.02c.12-.6.43-2.3.5-3.02"></path><path d="M2 12a10 10 0 0 1 18-6"></path><path d="M2 16h.01"></path><path d="M21.8 16c.2-2 .131-5.354 0-6"></path><path d="M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2"></path><path d="M8.65 22c.21-.66.45-1.32.57-2"></path><path d="M9 6.8a6 6 0 0 1 9 5.2v2"></path></svg>',applicationType:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1d212a" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-type" aria-hidden="true"><path d="M12 4v16"></path><path d="M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"></path><path d="M9 20h6"></path></svg>',applicantName:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1d212a" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-user-round" aria-hidden="true"><circle cx="12" cy="8" r="5"></circle><path d="M20 21a8 8 0 0 0-16 0"></path></svg>',applicationTime:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1d212a" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-calendar-clock" aria-hidden="true"><path d="M16 14v2.2l1.6 1"></path><path d="M16 2v3"></path><path d="M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338"></path><path d="M3 9h5.859"></path><path d="M8 2v3"></path><circle cx="16" cy="16" r="6"></circle></svg>'},ie=Object.fromEntries(Object.entries(Te).map(([e,t])=>[e,`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`])),te=64,le=[{key:"applicationNo",title:"申请单ID",width:260},{key:"applicationType",title:"业务表单",width:180},{key:"applicantName",title:"申请人",width:170},{key:"applicationTime",title:"申请时间",width:220}],ce=(e,t)=>{const i=t==="initiated"?[...le,{key:"statusLabel",title:"流程状态",width:140}]:le,R=i.reduce((M,E)=>M+E.width,te),z=Math.max(0,e-R)/i.length;return i.map(M=>({...M,width:M.width+z,showEllipsis:!0,sortable:!1,prefixRender:()=>({icon:ie[M.key]??ie.applicationType})}))},Re=({table:e,query:t,initialPage:i,loadPage:R,onChange:z,retryViewport:M,onReload:E,logger:v})=>{const x=new Map,w=new Set;let P=[];const d=new WeakMap,j=new Set;let h=i,S=i.total,L=0,N=!1,p=!1,C;const D=o=>Number.isSafeInteger(o)&&o>=0&&o*t.pageSize<S,s=(o,r,g)=>A(v,{operation:"list",phase:r,tab:t.tab,page:o+1,pageSize:t.pageSize,rowCount:g}),f=()=>{N||z({total:S,rows:P,failed:p||j.size>0,loading:x.size>0})},u=o=>{o.finished||(o.finished=!0,o.removeAbort(),x.get(o.page)===o&&x.delete(o.page),e.markPageLoadFailed(o.page,o.request),o.controller.abort(),s(o.page,"cancel"))},m=o=>{L=o;const r=e.getPagesInView()??[],g=new Set([L,...r].flatMap(k=>[k-1,k,k+1]).filter(D));for(const k of x.values())g.has(k.page)||u(k);for(const k of j)g.has(k)||j.delete(k)},T=(o,r,g)=>{const k=r.rows.map(b=>{const $={...b,statusLabel:ae(b.processStatus)};return d.set($,b),$});if(!e.setVirtualPageData(k,o,r.total,g)){s(o,"skip");return}S=r.total;try{P=Q({rows:e.getTableData()??[],total:S},Number.MAX_SAFE_INTEGER).rows.map(b=>d.get(b)??b)}catch(b){p=!0,P=[],h=void 0,C&&clearTimeout(C),C=void 0;for(const $ of x.values())u($);throw b}h&&h.total!==S&&(h=void 0),j.delete(o);for(const b of x.values())D(b.page)||u(b);!D(o)&&o>0&&e.scrollToRow(Math.max(0,S-1)),s(o,"success",r.rows.length)},B=()=>{if(N||C)return;const o=[...x.values()].filter(r=>!r.running&&!r.finished).sort((r,g)=>Math.abs(r.page-L)-Math.abs(g.page-L)||r.page-g.page);for(const r of o){if(w.size>=2)break;r.running=!0,w.add(r),s(r.page,"start"),(async()=>{try{const g=await R({...t,page:r.page+1},{signal:r.controller.signal});if(N||r.finished||r.controller.signal.aborted)return;const k=Q(g,t.pageSize);r.finished=!0,r.removeAbort(),x.delete(r.page),T(r.page,k,r.request)}catch{!N&&!r.controller.signal.aborted&&(j.add(r.page),s(r.page,"error"),e.markPageLoadFailed(r.page,r.request))}finally{r.finished||(r.finished=!0,r.removeAbort(),x.get(r.page)===r&&x.delete(r.page)),w.delete(r),f(),B()}})()}f()},O=()=>{C&&clearTimeout(C),C=setTimeout(()=>{C=void 0,B()},120)};return{load(o,r){if(r.useRequestIdentity(),N||p||r.signal.aborted||!D(o)){e.markPageLoadFailed(o,r),s(o,"skip");return}const g=x.get(o);if(g?.request===r&&!g.finished)return;if(g&&u(g),m(o),o===0&&h){const b=h;h=void 0;try{T(0,b,r)}catch{j.add(o),e.markPageLoadFailed(o,r),s(o,"error")}f();return}const k={page:o,request:r,controller:new AbortController,running:!1,finished:!1,removeAbort:()=>{}},V=()=>{u(k),f()};r.signal.addEventListener("abort",V,{once:!0}),k.removeAbort=()=>r.signal.removeEventListener("abort",V),x.set(o,k),O(),f()},viewportChanged(){if(N)return;const o=e.getPagesInView();o?.length&&(m(o[0]),x.size&&O(),f())},retry(){if(!N){if(p){E();return}j.size!==0&&(j.clear(),M(),f())}},dispose(){N=!0,C&&clearTimeout(C),C=void 0;for(const o of x.values())u(o);P=[],j.clear(),h=void 0}}},pe=40,Ce=e=>{const t=c.useRef(void 0);return e.initialPage?a.jsx(Me,{...e,initialPage:e.initialPage,restoreScroll:t.current?.query===e.query?t.current.position:void 0,rememberScroll:i=>{t.current={query:e.query,position:i}}}):a.jsx("div",{className:"make-app-approval-canvas",role:"group","aria-label":"审批记录表格"})},Me=({components:{Button:e},initialPage:t,query:i,provider:R,themeKey:z,onOpen:M,onReload:E,logger:v,restoreScroll:x,rememberScroll:w})=>{const P=c.useRef(null),d=c.useRef(null),j=c.useRef(null),[h,S]=c.useState(!1),[L,N]=c.useState(0),[p,C]=c.useState({...t,failed:!1,loading:!1}),D=c.useRef(t.rows),s=c.useRef(x),f=c.useRef({provider:R,onOpen:M,onReload:E,logger:v,rememberScroll:w});f.current={provider:R,onOpen:M,onReload:E,logger:v,rememberScroll:w};const u=c.useRef(()=>{});return c.useEffect(()=>{const m=P.current;if(!m)return;let T=!1,B,O,o,r,g,k=t.total;A(f.current.logger,{operation:"table",phase:"start"});const V=()=>{T||(S(!0),A(f.current.logger,{operation:"table",phase:"error"}))};return import("@qfei-design/canvas-table").then(b=>{if(T)return;const $=()=>{const n=d.current,l=n?.getScrollState();n&&l&&b.globalEventBus.emitWithNamespace("scroll:change",n.tableId,l)},Y=(n=!1)=>{if(!T)try{const{width:l,height:F}=m.getBoundingClientRect();if(l<=0||F<=0||!n&&g?.width===l&&g.height===F)return;const H=getComputedStyle(m),re={rowHeight:pe,headerHeight:40,fontSize:14,fontFamily:H.fontFamily||"Arial, sans-serif",...H.color?{textColor:H.color}:{},...H.getPropertyValue("--make-approval-bg").trim()?{rowBgColor:H.getPropertyValue("--make-approval-bg").trim()}:{},...H.getPropertyValue("--make-approval-header").trim()?{headerBgColor:H.getPropertyValue("--make-approval-header").trim()}:{},...H.getPropertyValue("--make-approval-border").trim()?{borderColor:H.getPropertyValue("--make-approval-border").trim()}:{}},fe=Math.max(Math.ceil(300/i.pageSize),Math.ceil(F*3/pe/i.pageSize)+2)*i.pageSize,oe={enabled:!0,totalRowCount:k,pageSize:i.pageSize,maxCachedRows:fe};if(d.current){const y=g?.width!==l?ce(l,i.tab):void 0;if(d.current.updateProps({canvasWidth:l,canvasHeight:F,style:re,virtualOptions:oe,...y?{columns:y}:{}}),y){const I=d.current.getScrollState(),K=Math.max(0,y.reduce((U,q)=>U+q.width,te)-l);I&&I.scrollX>K&&d.current.scrollTo(K,I.scrollY,!1)}g={width:l,height:F},$();return}d.current=new b.CanvasTableComponent(m,{columns:ce(l,i.tab),canvasWidth:l,canvasHeight:F,style:re,rowKey:"id",showSN:{enabled:!0,width:te,formatter:(y,I)=>I+1},virtualOptions:oe,selectable:{enabled:!1},rowSortable:{enabled:!1},editApplyMode:"controlled",customEdit:y=>{y.cancel()},emptyStateOptions:{text:"暂无审批记录"},bodyRowHeadSuffixOptions:{enabled:!0,width:20,render:({group:y,x:I,height:K,rowData:U})=>{const q=U?.id,_=new b.RectShape({name:"approval-open",x:I,y:K/2-10,cursor:"pointer",tooltip:"查看审批详情",attrs:{width:20,height:20,fill:"transparent",stroke:"transparent"}});_.addChild(new b.ImgShape({name:"approval-open-icon",x:3,y:3,attrs:{width:14,height:14,img:"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="${H.color||"#64748b"}" stroke-width="1.8"><path d="M8 3H3v5m13-5h5v5M3 16v5h5m13-5v5h-5"/></svg>`)}})),_.on("mousedown",ee=>ee.stopPropagation?.()),_.on("click",ee=>{ee.stopPropagation?.();const se=D.current.find(me=>me.id===q);se&&f.current.onOpen(se)}),y.addChild(_)}}});const X=d.current;g={width:l,height:F};const Z=Re({table:X,query:i,initialPage:t,retryViewport:$,onReload:()=>f.current.onReload(),loadPage:(y,I)=>f.current.provider.loadPage(y,I),logger:y=>A(f.current.logger,y),onChange:y=>{T||(k=y.total,D.current=y.rows,C(I=>I.total===y.total&&I.failed===y.failed&&I.loading===y.loading&&I.rows.length===y.rows.length&&I.rows.every((K,U)=>K===y.rows[U])?I:y))}});j.current=Z,O=b.globalEventBus.onWithNamespace("data:load",X.tableId,(y,I)=>Z.load(y,I)),o=b.globalEventBus.onWithNamespace("scroll:change",X.tableId,()=>Z.viewportChanged()),s.current&&X.scrollTo(s.current.scrollX,s.current.scrollY),S(!1),A(f.current.logger,{operation:"table",phase:"success"})}catch{V()}};u.current=()=>Y(!0);const W=()=>Y();B=new ResizeObserver(W),B.observe(m),window.addEventListener("resize",W),r=()=>window.removeEventListener("resize",W),Y()}).catch(V),()=>{T=!0,B?.disconnect(),r?.(),u.current=()=>{},d.current&&(s.current=d.current.getScrollState(),s.current&&f.current.rememberScroll(s.current)),O?.(),o?.(),j.current?.dispose(),j.current=null,d.current?.destroy(),d.current=null,A(f.current.logger,{operation:"table",phase:"destroy"})}},[t,i,L]),c.useEffect(()=>{u.current()},[z]),a.jsxs("div",{className:"make-app-approval-table-frame","aria-busy":p.loading,children:[a.jsx("div",{ref:P,className:"make-app-approval-canvas",role:"group","aria-label":"审批记录表格"}),h&&a.jsxs("div",{className:"make-app-approval-overlay",role:"alert",children:["表格加载失败 ",a.jsx(e,{htmlType:"button",variant:"default",onClick:()=>{S(!1),N(m=>m+1)},children:"重新加载表格"})]}),!h&&p.failed&&a.jsxs("div",{className:"make-app-approval-table-feedback",role:"alert",children:["部分审批记录加载失败 ",a.jsx(e,{htmlType:"button",variant:"default",onClick:()=>j.current?.retry(),children:"重试加载"})]}),!h&&!p.failed&&p.loading&&a.jsxs("div",{className:"make-app-approval-table-loading",role:"status","aria-label":"正在加载审批记录","aria-live":"polite",children:[a.jsx("span",{className:"make-app-approval-loading-spinner","aria-hidden":"true"}),a.jsx("span",{children:"加载中"})]}),a.jsxs("ul",{className:"make-app-approval-accessible-rows","aria-label":"审批记录文字视图",children:[p.total===0&&a.jsx("li",{children:"暂无审批记录"}),p.rows.map(m=>a.jsxs("li",{children:[a.jsxs("span",{children:[m.applicationNo,",",m.applicationType,",",m.applicantName,",",m.applicationTime,i.tab==="initiated"?`,${ae(m.processStatus)}`:"","。"]}),a.jsxs(e,{htmlType:"button",variant:"text",onClick:()=>M(m),children:["打开 ",m.applicationNo||m.applicationType," 的审批详情"]})]},m.id))]})]})},Pe=[],Ie=(e,t,i,R)=>{const[z,M]=c.useState(0),[E,v]=c.useState(),x=c.useRef({provider:e,logger:R});x.current={provider:e,logger:R};const w=c.useMemo(()=>({}),[t,i,z]);c.useEffect(()=>{const d=new AbortController,{provider:j,logger:h}=x.current,S={operation:"list",tab:t.tab,page:t.page,pageSize:t.pageSize};A(h,{...S,phase:"start"});let L=!1;return(async()=>{try{if(await Promise.resolve(),d.signal.aborted)return;const N=await j.loadPage(t,{signal:d.signal});if(d.signal.aborted)return;const p=Q(N,t.pageSize);L=!0,v({...p,token:w,status:"success"}),A(h,{...S,phase:"success",rowCount:p.rows.length})}catch{if(d.signal.aborted)return;L=!0,v({token:w,status:"error",rows:Pe,total:0}),A(h,{...S,phase:"error"})}})(),()=>{d.abort(),L||A(h,{...S,phase:"cancel"})}},[t,w]);const P=E?.token===w?E:void 0;return{initialPage:P?.status==="success"?P:void 0,total:P?.total??0,status:P?.status??"loading",reload:()=>M(d=>d+1)}},J={keyword:"",applicantId:"",processStatus:"",startDate:"",endDate:""},ue=["pending","approved"],he={pending:"待处理",approved:"已完成",initiated:"已发起"},G=e=>{if(e==="")return!0;if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;const t=new Date(`${e}T00:00:00Z`);return Number.isFinite(t.getTime())&&t.toISOString().slice(0,10)===e},ze=({components:e,provider:t,onOpenApproval:i,applicantOptions:R=[],pageSize:z=20,refreshKey:M,themeKey:E,logger:v,className:x,presentation:w="desktop",tabs:P=ue})=>{const{Input:d,Select:j,DateRangePicker:h,Button:S,Tabs:L}=e,N=c.useId(),[p,C]=c.useState(J),[D,s]=c.useState(0),[f,u]=c.useState(""),[m,T]=c.useState(""),[B,O]=c.useState({...J,tab:P[0],page:1,pageSize:z}),{initialPage:o,status:r,reload:g}=Ie(t,B,M,v),k=c.useRef(!1),V=c.useRef(!0);c.useEffect(()=>(V.current=!0,()=>{V.current=!1}),[]);const b=r==="loading",$=async n=>{if(!k.current){k.current=!0,T(""),A(v,{operation:"open",phase:"start"});try{await i(n),A(v,{operation:"open",phase:"success"})}catch{V.current&&T("审批详情打开失败,请重试"),A(v,{operation:"open",phase:"error"})}finally{k.current=!1}}},Y=n=>{n===B.tab||!P.includes(n)||(u(""),T(""),n==="initiated"&&C(l=>({...l,keyword:"",applicantId:"",processStatus:""})),O(l=>({...l,...n==="initiated"?{keyword:"",applicantId:"",processStatus:""}:{},tab:n,page:1})))},W=n=>{C(l=>({...l,...n})),w==="mobile"&&(u(""),T(""),O(l=>({...l,...n,page:1})))};return a.jsx("section",{className:["make-app-approval",w==="mobile"&&"make-app-approval--mobile",x].filter(Boolean).join(" "),"aria-label":"我的审批",children:a.jsxs(L,{items:P.map(n=>({value:n,label:he[n]})),value:B.tab,onChange:Y,ariaLabel:"审批分类",children:[a.jsxs("form",{className:"make-app-approval-filters",onSubmit:n=>{if(n.preventDefault(),w==="mobile"){u(""),T(""),O(l=>({...l,keyword:p.keyword.trim(),page:1}));return}if(!G(p.startDate)||!G(p.endDate)){u("请选择有效日期");return}if(p.startDate&&p.endDate&&p.startDate>p.endDate){u("开始日期不能晚于结束日期");return}u(""),T(""),O(l=>({...l,...p,keyword:p.keyword.trim(),page:1}))},children:[B.tab!=="initiated"&&a.jsxs("div",{className:"make-app-approval-filter-field",children:[w==="mobile"&&a.jsx(S,{htmlType:"submit",variant:"text",ariaLabel:"搜索申请单ID",children:a.jsxs("svg",{"aria-hidden":"true",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[a.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5"}),a.jsx("path",{d:"m16 16 5 5"})]})}),a.jsx(d,{id:`${N}-keyword`,ariaLabel:"申请单ID",placeholder:"搜索申请单ID",value:p.keyword,onChange:n=>{C(l=>({...l,keyword:n})),w==="mobile"&&!n&&O(l=>({...l,keyword:"",page:1}))}})]}),a.jsx("div",{className:"make-app-approval-date-control",children:a.jsx(h,{id:`${N}-period`,ariaLabel:"申请时间",placeholder:["开始日期","结束日期"],value:[p.startDate,p.endDate],onChange:([n,l])=>{if(w==="mobile"&&(!G(n)||!G(l)||n&&l&&n>l)){u("请选择有效日期范围");return}if(w==="mobile"&&!!n!=!!l){C(F=>({...F,startDate:n,endDate:l}));return}W({startDate:n,endDate:l})}},D)}),B.tab!=="initiated"&&a.jsx("div",{className:"make-app-approval-filter-field",children:a.jsx(j,{id:`${N}-applicant`,ariaLabel:"申请人",purpose:"applicant",value:p.applicantId??"",options:[{value:"",label:"全部申请人"},...R.filter(n=>n.value!=="")],onChange:n=>W({applicantId:n})})}),w!=="mobile"&&a.jsxs("div",{className:"make-app-approval-filter-actions",children:[a.jsx(S,{htmlType:"submit",variant:"primary",children:"查询"}),a.jsx(S,{htmlType:"button",variant:"default",onClick:()=>{C(J),s(n=>n+1),u(""),T(""),O(n=>({...n,...J,page:1}))},children:"重置"}),a.jsx(S,{htmlType:"button",variant:"default",disabled:b,loading:b,onClick:g,children:"刷新"})]})]}),f&&a.jsx("p",{role:"alert",className:"make-app-approval-error",children:f}),m&&a.jsx("p",{role:"alert",className:"make-app-approval-error",children:m}),a.jsxs("div",{className:"make-app-approval-results","aria-busy":b,children:[w==="mobile"?o&&a.jsx(Ne,{initialPage:o,query:B,provider:t,onReload:g,components:e,onOpen:n=>{$(n)},logger:v},JSON.stringify([B,M,o])):a.jsx(Ce,{components:e,initialPage:o,query:B,provider:t,onOpen:n=>{$(n)},onReload:g,themeKey:E,logger:v}),b&&a.jsx("div",{className:"make-app-approval-overlay",role:"status",children:"正在加载审批记录…"}),r==="error"&&a.jsxs("div",{className:"make-app-approval-overlay",role:"alert",children:[a.jsx("span",{children:"审批列表加载失败,请重试"}),a.jsx(S,{htmlType:"button",variant:"default",onClick:g,children:"重试"})]})]})]})})},Ae=e=>{const t=e.pageSize??20,i=e.tabs??ue;if(!i.length||new Set(i).size!==i.length||i.some(R=>!Object.hasOwn(he,R)))throw new Error("MyApprovalsPage requires valid unique tabs");if(!e.scopeKey.trim())throw new Error("MyApprovalsPage requires scopeKey");for(const R of["Input","Select","DateRangePicker","Button","Tabs"])if(!e.components?.[R])throw new Error(`MyApprovalsPage requires components.${R}`);if(!Number.isSafeInteger(t)||t<1||t>200)throw new Error("pageSize must be an integer from 1 to 200");return a.jsx(ze,{...e,tabs:i,pageSize:t},JSON.stringify([e.scopeKey,t,i]))};exports.MyApprovalsPage=Ae;