wot-design-uni/demo/assets/wd-picker-view.Dx6zaZVA.js

2 lines
5.3 KiB
JavaScript

var e=Object.defineProperty,a=Object.defineProperties,t=Object.getOwnPropertyDescriptors,l=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,r=(a,t,l)=>t in a?e(a,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[t]=l,s=(e,a)=>{for(var t in a||(a={}))n.call(a,t)&&r(e,t,a[t]);if(l)for(var t of l(a))o.call(a,t)&&r(e,t,a[t]);return e},u=(e,l)=>a(e,t(l));import{M as i,aL as c,O as d,d as m,r as v,C as p,J as g,b as f,g as h,w as y,z as b,h as w,i as k,E as _,aM as C,m as x,F as O,n as K,aN as $,q as j,j as P,t as I,at as S,aD as E,aO as H,au as D,B as V}from"./index-ChV97F5w.js";import{i as A}from"./page-wraper.D9WpzC1k.js";import{b as F,f as N,c as T,a as q,m as z,_ as B}from"./base64.D3gEw_Hf.js";const L=u(s({},F),{loading:T(!1),loadingColor:q("#4D80F0"),columnsHeight:z(217),itemHeight:z(35),valueKey:q("value"),labelKey:q("label"),immediateChange:T(!1),modelValue:{type:[String,Number,Boolean,Array,Array,Array],default:"",required:!0},columns:N(),columnChange:Function});function M(e,a,t){let l=i(e)?e:[e];const n=new Set(e.map(c));if(1!==n.size&&n.has("object"))throw Error("The columns are correct");i(e[0])||(l=[l]);return l.map((e=>e.map((e=>{if(!d(e))return{[a]:e,[t]:e};if(!e.hasOwnProperty(a)&&!e.hasOwnProperty(t))throw Error("Can't find valueKey and labelKey in columns");return e.hasOwnProperty(t)||(e[t]=e[a]),e.hasOwnProperty(a)||(e[a]=e[t]),e}))))}const G=B(m(u(s({},{name:"wd-picker-view",options:{virtualHost:!0,addGlobalClass:!0,styleIsolation:"shared"}}),{props:L,emits:["change","pickstart","pickend","update:modelValue"],setup(e,{expose:a,emit:t}){const l=e,n=t,o=v([]),r=v([]);p([()=>l.modelValue,()=>l.columns],((e,a)=>{D(a[1],e[1])||(i(e[1])&&e[1].length>0?o.value=M(e[1],l.valueKey,l.labelKey):(o.value=[],r.value=[])),V(e[0])&&function(e){if(0===o.value.length)return void(r.value=[]);(""===e||!V(e)||i(e)&&0===e.length)&&(e=o.value.map((e=>e[0][l.valueKey])));const a=c(e),t=["string","number","boolean","array"];-1===t.indexOf(a)&&console.error(`value must be one of ${t.toString()}`);e=(e=i(e)?e:[e]).slice(0,o.value.length);let n=S(r.value);e.forEach(((e,a)=>{let t=o.value[a].findIndex((a=>a[l.valueKey].toString()===e.toString()));t=-1===t?0:t,n=u(a,t,n)})),r.value=n.slice(0,e.length)}(e[0])}),{deep:!0,immediate:!0});const{proxy:s}=g();function u(e,a,t){const l=o.value[e];if(!l||!l[a])throw Error(`The value to select with Col:${e} Row:${a} is incorrect`);const n=S(t);if(n[e]=a,l[a].disabled){const t=l.slice(0,a).reverse().findIndex((e=>!e.disabled)),o=l.slice(a+1).findIndex((e=>!e.disabled));-1!==t?n[e]=a-1-t:-1!==o?n[e]=a+1+o:void 0===n[e]&&(n[e]=0)}return n}function d({detail:{value:e}}){const a=function(e){e=e.slice(0,o.value.length);const a=S(r.value);let t=S(r.value);e.forEach(((e,l)=>{(e=H(e,0,o.value[l].length-1))!==a[l]&&(t=u(l,e,t))}));const l=function(e,a){if(!e||!a)return-1;const t=e.findIndex(((e,t)=>e!==a[t]));return t}(t,a);if(-1===l)return;const n=t[l];return 1===t.length?n:l}(e=e.map((e=>Number(e||0))));r.value=S(e),E((()=>{r.value=function(e){let a=S(e);return e.forEach(((e,t)=>{e=H(e,0,o.value[t].length-1),a=u(t,e,a)})),a}(e),l.columnChange?l.columnChange.length<4?(l.columnChange(s.$.exposed,F(),a||0,(()=>{})),m(a||0)):l.columnChange(s.$.exposed,F(),a||0,(()=>{m(a||0)})):m(a||0)}))}function m(e){const a=N();D(a,l.modelValue)||(n("update:modelValue",a),setTimeout((()=>{n("change",{picker:s.$.exposed,value:a,index:e})}),0))}function F(){const e=r.value.map(((e,a)=>o.value[a][e]));return 1===e.length?e[0]:e}function N(){const{valueKey:e}=l,a=r.value.map(((a,t)=>o.value[t][a][e]));return 1===a.length?a[0]:a}function T(){n("pickstart")}function q(){n("pickend")}return a({getSelects:F,getValues:N,setColumnData:function(e,a,t=0){o.value[e]=M(a,l.valueKey,l.labelKey).reduce(((e,a)=>e.concat(a)),[]),r.value=u(e,t,r.value)},getColumnsData:function(){return S(o.value)},getColumnData:function(e){return o.value[e]},getColumnIndex:function(e){return r.value[e]},getLabels:function(){const{labelKey:e}=l;return r.value.map(((a,t)=>o.value[t][a][e]))},getSelectedIndex:function(){return r.value},resetColumns:function(e){i(e)&&e.length&&(o.value=M(e,l.valueKey,l.labelKey))}}),(e,a)=>{const t=k,l=$,n=C;return h(),f(t,{class:j(`wd-picker-view ${e.customClass}`),style:_(e.customStyle)},{default:y((()=>[e.loading?(h(),f(t,{key:0,class:"wd-picker-view__loading"},{default:y((()=>[w(A,{color:e.loadingColor},null,8,["color"])])),_:1})):b("",!0),w(t,{style:_(`height: ${e.columnsHeight-20}px;`)},{default:y((()=>[w(n,{"mask-class":"wd-picker-view__mask","indicator-class":"wd-picker-view__roller","indicator-style":`height: ${e.itemHeight}px;`,style:_(`height: ${e.columnsHeight-20}px;`),value:r.value,"immediate-change":e.immediateChange,onChange:d,onPickstart:T,onPickend:q},{default:y((()=>[(h(!0),x(O,null,K(o.value,((a,n)=>(h(),f(l,{key:n,class:"wd-picker-view-column"},{default:y((()=>[(h(!0),x(O,null,K(a,((a,l)=>(h(),f(t,{key:l,class:j(`wd-picker-view-column__item ${a.disabled?"wd-picker-view-column__item--disabled":""} ${r.value[n]==l?"wd-picker-view-column__item--active":""}`),style:_(`line-height: ${e.itemHeight}px;`)},{default:y((()=>[P(I(a[e.labelKey]),1)])),_:2},1032,["class","style"])))),128))])),_:2},1024)))),128))])),_:1},8,["indicator-style","style","value","immediate-change"])])),_:1},8,["style"])])),_:1},8,["class","style"])}}})),[["__scopeId","data-v-3a09b212"]]);export{M as f,G as w};