1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _xeUtils = _interopRequireDefault(require("xe-utils"));
|
9 |
|
10 | var _conf = _interopRequireDefault(require("../../v-x-e-table/src/conf"));
|
11 |
|
12 | var _size = _interopRequireDefault(require("../../mixins/size"));
|
13 |
|
14 | var _tools = require("../../tools");
|
15 |
|
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17 |
|
18 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
19 |
|
20 | var _default2 = {
|
21 | name: 'VxeButton',
|
22 | mixins: [_size.default],
|
23 | props: {
|
24 | type: String,
|
25 | size: {
|
26 | type: String,
|
27 | default: function _default() {
|
28 | return _conf.default.button.size || _conf.default.size;
|
29 | }
|
30 | },
|
31 | name: [String, Number],
|
32 | content: String,
|
33 | placement: String,
|
34 | status: String,
|
35 | icon: String,
|
36 | round: Boolean,
|
37 | circle: Boolean,
|
38 | disabled: Boolean,
|
39 | loading: Boolean,
|
40 | destroyOnClose: Boolean,
|
41 | className: String,
|
42 | transfer: {
|
43 | type: Boolean,
|
44 | default: function _default() {
|
45 | return _conf.default.button.transfer;
|
46 | }
|
47 | }
|
48 | },
|
49 | data: function data() {
|
50 | return {
|
51 | inited: false,
|
52 | showPanel: false,
|
53 | animatVisible: false,
|
54 | panelIndex: 0,
|
55 | panelStyle: null,
|
56 | panelPlacement: null
|
57 | };
|
58 | },
|
59 | computed: {
|
60 | isText: function isText() {
|
61 | return this.type === 'text';
|
62 | },
|
63 | isFormBtn: function isFormBtn() {
|
64 | return ['submit', 'reset', 'button'].indexOf(this.type) > -1;
|
65 | },
|
66 | btnType: function btnType() {
|
67 | return this.isText ? this.type : 'button';
|
68 | }
|
69 | },
|
70 | created: function created() {
|
71 | _tools.GlobalEvent.on(this, 'mousewheel', this.handleGlobalMousewheelEvent);
|
72 | },
|
73 | beforeDestroy: function beforeDestroy() {
|
74 | var panelElem = this.$refs.panel;
|
75 |
|
76 | if (panelElem && panelElem.parentNode) {
|
77 | panelElem.parentNode.removeChild(panelElem);
|
78 | }
|
79 | },
|
80 | destroyed: function destroyed() {
|
81 | _tools.GlobalEvent.off(this, 'mousewheel');
|
82 | },
|
83 | render: function render(h) {
|
84 | var _ref,
|
85 | _ref2,
|
86 | _this = this,
|
87 | _ref3,
|
88 | _ref4;
|
89 |
|
90 | var $scopedSlots = this.$scopedSlots,
|
91 | $listeners = this.$listeners,
|
92 | className = this.className,
|
93 | inited = this.inited,
|
94 | type = this.type,
|
95 | destroyOnClose = this.destroyOnClose,
|
96 | isFormBtn = this.isFormBtn,
|
97 | status = this.status,
|
98 | btnType = this.btnType,
|
99 | vSize = this.vSize,
|
100 | name = this.name,
|
101 | disabled = this.disabled,
|
102 | loading = this.loading,
|
103 | showPanel = this.showPanel,
|
104 | animatVisible = this.animatVisible,
|
105 | panelPlacement = this.panelPlacement;
|
106 | var downsSlot = $scopedSlots.dropdowns;
|
107 | return downsSlot ? h('div', {
|
108 | class: ['vxe-button--dropdown', className, (_ref = {}, _defineProperty(_ref, "size--".concat(vSize), vSize), _defineProperty(_ref, 'is--active', showPanel), _ref)]
|
109 | }, [h('button', {
|
110 | ref: 'xBtn',
|
111 | class: ['vxe-button', "type--".concat(btnType), (_ref2 = {}, _defineProperty(_ref2, "size--".concat(vSize), vSize), _defineProperty(_ref2, "theme--".concat(status), status), _defineProperty(_ref2, 'is--round', this.round), _defineProperty(_ref2, 'is--circle', this.circle), _defineProperty(_ref2, 'is--disabled', disabled || loading), _defineProperty(_ref2, 'is--loading', loading), _ref2)],
|
112 | attrs: {
|
113 | name: name,
|
114 | type: isFormBtn ? type : 'button',
|
115 | disabled: disabled || loading
|
116 | },
|
117 | on: Object.assign({
|
118 | mouseenter: this.mouseenterTargetEvent,
|
119 | mouseleave: this.mouseleaveEvent
|
120 | }, _xeUtils.default.objectMap($listeners, function (cb, type) {
|
121 | return function (evnt) {
|
122 | return _this.$emit(type, {
|
123 | $event: evnt
|
124 | });
|
125 | };
|
126 | }))
|
127 | }, this.renderContent(h).concat([h('i', {
|
128 | class: "vxe-button--dropdown-arrow ".concat(_conf.default.icon.BUTTON_DROPDOWN)
|
129 | })])), h('div', {
|
130 | ref: 'panel',
|
131 | class: ['vxe-button--dropdown-panel', (_ref3 = {}, _defineProperty(_ref3, "size--".concat(vSize), vSize), _defineProperty(_ref3, 'animat--leave', animatVisible), _defineProperty(_ref3, 'animat--enter', showPanel), _ref3)],
|
132 | attrs: {
|
133 | placement: panelPlacement
|
134 | },
|
135 | style: this.panelStyle
|
136 | }, inited ? [h('div', {
|
137 | class: 'vxe-button--dropdown-wrapper',
|
138 | on: {
|
139 | mousedown: this.mousedownDropdownEvent,
|
140 | click: this.clickDropdownEvent,
|
141 | mouseenter: this.mouseenterEvent,
|
142 | mouseleave: this.mouseleaveEvent
|
143 | }
|
144 | }, destroyOnClose && !showPanel ? [] : downsSlot.call(this, {}, h))] : null)]) : h('button', {
|
145 | ref: 'xBtn',
|
146 | class: ['vxe-button', "type--".concat(btnType), className, (_ref4 = {}, _defineProperty(_ref4, "size--".concat(vSize), vSize), _defineProperty(_ref4, "theme--".concat(status), status), _defineProperty(_ref4, 'is--round', this.round), _defineProperty(_ref4, 'is--circle', this.circle), _defineProperty(_ref4, 'is--disabled', disabled || loading), _defineProperty(_ref4, 'is--loading', loading), _ref4)],
|
147 | attrs: {
|
148 | name: name,
|
149 | type: isFormBtn ? type : 'button',
|
150 | disabled: disabled || loading
|
151 | },
|
152 | on: _xeUtils.default.objectMap($listeners, function (cb, type) {
|
153 | return function (evnt) {
|
154 | return _this.$emit(type, {
|
155 | $event: evnt
|
156 | });
|
157 | };
|
158 | })
|
159 | }, this.renderContent(h));
|
160 | },
|
161 | methods: {
|
162 | renderContent: function renderContent(h) {
|
163 | var $scopedSlots = this.$scopedSlots,
|
164 | content = this.content,
|
165 | icon = this.icon,
|
166 | loading = this.loading;
|
167 | var contents = [];
|
168 |
|
169 | if (loading) {
|
170 | contents.push(h('i', {
|
171 | class: ['vxe-button--loading-icon', _conf.default.icon.BUTTON_LOADING]
|
172 | }));
|
173 | } else if (icon) {
|
174 | contents.push(h('i', {
|
175 | class: ['vxe-button--icon', icon]
|
176 | }));
|
177 | }
|
178 |
|
179 | if ($scopedSlots.default) {
|
180 | contents.push(h('span', {
|
181 | class: 'vxe-button--content'
|
182 | }, $scopedSlots.default.call(this)));
|
183 | } else if (content) {
|
184 | contents.push(h('span', {
|
185 | class: 'vxe-button--content'
|
186 | }, [_tools.UtilTools.getFuncText(content)]));
|
187 | }
|
188 |
|
189 | return contents;
|
190 | },
|
191 | handleGlobalMousewheelEvent: function handleGlobalMousewheelEvent(evnt) {
|
192 | if (this.showPanel && !_tools.DomTools.getEventTargetNode(evnt, this.$refs.panel).flag) {
|
193 | this.closePanel();
|
194 | }
|
195 | },
|
196 | updateZindex: function updateZindex() {
|
197 | if (this.panelIndex < _tools.UtilTools.getLastZIndex()) {
|
198 | this.panelIndex = _tools.UtilTools.nextZIndex();
|
199 | }
|
200 | },
|
201 | mousedownDropdownEvent: function mousedownDropdownEvent(evnt) {
|
202 | var isLeftBtn = evnt.button === 0;
|
203 |
|
204 | if (isLeftBtn) {
|
205 | evnt.stopPropagation();
|
206 | }
|
207 | },
|
208 | clickDropdownEvent: function clickDropdownEvent(evnt) {
|
209 | var _this2 = this;
|
210 |
|
211 | var dropdownElem = evnt.currentTarget;
|
212 | var panelElem = this.$refs.panel;
|
213 |
|
214 | var _DomTools$getEventTar = _tools.DomTools.getEventTargetNode(evnt, dropdownElem, 'vxe-button'),
|
215 | flag = _DomTools$getEventTar.flag,
|
216 | targetElem = _DomTools$getEventTar.targetElem;
|
217 |
|
218 | if (flag) {
|
219 | if (panelElem) {
|
220 | panelElem.dataset.active = 'N';
|
221 | }
|
222 |
|
223 | this.showPanel = false;
|
224 | setTimeout(function () {
|
225 | if (!panelElem || panelElem.dataset.active !== 'Y') {
|
226 | _this2.animatVisible = false;
|
227 | }
|
228 | }, 350);
|
229 | this.$emit('dropdown-click', {
|
230 | name: targetElem.getAttribute('name'),
|
231 | $event: evnt
|
232 | });
|
233 | }
|
234 | },
|
235 | mouseenterTargetEvent: function mouseenterTargetEvent() {
|
236 | var _this3 = this;
|
237 |
|
238 | var panelElem = this.$refs.panel;
|
239 | panelElem.dataset.active = 'Y';
|
240 |
|
241 | if (!this.inited) {
|
242 | this.inited = true;
|
243 |
|
244 | if (this.transfer) {
|
245 | document.body.appendChild(panelElem);
|
246 | }
|
247 | }
|
248 |
|
249 | this.showTime = setTimeout(function () {
|
250 | if (panelElem.dataset.active === 'Y') {
|
251 | _this3.mouseenterEvent();
|
252 | } else {
|
253 | _this3.animatVisible = false;
|
254 | }
|
255 | }, 250);
|
256 | },
|
257 | mouseenterEvent: function mouseenterEvent() {
|
258 | var _this4 = this;
|
259 |
|
260 | var panelElem = this.$refs.panel;
|
261 | panelElem.dataset.active = 'Y';
|
262 | this.animatVisible = true;
|
263 | setTimeout(function () {
|
264 | if (panelElem.dataset.active === 'Y') {
|
265 | _this4.showPanel = true;
|
266 |
|
267 | _this4.updateZindex();
|
268 |
|
269 | _this4.updatePlacement();
|
270 |
|
271 | setTimeout(function () {
|
272 | if (_this4.showPanel) {
|
273 | _this4.updatePlacement();
|
274 | }
|
275 | }, 50);
|
276 | }
|
277 | }, 20);
|
278 | },
|
279 | mouseleaveEvent: function mouseleaveEvent() {
|
280 | this.closePanel();
|
281 | },
|
282 | closePanel: function closePanel() {
|
283 | var _this5 = this;
|
284 |
|
285 | var panelElem = this.$refs.panel;
|
286 | clearTimeout(this.showTime);
|
287 |
|
288 | if (panelElem) {
|
289 | panelElem.dataset.active = 'N';
|
290 | setTimeout(function () {
|
291 | if (panelElem.dataset.active !== 'Y') {
|
292 | _this5.showPanel = false;
|
293 | setTimeout(function () {
|
294 | if (panelElem.dataset.active !== 'Y') {
|
295 | _this5.animatVisible = false;
|
296 | }
|
297 | }, 350);
|
298 | }
|
299 | }, 100);
|
300 | } else {
|
301 | this.animatVisible = false;
|
302 | this.showPanel = false;
|
303 | }
|
304 | },
|
305 | updatePlacement: function updatePlacement() {
|
306 | var _this6 = this;
|
307 |
|
308 | return this.$nextTick().then(function () {
|
309 | var $refs = _this6.$refs,
|
310 | transfer = _this6.transfer,
|
311 | placement = _this6.placement,
|
312 | panelIndex = _this6.panelIndex;
|
313 | var targetElem = $refs.xBtn;
|
314 | var panelElem = $refs.panel;
|
315 |
|
316 | if (panelElem && targetElem) {
|
317 | var targetHeight = targetElem.offsetHeight;
|
318 | var targetWidth = targetElem.offsetWidth;
|
319 | var panelHeight = panelElem.offsetHeight;
|
320 | var panelWidth = panelElem.offsetWidth;
|
321 | var marginSize = 5;
|
322 | var panelStyle = {
|
323 | zIndex: panelIndex
|
324 | };
|
325 |
|
326 | var _DomTools$getAbsolute = _tools.DomTools.getAbsolutePos(targetElem),
|
327 | boundingTop = _DomTools$getAbsolute.boundingTop,
|
328 | boundingLeft = _DomTools$getAbsolute.boundingLeft,
|
329 | visibleHeight = _DomTools$getAbsolute.visibleHeight,
|
330 | visibleWidth = _DomTools$getAbsolute.visibleWidth;
|
331 |
|
332 | var panelPlacement = 'bottom';
|
333 |
|
334 | if (transfer) {
|
335 | var left = boundingLeft + targetWidth - panelWidth;
|
336 | var top = boundingTop + targetHeight;
|
337 |
|
338 | if (placement === 'top') {
|
339 | panelPlacement = 'top';
|
340 | top = boundingTop - panelHeight;
|
341 | } else if (!placement) {
|
342 |
|
343 | if (top + panelHeight + marginSize > visibleHeight) {
|
344 | panelPlacement = 'top';
|
345 | top = boundingTop - panelHeight;
|
346 | }
|
347 |
|
348 |
|
349 | if (top < marginSize) {
|
350 | panelPlacement = 'bottom';
|
351 | top = boundingTop + targetHeight;
|
352 | }
|
353 | }
|
354 |
|
355 |
|
356 | if (left + panelWidth + marginSize > visibleWidth) {
|
357 | left -= left + panelWidth + marginSize - visibleWidth;
|
358 | }
|
359 |
|
360 |
|
361 | if (left < marginSize) {
|
362 | left = marginSize;
|
363 | }
|
364 |
|
365 | Object.assign(panelStyle, {
|
366 | left: "".concat(left, "px"),
|
367 | right: 'auto',
|
368 | top: "".concat(top, "px"),
|
369 | minWidth: "".concat(targetWidth, "px")
|
370 | });
|
371 | } else {
|
372 | if (placement === 'top') {
|
373 | panelPlacement = 'top';
|
374 | panelStyle.bottom = "".concat(targetHeight, "px");
|
375 | } else if (!placement) {
|
376 |
|
377 | if (boundingTop + targetHeight + panelHeight > visibleHeight) {
|
378 |
|
379 | if (boundingTop - targetHeight - panelHeight > marginSize) {
|
380 | panelPlacement = 'top';
|
381 | panelStyle.bottom = "".concat(targetHeight, "px");
|
382 | }
|
383 | }
|
384 | }
|
385 | }
|
386 |
|
387 | _this6.panelStyle = panelStyle;
|
388 | _this6.panelPlacement = panelPlacement;
|
389 | return _this6.$nextTick();
|
390 | }
|
391 | });
|
392 | },
|
393 | focus: function focus() {
|
394 | this.$el.focus();
|
395 | return this.$nextTick();
|
396 | },
|
397 | blur: function blur() {
|
398 | this.$el.blur();
|
399 | return this.$nextTick();
|
400 | }
|
401 | }
|
402 | };
|
403 | exports.default = _default2; |
\ | No newline at end of file |