You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
7.3 KiB

import{j as V,T as Be,a0 as H,N as G,k as I,H as L,a3 as $,a8 as j,a as O,m as Pe,P as ue,s as ce,af as Se,E as re,b as r,M as ve,ab as me,n as pe,Y as de,I as R,G as Ve,V as Ie,q as k,aM as $e,v as J,bi as Q,a4 as je,a6 as fe,K as Ee,bj as Ae,O as Ye,__tla as Ke}from"./index.2ddf0537.js";import{a as Fe,T as qe,__tla as ze}from"./index.09abd82d.js";let he,U,Ge=Promise.all([(()=>{try{return Ke}catch{}})(),(()=>{try{return ze}catch{}})()]).then(async()=>{const[be,h,W]=V("picker"),X=e=>e.find(a=>!a.disabled)||e[0];function ge(e,a){const l=e[0];if(l){if(Array.isArray(l))return"multiple";if(a.children in l)return"cascade"}return"default"}function E(e,a){a=G(a,0,e.length);for(let l=a;l<e.length;l++)if(!e[l].disabled)return l;for(let l=a-1;l>=0;l--)if(!e[l].disabled)return l;return 0}const Z=(e,a,l)=>a!==void 0&&!!e.find(c=>c[l.value]===a);function A(e,a,l){const c=e.findIndex(p=>p[l.value]===a),o=E(e,c);return e[o]}function ye(e,a,l){const c=[];let o={[a.children]:e},p=0;for(;o&&o[a.children];){const d=o[a.children],v=l.value[p];if(o=Be(v)?A(d,v,a):void 0,!o&&d.length){const s=X(d)[a.value];o=A(d,s,a)}p++,c.push(d)}return c}function xe(e){const{transform:a}=window.getComputedStyle(e),l=a.slice(7,a.length-1).split(", ")[5];return Number(l)}function ke(e){return H({text:"text",value:"value",children:"children"},e)}const ee=200,te=300,we=15,[le,Y]=V("picker-column"),ne=Symbol(le);var He=I({name:le,props:{value:L,fields:$(Object),options:j(),readonly:Boolean,allowHtml:Boolean,optionHeight:$(Number),swipeDuration:$(L),visibleOptionNum:$(L)},emits:["change","clickOption"],setup(e,{emit:a,slots:l}){let c,o,p,d,v;const s=O(),b=O(),m=O(0),f=O(0),w=Pe(),T=()=>e.options.length,_=()=>e.optionHeight*(+e.visibleOptionNum-1)/2,x=i=>{const t=E(e.options,i),n=-t*e.optionHeight,u=()=>{const y=e.options[t][e.fields.value];y!==e.value&&a("change",y)};c&&n!==m.value?v=u:u(),m.value=n},g=()=>e.readonly||!e.options.length,F=i=>{c||g()||(v=null,f.value=ee,x(i),a("clickOption",e.options[i]))},D=i=>G(Math.round(-i/e.optionHeight),0,T()-1),M=(i,t)=>{const n=Math.abs(i/t);i=m.value+n/.003*(i<0?-1:1);const u=D(i);f.value=+e.swipeDuration,x(u)},B=()=>{c=!1,f.value=0,v&&(v(),v=null)},q=i=>{if(!g()){if(w.start(i),c){const t=xe(b.value);m.value=Math.min(0,t-_())}f.value=0,o=m.value,p=Date.now(),d=o,v=null}},z=i=>{if(g())return;w.move(i),w.isVertical()&&(c=!0,ve(i,!0)),m.value=G(o+w.deltaY.value,-(T()*e.optionHeight),e.optionHeight);const t=Date.now();t-p>te&&(p=t,d=m.value)},P=()=>{if(g())return;const i=m.value-d,t=Date.now()-p;if(t<te&&Math.abs(i)>we){M(i,t);return}const n=D(m.value);f.value=ee,x(n),setTimeout(()=>{c=!1},0)},S=()=>{const i={height:`${e.optionHeight}px`};return e.options.map((t,n)=>{const u=t[e.fields.text],{disabled:y}=t,C=t[e.fields.value],De={role:"button",style:i,tabindex:y?-1:0,class:[Y("item",{disabled:y,selected:C===e.value}),t.className],onClick:()=>F(n)},Me={class:"van-ellipsis",[e.allowHtml?"innerHTML":"textContent"]:u};return r("li",De,[l.option?l.option(t):r("div",Me,null)])})};return ue(ne),ce({stopMomentum:B}),Se(()=>{const i=e.options.findIndex(n=>n[e.fields.value]===e.value),t=-E(e.options,i)*e.optionHeight;m.value=t}),re("touchmove",z,{target:s}),()=>r("div",{ref:s,class:Y(),onTouchstartPassive:q,onTouchend:P,onTouchcancel:P},[r("ul",{ref:b,style:{transform:`translate3d(0, ${m.value+_()}px, 0)`,transitionDuration:`${f.value}ms`,transitionProperty:f.value?"all":"none"},class:Y("wrapper"),onTransitionend:B},[S()])])}});const[Oe]=V("picker-toolbar"),N={title:String,cancelButtonText:String,confirmButtonText:String},Te=["cancel","confirm","title","toolbar"],Ce=Object.keys(N);var ae=I({name:Oe,props:N,emits:["confirm","cancel"],setup(e,{emit:a,slots:l}){const c=()=>{if(l.title)return l.title();if(e.title)return r("div",{class:[h("title"),"van-ellipsis"]},[e.title])},o=()=>a("cancel"),p=()=>a("confirm"),d=()=>{const s=e.cancelButtonText||W("cancel");return r("button",{type:"button",class:[h("cancel"),me],onClick:o},[l.cancel?l.cancel():s])},v=()=>{const s=e.confirmButtonText||W("confirm");return r("button",{type:"button",class:[h("confirm"),me],onClick:p},[l.confirm?l.confirm():s])};return()=>r("div",{class:h("toolbar")},[l.toolbar?l.toolbar():[d(),c(),v()]])}});const[oe,K]=V("picker-group"),ie=Symbol(oe),Ne=H({tabs:j()},N);I({name:oe,props:Ne,emits:["confirm","cancel"],setup(e,{emit:a,slots:l}){const{children:c,linkChildren:o}=pe(ie);o();const p=()=>{a("confirm",c.map(v=>v.confirm()))},d=()=>a("cancel");return()=>{var v;const s=(v=l.default)==null?void 0:v.call(l);return r("div",{class:K()},[r(ae,de(e,{onConfirm:p,onCancel:d}),null),r(Fe,{shrink:!0,class:K("tabs"),animated:!0},{default:()=>[e.tabs.map((b,m)=>r(qe,{title:b,titleClass:K("tab-title")},{default:()=>[s==null?void 0:s[m]]}))]})])}}});let se;U=H({loading:Boolean,readonly:Boolean,allowHtml:Boolean,optionHeight:R(44),showToolbar:Ve,swipeDuration:R(1e3),visibleOptionNum:R(6)},N),se=H({},U,{columns:j(),modelValue:j(),toolbarPosition:Ie("top"),columnsFieldNames:Object});var _e=I({name:be,props:se,emits:["confirm","cancel","change","clickOption","update:modelValue"],setup(e,{emit:a,slots:l}){const c=O(),o=O(e.modelValue.slice(0)),{parent:p}=ue(ie),{children:d,linkChildren:v}=pe(ne);v();const s=k(()=>ke(e.columnsFieldNames)),b=k(()=>$e(e.optionHeight)),m=k(()=>ge(e.columns,s.value)),f=k(()=>{const{columns:t}=e;switch(m.value){case"multiple":return t;case"cascade":return ye(t,s.value,o);default:return[t]}}),w=k(()=>f.value.some(t=>t.length)),T=k(()=>f.value.map((t,n)=>A(t,o.value[n],s.value))),_=k(()=>f.value.map((t,n)=>t.findIndex(u=>u[s.value.value]===o.value[n]))),x=(t,n)=>{if(o.value[t]!==n){const u=o.value.slice(0);u[t]=n,o.value=u}},g=()=>({selectedValues:o.value.slice(0),selectedOptions:T.value,selectedIndexes:_.value}),F=(t,n)=>{x(n,t),m.value==="cascade"&&o.value.forEach((u,y)=>{const C=f.value[y];Z(C,u,s.value)||x(y,C.length?C[0][s.value.value]:void 0)}),a("change",H({columnIndex:n},g()))},D=(t,n)=>a("clickOption",H({columnIndex:n,currentOption:t},g())),M=()=>{d.forEach(n=>n.stopMomentum());const t=g();return Ee(()=>{a("confirm",t)}),t},B=()=>a("cancel",g()),q=()=>f.value.map((t,n)=>r(He,{value:o.value[n],fields:s.value,options:t,readonly:e.readonly,allowHtml:e.allowHtml,optionHeight:b.value,swipeDuration:e.swipeDuration,visibleOptionNum:e.visibleOptionNum,onChange:u=>F(u,n),onClickOption:u=>D(u,n)},{option:l.option})),z=t=>{if(w.value){const n={height:`${b.value}px`},u={backgroundSize:`100% ${(t-b.value)/2}px`};return[r("div",{class:h("mask"),style:u},null),r("div",{class:[Ae,h("frame")],style:n},null)]}},P=()=>{const t=b.value*+e.visibleOptionNum,n={height:`${t}px`};return r("div",{ref:c,class:h("columns"),style:n},[q(),z(t)])},S=()=>{if(e.showToolbar&&!p)return r(ae,de(fe(e,Ce),{onConfirm:M,onCancel:B}),fe(l,Te))};J(f,t=>{t.forEach((n,u)=>{n.length&&!Z(n,o.value[u],s.value)&&x(u,X(n)[s.value.value])})},{immediate:!0});let i;return J(()=>e.modelValue,t=>{!Q(t,o.value)&&!Q(t,i)&&(o.value=t.slice(0))},{deep:!0}),J(o,t=>{Q(t,e.modelValue)||(i=t.slice(0),a("update:modelValue",i))},{immediate:!0}),re("touchmove",ve,{target:c}),ce({confirm:M,getSelectedOptions:()=>T.value}),()=>{var t,n;return r("div",{class:h()},[e.toolbarPosition==="top"?S():null,e.loading?r(je,{class:h("loading")},null):null,(t=l["columns-top"])==null?void 0:t.call(l),P(),(n=l["columns-bottom"])==null?void 0:n.call(l),e.toolbarPosition==="bottom"?S():null])}}});he=Ye(_e)});export{he as P,Ge as __tla,U as p};