index-d315d9dc.js 3.1 KB

1
  1. import{c as A,ad as b,m as f,t as F,d as g,bo as L,r as N,Z as P,a as l,af as h,h as T,p as D,k as O,x as U,w as K,I as M,C as j,A as z}from"./index-869d77fb.js";import{f as k,F as Z}from"./index-0153d173.js";const[$,o,G]=A("search"),H=b({},k,{label:String,shape:f("square"),leftIcon:f("search"),clearable:F,actionText:String,background:String,showAction:Boolean});var J=g({name:$,props:H,emits:["blur","focus","clear","search","cancel","clickInput","clickLeftIcon","clickRightIcon","update:modelValue"],setup(a,{emit:n,slots:c,attrs:t}){const s=L(),u=N(),m=()=>{c.action||(n("update:modelValue",""),n("cancel"))},I=e=>{e.keyCode===13&&(D(e),n("search",a.modelValue))},d=()=>a.id||`${s}-input`,p=()=>{if(c.label||a.label)return l("label",{class:o("label"),for:d()},[c.label?c.label():a.label])},_=()=>{if(a.showAction){const e=a.actionText||G("cancel");return l("div",{class:o("action"),role:"button",tabindex:0,onClick:m},[c.action?c.action():e])}},y=()=>{var e;return(e=u.value)==null?void 0:e.blur()},C=()=>{var e;return(e=u.value)==null?void 0:e.focus()},S=e=>n("blur",e),v=e=>n("focus",e),B=e=>n("clear",e),V=e=>n("clickInput",e),w=e=>n("clickLeftIcon",e),x=e=>n("clickRightIcon",e),R=Object.keys(k),E=()=>{const e=b({},t,h(a,R),{id:d()}),i=q=>n("update:modelValue",q);return l(Z,T({ref:u,type:"search",class:o("field"),border:!1,onBlur:S,onFocus:v,onClear:B,onKeypress:I,onClickInput:V,onClickLeftIcon:w,onClickRightIcon:x,"onUpdate:modelValue":i},e),h(c,["left-icon","right-icon"]))};return P({focus:C,blur:y}),()=>{var e;return l("div",{class:o({"show-action":a.showAction}),style:{background:a.background}},[(e=c.left)==null?void 0:e.call(c),l("div",{class:o("content",a.shape)},[p(),E()]),_()])}}});const Q=O(J),W="_white_1oqt0_25",X="_transparent_1oqt0_28",Y="_searchBtn_1oqt0_40",r={"m-search":"_m-search_1oqt0_1",default:"_default_1oqt0_22",white:W,transparent:X,searchBtn:Y},ee=""+new URL("icon-search-d43eb2c3.svg",import.meta.url).href,ne=g({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:ee},inputBackground:{type:String,default:"default"}},emits:["search","focus","blur"],setup(a,{slots:n,emit:c}){const t=U({search:a.modelValue||""});return K(()=>a.modelValue,()=>{t.search=a.modelValue}),()=>l(Q,{class:[r["m-search"],r[a.inputBackground]],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":s=>t.search=s,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":()=>l(M,{name:a.searchIcon,class:r.leftIcon},null),"right-icon":()=>l(j,{disabled:a.disabled,class:r.searchBtn,round:!0,type:"primary",size:"mini",onClick:()=>c("search",t.search)},{default:()=>[z("搜索")]})})}});export{ne as M};