yw-common-list
Version:
基于vxe-table封装的自定义可配置表格
1 lines • 4.73 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _conf=_interopRequireDefault(require("../../v-x-e-table/src/conf")),_size=_interopRequireDefault(require("../../mixins/size")),_utils=_interopRequireDefault(require("../../tools/utils")),_dom=_interopRequireDefault(require("../../tools/dom")),_event=require("../../tools/event");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var _default2={name:"VxePulldown",mixins:[_size.default],props:{value:Boolean,disabled:Boolean,placement:String,size:{type:String,default:function(){return _conf.default.size}},destroyOnClose:Boolean,transfer:Boolean},data:function(){return{inited:!1,panelIndex:0,panelStyle:null,panelPlacement:null,currentValue:null,visiblePanel:!1,animatVisible:!1,isActivated:!1}},watch:{value:function(e){e?this.showPanel():this.hidePanel()}},created:function(){_event.GlobalEvent.on(this,"mousewheel",this.handleGlobalMousewheelEvent),_event.GlobalEvent.on(this,"mousedown",this.handleGlobalMousedownEvent),_event.GlobalEvent.on(this,"blur",this.handleGlobalBlurEvent)},beforeDestroy:function(){var e=this.$refs.panel;e&&e.parentNode&&e.parentNode.removeChild(e)},destroyed:function(){_event.GlobalEvent.off(this,"mousewheel"),_event.GlobalEvent.off(this,"mousedown"),_event.GlobalEvent.off(this,"blur")},render:function(e){var t,i=this.$scopedSlots,n=this.inited,l=this.vSize,a=this.destroyOnClose,s=this.transfer,o=this.isActivated,d=this.disabled,r=this.animatVisible,u=this.visiblePanel,h=this.panelStyle,f=this.panelPlacement,c=i.default,i=i.dropdown;return e("div",{class:["vxe-pulldown",(_defineProperty(t={},"size--".concat(l),l),_defineProperty(t,"is--visivle",u),_defineProperty(t,"is--disabled",d),_defineProperty(t,"is--active",o),t)]},[e("div",{ref:"content",class:"vxe-pulldown--content"},c?c.call(this,{$pulldown:this},e):[]),e("div",{ref:"panel",class:["vxe-table--ignore-clear vxe-pulldown--panel",(_defineProperty(d={},"size--".concat(l),l),_defineProperty(d,"is--transfer",s),_defineProperty(d,"animat--leave",r),_defineProperty(d,"animat--enter",u),d)],attrs:{placement:f},style:h},i?[e("div",{class:"vxe-pulldown--wrapper"},!n||a&&!u&&!r?[]:i.call(this,{$pulldown:this},e))]:[])])},methods:{handleGlobalMousewheelEvent:function(e){var t=this.$refs,i=this.disabled,n=this.visiblePanel;i||n&&(_dom.default.getEventTargetNode(e,t.panel).flag?this.updatePlacement():(this.hidePanel(),this.$emit("hide-panel",{$event:e})))},handleGlobalMousedownEvent:function(e){var t=this.$refs,i=this.$el,n=this.disabled,l=this.visiblePanel;n||(this.isActivated=_dom.default.getEventTargetNode(e,i).flag||_dom.default.getEventTargetNode(e,t.panel).flag,l&&!this.isActivated&&(this.hidePanel(),this.$emit("hide-panel",{$event:e})))},handleGlobalBlurEvent:function(e){this.visiblePanel&&(this.isActivated=!1,this.hidePanel(),this.$emit("hide-panel",{$event:e}))},updateZindex:function(){this.panelIndex<_utils.default.getLastZIndex()&&(this.panelIndex=_utils.default.nextZIndex())},isPanelVisible:function(){return this.visiblePanel},togglePanel:function(){return this.visiblePanel?this.hidePanel():this.showPanel()},showPanel:function(){var t=this;return this.inited||(this.inited=!0,this.transfer&&document.body.appendChild(this.$refs.panel)),new Promise(function(e){t.disabled?e(t.$nextTick()):(clearTimeout(t.hidePanelTimeout),t.isActivated=!0,t.animatVisible=!0,setTimeout(function(){t.visiblePanel=!0,t.$emit("update:input",!0),t.updatePlacement(),setTimeout(function(){e(t.updatePlacement())},40)},10),t.updateZindex())})},hidePanel:function(){var t=this;return this.visiblePanel=!1,this.$emit("update:input",!1),new Promise(function(e){t.animatVisible?t.hidePanelTimeout=setTimeout(function(){t.animatVisible=!1,e(t.$nextTick())},350):e(t.$nextTick())})},updatePlacement:function(){var f=this;return this.$nextTick().then(function(){var e,t,i,n,l,a,s,o,d=f.$refs,r=f.transfer,u=f.placement,h=f.panelIndex;return f.visiblePanel&&(n=d.panel,d=d.content,n&&d&&(e=d.offsetHeight,t=d.offsetWidth,i=n.offsetHeight,n=n.offsetWidth,h={zIndex:h},l=(d=_dom.default.getAbsolutePos(d)).boundingTop,o=d.boundingLeft,a=d.visibleHeight,d=d.visibleWidth,s="bottom",r?(r=l+e,"top"===u?(s="top",r=l-i):u||(a<r+i+5&&(s="top",r=l-i),r<5&&(s="bottom",r=l+e)),d<(o=o)+n+5&&(o-=o+n+5-d),o<5&&(o=5),Object.assign(h,{left:"".concat(o,"px"),top:"".concat(r,"px"),minWidth:"".concat(t,"px")})):"top"===u?(s="top",h.bottom="".concat(e,"px")):u||a<l+e+i&&5<l-e-i&&(s="top",h.bottom="".concat(e,"px")),f.panelStyle=h,f.panelPlacement=s)),f.$nextTick()})}}};exports.default=_default2;