From 32a7696b6656fa1f01aee475f0aed6e86f3066ad Mon Sep 17 00:00:00 2001 From: sunlizhou <296190577@qq.com> Date: Fri, 1 Dec 2023 17:36:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=9C=E8=89=B2=E9=85=8D=E7=BD=AE=E8=A1=A8?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 16 +-- src/engineer/components/Canvas.vue | 3 +- src/engineer/components/switch.vue | 124 ++++++++++++++++++++++ src/engineer/configs/BackgroundConfig.vue | 110 +++++++++++-------- src/engineer/configs/BaseConfig.vue | 19 ++++ src/engineer/configs/BooleanConfig.vue | 18 ++-- src/engineer/configs/ColorConfig.vue | 21 ++++ src/engineer/configs/ImageConfig.vue | 69 ++++++++++++ src/engineer/configs/ListConfig.vue | 23 ++-- src/engineer/configs/MarkConfig.vue | 47 +++++--- src/engineer/configs/ObjectConfig.vue | 9 +- src/engineer/configs/render.ts | 6 +- src/engineer/utils/clone.ts | 27 +++++ src/engineer/utils/index.ts | 1 + 14 files changed, 404 insertions(+), 89 deletions(-) create mode 100644 src/engineer/components/switch.vue create mode 100644 src/engineer/configs/ColorConfig.vue create mode 100644 src/engineer/utils/clone.ts diff --git a/src/App.vue b/src/App.vue index b58a4de..e70d3df 100644 --- a/src/App.vue +++ b/src/App.vue @@ -143,12 +143,14 @@ categories.value.unshift({ { type: 'list', field: 'items', - label: '', + label: '轮播图设置', help: '最多可添加10张图片,建议宽度750px;鼠标拖拽左侧圆点可调整图片顺序', addable: true, configs: [{ type: 'image', field: 'image', + label: '图片', + required: true, // 表示内联数据 inlines: [{ type: 'text', @@ -159,10 +161,8 @@ categories.value.unshift({ type: 'text', field: 'link', label: '链接', - // help: '请输入链接', // 自动生成:"请输入${label}" + help: '请输入链接', // 自动生成:"请输入${label}" }], - label: '图片', - required: true, }], }, { @@ -207,14 +207,18 @@ categories.value.unshift({ items: [ { image: '', - // title: '', - // link: '', + title: '123', + link: '123', } ], indicator: { style: 'circle', color: '#000000', position: 'left', + }, + background: { + enabled: true, + value: "#ffffff", } }, theme: { diff --git a/src/engineer/components/Canvas.vue b/src/engineer/components/Canvas.vue index 3973a67..68685ca 100644 --- a/src/engineer/components/Canvas.vue +++ b/src/engineer/components/Canvas.vue @@ -2,6 +2,7 @@ import { computed, ref } from 'vue' import Draggable from 'vuedraggable' import { useContext, getModule } from '../context' +import { clone } from '../utils' import { RenderBlock } from '../render' import { DddView } from '../views' @@ -73,7 +74,7 @@ function handleDragAdd(e: DraggableEvent): void { ctx.activeBlockId = block.vid ctx.hoverViewId = '#canvas' ctx.configurator = 'block' - ctx.sources[block.vid] = module.init ?? {} + ctx.sources[block.vid] = module?.init ? clone(module.init) : {} key.value++ } diff --git a/src/engineer/components/switch.vue b/src/engineer/components/switch.vue new file mode 100644 index 0000000..2d9742b --- /dev/null +++ b/src/engineer/components/switch.vue @@ -0,0 +1,124 @@ + + + + + + diff --git a/src/engineer/configs/BackgroundConfig.vue b/src/engineer/configs/BackgroundConfig.vue index cda414c..e9d13bd 100644 --- a/src/engineer/configs/BackgroundConfig.vue +++ b/src/engineer/configs/BackgroundConfig.vue @@ -1,62 +1,86 @@ diff --git a/src/engineer/configs/BaseConfig.vue b/src/engineer/configs/BaseConfig.vue index e69de29..a9924bc 100644 --- a/src/engineer/configs/BaseConfig.vue +++ b/src/engineer/configs/BaseConfig.vue @@ -0,0 +1,19 @@ + + diff --git a/src/engineer/configs/BooleanConfig.vue b/src/engineer/configs/BooleanConfig.vue index 27e439c..d168c0c 100644 --- a/src/engineer/configs/BooleanConfig.vue +++ b/src/engineer/configs/BooleanConfig.vue @@ -1,5 +1,7 @@ diff --git a/src/engineer/configs/ColorConfig.vue b/src/engineer/configs/ColorConfig.vue new file mode 100644 index 0000000..1c6e8d4 --- /dev/null +++ b/src/engineer/configs/ColorConfig.vue @@ -0,0 +1,21 @@ + + + diff --git a/src/engineer/configs/ImageConfig.vue b/src/engineer/configs/ImageConfig.vue index e69de29..fe65cdd 100644 --- a/src/engineer/configs/ImageConfig.vue +++ b/src/engineer/configs/ImageConfig.vue @@ -0,0 +1,69 @@ + + + + + diff --git a/src/engineer/configs/ListConfig.vue b/src/engineer/configs/ListConfig.vue index 052fe4b..aced9b5 100644 --- a/src/engineer/configs/ListConfig.vue +++ b/src/engineer/configs/ListConfig.vue @@ -35,18 +35,19 @@ const add = () => { diff --git a/src/engineer/configs/MarkConfig.vue b/src/engineer/configs/MarkConfig.vue index 2514b70..2b063a0 100644 --- a/src/engineer/configs/MarkConfig.vue +++ b/src/engineer/configs/MarkConfig.vue @@ -14,21 +14,44 @@ const props = defineProps<{ const tempString = useSource(props.field) -function selectChange(e: any){ - console.log(e.target.value) -} + + diff --git a/src/engineer/configs/ObjectConfig.vue b/src/engineer/configs/ObjectConfig.vue index c569c03..bbf3b7a 100644 --- a/src/engineer/configs/ObjectConfig.vue +++ b/src/engineer/configs/ObjectConfig.vue @@ -1,6 +1,5 @@ diff --git a/src/engineer/configs/render.ts b/src/engineer/configs/render.ts index b42ac23..9610841 100644 --- a/src/engineer/configs/render.ts +++ b/src/engineer/configs/render.ts @@ -6,6 +6,8 @@ import ObjectConfig from './ObjectConfig.vue' import MarkConfig from "./MarkConfig.vue"; import BooleanConfig from "./BooleanConfig.vue" import BackgroundConfig from "./BackgroundConfig.vue"; +import ImageConfig from "./ImageConfig.vue"; +import ColorConfig from './ColorConfig.vue' const configs: Record = { text: TextConfig, @@ -13,7 +15,9 @@ const configs: Record = { object: ObjectConfig, mark: MarkConfig, boolean: BooleanConfig, - background:BackgroundConfig, + background: BackgroundConfig, + image: ImageConfig, + color: ColorConfig, } function render(type: string, props: Record) { diff --git a/src/engineer/utils/clone.ts b/src/engineer/utils/clone.ts new file mode 100644 index 0000000..d18e581 --- /dev/null +++ b/src/engineer/utils/clone.ts @@ -0,0 +1,27 @@ +import { error } from "console" + +export function clone(v: T): T { + switch (typeof v) { + case "string": + case "boolean": + case "number": + case "undefined": + return v + case "symbol": + case "function": + case "bigint": + throw new Error("invalid type") + case "object": + if (v == null) { + return v + } + if (Array.isArray(v)) { + return v.map(clone) as T + } + const obj = Object.create(null) + for (const [key, value] of Object.entries(v)) { + obj[key] = clone(value) + } + return obj + } +} diff --git a/src/engineer/utils/index.ts b/src/engineer/utils/index.ts index 4d18ef1..d54e190 100644 --- a/src/engineer/utils/index.ts +++ b/src/engineer/utils/index.ts @@ -1,6 +1,7 @@ export * from './align' export * from './background' export * from './border' +export * from './clone' export * from './clip' export * from './gap' export * from './hash'