1 line
852 B
JavaScript
1 line
852 B
JavaScript
import{n as e}from"./rolldown-runtime-Dl_DZoUm.js";import{tr as t}from"./index-D422TGjj.js";var n=e(t(),1);function r(e,t,r){let[i,a]=(0,n.useState)({});return(0,n.useEffect)(()=>{let n=!0;async function i(i){if(i.key!==`ledger-print-status-changed`||!i.newValue)return;let o;try{o=JSON.parse(i.newValue)}catch{return}if(o?.user===t&&[`order`,`recovery`].includes(o.kind)&&/^[a-f0-9-]{36}$/.test(o.id))try{let t=await e.api(`/api/print-status/`+o.kind+`/`+o.id),r=t?.kind===o.kind&&t.id===o.id,i=o.kind===`order`&&t?.kind===`recovery`&&/^[a-f0-9-]{36}$/.test(t.id);if(!r&&!i||typeof t.printed!=`boolean`)throw Error(`打印状态与所选单据不一致,请重新读取。`);n&&a(e=>({...e,[t.id]:t}))}catch(e){n&&r(e.message)}}return window.addEventListener(`storage`,i),()=>{n=!1,window.removeEventListener(`storage`,i)}},[e,t,r]),i}export{r as t}; |