扫码
40.67M · 2026-04-17
一个基于 Vue 2 和 Ant Design Vue 1.x 的可视化组件装修工具,支持拖拽排序、属性编辑和实时预览。
src/
├── components/
│ └── DecorationBuilder/ # 装修工具主目录
│ ├── bases/ # 基础组件
│ │ ├── Editor/ # 属性编辑器
│ │ ├── Preview/ # 移动端预览组件
│ │ │ ├── components/ # 预览组件的子组件
│ │ │ │ ├── BrowserToolbar/ # 浏览器工具栏
│ │ │ │ └── SizeEditor/ # 尺寸编辑器
│ │ └── Selector/ # 组件选择器
│ ├── config/ # 配置文件
│ │ ├── componentTypes.js # 组件类型定义
│ │ └── settings.js # 全局设置
│ ├── widgets/ # 自定义组件
│ │ ├── Banner/ # 轮播图组件
│ │ ├── News/ # 新闻列表组件
│ │ └── index.js # 组件注册表
│ └── index.vue # 装修工具主入口
└── utils/
├── componentUtils.js # 组件相关工具函数
└── index.js # 通用工具函数
graph TD
A[DecorationBuilder] --> B[bases]
A --> C[config]
A --> D[widgets]
A --> E[index.vue]
B --> F[Editor]
B --> G[Preview]
B --> H[Selector]
G --> I[components]
I --> J[BrowserToolbar]
I --> K[SizeEditor]
C --> L[componentTypes.js]
C --> M[settings.js]
D --> N[Banner]
D --> O[News]
D --> P[index.js]
src/components/DecorationBuilder/index.vuesrc/components/DecorationBuilder/bases/Preview/index.vuesrc/components/DecorationBuilder/bases/Editor/index.vuesrc/components/DecorationBuilder/bases/Selector/index.vueexport const COMPONENT_TYPES = {
BANNER: 'banner', // 轮播图
NEWS_LIST: 'news-list' // 新闻列表
}
export const COMPONENT_METADATA = {
[COMPONENT_TYPES.BANNER]: {
name: '轮播图',
description: '支持多张图片轮播展示',
icon: 'picture',
category: '基础组件'
}
// ...
}
export const PREVIEW_SETTINGS = {
MOBILE_WIDTH: 375, // 默认移动端宽度
MOBILE_HEIGHT: 812 // 默认移动端高度
}
文件:src/utils/componentUtils.js
主要功能:
getComponentMetadata():获取组件元数据getAllComponentTypes():获取所有组件类型getWidgetConfig():获取组件配置getWidgetDefaultProps():获取组件默认属性getWidgetPreview():获取预览组件getWidgetEditor():获取编辑组件| 组件类型 | 组件名称 | 预览组件 | 编辑组件 |
|---|---|---|---|
| banner | 轮播图 | BannerPreview | BannerEditor |
| news-list | 新闻列表 | NewsPreview | NewsEditor |
[
{
"id": "1234567890",
"type": "banner",
"props": {
"images": [
{ "url": "https://example.com/image1.jpg", "link": "" },
{ "url": "https://example.com/image2.jpg", "link": "" }
],
"autoPlay": true,
"interval": 3000,
"dots": true,
"arrows": false
}
},
{
"id": "0987654321",
"type": "news-list",
"props": {
"title": "最新资讯",
"news": [
{ "id": 1, "title": "新闻标题1", "date": "2026-04-16", "link": "" },
{ "id": 2, "title": "新闻标题2", "date": "2026-04-17", "link": "" }
],
"showDate": true,
"showArrow": true,
"maxItems": 5
}
}
]
COMPONENT_TYPES 中的值index.js 文件中的 defaultProps以添加一个"轮播的通知公告"组件为例:
在 src/components/DecorationBuilder/widgets/ 下创建新组件目录:
NotificationBanner/
├── index.js # 组件配置文件
├── preview.vue # 预览组件
└── editor.vue # 编辑组件
import NotificationBannerPreview from './preview.vue'
import NotificationBannerEditor from './editor.vue'
import { COMPONENT_TYPES } from '../../config/componentTypes'
export default {
type: COMPONENT_TYPES.NOTIFICATION_BANNER, // 需要在componentTypes.js中定义
Preview: NotificationBannerPreview,
Editor: NotificationBannerEditor,
defaultProps: {
// 组件默认属性
notifications: [
{ id: 1, content: '通知内容1' },
{ id: 2, content: '通知内容2' }
],
autoPlay: true,
interval: 2000
}
}
<template>
<div class="notification-banner">
<!-- 轮播的通知内容 -->
</div>
</template>
<script>
export default {
name: 'NotificationBannerPreview',
props: {
component: {
type: Object,
required: true
}
}
}
</script>
<style scoped>
/* 组件样式 */
</style>
<template>
<div class="notification-banner-editor">
<!-- 属性编辑表单 -->
</div>
</template>
<script>
export default {
name: 'NotificationBannerEditor',
props: {
component: {
type: Object,
required: true
}
}
}
</script>
在 src/components/DecorationBuilder/config/componentTypes.js 中添加组件类型:
export const COMPONENT_TYPES = {
// ... 现有类型
NOTIFICATION_BANNER: 'notification-banner' // 新增通知公告类型
}
export const COMPONENT_METADATA = {
// ... 现有元数据
[COMPONENT_TYPES.NOTIFICATION_BANNER]: {
name: '通知公告',
description: '轮播展示通知内容',
icon: 'bell',
category: '基础组件'
}
}
在 src/components/DecorationBuilder/widgets/index.js 中导入并注册新组件:
import BannerComponent from './Banner'
import NewsComponent from './News'
import NotificationBannerComponent from './NotificationBanner' // 导入新组件
export const widgets = [
BannerComponent,
NewsComponent,
NotificationBannerComponent // 注册新组件
]
componentTypes.js 中定义类型和元数据index.js 中定义