setaria-vxe-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
1 lines • 14.1 kB
JavaScript
"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0,exports.renderOptgroup=renderOptgroup,exports.renderOption=renderOption;var _xeUtils=_interopRequireDefault(require("xe-utils")),_input=_interopRequireDefault(require("../../input/src/input")),_conf=_interopRequireDefault(require("../../v-x-e-table/src/conf")),_size=_interopRequireDefault(require("../../mixins/size")),_utils=_interopRequireWildcard(require("../../tools/utils")),_dom=_interopRequireDefault(require("../../tools/dom")),_event=require("../../tools/event");function _getRequireWildcardCache(t){if("function"!=typeof WeakMap)return null;var e=new WeakMap,i=new WeakMap;return(_getRequireWildcardCache=function(t){return t?i:e})(t)}function _interopRequireWildcard(t,e){if(!e&&t&&t.__esModule)return t;if(null===t||"object"!==_typeof(t)&&"function"!=typeof t)return{default:t};e=_getRequireWildcardCache(e);if(e&&e.has(t))return e.get(t);var i,n,o={},l=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(i in t)"default"!==i&&Object.prototype.hasOwnProperty.call(t,i)&&((n=l?Object.getOwnPropertyDescriptor(t,i):null)&&(n.get||n.set)?Object.defineProperty(o,i,n):o[i]=t[i]);return o.default=t,e&&e.set(t,o),o}function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _defineProperty(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function isOptionVisible(t){return!1!==t.visible}function getOptUniqueId(){return _xeUtils.default.uniqueId("opt_")}function getOptkey(t){return t.optionOpts.keyField||t.optionId||"_X_OPTION_KEY"}function getOptid(t,e){e=e[getOptkey(t)];return e?encodeURIComponent(e):""}function findOffsetOption(t,e,i){var n,o,l,s,r=t.isGroup,u=t.visibleOptionList,a=t.visibleGroupList,p=t.valueField,f=t.groupOptionsField;if(r)for(var c=0;c<a.length;c++){var d=a[c],h=d[f],v=d.disabled;if(h)for(var b=0;b<h.length;b++){var O=h[b],g=isOptionVisible(O),m=v||O.disabled;if(n||m||(n=O),s&&g&&!m&&(l=O,!i))return{offsetOption:l};if(e===O[p]){if(s=O,i)return{offsetOption:o}}else g&&!m&&(o=O)}}else for(var _=0;_<u.length;_++){var x=u[_],y=x.disabled;if(n||y||(n=x),s&&!y&&(l=x,!i))return{offsetOption:l};if(e===x[p]){if(s=x,i)return{offsetOption:o}}else y||(o=x)}return{firstOption:n}}function findOption(t,e){var i=t.isGroup,n=t.fullOptionList,o=t.fullGroupList,l=t.valueField;if(i)for(var s=0;s<o.length;s++){var r=o[s];if(r.options)for(var u=0;u<r.options.length;u++){var a=r.options[u];if(e===a[l])return a}}return n.find(function(t){return e===t[l]})}function getSelectLabel(t,e){var i=findOption(t,e);return _xeUtils.default.toValueString(i?i[t.labelField]:e)}function renderOption(r,u,t,a){var p=u.isGroup,f=u.labelField,c=u.valueField,d=u.optionKey,h=u.value,v=u.multiple,b=u.currentValue,O=u.optionOpts.useKey;return t.map(function(t,e){var i=t.slots,n=!p||isOptionVisible(t),o=a&&a.disabled||t.disabled,l=t[c],s=getOptid(u,t),i=i?i.default:null;return n?r("div",{key:O||d?s:e,class:["vxe-select-option",t.className,{"is--disabled":o,"is--selected":v?h&&-1<h.indexOf(l):h===l,"is--hover":b===l}],attrs:{optid:s},on:{mousedown:u.mousedownOptionEvent,click:function(t){o||u.changeOptionEvent(t,l)},mouseenter:function(){o||u.setCurrentOption(t)}}},i?u.callSlot(i,{option:t,$select:u},r):_utils.default.formatText((0,_utils.getFuncText)(t[f]))):null})}function renderOptgroup(l,s){var r=s.optionKey,t=s.visibleGroupList,u=s.groupLabelField,a=s.groupOptionsField,p=s.optionOpts.useKey;return t.map(function(t,e){var i=t.slots,n=getOptid(s,t),o=t.disabled,i=i?i.default:null;return l("div",{key:p||r?n:e,class:["vxe-optgroup",t.className,{"is--disabled":o}],attrs:{optid:n}},[l("div",{class:"vxe-optgroup--title"},i?s.callSlot(i,{option:t,$select:s},l):(0,_utils.getFuncText)(t[u])),l("div",{class:"vxe-optgroup--wrapper"},renderOption(l,s,t[a],t))])})}function renderOpts(t,e){var i=e.isGroup,n=e.visibleGroupList,o=e.visibleOptionList;if(i){if(n.length)return renderOptgroup(t,e)}else if(o.length)return renderOption(t,e,o);return[t("div",{class:"vxe-select--empty-placeholder"},e.emptyText||_conf.default.i18n("vxe.select.emptyText"))]}var _default2={name:"VxeSelect",mixins:[_size.default],props:{value:null,clearable:Boolean,placeholder:String,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],size:{type:String,default:function(){return _conf.default.select.size||_conf.default.size}},emptyText:String,optionId:{type:String,default:function(){return _conf.default.select.optionId}},optionKey:Boolean,transfer:{type:Boolean,default:function(){return _conf.default.select.transfer}}},components:{VxeInput:_input.default},inject:{$xeform:{default:null},$xeformiteminfo:{default:null}},provide:function(){return{$xeselect:this}},data:function(){return{inited:!1,collectOption:[],fullGroupList:[],fullOptionList:[],visibleGroupList:[],visibleOptionList:[],panelIndex:0,panelStyle:null,panelPlacement:null,currentValue:null,visiblePanel:!1,animatVisible:!1,isActivated:!1}},computed:{propsOpts:function(){return this.optionProps||{}},groupPropsOpts:function(){return this.optionGroupProps||{}},labelField:function(){return this.propsOpts.label||"label"},valueField:function(){return this.propsOpts.value||"value"},groupLabelField:function(){return this.groupPropsOpts.label||"label"},groupOptionsField:function(){return this.groupPropsOpts.options||"options"},optionOpts:function(){return Object.assign({},_conf.default.select.optionConfig,this.optionConfig)},isGroup:function(){return this.fullGroupList.some(function(t){return t.options&&t.options.length})},multiMaxCharNum:function(){return _xeUtils.default.toNumber(this.multiCharOverflow)},selectLabel:function(){var e=this,t=this.value,i=this.multiple,n=this.multiMaxCharNum;return t&&i?(_xeUtils.default.isArray(t)?t:[t]).map(function(t){t=getSelectLabel(e,t);return 0<n&&t.length>n?"".concat(t.substring(0,n),"..."):t}).join(", "):getSelectLabel(this,t)}},watch:{collectOption:function(t){t.some(function(t){return t.options&&t.options.length})?(this.fullOptionList=[],this.fullGroupList=t):(this.fullGroupList=[],this.fullOptionList=t),this.cacheItemMap()},options:function(t){this.fullGroupList=[],this.fullOptionList=t,this.cacheItemMap()},optionGroups:function(t){this.fullOptionList=[],this.fullGroupList=t,this.cacheItemMap()}},created:function(){var t=this.options,e=this.optionGroups;e?this.fullGroupList=e:t&&(this.fullOptionList=t),this.cacheItemMap(),_event.GlobalEvent.on(this,"mousewheel",this.handleGlobalMousewheelEvent),_event.GlobalEvent.on(this,"mousedown",this.handleGlobalMousedownEvent),_event.GlobalEvent.on(this,"keydown",this.handleGlobalKeydownEvent),_event.GlobalEvent.on(this,"blur",this.handleGlobalBlurEvent)},beforeDestroy:function(){var t=this.$refs.panel;t&&t.parentNode&&t.parentNode.removeChild(t)},destroyed:function(){_event.GlobalEvent.off(this,"mousewheel"),_event.GlobalEvent.off(this,"mousedown"),_event.GlobalEvent.off(this,"keydown"),_event.GlobalEvent.off(this,"blur")},render:function(t){var e=this.$scopedSlots,i=this.vSize,n=this.className,o=this.inited,l=this.isActivated,s=this.loading,r=this.disabled,u=this.visiblePanel,a=e.prefix;return t("div",{class:["vxe-select",n?_xeUtils.default.isFunction(n)?n({$select:this}):n:"",(_defineProperty(e={},"size--".concat(i),i),_defineProperty(e,"is--visivle",u),_defineProperty(e,"is--disabled",r),_defineProperty(e,"is--loading",s),_defineProperty(e,"is--active",l),e)]},[t("div",{class:"vxe-select-slots",ref:"hideOption"},this.$slots.default),t("vxe-input",{ref:"input",props:{clearable:this.clearable,placeholder:this.placeholder,readonly:!0,disabled:r,type:"text",prefixIcon:this.prefixIcon,suffixIcon:s?_conf.default.icon.SELECT_LOADED:u?_conf.default.icon.SELECT_OPEN:_conf.default.icon.SELECT_CLOSE,value:this.selectLabel},on:{clear:this.clearEvent,click:this.togglePanelEvent,focus:this.focusEvent,blur:this.blurEvent,"suffix-click":this.togglePanelEvent},scopedSlots:a?{prefix:function(){return a({})}}:{}}),t("div",{ref:"panel",class:["vxe-table--ignore-clear vxe-select--panel",(_defineProperty(n={},"size--".concat(i),i),_defineProperty(n,"is--transfer",this.transfer),_defineProperty(n,"animat--leave",!s&&this.animatVisible),_defineProperty(n,"animat--enter",!s&&u),n)],attrs:{placement:this.panelPlacement},style:this.panelStyle},o?[t("div",{ref:"optWrapper",class:"vxe-select-option--wrapper"},renderOpts(t,this))]:null)])},methods:{callSlot:function(t,e,i){if(t){var n=this.$scopedSlots;if(_xeUtils.default.isString(t)&&(t=n[t]||null),_xeUtils.default.isFunction(t))return t.call(this,e,i)}return[]},cacheItemMap:function(){function e(t){getOptid(i,t)||(t[l]=getOptUniqueId())}var i=this,t=this.fullOptionList,n=this.fullGroupList,o=this.groupOptionsField,l=getOptkey(this);n.length?n.forEach(function(t){e(t),t[o]&&t[o].forEach(e)}):t.length&&t.forEach(e),this.refreshOption()},refreshOption:function(){var t=this.isGroup,e=this.fullOptionList,i=this.fullGroupList;return t?this.visibleGroupList=i.filter(isOptionVisible):this.visibleOptionList=e.filter(isOptionVisible),this.$nextTick()},setCurrentOption:function(t){t&&(this.currentValue=t[this.valueField])},scrollToOption:function(n,o){var l=this;return this.$nextTick().then(function(){var t,e,i;n&&(t=(e=l.$refs).optWrapper,e=e.panel.querySelector("[optid='".concat(getOptid(l,n),"']")),t&&e&&(i=t.offsetHeight,o?e.offsetTop+e.offsetHeight-t.scrollTop>i&&(t.scrollTop=e.offsetTop+e.offsetHeight-i):(e.offsetTop+5<t.scrollTop||e.offsetTop+5>t.scrollTop+t.clientHeight)&&(t.scrollTop=e.offsetTop-5)))})},clearEvent:function(t,e){this.clearValueEvent(e,null),this.hideOptionPanel()},clearValueEvent:function(t,e){this.changeEvent(t,e),this.$emit("clear",{value:e,$event:t})},changeEvent:function(t,e){e!==this.value&&(this.$emit("input",e),this.$emit("change",{value:e,$event:t}),this.$xeform&&this.$xeformiteminfo&&this.$xeform.triggerItemEvent(t,this.$xeformiteminfo.itemConfig.field,e))},mousedownOptionEvent:function(t){0===t.button&&t.stopPropagation()},changeOptionEvent:function(t,e){var i=this.value;this.multiple?(i=i?-1===i.indexOf(e)?i.concat([e]):i.filter(function(t){return t!==e}):[e],this.changeEvent(t,i)):(this.changeEvent(t,e),this.hideOptionPanel())},handleGlobalMousewheelEvent:function(t){var e=this.$refs,i=this.disabled,n=this.visiblePanel;i||n&&(_dom.default.getEventTargetNode(t,e.panel).flag?this.updatePlacement():this.hideOptionPanel())},handleGlobalMousedownEvent:function(t){var e=this.$refs,i=this.$el,n=this.disabled,o=this.visiblePanel;n||(this.isActivated=_dom.default.getEventTargetNode(t,i).flag||_dom.default.getEventTargetNode(t,e.panel).flag,o&&!this.isActivated&&this.hideOptionPanel())},handleGlobalKeydownEvent:function(t){var e,i,n,o,l,s,r,u=this.visiblePanel,a=this.currentValue,p=this.clearable;this.disabled||(e=13===(r=t.keyCode),s=27===r,i=38===r,n=40===r,o=46===r,l=32===r,(r=9===r)&&(this.isActivated=!1),u?s||r?this.hideOptionPanel():e?(t.preventDefault(),t.stopPropagation(),this.changeOptionEvent(t,a)):i||n?(t.preventDefault(),s=(u=findOffsetOption(this,a,i)).firstOption,(r=u.offsetOption)||findOption(this,a)||(r=s),this.setCurrentOption(r),this.scrollToOption(r,n)):l&&t.preventDefault():(i||n||e||l)&&this.isActivated&&(t.preventDefault(),this.showOptionPanel()),this.isActivated&&o&&p&&this.clearValueEvent(t,null))},handleGlobalBlurEvent:function(){this.hideOptionPanel()},updateZindex:function(){this.panelIndex<_utils.default.getLastZIndex()&&(this.panelIndex=_utils.default.nextZIndex())},focusEvent:function(){this.disabled||(this.isActivated=!0)},blurEvent:function(){this.isActivated=!1},isPanelVisible:function(){return this.visiblePanel},togglePanel:function(){this.visiblePanel?this.hideOptionPanel():this.showOptionPanel(),this.$nextTick()},hidePanel:function(){this.visiblePanel&&this.hideOptionPanel(),this.$nextTick()},showPanel:function(){this.visiblePanel||this.showOptionPanel(),this.$nextTick()},togglePanelEvent:function(t){t.$event.preventDefault(),this.visiblePanel?this.hideOptionPanel():this.showOptionPanel()},showOptionPanel:function(){var i=this,t=this.loading,e=this.disabled;t||e||(clearTimeout(this.hidePanelTimeout),this.inited||(this.inited=!0,this.transfer&&document.body.appendChild(this.$refs.panel)),this.isActivated=!0,this.animatVisible=!0,setTimeout(function(){var t=i.value,e=i.multiple,e=findOption(i,e&&t?t[0]:t);i.visiblePanel=!0,e&&(i.setCurrentOption(e),i.scrollToOption(e))},10),this.updateZindex(),this.updatePlacement())},hideOptionPanel:function(){var t=this;this.visiblePanel=!1,this.hidePanelTimeout=setTimeout(function(){t.animatVisible=!1},350)},updatePlacement:function(){var c=this;return this.$nextTick().then(function(){var t,e,i,n,o,l,s,r=c.$refs,u=c.transfer,a=c.placement,p=c.panelIndex,f=r.input.$el,r=r.panel;if(r&&f)return t=f.offsetHeight,e=f.offsetWidth,i=r.offsetHeight,r=r.offsetWidth,p={zIndex:p},n=(f=_dom.default.getAbsolutePos(f)).boundingTop,s=f.boundingLeft,o=f.visibleHeight,f=f.visibleWidth,l="bottom",u?(u=n+t,"top"===a?(l="top",u=n-i):a||(o<u+i+5&&(l="top",u=n-i),u<5&&(l="bottom",u=n+t)),f<(s=s)+r+5&&(s-=s+r+5-f),s<5&&(s=5),Object.assign(p,{left:"".concat(s,"px"),top:"".concat(u,"px"),minWidth:"".concat(e,"px")})):"top"===a?(l="top",p.bottom="".concat(t,"px")):a||o<n+t+i&&5<n-t-i&&(l="top",p.bottom="".concat(t,"px")),c.panelStyle=p,c.panelPlacement=l,c.$nextTick()})},focus:function(){return this.isActivated=!0,this.$refs.input.focus(),this.$nextTick()},blur:function(){return this.hideOptionPanel(),this.$refs.input.blur(),this.$nextTick()}}};exports.default=_default2;