You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
9.2 KiB
2 lines
9.2 KiB
import{j as l}from"./markdown-vendor-BZI_VWzW.js";import{u as oe,r as i}from"./data-vendor-BOGugMqL.js";import{g as ue}from"./react-vendor-CmPQC3tV.js";import{M as J,j as X,N as de,o as ee,O as fe,i as me}from"./index-RTMDNWJ5.js";import{M as ge}from"./arco-vendor-gN7EHfgO.js";const T=20,pe=3e3,ye=120,te="myCreations:taskCreated",re=[{title:"all",type:0},{title:"image",type:1},{title:"video",type:2},{title:"template",type:4}];function V(d){if(d==null||d==="")return 0;if(typeof d=="number")return d<1e11?d*1e3:d;const a=Date.parse(String(d));return Number.isNaN(a)?0:a}function M(d){const a=d?.id??d?.taskId;return a==null||a===""?"":String(a)}function j(d){return d?.data?.list??[]}function A(d,a){const p={...d};return a===0&&delete p.type,a===1&&(p.subType="102,103,107,108"),a===0&&(p.subType="102,103,107,108,202,203,204,205"),a===4?(delete p.type,fe(p)):me(p)}function _e(d){let a=d?.parentElement??null;for(;a!=null;){const b=window.getComputedStyle(a).overflowY;if((b==="auto"||b==="scroll")&&a.scrollHeight>a.clientHeight)return a;a=a.parentElement}return null}function ve({tabIdPrefix:d}){const{t:a}=oe(),[p,b]=ue(),D=p.get(J),[o,B]=i.useState(0),[v,P]=i.useState([]),[q,F]=i.useState(1),[w,L]=i.useState(!0),[C,G]=i.useState(!1),[Y,K]=i.useState(!1),[O,$]=i.useState(null),Z=i.useRef(null),H=i.useRef(!1),g=i.useRef(!1),f=i.useRef(0),I=i.useRef(0),z=i.useRef(new Set),k=i.useRef(a);k.current=a;const Q=i.useRef(async()=>{}),se=X(Date.now(),"YYYY-MM-DD"),U=i.useMemo(()=>{const e=v.filter(t=>{const s=Number(t?.type);return Number.isFinite(s)&&s<=0?!1:t.status==0||t.status==1?Number(t.batchSize||0)>0:t.status!=2||!Array.isArray(t.resultList)||t.resultList.length===0?!1:o===2?t.resultList.some(n=>n?.video):o===0?t.resultList.some(n=>n?.video||n?.images?.[0]):o===4?t.type==1?t.resultList.some(n=>n?.images?.[0]):t.type==2?t.resultList.some(n=>n?.video):t.resultList.some(n=>n?.images?.[0]||n?.video):t.resultList.some(n=>n?.images?.[0])}).sort((t,s)=>V(s?.createTime)-V(t?.createTime)),r=new Map;for(const t of e){const s=V(t?.createTime),n=s>0?X(s,"YYYY-MM-DD"):"unknown";r.has(n)||r.set(n,[]),r.get(n).push(t)}return[...r.entries()].map(([t,s])=>({dateKey:t,taskList:s}))},[v,o]),R=i.useMemo(()=>{const e=new Set;for(const r of v){const t=Number(r?.type??r?.taskType);if(Number.isFinite(t)&&t<=0)continue;const s=M(r);s&&(r.status==0||r.status==1)&&e.add(s)}return[...e].sort().join(",")},[v]),W=i.useRef(R);W.current=R;const E=i.useRef(o);E.current=o,i.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),i.useEffect(()=>{const e=r=>{const t=r.detail,s=Number(t?.type);if(!Number.isFinite(s)||s!==E.current)return;const n=f.current;A({type:s,page:1,pageSize:T,status_min:0},s).then(u=>{if(!g.current||f.current!==n)return;const c=j(u);P(c),F(1),L(c.length>=T),$(null)}).catch(()=>{})};return window.addEventListener(te,e),()=>{window.removeEventListener(te,e)}},[]),i.useEffect(()=>{const e=p.get("type");if(e==null)return;const r=Number(e);Number.isFinite(r)&&r!==E.current&&re.some(t=>t.type===r)&&B(r)},[p]),i.useEffect(()=>{let e=!1;f.current+=1,z.current.clear();const r=f.current;F(1),L(!0),P([]),G(!0),$(null);const s=D!=null&&D!==""?ye:0,n=()=>{e||f.current!==r||A({type:o,page:1,pageSize:T,status_min:0},o).then(c=>{if(e||!g.current||f.current!==r)return;const m=j(c);P(m),L(m.length>=T)}).catch(c=>{e||!g.current||f.current!==r||($(c instanceof Error?c:new Error(String(c))),P([]),L(!1))}).finally(()=>{!e&&g.current&&f.current===r&&G(!1)})};let u;return s===0?n():u=window.setTimeout(n,s),()=>{e=!0,u!==void 0&&window.clearTimeout(u)}},[o,D]),i.useEffect(()=>{if(!R)return;const e=f.current;let r=!0;const t=++I.current;async function s(){if(!r||!g.current||I.current!==t||f.current!==e)return;const c=W.current.split(",").filter(Boolean);if(c.length===0)return;const m=E.current;try{const _=c.join(","),x=await A(m===4?{idList:_,type:m}:{ids:_,type:m},m);if(!r||!g.current||I.current!==t||f.current!==e)return;const h=j(x);if(h.length===0)return;const S=new Map;for(const y of h){const N=M(y);N&&(S.set(N,y),(y.status==-1||y.status==-2)&&!z.current.has(N)&&(z.current.add(N),ge.error(y.userErrorTipMsg||k.current("pages.create.panels.myCreations.taskFailedFallback"))))}P(y=>y.map(N=>S.get(M(N))??N))}catch{}}s();const n=window.setInterval(()=>void s(),pe);return()=>{r=!1,I.current+=1,window.clearInterval(n)}},[R,o]);const ne=i.useCallback(async()=>{if(!w||H.current||C||Y)return;H.current=!0,K(!0);const e=f.current,r=q+1;try{const t=await A({type:o,page:r,pageSize:T,status_min:0},o);if(!g.current||f.current!==e)return;const s=j(t);s.length===0?L(!1):(P(n=>[...n,...s]),F(r),L(s.length>=T))}catch{g.current&&f.current===e&&L(!1)}finally{H.current=!1,g.current&&f.current===e&&K(!1)}},[w,C,Y,q,o]);Q.current=ne,i.useEffect(()=>{const e=Z.current;if(!e||!w||C)return;const r=_e(e),t=new IntersectionObserver(s=>{s[0]?.isIntersecting&&Q.current()},{root:r,rootMargin:"160px",threshold:0});return t.observe(e),()=>t.disconnect()},[w,C,v.length]);const ae=i.useCallback(e=>{B(e),b(r=>{const t=new URLSearchParams(r);return t.set("type",String(e)),t.delete(J),t},{replace:!0})},[b]),ie=i.useCallback(async e=>{const r=String(e?.id??e?.assetId??""),t=s=>{if(!g.current)return;const n=String(s||r);n&&P(u=>u.map(c=>{if(c.status!=2||!Array.isArray(c.resultList))return c;const m=c.resultList.filter(_=>String(_?.id??_?.assetId??"")!==n);return m.length===c.resultList.length?c:{...c,resultList:m}}).filter(c=>c.status!=2||!Array.isArray(c.resultList)||c.resultList.length>0))};try{if(o==4){const s=await de(e.id??e.assetId);if(!g.current)return;const n=s?.data?.id;if(n==null||n==="")return;ee({assetId:n,onDeleted:t});return}r&&ee({assetId:r,onDeleted:t})}catch{}},[o]),ce=i.useCallback(e=>{const r=e.currentTarget.querySelector("video");r&&r.play().catch(()=>{})},[]),le=i.useCallback(e=>{e.currentTarget.querySelector("video")?.pause()},[]);return l.jsxs("div",{className:"createPage__panelShell createPage__myCreationsWrap",children:[l.jsx("div",{className:"createPage__subRow",children:l.jsx("div",{className:"createPage__filters",role:"group","aria-label":a("pages.create.filtersAria"),"data-active-tab":o,children:re.map(e=>{const r=o===e.type;return l.jsx("button",{type:"button","data-type":e.type,"data-selected":r,"aria-pressed":r,className:r?"createPage__filterPill createPage__filterPill_active":"createPage__filterPill",onClick:()=>ae(e.type),children:a(`pages.create.filters.${e.title}`)},e.type)})})}),l.jsxs("section",{className:"createPage__panel createPage__panelScroll createPage__panel_below_filters",id:`${d}-panel-myCreations`,role:"tabpanel","aria-labelledby":`${d}-tab-myCreations`,children:[C&&v.length===0?l.jsx("p",{className:"createPage__panelStatus",children:a("common.loading")}):null,O?l.jsx("p",{className:"createPage__panelStatus createPage__panelStatus_error",children:O.message}):null,!C&&!O&&U.length===0?l.jsx("p",{className:"createPage__panelPlaceholder",children:a("pages.create.panels.myCreations.placeholder")}):null,U.length>0?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"createPage__myCreationsGrouped",children:U.map(({dateKey:e,taskList:r})=>{const t=e==="unknown"?a("pages.create.panels.myCreations.dateUnknown"):e===se?a("pages.create.panels.myCreations.dateToday"):e.replace(/-/g,"/");return l.jsxs("section",{className:"createPage__myCreationsDaySection","aria-label":t,children:[l.jsx("h3",{className:"createPage__myCreationsDayTitle",children:t}),l.jsx("ul",{className:"createPage__myCreationsList",role:"list",children:r.map((s,n)=>{if(s.status==0||s.status==1){const u=M(s)||`idx-${n}`;return Array.from({length:Number(s.batchSize||0)},(c,m)=>l.jsxs("li",{className:"createPage__myCreationsListItem createPage__myCreationsListItem_pending",children:[l.jsx("img",{className:"createPage__myCreationsPendingIcon",src:new URL("/assets/pending-iKg2Z6_3.png",import.meta.url).href}),l.jsx("span",{className:"createPage__myCreationsPendingLabel",children:s.status==0?a("pages.create.panels.myCreations.queued"):a("pages.create.panels.myCreations.generating")})]},`pending-${u}-${m}`))}return s.status!=2||!Array.isArray(s.resultList)?null:s.resultList.map((u,c)=>{const m=String(u.id??u.assetId??`${e}-${s?.id??"task"}-${c}`),_=()=>void ie(u),x=o===0;let h,S;if(o===4?s.type==1?(h=!1,S=!!u?.images?.[0]):s.type==2?(h=!!u?.video,S=!1):(h=!1,S=!1):(h=(o===2||x)&&u?.video,S=(o===1||x)&&u?.images?.[0]),h){const y=u.cover||"";return l.jsxs("li",{className:"createPage__myCreationsListItem createPage__myCreationsListItem_video",onClick:_,onMouseEnter:ce,onMouseLeave:le,children:[l.jsx("video",{className:"createPage__myCreationsThumb",src:u.video,muted:!0,playsInline:!0,loop:!0,preload:"metadata",poster:y,"aria-hidden":!0}),l.jsx("div",{className:"createPage__myCreationsVideoHoverOverlay","aria-hidden":!0,children:l.jsx("img",{className:"createPage__myCreationsVideoHoverIcon",src:new URL("/assets/ic_play_gray-Bw0AiFae.png",import.meta.url).href,alt:"",draggable:!1})})]},m)}return S?l.jsx("li",{className:"createPage__myCreationsListItem",onClick:_,children:l.jsx("img",{className:"createPage__myCreationsThumb",src:u.images[0],loading:"lazy"})},m):null})})})]},e)})}),w?l.jsx("div",{ref:Z,className:"createPage__myCreationsSentinel","aria-hidden":!0}):null,Y?l.jsx("p",{className:"createPage__panelStatus createPage__myCreationsLoadMore",children:a("common.loading")}):null]}):null]})]})}export{ve as default};
|
|
//# sourceMappingURL=index-B0r4k3b1.js.map
|
|
|