UNPKG

@jecloud/func

Version:

JECloud 功能库

1 lines 4.18 kB
var e=this&&this.__assign||function(){return e=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var i in n=arguments[t])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e},e.apply(this,arguments)};import{createTextVNode as n,createVNode as t}from"vue";import{isEmpty as o,decode as i,previewFile as c,downloadFile as l,getDDItemCache as r,omit as a,toBoolean as u,getDDCache as f}from"@jecloud/utils";import{DatePicker as s}from"@jecloud/ui";import{FuncDataTypeEnum as d,FuncFieldTypeEnum as p}from"../../../data/enum";import{useColumnField as y}from"../../../form/src/hooks/use-func-field";import{parseConfigInfo as m}from"../../../field/src/config-info";export function useColumn(e){var n=e.gridAttrs,t=e.$grid,o=e.$func,i=t.getFuncData,c=t.type,l=i().getData("columns."+c).slice(0);h({columns:l,$func:o,type:c}),n.multiple&&l.unshift({type:"checkbox"});var r=l.find((function(e){return"before"===e.lock})),a=l.indexOf(r),u=l.find((function(e){return"after"===e.lock})),f=l.indexOf(u);return l.forEach((function(e,n){n<=a?e.fixed="left":-1!=f&&n>=f&&(e.fixed="right")})),l}var v=["seq","checkbox","radio","expand","html"];function h(e){var n=e.columns,t=e.$func,i=e.type;null==n||n.forEach((function(e){var n;e.slots=null!==(n=e.slots)&&void 0!==n?n:{},C({column:e,$func:t,type:i}),x({column:e,$func:t,type:i}),e.field&&o(e.children)&&!v.includes(e.type)&&(g({column:e,$func:t,type:i}),b({column:e,$func:t,type:i})),h({columns:e.children,$func:t,type:i})}))}function g(o){var a=o.column,y=o.$func,v=o.type;if(!a.slots.default){var h=y.getFuncData(),g=h.info.gridOptions.ddTdBackgroundColor,b=h.basic.fields.get(a.field);a.slots.default=function(o){var y,h=o.row,C=h[a.field];if(a.dictionary){var x=r(a.dictionary),k=f(a.dictionary);if("YESORNO"===a.dictionary&&a.switchStyle.enable){var E=u(C);C=t("div",{class:"switch-cell switch-layout-checkbox"},[t("i",{style:"font-size:18px",class:(y={"switch-cell-item-checked":E},y[a.switchStyle.checkIcon||"fas fa-check-square"]=E,y[a.switchStyle.checkIcon||"fal fa-square"]=!E,y)},null)])}else if(C)if("LIST"===(null==k?void 0:k.type)&&x){var O=C.split(","),$=a.ddColor.icon,j=a.ddColor.textColor,I=a.ddColor.backgroundColor,T="",w="",R=O.map((function(e){var n=x.find((function(n){return n.code===e}));return n?(j&&(T=n.textColor),I&&(w=n.backgroundColor),$&&n.icon?t("i",{class:["je-column-dictionary-icon",n.icon]},null):n.text):e}));C=g?t("span",{style:{color:T}},[$?R:R.join(",")]):t("div",{style:e({backgroundColor:w,color:T},I?{padding:"2px 8px",borderRadius:"10px",lineHeight:1,display:"inline-block"}:{})},[$?R:R.join(",")])}else{var D=m({configInfo:b.configInfo});C=h[D.fieldMaps.sourceToTarget.text[0]]}}else if((null==b?void 0:b.xtype)===p.UPLOAD_INPUT.type){var S=i(C)||{};C=S.relName?t("div",{class:"je-column-upload-cell"},[S.relName,t("span",{onClick:function(){return c(S.fileKey)}},[n("预览")]),n("|"),t("span",{onClick:function(){return l(S.fileKey)}},[n("下载")])]):null}else if([p.DATE_PICKER.type,p.TIME_PICKER.type].includes(null==b?void 0:b.xtype)){var N=b.configInfo,A=p.TIME_PICKER.type===b.xtype?"time":b.otherConfig.dateType;C=s.rendererDateValue({value:C,picker:A,format:N})}if(a.link.enable&&v===d.FUNC){C=t("span",{class:"je-column-link-cell"},[C])}return C},a.titleColor&&(a.slots.header=function(){return t("span",{style:{color:a.titleColor}},[a.title])})}}function b(e){var n=e.column,t=e.$func,o=e.type;if(n.editable&&o!==d.SELECT){var i=t.getFuncData().basic.fields.get(n.field);if(i)if("YESORNO"===n.dictionary)n.type="switch",Object.assign(n,a(n.switchStyle,["enable"])),delete n.slots.default;else{var c=y({field:i,column:n,$func:t}),l=c.editRender,r=c.editSlot;n.editRender=l,n.slots.edit=r}}}function C(e){var n=e.column,t=e.$func,o=(e.type,t.action.eventAction.bindGridColumnEvents);Object.assign(n,o({column:n})),n.onRenderer&&(n.slots.default=function(e){return n.onRenderer(e)})}function x(e){var n,t=e.column,o=e.$func;e.type;if("action"===t.type){var i=o.action.eventAction.bindActionButtonEvents,c=null!==(n=o.getFuncData().getData("buttons.action"))&&void 0!==n?n:[];c.forEach((function(e){Object.assign(e,i({button:e}))})),t.actionConfig={buttons:c}}}