import{n as e,t}from"./useSnackbar-BFeYjAzp.js";import{Er as n,I as r,Or as i,Sr as a,Tr as o,Vr as s,Zr as c,_ as l,br as u,di as d,en as f,hi as p,hr as m,ii as h,kt as g,qt as _,xr as v,y}from"./index-BKLG6eUi.js";import{t as b}from"./usePageActivateRefresh-BXQgZGHS.js";import{n as x}from"./dataTable-esDY4cOk.js";import{_ as S,b as C,t as w}from"./VTextField-Bs8XQAKI.js";import{t as T}from"./VSelect-Dy70bHJm.js";import{t as E}from"./VDataTableServer-GLUwxaQu.js";import{a as D,n as O,r as k,t as A}from"./auditNormalize-C-_Ftbtx.js";var j=new Set([`batch_install_agent`,`batch_upgrade_agent`,`batch_uninstall_agent`,`batch_detect_path`,`batch_health_check`,`batch_update_category`,`batch_server_op`]);function M(e){return j.has(e)}function N(e){let t=(e||``).trim();if(!t.startsWith(`{`))return null;try{let e=JSON.parse(t);return typeof e.job_id!=`number`||!e.summary?null:e}catch{return null}}function P(e){let t=[e.summary],n=e.failures||[];if(n.length){let e=n.slice(0,3).map(e=>e.server_name).join(`、`);t.push(`失败: ${e}${n.length>3?`…`:``}`)}return t.join(` · `)}var F={class:`font-weight-medium`},I={class:`text-body-2`},L={class:`d-flex align-center ga-2 flex-wrap`},R={class:`text-body-2 text-medium-emphasis`,style:{"max-width":`360px`}},z={class:`text-caption text-medium-emphasis`},B={class:`text-caption text-medium-emphasis`},V=i({name:`AuditPage`,__name:`AuditPage`,setup(i){let j=t(),V=h(!1),H=h([]),U=h(0),W=h(1),G=h(null),K=h(``),q=h(``),J=O,Y=x([{title:`操作`,key:`action`,width:100},{title:`用户`,key:`admin_username`,width:100},{title:`目标`,key:`target`,width:140},{title:`详情`,key:`detail`},{title:`IP`,key:`ip_address`,width:120},{title:`时间`,key:`created_at`,width:160}]);async function X(e=!1){e||(V.value=!0);try{let e=(W.value-1)*50,t=await f.get(`/audit/`,{limit:50,offset:e,action:G.value||void 0,admin_username:K.value||void 0,date_from:q.value||void 0});H.value=A(t.items||[]),U.value=t.total||0}catch{H.value=[],e||j(`加载审计日志失败`,`error`)}finally{e||(V.value=!1)}}function Z(e){return e.startsWith(`create`)||e===`login`?`success`:e.startsWith(`update`)?`info`:e.startsWith(`delete`)||e===`logout`?`error`:e.includes(`execute`)||e.includes(`push`)||e.includes(`retry`)?`warning`:`primary`}function Q(e){return M(e.action)?N(e.detail):null}function $(e){let t=Q(e);return t?P(t):(e.detail||``).trim()||`—`}function ee(e){g(e.job_id,e.summary)}return b(e=>X(e)),(t,i)=>(s(),v(e,{fluid:``,class:`pa-6`},{default:c(()=>[n(S,{elevation:`0`,border:``,rounded:`lg`},{default:c(()=>[n(C,{class:`d-flex align-center`},{default:c(()=>[i[7]||=o(` 审计日志 `,-1),n(l),n(T,{modelValue:G.value,"onUpdate:modelValue":[i[0]||=e=>G.value=e,i[1]||=e=>{W.value=1,X()}],items:d(J),"item-title":`label`,"item-value":`value`,label:`操作类型`,variant:`outlined`,density:`compact`,"hide-details":``,style:{"max-width":`200px`},clearable:``},null,8,[`modelValue`,`items`]),n(w,{modelValue:K.value,"onUpdate:modelValue":[i[2]||=e=>K.value=e,i[3]||=e=>{W.value=1,X()}],"prepend-inner-icon":`mdi-account`,label:`用户`,variant:`outlined`,density:`compact`,"hide-details":``,style:{"max-width":`140px`},class:`ml-3`,clearable:``},null,8,[`modelValue`]),n(w,{modelValue:q.value,"onUpdate:modelValue":[i[4]||=e=>q.value=e,i[5]||=e=>{W.value=1,X()}],"prepend-inner-icon":`mdi-calendar`,label:`日期`,variant:`outlined`,density:`compact`,"hide-details":``,style:{"max-width":`160px`},class:`ml-3`,type:`date`,clearable:``},null,8,[`modelValue`])]),_:1}),n(E,{items:H.value,headers:d(Y),"items-length":U.value,loading:V.value,page:W.value,"items-per-page":50,hover:``,density:`compact`,"onUpdate:page":i[6]||=e=>{W.value=e,X()}},{"item.action":c(({item:e})=>[n(y,{color:Z(e.action),size:`small`,variant:`tonal`,label:``},{default:c(()=>[o(p(d(k)(e.action)),1)]),_:2},1032,[`color`])]),"item.admin_username":c(({item:e})=>[u(`span`,F,p(e.admin_username),1)]),"item.target":c(({item:e})=>[u(`span`,I,p(d(D)(e.resource_type))+p(e.resource_id?` #${e.resource_id}`:``),1)]),"item.detail":c(({item:e})=>[u(`div`,L,[u(`span`,R,p($(e)),1),Q(e)?(s(),v(r,{key:0,size:`x-small`,variant:`tonal`,color:`primary`,onClick:m(t=>ee(Q(e)),[`stop`])},{default:c(()=>[...i[8]||=[o(` 查看结果 `,-1)]]),_:1},8,[`onClick`])):a(``,!0)])]),"item.ip_address":c(({item:e})=>[u(`span`,z,p(e.ip_address||`—`),1)]),"item.created_at":c(({item:e})=>[u(`span`,B,p(d(_)(e.created_at)),1)]),"no-data":c(()=>[...i[9]||=[u(`div`,{class:`text-center text-medium-emphasis py-6`},`暂无数据`,-1)]]),_:1},8,[`items`,`headers`,`items-length`,`loading`,`page`])]),_:1})]),_:1}))}});export{V as default};