UNPKG

vxe-table

Version:

一个基于 vue 的 PC 端表单/表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式...

1 lines 14.6 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _vue=require("vue"),_xeUtils=_interopRequireDefault(require("xe-utils")),_conf=_interopRequireDefault(require("../../v-x-e-table/src/conf")),_size=require("../../hooks/size"),_dom=require("../../tools/dom"),_utils=require("../../tools/utils"),_event=require("../../tools/event"),_input=_interopRequireDefault(require("../../input/src/input")),_vn=require("../../tools/vn");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function isOptionVisible(e){return!1!==e.visible}function getOptUniqueId(){return _xeUtils.default.uniqueId("opt_")}var _default=(0,_vue.defineComponent)({name:"VxeSelect",props:{modelValue:null,clearable:Boolean,placeholder:{type:String,default:function(){return _xeUtils.default.eqNull(_conf.default.select.placeholder)?_conf.default.i18n("vxe.base.pleaseSelect"):_conf.default.select.placeholder}},loading:Boolean,disabled:Boolean,multiple:Boolean,multiCharOverflow:{type:[Number,String],default:function(){return _conf.default.select.multiCharOverflow}},prefixIcon:String,placement:String,options:Array,optionProps:Object,optionGroups:Array,optionGroupProps:Object,optionConfig:Object,className:[String,Function],popupClassName:[String,Function],max:{type:[String,Number],default:null},size:{type:String,default:function(){return _conf.default.select.size||_conf.default.size}},filterable:Boolean,filterMethod:Function,remote:Boolean,remoteMethod:Function,emptyText:String,optionId:{type:String,default:function(){return _conf.default.select.optionId}},optionKey:Boolean,transfer:{type:Boolean,default:function(){return _conf.default.select.transfer}}},emits:["update:modelValue","change","clear","blur","focus"],setup:function(x,e){function g(e,t){return e&&(_xeUtils.default.isString(e)&&(e=_[e]||null),_xeUtils.default.isFunction(e))?(0,_vn.getSlotVNs)(e(t)):[]}function v(t){var e=V.fullOptionList,n=V.fullGroupList,i=k.value,l=P.value;if(i)for(var o=0;o<n.length;o++){var u=n[o];if(u.options)for(var a=0;a<u.options.length;a++){var r=u.options[a];if(t===r[l])return r}}return e.find(function(e){return t===e[l]})}function l(t){var e=V.remoteValueList,n=S.value,e=(e=e.find(function(e){return t===e.key}))?e.result:null;return _xeUtils.default.toValueString(e?e[n]:t)}function o(e){var t=S.value,n=v(e);return _xeUtils.default.toValueString(n?n[t]:e)}function u(){var e=x.filterable,t=x.filterMethod,n=V.fullOptionList,i=V.fullGroupList,l=V.searchValue,o=k.value,u=Z.value,a=S.value;return o?V.visibleGroupList=e&&t?i.filter(function(e){return isOptionVisible(e)&&t({group:e,option:null,searchValue:l})}):e?i.filter(function(e){return isOptionVisible(e)&&(!l||-1<"".concat(e[u]).indexOf(l))}):i.filter(isOptionVisible):V.visibleOptionList=e&&t?n.filter(function(e){return isOptionVisible(e)&&t({group:null,option:e,searchValue:l})}):e?n.filter(function(e){return isOptionVisible(e)&&(!l||-1<"".concat(e[a]).indexOf(l))}):n.filter(isOptionVisible),(0,_vue.nextTick)()}function n(){function t(e){A(e)||(e[l]=getOptUniqueId())}var e=V.fullOptionList,n=V.fullGroupList,i=N.value,l=ee();n.length?n.forEach(function(e){t(e),e[i]&&e[i].forEach(t)}):e.length&&e.forEach(t),u()}function E(e){var t=P.value;e&&(V.currentOption=e,V.currentValue=e[t])}function p(i,l){(0,_vue.nextTick)().then(function(){var e,t,n;i&&(e=T.value,t=L.value.querySelector("[optid='".concat(A(i),"']")),e)&&t&&(n=e.offsetHeight,l?t.offsetTop+t.offsetHeight-e.scrollTop>n&&(e.scrollTop=t.offsetTop+t.offsetHeight-n):(t.offsetTop+5<e.scrollTop||t.offsetTop+5>e.scrollTop+e.clientHeight)&&(e.scrollTop=t.offsetTop-5))})}function i(){(0,_vue.nextTick)().then(function(){var e,t,n,i,l,o,u,a=x.transfer,r=x.placement,s=V.panelIndex,c=b.value,f=L.value;if(f&&c)return e=c.offsetHeight,t=c.offsetWidth,n=f.offsetHeight,f=f.offsetWidth,s={zIndex:s},i=(c=(0,_dom.getAbsolutePos)(c)).boundingTop,u=c.boundingLeft,l=c.visibleHeight,c=c.visibleWidth,o="bottom",a?(a=i+e,"top"===r?(o="top",a=i-n):r||(l<a+n+5&&(o="top",a=i-n),a<5&&(o="bottom",a=i+e)),c<(u=u)+f+5&&(u-=u+f+5-c),u<5&&(u=5),Object.assign(s,{left:"".concat(u,"px"),top:"".concat(a,"px"),minWidth:"".concat(t,"px")})):"top"===r?(o="top",s.bottom="".concat(e,"px")):r||l<i+e+n&&5<i-e-n&&(o="top",s.bottom="".concat(e,"px")),V.panelStyle=s,V.panelPlacement=o,(0,_vue.nextTick)()})}function U(e,t){te(t,null),I()}function O(e,t,n){var i=x.modelValue,l=x.multiple,o=V.remoteValueList;l?(l=void 0,l=i?-1===i.indexOf(t)?i.concat([t]):i.filter(function(e){return e!==t}):[t],(i=o.find(function(e){return e.key===t}))?i.result=n:o.push({key:t,result:n}),K(e,l)):(V.remoteValueList=[{key:t,result:n}],K(e,t),I())}function w(e){var t=x.disabled,n=V.visiblePanel;t||n&&(t=L.value,((0,_dom.getEventTargetNode)(e,t).flag?i:I)())}function q(e){var t,n=x.disabled,i=V.visiblePanel;n||(n=b.value,t=L.value,V.isActivated=(0,_dom.getEventTargetNode)(e,n).flag||(0,_dom.getEventTargetNode)(e,t).flag,i&&!V.isActivated&&I())}function D(e){var t,n,i,l,o,u,a=x.clearable,r=x.disabled,s=V.visiblePanel,c=V.currentValue,f=V.currentOption;r||(r=(0,_event.hasEventKey)(e,_event.EVENT_KEYS.TAB),t=(0,_event.hasEventKey)(e,_event.EVENT_KEYS.ENTER),u=(0,_event.hasEventKey)(e,_event.EVENT_KEYS.ESCAPE),n=(0,_event.hasEventKey)(e,_event.EVENT_KEYS.ARROW_UP),i=(0,_event.hasEventKey)(e,_event.EVENT_KEYS.ARROW_DOWN),l=(0,_event.hasEventKey)(e,_event.EVENT_KEYS.DELETE),o=(0,_event.hasEventKey)(e,_event.EVENT_KEYS.SPACEBAR),r&&(V.isActivated=!1),s?u||r?I():t?(e.preventDefault(),e.stopPropagation(),O(e,c,f)):n||i?(e.preventDefault(),u=(s=function(e,t){var n,i,l,o,u=V.visibleOptionList,a=V.visibleGroupList,r=k.value,s=P.value,c=N.value;if(r)for(var f=0;f<a.length;f++){var v=a[f],p=v[c],d=v.disabled;if(p)for(var _=0;_<p.length;_++){var b=isOptionVisible(h=p[_]),m=d||h.disabled;if(n||m||(n=h),o&&b&&!m&&(l=h,!t))return{offsetOption:l};if(e===h[s]){if(o=h,t)return{offsetOption:i}}else b&&!m&&(i=h)}}else for(_=0;_<u.length;_++){var h,m=(h=u[_]).disabled;if(n||m||(n=h),o&&!m&&(l=h,!t))return{offsetOption:l};if(e===h[s]){if(o=h,t)return{offsetOption:i}}else m||(i=h)}return{firstOption:n}}(c,n)).firstOption,(r=s.offsetOption)||v(c)||(r=u),E(r),p(r,i)):o&&e.preventDefault():(n||i||t||o)&&V.isActivated&&(e.preventDefault(),C()),V.isActivated&&l&&a&&te(e,null))}function F(){I()}function R(e){x.disabled||(V.isActivated=!0),f.dispatchEvent("focus",{},e)}function $(e){V.isActivated=!1,f.dispatchEvent("blur",{},e)}function j(e){V.searchValue=e}function B(){V.isActivated=!0}function z(e){e=e.$event,(0,_event.hasEventKey)(e,_event.EVENT_KEYS.ENTER)&&(e.preventDefault(),e.stopPropagation())}function d(e){e.$event.preventDefault(),(V.visiblePanel?I:C)()}var a,_=e.slots,r=e.emit,s=(0,_vue.inject)("$xeform",null),c=(0,_vue.inject)("$xeformiteminfo",null),M=_xeUtils.default.uniqueId(),Y=(0,_size.useSize)(x),V=(0,_vue.reactive)({inited:!1,staticOptions:[],fullGroupList:[],fullOptionList:[],visibleGroupList:[],visibleOptionList:[],remoteValueList:[],panelIndex:0,panelStyle:{},panelPlacement:null,currentOption:null,currentValue:null,visiblePanel:!1,animatVisible:!1,isActivated:!1,searchValue:"",searchLoading:!1}),b=(0,_vue.ref)(),m=(0,_vue.ref)(),h=(0,_vue.ref)(),T=(0,_vue.ref)(),L=(0,_vue.ref)(),H={refElem:b},y={xID:M,props:x,context:e,reactData:V,getRefMaps:function(){return H}},f={},t=(0,_vue.computed)(function(){return x.optionProps||{}}),W=(0,_vue.computed)(function(){return x.optionGroupProps||{}}),S=(0,_vue.computed)(function(){return t.value.label||"label"}),P=(0,_vue.computed)(function(){return t.value.value||"value"}),Z=(0,_vue.computed)(function(){return W.value.label||"label"}),N=(0,_vue.computed)(function(){return W.value.options||"options"}),X=(0,_vue.computed)(function(){var e=x.modelValue,t=x.multiple,n=x.max;return!(!t||!n)&&(e?e.length:0)>=_xeUtils.default.toNumber(n)}),G=(0,_vue.computed)(function(){return Object.assign({},_conf.default.select.optionConfig,x.optionConfig)}),k=(0,_vue.computed)(function(){return V.fullGroupList.some(function(e){return e.options&&e.options.length})}),J=(0,_vue.computed)(function(){return _xeUtils.default.toNumber(x.multiCharOverflow)}),Q=(0,_vue.computed)(function(){var e=x.modelValue,t=x.multiple,n=x.remote,i=J.value;return e&&t?(t=_xeUtils.default.isArray(e)?e:[e],(n?t.map(l):t.map(function(e){e=o(e);return 0<i&&e.length>i?"".concat(e.substring(0,i),"..."):e})).join(", ")):(n?l:o)(e)}),ee=function(){return G.value.keyField||x.optionId||"_X_OPTION_KEY"},A=function(e){e=e[ee()];return e?encodeURIComponent(e):""},C=function(){var e=x.loading,t=x.disabled,n=x.filterable;e||t||(clearTimeout(a),V.inited||(V.inited=!0),V.isActivated=!0,V.animatVisible=!0,n&&u(),setTimeout(function(){var e=x.modelValue,t=x.multiple,t=v(t&&e?e[0]:e);V.visiblePanel=!0,t&&(E(t),p(t)),x.filterable&&(0,_vue.nextTick)(function(){var e=h.value;e&&e.focus()})},10),V.panelIndex<(0,_utils.getLastZIndex)()&&(V.panelIndex=(0,_utils.nextZIndex)()),i())},I=function(){V.searchValue="",V.searchLoading=!1,V.visiblePanel=!1,a=window.setTimeout(function(){V.animatVisible=!1},350)},K=function(e,t){t!==x.modelValue&&(r("update:modelValue",t),f.dispatchEvent("change",{value:t},e),s)&&c&&s.triggerItemEvent(e,c.itemConfig.field,t)},te=function(e,t){V.remoteValueList=[],K(e,t),f.dispatchEvent("clear",{value:t},e)},ne=_xeUtils.default.debounce(function(){var e=x.remote,t=x.remoteMethod,n=V.searchValue;e&&t?(V.searchLoading=!0,Promise.resolve(t({searchValue:n})).then(function(){return(0,_vue.nextTick)()}).catch(function(){return(0,_vue.nextTick)()}).finally(function(){V.searchLoading=!1,u()})):u()},350,{trailing:!0}),ie=function(e,c){var f=x.optionKey,v=x.modelValue,p=x.multiple,d=V.currentValue,t=G.value,_=S.value,b=P.value,m=k.value,h=t.useKey;return e.map(function(t,e){var n=t.slots,i=t.className,l=t[b],o=p?v&&-1<v.indexOf(l):v===l,u=!m||isOptionVisible(t),a=(s=o,r=c,!!t.disabled||!(!r||!r.disabled)||!(!X.value||s)),r=A(t),s=n?n.default:null;return u?(0,_vue.h)("div",{key:h||f?r:e,class:["vxe-select-option",i?_xeUtils.default.isFunction(i)?i({option:t,$select:y}):i:"",{"is--disabled":a,"is--selected":o,"is--hover":d===l}],optid:r,onMousedown:function(e){0===e.button&&e.stopPropagation()},onClick:function(e){a||O(e,l,t)},onMouseenter:function(){a||E(t)}},s?g(s,{option:t,$select:y}):(0,_utils.formatText)((0,_utils.getFuncText)(t[_]))):null})},le=function(){var u=x.optionKey,e=V.visibleGroupList,t=G.value,a=Z.value,r=N.value,s=t.useKey;return e.map(function(e,t){var n=e.slots,i=e.className,l=A(e),o=e.disabled,n=n?n.default:null;return(0,_vue.h)("div",{key:s||u?l:t,class:["vxe-optgroup",i?_xeUtils.default.isFunction(i)?i({option:e,$select:y}):i:"",{"is--disabled":o}],optid:l},[(0,_vue.h)("div",{class:"vxe-optgroup--title"},n?g(n,{option:e,$select:y}):(0,_utils.getFuncText)(e[a])),(0,_vue.h)("div",{class:"vxe-optgroup--wrapper"},ie(e[r]||[],e))])})},f={dispatchEvent:function(e,t,n){r(e,Object.assign({$select:y,$event:n},t))},isPanelVisible:function(){return V.visiblePanel},togglePanel:function(){return(V.visiblePanel?I:C)(),(0,_vue.nextTick)()},hidePanel:function(){return V.visiblePanel&&I(),(0,_vue.nextTick)()},showPanel:function(){return V.visiblePanel||C(),(0,_vue.nextTick)()},refreshOption:u,focus:function(){var e=m.value;return V.isActivated=!0,e.blur(),(0,_vue.nextTick)()},blur:function(){return m.value.blur(),(V.isActivated=!1,_vue.nextTick)()}};Object.assign(y,f),(0,_vue.watch)(function(){return V.staticOptions},function(e){e.some(function(e){return e.options&&e.options.length})?(V.fullOptionList=[],V.fullGroupList=e):(V.fullGroupList=[],V.fullOptionList=e||[]),n()}),(0,_vue.watch)(function(){return x.options},function(e){V.fullGroupList=[],V.fullOptionList=e||[],n()}),(0,_vue.watch)(function(){return x.optionGroups},function(e){V.fullOptionList=[],V.fullGroupList=e||[],n()}),(0,_vue.onMounted)(function(){(0,_vue.nextTick)(function(){var e=x.options,t=x.optionGroups;t?V.fullGroupList=t:e&&(V.fullOptionList=e),n()}),_event.GlobalEvent.on(y,"mousewheel",w),_event.GlobalEvent.on(y,"mousedown",q),_event.GlobalEvent.on(y,"keydown",D),_event.GlobalEvent.on(y,"blur",F)}),(0,_vue.onUnmounted)(function(){_event.GlobalEvent.off(y,"mousewheel"),_event.GlobalEvent.off(y,"mousedown"),_event.GlobalEvent.off(y,"keydown"),_event.GlobalEvent.off(y,"blur")});return y.renderVN=function(){var e=x.className,t=x.popupClassName,n=x.transfer,i=x.disabled,l=x.loading,o=x.filterable,u=V.inited,a=V.isActivated,r=V.visiblePanel,s=Y.value,c=Q.value,f=_.prefix;return(0,_vue.h)("div",{ref:b,class:["vxe-select",e?_xeUtils.default.isFunction(e)?e({$select:y}):e:"",((e={})["size--".concat(s)]=s,e["is--visivle"]=r,e["is--disabled"]=i,e["is--filter"]=o,e["is--loading"]=l,e["is--active"]=a,e)]},[(0,_vue.h)("div",{class:"vxe-select-slots",ref:"hideOption"},_.default?_.default({}):[]),(0,_vue.h)(_input.default,{ref:m,clearable:x.clearable,placeholder:x.placeholder,readonly:!0,disabled:i,type:"text",prefixIcon:x.prefixIcon,suffixIcon:l?_conf.default.icon.SELECT_LOADED:r?_conf.default.icon.SELECT_OPEN:_conf.default.icon.SELECT_CLOSE,modelValue:c,onClear:U,onClick:d,onFocus:R,onBlur:$,onSuffixClick:d},f?{prefix:function(){return f({})}}:{}),(0,_vue.h)(_vue.Teleport,{to:"body",disabled:!n||!u},[(0,_vue.h)("div",{ref:L,class:["vxe-table--ignore-clear vxe-select--panel",t?_xeUtils.default.isFunction(t)?t({$select:y}):t:"",((a={})["size--".concat(s)]=s,a["is--transfer"]=n,a["animat--leave"]=!l&&V.animatVisible,a["animat--enter"]=!l&&r,a)],placement:V.panelPlacement,style:V.panelStyle},u?[o?(0,_vue.h)("div",{class:"vxe-select-filter--wrapper"},[(0,_vue.h)(_input.default,{ref:h,class:"vxe-select-filter--input",modelValue:V.searchValue,clearable:!0,placeholder:_conf.default.i18n("vxe.select.search"),prefixIcon:_conf.default.icon.INPUT_SEARCH,"onUpdate:modelValue":j,onFocus:B,onKeydown:z,onChange:ne,onSearch:ne})]):(0,_vue.createCommentVNode)(),(0,_vue.h)("div",{ref:T,class:"vxe-select-option--wrapper"},function(){var e=V.visibleGroupList,t=V.visibleOptionList,n=V.searchLoading,i=k.value;if(n)return[(0,_vue.h)("div",{class:"vxe-select--search-loading"},[(0,_vue.h)("i",{class:["vxe-select--search-icon",_conf.default.icon.SELECT_LOADED]}),(0,_vue.h)("span",{class:"vxe-select--search-text"},_conf.default.i18n("vxe.select.loadingText"))])];if(i){if(e.length)return le()}else if(t.length)return ie(t);return[(0,_vue.h)("div",{class:"vxe-select--empty-placeholder"},x.emptyText||_conf.default.i18n("vxe.select.emptyText"))]}())]:[])])])},(0,_vue.provide)("$xeselect",y),y},render:function(){return this.renderVN()}});exports.default=_default;