import draggable from "vuedraggable";
import render from "@/utils/generator/render";
import { defineComponent } from "vue";
import { CopyDocument, Delete } from "@element-plus/icons-vue";
const components = {
itemBtns(currentItem, index, list) {
const { onCopyItem, onDeleteItem } = this.$attrs;
return [
{
onCopyItem(currentItem, list);
event.stopPropagation();
}}
>
,
{
onDeleteItem(index, list);
event.stopPropagation();
}}
>
,
];
},
};
const layouts = {
colFormItem(
// h,
currentItem,
index,
list
) {
const { onActiveItem } = this.$attrs;
const config = currentItem.__config__;
// console.log(arguments, "argu");
const child = renderChildren.apply(this, arguments);
let className =
this.activeId === config.formId
? "drawing-item active-from-item"
: "drawing-item";
if (this.formConf.unFocusedComponentBorder)
className += " unfocus-bordered";
let labelWidth = config.labelWidth ? `${config.labelWidth}px` : null;
if (config.showLabel === false) labelWidth = "0";
// console.log(child);
return (
{
onActiveItem(currentItem);
event.stopPropagation();
}}
>
{
config.defaultValue = event;
}}
>
{{
default: child,
}}
{components.itemBtns.apply(this, arguments)}
);
},
rowFormItem(
// h,
currentItem,
index,
list
) {
const { onActiveItem } = this.$attrs;
const config = currentItem.__config__;
// console.log(config);
const className =
this.activeId === config.formId
? "drawing-row-item active-from-item"
: "drawing-row-item";
let child = renderChildren.apply(this, arguments);
if (currentItem.type === "flex") {
child = (
{child}
);
}
return (
{
onActiveItem(currentItem);
event.stopPropagation();
}}
>
{config.componentName}
{{
item: ({ element, index }) => {
const layout = layouts[element.__config__.layout];
console.log(element, "element");
if (layout) {
return layout.call(this, element, index, config.children);
}
return layoutIsNotFound.call(this);
},
}}
{components.itemBtns.apply(this, arguments)}
);
},
raw(
// h,
currentItem,
index,
list
) {
const config = currentItem.__config__;
const child = renderChildren.apply(this, arguments);
return (
{
config.defaultValue = event;
}}
>
{child}
);
},
};
function renderChildren(
// // h,
currentItem,
index,
list
) {
const config = currentItem.__config__;
// // console.log(config, "config");
if (!Array.isArray(config.children)) return null;
return config.children.map((el, i) => {
const layout = layouts[el.__config__.layout];
// console.log(el.__config__.layout, `row's child`);
if (layout) {
return layout.call(
this,
// // h,
el,
i,
config.children
);
}
return layoutIsNotFound.call(this);
});
}
function layoutIsNotFound() {
throw new Error(`没有与${this.currentItem.__config__.layout}匹配的layout`);
}
export default defineComponent({
name: "DraggableItem",
components: {
render,
draggable,
},
props: ["currentItem", "index", "drawingList", "activeId", "formConf"],
methods: {
set(val) {
this.currentItem.__config__.defaultValue = val;
},
},
render() {
// // console.log(this.currentItem.__config__.layout);
const layout = layouts[this.currentItem.__config__.layout];
// // console.log(this.currentItem);
// // console.log(layout, "layout");
if (layout) {
return layout.call(
this,
// // h,
this.currentItem,
this.index,
this.drawingList
);
}
return layoutIsNotFound.call(this);
},
});