import{d as Y,aa as Z,r as c,w as M,o as j,A as o,J as n,P as d,j as i,t as l,B as C,am as ee,au as O,H as p,_ as te,G as U,K as b,L as N,av as ae,c as V,g as r,a8 as B,az as se,O as z,e as le}from"./index-DOFLUERq.js";import{getPageTypeMeta as ne}from"./common-DEIQtiPI.js";import{g as oe,t as A}from"./scheduledJobs-joQMtCXM.js";import{_ as ie}from"./_plugin-vue_export-helper-DlAUqK2U.js";const re={class:"page"},ue={class:"page-header"},ce={class:"header-left"},de={class:"header-right"},pe={class:"filters"},me=["disabled"],fe={class:"page-content"},ve={key:0,class:"loading"},ye={key:1},he={class:"job-list"},ge={class:"col-actions"},_e={class:"list-body"},xe=["onClick"],ke={key:0,class:"col-name-wrapper"},Se={class:"name"},Ce={key:0,class:"description"},be={key:1,class:"badge"},we={key:2,class:"cron-text"},Fe={class:"col-actions"},De=["onClick","title"],Je=["onClick","title"],qe={class:"list-pagination"},Le=Y({__name:"ScheduledJobList",setup(Te){const R=le(),m=Z(),k=c(!1),w=c([]),F=c([]),D=c(0),f=c(""),v=c("all"),y=c("all"),g=c(1),J=c(parseInt(localStorage.getItem("itemsPerPage")||"10")),q=c([]),h=c([]),P=c([]),E=V(()=>[{label:l("All"),value:"all"},{label:l("Running"),value:"running"},{label:l("Stopped"),value:"stopped"}]),G=V(()=>Math.max(1,Math.ceil(D.value/J.value)));async function _(){k.value=!0;try{const a=[];if(f.value&&a.push(["method","like",`%${f.value}%`]),v.value!=="all"&&a.push(["frequency","=",v.value]),y.value!=="all"){const e=y.value==="stopped";a.push(["stopped","=",e?1:0])}const t=await oe(g.value,J.value,a);F.value=t.items||[],H(),D.value=t.total||0}catch(a){console.error("获取任务列表失败:",a),m.error(l("Failed to load jobs")),w.value=[],F.value=[],D.value=0}finally{k.value=!1}}async function H(){let a=[...F.value];if(a=a.map(t=>({...t,stopped:!!t.stopped})),f.value){const t=f.value.toLowerCase();a=a.filter(e=>e.method?.toLowerCase().includes(t)||e.name?.toLowerCase().includes(t))}if(v.value!=="all"&&(a=a.filter(t=>t.frequency===v.value)),y.value!=="all"){const t=y.value==="stopped";a=a.filter(e=>!!e.stopped===t)}w.value=a}function K(){_()}function $(a){R.push({name:"ScheduledJobDetail",params:{id:a}})}async function Q(a){try{const t=await A(a.name);t.success?m.success(t.message||l("Job status updated successfully")):(m.error(t.message||l("Failed to update job status")),a.stopped=!a.stopped)}catch(t){console.error("Toggle job status error:",t),m.error(l("Failed to update job status")),a.stopped=!a.stopped}}async function W(a){try{const t=await A(a);t.success?(m.success(t.message||l("Job status updated successfully")),await _()):m.error(t.message||l("Failed to update job status"))}catch(t){console.error("Toggle job status error:",t),m.error(l("Failed to update job status"))}}function I(){if(h.value.length===0)return"1fr 120px 150px 100px 180px 120px";const a=h.value.map(t=>t.fieldname==="method"||t.fieldname==="name"?"1fr":t.fieldname==="frequency"?"120px":t.fieldname==="cron_format"?"150px":t.fieldname==="stopped"?"120px":t.fieldtype==="Datetime"||t.fieldtype==="Date"?"180px":t.fieldtype==="Check"?"100px":"120px");return a.push("120px"),a.join(" ")}async function X(){try{const a=await ne("Local Scheduled Job"),t=a.success&&a.data?a.data:{};q.value=t.fields||[],h.value=q.value.filter(u=>u.in_list_view===1||["method","frequency","cron_format","stopped","last_execution"].includes(u.fieldname));const e=t.field_order||[];h.value.sort((u,x)=>{const L=e.indexOf(u.fieldname),T=e.indexOf(x.fieldname);return L===-1&&T===-1?0:L===-1?1:T===-1?-1:L-T});const s=q.value.find(u=>u.fieldname==="frequency");if(s&&s.options){const u=typeof s.options=="string"?s.options.split(`
`).filter(x=>x.trim()):[];P.value=[{label:l("All"),value:"all"},...u.map(x=>({label:l(x.trim()),value:x.trim()}))]}}catch(a){console.error("Failed to load meta fields:",a),h.value=[{fieldname:"method",label:"Method",fieldtype:"Data"},{fieldname:"frequency",label:"Frequency",fieldtype:"Select"},{fieldname:"cron_format",label:"Cron Format",fieldtype:"Data"},{fieldname:"stopped",label:"Status",fieldtype:"Check"},{fieldname:"last_execution",label:"Last Execution",fieldtype:"Datetime"}]}}function S(a,t){const e=t[a.fieldname];switch(a.fieldtype||"Data"){case"Check":return{type:"checkbox",value:!!e};case"Datetime":case"Date":if(!e)return{type:"text",value:"—"};try{return{type:"text",value:new Date(e).toLocaleString()}}catch{return{type:"text",value:e}}case"Select":return{type:"text",value:e||"—"};case"Link":return{type:"text",value:e||"—"};default:return{type:"text",value:e||"—"}}}return M([f,v,y],()=>{g.value=1,_()},{deep:!0}),M([g],()=>{_()}),M(()=>localStorage.getItem("itemsPerPage"),a=>{a&&(J.value=parseInt(a),g.value=1,_())}),j(()=>{X(),_()}),(a,t)=>(r(),o("div",re,[n("div",ue,[n("div",ce,[n("h2",null,d(i(l)("Scheduled Jobs")),1)]),n("div",de,[n("div",pe,[C(i(ee),{value:f.value,"onUpdate:value":t[0]||(t[0]=e=>f.value=e),placeholder:i(l)("Search jobs..."),clearable:"",style:{width:"200px"}},null,8,["value","placeholder"]),C(i(O),{value:v.value,"onUpdate:value":t[1]||(t[1]=e=>v.value=e),options:P.value,placeholder:i(l)("Frequency"),style:{width:"120px"}},null,8,["value","options","placeholder"]),C(i(O),{value:y.value,"onUpdate:value":t[2]||(t[2]=e=>y.value=e),options:E.value,placeholder:i(l)("Status"),style:{width:"120px"}},null,8,["value","options","placeholder"])]),n("button",{class:"refresh-btn",onClick:K,disabled:k.value},[n("i",{class:p(k.value?"fa fa-spinner fa-spin":"fa fa-refresh")},null,2)],8,me)])]),n("div",fe,[k.value?(r(),o("div",ve,[t[5]||(t[5]=n("i",{class:"fa fa-spinner fa-spin"},null,-1)),te(" "+d(i(l)("Loading...")),1)])):(r(),o("div",ye,[n("div",he,[n("div",{class:"list-header",style:U({gridTemplateColumns:I()})},[(r(!0),o(b,null,N(h.value,e=>(r(),o("div",{key:e.fieldname,class:p(["col-header",`col-${e.fieldname}`])},d(i(l)(e.label||e.fieldname)),3))),128)),n("div",ge,d(i(l)("Actions")),1)],4),n("div",_e,[(r(!0),o(b,null,N(w.value,e=>(r(),o("div",{key:e.name,class:"list-item",style:U({gridTemplateColumns:I()}),onClick:s=>$(e.name)},[(r(!0),o(b,null,N(h.value,s=>(r(),o("div",{key:s.fieldname,class:p(["col-field",`col-${s.fieldname}`])},[s.fieldtype==="Check"?(r(),o(b,{key:0},[C(i(se),{checked:e[s.fieldname],"onUpdate:checked":[u=>e[s.fieldname]=u,u=>s.fieldname==="stopped"?()=>Q(e):void 0],onClick:t[3]||(t[3]=B(()=>{},["stop"]))},null,8,["checked","onUpdate:checked"]),s.fieldname==="stopped"?(r(),o("span",{key:0,class:p(["status-badge",e[s.fieldname]?"stopped":"running"])},d(e[s.fieldname]?i(l)("Stopped"):i(l)("Running")),3)):z("",!0)],64)):(r(),o(b,{key:1},[s.fieldname==="method"||s.fieldname==="name"?(r(),o("div",ke,[n("div",Se,d(S(s,e).value),1),s.fieldname==="method"&&e.name!==e.method?(r(),o("div",Ce,d(e.name),1)):z("",!0)])):s.fieldtype==="Select"&&s.fieldname==="frequency"?(r(),o("span",be,d(i(l)(S(s,e).value)),1)):s.fieldname==="cron_format"&&e.cron_format?(r(),o("span",we,d(S(s,e).value),1)):s.fieldtype==="Datetime"||s.fieldtype==="Date"?(r(),o("span",{key:3,class:p(e[s.fieldname]?"datetime-text":"text-muted")},d(S(s,e).value),3)):(r(),o("span",{key:4,class:p(e[s.fieldname]?"":"text-muted")},d(S(s,e).value),3))],64))],2))),128)),n("div",Fe,[n("button",{class:p(["action-btn",e.stopped?"start-btn":"stop-btn"]),onClick:B(s=>W(e.name),["stop"]),title:e.stopped?i(l)("Start"):i(l)("Stop")},[n("i",{class:p(e.stopped?"fa fa-play":"fa fa-pause")},null,2)],10,De),n("button",{class:"action-btn",onClick:B(s=>$(e.name),["stop"]),title:i(l)("View Details")},[...t[6]||(t[6]=[n("i",{class:"fa fa-eye"},null,-1)])],8,Je)])],12,xe))),128))]),n("div",qe,[C(i(ae),{page:g.value,"onUpdate:page":t[4]||(t[4]=e=>g.value=e),"page-count":G.value,size:"small"},null,8,["page","page-count"])])])]))])]))}}),$e=ie(Le,[["__scopeId","data-v-aa78d997"]]);export{$e as default};
