index-28950e57.js 3.3 KB

1
  1. import{c as L,aj as m,m as b,t as N,d as k,bn as P,r as I,a3 as T,a as o,al as g,h as U,p as D,k as O,x as j,w as K,I as M,C as q,A as z}from"./index-b80927fb.js";import{f as p,F as $}from"./index-a60cffc2.js";const[G,s,H]=L("search"),J=m({},p,{label:String,shape:b("square"),leftIcon:b("search"),clearable:N,actionText:String,background:String,showAction:Boolean});var Q=k({name:G,props:J,emits:["blur","focus","clear","search","cancel","clickInput","clickLeftIcon","clickRightIcon","update:modelValue"],setup(a,{emit:n,slots:c,attrs:d}){const t=P(),r=I(),i=()=>{c.action||(n("update:modelValue",""),n("cancel"))},l=e=>{e.keyCode===13&&(D(e),n("search",a.modelValue))},f=()=>a.id||`${t}-input`,_=()=>{if(c.label||a.label)return o("label",{class:s("label"),for:f()},[c.label?c.label():a.label])},y=()=>{if(a.showAction){const e=a.actionText||H("cancel");return o("div",{class:s("action"),role:"button",tabindex:0,onClick:i},[c.action?c.action():e])}},C=()=>{var e;return(e=r.value)==null?void 0:e.blur()},B=()=>{var e;return(e=r.value)==null?void 0:e.focus()},v=e=>n("blur",e),S=e=>n("focus",e),V=e=>n("clear",e),w=e=>n("clickInput",e),x=e=>n("clickLeftIcon",e),R=e=>n("clickRightIcon",e),E=Object.keys(p),A=()=>{const e=m({},d,g(a,E),{id:f()}),h=F=>n("update:modelValue",F);return o($,U({ref:r,type:"search",class:s("field"),border:!1,onBlur:v,onFocus:S,onClear:V,onKeypress:l,onClickInput:w,onClickLeftIcon:x,onClickRightIcon:R,"onUpdate:modelValue":h},e),g(c,["left-icon","right-icon"]))};return T({focus:B,blur:C}),()=>{var e;return o("div",{class:s({"show-action":a.showAction}),style:{background:a.background}},[(e=c.left)==null?void 0:e.call(c),o("div",{class:s("content",a.shape)},[_(),A()]),y()])}}});const W=O(Q),X="_white_omrn1_29",Y="_transparent_omrn1_32",Z="_searchBtn_omrn1_44",ee="_leftIcon_omrn1_59",u={"m-search":"_m-search_omrn1_1",default:"_default_omrn1_26",white:X,transparent:Y,searchBtn:Z,leftIcon:ee},ae=""+new URL("icon-search-bf97b20b.svg",import.meta.url).href,te=k({name:"m-search",props:{modelValue:{type:String,default:""},shape:{type:String,default:"round"},disabled:{type:Boolean,default:!1},clearable:{type:Boolean,default:!0},autofocus:{type:Boolean,default:!1},placeholder:{type:String,default:"请输入搜索关键词"},background:{type:String,default:"#fff"},searchIcon:{type:String,default:ae},inputBackground:{type:String,default:"default"}},emits:["search","focus","blur","searchUpdate"],setup(a,{slots:n,emit:c,expose:d}){const t=j({search:a.modelValue||""}),r=I();return K(()=>a.modelValue,()=>{t.search=a.modelValue}),d({searchBlur:()=>{var l;(l=r.value)==null||l.blur()}}),()=>o(W,{class:[u["m-search"],u[a.inputBackground]],ref:r,shape:a.shape,background:a.background,placeholder:a.placeholder,disabled:a.disabled,autofocus:a.autofocus,autocomplete:"off",clearable:a.clearable,modelValue:t.search,"onUpdate:modelValue":[l=>t.search=l,l=>{c("searchUpdate",l)}],clearTrigger:"always",onClear:()=>{console.log("clear"),t.search="",c("search",t.search)},onFocus:()=>c("focus"),onBlur:()=>c("blur",t.search),onSearch:()=>c("search",t.search)},{left:()=>n.left&&n.left(),"left-icon":()=>o(M,{name:a.searchIcon,class:u.leftIcon},null),"right-icon":()=>o(q,{disabled:a.disabled,class:u.searchBtn,round:!0,type:"primary",size:"mini",onClick:()=>c("search",t.search)},{default:()=>[z("搜索")]})})}});export{te as M};