SysConfig.b8170049.js 7.8 KB

1
  1. var e=Object.defineProperty,t=(t,i,l)=>(((t,i,l)=>{i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[i]=l})(t,"symbol"!=typeof i?i+"":i,l),l);import{m as i}from"../como-admin-web/como-admin-web.4290f457.js";import{d as l}from"../como-ts-utils/como-ts-utils.52443996.js";import{B as a,Q as n}from"../BaseValidRule/BaseValidRule.98e536d5.js";import{B as o}from"../Controller/Controller.ef4ed6a0.js";const s=(e={},t=[],l=[])=>{var a,n,o,s,r,d,u,m,c;const f=[[i.ElementFormColumnGender.Ins.Name("配置项分组").Field("field_group").Required(!0).Type("select").List(t).Value(null!=(a=e.field_group)?a:"").Options({style:{width:"100%"},size:"large"}).Other("span",10).Convert(),i.ElementFormColumnGender.Ins.Name("配置项名称").Field("field_label").Required(!0).Value(null!=(n=e.field_label)?n:"").Other("span",14).Convert()],[i.ElementFormColumnGender.Ins.Name("配置项类型").Field("field_type").Required(!0).Type("select").List(l).Options({style:{width:"100%"},size:"large"}).Value(null!=(o=e.field_type)?o:[]).Other("span",10).Convert(),i.ElementFormColumnGender.Ins.Name("配置项索引").Field("field_index").Required(!0).Value(null!=(s=e.field_index)?s:"").Other("span",14).Convert()],[i.ElementFormColumnGender.Ins.Name("配置项的值").Field("field_value").Value(null!=(r=e.field_value)?r:"").Options({disabled:!0}).Other("span",10).Convert(),i.ElementFormColumnGender.Ins.Name("配置项说明").Field("field_desc").Value(null!=(d=e.field_desc)?d:"").Other("span",14).Convert()],i.ElementFormColumnGender.Ins.Name("配置项选项").Field("field_options").Type("textarea").Value(null!=(u=e.field_options)?u:"").Convert(),[i.ElementFormColumnGender.Ins.Name("配置项状态").Field("field_status").Type("switch").Value(null!=(m=e.field_status)?m:0).Other("span",10).Convert(),i.ElementFormColumnGender.Ins.Name("配置项排序").Field("field_sort").Value(null!=(c=e.field_sort)?c:99).Other("span",14).Convert()]];e.config_id&&f.push(i.ElementFormColumnGender.Ins.Name("").Type("hidden").Value(e.config_id).Field("config_id").Convert());return i.ComoFormComponent.Ins.FormConfig(f).SubmitButtonName("立即提交").ItemBottomMargin("20px").toObject()},r=function(e,t){let l=i.ElementFormColumnGender.Ins.Name(e.field_label).Field(e.field_index).Other("span",16).Type(e.field_type);return"radio"!=e.field_type&&"checkbox"!=e.field_type&&"select"!=e.field_type||e.field_options&&l.List(JSON.parse(e.field_options)),"checkbox"==e.field_type?e.field_value?l.Value(JSON.parse(e.field_value)):l.Value([]):"switch"==e.field_type&&e.field_value?l.Value(Number(e.field_value)):l.Value(e.field_value),"image"!=e.field_type&&"images"!=e.field_type||l.Options({httpRequest:e=>t(e),limit:"image"==e.field_type?1:10,accept:".jpg,.png,.gif,.bmp,.jpeg"}),l.Convert()},d=function(e,t){const l=[];return e.forEach((e=>{let a=[r(e,t),i.ElementFormColumnGender.Ins.Name(e.field_desc).Type("label").Other("span",8).Convert()];l.push(a)})),l};class u extends a{constructor(){super(...arguments),t(this,"config_id",l.ComoTsRuleUtil.Ins.Name("配置项ID").Required().NotEmpty().Number().Rules()),t(this,"field_label",l.ComoTsRuleUtil.Ins.Name("配置项名称").Required().NotEmpty().Trim().Rules()),t(this,"field_index",l.ComoTsRuleUtil.Ins.Name("配置项索引").Required().NotEmpty().Rules()),t(this,"field_type",l.ComoTsRuleUtil.Ins.Name("配置项类型").Required().NotEmpty().Rules()),t(this,"field_group",l.ComoTsRuleUtil.Ins.Name("配置项分组").Required().NotEmpty().Rules()),t(this,"createValidator",[{field:"field_group",ruleType:n.required},{field:"field_label",ruleType:n.required},{field:"field_index",ruleType:n.required},{field:"field_type",ruleType:n.required}]),t(this,"updateValidator",[{field:"field_group",ruleType:n.existisRequired},{field:"field_label",ruleType:n.existisRequired},{field:"field_index",ruleType:n.existisRequired},{field:"field_type",ruleType:n.existisRequired},{field:"config_id",ruleType:n.required}]),t(this,"deleteValidator",[{field:"config_id",ruleType:n.required}])}}class m extends o{constructor(){super(...arguments),t(this,"createSysConfig","CreateSysConfig"),t(this,"updateSysConfig","UpdateSysConfig"),t(this,"deleteSysConfig","DeleteSysConfig"),t(this,"formTypes",[{name:"单行输入框",value:"input"},{name:"多行输入框",value:"textarea"},{name:"单选",value:"radio"},{name:"多选",value:"checkbox"},{name:"下拉框",value:"select"},{name:"日期",value:"date"},{name:"日期与时间",value:"datetime"},{name:"月份",value:"month"},{name:"年份",value:"year"},{name:"开关",value:"switch"},{name:"颜色",value:"color"},{name:"单张图",value:"image"},{name:"多张图",value:"images"}])}async Select(e){const t=this;try{const i=await t.Request.Get("/Configs",e);if(!1!==i.error)throw new Error(i.message);return i.data}catch(i){return t.Exception(null==i?void 0:i.message),[]}}async FormSubmitHandle(e,t){const i=this;try{const l=new u,a=e.config_id?l.updateValidator:l.createValidator,n=await l.DataRuleAndValidator(a,e),o=n.config_id?"更新":"添加",s=n.config_id?await i.Request.Put("/Configs",n):await i.Request.Post("/Configs",n);if(!1!==s.error)throw new Error(s.message);(await i.Dialog()).Message(`配置项信息${o}成功`,{icon:"SUCCESS"},(()=>{i.dialogIns&&i.dialogIns.Close(),t()}))}catch(l){return void i.Exception(null==l?void 0:l.message)}}async Create(e,t=[],i){const l=this;try{l.RouteActionAuth(l.createSysConfig);const a=s(e,t,l.formTypes);l.dialogIns=await l.Dialog(),l.dialogIns.Form(a,{title:"添加配置项,红色*号为必填项",width:"800px",top:"20vh",callback:e=>l.FormSubmitHandle(e,i)})}catch(a){return void l.Exception(null==a?void 0:a.message)}}async Update(e,t=[],i){const l=this;try{l.RouteActionAuth(l.updateSysConfig);const a=s(e,t,l.formTypes);l.dialogIns=await l.Dialog(),l.dialogIns.Form(a,{title:`更新配置项【${e.field_label}】,红色*号为必填项`,width:"800px",top:"20vh",callback:e=>l.FormSubmitHandle(e,i)})}catch(a){return void l.Exception(null==a?void 0:a.message)}}async Delete(e,t){const i=this;try{i.RouteActionAuth(i.deleteSysConfig);const l={name:`配置项<span style="color:#ff0000;">【${e.field_label}】</span>`,title:"删除配置项信息提醒"};if(!(await i.DeleteHandle(l)))return;const a=await i.Request.Delete("/Configs",{config_id:e.config_id});if(!1!==a.error)throw new Error(a.message);(await i.Dialog()).Message(`${l.name}删除成功`,{icon:"SUCCESS"},t)}catch(l){return void i.Exception(null==l?void 0:l.message)}}async SwitchChangeConfig(e,t){const i=this;try{const l={config_id:e.row.config_id};l[e.prop]=e.value,i.FormSubmitHandle(l,t)}catch(l){return void i.Exception(null==l?void 0:l.message)}}async CreateSetSysConfigForm(){const e=this;try{const t=await e.Select({page:1,limit:1e3,field_status:1});let i=[];return t.forEach((t=>{let l={config:d(t.children,(t=>e.UploadImageHandle(t))),submitBtnName:"立即提交",formItemMarginBottom:"15px",submitBtnOptions:{type:"success",size:"default"}},a={name:t.name,value:t.value,children:l};i.push(a)})),i}catch(t){return e.Exception(null==t?void 0:t.message),[]}}async UploadImageHandle(e){const t=this;try{const i=await t.GetImageCompressOptions(),l=await t.ImageHandle.compress(e.file,i),a=await t.Request.Upload({url:"/Config/upload",fileObject:l.file,filename:"filename"});if(!1!==a.error)throw new Error(a.message);if("image"==e.data.uploadType||"file"==e.data.uploadType)e.data.change(a.data.savePath);else if("images"==e.data.uploadType){let t=e.data.value?e.data.value.split(","):[];t.unshift(a.data.savePath),e.data.change(t.join(","))}}catch(i){return void t.Exception(null==i?void 0:i.message)}}async SubmitSettingConfig(e){const t=this;try{const i=await t.Request.Post("/Configs/setting",{setting:e});if(!1!==i.error)throw new Error(i.message);(await t.Dialog()).Message("系统配置设置提交成功",{icon:"SUCCESS"})}catch(i){return void t.Exception(null==i?void 0:i.message)}}static get Ins(){return new this}}export{m as S};