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