将多个组件使用同一事件改为每个组件单独事件
This commit is contained in:
parent
75b51df049
commit
679602f662
|
@ -75,6 +75,66 @@ const emits = [
|
|||
...[...events.manageAndEmit, ...events.emit].map((evt) => evt.toLowerCase()),
|
||||
];
|
||||
|
||||
const initialize_sortablejs = () => {
|
||||
function AfxEventPlugin() {
|
||||
function AfxEvent() {
|
||||
this.defaults = {};
|
||||
this.vue_self = null;
|
||||
}
|
||||
|
||||
AfxEvent.prototype = {
|
||||
_emitVueEvent: function _emitVueEvent(name, arg) {
|
||||
try {
|
||||
if (this.vue_self) {
|
||||
this.vue_self.$emit(name, arg);
|
||||
}
|
||||
} catch {}
|
||||
},
|
||||
dropGlobal: function dropGlobal(evt) {
|
||||
try {
|
||||
if (evt.dragEl) {
|
||||
this._emitVueEvent("drop", {
|
||||
data: evt.dragEl.__draggable_context.element,
|
||||
event: evt.originalEvent,
|
||||
});
|
||||
}
|
||||
setTimeout(() => {
|
||||
// 模拟点击,修复拖拽后必须点一下才能切换tab的BUG
|
||||
document.body.click();
|
||||
}, 0);
|
||||
} catch {}
|
||||
},
|
||||
};
|
||||
|
||||
function _extends() {
|
||||
_extends =
|
||||
Object.assign ||
|
||||
function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
|
||||
for (var key in source) {
|
||||
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
return _extends.apply(this, arguments);
|
||||
}
|
||||
return _extends(AfxEvent, {
|
||||
pluginName: "afx_event",
|
||||
});
|
||||
}
|
||||
try {
|
||||
Sortable.mount(new AfxEventPlugin());
|
||||
} catch {}
|
||||
};
|
||||
initialize_sortablejs();
|
||||
|
||||
const draggableComponent = defineComponent({
|
||||
name: "draggable",
|
||||
|
||||
|
@ -122,8 +182,6 @@ const draggableComponent = defineComponent({
|
|||
return;
|
||||
}
|
||||
|
||||
const self = this;
|
||||
|
||||
const { $attrs, $el, componentStructure } = this;
|
||||
componentStructure.updated();
|
||||
|
||||
|
@ -137,51 +195,12 @@ const draggableComponent = defineComponent({
|
|||
});
|
||||
const targetDomElement = $el.nodeType === 1 ? $el : $el.parentElement;
|
||||
|
||||
function AfxTestPlugin() {
|
||||
function AfxTest() {
|
||||
this.defaults = {};
|
||||
}
|
||||
|
||||
AfxTest.prototype = {
|
||||
dropGlobal: function dropGlobal(evt) {
|
||||
try {
|
||||
self.$emit("drop", {
|
||||
data: evt.dragEl.__draggable_context.element,
|
||||
event: evt.originalEvent,
|
||||
});
|
||||
} catch {}
|
||||
},
|
||||
};
|
||||
|
||||
function _extends() {
|
||||
_extends =
|
||||
Object.assign ||
|
||||
function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
|
||||
for (var key in source) {
|
||||
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
return _extends.apply(this, arguments);
|
||||
}
|
||||
return _extends(AfxTest, {
|
||||
pluginName: "afxtest",
|
||||
});
|
||||
}
|
||||
try {
|
||||
Sortable.mount(new AfxTestPlugin());
|
||||
} catch {}
|
||||
|
||||
sortableOptions.fallbackOnBody = true;
|
||||
this._sortable = new Sortable(targetDomElement, sortableOptions);
|
||||
console.log();
|
||||
if (this._sortable["afx_event"]) {
|
||||
this._sortable["afx_event"].vue_self = this;
|
||||
}
|
||||
this.targetDomElement = targetDomElement;
|
||||
targetDomElement.__draggable_component__ = this;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue