修改表单构建
parent
391153ec0a
commit
501c24448a
@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<div class="element-mini">
|
||||
<el-icon style="line-height: 32px;font-size: 12px;margin: 0 4px 0 8px">
|
||||
<Eleme />
|
||||
</el-icon>
|
||||
<span>{{ option.name }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
defineOptions({
|
||||
name: 'element-mini'
|
||||
});
|
||||
|
||||
const props = defineProps({
|
||||
option: Array
|
||||
});
|
||||
const { option } = toRefs(props);
|
||||
</script>
|
||||
<style scoped lang="less">
|
||||
.element-mini {
|
||||
width: 120px;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
font-size: 12px;
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
background-color: #f2f2f2;
|
||||
border-radius: 5px;
|
||||
color: #000;
|
||||
margin: 2px;
|
||||
cursor: pointer;
|
||||
border: 1px dashed #0000;
|
||||
|
||||
&:hover {
|
||||
//background-color: #00afff;
|
||||
border: 1px dashed #00afff;
|
||||
color: #00afff;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
<template>
|
||||
<div class="element-mini">
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
defineOptions({
|
||||
name: 'el-input'
|
||||
});
|
||||
|
||||
const props = defineProps({
|
||||
options: Array
|
||||
})
|
||||
const { options } = toRefs(props);
|
||||
</script>
|
||||
<style scoped lang="less">
|
||||
</style>
|
||||
|
||||
|
||||
|
@ -0,0 +1,112 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="left-box">
|
||||
<div class="model" :style="`display:${isDrag?'inline-block':'none'}`">
|
||||
</div>
|
||||
<draggable :list="dragList" ghost-class="ghost" :force-fallback="true" :group="{ name: 'list', pull: 'clone' }"
|
||||
:sort="false" itemKey="id" @start="onStartLeft" :clone="onClone">
|
||||
<template #item="{ element }">
|
||||
<element-mini :option="element" />
|
||||
</template>
|
||||
</draggable>
|
||||
</div>
|
||||
<div class="right-box">
|
||||
<nested-draggable :tasks="widgetList" style="height: 100%;" />
|
||||
</div>
|
||||
<div class="option-box">
|
||||
|
||||
</div>
|
||||
<div class="dataBox">
|
||||
<div>{{ dragList }}</div>
|
||||
</div>
|
||||
<div class="dataBox">
|
||||
<div>{{ widgetList }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import draggable from 'vuedraggable';
|
||||
import nestedDraggable from './nest.vue';
|
||||
import elementMini from './element-mini.vue';
|
||||
|
||||
interface type {
|
||||
name: string,
|
||||
id: number
|
||||
}
|
||||
|
||||
const dragList = [
|
||||
{ type: 'el-input', options: { labelWidth: '120px' }, tasks: [], name: '表单', id: 0 },
|
||||
{ type: 'el-input', options: { type: 'text' }, name: '单行文本', id: 1 },
|
||||
{ type: 'el-input', options: { type: 'password' }, name: '密码文本', id: 2 },
|
||||
{ type: 'el-input', options: { type: 'textarea' }, name: '多行文本', id: 3 },
|
||||
{ type: 'el-input-number', options: { step: 2 }, name: '计数器', id: 4 },
|
||||
{
|
||||
type: 'el-radio-group',
|
||||
options: { items: [{ value: '1', label: '1' }, { value: '1', label: '1' }] },
|
||||
name: '单选框组',
|
||||
id: 5
|
||||
},
|
||||
{ type: 'el-slider', options: { step: 2, showStops: true }, name: '滑块', id: 6 }
|
||||
];
|
||||
|
||||
const widgetList = reactive<type[]>([]);
|
||||
const isDrag = ref(false);
|
||||
const onClone = (e) => {
|
||||
console.log(JSON.parse(JSON.stringify(e)));
|
||||
return JSON.parse(JSON.stringify(e));
|
||||
};
|
||||
const onStartLeft = (e) => {
|
||||
// console.log(e);
|
||||
};
|
||||
|
||||
</script>
|
||||
<style scoped>
|
||||
.model {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.left-box {
|
||||
width: 260px;
|
||||
display: inline-block;
|
||||
user-select: none;
|
||||
vertical-align: top;
|
||||
position: relative;
|
||||
margin: 8px;
|
||||
padding: 2px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.right-box {
|
||||
width: 400px;
|
||||
display: inline-block;
|
||||
user-select: none;
|
||||
vertical-align: top;
|
||||
margin: 8px;
|
||||
border: 1px solid #ccc;
|
||||
height: 80vh;
|
||||
}
|
||||
|
||||
.option-box {
|
||||
width: 400px;
|
||||
display: inline-block;
|
||||
user-select: none;
|
||||
vertical-align: top;
|
||||
margin: 8px;
|
||||
border: 1px solid #ccc;
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
.dataBox {
|
||||
width: 200px;
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
margin-right: 10px;
|
||||
border: 1px solid #ccc;
|
||||
|
||||
}
|
||||
</style>
|
@ -0,0 +1,52 @@
|
||||
<template>
|
||||
<draggable
|
||||
class="dragArea"
|
||||
style="height: 100%"
|
||||
:list="tasks"
|
||||
:group="{ name: 'list' }"
|
||||
item-key="name"
|
||||
@change="changeCB"
|
||||
:move="onMove"
|
||||
>
|
||||
<template #item="{ element }">
|
||||
<div style="margin-bottom: 10px;">
|
||||
<div>{{ element.name }}</div>
|
||||
<nested-draggable :tasks="element.tasks" v-if="element.tasks" />
|
||||
<component :is="element.type" :options="element.options" v-else />
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
defineOptions({
|
||||
name: 'nested-draggable'
|
||||
});
|
||||
import draggable from 'vuedraggable';
|
||||
|
||||
const props = defineProps({
|
||||
tasks: Array
|
||||
});
|
||||
const { tasks } = toRefs(props);
|
||||
const changeCB = (e) => {
|
||||
console.log('changeCB', e);
|
||||
// console.log('changeCB', tasks.value[e.added.newIndex]);
|
||||
// tasks.value[e.added.newIndex].id = Date.now();
|
||||
if (e.added) {
|
||||
tasks.value[e.added.newIndex].id = Date.now();
|
||||
}
|
||||
if (e.moved) {
|
||||
tasks.value[e.moved.newIndex].id = Date.now();
|
||||
}
|
||||
};
|
||||
const onMove = (e) => {
|
||||
console.log('move', e);
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.dragArea {
|
||||
min-height: 50px;
|
||||
outline: 1px dashed;
|
||||
margin-bottom: 5px;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue