Spaces:
Sleeping
Sleeping
Claude Claude Opus 4.8 commited on
品牌/首页可配置 + 登录封面页
Browse files需求:首页显示水厂名+节能系统名,公司/联系方式可配置,可选登录页。
- app/branding.py + branding_api.py:水厂名/系统名/副标题/公司/联系人/电话/邮箱/网址/
Logo(data:URI)/可选登录口令(隔离) 全部配置项;/api/branding GET(公开)/PUT + /login 校验
- frontend/home.html:品牌封面/登录页,读 /api/branding 展示,可选口令;进入→ index.html
- 单容器 / 根路径改为首页(home.html),大屏在 index.html;nginx 同步;Docker env + 持久化
- config.html 加「07 品牌/关于」Tab;index.html 侧栏标题/公司/联系方式随配置显示
- 新增 test_branding.py(口令隔离/校验),全套 55 项通过
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QJjVUJM3KCFfKriCFvDaEF
- .gitignore +4 -0
- Dockerfile +2 -0
- backend/app/branding.py +94 -0
- backend/app/branding_api.py +32 -0
- backend/app/main.py +8 -0
- backend/tests/test_branding.py +23 -0
- frontend/Dockerfile +1 -0
- frontend/config.html +40 -1
- frontend/home.html +79 -0
- frontend/index.html +18 -3
- frontend/nginx.conf +2 -0
.gitignore
CHANGED
|
@@ -32,3 +32,7 @@ docs/sources/*_page*.png
|
|
| 32 |
# 云端转发运行时配置(app 管理)
|
| 33 |
backend/config/cloud_forward.json
|
| 34 |
backend/config/cloud_secret.json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# 云端转发运行时配置(app 管理)
|
| 33 |
backend/config/cloud_forward.json
|
| 34 |
backend/config/cloud_secret.json
|
| 35 |
+
|
| 36 |
+
# 品牌配置(app 管理)
|
| 37 |
+
backend/config/branding.json
|
| 38 |
+
backend/config/branding_secret.json
|
Dockerfile
CHANGED
|
@@ -21,6 +21,8 @@ ENV FRONTEND_DIR=/app/frontend \
|
|
| 21 |
BIDITECH_OPCUA_SECRET=/data/opcua_secret.json \
|
| 22 |
BIDITECH_CLOUD_CONFIG=/data/cloud_forward.json \
|
| 23 |
BIDITECH_CLOUD_SECRET=/data/cloud_secret.json \
|
|
|
|
|
|
|
| 24 |
BIDITECH_DEMO_REPLAY_CSV=/app/demo-data/pump_history_demo.csv \
|
| 25 |
BIDITECH_DEMO_OPCUA_ENDPOINT=opc.tcp://127.0.0.1:4840/biditech/server/ \
|
| 26 |
BIDITECH_DEFAULT_OPCUA_ENDPOINT=opc.tcp://127.0.0.1:4840/biditech/server/ \
|
|
|
|
| 21 |
BIDITECH_OPCUA_SECRET=/data/opcua_secret.json \
|
| 22 |
BIDITECH_CLOUD_CONFIG=/data/cloud_forward.json \
|
| 23 |
BIDITECH_CLOUD_SECRET=/data/cloud_secret.json \
|
| 24 |
+
BIDITECH_BRANDING_CONFIG=/data/branding.json \
|
| 25 |
+
BIDITECH_BRANDING_SECRET=/data/branding_secret.json \
|
| 26 |
BIDITECH_DEMO_REPLAY_CSV=/app/demo-data/pump_history_demo.csv \
|
| 27 |
BIDITECH_DEMO_OPCUA_ENDPOINT=opc.tcp://127.0.0.1:4840/biditech/server/ \
|
| 28 |
BIDITECH_DEFAULT_OPCUA_ENDPOINT=opc.tcp://127.0.0.1:4840/biditech/server/ \
|
backend/app/branding.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""品牌/首页配置:水厂名、系统名、公司、联系方式、Logo,以及可选的简易登录口令。
|
| 2 |
+
|
| 3 |
+
现场部署时不同水厂显示不同名字与联系方式——全部做成配置项,存 /data,
|
| 4 |
+
登录口令单独隔离(不随 GET 返回、不进日志)。GET 为公开只读(首页要用),PUT 需管理。
|
| 5 |
+
"""
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Optional
|
| 12 |
+
|
| 13 |
+
from pydantic import BaseModel, Field
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class BrandingConfig(BaseModel):
|
| 17 |
+
system_title: str = Field(default="泵站节能优化系统", max_length=60)
|
| 18 |
+
plant_name: str = Field(default="", max_length=80) # 如:胶州水厂二期
|
| 19 |
+
subtitle: str = Field(default="", max_length=120)
|
| 20 |
+
company: str = Field(default="上海碧帝数据科技有限公司", max_length=80)
|
| 21 |
+
contact_person: str = Field(default="", max_length=40)
|
| 22 |
+
contact_phone: str = Field(default="", max_length=40)
|
| 23 |
+
contact_email: str = Field(default="", max_length=80)
|
| 24 |
+
website: str = Field(default="", max_length=120)
|
| 25 |
+
logo_data_uri: str = Field(default="", max_length=400000) # 可选内嵌 logo(data:URI)
|
| 26 |
+
login_enabled: bool = False
|
| 27 |
+
password_configured: bool = False # 只读标志
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class BrandingUpdate(BrandingConfig):
|
| 31 |
+
password: Optional[str] = Field(default=None, max_length=200, exclude=True)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _cfg_path() -> Path:
|
| 35 |
+
return Path(os.environ.get(
|
| 36 |
+
"BIDITECH_BRANDING_CONFIG",
|
| 37 |
+
str(Path(__file__).resolve().parent.parent / "config" / "branding.json")))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _secret_path() -> Path:
|
| 41 |
+
return Path(os.environ.get(
|
| 42 |
+
"BIDITECH_BRANDING_SECRET",
|
| 43 |
+
str(Path(__file__).resolve().parent.parent / "config" / "branding_secret.json")))
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class BrandingStore:
|
| 47 |
+
def load(self) -> BrandingConfig:
|
| 48 |
+
p = _cfg_path()
|
| 49 |
+
if not p.exists():
|
| 50 |
+
return BrandingConfig()
|
| 51 |
+
try:
|
| 52 |
+
cfg = BrandingConfig(**json.loads(p.read_text(encoding="utf-8")))
|
| 53 |
+
cfg.password_configured = bool(self._password())
|
| 54 |
+
return cfg
|
| 55 |
+
except Exception:
|
| 56 |
+
return BrandingConfig()
|
| 57 |
+
|
| 58 |
+
def public(self) -> dict:
|
| 59 |
+
"""首页用的公开信息(不含口令)。"""
|
| 60 |
+
return self.load().model_dump()
|
| 61 |
+
|
| 62 |
+
def save(self, update: BrandingUpdate) -> BrandingConfig:
|
| 63 |
+
cfg = BrandingConfig(**update.model_dump(exclude={"password"}))
|
| 64 |
+
if update.password is not None:
|
| 65 |
+
self._save_password(update.password)
|
| 66 |
+
cfg.password_configured = bool(self._password())
|
| 67 |
+
_cfg_path().parent.mkdir(parents=True, exist_ok=True)
|
| 68 |
+
_cfg_path().write_text(cfg.model_dump_json(indent=2), encoding="utf-8")
|
| 69 |
+
return cfg
|
| 70 |
+
|
| 71 |
+
def verify(self, password: str) -> bool:
|
| 72 |
+
saved = self._password()
|
| 73 |
+
if not saved:
|
| 74 |
+
return True # 未设口令 → 放行
|
| 75 |
+
import secrets as _s
|
| 76 |
+
return _s.compare_digest(password or "", saved)
|
| 77 |
+
|
| 78 |
+
def _password(self) -> str:
|
| 79 |
+
sp = _secret_path()
|
| 80 |
+
if not sp.exists():
|
| 81 |
+
return ""
|
| 82 |
+
try:
|
| 83 |
+
return json.loads(sp.read_text(encoding="utf-8")).get("login_password", "")
|
| 84 |
+
except Exception:
|
| 85 |
+
return ""
|
| 86 |
+
|
| 87 |
+
def _save_password(self, password: str) -> None:
|
| 88 |
+
sp = _secret_path()
|
| 89 |
+
sp.parent.mkdir(parents=True, exist_ok=True)
|
| 90 |
+
sp.write_text(json.dumps({"login_password": password}), encoding="utf-8")
|
| 91 |
+
try:
|
| 92 |
+
os.chmod(sp, 0o600)
|
| 93 |
+
except OSError:
|
| 94 |
+
pass
|
backend/app/branding_api.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""品牌/首页 API:公开读(首页用) + 管理写 + 简易登录校验。"""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from fastapi import APIRouter
|
| 5 |
+
from pydantic import BaseModel
|
| 6 |
+
|
| 7 |
+
from .branding import BrandingStore, BrandingUpdate
|
| 8 |
+
|
| 9 |
+
router = APIRouter(prefix="/api/branding", tags=["品牌/首页"])
|
| 10 |
+
store = BrandingStore()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class LoginRequest(BaseModel):
|
| 14 |
+
password: str = ""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@router.get("")
|
| 18 |
+
def get_branding():
|
| 19 |
+
"""公开只读:首页/大屏读取水厂名、公司、联系方式等(不含登录口令)。"""
|
| 20 |
+
return store.public()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@router.put("")
|
| 24 |
+
def put_branding(update: BrandingUpdate):
|
| 25 |
+
return store.save(update).model_dump()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@router.post("/login")
|
| 29 |
+
def login(req: LoginRequest):
|
| 30 |
+
"""简易登录校验(可选):未设口令则始终放行;设了则比对。"""
|
| 31 |
+
ok = store.verify(req.password)
|
| 32 |
+
return {"success": ok}
|
backend/app/main.py
CHANGED
|
@@ -41,6 +41,8 @@ app.add_middleware(
|
|
| 41 |
)
|
| 42 |
app.include_router(integration_router)
|
| 43 |
app.include_router(cloud_router)
|
|
|
|
|
|
|
| 44 |
|
| 45 |
plant = Plant()
|
| 46 |
|
|
@@ -384,4 +386,10 @@ async def realtime_ws(websocket: WebSocket):
|
|
| 384 |
_FRONT = os.environ.get(
|
| 385 |
"FRONTEND_DIR", str(Path(__file__).resolve().parents[2] / "frontend"))
|
| 386 |
if Path(_FRONT).is_dir():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
app.mount("/", StaticFiles(directory=_FRONT, html=True), name="frontend")
|
|
|
|
| 41 |
)
|
| 42 |
app.include_router(integration_router)
|
| 43 |
app.include_router(cloud_router)
|
| 44 |
+
from .branding_api import router as branding_router # noqa: E402
|
| 45 |
+
app.include_router(branding_router)
|
| 46 |
|
| 47 |
plant = Plant()
|
| 48 |
|
|
|
|
| 386 |
_FRONT = os.environ.get(
|
| 387 |
"FRONTEND_DIR", str(Path(__file__).resolve().parents[2] / "frontend"))
|
| 388 |
if Path(_FRONT).is_dir():
|
| 389 |
+
from fastapi.responses import FileResponse
|
| 390 |
+
_home = Path(_FRONT) / "home.html"
|
| 391 |
+
if _home.exists():
|
| 392 |
+
@app.get("/", include_in_schema=False) # 首页=品牌封面/登录页;大屏在 index.html
|
| 393 |
+
def _landing():
|
| 394 |
+
return FileResponse(str(_home), headers={"Cache-Control": "no-store"})
|
| 395 |
app.mount("/", StaticFiles(directory=_FRONT, html=True), name="frontend")
|
backend/tests/test_branding.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from app.branding import BrandingStore, BrandingUpdate
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_branding_save_public_and_password_isolated(tmp_path, monkeypatch):
|
| 5 |
+
monkeypatch.setenv("BIDITECH_BRANDING_CONFIG", str(tmp_path / "b.json"))
|
| 6 |
+
monkeypatch.setenv("BIDITECH_BRANDING_SECRET", str(tmp_path / "bs.json"))
|
| 7 |
+
store = BrandingStore()
|
| 8 |
+
store.save(BrandingUpdate(plant_name="胶州水厂二期", system_title="泵组节能优化系统",
|
| 9 |
+
company="上海碧帝", contact_phone="021-1", login_enabled=True,
|
| 10 |
+
password="pump2026"))
|
| 11 |
+
pub = store.public()
|
| 12 |
+
assert pub["plant_name"] == "胶州水厂二期"
|
| 13 |
+
assert pub["password_configured"] is True
|
| 14 |
+
assert "password" not in pub # 公开信息不含口令
|
| 15 |
+
assert store.verify("pump2026") is True
|
| 16 |
+
assert store.verify("wrong") is False
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def test_branding_no_password_allows_all(tmp_path, monkeypatch):
|
| 20 |
+
monkeypatch.setenv("BIDITECH_BRANDING_CONFIG", str(tmp_path / "b.json"))
|
| 21 |
+
monkeypatch.setenv("BIDITECH_BRANDING_SECRET", str(tmp_path / "bs.json"))
|
| 22 |
+
store = BrandingStore()
|
| 23 |
+
assert store.verify("anything") is True # 未设口令 → 放行
|
frontend/Dockerfile
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
FROM nginx:alpine
|
| 3 |
COPY index.html /usr/share/nginx/html/index.html
|
| 4 |
COPY config.html /usr/share/nginx/html/config.html
|
|
|
|
| 5 |
COPY echarts.min.js /usr/share/nginx/html/echarts.min.js
|
| 6 |
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
| 7 |
EXPOSE 80
|
|
|
|
| 2 |
FROM nginx:alpine
|
| 3 |
COPY index.html /usr/share/nginx/html/index.html
|
| 4 |
COPY config.html /usr/share/nginx/html/config.html
|
| 5 |
+
COPY home.html /usr/share/nginx/html/home.html
|
| 6 |
COPY echarts.min.js /usr/share/nginx/html/echarts.min.js
|
| 7 |
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
| 8 |
EXPOSE 80
|
frontend/config.html
CHANGED
|
@@ -36,6 +36,7 @@ button,input,select{font:inherit}button{cursor:pointer}.app{display:grid;grid-te
|
|
| 36 |
<button data-view="browse"><span class="num">04</span>节点浏览</button>
|
| 37 |
<button data-view="preview"><span class="num">05</span>实时预览</button>
|
| 38 |
<button data-view="cloud"><span class="num">06</span>云端转发</button>
|
|
|
|
| 39 |
</nav>
|
| 40 |
<div class="side-bottom"><a class="back-link" href="./index.html">← 返回运行大屏</a></div>
|
| 41 |
</aside>
|
|
@@ -144,13 +145,33 @@ button,input,select{font:inherit}button{cursor:pointer}.app{display:grid;grid-te
|
|
| 144 |
<div class="hint" id="cloudStatus" style="margin-top:14px"></div>
|
| 145 |
</div>
|
| 146 |
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
</div>
|
| 148 |
</main>
|
| 149 |
</div>
|
| 150 |
<div class="toast" id="toast"></div>
|
| 151 |
<script>
|
| 152 |
var state={config:null,selectedTag:-1,browseNodes:[],status:null};
|
| 153 |
-
var titles={overview:"接入总览",connection:"OPC 连接",mapping:"点位映射",browse:"节点浏览",preview:"实时预览",cloud:"云端转发"};
|
| 154 |
|
| 155 |
function esc(value){return String(value==null?"":value).replace(/[&<>"']/g,function(c){return({"&":"&","<":"<",">":">",'"':""","'":"'"})[c]})}
|
| 156 |
async function request(path,options){
|
|
@@ -169,7 +190,24 @@ function setView(name){
|
|
| 169 |
document.getElementById("pageTitle").textContent=titles[name]||name;
|
| 170 |
if(name==="preview")renderPreview([]);
|
| 171 |
if(name==="cloud")loadCloud();
|
|
|
|
| 172 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
function fillCloud(c){
|
| 174 |
document.getElementById("cloudEnabled").value=String(!!c.enabled);
|
| 175 |
document.getElementById("cloudInterval").value=c.publish_interval_s||10;
|
|
@@ -352,6 +390,7 @@ document.getElementById("browseList").addEventListener("click",function(e){if(e.
|
|
| 352 |
document.getElementById("previewBtn").addEventListener("click",preview);
|
| 353 |
document.getElementById("cloudSaveBtn").addEventListener("click",saveCloud);
|
| 354 |
document.getElementById("cloudTestBtn").addEventListener("click",testCloud);
|
|
|
|
| 355 |
document.getElementById("previewSelected").addEventListener("click",function(){setView("preview");preview()});
|
| 356 |
loadAll();
|
| 357 |
</script>
|
|
|
|
| 36 |
<button data-view="browse"><span class="num">04</span>节点浏览</button>
|
| 37 |
<button data-view="preview"><span class="num">05</span>实时预览</button>
|
| 38 |
<button data-view="cloud"><span class="num">06</span>云端转发</button>
|
| 39 |
+
<button data-view="brand"><span class="num">07</span>品牌/关于</button>
|
| 40 |
</nav>
|
| 41 |
<div class="side-bottom"><a class="back-link" href="./index.html">← 返回运行大屏</a></div>
|
| 42 |
</aside>
|
|
|
|
| 145 |
<div class="hint" id="cloudStatus" style="margin-top:14px"></div>
|
| 146 |
</div>
|
| 147 |
</section>
|
| 148 |
+
|
| 149 |
+
<section class="view" id="view-brand">
|
| 150 |
+
<div class="card section">
|
| 151 |
+
<div class="section-head"><div><h2>品牌 / 首页信息</h2><p>首页(登录/封面页)与大屏标题展示的水厂名、系统名、公司与联系方式,全部可配。</p></div><div class="actions button-row"><button class="btn primary" id="brandSaveBtn">保存</button></div></div>
|
| 152 |
+
<div class="form-grid">
|
| 153 |
+
<div class="field half"><label>水厂 / 项目名称</label><input id="bPlant" placeholder="如:胶州水厂二期"></div>
|
| 154 |
+
<div class="field half"><label>系统名称</label><input id="bTitle" placeholder="泵站节能优化系统"></div>
|
| 155 |
+
<div class="field full"><label>副标题 / 一句话介绍</label><input id="bSub" placeholder="AI 驱动的泵组能效优化与运行监控"></div>
|
| 156 |
+
<div class="field"><label>公司名称</label><input id="bCompany"></div>
|
| 157 |
+
<div class="field"><label>联系人</label><input id="bPerson"></div>
|
| 158 |
+
<div class="field"><label>联系电话</label><input id="bPhone"></div>
|
| 159 |
+
<div class="field"><label>邮箱</label><input id="bEmail"></div>
|
| 160 |
+
<div class="field"><label>网址</label><input id="bWeb"></div>
|
| 161 |
+
<div class="field"><label>Logo(data:URI,可选)</label><input id="bLogo" placeholder="data:image/png;base64,..."></div>
|
| 162 |
+
<div class="field half"><label>启用登录口令</label><select id="bLogin"><option value="false">否(直接进入)</option><option value="true">是(首页需口令)</option></select></div>
|
| 163 |
+
<div class="field half"><label>登录口令 <span id="bPwHint" class="required"></span></label><input id="bPw" type="password" placeholder="留空则不修改"></div>
|
| 164 |
+
</div>
|
| 165 |
+
<div class="hint" style="margin-top:12px">保存后:首页 <b>/home.html</b>(单容器下为根路径 <b>/</b>)与大屏标题即显示以上信息。</div>
|
| 166 |
+
</div>
|
| 167 |
+
</section>
|
| 168 |
</div>
|
| 169 |
</main>
|
| 170 |
</div>
|
| 171 |
<div class="toast" id="toast"></div>
|
| 172 |
<script>
|
| 173 |
var state={config:null,selectedTag:-1,browseNodes:[],status:null};
|
| 174 |
+
var titles={overview:"接入总览",connection:"OPC 连接",mapping:"点位映射",browse:"节点浏览",preview:"实时预览",cloud:"云端转发",brand:"品牌 / 关于"};
|
| 175 |
|
| 176 |
function esc(value){return String(value==null?"":value).replace(/[&<>"']/g,function(c){return({"&":"&","<":"<",">":">",'"':""","'":"'"})[c]})}
|
| 177 |
async function request(path,options){
|
|
|
|
| 190 |
document.getElementById("pageTitle").textContent=titles[name]||name;
|
| 191 |
if(name==="preview")renderPreview([]);
|
| 192 |
if(name==="cloud")loadCloud();
|
| 193 |
+
if(name==="brand")loadBrand();
|
| 194 |
}
|
| 195 |
+
async function loadBrand(){try{var b=await request("/api/branding");
|
| 196 |
+
document.getElementById("bPlant").value=b.plant_name||"";document.getElementById("bTitle").value=b.system_title||"";
|
| 197 |
+
document.getElementById("bSub").value=b.subtitle||"";document.getElementById("bCompany").value=b.company||"";
|
| 198 |
+
document.getElementById("bPerson").value=b.contact_person||"";document.getElementById("bPhone").value=b.contact_phone||"";
|
| 199 |
+
document.getElementById("bEmail").value=b.contact_email||"";document.getElementById("bWeb").value=b.website||"";
|
| 200 |
+
document.getElementById("bLogo").value=b.logo_data_uri||"";document.getElementById("bLogin").value=String(!!b.login_enabled);
|
| 201 |
+
document.getElementById("bPw").value="";document.getElementById("bPwHint").textContent=b.password_configured?"已保存":"未配置";
|
| 202 |
+
}catch(e){}}
|
| 203 |
+
async function saveBrand(){try{var o={plant_name:document.getElementById("bPlant").value.trim(),system_title:document.getElementById("bTitle").value.trim()||"泵站节能优化系统",
|
| 204 |
+
subtitle:document.getElementById("bSub").value.trim(),company:document.getElementById("bCompany").value.trim(),
|
| 205 |
+
contact_person:document.getElementById("bPerson").value.trim(),contact_phone:document.getElementById("bPhone").value.trim(),
|
| 206 |
+
contact_email:document.getElementById("bEmail").value.trim(),website:document.getElementById("bWeb").value.trim(),
|
| 207 |
+
logo_data_uri:document.getElementById("bLogo").value.trim(),login_enabled:document.getElementById("bLogin").value==="true"};
|
| 208 |
+
var pw=document.getElementById("bPw").value;if(pw)o.password=pw;
|
| 209 |
+
await request("/api/branding",{method:"PUT",body:JSON.stringify(o)});toast("品牌信息已保存","ok");loadBrand();
|
| 210 |
+
}catch(e){toast(e.message,"bad")}}
|
| 211 |
function fillCloud(c){
|
| 212 |
document.getElementById("cloudEnabled").value=String(!!c.enabled);
|
| 213 |
document.getElementById("cloudInterval").value=c.publish_interval_s||10;
|
|
|
|
| 390 |
document.getElementById("previewBtn").addEventListener("click",preview);
|
| 391 |
document.getElementById("cloudSaveBtn").addEventListener("click",saveCloud);
|
| 392 |
document.getElementById("cloudTestBtn").addEventListener("click",testCloud);
|
| 393 |
+
document.getElementById("brandSaveBtn").addEventListener("click",saveBrand);
|
| 394 |
document.getElementById("previewSelected").addEventListener("click",function(){setView("preview");preview()});
|
| 395 |
loadAll();
|
| 396 |
</script>
|
frontend/home.html
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="zh-CN">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 6 |
+
<title>节能系统</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root{--bg:#06121f;--panel:#0e2033;--line:#1e3a52;--text:#eaf3fb;--muted:#8fa8ba;--cyan:#43c7d7;--green:#38d39f}
|
| 9 |
+
*{box-sizing:border-box}
|
| 10 |
+
body{margin:0;min-height:100vh;font-family:-apple-system,"Microsoft YaHei",sans-serif;color:var(--text);
|
| 11 |
+
background:radial-gradient(1200px 600px at 70% -10%,rgba(67,199,215,.18),transparent),
|
| 12 |
+
radial-gradient(900px 500px at 10% 110%,rgba(56,211,159,.12),transparent),var(--bg);
|
| 13 |
+
display:flex;flex-direction:column}
|
| 14 |
+
.top{display:flex;align-items:center;gap:12px;padding:20px 30px}
|
| 15 |
+
.top img{height:38px} .top .co{font-size:13px;color:var(--muted)}
|
| 16 |
+
.wrap{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:20px}
|
| 17 |
+
.plant{font-size:15px;color:var(--cyan);letter-spacing:3px;margin-bottom:10px}
|
| 18 |
+
h1{font-size:clamp(30px,6vw,60px);margin:0 0 14px;font-weight:800;letter-spacing:2px;
|
| 19 |
+
background:linear-gradient(90deg,#eaf3fb,#43c7d7);-webkit-background-clip:text;background-clip:text;color:transparent}
|
| 20 |
+
.sub{font-size:15px;color:var(--muted);max-width:640px;margin:0 auto 34px;line-height:1.8}
|
| 21 |
+
.card{background:rgba(14,32,51,.7);border:1px solid var(--line);border-radius:16px;padding:26px 30px;min-width:320px;backdrop-filter:blur(6px)}
|
| 22 |
+
.card input{width:100%;background:#081a29;border:1px solid var(--line);color:var(--text);padding:12px 14px;border-radius:10px;font-size:15px;margin-bottom:14px;outline:none}
|
| 23 |
+
.card input:focus{border-color:var(--cyan)}
|
| 24 |
+
.btn{width:100%;border:0;background:linear-gradient(90deg,var(--cyan),var(--green));color:#052029;font-weight:800;font-size:16px;padding:13px;border-radius:10px;cursor:pointer;letter-spacing:2px}
|
| 25 |
+
.err{color:#ff6b78;font-size:13px;min-height:18px;margin-top:8px}
|
| 26 |
+
.foot{padding:22px 30px;border-top:1px solid var(--line);color:var(--muted);font-size:12.5px;display:flex;flex-wrap:wrap;gap:18px;justify-content:center}
|
| 27 |
+
.foot b{color:var(--text);font-weight:600}
|
| 28 |
+
</style>
|
| 29 |
+
</head>
|
| 30 |
+
<body>
|
| 31 |
+
<div class="top"><img id="logo" alt="" style="display:none"><span class="co" id="topCompany"></span></div>
|
| 32 |
+
<div class="wrap">
|
| 33 |
+
<div class="plant" id="plant"></div>
|
| 34 |
+
<h1 id="title">泵站节能优化系统</h1>
|
| 35 |
+
<div class="sub" id="subtitle"></div>
|
| 36 |
+
<div class="card">
|
| 37 |
+
<div id="loginBox" style="display:none">
|
| 38 |
+
<input id="pw" type="password" placeholder="请输入访问口令" autocomplete="current-password">
|
| 39 |
+
</div>
|
| 40 |
+
<button class="btn" id="enter">进 入 系 统</button>
|
| 41 |
+
<div class="err" id="err"></div>
|
| 42 |
+
</div>
|
| 43 |
+
</div>
|
| 44 |
+
<div class="foot" id="foot"></div>
|
| 45 |
+
<script>
|
| 46 |
+
async function req(path,opt){var r=await fetch(path,Object.assign({headers:{'Content-Type':'application/json'}},opt||{}));return r.json()}
|
| 47 |
+
function txt(id,v){document.getElementById(id).textContent=v||''}
|
| 48 |
+
var LOGIN=false;
|
| 49 |
+
(async function(){
|
| 50 |
+
var b={};try{b=await fetch('/api/branding').then(r=>r.json())}catch(e){}
|
| 51 |
+
txt('title',b.system_title||'泵站节能优化系统');
|
| 52 |
+
document.title=(b.plant_name?b.plant_name+' · ':'')+(b.system_title||'节能系统');
|
| 53 |
+
txt('plant',b.plant_name||'');
|
| 54 |
+
txt('subtitle',b.subtitle||'AI 驱动的泵组能效优化与运行监控');
|
| 55 |
+
txt('topCompany',b.company||'');
|
| 56 |
+
if(b.logo_data_uri){var l=document.getElementById('logo');l.src=b.logo_data_uri;l.style.display='block'}
|
| 57 |
+
LOGIN=!!(b.login_enabled&&b.password_configured);
|
| 58 |
+
document.getElementById('loginBox').style.display=LOGIN?'block':'none';
|
| 59 |
+
document.getElementById('enter').textContent=LOGIN?'登 录':'进 入 系 统';
|
| 60 |
+
var f=[];if(b.company)f.push('<b>'+b.company+'</b>');
|
| 61 |
+
if(b.contact_person)f.push('联系人:'+b.contact_person);
|
| 62 |
+
if(b.contact_phone)f.push('电话:'+b.contact_phone);
|
| 63 |
+
if(b.contact_email)f.push('邮箱:'+b.contact_email);
|
| 64 |
+
if(b.website)f.push(b.website);
|
| 65 |
+
document.getElementById('foot').innerHTML=f.join('<span style="opacity:.4">|</span>');
|
| 66 |
+
})();
|
| 67 |
+
async function enter(){
|
| 68 |
+
if(LOGIN){
|
| 69 |
+
var r=await req('/api/branding/login',{method:'POST',body:JSON.stringify({password:document.getElementById('pw').value})});
|
| 70 |
+
if(!r.success){document.getElementById('err').textContent='口令不正确';return}
|
| 71 |
+
sessionStorage.setItem('biditech_auth','1');
|
| 72 |
+
}
|
| 73 |
+
location.href='index.html';
|
| 74 |
+
}
|
| 75 |
+
document.getElementById('enter').addEventListener('click',enter);
|
| 76 |
+
document.getElementById('pw')&&document.getElementById('pw').addEventListener('keydown',function(e){if(e.key==='Enter')enter()});
|
| 77 |
+
</script>
|
| 78 |
+
</body>
|
| 79 |
+
</html>
|
frontend/index.html
CHANGED
|
@@ -249,8 +249,8 @@
|
|
| 249 |
<body>
|
| 250 |
<aside class="sidebar">
|
| 251 |
<div class="brand">
|
| 252 |
-
<h1>泵站 AI 节能优化</h1>
|
| 253 |
-
<span>Biditech · 展示台</span>
|
| 254 |
</div>
|
| 255 |
<ul class="nav" id="nav">
|
| 256 |
<li data-view="dashboard" class="active"><span class="dot"></span>运行总览大屏</li>
|
|
@@ -264,7 +264,7 @@
|
|
| 264 |
<li data-view="suggest"><span class="dot"></span>AI 优化建议</li>
|
| 265 |
<li data-view="curve"><span class="dot"></span>泵曲线管理</li>
|
| 266 |
</ul>
|
| 267 |
-
<div class="sidebar-foot">数据源:Node-RED / OPC UA<br/>力控 FWebView 嵌入显示</div>
|
| 268 |
</aside>
|
| 269 |
|
| 270 |
<div class="main">
|
|
@@ -1618,7 +1618,22 @@ async function loadConfig() {
|
|
| 1618 |
}
|
| 1619 |
|
| 1620 |
/* ---- 启动 ---- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1621 |
window.addEventListener('load', async () => {
|
|
|
|
| 1622 |
await loadConfig(); // 先确定泵组(数量/性质)
|
| 1623 |
refreshSafetyBar(); // 初始化安全状态条
|
| 1624 |
renderCurrent(); // 先画空曲线族
|
|
|
|
| 249 |
<body>
|
| 250 |
<aside class="sidebar">
|
| 251 |
<div class="brand">
|
| 252 |
+
<h1 id="brandTitle">泵站 AI 节能优化</h1>
|
| 253 |
+
<span id="brandPlant">Biditech · 展示台</span>
|
| 254 |
</div>
|
| 255 |
<ul class="nav" id="nav">
|
| 256 |
<li data-view="dashboard" class="active"><span class="dot"></span>运行总览大屏</li>
|
|
|
|
| 264 |
<li data-view="suggest"><span class="dot"></span>AI 优化建议</li>
|
| 265 |
<li data-view="curve"><span class="dot"></span>泵曲线管理</li>
|
| 266 |
</ul>
|
| 267 |
+
<div class="sidebar-foot" id="brandFoot">数据源:Node-RED / OPC UA<br/>力控 FWebView 嵌入显示</div>
|
| 268 |
</aside>
|
| 269 |
|
| 270 |
<div class="main">
|
|
|
|
| 1618 |
}
|
| 1619 |
|
| 1620 |
/* ---- 启动 ---- */
|
| 1621 |
+
async function applyBranding() {
|
| 1622 |
+
try {
|
| 1623 |
+
const b = await fetch(CONFIG.API_BASE + '/api/branding').then(r => r.json());
|
| 1624 |
+
if (b && b.system_title) document.getElementById('brandTitle').textContent = b.system_title;
|
| 1625 |
+
if (b && b.plant_name) document.getElementById('brandPlant').textContent = b.plant_name;
|
| 1626 |
+
else if (b && b.company) document.getElementById('brandPlant').textContent = b.company;
|
| 1627 |
+
if (b && (b.plant_name || b.system_title)) document.title = (b.plant_name ? b.plant_name + ' · ' : '') + (b.system_title || '节能系统');
|
| 1628 |
+
const foot = [];
|
| 1629 |
+
if (b && b.company) foot.push(b.company);
|
| 1630 |
+
if (b && b.contact_phone) foot.push('电话 ' + b.contact_phone);
|
| 1631 |
+
if (foot.length) document.getElementById('brandFoot').innerHTML = foot.join('<br/>');
|
| 1632 |
+
} catch (e) { /* 后端未连接则保留默认名 */ }
|
| 1633 |
+
}
|
| 1634 |
+
|
| 1635 |
window.addEventListener('load', async () => {
|
| 1636 |
+
applyBranding(); // 品牌名/公司/联系方式(可配置)
|
| 1637 |
await loadConfig(); // 先确定泵组(数量/性质)
|
| 1638 |
refreshSafetyBar(); // 初始化安全状态条
|
| 1639 |
renderCurrent(); // 先画空曲线族
|
frontend/nginx.conf
CHANGED
|
@@ -29,6 +29,8 @@ server {
|
|
| 29 |
# 展示页不缓存(改动即时生效);js 长缓存
|
| 30 |
location = /index.html { add_header Cache-Control "no-store"; }
|
| 31 |
location = /config.html { add_header Cache-Control "no-store"; }
|
|
|
|
|
|
|
| 32 |
location ~* \.js$ { add_header Cache-Control "public, max-age=86400"; }
|
| 33 |
location / { try_files $uri $uri/ /index.html; }
|
| 34 |
}
|
|
|
|
| 29 |
# 展示页不缓存(改动即时生效);js 长缓存
|
| 30 |
location = /index.html { add_header Cache-Control "no-store"; }
|
| 31 |
location = /config.html { add_header Cache-Control "no-store"; }
|
| 32 |
+
location = /home.html { add_header Cache-Control "no-store"; }
|
| 33 |
+
location = / { try_files /home.html =404; add_header Cache-Control "no-store"; }
|
| 34 |
location ~* \.js$ { add_header Cache-Control "public, max-age=86400"; }
|
| 35 |
location / { try_files $uri $uri/ /index.html; }
|
| 36 |
}
|