UNPKG

dk-plus

Version:
2 lines (1 loc) 6.88 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),Z=require("./index3.js"),ee=require("./index4.js"),r=require("../../_hooks/get-input/index.js"),te=require("../../_hooks/public/get-return/index.js");require("../../_icon/index.js");const ne={key:1},oe={key:0,class:"dk-input_label-text"},se={key:1,class:"dk-input_prefix"},le=["type"],re={key:2,class:"dk-input_length"},ae={key:3,class:"dk-input_length"},ce={key:4,class:"dk-input_suffix"},ie={key:1},pe=["type"],ue={key:0,class:"dk-input_textarea_length"},de={key:1,class:"dk-input_length"},me=e.defineComponent({__name:"input",props:Z.dkInputProps,emits:ee.inputEmits,setup(L,{emit:A}){const a=L,c=A,k=e.useSlots(),v=e.shallowRef(),x=e.shallowRef(),d=e.computed(()=>v.value||x.value),{classList:P,styleList:C,wrapperClassList:w,innerClassList:$,pendStyleList:B}=r.getInput(a),m=e.ref(a.modelValue),_=e.ref(!1),V=e.ref(!1),n=r.setPropData(a),u=e.ref(a.modelValue);let i=!1,p=e.ref(r.verifyInputType(n.typeProp,i));const j=(t="")=>{let o="";return n.maxlengthProp&&n.minlengthProp?o=`${n.minlengthProp}/${n.maxlengthProp}`:n.maxlengthProp?o=`${t.toString().length}/${n.maxlengthProp}`:n.minlengthProp&&(o=`${n.minlengthProp}`),o},s=r.setData(n,k,p.value),q=e.computed(()=>r.getNull(u.value));let h=j();const I=e.reactive({isPrependText:r.getBooleanAnd([!k.prepend,r.getNull(n.prependText),!s.isPrependIcon]),isAppendText:r.getBooleanAnd([r.getNull(n.appendText),!k.append,!s.isAppendIcon])}),R=["dk-input_prepend","dk-input_pend"],K=["dk-input_append","dk-input_pend"],g=e.ref(0);e.watch(()=>a.modelValue,()=>{u.value=r.getValue(a.modelValue,n.prependText,n.prependIcon,n.appendText,n.appendIcon),m.value=u.value}),e.watch(()=>u.value,t=>{const o=t.toString().length;if(n.maxlengthProp&&(h=`${o}/${n.maxlengthProp}`),z().autosize){const l=d.value;l.style.height="auto",l.style.height=`${l.scrollHeight+2}px`}s.showLength&&(g.value=o),n.typeProp==="number"?c("update:modelValue",Number(t)):c("update:modelValue",r.getPendValue(t,n.prependText,n.prependIcon,n.appendText,n.appendIcon))});const S=t=>{const o=t.target;u.value=o.value},M=()=>["dk-input_prefix-icon",typeof n.prefixIcon=="boolean"?"dk-icon-search":n.prefixIcon],H=()=>["dk-input_suffix-icon",typeof n.suffixIcon=="boolean"?"dk-icon-search":n.suffixIcon],O=()=>{m.value="",c("update:modelValue",""),N()},N=async()=>{var t;await e.nextTick(),(t=d.value)==null||t.focus()};let E=e.ref("IconPasswordSee");const F=()=>{var t,o;i=!i,E.value=i?"IconPasswordShow":"IconPasswordSee",p.value=i?"text":"password",i?(t=d.value)==null||t.setAttribute("type","text"):(o=d.value)==null||o.setAttribute("type","password"),N()},U=()=>["dk-input_password-icon"],T=t=>{_.value=!0,c("focus",t)},b=t=>{_.value=!1,c("blur",t)},{getRun:y}=te.getReturn(),G=t=>{y(a.onAppendClick,t)},J=t=>{y(a.onPrependClick,t)},Q=t=>{if(t.which===13){const o=t.target;y(a.onEnter,o.value)}},z=()=>{let t=1;const o=p.value==="textarea",l=n.autosizeProp,f=+n.rowsProp,Y=f>0;return o&&Y&&(t=f),{row:t,autosize:o&&l}},D=t=>{const o=t.target;c("change",o.value)},W=e.reactive({class:$.value,placeholder:n.placeholder,oninput:S,disabled:n.disabledProp,inputmode:s.inputmode,onfocus:T,onblur:b,onChange:D,maxlength:n.maxlengthProp,minlength:n.minlengthProp,readonly:n.readonlyProp}),X=e.reactive({class:w.value,type:p.value,placeholder:n.placeholder,onInput:S,onfocus:T,onblur:b,onChange:D,disabled:n.disabledProp,maxlength:n.maxlengthProp,minlength:n.minlengthProp,autosize:n.autosizeProp,rows:z().row,readonly:n.readonlyProp});return(t,o)=>{const l=e.resolveComponent("dk-icon");return t.type!=="textarea"?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass([e.unref(P),"dk-input"]),style:e.normalizeStyle(e.unref(C))},[!V.value&&e.unref(s).isPrepend?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(R),style:e.normalizeStyle(e.unref(B))},[e.renderSlot(t.$slots,"prepend"),e.unref(s).isPrependIcon?(e.openBlock(),e.createBlock(l,{key:0,icon:t.prependIcon,onClick:J},null,8,["icon"])):e.createCommentVNode("",!0),I.isPrependText?(e.openBlock(),e.createElementBlock("span",ne,e.toDisplayString(t.prependText),1)):e.createCommentVNode("",!0)],4)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(e.unref(w))},[e.unref(s).labelText?(e.openBlock(),e.createElementBlock("div",oe,[e.createElementVNode("span",null,e.toDisplayString(e.unref(s).labelText),1)])):e.createCommentVNode("",!0),e.unref(s).isPrefix?(e.openBlock(),e.createElementBlock("span",se,[e.renderSlot(t.$slots,"prefix"),e.unref(s).isPrefixIcon?(e.openBlock(),e.createBlock(l,{key:0,class:e.normalizeClass(M),icon:t.prefixIcon,size:"19px"},null,8,["icon"])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("input",e.mergeProps({ref_key:"input",ref:v,"onUpdate:modelValue":o[0]||(o[0]=f=>m.value=f),type:e.unref(p)},W,{onKeydown:e.withKeys(Q,["enter"])}),null,16,le),[[e.vModelDynamic,m.value]]),e.unref(s).isLength?(e.openBlock(),e.createElementBlock("span",re,e.toDisplayString(e.unref(h)),1)):e.createCommentVNode("",!0),t.showLength?(e.openBlock(),e.createElementBlock("span",ae,e.toDisplayString(g.value),1)):e.createCommentVNode("",!0),e.unref(s).isSuffix?(e.openBlock(),e.createElementBlock("div",ce,[e.renderSlot(t.$slots,"suffix"),e.unref(s).isSuffixIcon?(e.openBlock(),e.createBlock(l,{key:0,class:e.normalizeClass(H),icon:t.suffixIcon},null,8,["icon"])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.unref(s).isClear?e.withDirectives((e.openBlock(),e.createBlock(l,{key:5,class:"dk-input-clearable",icon:"IconShanchu1",onClick:O},null,512)),[[e.vShow,q.value]]):e.createCommentVNode("",!0),e.unref(s).isShowPassword?(e.openBlock(),e.createBlock(l,{key:6,class:e.normalizeClass(U),icon:e.unref(E),onClick:F},null,8,["icon"])):e.createCommentVNode("",!0)],2),!V.value&&e.unref(s).isAppend?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(K),style:e.normalizeStyle(e.unref(B))},[e.renderSlot(t.$slots,"append"),e.unref(s).isAppendIcon?(e.openBlock(),e.createBlock(l,{key:0,icon:t.appendIcon,onClick:G},null,8,["icon"])):e.createCommentVNode("",!0),I.isAppendText?(e.openBlock(),e.createElementBlock("span",ie,e.toDisplayString(t.appendText),1)):e.createCommentVNode("",!0)],4)):e.createCommentVNode("",!0)],6)):(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(e.unref(P)),style:e.normalizeStyle(e.unref(C))},[e.createElementVNode("textarea",e.mergeProps({ref_key:"textarea",ref:x,type:e.unref(p)},X),null,16,pe),e.unref(s).isLength?(e.openBlock(),e.createElementBlock("span",ue,e.toDisplayString(e.unref(h)),1)):e.createCommentVNode("",!0),t.showLength?(e.openBlock(),e.createElementBlock("span",de,e.toDisplayString(g.value),1)):e.createCommentVNode("",!0)],6))}}});exports.default=me;