import{b as H}from"./users-BKWiZCGY.js";import{d as J,e as K,g as Q}from"./taskSource-B7bFDyX8.js";import{_ as W,r as s,y as X,o as Z,c as E,a as p,b as t,w as l,d as u,e as ee,g as _,h as d,F as te,s as ae,k,j as le,t as c,E as P,m as oe}from"./index-DMMQbxWA.js";const ne={class:"page-stack"},se={class:"app-page-title"},ue={class:"toolbar"},re={class:"filters"},ie={class:"table-wrap"},de={class:"ellipsis"},ce={class:"pagination"},pe={class:"page-hint app-muted"},M=20,ve={__name:"LogsPage",setup(fe){const F=s(!1),B=s([]),V=s(0),v=s(1),C=s(!1),T=s([]),g=s(""),b=s(""),y=s(""),h=s(""),w=s(""),I=X(()=>Math.max(1,Math.ceil((V.value||0)/M)));function Y(o){if(o==null)return"-";const e=Number(o);return Number.isFinite(e)?e<60?`${e}秒`:`${Math.floor(e/60)}分${e%60}秒`:"-"}function f(o){const e=Q(o);return{key:e.group,label:e.label,type:e.type,tooltip:e.tooltip}}function L(o){return o==="success"?{label:"成功",type:"success"}:o==="failed"?{label:"失败",type:"danger"}:{label:o||"-",type:"info"}}async function $(){C.value=!0;try{const o=await H();T.value=(o||[]).map(e=>({id:e.id,username:e.username}))}catch{T.value=[]}finally{C.value=!1}}async function m(){F.value=!0;try{const o=(v.value-1)*M,e={limit:M,offset:o};g.value&&(e.date=g.value),b.value&&(e.status=b.value),y.value&&(e.source=y.value),h.value&&(e.user_id=h.value),w.value&&(e.account=w.value);const r=await J(e);B.value=r?.logs||[],V.value=r?.total||0}catch{B.value=[],V.value=0}finally{F.value=!1}}function O(){v.value=1,m()}function j(){g.value="",b.value="",y.value="",h.value="",w.value="",v.value=1,m()}async function z(){let o;try{const e=await P.prompt("请输入要清理多少天前的日志(默认30天)","清理旧日志",{inputValue:"30",confirmButtonText:"下一步",cancelButtonText:"取消",inputValidator:r=>{const x=parseInt(String(r),10);return Number.isFinite(x)&&x>=1},inputErrorMessage:"请输入有效的天数(大于0的整数)"});o=parseInt(String(e.value),10)}catch{return}try{await P.confirm(`确定要删除 ${o} 天前的所有日志吗?此操作不可恢复!`,"二次确认",{confirmButtonText:"删除",cancelButtonText:"取消",type:"warning"})}catch{return}try{const e=await K(o);oe.success(e?.message||"清理成功"),v.value=1,await m()}catch{}}return Z(async()=>{await $(),await m()}),(o,e)=>{const r=u("el-button"),x=u("el-date-picker"),n=u("el-option"),U=u("el-select"),A=u("el-input"),N=u("el-card"),i=u("el-table-column"),D=u("el-tag"),S=u("el-tooltip"),R=u("el-table"),q=u("el-pagination"),G=ee("loading");return _(),E("div",ne,[p("div",se,[e[7]||(e[7]=p("h2",null,"任务日志",-1)),p("div",ue,[t(r,{onClick:m},{default:l(()=>[...e[6]||(e[6]=[d("刷新",-1)])]),_:1})])]),t(N,{shadow:"never","body-style":{padding:"16px"},class:"card"},{default:l(()=>[p("div",re,[t(x,{modelValue:g.value,"onUpdate:modelValue":e[0]||(e[0]=a=>g.value=a),type:"date","value-format":"YYYY-MM-DD",placeholder:"日期",style:{width:"150px"}},null,8,["modelValue"]),t(U,{modelValue:b.value,"onUpdate:modelValue":e[1]||(e[1]=a=>b.value=a),placeholder:"状态",style:{width:"120px"}},{default:l(()=>[t(n,{label:"全部",value:""}),t(n,{label:"成功",value:"success"}),t(n,{label:"失败",value:"failed"})]),_:1},8,["modelValue"]),t(U,{modelValue:y.value,"onUpdate:modelValue":e[2]||(e[2]=a=>y.value=a),placeholder:"来源",style:{width:"120px"}},{default:l(()=>[t(n,{label:"全部",value:""}),t(n,{label:"手动",value:"manual"}),t(n,{label:"定时任务(系统)",value:"scheduled"}),t(n,{label:"定时任务(用户)",value:"user_scheduled"}),t(n,{label:"手动(批量)",value:"batch"}),t(n,{label:"手动(截图)",value:"manual_screenshot"}),t(n,{label:"手动(立即)",value:"immediate"}),t(n,{label:"手动(恢复)",value:"resumed"})]),_:1},8,["modelValue"]),t(U,{modelValue:h.value,"onUpdate:modelValue":e[3]||(e[3]=a=>h.value=a),placeholder:"用户",style:{width:"140px"},loading:C.value,filterable:"",clearable:""},{default:l(()=>[t(n,{label:"全部",value:""}),(_(!0),E(te,null,ae(T.value,a=>(_(),k(n,{key:a.id,label:a.username,value:String(a.id)},null,8,["label","value"]))),128))]),_:1},8,["modelValue","loading"]),t(A,{modelValue:w.value,"onUpdate:modelValue":e[4]||(e[4]=a=>w.value=a),placeholder:"账号关键字",style:{width:"170px"},clearable:""},null,8,["modelValue"]),t(r,{type:"primary",onClick:O},{default:l(()=>[...e[8]||(e[8]=[d("筛选",-1)])]),_:1}),t(r,{onClick:j},{default:l(()=>[...e[9]||(e[9]=[d("重置",-1)])]),_:1}),t(r,{type:"danger",plain:"",onClick:z},{default:l(()=>[...e[10]||(e[10]=[d("清理旧日志",-1)])]),_:1})])]),_:1}),t(N,{shadow:"never","body-style":{padding:"16px"},class:"card"},{default:l(()=>[p("div",ie,[le((_(),k(R,{data:B.value,style:{width:"100%"}},{default:l(()=>[t(i,{prop:"created_at",label:"时间",width:"180"}),t(i,{label:"来源",width:"110"},{default:l(({row:a})=>[f(a.source).tooltip?(_(),k(S,{key:0,content:f(a.source).tooltip,placement:"top","show-after":300},{default:l(()=>[t(D,{type:f(a.source).type,effect:"light"},{default:l(()=>[d(c(f(a.source).label),1)]),_:2},1032,["type"])]),_:2},1032,["content"])):(_(),k(D,{key:1,type:f(a.source).type,effect:"light"},{default:l(()=>[d(c(f(a.source).label),1)]),_:2},1032,["type"]))]),_:1}),t(i,{prop:"user_username",label:"用户",width:"140"}),t(i,{prop:"username",label:"账号",width:"160"}),t(i,{prop:"browse_type",label:"浏览类型",width:"120"}),t(i,{label:"状态",width:"90"},{default:l(({row:a})=>[t(D,{type:L(a.status).type,effect:"light"},{default:l(()=>[d(c(L(a.status).label),1)]),_:2},1032,["type"])]),_:1}),t(i,{label:"内容/附件",width:"110"},{default:l(({row:a})=>[d(c(a.total_items)+" / "+c(a.total_attachments),1)]),_:1}),t(i,{label:"用时",width:"90"},{default:l(({row:a})=>[d(c(Y(a.duration)),1)]),_:1}),t(i,{label:"失败原因","min-width":"220"},{default:l(({row:a})=>[t(S,{content:a.error_message||"",placement:"top","show-after":300},{default:l(()=>[p("span",de,c(a.error_message||"-"),1)]),_:2},1032,["content"])]),_:1})]),_:1},8,["data"])),[[G,F.value]])]),p("div",ce,[t(q,{"current-page":v.value,"onUpdate:currentPage":e[5]||(e[5]=a=>v.value=a),"page-size":M,total:V.value,layout:"prev, pager, next, jumper, ->, total",onCurrentChange:m},null,8,["current-page","total"]),p("div",pe,"第 "+c(v.value)+" / "+c(I.value)+" 页",1)])]),_:1})])}}},be=W(ve,[["__scopeId","data-v-080a6c1f"]]);export{be as default};