CostPrediction/frontend/dist/assets/ModelPage-DFNq0Y7S.js

2 lines
5.2 KiB
JavaScript

import{_ as I,r as p,w as O,o as T,a as j,b as N,c as R,d as e,e as a,f as y,A as w,E as m,g as u,h as n,t as i,i as v,j as U,k as S,n as q,l as X}from"./index-BclX5sLE.js";const J={class:"model-page"},Z={style:{"margin-top":"20px"}},H={key:0,style:{"margin-top":"20px"}},K={__name:"ModelPage",setup(Q){const x=p([]),r=p(null),f=p(!1),h=p(null),_=p(null),b=async()=>{try{const l=await y.get(`${w}/models`);x.value=l.data}catch{m.error("获取模型列表失败")}},A=async l=>{try{await S.confirm("确定要激活这个模型吗?","提示",{type:"warning"}),await y.post(`${w}/models/${l.id}/activate`),m.success("模型激活成功"),b()}catch(o){o!=="cancel"&&m.error("模型激活失败")}},F=async l=>{try{await S.confirm("确定要删除这个模型吗?","警告",{type:"warning"}),await y.delete(`${w}/models/${l.id}`),m.success("删除成功"),b()}catch(o){o!=="cancel"&&m.error("删除失败")}},V=async l=>{r.value=l,f.value=!0};O(()=>f.value,async l=>{var o;l&&((o=r.value)!=null&&o.feature_importance)&&(await q(),$())});const $=()=>{_.value&&_.value.dispose(),_.value=X(h.value);const l=JSON.parse(r.value.feature_importance),o=Object.keys(l),d=Object.values(l);_.value.setOption({title:{text:"特征重要性"},tooltip:{},xAxis:{type:"value",name:"重要性得分"},yAxis:{type:"category",data:o},series:[{type:"bar",data:d}]})},L=l=>({pytorch:"PyTorch",xgboost:"XGBoost",lightgbm:"LightGBM",gbm:"GBM",rf:"Random Forest",pls:"PLS回归"})[l]||l,M=l=>l?new Date(l).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZone:"Asia/Shanghai"}):"-";T(()=>{var l;(l=_.value)==null||l.dispose()}),j(()=>{b()});const G=l=>({pls:"PLS回归",xgboost:"XGBoost",lightgbm:"LightGBM",gbm:"GBM",rf:"Random Forest"})[l]||l;return(l,o)=>{const d=u("el-table-column"),C=u("el-tag"),g=u("el-button"),P=u("el-table"),z=u("el-card"),c=u("el-descriptions-item"),k=u("el-descriptions"),B=u("el-divider"),D=u("el-dialog");return N(),R("div",J,[e(z,{class:"model-card"},{header:a(()=>o[1]||(o[1]=[v("div",{class:"header-content"},[v("h2",null,"模型管理")],-1)])),default:a(()=>[e(P,{data:x.value,border:"",style:{width:"100%"}},{default:a(()=>[e(d,{prop:"model_type",label:"模型类型"},{default:a(s=>[n(i(G(s.row.model_type)),1)]),_:1}),e(d,{prop:"model_name",label:"模型名称"}),e(d,{prop:"equipment_type",label:"装备类型"}),e(d,{prop:"r2_score",label:"R²分数"},{default:a(s=>[n(i(s.row.r2_score.toFixed(4)),1)]),_:1}),e(d,{prop:"mae",label:"MAE (美元)"},{default:a(s=>[n(i(s.row.mae.toFixed(2)),1)]),_:1}),e(d,{prop:"rmse",label:"RMSE (美元)"},{default:a(s=>[n(i(s.row.rmse.toFixed(2)),1)]),_:1}),e(d,{prop:"training_date",label:"训练时间",width:"180"},{default:a(s=>[n(i(M(s.row.training_date)),1)]),_:1}),e(d,{prop:"is_active",label:"状态"},{default:a(s=>[e(C,{type:s.row.is_active?"success":"info"},{default:a(()=>[n(i(s.row.is_active?"使用中":"未使用"),1)]),_:2},1032,["type"])]),_:1}),e(d,{label:"操作",width:"200"},{default:a(s=>[e(g,{size:"small",type:"primary",disabled:s.row.is_active,onClick:t=>A(s.row)},{default:a(()=>o[2]||(o[2]=[n(" 激活 ")])),_:2},1032,["disabled","onClick"]),e(g,{size:"small",onClick:t=>V(s.row)},{default:a(()=>o[3]||(o[3]=[n(" 详情 ")])),_:2},1032,["onClick"]),e(g,{size:"small",type:"danger",disabled:s.row.is_active,onClick:t=>F(s.row)},{default:a(()=>o[4]||(o[4]=[n(" 删除 ")])),_:2},1032,["disabled","onClick"])]),_:1})]),_:1},8,["data"])]),_:1}),e(D,{modelValue:f.value,"onUpdate:modelValue":o[0]||(o[0]=s=>f.value=s),title:"模型详情",width:"70%"},{default:a(()=>{var s;return[e(k,{column:2,border:""},{default:a(()=>[e(c,{label:"模型名称"},{default:a(()=>{var t;return[n(i((t=r.value)==null?void 0:t.model_name),1)]}),_:1}),e(c,{label:"模型类型"},{default:a(()=>{var t;return[n(i(L((t=r.value)==null?void 0:t.model_type)),1)]}),_:1}),e(c,{label:"装备类型"},{default:a(()=>{var t;return[n(i((t=r.value)==null?void 0:t.equipment_type),1)]}),_:1}),e(c,{label:"训练数据量"},{default:a(()=>{var t;return[n(i((t=r.value)==null?void 0:t.training_data_size),1)]}),_:1}),e(c,{label:"训练时间"},{default:a(()=>{var t;return[n(i(M((t=r.value)==null?void 0:t.training_date)),1)]}),_:1}),e(c,{label:"状态"},{default:a(()=>{var t;return[e(C,{type:(t=r.value)!=null&&t.is_active?"success":"info"},{default:a(()=>{var E;return[n(i((E=r.value)!=null&&E.is_active?"使用中":"未使用"),1)]}),_:1},8,["type"])]}),_:1})]),_:1}),v("div",Z,[e(B,{"content-position":"left"},{default:a(()=>o[5]||(o[5]=[n("评估指标")])),_:1}),e(k,{column:3,border:""},{default:a(()=>[e(c,{label:"R²分数"},{default:a(()=>{var t;return[n(i((t=r.value)==null?void 0:t.r2_score.toFixed(4)),1)]}),_:1}),e(c,{label:"MAE"},{default:a(()=>{var t;return[n(i((t=r.value)==null?void 0:t.mae.toFixed(2))+" 美元",1)]}),_:1}),e(c,{label:"RMSE"},{default:a(()=>{var t;return[n(i((t=r.value)==null?void 0:t.rmse.toFixed(2))+" 美元",1)]}),_:1})]),_:1})]),(s=r.value)!=null&&s.feature_importance?(N(),R("div",H,[e(B,{"content-position":"left"},{default:a(()=>o[6]||(o[6]=[n("特征重要性")])),_:1}),v("div",{ref_key:"importanceChartRef",ref:h,style:{width:"100%",height:"400px"}},null,512)])):U("",!0)]}),_:1},8,["modelValue"])])}}},Y=I(K,[["__scopeId","data-v-e4c34bb7"]]);export{Y as default};