This commit is contained in:
wfz
2025-12-22 23:54:48 +08:00
parent 9829b91321
commit 378fb65c76
8 changed files with 166 additions and 47 deletions

View File

@@ -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()
}
})
}
}
}