|
@@ -4,7 +4,16 @@
|
|
ref="componentWrapperRef"
|
|
ref="componentWrapperRef"
|
|
:style="warpperStyle"
|
|
:style="warpperStyle"
|
|
>
|
|
>
|
|
- <Container v-bind="componentData.container" @click.stop="handleSelectComponent">
|
|
|
|
|
|
+ <div class="group-box" v-if="componentData.componentType === 'group'">
|
|
|
|
+ <ComponentWrapper
|
|
|
|
+ v-for="item in componentData.children"
|
|
|
|
+ v-show="item.visible"
|
|
|
|
+ :component-data="item"
|
|
|
|
+ :key="item.key"
|
|
|
|
+ :style="{ zIndex: item.zIndex }"
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ <Container v-bind="componentData.container" v-else>
|
|
<component
|
|
<component
|
|
:is="component"
|
|
:is="component"
|
|
v-bind="componentData.props"
|
|
v-bind="componentData.props"
|
|
@@ -39,14 +48,16 @@ import { useProjectStore } from "@/store/modules/project";
|
|
import { useDraggable } from "@vueuse/core";
|
|
import { useDraggable } from "@vueuse/core";
|
|
import { UseDraggable } from "@vueuse/components";
|
|
import { UseDraggable } from "@vueuse/components";
|
|
import { useAcionStore } from "@/store/modules/action";
|
|
import { useAcionStore } from "@/store/modules/action";
|
|
-import { asyncComponentAll } from 'shalu-dashboard-ui';
|
|
|
|
|
|
+import { asyncComponentAll } from "shalu-dashboard-ui";
|
|
import Container from "@/components/Container/index.vue";
|
|
import Container from "@/components/Container/index.vue";
|
|
|
|
+import { scaleAction } from "@/utils/scale";
|
|
|
|
|
|
const { componentData } = defineProps<{ componentData: CustomElement }>();
|
|
const { componentData } = defineProps<{ componentData: CustomElement }>();
|
|
// 动态引入组件
|
|
// 动态引入组件
|
|
-const component = defineAsyncComponent(
|
|
|
|
- asyncComponentAll[componentData.componentType]
|
|
|
|
-);
|
|
|
|
|
|
+const component =
|
|
|
|
+ componentData.componentType === "group"
|
|
|
|
+ ? ""
|
|
|
|
+ : defineAsyncComponent(asyncComponentAll[componentData.componentType]);
|
|
|
|
|
|
const componentWrapperRef = ref<HTMLElement | null>(null);
|
|
const componentWrapperRef = ref<HTMLElement | null>(null);
|
|
const stageStore = useStageStore();
|
|
const stageStore = useStageStore();
|
|
@@ -69,14 +80,16 @@ const editWapperStyle = computed(() => {
|
|
// 组件宽--根据边距计算
|
|
// 组件宽--根据边距计算
|
|
const getComponentWidth = computed(() => {
|
|
const getComponentWidth = computed(() => {
|
|
const { width = 400 } = componentData.container.props || {};
|
|
const { width = 400 } = componentData.container.props || {};
|
|
- const { paddingLeft = 0, paddingRight = 0 } = componentData.container.props || {};
|
|
|
|
|
|
+ const { paddingLeft = 0, paddingRight = 0 } =
|
|
|
|
+ componentData.container.props || {};
|
|
return width - paddingLeft - paddingRight;
|
|
return width - paddingLeft - paddingRight;
|
|
});
|
|
});
|
|
|
|
|
|
// 组件高--根据边距计算
|
|
// 组件高--根据边距计算
|
|
const getComponentHeight = computed(() => {
|
|
const getComponentHeight = computed(() => {
|
|
const { height = 260 } = componentData.container.props || {};
|
|
const { height = 260 } = componentData.container.props || {};
|
|
- const { paddingTop = 0, paddingBottom = 0 } = componentData.container.props || {};
|
|
|
|
|
|
+ const { paddingTop = 0, paddingBottom = 0 } =
|
|
|
|
+ componentData.container.props || {};
|
|
return height - paddingTop - paddingBottom;
|
|
return height - paddingTop - paddingBottom;
|
|
});
|
|
});
|
|
|
|
|
|
@@ -88,7 +101,7 @@ const warpperStyle = computed(() => {
|
|
y,
|
|
y,
|
|
} = componentData.container.props || {};
|
|
} = componentData.container.props || {};
|
|
// const style = transformStyle(componentData.container?.style || {});
|
|
// const style = transformStyle(componentData.container?.style || {});
|
|
-
|
|
|
|
|
|
+
|
|
return {
|
|
return {
|
|
width: `${width}px`,
|
|
width: `${width}px`,
|
|
height: `${height}px`,
|
|
height: `${height}px`,
|
|
@@ -123,22 +136,27 @@ useDraggable(componentWrapperRef, {
|
|
// 计算移动的距离
|
|
// 计算移动的距离
|
|
const xMoveLength = position.x - originPosition.left;
|
|
const xMoveLength = position.x - originPosition.left;
|
|
const yMoveLentgh = position.y - originPosition.top;
|
|
const yMoveLentgh = position.y - originPosition.top;
|
|
- const { x, y } = componentData.container.props || {};
|
|
|
|
|
|
|
|
moveLeft = Math.max(Math.abs(xMoveLength), Math.abs(yMoveLentgh));
|
|
moveLeft = Math.max(Math.abs(xMoveLength), Math.abs(yMoveLentgh));
|
|
- projectStore.updateElement(
|
|
|
|
- componentData.key,
|
|
|
|
- "container.props.x",
|
|
|
|
- Math.round(x + xMoveLength)
|
|
|
|
- );
|
|
|
|
- projectStore.updateElement(
|
|
|
|
- componentData.key,
|
|
|
|
- "container.props.y",
|
|
|
|
- Math.round(y + yMoveLentgh)
|
|
|
|
- );
|
|
|
|
|
|
+ // 对每个选中的组件进行移动
|
|
|
|
+ projectStore.currentSelectedElements.forEach((item) => {
|
|
|
|
+ const { x, y } = item.container.props || {};
|
|
|
|
+ projectStore.updateElement(
|
|
|
|
+ item.key,
|
|
|
|
+ "container.props.x",
|
|
|
|
+ Math.round(x + xMoveLength)
|
|
|
|
+ );
|
|
|
|
+ projectStore.updateElement(
|
|
|
|
+ item.key,
|
|
|
|
+ "container.props.y",
|
|
|
|
+ Math.round(y + yMoveLentgh)
|
|
|
|
+ );
|
|
|
|
+ });
|
|
},
|
|
},
|
|
onStart: () => {
|
|
onStart: () => {
|
|
- projectStore.setSelectedElementKeys([componentData.key]);
|
|
|
|
|
|
+ if (!projectStore.selectedElementKeys.includes(componentData.key)) {
|
|
|
|
+ projectStore.setSelectedElementKeys([componentData.key]);
|
|
|
|
+ }
|
|
showNameTip.value = false;
|
|
showNameTip.value = false;
|
|
moveLeft = 0;
|
|
moveLeft = 0;
|
|
},
|
|
},
|
|
@@ -147,9 +165,6 @@ useDraggable(componentWrapperRef, {
|
|
moveLeft && actionStore.addRecord(); // 记录操作
|
|
moveLeft && actionStore.addRecord(); // 记录操作
|
|
},
|
|
},
|
|
});
|
|
});
|
|
-const handleSelectComponent = () => {
|
|
|
|
- projectStore.setSelectedElementKeys([componentData.key]);
|
|
|
|
-};
|
|
|
|
|
|
|
|
/* ===============================缩放组件==================================== */
|
|
/* ===============================缩放组件==================================== */
|
|
const dragPointList = [
|
|
const dragPointList = [
|
|
@@ -167,63 +182,22 @@ const startPoint = {
|
|
x: 0,
|
|
x: 0,
|
|
y: 0,
|
|
y: 0,
|
|
};
|
|
};
|
|
-// 拖拽点移动
|
|
|
|
|
|
+// 拖拽点移动 => 缩放组件
|
|
const handleDragPoint = (type: string, e: PointerEvent) => {
|
|
const handleDragPoint = (type: string, e: PointerEvent) => {
|
|
const moveX = (e.x - startPoint.x) / stageStore.scale;
|
|
const moveX = (e.x - startPoint.x) / stageStore.scale;
|
|
const moveY = (e.y - startPoint.y) / stageStore.scale;
|
|
const moveY = (e.y - startPoint.y) / stageStore.scale;
|
|
|
|
|
|
- let { x, y, width, height } = componentData.container.props || {};
|
|
|
|
-
|
|
|
|
- switch (type) {
|
|
|
|
- case "top-left":
|
|
|
|
- width -= moveX;
|
|
|
|
- height -= moveY;
|
|
|
|
- x += moveX;
|
|
|
|
- y += moveY;
|
|
|
|
- break;
|
|
|
|
- case "top-center":
|
|
|
|
- height -= moveY;
|
|
|
|
- y += moveY;
|
|
|
|
- break;
|
|
|
|
- case "top-right":
|
|
|
|
- width += moveX;
|
|
|
|
- height -= moveY;
|
|
|
|
- y += moveY;
|
|
|
|
- break;
|
|
|
|
- case "left-center":
|
|
|
|
- width -= moveX;
|
|
|
|
- x += moveX;
|
|
|
|
- break;
|
|
|
|
- case "right-center":
|
|
|
|
- width += moveX;
|
|
|
|
- break;
|
|
|
|
- case "bottom-left":
|
|
|
|
- width -= moveX;
|
|
|
|
- height += moveY;
|
|
|
|
- x += moveX;
|
|
|
|
- break;
|
|
|
|
- case "bottom-center":
|
|
|
|
- height += moveY;
|
|
|
|
- break;
|
|
|
|
- case "bottom-right":
|
|
|
|
- width += moveX;
|
|
|
|
- height += moveY;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
startPoint.x = e.x;
|
|
startPoint.x = e.x;
|
|
startPoint.y = e.y;
|
|
startPoint.y = e.y;
|
|
|
|
|
|
- if (width < 10 || height < 10) return;
|
|
|
|
-
|
|
|
|
- projectStore.updateElement(componentData.key, "container.props.x", Math.round(x));
|
|
|
|
- projectStore.updateElement(componentData.key, "container.props.y", Math.round(y));
|
|
|
|
- projectStore.updateElement(componentData.key, "container.props.width", Math.round(width));
|
|
|
|
- projectStore.updateElement(
|
|
|
|
- componentData.key,
|
|
|
|
- "container.props.height",
|
|
|
|
- Math.round(height)
|
|
|
|
- );
|
|
|
|
|
|
+ // 对选中的组件进行缩放
|
|
|
|
+ scaleAction({
|
|
|
|
+ projectStore,
|
|
|
|
+ type,
|
|
|
|
+ moveX,
|
|
|
|
+ moveY,
|
|
|
|
+ elements: projectStore.currentSelectedElements,
|
|
|
|
+ });
|
|
};
|
|
};
|
|
// 拖拽点开始
|
|
// 拖拽点开始
|
|
const handleDragStart = (_: any, e: PointerEvent) => {
|
|
const handleDragStart = (_: any, e: PointerEvent) => {
|
|
@@ -240,6 +214,12 @@ const handleDragEnd = () => {
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
+<script lang="ts">
|
|
|
|
+export default {
|
|
|
|
+ name: "ComponentWrapper",
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+
|
|
<style lang="less" scoped>
|
|
<style lang="less" scoped>
|
|
.component-wrapper {
|
|
.component-wrapper {
|
|
position: absolute;
|
|
position: absolute;
|