3
This commit is contained in:
@@ -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()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user