|
|
@@ -1,9 +1,9 @@
|
|
|
<template>
|
|
|
- <el-tabs v-model="activeMenu" stretch>
|
|
|
+ <el-tabs v-model="activeMenu" stretch class="w-full h-full">
|
|
|
<el-tab-pane label="屏幕" name="screen" class="flex-1">
|
|
|
<!-- 屏幕层 -->
|
|
|
<el-tree
|
|
|
- ref="treeRef"
|
|
|
+ ref="screenTreeRef"
|
|
|
style="max-width: 600px"
|
|
|
default-expand-all
|
|
|
node-key="id"
|
|
|
@@ -16,34 +16,67 @@
|
|
|
</template>
|
|
|
</el-tree>
|
|
|
</el-tab-pane>
|
|
|
- <el-tab-pane label="页面" name="page">
|
|
|
+ <el-tab-pane label="页面" name="page" class="w-full h-full">
|
|
|
<!-- 页面层 -->
|
|
|
- <el-tree
|
|
|
- ref="treeRef"
|
|
|
- style="max-width: 600px"
|
|
|
- default-expand-all
|
|
|
- node-key="id"
|
|
|
- :highlight-current="false"
|
|
|
- :data="projectStore.activePage ? [projectStore.activePage] : []"
|
|
|
- :props="{ label: 'name', children: 'children' }"
|
|
|
- @node-click="handleWidgetNodeClick"
|
|
|
- >
|
|
|
- <template #default="{ node, data }">
|
|
|
- <PageTreeItem :node="node" :data="data" />
|
|
|
- </template>
|
|
|
- </el-tree>
|
|
|
+ <div class="h-full overflow-hidden" ref="pageBoxRef">
|
|
|
+ <el-tree-v2
|
|
|
+ ref="pageTreeRef"
|
|
|
+ style="max-width: 600px"
|
|
|
+ default-expand-all
|
|
|
+ node-key="id"
|
|
|
+ :height="height || 100"
|
|
|
+ :highlight-current="false"
|
|
|
+ :default-expanded-keys="projectStore.activePageId ? [projectStore.activePageId] : []"
|
|
|
+ :data="projectStore.activePage ? [projectStore.activePage] : []"
|
|
|
+ :props="{ label: 'name', children: 'children' }"
|
|
|
+ @node-click="handleWidgetNodeClick"
|
|
|
+ >
|
|
|
+ <template #default="{ node, data }">
|
|
|
+ <PageTreeItem :node="node" :data="data" />
|
|
|
+ </template>
|
|
|
+ </el-tree-v2>
|
|
|
+ </div>
|
|
|
</el-tab-pane>
|
|
|
</el-tabs>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
+import { ref, watch } from 'vue'
|
|
|
+
|
|
|
import ScreenTreeItem from './components/ScreenTreeItem.vue'
|
|
|
import PageTreeItem from './components/PageTreeItem.vue'
|
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
|
-import { ref } from 'vue'
|
|
|
+import { useElementSize } from '@vueuse/core'
|
|
|
+
|
|
|
+import type { TreeV2Instance } from 'element-plus'
|
|
|
|
|
|
const projectStore = useProjectStore()
|
|
|
const activeMenu = ref<string>('screen')
|
|
|
+const pageTreeRef = ref<TreeV2Instance>()
|
|
|
+const pageBoxRef = ref<HTMLDivElement>()
|
|
|
+
|
|
|
+const { height } = useElementSize(pageBoxRef, {
|
|
|
+ height: 100,
|
|
|
+ width: 100
|
|
|
+})
|
|
|
+
|
|
|
+// 更新控件树
|
|
|
+watch(
|
|
|
+ () => projectStore.activePage?.children,
|
|
|
+ (arr) => {
|
|
|
+ if (arr) pageTreeRef.value?.setData([projectStore.activePage!])
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deep: true
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => projectStore.activeWidgets,
|
|
|
+ (arr) => {
|
|
|
+ if (arr.length) pageTreeRef.value?.scrollToNode(arr[0].id)
|
|
|
+ }
|
|
|
+)
|
|
|
|
|
|
const handlePageNodeClick = (node: any) => {
|
|
|
if (node.type === 'page') {
|
|
|
@@ -59,7 +92,7 @@ const handlePageNodeClick = (node: any) => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-const handleWidgetNodeClick = (nodeData, _node, _a, e) => {
|
|
|
+const handleWidgetNodeClick = (nodeData, _node, e) => {
|
|
|
if (nodeData.type !== 'page') {
|
|
|
if (e.ctrlKey) {
|
|
|
projectStore.activeWidgets.push(nodeData)
|