acdr-ui/dist/build/mp-weixin/node-modules/wot-design-uni/components/wd-col-picker/wd-col-picker.js

2 lines
6.6 KiB
JavaScript

"use strict";var e=Object.defineProperty,l=Object.defineProperties,a=Object.getOwnPropertyDescriptors,t=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,u=(l,a,t)=>a in l?e(l,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[a]=t;const n=require("../../../../common/vendor.js");if(!Array){(n.resolveComponent("wd-icon")+n.resolveComponent("wd-loading")+n.resolveComponent("wd-action-sheet"))()}Math||((()=>"../wd-icon/wd-icon.js")+(()=>"../wd-loading/wd-loading.js")+(()=>"../wd-action-sheet/wd-action-sheet.js"))();const s=n.defineComponent((i=((e,l)=>{for(var a in l||(l={}))o.call(l,a)&&u(e,a,l[a]);if(t)for(var a of t(l))r.call(l,a)&&u(e,a,l[a]);return e})({},{name:"wd-col-picker",options:{addGlobalClass:!0,virtualHost:!0,styleIsolation:"shared"}}),c={props:n.colPickerProps,emits:["close","update:modelValue","confirm"],setup(e,{expose:l,emit:a}){const{translate:t}=n.useTranslate("col-picker"),o=".wd-col-picker__selected-container",r=".wd-col-picker__selected-item",u=e,s=a,i=n.ref(!1),c=n.ref(0),d=n.ref([]),v=n.ref([]),p=n.ref([]),m=n.ref(!1),f=n.ref(!1),b=n.ref([]),h=n.ref([]),y=n.ref(""),w=n.ref(0),g=n.ref(!1),_=n.ref(!1),{proxy:k}=n.getCurrentInstance(),C=n.useCell(),$=n.debounce((function(e=!0){!function(e=!0){g.value&&n.getRect(r,!0,k).then((l=>{const a=l[c.value],t=16;let o=l.slice(0,c.value).reduce(((e,l)=>e+l.width),0);o+=(Number(a.width)-t)/2;const r=`\n transform: translateX(${o}px);\n ${e?"transition: width 300ms ease, transform 300ms ease;":""}\n `;y.value!==r&&(y.value=r)}))}(e),g.value&&Promise.all([n.getRect(r,!0,k),n.getRect(o,!1,k)]).then((([e,l])=>{if(!n.isArray(e)||0===e.length)return;const a=e[c.value],t=e.slice(0,c.value).reduce(((e,l)=>e+Number(l.width)),0);w.value=t-(l.width-Number(a.width))/2}))}),50),K=n.computed((()=>{const e=(u.modelValue||[]).map(((e,l)=>A(e,l,d.value)));return u.displayFormat?u.displayFormat(e):e.map((e=>e[u.labelKey])).join("")}));n.watch((()=>u.modelValue),(e=>{e!==v.value&&(v.value=e,e.map(((e,l)=>A(e,l,d.value)[u.labelKey])),u.autoComplete&&(d.value.length<u.modelValue.length||0===d.value.length)&&(_.value||q(0===d.value.length?-1:d.value.length-1),_.value=!0))}),{deep:!0,immediate:!0}),n.watch((()=>u.columns),((e,l)=>{if(e.length&&!n.isArray(e[0]))return;if(0===e.length&&!l)return;const a=e.slice(0);d.value=a,p.value=v.value.map(((e,l)=>A(e,l,a)[u.labelKey])),b.value=a,a.length>0&&(c.value=a.length-1)}),{deep:!0,immediate:!0}),n.watch((()=>u.columnChange),(e=>{e&&n.isFunction(e)}),{deep:!0,immediate:!0}),n.watch((()=>u.displayFormat),(e=>{e&&n.isFunction(e)}),{deep:!0,immediate:!0}),n.watch((()=>u.beforeConfirm),(e=>{e&&n.isFunction(e)}),{deep:!0,immediate:!0});const{parent:j}=n.useParent(n.FORM_KEY),O=n.computed((()=>j&&u.prop&&j.errorMessages&&j.errorMessages[u.prop]?j.errorMessages[u.prop]:"")),x=n.computed((()=>{let e=!1;if(j&&j.props.rules){const l=j.props.rules;for(const a in l)Object.prototype.hasOwnProperty.call(l,a)&&a===u.prop&&Array.isArray(l[a])&&(e=l[a].some((e=>e.required)))}return u.required||u.rules.some((e=>e.required))||e}));function P(){$(!1)}function I(){i.value=!1,f.value&&setTimeout((()=>{d.value=b.value.slice(0),v.value=h.value.slice(0),p.value=h.value.map(((e,l)=>A(e,l,b.value)[u.labelKey])),c.value=b.value.length-1,f.value=!1}),250),s("close")}function V(){const{disabled:e,readonly:l}=u;e||l||(i.value=!0,h.value=v.value.slice(0),b.value=d.value.slice(0))}function A(e,l,a){const{valueKey:t,labelKey:o}=u;if(a[l]){const o=a[l].filter((l=>l[t]===e));if(o.length>0)return o[0]}return{[t]:e,[o]:""}}function F(e,l,a,t){m.value=!0;const{columnChange:o,beforeConfirm:r}=u;o&&o({selectedItem:l,index:e,rowIndex:a,resolve:l=>{if(!n.isArray(l))return;const a=d.value.slice(0);a[e+1]=l,d.value=a,m.value=!1,c.value=e+1,$(!0),"function"==typeof t&&(_.value=!1,p.value=v.value.map(((e,l)=>A(e,l,d.value)[u.labelKey])),t())},finish:e=>{if("function"==typeof t)return m.value=!1,void(_.value=!1);!n.isBoolean(e)||e?r?r(v.value,v.value.map(((e,l)=>A(e,l,d.value))),(e=>{e?M():m.value=!1})):M():m.value=!1}})}function M(){f.value=!1,m.value=!1,i.value=!1,s("update:modelValue",v.value),s("confirm",{value:v.value,selectedItems:v.value.map(((e,l)=>A(e,l,d.value)))})}function q(e){const l=-1===e?{}:{[u.valueKey]:u.modelValue[e]};F(e,l,-1,(()=>{d.value.length<u.modelValue.length&&q(e+1)}))}return n.onMounted((()=>{g.value=!0})),l({close:function(){I()},open:function(){V()}}),(e,l)=>n.e({a:e.useDefaultSlot},e.useDefaultSlot?{}:n.e({b:e.label||e.useLabelSlot},e.label||e.useLabelSlot?n.e({c:e.label},e.label?{d:n.t(e.label)}:{},{e:n.n(`wd-col-picker__label ${x.value&&"is-required"} ${e.customLabelClass}`),f:n.s(e.labelWidth?"min-width:"+e.labelWidth+";max-width:"+e.labelWidth+";":"")}):{},{g:n.t(K.value||e.placeholder||n.unref(t)("placeholder")),h:n.n(`wd-col-picker__value ${e.ellipsis&&"is-ellipsis"} ${e.customValueClass} ${K.value?"":"wd-col-picker__value--placeholder"}`),i:!e.disabled&&!e.readonly},e.disabled||e.readonly?{}:{j:n.p({"custom-class":"wd-col-picker__arrow",name:"arrow-right"})},{k:O.value},O.value?{l:n.t(O.value)}:{},{m:n.n(`wd-col-picker__cell ${e.disabled&&"is-disabled"} ${e.readonly&&"is-readonly"} ${e.alignRight&&"is-align-right"} ${e.error&&"is-error"} ${e.size&&"is-"+e.size}`)}),{n:n.o(V),o:n.f(d.value,((e,l,a)=>({a:n.t(p.value[l]||n.unref(t)("select")),b:l,c:n.n(`wd-col-picker__selected-item ${l===c.value&&"is-selected"}`),d:n.o((e=>{return a=l,f.value=!0,c.value=a,void $(!0);var a}),l)}))),p:n.s(y.value),q:w.value,r:n.f(d.value,((l,a,t)=>n.e({a:n.f(l,((l,o,r)=>n.e({a:n.t(l[e.labelKey]),b:l[e.tipKey]},l[e.tipKey]?{c:n.t(l[e.tipKey])}:{},{d:"ae689f9f-2-"+t+"-"+r+",ae689f9f-1",e:o,f:n.n(`wd-col-picker__list-item ${v.value[a]&&l[e.valueKey]===v.value[a]&&"is-selected"} ${l.disabled&&"is-disabled"}`),g:n.o((e=>function(e,l){const a=d.value[e][l];if(a.disabled)return;const t=v.value.slice(0,e);t.push(a[u.valueKey]),f.value=!0,v.value=t,d.value=d.value.slice(0,e+1),p.value=t.map(((e,l)=>A(e,l,d.value)[u.labelKey])),F(e,a,l)}(a,o)),o)})))},m.value?{b:"ae689f9f-3-"+t+",ae689f9f-1",c:n.p({color:e.loadingColor})}:{},{d:a,e:n.s(a===c.value?"display: block;":"display: none;")}))),s:n.p({"custom-class":"wd-col-picker__checked",name:"check"}),t:m.value,v:n.o(P),w:n.o(I),x:n.o((e=>i.value=e)),y:n.p({duration:250,title:e.title||n.unref(t)("title"),"close-on-click-modal":e.closeOnClickModal,"z-index":e.zIndex,"safe-area-inset-bottom":e.safeAreaInsetBottom,modelValue:i.value}),z:n.n(`wd-col-picker ${n.unref(C).border.value?"is-border":""} ${e.customClass}`),A:n.s(e.customStyle)})}},l(i,a(c))));var i,c;const d=n._export_sfc(s,[["__scopeId","data-v-ae689f9f"]]);wx.createComponent(d);