vue实现可视化网页拖拽设计器代码

代码语言:html

所属分类:拖放

代码描述:vue实现可视化网页拖拽设计器代码

代码标签: vue 可视化 网页 拖拽 设计器 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Visual Web Page Designer</title>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue@2.6.1-dev.js"></script>
 <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Sortable.1.15.0.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vuedraggable.umd.2.20.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }
        #app {
           
            height: 100vh;
        }
        .design-area {
            flex: 2;
            border-right: 1px solid #ccc;
            padding: 20px;
            overflow-y: auto;
            min-height: 100vh;
        }
        .components-list {
            flex: 1;
            padding: 20px;
            background-color: #f0f0f0;
            overflow-y: auto;
        }
        .component-item {
            background-color: #fff;
            border: 1px solid #ddd;
            padding: 10px;
            margin-bottom: 10px;
            cursor: move;
        }
        .design-component {
            border: 1px dashed #999;
            padding: 10px;
            margin-bottom: 10px;
            position: relative;
        }
        .design-component.active {
            border: 2px solid #007bff;
        }
        .remove-btn {
            position: absolute;
            top: 5px;
            right: 5px;
            background-color: #ff4444;
            color: white;
            border: none;
            padding: 2px 5px;
            cursor: pointer;
        }
        .properties-panel {
            background-color: #f8f9fa;
            border-left: 1px solid #ccc;
            padding: 20px;
            width: 200px;
        }
        .export-btn {
            background-color: #28a745;
            color: white;
            border: none;
            padding: 10px 20px;
            cursor: pointer;
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div><button class="export-btn" @click="exportJSON">导出 JSON</button></div>
        <div style=" display: flex;">
            <div class="design-area">
                <h2>设计区</h2>
                <draggable v-model="designComponents" group="components" style="height:100vh;">
                    <div v-for="(component, index) in designComponents" :key="index" class="design-component" :class="{ active: selectedComponent === component }" @click="selectComponent(component)">
                        <component :is="component.type" v-bind="component.props">
                            {{ component.content }}
                        </component>
                        <button class="remove-btn" @click.stop="removeComponent(index)">X</button>
                    </div>
                </draggable>
            </div>
            <div class="components-list">
                <h2>组件列表</h2>
                <draggable v-model="availableComponents" :group="{ name: 'components', pull: 'clone', put: false }" :clone="cloneComponent">
                    <div v-for="component in availableComponents" :key="component.type" class="component-item">
                        {{ component.name }}
                    </div>
                </draggable>
            </div>
            <div class="properties-panel" v-if="selectedComponent">
                <h2>属性设置</h2>
                <div v-for="(value, key) in selectedComponent.props" :key="key">
                    <label>{{ key }}:</label>
                    <input v-model="selectedComponent.props[key]" @input="updateComponent">
                </div>
                <div v-if="selectedComponent.content !== undefined">
                    <la.........完整代码请登录后点击上方下载按钮下载查看

网友评论0