feat: 完成梦象虚拟电厂集中门户基础框架搭建

新增登录页、布局、路由、Pinia状态管理、Mock数据等核心模块,配置环境变量、Vite、ESLint、Prettier、CommitLint等开发工具,添加品牌资源与全局样式。
This commit is contained in:
zhangzhenbing committed 2026-11-12 17:00:48 +08:00
commit 9ddecbdb9a
42 files changed
+10448

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
# 基础环境变量
VITE_APP_TITLE=梦象虚拟电厂集中门户
VITE_PORT=3000
VITE_HOST=0.0.0.0
VITE_API_BASE_URL=/api
VITE_API_TARGET=http://localhost:8080
+4
View File
@@ -0,0 +1,4 @@
# 开发环境
VITE_APP_ENV=development
VITE_API_BASE_URL=/api
VITE_API_TARGET=http://localhost:8080
+4
View File
@@ -0,0 +1,4 @@
# 生产环境
VITE_APP_ENV=production
VITE_API_BASE_URL=/api
VITE_API_TARGET=https://api.manabox.cn
+4
View File
@@ -0,0 +1,4 @@
# 测试环境
VITE_APP_ENV=test
VITE_API_BASE_URL=/api
VITE_API_TARGET=https://test-api.manabox.cn
+64
View File
@@ -0,0 +1,64 @@
/* eslint-env node */
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
node: true,
},
extends: ["eslint:recommended", "plugin:vue/vue3-recommended", "@vue/eslint-config-prettier"],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
ignorePatterns: ["dist/", "node_modules/"],
rules: {
// ===== 错误预防(主流团队级标配防错规则) =====
eqeqeq: ["error", "always", { null: "ignore" }],
"no-var": "error",
"prefer-const": "error",
"no-shadow": ["error", { hoist: "never" }],
"no-throw-literal": "error",
"no-unused-expressions": ["error", { allowShortCircuit: true, allowTernary: true }],
"no-param-reassign": [
"error",
{
props: true,
ignorePropertyModificationsFor: [
"config",
"state",
"acc",
"e",
"ctx",
"req",
"res",
"options",
"opts",
"draft",
"el",
"vm",
],
},
],
"require-await": "error",
"no-return-await": "error",
"no-template-curly-in-string": "warn",
"default-case": "error",
"no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }],
"no-console": "warn",
"no-debugger": "warn",
// ===== 复杂度治理(中大型团队协作约束) =====
complexity: ["warn", 15],
"max-depth": ["warn", 4],
"max-params": ["warn", 4],
"max-lines-per-function": ["warn", { max: 200, skipBlankLines: true, skipComments: true }],
// ===== 代码风格(统一交给 Prettier,冲突规则已关闭) =====
"prettier/prettier": "error",
// ===== Vue 专项 =====
"vue/multi-word-component-names": "off",
"vue/no-v-html": "warn",
},
};
+36
View File
@@ -0,0 +1,36 @@
# 依赖
node_modules/
# 构建产物
dist/
dist-ssr/
# 编辑器
.vscode/*
!.vscode/extensions.json
!.vscode/settings.json
.idea/
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# 系统文件
.DS_Store
Thumbs.db
# 环境变量(本地覆盖)
.env.local
.env.*.local
# 自动生成文件
src/auto-imports.d.ts
src/components.d.ts
# 日志
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
+2
View File
@@ -0,0 +1,2 @@
# 提交信息校验:不符合 commitlint 规范的提交将被拦截
npx --no -- commitlint --edit "$1"
+2
View File
@@ -0,0 +1,2 @@
# 提交前自动校验暂存区文件:ESLint 修复 + Prettier 格式化
npx lint-staged
+11
View File
@@ -0,0 +1,11 @@
{
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 100,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "auto",
"vueIndentScriptAndStyle": false
}
Binary file not shown.
+32
View File
@@ -0,0 +1,32 @@
---
alwaysApply: true
---
# ESLint 代码规范(编写与修改代码时必须遵守)
项目使用 ESLint + Prettier 强制校验,配置文件为根目录 `.eslintrc.cjs`(基线:eslint:recommended + plugin:vue/vue3-recommended + eslint-config-prettier)。生成或修改任何代码时必须满足以下规则。
## 必须遵守的编码规则
- 变量声明默认用 `const`,仅需要重新赋值时用 `let`,禁止使用 `var`
- 相等比较必须使用 `===` / `!==`,仅与 `null` 比较时允许 `==`
- 禁止遮蔽外层作用域的同名变量(no-shadow)
- `throw` 只能抛出 `Error` 对象,禁止抛出字符串等字面量
- 禁止对函数参数重新赋值或修改其属性(`config`、`state`、`options` 等在白名单中的除外)
- 声明为 `async` 的函数体内必须包含 `await`;禁止 `return await`(直接 `return` Promise)
- 不允许出现未使用的变量/参数,必须使用的占位参数以 `_` 开头
- 函数圈复杂度 ≤ 15、嵌套深度 ≤ 4、参数个数 ≤ 4、单函数 ≤ 200 行
- 禁止在代码中残留 `console` / `debugger`
- Vue 单文件组件遵守 vue3-recommended:属性按顺序书写(v-for/v-if 在前,绑定属性次之)、props 必须定义类型、模板禁止使用 `v-html`(确需使用时必须说明已做 XSS 转义处理)
- 组件文件名遵循目录约定:views 下为 `index.vue`,公共组件用多词 PascalCase 命名
## 格式要求
- 代码格式统一由 Prettier 保证:2 空格缩进、双引号、行尾分号、尾逗号、单行最大 100 字符
- 不要手工调整纯格式内容,保存时由编辑器自动执行 `source.fixAll.eslint` 修复
## 执行要求
- 每次完成代码修改后,必须运行 `npm run lint:check` 验证,确保 0 error、0 warning 后才算完成
- 若 lint 报错,优先修改代码本身,禁止通过关闭规则来消除报错;确需禁用某条规则时,必须用 `// eslint-disable-next-line <规则名> -- 原因` 行内注释并说明理由
- git 提交时 `.husky/pre-commit` 会自动执行 lint-staged 校验暂存文件,校验不通过则提交失败,此时必须先修复问题再重新提交
+89
View File
@@ -0,0 +1,89 @@
---
alwaysApply: true
scene: git_message
---
# Git 提交信息规则
> 完整规范见 docs/git-commit-convention.md,生成提交信息时必须遵守以下规则。
## 提交信息格式
```
<type>(<scope>): <subject>
[body]
[footer]
```
## 提交类型(type,必填,小写)
| 类型 | 适用场景 |
| -------- | ---------------------------------------- |
| feat | 新增页面、组件、接口、业务功能 |
| fix | 修复缺陷或逻辑错误 |
| docs | 仅修改文档、注释 |
| style | 不影响逻辑的格式调整(空格、缩进、分号) |
| refactor | 既非修复也非新增的代码调整 |
| perf | 性能优化 |
| test | 测试用例新增或修正 |
| chore | 构建、依赖、配置等辅助变更 |
| ci | 持续集成配置变更 |
| revert | 回滚提交 |
| build | 构建系统或外部依赖变更 |
## 作用域(scope,选填)
- 使用受影响的模块或目录名:`login`、`portal`、`systems`、`utils`、`router`、`store`、`api`、`styles`
- 无明确模块边界时省略
## 主题描述(subject,必填)
- 长度不超过 72 字符
- 统一使用中文,动词开头,祈使句语气,不加主语
- 不加句号,不使用过去式(不写"修改了""更新了")
- 英文部分首字母小写
- 推荐动词:新增、修复、调整、移除、重构、优化、补充、升级、适配
## 正文与脚注(选填)
- body 说明"做了什么"和"为什么",每行不超过 100 字符,与 subject 之间空一行
- footer 用于关联编号:`Closes #256`、`Refs REQ-042`;不兼容变更使用 `BREAKING CHANGE:` 开头说明
## 分支命名
| 分支 | 格式 | 示例 |
| ------ | ---------------------- | ------------------------- |
| 功能 | feature/<模块>-<简述> | feature/login-remember |
| 修复 | fix/<模块>-<简述> | fix/portal-shortcut |
| 发布 | release/<版本号> | release/1.0.0 |
| 热修复 | hotfix/<版本号>-<简述> | hotfix/1.0.1-token-expire |
## 禁止事项
- 禁止提交:密码、Token、密钥、.env.local、dist/、node_modules/、.idea/、日志及临时文件
- 禁止使用 update、修改代码、asdf 等无意义描述
- 禁止单次提交超过 15 个文件的混合变更
## 正确示例
```
feat(login): 新增记住账号功能
登录成功后将用户名写入 localStorage,下次打开页面自动填充。
Closes #42
```
```
fix(portal): 修复快捷入口点击无响应的问题
```
## 错误示例(禁止)
```
update ← 缺少 type,含义模糊
Feat: 新增了登录页功能 ← type 大写、用了"了"、含句号
修改了一些样式 ← 缺少 type/scope,描述模糊
```
+3
View File
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "Vue.volar"]
}
+9
View File
@@ -0,0 +1,9 @@
{
"eslint.enable": true,
"eslint.useFlatConfig": false,
"eslint.validate": ["javascript", "vue"],
"eslint.workingDirectories": [{ "mode": "auto" }],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
}
+56
View File
@@ -0,0 +1,56 @@
/* eslint-env node */
// 提交信息校验规则,与 .trae/rules/git-commit-message.md 保持一致
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
// 提交类型白名单(必填、小写)
"type-enum": [
2,
"always",
[
"feat",
"fix",
"docs",
"style",
"refactor",
"perf",
"test",
"chore",
"ci",
"revert",
"build",
],
],
"type-empty": [2, "never"],
"subject-empty": [2, "never"],
// 主题描述统一中文,关闭大小写类检查
"subject-case": [0],
"scope-case": [0],
// 标题(type(scope): subject 整体)不超过 100 字符,正文每行不超过 100 字符
"header-max-length": [2, "always", 100],
"body-max-line-length": [2, "always", 100],
"body-leading-blank": [2, "always"],
"footer-leading-blank": [2, "always"],
// 主题不以句号结尾(中文句号"。"由 .trae/rules/git-commit-message.md 约束)
"subject-full-stop": [2, "never", "."],
// scope 建议使用项目既有模块名(仅提示,不阻断提交)
"scope-enum": [
1,
"always",
[
"login",
"portal",
"systems",
"utils",
"router",
"store",
"api",
"styles",
"layout",
"components",
"deps",
"project",
],
],
},
};
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>梦象虚拟电厂集中门户</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
+6052
View File
File diff suppressed because it is too large. Load diff
+49
View File
@@ -0,0 +1,49 @@
{
"name": "mengxiang-vpp-portal-web",
"private": true,
"version": "1.0.0",
"type": "module",
"description": "梦象虚拟电厂集中门户 - 多系统链接统一管理平台",
"author": "上海梦象智能科技有限公司",
"scripts": {
"dev": "vite",
"build": "vite build",
"build:test": "vite build --mode test",
"preview": "vite preview",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix",
"lint:check": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --max-warnings 0",
"format": "prettier --write \"src/**/*.{vue,js,jsx,css,scss,json}\"",
"prepare": "husky"
},
"lint-staged": {
"*.{vue,js,jsx,cjs,mjs}": [
"eslint --fix"
],
"*.{json,css,scss,md,html}": [
"prettier --write"
]
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"axios": "^1.6.8",
"element-plus": "^2.6.3",
"pinia": "^2.1.7",
"vue": "^3.4.21",
"vue-router": "^4.3.0"
},
"devDependencies": {
"@commitlint/cli": "^19.8.1",
"@commitlint/config-conventional": "^19.8.1",
"@vitejs/plugin-vue": "^5.0.4",
"@vue/eslint-config-prettier": "^9.0.0",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.24.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"sass": "^1.72.0",
"unplugin-auto-import": "^0.17.5",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.2.8"
}
}
+121
View File
@@ -0,0 +1,121 @@
<template>
<!-- 全局 SVG 图标库:迁移自原型项目 index.html,供各页面 <use href="#i-xxx"> 引用 -->
<svg class="svg-library" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<symbol id="i-user" viewBox="0 0 24 24">
<path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" />
<circle cx="12" cy="7" r="4" />
</symbol>
<symbol id="i-lock" viewBox="0 0 24 24">
<rect width="16" height="12" x="4" y="10" rx="2" />
<path d="M8 10V6a4 4 0 0 1 8 0v4" />
</symbol>
<symbol id="i-eye" viewBox="0 0 24 24">
<path
d="M2.06 12.35a1 1 0 0 1 0-.7C3.73 7.6 7.7 5 12 5c4.3 0 8.27 2.6 9.94 6.65a1 1 0 0 1 0 .7C20.27 16.4 16.3 19 12 19c-4.3 0-8.27-2.6-9.94-6.65Z"
/>
<circle cx="12" cy="12" r="3" />
</symbol>
<symbol id="i-eye-off" viewBox="0 0 24 24">
<path d="m2 2 20 20" />
<path
d="M6.71 6.71C4.95 7.96 3.62 9.76 2.06 11.65a1 1 0 0 0 0 .7C3.73 16.4 7.7 19 12 19c1.57 0 3.07-.3 4.43-.83"
/>
<path
d="M10.73 5.08C11.14 5.03 11.56 5 12 5c4.3 0 8.27 2.6 9.94 6.65a1 1 0 0 1 0 .7c-.56 1.08-1.24 2.09-2.02 3.01"
/>
<path d="M14.12 14.12a3 3 0 0 1-4.24-4.24" />
</symbol>
<symbol id="i-arrow-right" viewBox="0 0 24 24">
<path d="M5 12h14" />
<path d="m13 6 6 6-6 6" />
</symbol>
<symbol id="i-arrow-left" viewBox="0 0 24 24">
<path d="M19 12H5" />
<path d="m11 18-6-6 6-6" />
</symbol>
<symbol id="i-shield-check" viewBox="0 0 24 24">
<path d="M20 13c0 5-3.5 7.5-8 9-4.5-1.5-8-4-8-9V5l8-3 8 3v8Z" />
<path d="m9 12 2 2 4-4" />
</symbol>
<symbol id="i-check" viewBox="0 0 24 24"><path d="m5 12 4 4L19 6" /></symbol>
<symbol id="i-check-circle" viewBox="0 0 24 24">
<circle cx="12" cy="12" r="9" />
<path d="m8 12 3 3 5-6" />
</symbol>
<symbol id="i-alert-circle" viewBox="0 0 24 24">
<circle cx="12" cy="12" r="9" />
<path d="M12 8v4" />
<path d="M12 16h.01" />
</symbol>
<symbol id="i-search" viewBox="0 0 24 24">
<circle cx="11" cy="11" r="7" />
<path d="m20 20-4-4" />
</symbol>
<symbol id="i-map-pin" viewBox="0 0 24 24">
<path d="M20 10c0 5-8 12-8 12S4 15 4 10a8 8 0 1 1 16 0Z" />
<circle cx="12" cy="10" r="2.5" />
</symbol>
<symbol id="i-zap" viewBox="0 0 24 24">
<path
d="M4 14a1 1 0 0 1-.78-1.63l9-11a.5.5 0 0 1 .87.45l-1.58 6.33A1 1 0 0 0 12.48 9H20a1 1 0 0 1 .78 1.63l-9 11a.5.5 0 0 1-.87-.45l1.58-6.33A1 1 0 0 0 11.52 14H4Z"
/>
</symbol>
<symbol id="i-grid" viewBox="0 0 24 24">
<rect width="7" height="7" x="3" y="3" rx="1" />
<rect width="7" height="7" x="14" y="3" rx="1" />
<rect width="7" height="7" x="14" y="14" rx="1" />
<rect width="7" height="7" x="3" y="14" rx="1" />
</symbol>
<symbol id="i-log-out" viewBox="0 0 24 24">
<path d="M10 17l5-5-5-5" />
<path d="M15 12H3" />
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4" />
</symbol>
<symbol id="i-chevron-down" viewBox="0 0 24 24"><path d="m6 9 6 6 6-6" /></symbol>
<symbol id="i-help-circle" viewBox="0 0 24 24">
<circle cx="12" cy="12" r="9" />
<path d="M9.1 9a3 3 0 1 1 5.83 1c0 2-3 2-3 4" />
<path d="M12 18h.01" />
</symbol>
<symbol id="i-x" viewBox="0 0 24 24">
<path d="M18 6 6 18" />
<path d="m6 6 12 12" />
</symbol>
<symbol id="i-phone" viewBox="0 0 24 24">
<path
d="M22 16.92v3a2 2 0 0 1-2.18 2 19.8 19.8 0 0 1-8.63-3.07 19.45 19.45 0 0 1-6-6A19.8 19.8 0 0 1 2.12 4.18 2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.69 2.8a2 2 0 0 1-.45 2.11L8.08 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.33 1.85.56 2.81.69A2 2 0 0 1 22 16.92Z"
/>
</symbol>
<symbol id="i-building" viewBox="0 0 24 24">
<path d="M3 21h18" />
<path d="M5 21V7l7-4 7 4v14" />
<path d="M9 9h1" />
<path d="M14 9h1" />
<path d="M9 13h1" />
<path d="M14 13h1" />
<path d="M10 21v-4h4v4" />
</symbol>
<symbol id="i-leaf" viewBox="0 0 24 24">
<path d="M11 20A7 7 0 0 1 9.8 6.1C15.5 5 17 2 17 2c1 4 4 5 4 11a7 7 0 0 1-7 7Z" />
<path d="M2 21c0-3 1.85-5.36 5.08-6.94C9.6 12.86 12 12 16 12" />
</symbol>
<symbol id="i-headphones" viewBox="0 0 24 24">
<path d="M4 14a8 8 0 0 1 16 0" />
<path d="M18 19c0 1.1-.9 2-2 2h-3" />
<rect width="4" height="7" x="3" y="13" rx="2" />
<rect width="4" height="7" x="17" y="13" rx="2" />
</symbol>
</svg>
<router-view />
</template>
<script setup>
// 应用根组件:承载全局 SVG 图标库
</script>
<style lang="scss">
#app {
width: 100%;
height: 100%;
}
</style>
+42
View File
@@ -0,0 +1,42 @@
import { MOCK_USER } from "@/mock";
/**
* 模拟网络延迟
*/
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
/**
* 用户登录(模拟)
* TODO: 接口就绪后替换为 POST /auth/login { account, password }
*/
export async function login(params) {
await delay(700);
const account = String(params?.account ?? "").trim();
const password = String(params?.password ?? "");
if (account !== MOCK_USER.account || password !== MOCK_USER.password) {
throw new Error("账号或密码不正确,请使用演示账号登录");
}
const { password: _ignored, ...user } = MOCK_USER;
return { code: 0, data: { user, token: "mock-unified-token" } };
}
/**
* 获取当前用户信息(模拟)
* TODO: 接口就绪后替换为 GET /auth/userinfo
*/
export async function getUserInfo() {
await delay(200);
const { password: _ignored, ...user } = MOCK_USER;
return { code: 0, data: user };
}
/**
* 退出登录(模拟)
* TODO: 接口就绪后替换为 POST /auth/logout
*/
export async function logout() {
await delay(200);
return { code: 0 };
}
+30
View File
@@ -0,0 +1,30 @@
import { MOCK_PLANTS, sortPlants } from "@/mock";
/**
* 模拟网络延迟
*/
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
/**
* 获取已授权虚拟电厂列表(模拟)
* 说明:无论后端返回顺序如何,统一将讲解类平台置顶展示。
* TODO: 接口就绪后替换为 GET /plants,后端返回的数据同样走 sortPlants 排序。
*/
export async function fetchPlants() {
await delay(350);
const sorted = sortPlants(MOCK_PLANTS);
return { code: 0, data: sorted.map((plant) => ({ ...plant })) };
}
/**
* 进入指定虚拟电厂(模拟)
* TODO: 接口就绪后替换为 POST /plants/{id}/enter
*/
export async function enterPlant(id) {
await delay(650);
const plant = MOCK_PLANTS.find((item) => item.id === id);
if (!plant) {
throw new Error("未找到该虚拟电厂,请重新选择");
}
return { code: 0, data: { plant, accessToken: "mock-plant-token" } };
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 KiB

+126
View File
@@ -0,0 +1,126 @@
<template>
<el-container class="layout-container">
<el-header class="layout-header">
<div class="header-left">
<h1 class="app-title">梦象虚拟电厂集中门户</h1>
</div>
<div class="header-right">
<el-dropdown trigger="click" @command="handleCommand">
<span class="user-info">
<el-icon><User /></el-icon>
<span class="username">{{ userStore.username || "管理员" }}</span>
<el-icon><ArrowDown /></el-icon>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="logout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</el-header>
<el-container class="layout-body">
<el-aside :width="isCollapsed ? '64px' : '220px'" class="layout-sidebar">
<el-menu :default-active="currentRoute" :collapse="isCollapsed" router class="sidebar-menu">
<el-menu-item index="/plants">
<el-icon><HomeFilled /></el-icon>
<template #title>电厂门户</template>
</el-menu-item>
<el-menu-item index="/systems">
<el-icon><Menu /></el-icon>
<template #title>系统管理</template>
</el-menu-item>
</el-menu>
</el-aside>
<el-main class="layout-main">
<router-view v-slot="{ Component }">
<transition name="fade" mode="out-in">
<component :is="Component" />
</transition>
</router-view>
</el-main>
</el-container>
</el-container>
</template>
<script setup>
import { computed, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { User, ArrowDown, HomeFilled, Menu } from "@element-plus/icons-vue";
import { useUserStore } from "@/store/modules/user";
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
const isCollapsed = ref(false);
const currentRoute = computed(() => route.path);
function handleCommand(command) {
if (command === "logout") {
userStore.logout();
router.push({ name: "Login" });
}
}
</script>
<style lang="scss" scoped>
.layout-container {
width: 100%;
height: 100vh;
}
.layout-header {
display: flex;
align-items: center;
justify-content: space-between;
height: $header-height;
padding: 0 $spacing-lg;
background-color: $color-bg-white;
border-bottom: 1px solid $color-border;
box-shadow: $shadow-sm;
}
.app-title {
font-size: $font-size-xl;
font-weight: 600;
color: $primary;
}
.header-right {
.user-info {
display: flex;
align-items: center;
gap: $spacing-sm;
cursor: pointer;
color: $color-text-regular;
.username {
font-size: $font-size-md;
}
}
}
.layout-body {
height: calc(100vh - #{$header-height});
}
.layout-sidebar {
background-color: $color-bg-white;
border-right: 1px solid $color-border;
transition: width $transition-normal;
overflow: hidden;
}
.sidebar-menu {
height: 100%;
border-right: none;
}
.layout-main {
background-color: $color-bg;
overflow-y: auto;
}
</style>
+17
View File
@@ -0,0 +1,17 @@
import { createApp } from "vue";
import { createPinia } from "pinia";
import ElementPlus from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import "element-plus/dist/index.css";
import App from "./App.vue";
import router from "./router";
import "@/styles/index.scss";
const app = createApp(App);
app.use(createPinia());
app.use(router);
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
+101
View File
@@ -0,0 +1,101 @@
/**
* Mock 数据层
* 来源:原型项目 mock.js,用于接口未就绪阶段模拟后端响应
*/
export const MOCK_USER = {
account: "admin",
password: "123456",
name: "平台管理员",
role: "虚拟电厂运营人员",
};
/**
* 讲解类平台的 ID 前缀,用于排序兜底:讲解类数据始终置顶
*/
const PRESENTATION_IDS = ["csg-jj", "sg-jj"];
export const MOCK_PLANTS = [
{
id: "csg-jj",
name: "南网讲解",
operator: "南网",
region: "讲解",
code: "NJ",
description: "用于南网业务讲解的资源接入与运营演示平台。",
capabilities: ["业务演示", "资源聚合"],
status: "可访问",
type: "讲解演示平台",
entryUrl: "http://vpp.test.manabox.cn/#/southernPowerGrid",
},
{
id: "sg-jj",
name: "国网讲解",
operator: "国网",
region: "讲解",
code: "GJ",
description: "用于国网业务讲解的调度执行与运营演示平台。",
capabilities: ["业务演示", "调度执行"],
status: "可访问",
type: "讲解演示平台",
},
{
id: "sg-sh",
name: "国网上海",
operator: "国网",
region: "上海",
code: "SH",
description: "面向上海区域的负荷聚合、需求响应与协同调度。",
capabilities: ["资源聚合", "调度执行"],
status: "可访问",
type: "区域虚拟电厂",
},
{
id: "sg-js",
name: "国网江苏",
operator: "国网",
region: "江苏",
code: "JS",
description: "汇聚省内可调节资源,支撑电力交易与精细运营。",
capabilities: ["双网邀约", "计量分润"],
status: "可访问",
type: "区域虚拟电厂",
},
{
id: "csg-yn",
name: "南网云南",
operator: "南网",
region: "云南",
code: "YN",
description: "连接云南绿色能源资源,实现统一监测与灵活调度。",
capabilities: ["资源聚合", "绿色运力"],
status: "可访问",
type: "区域虚拟电厂",
},
{
id: "csg-gx",
name: "南网广西",
operator: "南网",
region: "广西",
code: "GX",
description: "服务广西多元负荷场景,提升资源协同运行效率。",
capabilities: ["调度执行", "计量分润"],
status: "可访问",
type: "区域虚拟电厂",
},
];
/**
* 统一排序函数:讲解类(type 包含"讲解"或 id 在白名单内)置顶,
* 其余保持原有相对顺序。
*/
export function sortPlants(plants) {
return [...plants].sort((a, b) => {
const aIsPresentation = a.type?.includes("讲解") || PRESENTATION_IDS.includes(a.id);
const bIsPresentation = b.type?.includes("讲解") || PRESENTATION_IDS.includes(b.id);
if (aIsPresentation !== bIsPresentation) {
return aIsPresentation ? -1 : 1;
}
return 0;
});
}
+83
View File
@@ -0,0 +1,83 @@
import { createRouter, createWebHistory } from "vue-router";
import { useUserStore } from "@/store/modules/user";
/**
* 路由配置
* meta 字段说明:
* title - 页面标题
* requiresAuth - 是否需要登录鉴权(默认 true)
* hidden - 是否在菜单中隐藏
*/
const routes = [
{
path: "/login",
name: "Login",
component: () => import("@/views/login/index.vue"),
meta: { title: "集中登录 · 梦象虚拟电厂", titleAsIs: true, requiresAuth: false },
},
{
path: "/plants",
name: "Plants",
component: () => import("@/views/plants/index.vue"),
meta: { title: "选择虚拟电厂 · 梦象虚拟电厂", titleAsIs: true },
},
{
path: "/",
name: "Layout",
component: () => import("@/layout/index.vue"),
redirect: "/plants",
children: [
{
path: "systems",
name: "Systems",
component: () => import("@/views/systems/index.vue"),
meta: { title: "系统管理" },
},
],
},
{
path: "/:pathMatch(.*)*",
name: "NotFound",
component: () => import("@/views/error/404.vue"),
meta: { title: "页面不存在", requiresAuth: false },
},
];
const router = createRouter({
history: createWebHistory(),
routes,
});
/**
* 全局前置守卫
*/
router.beforeEach((to, _from, next) => {
const userStore = useUserStore();
// 设置页面标题
if (to.meta?.titleAsIs) {
document.title = to.meta.title;
} else {
document.title = to.meta?.title
? `${to.meta.title} - 梦象虚拟电厂集中门户`
: "梦象虚拟电厂集中门户";
}
// 判断是否需要鉴权
if (to.meta?.requiresAuth !== false) {
if (!userStore.token) {
next({ name: "Login", query: { redirect: to.fullPath } });
return;
}
}
// 已登录用户访问登录页时重定向到首页
if (to.name === "Login" && userStore.token) {
next({ name: "Portal" });
return;
}
next();
});
export default router;
+5
View File
@@ -0,0 +1,5 @@
import { createPinia } from "pinia";
const pinia = createPinia();
export default pinia;
+60
View File
@@ -0,0 +1,60 @@
import { defineStore } from "pinia";
/**
* 多系统链接管理 Store
* 预留:后续用于管理子系统列表、快捷跳转、权限关联等
*/
export const useSystemStore = defineStore("system", {
state: () => ({
/** 系统列表 */
systemList: [],
/** 当前选中的系统 */
currentSystem: null,
/** 系统分类 */
categories: [],
/** 加载状态 */
loading: false,
}),
getters: {
/**
* 按分类获取系统列表
*/
getSystemsByCategory: (state) => (categoryId) => {
return state.systemList.filter((s) => s.categoryId === categoryId);
},
/**
* 获取收藏的系统
*/
favoriteSystems: (state) => {
return state.systemList.filter((s) => s.isFavorite);
},
},
actions: {
/**
* 设置系统列表
*/
setSystemList(list) {
this.systemList = list;
},
/**
* 设置当前系统
*/
setCurrentSystem(system) {
this.currentSystem = system;
},
/**
* 重置状态
*/
reset() {
this.systemList = [];
this.currentSystem = null;
this.categories = [];
this.loading = false;
},
},
});
+66
View File
@@ -0,0 +1,66 @@
import { defineStore } from "pinia";
import { login as loginApi } from "@/api/auth";
import {
getToken,
setToken,
removeToken,
getStoredUser,
setStoredUser,
removeStoredUser,
} from "@/utils/auth";
export const useUserStore = defineStore("user", {
state: () => ({
token: getToken() || "",
userInfo: getStoredUser(),
}),
getters: {
isLoggedIn: (state) => Boolean(state.token),
username: (state) => state.userInfo?.name || "",
},
actions: {
/**
* 用户登录(当前为模拟接口)
*/
async login(loginForm) {
try {
const { data } = await loginApi(loginForm);
this.token = data.token;
this.userInfo = data.user;
setToken(data.token);
setStoredUser(data.user);
return data;
} catch (error) {
this.resetState();
throw error;
}
},
/**
* 设置用户信息
*/
setUserInfo(info) {
this.userInfo = info;
setStoredUser(info);
},
/**
* 退出登录
*/
logout() {
this.resetState();
removeToken();
removeStoredUser();
},
/**
* 重置状态
*/
resetState() {
this.token = "";
this.userInfo = null;
},
},
});
+101
View File
@@ -0,0 +1,101 @@
// ==========================================
// 全局样式入口
// ==========================================
@use "./reset";
// 全局工具类
.flex {
display: flex;
}
.flex-center {
display: flex;
align-items: center;
justify-content: center;
}
.flex-between {
display: flex;
align-items: center;
justify-content: space-between;
}
.text-ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.page-container {
width: 100%;
height: 100%;
padding: $spacing-lg;
}
// 滚动条美化
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.15);
border-radius: 3px;
&:hover {
background-color: rgba(0, 0, 0, 0.25);
}
}
::-webkit-scrollbar-track {
background-color: transparent;
}
// 过渡动画
.fade-enter-active,
.fade-leave-active {
transition: opacity $transition-normal;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.slide-fade-enter-active {
transition: all $transition-normal;
}
.slide-fade-leave-active {
transition: all $transition-fast;
}
.slide-fade-enter-from {
transform: translateY(-10px);
opacity: 0;
}
.slide-fade-leave-to {
transform: translateY(10px);
opacity: 0;
}
// 全局 SVG 图标(迁移自原型,配合 App.vue 中的图标库使用)
.svg-library {
position: absolute;
width: 0;
height: 0;
overflow: hidden;
}
.icon {
width: 20px;
height: 20px;
flex: 0 0 auto;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
+50
View File
@@ -0,0 +1,50 @@
// ==========================================
// CSS Reset
// ==========================================
@use "./variables" as *;
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
font-family: $font-family;
font-size: $font-size-md;
color: $color-text-primary;
background-color: $color-bg;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
color: $primary;
text-decoration: none;
&:hover {
color: $primary-light;
}
}
ul,
ol {
list-style: none;
}
img {
max-width: 100%;
vertical-align: middle;
}
input,
button,
textarea,
select {
font: inherit;
}
+78
View File
@@ -0,0 +1,78 @@
// ==========================================
// 设计 Token(与参考项目保持一致)
// ==========================================
// 主色调
$primary: #20a4b8;
$primary-light: #3dc5d8;
$primary-dark: #178a9a;
// 功能色
$success: #52c41a;
$warning: #faad14;
$danger: #ff4d4f;
$info: #1890ff;
// 中性色
$color-text-primary: #1a1a2e;
$color-text-regular: #4a4a5a;
$color-text-secondary: #8c8c9a;
$color-text-placeholder: #b0b0bc;
// 背景色
$color-bg: #f5f7fa;
$color-bg-white: #ffffff;
$color-bg-card: #ffffff;
$color-bg-hover: #f0f9fb;
// 边框色
$color-border: #e4e7ed;
$color-border-light: #ebeef5;
// 圆角
$radius-sm: 4px;
$radius-md: 8px;
$radius-lg: 12px;
$radius-xl: 16px;
// 阴影
$shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
$shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
$shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
// 字体
$font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
$font-size-xs: 12px;
$font-size-sm: 13px;
$font-size-md: 14px;
$font-size-lg: 16px;
$font-size-xl: 20px;
$font-size-xxl: 24px;
// 间距
$spacing-xs: 4px;
$spacing-sm: 8px;
$spacing-md: 16px;
$spacing-lg: 24px;
$spacing-xl: 32px;
$spacing-xxl: 48px;
// 过渡
$transition-fast: 0.15s ease;
$transition-normal: 0.3s ease;
$transition-slow: 0.5s ease;
// 布局
$header-height: 60px;
$sidebar-width: 220px;
$sidebar-collapsed-width: 64px;
// Element Plus 主题覆盖
$--el-color-primary: $primary;
$--el-color-success: $success;
$--el-color-warning: $warning;
$--el-color-danger: $danger;
$--el-color-info: $info;
$--el-font-family: $font-family;
$--el-font-size-base: $font-size-md;
$--el-border-radius-base: $radius-sm;
+126
View File
@@ -0,0 +1,126 @@
const TOKEN_KEY = "vpp_portal_token";
const USER_KEY = "vpp_portal_user";
const REMEMBER_KEY = "vpp_portal_account";
const PLANT_KEY = "vpp_portal_selected_plant";
/**
* 获取 Token
*/
export function getToken() {
try {
return localStorage.getItem(TOKEN_KEY);
} catch {
return "";
}
}
/**
* 设置 Token
*/
export function setToken(token) {
try {
localStorage.setItem(TOKEN_KEY, token);
} catch {
// localStorage 不可用时静默处理
}
}
/**
* 移除 Token
*/
export function removeToken() {
try {
localStorage.removeItem(TOKEN_KEY);
} catch {
// localStorage 不可用时静默处理
}
}
/**
* 获取本地缓存的用户信息
*/
export function getStoredUser() {
try {
const raw = localStorage.getItem(USER_KEY);
return raw ? JSON.parse(raw) : null;
} catch {
return null;
}
}
/**
* 缓存用户信息
*/
export function setStoredUser(user) {
try {
localStorage.setItem(USER_KEY, JSON.stringify(user));
} catch {
// localStorage 不可用时静默处理
}
}
/**
* 移除用户信息
*/
export function removeStoredUser() {
try {
localStorage.removeItem(USER_KEY);
} catch {
// localStorage 不可用时静默处理
}
}
/**
* 获取记住的账号
*/
export function getRememberedAccount() {
try {
return localStorage.getItem(REMEMBER_KEY) || "";
} catch {
return "";
}
}
/**
* 记住账号
*/
export function setRememberedAccount(account) {
try {
localStorage.setItem(REMEMBER_KEY, account);
} catch {
// localStorage 不可用时静默处理
}
}
/**
* 移除记住的账号
*/
export function removeRememberedAccount() {
try {
localStorage.removeItem(REMEMBER_KEY);
} catch {
// localStorage 不可用时静默处理
}
}
/**
* 获取已选中的虚拟电厂 ID
*/
export function getSelectedPlant() {
try {
return localStorage.getItem(PLANT_KEY) || "";
} catch {
return "";
}
}
/**
* 记录选中的虚拟电厂 ID
*/
export function setSelectedPlant(id) {
try {
localStorage.setItem(PLANT_KEY, id);
} catch {
// localStorage 不可用时静默处理
}
}
+49
View File
@@ -0,0 +1,49 @@
/**
* 通用工具函数
*/
/**
* 防抖
*/
export function debounce(fn, delay = 300) {
let timer = null;
return function (...args) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), delay);
};
}
/**
* 节流
*/
export function throttle(fn, interval = 300) {
let last = 0;
return function (...args) {
const now = Date.now();
if (now - last >= interval) {
last = now;
fn.apply(this, args);
}
};
}
/**
* 深拷贝
*/
export function deepClone(obj) {
if (obj === null || typeof obj !== "object") return obj;
try {
return JSON.parse(JSON.stringify(obj));
} catch {
return obj;
}
}
/**
* HTML 转义(防 XSS)
*/
export function escapeHTML(str) {
if (!str) return "";
const map = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
return str.replace(/[&<>"']/g, (c) => map[c]);
}
+79
View File
@@ -0,0 +1,79 @@
import axios from "axios";
import { ElMessage } from "element-plus";
import { getToken, removeToken } from "@/utils/auth";
import router from "@/router";
/**
* 创建 Axios 实例
*/
const service = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL,
timeout: 30000,
headers: {
"Content-Type": "application/json",
},
});
/**
* 请求拦截器
*/
service.interceptors.request.use(
(config) => {
const token = getToken();
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
},
);
/**
* 响应拦截器
*/
service.interceptors.response.use(
(response) => {
const res = response.data;
// 约定 code === 0 为成功,其他为业务错误
if (res.code !== undefined && res.code !== 0) {
ElMessage.error(res.message || "请求失败");
// Token 过期
if (res.code === 401) {
removeToken();
router.push({ name: "Login" });
}
return Promise.reject(new Error(res.message || "请求失败"));
}
return res;
},
(error) => {
const status = error.response?.status;
const messages = {
400: "请求参数错误",
401: "未授权,请重新登录",
403: "拒绝访问",
404: "请求资源不存在",
500: "服务器内部错误",
502: "网关错误",
503: "服务不可用",
};
const message = messages[status] || `请求失败(${status || "网络异常"})`;
ElMessage.error(message);
if (status === 401) {
removeToken();
router.push({ name: "Login" });
}
return Promise.reject(error);
},
);
export default service;
+42
View File
@@ -0,0 +1,42 @@
<template>
<div class="error-page">
<div class="error-content">
<h1 class="error-code">404</h1>
<p class="error-message">抱歉,您访问的页面不存在</p>
<el-button type="primary" @click="$router.push('/portal')"> 返回首页 </el-button>
</div>
</div>
</template>
<script setup>
// 404 页面
</script>
<style lang="scss" scoped>
.error-page {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100vh;
background-color: $color-bg;
}
.error-content {
text-align: center;
}
.error-code {
font-size: 120px;
font-weight: 700;
color: $primary;
line-height: 1;
margin-bottom: $spacing-md;
}
.error-message {
font-size: $font-size-lg;
color: $color-text-secondary;
margin-bottom: $spacing-xl;
}
</style>
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+85
View File
@@ -0,0 +1,85 @@
<template>
<div class="page-container systems-page">
<div class="page-header flex-between">
<div>
<h2 class="page-title">系统管理</h2>
<p class="page-desc">管理和配置所有子系统链接</p>
</div>
<el-button type="primary" @click="handleAdd"> 添加系统 </el-button>
</div>
<!-- 搜索筛选区域 -->
<el-card shadow="never" class="filter-card">
<el-form :inline="true" :model="filterForm">
<el-form-item label="系统名称">
<el-input v-model="filterForm.keyword" placeholder="请输入系统名称" clearable />
</el-form-item>
<el-form-item label="系统分类">
<el-select v-model="filterForm.category" placeholder="全部分类" clearable>
<el-option label="全部" value="" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleSearch">查询</el-button>
<el-button @click="handleReset">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<!-- 系统列表区域 -->
<el-card shadow="never" class="list-card">
<el-empty description="暂无系统数据" />
</el-card>
</div>
</template>
<script setup>
import { reactive } from "vue";
import { ElMessage } from "element-plus";
const filterForm = reactive({
keyword: "",
category: "",
});
function handleSearch() {
// 预留:查询逻辑
}
function handleReset() {
filterForm.keyword = "";
filterForm.category = "";
}
function handleAdd() {
ElMessage.info("添加系统功能待开发");
}
</script>
<style lang="scss" scoped>
.systems-page {
.page-header {
margin-bottom: $spacing-lg;
}
.page-title {
font-size: $font-size-xxl;
font-weight: 600;
color: $color-text-primary;
margin-bottom: $spacing-xs;
}
.page-desc {
font-size: $font-size-md;
color: $color-text-secondary;
}
.filter-card {
margin-bottom: $spacing-lg;
}
.list-card {
margin-bottom: $spacing-lg;
}
}
</style>
+63
View File
@@ -0,0 +1,63 @@
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import path from "path";
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
return {
plugins: [
vue(),
AutoImport({
imports: ["vue", "vue-router", "pinia"],
resolvers: [ElementPlusResolver()],
dts: "src/auto-imports.d.ts",
}),
Components({
resolvers: [ElementPlusResolver()],
dts: "src/components.d.ts",
}),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
},
server: {
port: Number(env.VITE_PORT) || 3000,
host: env.VITE_HOST || "0.0.0.0",
open: true,
proxy: {
[env.VITE_API_BASE_URL]: {
target: env.VITE_API_TARGET,
changeOrigin: true,
rewrite: (p) => p.replace(new RegExp("^" + env.VITE_API_BASE_URL), ""),
},
},
},
build: {
target: "es2015",
outDir: "dist",
chunkSizeWarningLimit: 2000,
rollupOptions: {
output: {
manualChunks: {
vue: ["vue", "vue-router", "pinia"],
"element-plus": ["element-plus"],
},
},
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/styles/variables.scss" as *;`,
},
},
},
};
});