diff --git a/backend/index.js b/backend/index.js new file mode 100644 index 0000000..e9ba123 --- /dev/null +++ b/backend/index.js @@ -0,0 +1,40 @@ +import express from 'express'; +import bodyParser from 'body-parser'; +import cors from 'cors'; +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const app = express(); +const PORT = 3000; + +// 获取当前文件的目录路径 +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +const FILE_PATH = path.join(__dirname, '../src/modules/previewScheme.json'); + +app.use(cors()); +app.use(bodyParser.json()); + +app.post('/save', (req, res) => { + const data = req.body; + try { + fs.writeFileSync(FILE_PATH, JSON.stringify(data, null, 2)); + res.status(200).send('Data saved successfully'); + } catch (error) { + res.status(500).send('Error saving data'); + } +}); + +app.get('/load', (req, res) => { + try { + const data = fs.readFileSync(FILE_PATH, 'utf-8'); + res.status(200).json(JSON.parse(data)); + } catch (error) { + res.status(500).send('Error loading data'); + } +}); + +app.listen(PORT, () => { + console.log(`Server is running on port ${PORT}`); +}); \ No newline at end of file diff --git a/backend/package.json b/backend/package.json new file mode 100644 index 0000000..454fa5e --- /dev/null +++ b/backend/package.json @@ -0,0 +1,20 @@ +{ + "name": "backend", + "version": "1.0.0", + "type": "module", + "main": "dist/index.js", + "scripts": { + "start": "node index.js" + }, + "dependencies": { + "body-parser": "^1.20.3", + "cors": "^2.8.5", + "express": "^4.21.1" + }, + "volta": { + "node": "22.11.0" + }, + "devDependencies": { + "@types/cors": "^2.8.17" + } +} diff --git a/package.json b/package.json index 03dc273..006426e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@arco-plugins/vite-vue": "^1.4.5", "@vueuse/core": "^10.11.0", + "axios": "^1.7.7", "js-sha256": "^0.11.0", "js-yaml": "^4.1.0", "lodash": "^4.17.21", diff --git a/preview/views/MainView.vue b/preview/views/MainView.vue index 0f5f31d..220416a 100644 --- a/preview/views/MainView.vue +++ b/preview/views/MainView.vue @@ -15,7 +15,7 @@ - 保存 + 保存 预览 @@ -49,12 +49,10 @@ @update="onPreviewUpdate" @stop="onPreviewStop" > - {{ component.id }} -
@@ -64,20 +62,19 @@