crud.B5g3LF1x.js 5.6 KB

1
  1. import{r as i,W as d,F as w,s as c,am as n}from"./index.CL7yl-Wb.js";import{G as y}from"./api.ssM5yC3w.js";import{M as g}from"./md5.DLPczxzP.js";const u="/api/platform/users/";function b(t){return i({url:u,method:"get",params:t})}function _(t){return i({url:u,method:"post",data:t})}function v(t){return i({url:u+t.id+"/",method:"put",data:t})}function x(t){return i({url:u+t+"/",method:"delete",data:{id:t}})}function q(t){return i({url:"/api/platform/tenant/copy-from-base/",method:"post",data:{tenant_id:t,components:["digital_humans","questions","roles"]},timeout:0})}function R(t){return i({url:`/api/platform/tenant/copy-status/${t}/`,method:"get"})}const W=function({crudExpose:t}){const p=async(e,s=60)=>{let o=0;const a=async()=>{try{o++;const r=await R(e);if(console.log(`任务状态检查 (${o}/${s}):`,r),r.data&&r.data.status){const l=r.data.status;if(l==="completed"||l==="success"){console.log("配置复制任务完成"),c("配置复制任务已完成");return}else if(l==="failed"||l==="error"){console.error("配置复制任务失败:",r.data.message||"未知错误"),n("配置复制任务失败: "+(r.data.message||"未知错误"));return}else l==="running"||l==="in_progress"||l==="pending"?o<s?setTimeout(a,5e3):(console.warn("轮询超时,任务可能仍在进行中"),n("配置复制任务超时,请稍后手动检查任务状态")):o<s?setTimeout(a,5e3):(console.warn("轮询超时,未知任务状态"),n("配置复制任务状态未知,请稍后手动检查"))}else o<s?setTimeout(a,5e3):(console.error("任务状态响应格式异常"),n("无法获取任务状态,请稍后手动检查"))}catch(r){console.error("检查任务状态时出错:",r),o<s?setTimeout(a,5e3):n("检查任务状态失败,请稍后手动检查")}};a()},h=async e=>(console.log(e),await b(e)),f=async({form:e,row:s})=>(e.id=s.id,await v(e)),m=async({row:e})=>await x(e.id);return{crudOptions:{toolbar:{buttons:{search:{show:!1},refresh:{show:!1},compact:{show:!1},export:{text:"导出",type:"primary",size:"small",icon:"upload",circle:!1,display:!0,show:!1},columns:{show:!1}}},search:{col:{span:3},show:!0,autoSearch:!1,buttons:{search:{size:"small"},reset:{size:"small"}}},request:{pageRequest:h,addRequest:async({form:e})=>{const s=await _(e);return s&&e.tenant_id&&Promise.resolve().then(async()=>{try{const o=await q(e.tenant_id);if(console.log("Copy from base response:",o),o&&o.data&&o.data.task_id){const a=o.data.task_id;console.log("开始轮询任务状态,task_id:",a),c("用户添加成功,配置复制任务已启动"),p(a)}else console.warn("Copy from base响应中未找到task_id"),c("用户添加成功,但无法获取配置复制任务ID")}catch(o){console.error("Copy from base failed:",o),n("用户添加成功,但启动配置复制任务失败")}}),s},editRequest:f,delRequest:m},actionbar:{buttons:{add:{show:!0}}},rowHandle:{fixed:"right",width:200,buttons:{view:{iconRight:"View",type:"text",show:!0},edit:{iconRight:"Edit",type:"text",show:!1},remove:{iconRight:"Delete",type:"text",show:!0,click:async e=>{try{await w.confirm(`确定要删除用户"${e.row.username}"吗?此操作不可撤销。`,"删除确认",{confirmButtonText:"确定删除",cancelButtonText:"取消",type:"warning",confirmButtonClass:"el-button--danger"}),await m(e),c("删除成功"),t.doRefresh()}catch(s){s!=="cancel"&&n("删除失败")}}}}},columns:{_index:{title:"序号",form:{show:!1},column:{type:"index",align:"center",width:"70px",columnSetDisabled:!0}},username:{title:"用户名",type:"text",search:{show:!0},form:{component:{placeholder:"请输入用户名"},rules:[{required:!0,message:"请输入用户名"}]},column:{minWidth:120}},password:{title:"密码",type:"password",search:{show:!1},column:{show:!1},form:{component:{placeholder:"请输入密码"},rules:[{required:!0,message:"请输入密码"}],show:!0,column:{show:!1}},valueResolve({form:e}){e.password&&(e.password=g.hashStr(e.password))}},name:{title:"姓名",type:"text",search:{show:!1},form:{component:{placeholder:"请输入姓名"},rules:[{required:!0,message:"请输入姓名"}]},column:{minWidth:120}},mobile:{title:"手机号",type:"text",search:{show:!0},form:{component:{placeholder:"请输入手机号"},rules:[{required:!0,message:"请输入手机号"}]},column:{minWidth:120}},email:{title:"邮箱",type:"text",search:{show:!1},form:{component:{placeholder:"请输入邮箱"},rules:[{required:!0,message:"请输入邮箱"}]},column:{minWidth:180}},tenant_id:{title:"商户ID",search:{show:!0},type:"dict-select",form:{component:{placeholder:"请选择商户"},rules:[{required:!0,message:"请选择商户"}]},column:{minWidth:120},dict:d({url:"/api/platform/tenants/",value:"tenant_id",label:"name",getData:e=>y({page:1,limit:20}).then(s=>s.data.results)})},is_active:{title:"账号状态",search:{show:!0},type:"dict-select",form:{show:!1,component:{placeholder:"请选择账号状态"}},column:{minWidth:120},dict:d({data:[{value:!0,label:"启用"},{value:!1,label:"禁用"}]})},date_joined:{title:"开通时间",type:"datetime",search:{show:!1},form:{component:{placeholder:"请选择开通时间"},show:!1},column:{minWidth:150}},last_login:{title:"最后登录时间",type:"datetime",search:{show:!1},form:{component:{placeholder:"请选择最后登录时间"},show:!1},column:{minWidth:150}},permission_level:{title:"权限等级",search:{show:!1},type:"dict-select",form:{component:{placeholder:"请选择权限等级"},show:!1},column:{minWidth:120},dict:d({data:[{value:"admin",label:"管理员"},{value:"user",label:"普通用户"},{value:"guest",label:"访客"}]})},account_status_display:{title:"账号状态"}}}}},S=Object.freeze(Object.defineProperty({__proto__:null,createCrudOptions:W},Symbol.toStringTag,{value:"Module"}));export{b as G,S as a,W as c};