|
@@ -11,20 +11,17 @@
|
|
|
>
|
|
>
|
|
|
<!-- 控件 -->
|
|
<!-- 控件 -->
|
|
|
<component
|
|
<component
|
|
|
- v-bind="schema.props"
|
|
|
|
|
|
|
+ v-bind="widgetProps"
|
|
|
:is="widget"
|
|
:is="widget"
|
|
|
- :part="schema?.part"
|
|
|
|
|
- :state="schema?.state"
|
|
|
|
|
- :styles="schema.style"
|
|
|
|
|
style="width: 100%; height: 100%"
|
|
style="width: 100%; height: 100%"
|
|
|
:style="{ 'pointer-events': schema.type === 'page' ? 'none' : '' }"
|
|
:style="{ 'pointer-events': schema.type === 'page' ? 'none' : '' }"
|
|
|
/>
|
|
/>
|
|
|
<!-- 子节点 -->
|
|
<!-- 子节点 -->
|
|
|
<NodeItem
|
|
<NodeItem
|
|
|
v-if="schema.children"
|
|
v-if="schema.children"
|
|
|
- v-for="(child, index) in schema.children"
|
|
|
|
|
|
|
+ v-for="(child, index) in children"
|
|
|
:key="child.id"
|
|
:key="child.id"
|
|
|
- :zIndex="schema.children.length - index"
|
|
|
|
|
|
|
+ :zIndex="schema.children.length - Number(index)"
|
|
|
:schema="child"
|
|
:schema="child"
|
|
|
:rootContainer="nodeRef!"
|
|
:rootContainer="nodeRef!"
|
|
|
/>
|
|
/>
|
|
@@ -48,6 +45,7 @@ import { useDrop } from 'vue-hooks-plus'
|
|
|
import { createWidget } from '@/model'
|
|
import { createWidget } from '@/model'
|
|
|
import LvglWidgets from '@/lvgl-widgets'
|
|
import LvglWidgets from '@/lvgl-widgets'
|
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
|
|
|
+import { has } from 'lodash-es'
|
|
|
|
|
|
|
|
import ContentMenu from './ContentMenu.vue'
|
|
import ContentMenu from './ContentMenu.vue'
|
|
|
import { getAddWidgetIndex } from '@/utils'
|
|
import { getAddWidgetIndex } from '@/utils'
|
|
@@ -81,6 +79,30 @@ const zIndex = ref(props.zIndex)
|
|
|
// 放置效果样式
|
|
// 放置效果样式
|
|
|
const dropStyle = ref<CSSProperties>({})
|
|
const dropStyle = ref<CSSProperties>({})
|
|
|
|
|
|
|
|
|
|
+// 子节点
|
|
|
|
|
+// 默认为子节点 当子节点为可切换容器时 根据activeIndex展示下一级节点
|
|
|
|
|
+const children = computed(() => {
|
|
|
|
|
+ const { schema } = props
|
|
|
|
|
+
|
|
|
|
|
+ return has(schema.props, 'activeIndex')
|
|
|
|
|
+ ? schema.children?.[schema.props.activeIndex]?.children || []
|
|
|
|
|
+ : schema.children
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+// 控件属性
|
|
|
|
|
+const widgetProps = computed(() => {
|
|
|
|
|
+ const { schema } = props
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...(schema?.props || {}),
|
|
|
|
|
+ part: schema?.part,
|
|
|
|
|
+ state: schema?.state,
|
|
|
|
|
+ styles: schema?.style,
|
|
|
|
|
+ // 处理可切换子节点容器属性
|
|
|
|
|
+ ...(has(schema.props, 'activeIndex') && schema.children ? { children: schema.children } : {})
|
|
|
|
|
+ }
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
// 组件样式
|
|
// 组件样式
|
|
|
const getStyle = computed((): CSSProperties => {
|
|
const getStyle = computed((): CSSProperties => {
|
|
|
const { style = {}, schema } = props
|
|
const { style = {}, schema } = props
|
|
@@ -119,17 +141,26 @@ const getStyle = computed((): CSSProperties => {
|
|
|
useDrop(nodeRef, {
|
|
useDrop(nodeRef, {
|
|
|
// 元素放置
|
|
// 元素放置
|
|
|
onDom: (content, event) => {
|
|
onDom: (content, event) => {
|
|
|
|
|
+ const { schema } = props
|
|
|
|
|
+
|
|
|
dropStyle.value = {}
|
|
dropStyle.value = {}
|
|
|
event?.stopPropagation()
|
|
event?.stopPropagation()
|
|
|
- if (!content) return
|
|
|
|
|
|
|
+ if (!content || !schema?.children) return
|
|
|
|
|
+
|
|
|
// 创建控件
|
|
// 创建控件
|
|
|
const { offsetX = 0, offsetY = 0 } = event || {}
|
|
const { offsetX = 0, offsetY = 0 } = event || {}
|
|
|
const index = getAddWidgetIndex(page!, content.key)
|
|
const index = getAddWidgetIndex(page!, content.key)
|
|
|
const newWidget = createWidget(content, index)
|
|
const newWidget = createWidget(content, index)
|
|
|
newWidget.props.x = offsetX
|
|
newWidget.props.x = offsetX
|
|
|
newWidget.props.y = offsetY
|
|
newWidget.props.y = offsetY
|
|
|
|
|
+
|
|
|
// 添加到前面
|
|
// 添加到前面
|
|
|
- props.schema.children?.unshift(newWidget)
|
|
|
|
|
|
|
+ if (has(schema.props, 'activeIndex')) {
|
|
|
|
|
+ schema.children[schema.props.activeIndex].children?.unshift(newWidget)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ schema.children?.unshift(newWidget)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
projectStore.setSelectWidgets([newWidget])
|
|
projectStore.setSelectWidgets([newWidget])
|
|
|
},
|
|
},
|
|
|
onDragOver: () => {
|
|
onDragOver: () => {
|