diff --git a/src/components/editor/config/block.ts b/src/components/editor/config/block.ts
index ff6b685..cb8767c 100644
--- a/src/components/editor/config/block.ts
+++ b/src/components/editor/config/block.ts
@@ -1,17 +1,66 @@
export interface Block
{
+ /**
+ * 组件ID
+ */
id: string;
+ /**
+ * 组件类型
+ */
type: string;
+ /**
+ * 组件名称
+ */
+ title: string;
+ /**
+ * 距离左侧
+ */
x: number;
+ /**
+ * 距离顶部
+ */
y: number;
+ /**
+ * 宽度
+ */
w: number;
+ /**
+ * 高度
+ */
h: number;
+ /**
+ * 水平方向是否固定
+ */
xFixed: boolean;
+ /**
+ * 垂直方向是否固定
+ */
yFixed: boolean;
+ /**
+ * 背景图片
+ */
bgImage?: string;
+ /**
+ * 背景颜色
+ */
bgColor?: string;
+ /**
+ * 是否选中
+ */
actived: boolean;
+ /**
+ * 是否可缩放
+ */
resizable: boolean;
+ /**
+ * 是否可拖拽
+ */
draggable: boolean;
+ /**
+ * 元数据
+ */
meta: Record;
+ /**
+ * 组件参数
+ */
params: T;
}
diff --git a/src/components/editor/config/context.ts b/src/components/editor/config/context.ts
index 89e1dfe..332fc85 100644
--- a/src/components/editor/config/context.ts
+++ b/src/components/editor/config/context.ts
@@ -2,14 +2,16 @@ import { InjectionKey, Ref } from "vue";
import { Block } from "./block";
import { Container } from "./container";
+export interface Current {
+ block: Block | null;
+ rightPanelCollapsed: boolean;
+}
+
export interface Context {
/**
* 运行时数据
*/
- current: Ref<{
- block: Block | null;
- rightPanelCollapsed: boolean;
- }>;
+ current: Ref;
/**
* 组件列表
*/
@@ -36,7 +38,10 @@ export interface Context {
* 加载数据
*/
loadData: () => void;
+ /**
+ * 预览
+ */
+ preview: () => void;
}
-export const ContextKey = Symbol('ContextKey') as InjectionKey;
-
+export const ContextKey = Symbol("ContextKey") as InjectionKey;
diff --git a/src/components/editor/index.vue b/src/components/editor/index.vue
index 6733542..3a29206 100644
--- a/src/components/editor/index.vue
+++ b/src/components/editor/index.vue
@@ -4,7 +4,7 @@
-
+
@@ -25,6 +26,9 @@ import PanelHeader from "./panel-header/index.vue";
import PanelLeft from "./panel-left/index.vue";
import PanelMain from "./panel-main/index.vue";
import PanelRight from "./panel-right/index.vue";
+import AppnifyPreview from "./preview/index.vue";
+
+const preview = ref(false);
/**
* 运行时上下文
@@ -105,7 +109,15 @@ const setCurrentBlock = (block: Block | null) => {
const setContainerOrigin = () => {
container.value.x = 0;
container.value.y = 0;
- container.value.zoom = 0.7;
+ const el = document.querySelector(".juetan-editor-container");
+ if (el) {
+ const { width, height } = el.getBoundingClientRect();
+ const wZoom = width / container.value.width;
+ const hZoom = height / container.value.width;
+ const zoom = Math.floor((wZoom > hZoom ? wZoom : hZoom) * 100) / 100;
+ // console.log(width, height, wZoom, hZoom, zoom);
+ container.value.zoom = zoom;
+ }
};
/**
@@ -119,14 +131,17 @@ provide(ContextKey, {
setContainerOrigin,
loadData,
saveData,
+ preview() {
+ preview.value = true;
+ },
});
diff --git a/src/components/editor/panel-main/components/block.vue b/src/components/editor/panel-main/components/block.vue
index 66a554c..f2743fe 100644
--- a/src/components/editor/panel-main/components/block.vue
+++ b/src/components/editor/panel-main/components/block.vue
@@ -13,6 +13,7 @@
:isActive="data.actived"
:isResizable="data.resizable"
:style="blockStyle"
+ :class="'resizer'"
@dragging="onItemDragOrResize"
@resizing="onItemDragOrResize"
@activated="setCurrentBlock(data)"
@@ -57,4 +58,25 @@ const onItemDragOrResize = (rect: any) => {
};
-
+
diff --git a/src/components/editor/panel-main/components/header.vue b/src/components/editor/panel-main/components/header.vue
index 68efe8b..0d4e4b0 100644
--- a/src/components/editor/panel-main/components/header.vue
+++ b/src/components/editor/panel-main/components/header.vue
@@ -21,7 +21,7 @@
组件:
- {{ blocks.length }} 个
+ {{ blocks.length }} 个
@@ -31,7 +31,7 @@
-
+
@@ -78,7 +78,7 @@ import InputImage from "../../components/InputImage.vue";
import { ContextKey } from "../../config";
import AniTexter from "./texter.vue";
-const { container, blocks, current, setContainerOrigin } = inject(ContextKey)!;
+const { container, blocks, current, preview, setContainerOrigin } = inject(ContextKey)!;
diff --git a/src/components/editor/panel-main/index.vue b/src/components/editor/panel-main/index.vue
index 74e3da9..257e59c 100644
--- a/src/components/editor/panel-main/index.vue
+++ b/src/components/editor/panel-main/index.vue
@@ -4,7 +4,7 @@