UNPKG

@jecloud/ui

Version:

JECloud UI库,基于ant-design-vue封装

1 lines 1.99 kB
import{computed as e,ref as l,getCurrentInstance as o,isRef as n}from"vue";import{useInjectForm as r,useInjectFormItemContext as t}from"../form/src/context";import{useInjectGrid as i}from"../grid/src/context";import u from"../config-provider";import{useModelValue as d}from".";export function useField(f){var a=f.props,v=f.context,m=r(),c=t(),p=i(),g=a.model?d({props:a,context:v,key:"model"}):l(),s=u.getGlobalConfig("func"),b=null,x=null,y=o(),I=e((function(){for(var e,l,o,n=y.parent,r=10;r&&n;)["VxeTable","JeFormItem"].includes(null===(e=null==n?void 0:n.type)||void 0===e?void 0:e.name)?(o="VxeTable"==(null===(l=null==n?void 0:n.type)||void 0===l?void 0:l.name)?"grid":"formItem",r=0):(n=null==n?void 0:n.parent,r--);return o})).value,O=function(){var e,l={};if(g.value)l=g.value;else if("formItem"===I&&(null==m?void 0:m.enabled)&&(null==c?void 0:c.enabled))l=n(m.model)?m.model.value:m.model;else if("grid"===I&&p){var o=null!==(e=p.getActiveRecord())&&void 0!==e?e:{},r=o.row,t=o.column;l=r,b=null==t?void 0:t.field,x=null==t?void 0:t.title}else console.warn("未找到model数据,组件将无法正确赋值!");return null!=l?l:{}};return{parentType:I,getModel:O,setModel:function(e,l){void 0===e&&(e={}),void 0===l&&(l=!1);var o=O();l?Object.assign(o,e):Object.keys(e).forEach((function(l){Object.prototype.hasOwnProperty.call(o,l)&&(o[l]=e[l])}))},getModelOwner:function(){return{$form:m,$grid:p}},getName:function(){var e;if(b)return b;if(a.name)return a.name;if("formItem"===I&&(null==c?void 0:c.enabled))return c.name;if("grid"===I&&p){var l=(null!==(e=p.getActiveRecord())&&void 0!==e?e:{}).column;return null==l?void 0:l.field}},getLabel:function(){var e;if(x)return x;if(a.label)return a.label;if("formItem"===I&&(null==c?void 0:c.enabled))return c.label;if("grid"===I&&p){var l=(null!==(e=p.getActiveRecord())&&void 0!==e?e:{}).column;return null==l?void 0:l.title}},resetModel:function(e){void 0===e&&(e=[]);var l=O();e.forEach((function(e){l[e]=null}))},func:s}}