@jecloud/func
Version:
JECloud 功能库
1 lines • 6.67 kB
JavaScript
var e=this&&this.__extends||function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){function E(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(E.prototype=n.prototype,new E)}}(),t=this&&this.__awaiter||function(e,t,n,E){return new(n||(n=Promise))((function(i,r){function o(e){try{l(E.next(e))}catch(e){r(e)}}function a(e){try{l(E.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((E=E.apply(e,t||[])).next())}))},n=this&&this.__generator||function(e,t){var n,E,i,r,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,E&&(i=2&r[0]?E.return:r[0]?E.throw||((i=E.return)&&i.call(E),0):E.next)&&!(i=i.call(E,r[1])).done)return i;switch(E=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,E=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){o.label=r[1];break}if(6===r[0]&&o.label<i[1]){o.label=i[1],i=r;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(r);break}i[2]&&o.ops.pop(),o.trys.pop();continue}r=t.call(e,o)}catch(e){r=[6,e],E=0}finally{n=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}};import{toBoolean as E,isPlainObject as i,forEach as r,isEmpty as o,toNumber as a,decode as l,isNotEmpty as u,execScript as s}from"@jecloud/utils";import R from"../base";import{FuncFieldTypeEnum as p}from"../../enum";import{parseEvents as c}from"./util";var d=function(R){function d(e){var t,n,i,r,o,s=R.call(this,e)||this;switch(s.id=e.JE_CORE_RESOURCEFIELD_ID,s.name=e.RESOURCEFIELD_CODE,s.label=e.RESOURCEFIELD_NAME,s.xtype=e.RESOURCEFIELD_XTYPE,s.value=e.RESOURCEFIELD_VALUE,s.required=E(e.RESOURCEFIELD_REQUIRE),s.disabled=E(e.RESOURCEFIELD_READONLY),s.hidden=E(e.RESOURCEFIELD_HIDDEN),s.configInfo=e.RESOURCEFIELD_CONFIGINFO,s.labelAlign=e.RESOURCEFIELD_LABELALIGN||"right",s.querys=null!==(t=l(e.RESOURCEFIELD_WHERESQL))&&void 0!==t?t:[],s.groupName=null!==(n=e.RESOURCEFIELD_GROUPNAME)&&void 0!==n?n:"",s.orderIndex=a(e.SY_ORDERINDEX),s.colSpan=a(null!==(i=e.RESOURCEFIELD_COLSPAN)&&void 0!==i?i:1),s.cols=a(null!==(r=e.RESOURCEFIELD_COLS)&&void 0!==r?r:2),s.placeholder=e.RESOURCEFIELD_EMPTYTEXT,s.labelHidden=E(e.RESOURCEFIELD_HIDELABEL),s.labelColor=e.RESOURCEFIELD_LABELCOLOR,s.fieldColor=e.RESOURCEFIELD_FIELDCOLOR,s.height=a(e.RESOURCEFIELD_HEIGHT),s.width=a(e.RESOURCEFIELD_WIDTH),s.addonAfter=l(e.RESOURCEFIELD_UNITLISTTPL)||[],s.help={enable:u(e.RESOURCEFIELD_HELP),html:!0,message:e.RESOURCEFIELD_HELP,width:a(e.RESOURCEFIELD_HELP_TIP_W),height:a(e.RESOURCEFIELD_HELP_TIP_H)},s.exps={data:{exp:e.RESOURCEFIELD_BINDING,fn:e.RESOURCEFIELD_BINDINGFN},visible:{exp:e.RESOURCEFIELD_INTERPRETER,fn:e.RESOURCEFIELD_INTERPRETERFN},readOnly:{exp:e.RESOURCEFIELD_READONLYEXP,fn:e.RESOURCEFIELD_READONLYEXPFN},required:{exp:e.RESOURCEFIELD_REQUIRE_EXP,fn:e.RESOURCEFIELD_REQUIRE_EXPFN},select:{exp:e.RESOURCEFIELD_ENABLEEXP,fn:e.RESOURCEFIELD_ENABLEEXPFN,message:e.RESOURCEFIELD_ENABLETIP}},s.selectExp,s.expsEnable=!1,Object.keys(s.exps).forEach((function(e){var t=s.exps[e];t.exp||t.fn?"select"===e?s.selectExp=t:s.expsEnable=!0:delete s.exps[e]})),s.validation={regex:e.RESOURCEFIELD_REGEX,regexMessage:e.RESOURCEFIELD_REGEXTEXT,max:a(e.RESOURCEFIELD_MAXLENGTH),vtype:e.RESOURCEFIELD_VTYPE,vtypeFn:e.RESOURCEFIELD_VTYPEFN},s.funcId=e.RESOURCEFIELD_FUNCINFO_ID,s.events=c(e.RESOURCEFIELD_JSLISTENER),s.otherConfig=null!==(o=l(e.RESOURCEFIELD_OTHERCONFIG))&&void 0!==o?o:{},s.anchor=!1,s.children=[],s.xtype){case p.INPUT_CODE.type:s.value="<系统自动生成>",s.readOnly=!0,s.disabled=!0;break;case p.FUNC_CHILD.type:s.groupName="";break;case p.FIELDSET.type:s.anchor=E(s.otherConfig.quickPositioning)}return s}return e(d,R),Object.defineProperty(d.prototype,"code",{get:function(){return this.name},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"text",{get:function(){return this.label},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"readOnly",{get:function(){return this.disabled},set:function(e){this.disabled=e},enumerable:!1,configurable:!0}),d.prototype.addChild=function(e,t){var n=this;i(e)&&(e=[e]),r(e,(function(E){E.isModel||(E=new d(E)),n.name===E.groupName&&(t&&E.addChild(e,t),n.children.push(E))}))},d.prototype.isFormItem=function(){return![p.FIELDSET.type,p.FUNC_CHILD.type].includes(this.xtype)},d.prototype.isBeanField=function(){return![p.FIELDSET.type,p.FUNC_CHILD.type,p.FUNC_CHILD_FIELD.type,p.DISPLAY.type].includes(this.xtype)},d.prototype.getDefaultValue=function(){return o(this.value)&&[p.INPUT_NUMBER.type].includes(this.xtype)&&(this.value=this.required?this.value:0),this.value},d.prototype.getRules=function(e){var E,i=this,r=[];if(this.xtype===p.FUNC_CHILD_FIELD.type)return r.push({required:this.required,message:"该输入项为必填项",validator:function(){for(var E=[],r=0;r<arguments.length;r++)E[r]=arguments[r];return t(i,void 0,void 0,(function(){var t,i;return n(this,(function(n){return[2,null===(i=null===(t=e.$field)||void 0===t?void 0:t.value)||void 0===i?void 0:i.validator.apply(i,E)]}))}))}}),r;switch(this.required&&r.push({required:!0,message:"该输入项为必填项"}),this.validation.regex&&r.push({pattern:new RegExp(this.validation.regex),message:this.validation.regexMessage}),this.validation.max>0&&r.push({max:a(this.validation.max),message:"该输入内容最大长度为"+this.validation.max+"字"}),this.validation.vtype){case"method":if(this.validation.vtypeFn){var l=null!==(E=s(this.validation.vtypeFn,e))&&void 0!==E?E:[];r.push.apply(r,l)}break;case"unique":r.push({message:"该输入项已存在,请重新输入",validator:function(E,r){return t(i,void 0,void 0,(function(){return n(this,(function(t){return o(r)?[2,!0]:[2,e.$func.action.baseAction.checkFieldUnique([{fieldCode:this.name,value:r}])]}))}))}})}return r.forEach((function(e){e.message=e.message||"该输入项不符合验证规则"})),r},d}(R);export default d;export function parseDisplayFields(e){var t=[];return e.forEach((function(n){!n.hidden&&o(n.groupName)&&(n.addChild(e,!0),t.push(n))})),t}