import{_ as O,q as S,c as U,a as e,b as l,w as s,y as A,k as L,e as o,h as r,r as m,x as F,o as C,t as D,B as V,E as c,A as b}from"./index-Dn6fDqC3.js";import{b as p}from"./index-D0SgC7D8.js";const I={class:"content-card"},J={class:"content-card",style:{"margin-top":"20px"}},$={class:"card-title"},q={class:"content-card",style:{"margin-top":"20px"}},K={class:"content-card danger-card",style:{"margin-top":"20px"}},G={__name:"DataManage",setup(H){const g=r(!1),f=r(!1),k=r([]),v=r(!1),x=r(!1),d=r(null);async function T(){g.value=!0;try{const a=await p.downloadBackup(),t=new Date().toISOString().slice(0,10);_(a.data,`backup-${t}.json`),c.success("备份文件已下载")}finally{g.value=!1}}async function B(){f.value=!0;try{const a=await p.getBackups();k.value=a.data}finally{f.value=!1}}async function j(a){const t=await p.downloadAutoBackup(a);_(t.data,a)}function z(a){d.value=a.raw}async function R(){var a,t;if(d.value){await b.confirm("恢复将清除当前所有数据，替换为备份内容。此操作不可撤销，确定继续吗？","确认恢复",{type:"warning",confirmButtonText:"确认恢复",cancelButtonText:"取消"}),v.value=!0;try{const n=await d.value.text(),i=JSON.parse(n),y=await p.restoreData(i);c.success(y.message||"恢复成功"),d.value=null}catch(n){(t=(a=n==null?void 0:n.response)==null?void 0:a.data)!=null&&t.message&&c.error(n.response.data.message)}finally{v.value=!1}}}async function E(){await b.confirm("此操作将永久删除所有工时记录和客户/项目数据，用户账号保留。确定吗？","二次确认",{type:"error",confirmButtonText:"确认清除",cancelButtonText:"取消"}),await b.confirm("最后确认：所有数据将无法恢复，请确保已备份！","最终确认",{type:"error",confirmButtonText:"我确认，执行清除",cancelButtonText:"取消"}),x.value=!0;try{const a=await p.resetData();c.success(a.message||"数据已清除")}finally{x.value=!1}}function _(a,t){const n=URL.createObjectURL(new Blob([a])),i=document.createElement("a");i.href=n,i.download=t,i.click(),URL.revokeObjectURL(n)}return S(B),(a,t)=>{const n=m("el-button"),i=m("el-table-column"),y=m("el-table"),M=m("el-upload"),N=F("loading");return C(),U("div",null,[t[14]||(t[14]=e("div",{class:"page-header"},[e("h1",null,"数据管理"),e("p",null,"备份、恢复与清除系统数据")],-1)),e("div",I,[t[1]||(t[1]=e("div",{class:"card-title"},"💾 手动备份",-1)),t[2]||(t[2]=e("p",{style:{color:"var(--text-muted)","margin-bottom":"16px"}}," 将当前全部数据（用户、项目、工时记录）导出为 JSON 文件，可用于恢复。 ",-1)),l(n,{type:"primary",onClick:T,loading:g.value},{default:s(()=>[...t[0]||(t[0]=[o("⬇️ 立即备份 / 下载",-1)])]),_:1},8,["loading"])]),e("div",J,[e("div",$,[t[4]||(t[4]=e("span",null,"🕐 自动备份列表",-1)),l(n,{size:"small",onClick:B,loading:f.value},{default:s(()=>[...t[3]||(t[3]=[o("刷新",-1)])]),_:1},8,["loading"])]),t[6]||(t[6]=e("p",{style:{color:"var(--text-muted)","font-size":"13px","margin-bottom":"14px"}}," 系统每天凌晨3点自动备份，最多保留30天。 ",-1)),A((C(),L(y,{data:k.value,stripe:"","empty-text":"暂无自动备份"},{default:s(()=>[l(i,{prop:"name",label:"文件名","min-width":"220"}),l(i,{label:"大小",width:"100"},{default:s(({row:u})=>[o(D((u.size/1024).toFixed(1))+" KB",1)]),_:1}),l(i,{label:"备份时间","min-width":"180"},{default:s(({row:u})=>{var w;return[o(D((w=u.created_at)==null?void 0:w.slice(0,19).replace("T"," ")),1)]}),_:1}),l(i,{label:"操作",width:"100"},{default:s(({row:u})=>[l(n,{size:"small",onClick:w=>j(u.name)},{default:s(()=>[...t[5]||(t[5]=[o("下载",-1)])]),_:1},8,["onClick"])]),_:1})]),_:1},8,["data"])),[[N,f.value]])]),e("div",q,[t[9]||(t[9]=e("div",{class:"card-title"},"📂 从备份文件恢复",-1)),t[10]||(t[10]=e("p",{style:{color:"var(--text-muted)","font-size":"13px","margin-bottom":"16px"}},[o(" 上传一个 "),e("code",null,".json"),o(" 备份文件，系统将清除当前全部数据并从备份中恢复。"),e("br"),o(" ⚠️ 此操作不可撤销，请确认您已保留重要数据。 ")],-1)),l(M,{accept:".json","auto-upload":!1,"show-file-list":!0,limit:1,"on-change":z,"on-exceed":()=>V(c).warning("只能选择一个文件")},{default:s(()=>[l(n,null,{default:s(()=>[...t[7]||(t[7]=[o("选择备份文件 (.json)",-1)])]),_:1})]),_:1},8,["on-exceed"]),l(n,{type:"warning",style:{"margin-top":"12px"},loading:v.value,disabled:!d.value,onClick:R},{default:s(()=>[...t[8]||(t[8]=[o(" 🔄 开始恢复 ",-1)])]),_:1},8,["loading","disabled"])]),e("div",K,[t[12]||(t[12]=e("div",{class:"card-title",style:{color:"#f87171"}},"⚠️ 危险操作",-1)),t[13]||(t[13]=e("p",{style:{color:"var(--text-muted)","font-size":"13px","margin-bottom":"16px"}},[o(" 清除所有工时记录与客户/项目数据，"),e("strong",null,"用户账号保留"),o("。此操作不可撤销。 ")],-1)),l(n,{type:"danger",onClick:E,loading:x.value},{default:s(()=>[...t[11]||(t[11]=[o("🗑️ 清除所有项目与工时数据",-1)])]),_:1},8,["loading"])])])}}},W=O(G,[["__scopeId","data-v-11408198"]]);export{W as default};
