import{b as N}from"./index-D7dBOFlH.js";import{c as T}from"./generator-8bZWr5RT.js";import{H as S,N as z,Q as G,i as H,G as Q}from"./element-plus-DckSU5ni.js";import{x as A,s as J,r as i,c as K,k as V,E as _,F as s,u as o,j as P,O as t,y as k,a4 as x,M as F,C as h,z as d}from"./vue-vendor-vBC20LeU.js";const ee=A({__name:"relation",emits:["success"],setup(W,{expose:w,emit:E}){const O=E,p=J(),f=i(-1),r=i(!1),R=K(()=>f.value===-1?"新增关联":"编辑关联"),g={type:"hasOne",name:"",model:"",local_key:"",foreign_key:""},a=V({...g}),U=V({type:[{required:!0,message:"请选择关联类型",trigger:["blur","change"]}],name:[{required:!0,message:"请输入关联方法名称",trigger:["blur","change"]}],model:[{required:!0,message:"请选择关联模型",trigger:["blur","change"]}],local_key:[{required:!0,message:"请选择关联键",trigger:["blur","change"]}],foreign_key:[{required:!0,message:"请输入外键",trigger:["blur","change"]}]}),b=i([]),v=i([]),q=(n=-1)=>{D(),f.value=n,r.value=!0},M=async n=>{C(),n&&Object.keys(a).forEach(l=>{n[l]!=null&&(a[l]=n[l])})},B=n=>{v.value=n},C=()=>{Object.assign(a,g),p.value?.resetFields()},D=()=>{T().then(n=>{b.value=n})},j=()=>{p.value?.validate(async n=>{n&&(O("success",f.value,a),r.value=!1)})};return w({open:q,setFormData:M,setRelationFields:B}),(n,l)=>{const u=G,c=z,m=S,y=H,I=Q,L=N;return d(),_(L,{modelValue:o(r),"onUpdate:modelValue":l[5]||(l[5]=e=>P(r)?r.value=e:null),title:o(R),width:"600px","close-on-click-modal":!1,onConfirm:j},{default:s(()=>[t(I,{ref_key:"formRef",ref:p,model:o(a),"label-width":"120px",rules:o(U)},{default:s(()=>[t(m,{label:"关联类型",prop:"type"},{default:s(()=>[t(c,{modelValue:o(a).type,"onUpdate:modelValue":l[0]||(l[0]=e=>o(a).type=e),placeholder:"请选择角色"},{default:s(()=>[t(u,{label:"一对一 (hasOne)",value:"hasOne"}),t(u,{label:"一对多 (hasMany)",value:"hasMany"}),t(u,{label:"属于 (belongsTo)",value:"belongsTo"})]),_:1},8,["modelValue"])]),_:1}),t(m,{label:"关联方法名称",prop:"name"},{default:s(()=>[t(y,{modelValue:o(a).name,"onUpdate:modelValue":l[1]||(l[1]=e=>o(a).name=e),placeholder:"请输入关联方法名称"},null,8,["modelValue"])]),_:1}),t(m,{label:"关联模型",prop:"model"},{default:s(()=>[t(c,{modelValue:o(a).model,"onUpdate:modelValue":l[2]||(l[2]=e=>o(a).model=e),placeholder:"请选择关联模型",filterable:"","popper-style":"max-width: 100vw;"},{default:s(()=>[(d(!0),k(F,null,x(o(b),e=>(d(),_(u,{key:e.value,label:e.name+" ("+e.value+")",value:e.value},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),t(m,{label:"关联键",prop:"local_key"},{default:s(()=>[t(c,{modelValue:o(a).local_key,"onUpdate:modelValue":l[3]||(l[3]=e=>o(a).local_key=e),placeholder:"请选择关联键","allow-create":"",filterable:""},{default:s(()=>[(d(!0),k(F,null,x(o(v),e=>(d(),_(u,{key:e.name,label:e.name+" ("+e.desc+")",value:e.name},null,8,["label","value"]))),128))]),_:1},8,["modelValue"]),l[6]||(l[6]=h("div",{class:"text-sm text-info"},"当前模型中的关联字段，例如 user_id",-1))]),_:1}),t(m,{label:"外键",prop:"foreign_key"},{default:s(()=>[t(y,{modelValue:o(a).foreign_key,"onUpdate:modelValue":l[4]||(l[4]=e=>o(a).foreign_key=e),placeholder:"请输入外键"},null,8,["modelValue"]),l[7]||(l[7]=h("div",{class:"text-sm text-info"},"对方模型中的关联字段，例如 id",-1))]),_:1})]),_:1},8,["model","rules"])]),_:1},8,["modelValue","title"])}}});export{ee as _};
