2 lines
6.6 KiB
JavaScript
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()
|