From 378fb65c765d25c19d42dca22ce11f0398d90647 Mon Sep 17 00:00:00 2001
From: wfz <1040079213@qq.com>
Date: Mon, 22 Dec 2025 23:54:48 +0800
Subject: [PATCH] 3
---
draggable-panels/config.json | 8 ++-
.../fauto/materials/DesignCenter/DropZone.vue | 34 ++---------
.../DesignCenter/InteractiveWrapper.vue | 27 ++++-----
.../src/fauto/materials/PageManager/index.vue | 3 +
.../src/fauto/plugins/dragStore.ts | 58 ++++++++++++++++++-
.../src/fauto/stores/vueFileStore.ts | 48 +++++++++++++++
draggable-panels/vite.config.ts | 31 ++++++++++
draggable-panels/vue-file-selection.json | 4 ++
8 files changed, 166 insertions(+), 47 deletions(-)
create mode 100644 draggable-panels/vue-file-selection.json
diff --git a/draggable-panels/config.json b/draggable-panels/config.json
index baff7fa..41a0905 100644
--- a/draggable-panels/config.json
+++ b/draggable-panels/config.json
@@ -26,6 +26,12 @@
"title": "设计中心",
"content": "新窗口内容",
"materialId": "DesignCenter"
+ },
+ {
+ "id": "m9fv3nb",
+ "title": "测试组件A",
+ "content": "新窗口内容",
+ "materialId": "TestWidget1"
}
],
"activeTabId": "j70ckww"
@@ -141,5 +147,5 @@
"activeTabId": "mxfx11j"
}
},
- "lastUpdated": "2025-12-22T15:06:06.209Z"
+ "lastUpdated": "2025-12-22T15:54:13.388Z"
}
\ No newline at end of file
diff --git a/draggable-panels/src/fauto/materials/DesignCenter/DropZone.vue b/draggable-panels/src/fauto/materials/DesignCenter/DropZone.vue
index 8c7286a..835274b 100644
--- a/draggable-panels/src/fauto/materials/DesignCenter/DropZone.vue
+++ b/draggable-panels/src/fauto/materials/DesignCenter/DropZone.vue
@@ -1,5 +1,5 @@
diff --git a/draggable-panels/src/fauto/materials/PageManager/index.vue b/draggable-panels/src/fauto/materials/PageManager/index.vue
index 62338c4..a30a55f 100644
--- a/draggable-panels/src/fauto/materials/PageManager/index.vue
+++ b/draggable-panels/src/fauto/materials/PageManager/index.vue
@@ -78,6 +78,9 @@ const getNodeIcon = (data: TreeNodeData) => {
}
onMounted(() => {
+ // 初始化Vue文件选择store
+ vueFileStore.initialize()
+ // 扫描文件
scanViewsDirectory()
})
diff --git a/draggable-panels/src/fauto/plugins/dragStore.ts b/draggable-panels/src/fauto/plugins/dragStore.ts
index b1a4947..ff252d9 100644
--- a/draggable-panels/src/fauto/plugins/dragStore.ts
+++ b/draggable-panels/src/fauto/plugins/dragStore.ts
@@ -139,8 +139,64 @@ export const useDragStore = defineStore('drag', () => {
// 按深度从深到浅排序(最深的在前面)
nodes.sort((a, b) => b.depth - a.depth)
+ // 检查层级结构是否改变(比较路径列表)
+ const oldPaths = hierarchyNodes.value.map(n => n.path).join(',')
+ const newPaths = nodes.map(n => n.path).join(',')
+ const hierarchyChanged = oldPaths !== newPaths
+
+ // 记录旧的选择深度和路径
+ const oldSelectedNode = hierarchyNodes.value[selectedHierarchyIndex.value]
+ const oldSelectedDepth = oldSelectedNode?.depth
+ const oldSelectedPath = oldSelectedNode?.path
+
+ // 始终更新层级节点列表
hierarchyNodes.value = nodes
- selectedHierarchyIndex.value = 0 // 默认选中最深层级
+
+ // 如果层级结构改变,尝试保持相同深度或路径的选择
+ if (hierarchyChanged) {
+ // 1. 优先尝试找到相同路径的节点
+ if (oldSelectedPath) {
+ const samePathIndex = nodes.findIndex(n => n.path === oldSelectedPath)
+ if (samePathIndex !== -1) {
+ selectedHierarchyIndex.value = samePathIndex
+ console.log('[DragStore] 保持相同路径选择:', oldSelectedPath)
+ return
+ }
+ }
+
+ // 2. 尝试找到相同深度的节点
+ if (oldSelectedDepth !== undefined) {
+ const sameDepthIndex = nodes.findIndex(n => n.depth === oldSelectedDepth)
+ if (sameDepthIndex !== -1) {
+ selectedHierarchyIndex.value = sameDepthIndex
+ console.log('[DragStore] 保持相同深度选择:', oldSelectedDepth)
+ return
+ }
+ }
+
+ // 3. 找到最接近的深度
+ if (oldSelectedDepth !== undefined && nodes.length > 0) {
+ let closestIndex = 0
+ let minDiff = Math.abs(nodes[0].depth - oldSelectedDepth)
+ for (let i = 1; i < nodes.length; i++) {
+ const diff = Math.abs(nodes[i].depth - oldSelectedDepth)
+ if (diff < minDiff) {
+ minDiff = diff
+ closestIndex = i
+ }
+ }
+ selectedHierarchyIndex.value = closestIndex
+ console.log('[DragStore] 选择最接近深度:', nodes[closestIndex].path)
+ } else {
+ // 4. 默认选中最深层级
+ selectedHierarchyIndex.value = 0
+ console.log('[DragStore] 默认选择最深层级')
+ }
+ } else {
+ // 层级结构未变,保持当前索引(确保不超出范围)
+ selectedHierarchyIndex.value = Math.min(selectedHierarchyIndex.value, nodes.length - 1)
+ console.log('[DragStore] 保持当前选择索引:', selectedHierarchyIndex.value)
+ }
console.log('[DragStore] 更新层级:', nodes.map(n => n.path))
}
diff --git a/draggable-panels/src/fauto/stores/vueFileStore.ts b/draggable-panels/src/fauto/stores/vueFileStore.ts
index 9f9ffc7..ff30086 100644
--- a/draggable-panels/src/fauto/stores/vueFileStore.ts
+++ b/draggable-panels/src/fauto/stores/vueFileStore.ts
@@ -10,6 +10,20 @@ export interface VueFileNode {
}
export const useVueFileStore = defineStore('vueFile', () => {
+ // 从 API 加载上次选中的文件
+ const loadFromApi = async () => {
+ try {
+ const response = await fetch('/api/vue-file-selection')
+ if (response.ok) {
+ const data = await response.json()
+ return data
+ }
+ } catch (error) {
+ console.error('加载Vue文件选择失败:', error)
+ }
+ return { path: null, name: null }
+ }
+
// 当前选中的Vue文件路径
const selectedFilePath = ref(null)
@@ -19,10 +33,26 @@ export const useVueFileStore = defineStore('vueFile', () => {
// 文件树结构
const fileTree = ref([])
+ // 是否已加载
+ const isLoaded = ref(false)
+
+ // 初始化加载
+ const initialize = async () => {
+ const stored = await loadFromApi()
+ selectedFilePath.value = stored.path
+ selectedFileName.value = stored.name
+ isLoaded.value = true
+ console.log('初始化Vue文件选择:', stored)
+ }
+
// 设置选中的文件
const selectFile = (path: string, name: string) => {
selectedFilePath.value = path
selectedFileName.value = name
+
+ // 保存到 API
+ saveToApi({ path, name })
+
console.log('选中文件:', { path, name })
}
@@ -30,6 +60,22 @@ export const useVueFileStore = defineStore('vueFile', () => {
const clearSelection = () => {
selectedFilePath.value = null
selectedFileName.value = null
+
+ // 清除 API 数据
+ saveToApi({ path: null, name: null })
+ }
+
+ // 保存到 API
+ const saveToApi = async (data: { path: string | null, name: string | null }) => {
+ try {
+ await fetch('/api/vue-file-selection', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(data)
+ })
+ } catch (error) {
+ console.error('保存Vue文件选择失败:', error)
+ }
}
// 构建文件树(从import.meta.glob结果)
@@ -103,6 +149,8 @@ export const useVueFileStore = defineStore('vueFile', () => {
selectedFilePath,
selectedFileName,
fileTree,
+ isLoaded,
+ initialize,
selectFile,
clearSelection,
buildFileTree
diff --git a/draggable-panels/vite.config.ts b/draggable-panels/vite.config.ts
index 4442870..4e9f1eb 100644
--- a/draggable-panels/vite.config.ts
+++ b/draggable-panels/vite.config.ts
@@ -8,6 +8,7 @@ import type { Plugin } from 'vite'
const CONFIG_FILE = path.resolve(__dirname, 'config.json')
const DESIGN_STATE_FILE = path.resolve(__dirname, 'design-state.json')
const MATERIAL_STATES_FILE = path.resolve(__dirname, 'material-states.json')
+const VUE_FILE_SELECTION_FILE = path.resolve(__dirname, 'vue-file-selection.json')
const DESIGN_COMPONENTS_DIR = path.resolve(__dirname, 'src/designComponents')
// 通用JSON文件读写处理器
@@ -52,6 +53,7 @@ function configApiPlugin(): Plugin {
const configHandler = createJsonHandler(CONFIG_FILE)
const designStateHandler = createJsonHandler(DESIGN_STATE_FILE)
const materialStatesHandler = createJsonHandler(MATERIAL_STATES_FILE)
+ const vueFileSelectionHandler = createJsonHandler(VUE_FILE_SELECTION_FILE)
return {
name: 'config-api',
@@ -158,6 +160,35 @@ function configApiPlugin(): Plugin {
next()
}
})
+
+ // Vue文件选择状态 API
+ server.middlewares.use('/api/vue-file-selection', (req, res, next) => {
+ if (req.method === 'GET') {
+ try {
+ res.setHeader('Content-Type', 'application/json')
+ res.end(vueFileSelectionHandler.read())
+ } catch (error) {
+ res.statusCode = 500
+ res.end(JSON.stringify({ error: 'Failed to read vue file selection' }))
+ }
+ } else if (req.method === 'POST') {
+ let body = ''
+ req.on('data', (chunk) => body += chunk.toString())
+ req.on('end', () => {
+ try {
+ const selection = JSON.parse(body)
+ vueFileSelectionHandler.write(JSON.stringify(selection, null, 2))
+ res.setHeader('Content-Type', 'application/json')
+ res.end(JSON.stringify({ success: true }))
+ } catch (error) {
+ res.statusCode = 500
+ res.end(JSON.stringify({ error: 'Failed to save vue file selection' }))
+ }
+ })
+ } else {
+ next()
+ }
+ })
}
}
}
diff --git a/draggable-panels/vue-file-selection.json b/draggable-panels/vue-file-selection.json
new file mode 100644
index 0000000..a653aba
--- /dev/null
+++ b/draggable-panels/vue-file-selection.json
@@ -0,0 +1,4 @@
+{
+ "path": "../../../views/TestPage1.vue",
+ "name": "TestPage1.vue"
+}
\ No newline at end of file