@jecloud/ui
Version:
JECloud UI库,基于ant-design-vue封装
1 lines • 1.88 kB
JavaScript
var e=this&&this.__assign||function(){return e=Object.assign||function(e){for(var l,n=1,u=arguments.length;n<u;n++)for(var o in l=arguments[n])Object.prototype.hasOwnProperty.call(l,o)&&(e[o]=l[o]);return e},e.apply(this,arguments)};import{ref as l,computed as n,watch as u}from"vue";import{useModelValue as o,useConfigInfo as t,useExtendMethods as a}from"../../hooks";import{isEmpty as i,pinyin as r}from"@jecloud/utils";export function useSelect(v){var c=v.props,s=v.context,p=s.emit,d=s.expose,f=t({props:c,context:s}),g=f.options,m=f.multiple,b=f.setValues,h=f.onDropdownVisibleChange,y=n((function(){return c.readonly||c.disabled})),w=n((function(){return m.value||c.multiple})),x=o({props:c,context:s,multiple:m.value,changeEvent:!0}),C=l(),L=a({plugin:C,keys:["blur","focus"]});d(e(e({},L),{$plugin:C}));var V=x,O=l();return!w.value&&c.editable&&(V=l(x.value),u((function(){return x.value}),(function(){var e,l=null===(e=g.value)||void 0===e?void 0:e.find((function(e){return e.value==x.value}));V.value=l?l.label:x.value}),{immediate:!0}),u((function(){return V.value}),(function(){var e,l=null===(e=g.value)||void 0===e?void 0:e.find((function(e){return e.value==V.value||e.label==V.value}));l?(x.value=l.value,V.value=l.label):x.value=V.value,O.value=V.value}))),{filterOption:function(e,l){var n,u,o;if(!e)return!0;e=null!==(n=null==e?void 0:e.toString().toLocaleLowerCase())&&void 0!==n?n:e;var t=l.value.toString().toLocaleLowerCase(),a=null!==(o=null===(u=l.label)||void 0===u?void 0:u.toString().toLocaleLowerCase())&&void 0!==o?o:t,i=r(a,"pinyin");return t.includes(e)||a.includes(e)||i.includes(e)},selectValue:V,computeReadonly:y,computeMultiple:w,onChange:function(e,l){w.value&&c.editable&&(null!=e?e:[]).forEach((function(e,n){i(l[n])&&(l[n]={label:e,value:e,text:e,code:e})})),p("change",e,l),b(l)},onDropdownVisibleChange:h,options:g,$plugin:C,searchValue:O}}