import{_ as P,aA as q,f as L,u as Q,c as l,a,e as u,A as N,w as c,d as y,E as R,K as V,F as v,y as w,t as g,i as n,x as f,ay as D,o as t,aC as F,r as B}from"./index-DiBxRW4b.js";import{E as I,a as M,b as T}from"./pagination-Bt2wIEmf.js";import"./select-BDVmAxby.js";import{E as U}from"./empty-D_EVTe0N.js";import{E as A}from"./card-ZWJ79s8j.js";import"./_initCloneObject-CeJycvfb.js";import"./raf-DG3hW5tP.js";const H={data(){const{t:s}=Q();return{sql:"",show_result:!1,result:[],error:"",affectedRows:null,history:[],historyPage:1,resultPage:1,historyPageSize:5,resultPageSize:10,loading:!1,t:s}},computed:{pagedResult(){const s=(this.resultPage-1)*this.resultPageSize;return this.result.slice(s,s+this.resultPageSize)},pagedHistory(){const s=(this.historyPage-1)*this.historyPageSize;return this.history.slice(s,s+this.historyPageSize)}},methods:{async executeSQL(){if(this.sql){this.result=[],this.error="",this.affectedRows=null,this.show_result=!1,this.history.unshift(this.sql),this.loading=!0;try{const s=await q.post("/api/database/exec",{sql:this.sql});this.show_result=!0,s.data.success?(s.data.affected_rows!==void 0?this.affectedRows=s.data.affected_rows:this.result=s.data.data||[],this.error=""):(this.result=[],this.error=s.data.error)}catch(s){L.error(this.t("message.error.fetch")+s.message)}finally{this.loading=!1}}},clearSQL(){this.sql="",this.result=[],this.error="",this.show_result=!1,this.resultPage=1},setSQL(s){this.sql=s}}},K={class:"sql-console"},j={class:"button-toolbar"},G={class:"editor-area"},J={class:"history"},O=["onClick"],W={class:"pagination-wrapper"},X={key:0,class:"error"},Y={key:1,class:"affected-rows"},Z={key:3,class:"table-wrapper"},$={class:"pagination-wrapper"};function ee(s,o,b,k,e,i){const p=R,_=V,m=I,h=A,x=U,z=T,C=M,E=D;return t(),l("div",K,[a("div",j,[u(p,{type:"primary",disabled:e.loading,onClick:i.executeSQL},{default:c(()=>[...o[3]||(o[3]=[a("i",{class:"mdi mdi-console-line"},null,-1),y(" 執行 ",-1)])]),_:1},8,["disabled","onClick"]),u(p,{disabled:e.loading,onClick:i.clearSQL},{default:c(()=>[...o[4]||(o[4]=[a("i",{class:"mdi mdi-restart"},null,-1),y(" 清空 ",-1)])]),_:1},8,["disabled","onClick"])]),u(h,{class:"editor-card",shadow:"never"},{default:c(()=>[a("div",G,[u(_,{type:"textarea",modelValue:e.sql,"onUpdate:modelValue":o[0]||(o[0]=r=>e.sql=r),placeholder:"请输入 SQL 语句",resize:"none",rows:"9",class:"sql-input"},null,8,["modelValue"]),u(h,{class:"history-area",shadow:"never"},{default:c(()=>[a("div",J,[(t(!0),l(v,null,w(i.pagedHistory,(r,d)=>(t(),l("div",{key:d,class:"history-item",onClick:re=>i.setSQL(r)},g(r),9,O))),128))]),a("div",W,[e.history.length>e.historyPageSize?(t(),n(m,{key:0,layout:"prev, pager, next","page-size":e.historyPageSize,total:e.history.length,"current-page":e.historyPage,"onUpdate:currentPage":o[1]||(o[1]=r=>e.historyPage=r)},null,8,["page-size","total","current-page"])):f("",!0)])]),_:1})])]),_:1}),N((t(),n(h,{class:"result-card",shadow:"never"},{default:c(()=>[e.error?(t(),l("div",X,g(e.error),1)):e.affectedRows!==null?(t(),l("div",Y," ("+g(e.affectedRows)+" row(s) affected) ",1)):e.show_result&&!e.result.length?(t(),n(x,{key:2})):(t(),l("div",Z,[e.result.length?(t(),n(C,{key:0,data:i.pagedResult,stripe:"",width:"100%"},{default:c(()=>[(t(!0),l(v,null,w(e.result[0],(r,d)=>(t(),n(z,{key:d,prop:d,label:d},null,8,["prop","label"]))),128))]),_:1},8,["data"])):f("",!0)])),a("div",$,[e.result.length>e.resultPageSize?(t(),n(m,{key:0,background:"",layout:"prev, pager, next","page-size":e.resultPageSize,total:e.result.length,style:{"margin-top":"20px"},"current-page":e.resultPage,"onUpdate:currentPage":o[2]||(o[2]=r=>e.resultPage=r)},null,8,["page-size","total","current-page"])):f("",!0)])]),_:1})),[[E,e.loading]])])}const S=P(H,[["render",ee],["__scopeId","data-v-a2d2c625"]]),se={name:"DatabasePage",components:{SQLConsole:S,NotFound:F},data(){return{isDevelopMode:localStorage.getItem("isDevelopMode")==="true"}}},te={key:0};function oe(s,o,b,k,e,i){const p=S,_=B("NotFound");return e.isDevelopMode?(t(),l("div",te,[u(p)])):(t(),n(_,{key:1}))}const pe=P(se,[["render",oe]]);export{pe as default};
