feat: 实现v3版本的中心机与部署壳拆分登录架构
此提交完成了核心架构改造: 1. 新增钉钉直连接登录链路,使用浏览器本地跳转而非云端中转 2. 实现壳本机会话持久化,重启后不丢失登录态 3. 重构后端API鉴权,支持Bearer Token身份验证 4. 重写ProfilePanel与LoginPage页面样式与交互逻辑 5. 新增文档说明完整的拆分重构方案 主要变更包括: - 新增/auth/exchange、/api/auth/dingtalk等登录相关接口 - 重构plugins/allowed_platforms接口支持新鉴权方式 - 实现云端会话token管理与本地会话落盘 - 替换旧登录页为分屏设计,支持钉钉扫码直连登录
This commit is contained in:
+109
-16
@@ -27,6 +27,7 @@ import re
|
||||
import secrets
|
||||
import sqlite3
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import zipfile
|
||||
from contextlib import asynccontextmanager, contextmanager
|
||||
@@ -470,12 +471,20 @@ def health() -> dict:
|
||||
|
||||
|
||||
@app.get("/api/plugins", response_model=dict)
|
||||
def plugins(account: str = Query(..., description="账号"),
|
||||
x_api_token: str = Header(default="", alias="X-API-Token")) -> dict:
|
||||
"""按账号返回可用插件清单(权限隔离):无权限的账号返回空列表。"""
|
||||
_check_token(x_api_token)
|
||||
if not account.strip():
|
||||
raise HTTPException(400, "account 不能为空")
|
||||
def plugins(account: str = Query(default="", description="账号(旧底座按此传)"),
|
||||
x_api_token: str = Header(default="", alias="X-API-Token"),
|
||||
authorization: str = Header(default="", alias="Authorization")) -> dict:
|
||||
"""按账号返回可用插件清单(权限隔离):无权限的账号返回空列表。
|
||||
|
||||
§2.2:优先用云端会话 token(Authorization: Bearer <token>)解出工号,不再明文传 account;
|
||||
兜底兼容旧底座 `account?` + X-API-Token 的调用方式。
|
||||
"""
|
||||
acct = _cloud_account(authorization)
|
||||
if not acct:
|
||||
_check_token(x_api_token)
|
||||
acct = (account or "").strip()
|
||||
if not acct:
|
||||
raise HTTPException(400, "缺少有效会话或 account")
|
||||
with _db() as conn:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
@@ -485,24 +494,28 @@ def plugins(account: str = Query(..., description="账号"),
|
||||
WHERE ap.account = ?
|
||||
ORDER BY p.id
|
||||
""",
|
||||
(account.strip(),),
|
||||
(acct,),
|
||||
).fetchall()
|
||||
return {"account": account.strip(), "plugins": [PluginOut(**dict(r)).model_dump() for r in rows]}
|
||||
return {"account": acct, "plugins": [PluginOut(**dict(r)).model_dump() for r in rows]}
|
||||
|
||||
|
||||
@app.get("/api/platforms/allowed", response_model=dict)
|
||||
def platforms_allowed(account: str = Query(..., description="账号"),
|
||||
x_api_token: str = Header(default="", alias="X-API-Token")) -> dict:
|
||||
"""按账号返回可登录平台白名单(与插件权限同模式)。"""
|
||||
_check_token(x_api_token)
|
||||
if not account.strip():
|
||||
raise HTTPException(400, "account 不能为空")
|
||||
def platforms_allowed(account: str = Query(default="", description="账号(旧底座按此传)"),
|
||||
x_api_token: str = Header(default="", alias="X-API-Token"),
|
||||
authorization: str = Header(default="", alias="Authorization")) -> dict:
|
||||
"""按账号返回可登录平台白名单(与插件权限同模式)。支持云端会话 token 或旧底座 account 两种身份来源。"""
|
||||
acct = _cloud_account(authorization)
|
||||
if not acct:
|
||||
_check_token(x_api_token)
|
||||
acct = (account or "").strip()
|
||||
if not acct:
|
||||
raise HTTPException(400, "缺少有效会话或 account")
|
||||
with _db() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT platform_id FROM account_platforms WHERE account = ? ORDER BY platform_id",
|
||||
(account.strip(),),
|
||||
(acct,),
|
||||
).fetchall()
|
||||
return {"account": account.strip(), "allowed": [dict(r)["platform_id"] for r in rows]}
|
||||
return {"account": acct, "allowed": [dict(r)["platform_id"] for r in rows]}
|
||||
|
||||
|
||||
def _load_manifest(raw: str) -> dict:
|
||||
@@ -1089,6 +1102,86 @@ def dingtalk_inline_qr(back: str = Query(default="", description="(兼容保留
|
||||
return {"goto": _q(auth_url)}
|
||||
|
||||
|
||||
# ==================== 员工端登录 /auth/exchange(v3 最简方案,壳本机直连接 code) ====================
|
||||
# 安全要点:
|
||||
# 1. 钉钉扫码是浏览器跳转,redirect_uri 固定为壳本机 http://localhost:8799(多壳共用);
|
||||
# 浏览器把 code 直接交给壳,云端不参与中转(无 /auth/dingtalk/* 、无 poll、无内部一次性 code)。
|
||||
# 2. /auth/exchange 是壳登录唯一云端接口:壳把浏览器带回的钉钉 code POST 到此,
|
||||
# 云端用 AppSecret 换身份 → 只验证不建号 → 签发云端会话 token(供壳调 /api/plugins 鉴权,见 §2.2)。
|
||||
# 3. code 一次性、短时效;账号不存在时只验证不建号,返回 exists=False,壳端提示联系管理员。
|
||||
# 说明:本链路独立新增,不改动现有 /api/admin/dingtalk/scan→/cb(后台登录仍走原路)。
|
||||
_CLOUD_TOKEN_TTL = 7 * 24 * 3600 # 云端会话 token 有效期(秒,7 天)
|
||||
_cloud_tokens: dict = {} # token -> {exp, account, nickname};壳持此调云端 API(§2.2)
|
||||
_cloud_lock = threading.Lock()
|
||||
|
||||
|
||||
def _auth_account_lookup(account: str) -> dict:
|
||||
"""仅查询统一账号是否存在(登录链路不建号,建号只在管理员入口 /api/admin/dingtalk/auth)。
|
||||
|
||||
返回 {"exists": bool, "nickname": 账号记录昵称或空},绝不 INSERT accounts。
|
||||
"""
|
||||
if not account.strip():
|
||||
return {"exists": False, "nickname": ""}
|
||||
with _db() as conn:
|
||||
row = conn.execute(
|
||||
"SELECT nickname FROM accounts WHERE account = ?", (account.strip(),)).fetchone()
|
||||
return {"exists": bool(row), "nickname": (row["nickname"] if row else "") or ""}
|
||||
|
||||
|
||||
def _cloud_account(bearer: str) -> str:
|
||||
"""从 Bearer 云端会话 token 解出工号(§2.2);无效/过期/缺失返回空串。
|
||||
|
||||
壳登录经 /auth/exchange 拿到的云端 token,调 /api/plugins 等带此作为身份(代替明文传 account)。
|
||||
"""
|
||||
token = (bearer or "").strip()
|
||||
if token.lower().startswith("bearer "):
|
||||
token = token[7:].strip()
|
||||
if not token:
|
||||
return ""
|
||||
now = time.time()
|
||||
with _cloud_lock:
|
||||
rec = _cloud_tokens.get(token)
|
||||
if rec and rec["exp"] >= now:
|
||||
return rec["account"]
|
||||
if rec: # 过期顺手清理,防内存无限增长
|
||||
_cloud_tokens.pop(token, None)
|
||||
return ""
|
||||
|
||||
|
||||
class AuthExchangeIn(BaseModel):
|
||||
code: str
|
||||
|
||||
|
||||
@app.post("/auth/exchange")
|
||||
def auth_exchange(d: AuthExchangeIn) -> dict:
|
||||
"""壳 → 云端:壳 POST 钉钉授权码 code,换取员工工号 + 云端会话 token。
|
||||
|
||||
只验证不建号:账号不存在时返回 exists=False,壳端提示联系管理员,不建立会话。
|
||||
成功后签发云端会话 token(_cloud_tokens),壳之后调 /api/plugins 等带此 token(§2.2)。
|
||||
"""
|
||||
code = (d.code or "").strip()
|
||||
if not code:
|
||||
raise HTTPException(400, "缺少 code")
|
||||
if not DINGTALK_APP_KEY or not DINGTALK_APP_SECRET:
|
||||
raise HTTPException(503, "未配置钉钉开放平台应用(DINGTALK_APP_KEY / DINGTALK_APP_SECRET)")
|
||||
info = _dingtalk_userinfo(code) # 用 AppSecret 换身份(复用现有实现,只读不建号)
|
||||
account = (info.get("account") or "").strip()
|
||||
if not account:
|
||||
raise HTTPException(401, "扫码未解析到有效账号,请重新扫码")
|
||||
acct = _auth_account_lookup(account) # 只验证不建号
|
||||
token = secrets.token_urlsafe(32)
|
||||
now = time.time()
|
||||
with _cloud_lock:
|
||||
# 惰性清理过期云端会话,防内存无限增长
|
||||
for k in [k for k, v in _cloud_tokens.items() if v["exp"] < now]:
|
||||
_cloud_tokens.pop(k, None)
|
||||
_cloud_tokens[token] = {"exp": now + _CLOUD_TOKEN_TTL, "account": account,
|
||||
"nickname": acct["nickname"] or (info.get("nickname") or "")}
|
||||
return {"token": token,
|
||||
"account": account, "nickname": acct["nickname"] or (info.get("nickname") or ""),
|
||||
"exists": bool(acct["exists"]), "is_admin": False}
|
||||
|
||||
|
||||
class PwdIn(BaseModel):
|
||||
account: str
|
||||
old_password: str
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,320 @@
|
||||
# 重构方案:中心机(云端/后台)与部署壳(员工客户端)拆分 v3
|
||||
|
||||
> 目标:把「服务器管理所有」和「壳只在设备上干活」分开;**中心机离线不影响日常执行,只影响插件更新**。
|
||||
>
|
||||
> v2:钉钉身份换取必须在持有 AppSecret 的云端完成(钉钉仅支持 Authorization Code,无 PKCE/无 secret 模式),登录链路定为"云端换取 + 一次性 code + 壳建本机会话",并补齐机器凭证双因子、插件签名、权限缓存 TTL/吊销。
|
||||
>
|
||||
> v3:细化为**最简可实施方案**——两层架构(云端控制面 + 本地壳执行面),插件保留现有形态不动,执行链路复用现状 `plugin_runner`+`RunContext`+`scheduler`+`winjob`+`hub`。新增内容:登录实现细节(壳本机浏览器直连接 code / state 防 CSRF / userid→工号映射 / `/auth/exchange` 鉴权 / 登出 / 续期)与阶段二触发条件。
|
||||
|
||||
***
|
||||
|
||||
## 0. 前置验证项(先于一切动工,未过则后续设计需重排)
|
||||
|
||||
### 0.0 登录不再依赖云端公网可达(关键前提,已核实)
|
||||
|
||||
**钉钉扫码登录是浏览器跳转,不是服务器回调。** 跳转由**用户本机浏览器**完成,浏览器访问 `http://localhost:8799` 毫无障碍。因此"服务器能出不能进/云端无公网域名"**对登录链路不构成任何障碍**——钉钉根本不访问云端,只把浏览器重定向到本机 localhost 壳。
|
||||
|
||||
- 钉钉官方开放平台文档**明示可用 `http://localhost` 作为 OAuth 回调域名**(示例 `http://localhost:5173`),即 `localhost` 回调平台原生支持,无需公网域名。
|
||||
- 故 §0.0(原"云端必须对钉钉回调可达")**删除**:不再需要公网域名、内网穿透、反代。
|
||||
- AppSecret 仍只在云端:换取动作由壳 POST 云端 `/auth/exchange{code}` 在服务端完成,**不涉及任何公网回调**。
|
||||
|
||||
### 0.0b 钉钉开放平台事实(2026-09 查证)
|
||||
|
||||
1. 登录采用 Authorization Code Grant:`authCode` → `POST /v1.0/oauth2/userAccessToken` 换 access\_token,**必填 clientSecret**;`response_type` 固定 `code`,只此一种响应模式。
|
||||
2. 无公共客户端 / 无 secret / 原生 PKCE 授权模式——**不支持**(网上"钉钉+PKCE"方案是在自有网关段引入 PKCE,不解除 secret 依赖)。
|
||||
3. `redirect_uri` 需在开发者后台**提前登记且与调用一致**(协议/域名/端口/路径字面量一致、大小写及尾斜杠敏感),**`localhost` 可登记**(官方支持);两处须 URL 编码。
|
||||
|
||||
结论:**AppSecret 只能放云端;换 token 由壳 POST 云端完成。** redirect\_uri 登记为**壳本机 `http://localhost:8799`(协议/端口固定)**,多壳共用同一应用、同一回调地址(各壳本机均为 localhost:8799),无需逐壳登记、无需公网域名。
|
||||
|
||||
前置验证清单(全部通过才动工):
|
||||
|
||||
- 钉钉开发者后台「钉钉登录与分享」登记回调域名 `http://localhost:8799`,并验证与授权 URL 的 `redirect_uri` **字面量一致**。
|
||||
- 用户扫码后**浏览器能跳回 `http://localhost:8799`** 且带 `code` + `state` 两参数。
|
||||
- 壳 POST 云端 `/auth/exchange{code}` 后,`code`+`AppSecret` 能换取到 `jobNumber`(现状 `_dingtalk_userinfo` 已验,确认该应用已开取工号权限)。
|
||||
|
||||
***
|
||||
|
||||
## 1. 目标架构
|
||||
|
||||
```
|
||||
云端 = 中心机 (controlplane/,一台服务器,唯一"管理员入口")
|
||||
├─ 账号与授权 哪个员工能用哪些插件 ✅ 现有 /api/plugins?account / admin 后台
|
||||
├─ 插件仓库 zip + plugin.json(版本/manifest) ✅ 现有 packages/ + /api/manifest + /api/pkg
|
||||
├─ 审计/运行记录 ✅ 现有 admin/audit、admin/reports
|
||||
├─ 钉钉身份换取 唯一持有 DINGTALK_APP_KEY/SECRET ✅ /auth/exchange(壳浏览器直连接 code,云端仅换身份)
|
||||
└─ 不做 使用界面 / 跨机调度 / 参数透传 / 长期持员工会话 ← 移除
|
||||
|
||||
本地壳 = 执行端 (webhost/,每台机器一个,唯一"员工入口")
|
||||
├─ 登录 壳会话=员工身份;身份由云端一次性 code 换取建立 ← 链路改造
|
||||
├─ 查 持身份 → 云端换「权限 + 插件目录/schema」
|
||||
├─ 更新 版本比对 → 下载 zip → 验签 → 解压 exe 到本机
|
||||
├─ 运行 本机选插件 → 本机填参 → 起 exe(JSON 进/出) → 本机看日志
|
||||
└─ 上报 结果上报云端审计;离线先本地缓存、联网补报
|
||||
```
|
||||
|
||||
身份边界精确表述:
|
||||
|
||||
- **会话/令牌不出本机**(成立):壳本机会话 cookie 只在壳内有效。
|
||||
- **工号必然到云端**(成立):权限本体的键是工号,壳持工号才能向云端查权限。
|
||||
|
||||
***
|
||||
|
||||
## 2. 关键链路设计
|
||||
|
||||
### 2.1 钉钉登录:壳本机直接接 code(浏览器跳转,非云端中转)
|
||||
|
||||
**机制本质**:钉钉扫码是**浏览器跳转**,不是服务器回调。`redirect_uri` 设为壳本机 `http://localhost:8799`,用户本机浏览器就地把 code 交给壳——**云端不参与中转,无 poll、无 nonce、无回调白名单**。AppSecret 仍在云端,由壳 POST 云端换 token 完成。
|
||||
|
||||
```
|
||||
1. LoginPage 点"钉钉登录"
|
||||
2. 壳后端生成 state(随机,防CSRF),落盘存本地
|
||||
3. 壳打开钉钉授权 URL:
|
||||
https://login.dingtalk.com/oauth2/challenge.htm?redirect_uri=http://localhost:8799/auth/done&...&state=<state>
|
||||
4. 用户扫码确认
|
||||
5. 钉钉让【用户本机浏览器】跳转 → http://localhost:8799/auth/done?code=xxx&state=xxx
|
||||
6. 壳后端接住 code + state,校验 state 与发起时一致(防 CSRF,不一致→拒绝)
|
||||
7. 壳后端 POST 云端 /auth/exchange {code}
|
||||
8. 云端用 code + AppSecret 换 access_token → 拉 job_number/工号/姓名(复用 _dingtalk_userinfo) → 只验证不建号(_auth_account_lookup)
|
||||
9. 云端返回 工号 + 云端会话 token
|
||||
10. 壳建本机会话(壳 SESSION_COOKIE) + 存云端 token → 前端进入插件清单(2.2)
|
||||
```
|
||||
|
||||
- **code 经本机浏览器地址栏落到 localhost 壳**:code 为一次性、60s、单次消费、且落在用户自己的机器,等效标准 OAuth loopback 模式,可接受。
|
||||
- **云端只有一个接口 `/auth/exchange`**:AppSecret 不出云端;那里是本链路唯一"见过 code+工号"的瞬间。
|
||||
- 无需 `client_nonce`(不再有取码方与发起方分离的问题)、无需 `poll`(壳直接拿到 code)、无需回调白名单(回跳地址由钉钉按登记的 localhost 固定,不接受任意参数)。
|
||||
- code 与工号一对一绑定、单次消费、秒级过期,防重放/冒充。
|
||||
|
||||
#### 2.1.1 redirect_uri:一层,固定壳本机 localhost
|
||||
|
||||
- **仅一层**:钉钉 → 壳本机 `http://localhost:8799/auth/done`。无"云端→壳"第二层。
|
||||
- 登记:钉钉开发者后台「钉钉登录与分享」登记回调域名 `http://localhost:8799`(协议/端口固定)。**多壳共用同一应用、同一回调**(各壳本机都是 localhost:8799),无需逐壳登记、无需公网域名。
|
||||
- 校验:`redirect_uri` 与登记处**字面量一致**(协议/域名/端口/路径一致、大小写及尾斜杠敏感),且 URL 编码。
|
||||
- **open-redirect 问题不存在**:回跳地址由钉钉按登记固定为 localhost,不接受任何可注入的"回跳去哪"参数,故无需回调白名单。
|
||||
|
||||
#### 2.1.2 state(防 CSRF,唯一回跳校验)
|
||||
|
||||
- `state`:**壳后端本地生成**(一次性随机串,落盘存本地),发起登录时随授权 URL 传给钉钉;钉钉回调 `code+state` 原样带回,壳校验 `state` 与发起时一致才处理 code;**不一致/缺失/已消费 → 拒绝**,防止攻击者伪造回调把自己的 code 塞进壳会话。
|
||||
- state 只在壳本地生成与校验,云端不持有、不校验(云端只有 `/auth/exchange`)。
|
||||
- **落盘**:壳在发起与接收之间若重启,本地 state 丢失即视为登录失败重新扫码即可;设**登录超时清理**(如 5 分钟未收到回调即丢弃本地 state)。
|
||||
|
||||
#### 2.1.3 userid → 员工工号映射(现状已具备,写清绑定规则)
|
||||
|
||||
- 现状 `_dingtalk_userinfo` 已返回 `account`(优先 `jobNumber`,回退 `userId`/`unionid`),见 [app.py](file:///d:/work/code/Process-Automation/controlplane/app.py#L937-L978) [`_dingtalk_userinfo`](file:///d:/work/code/Process-Automation/controlplane/app.py#L937-L978)。
|
||||
- 账号绑定规则:**账号主键 = 工号**,由管理员入口 `/api/admin/dingtalk/auth`(`find-or-create`)建立。
|
||||
- 换钉钉账号:建议 accounts 表加一列 `dingtalk_uid`(unionid)。扫码时若该 unionid 已绑定某工号则沿用;否则按 `jobNumber` 匹配。避免同/异工号造成散号;散号由管理员后台合并,账号以工号为唯一键。
|
||||
- 若 `jobNumber` 拿不到(权限/配置缺失):回退 `userId`,并要求管理员在后台补绑工号后该账号才可见插件。
|
||||
|
||||
#### 2.1.3b 登录接口不建号(权限边界,重要)
|
||||
|
||||
- **员工登录链路(`/auth/exchange`)只验证、不建号**:壳 POST `/auth/exchange{code}` 云端换取时**不 create 账号**,只在账号已存在时返回工号 + 云端 token。
|
||||
- **建号只发生在管理员入口** `/api/admin/dingtalk/auth`(后台为员工开通,或管理员主动建号)。
|
||||
- 员工首次扫码若工号在 accounts 不存在:登录链路返回"账号未开通,请联系管理员",壳端提示人工开通,**绝不自动建号**。避免"壳能建云端账号"这一隐含越权。
|
||||
- 登录接口因此天然避免"任何扫到钉钉身份的人自建账号"的权限提升面。
|
||||
|
||||
#### 2.1.4 `/auth/exchange` 鉴权
|
||||
|
||||
- 输入:壳 POST `{code}`(钉钉授权码,已由浏览器带到 localhost 壳)。输出:工号 + 云端会话 token。
|
||||
- 一次性 code 短时效(60s) + 单次消费;即使泄漏攻击窗口极小。
|
||||
- 云端用 code + AppSecret 换 access\_token → 拉工号(`_dingtalk_userinfo`)→ **只验证不建号**;工号存在则签发云端会话 token,壳据此建本机会话 + 存云端 token。
|
||||
- 该接口**不建号**:工号不存在时返回 `exists=False`,壳端提示"账号未开通,请联系管理员",不建立会话。
|
||||
|
||||
#### 2.1.4b TTL
|
||||
|
||||
- **code 60 秒**(云端 `/auth/exchange` 消费时限,单次消费)。
|
||||
- **state 5 分钟**(壳本地:发起登录到收到回调的最大间隔,超时丢弃本地 state,重新扫码)。
|
||||
|
||||
#### 2.1.4c 登录页交互路径与 `/auth/done` 路由(新增)
|
||||
|
||||
- **当前窗口跳转,不用新窗口**。`LoginPage.vue` 点"钉钉登录"→ 壳后端生成 state 落盘 → 当前标签页跳转钉钉授权 URL(`redirect_uri=http://localhost:8799/auth/done`)。
|
||||
- **壳新增 `/auth/done` 路由**:钉钉把浏览器跳回 `http://localhost:8799/auth/done?code=xxx&state=xxx`。壳后端:
|
||||
1. 校验 `state` 与本地已发起的一致(不一致→拒绝);
|
||||
2. POST 云端 `/auth/exchange{code}` → 得工号 + 云端 token;
|
||||
3. 建本机会话(`SESSION_COOKIE`)+ 存云端 token → 前端 `window.location` 进插件清单(§2.2)。
|
||||
- `/auth/done` 是本链路唯一浏览器落点,不做其它中转。
|
||||
|
||||
#### 2.1.4d 启动流程与会话检查(默认真实变化:能进插件页就不显示登录页)
|
||||
|
||||
**打开壳的默认落点是插件页,不是登录页。** 只有两种情况会看到登录页:**首次安装(从没登录过)**① 或 **会话过期(超过 7 天没打开,滑动 TTL 超了)**。天天用的人永不重扫。
|
||||
|
||||
```
|
||||
双击壳
|
||||
→ 壳后端启动(FastAPI/8799)
|
||||
→ 前端加载(本地 Vue)
|
||||
→ 前端调壳后端 /auth/status 检查本机会话
|
||||
├─ 会话有效 → 直接进插件页
|
||||
└─ 会话无效/过期 → 进登录页,展示二维码(§2.1 直连接 code)
|
||||
```
|
||||
|
||||
- **`/auth/status`(壳后端新增)**:读本地会话,返回 `{logged_in: true}` 或 `{logged_in: false}`;前端据此定向。
|
||||
- **能否保活与云端在线无关**:会话存壳本地 cookie;云端只在登录时参与一次换 token,换完即忘;云端宕机不影响 7 天内会话有效性。
|
||||
- **联网依赖**:首次登录必须联网(调云端 `/auth/exchange` 换 token);日常使用不查云端、本地直接放行;会话过期后需联网重扫。
|
||||
|
||||
① 注:统一账户早期形态可先"账号+密码"登录,扫码为后续升级;但会话保持/`/auth/status` 逻辑与登录方式无关,先行落地。
|
||||
|
||||
#### 2.1.5 登出
|
||||
|
||||
- 壳:清本地 `SESSION_COOKIE` / session.json 即登出。
|
||||
- 云端:本就不持有员工会话,**无需清**;一次性 code 已消费。钉钉 access\_token 属短期,不强调登出接口,可选在登出时弹钉钉退出授权(可后置)。
|
||||
|
||||
#### 2.1.6 续期
|
||||
|
||||
- 本机会话沿用现有 `SESSION_COOKIE` + **滑动续期**机制(每次有效请求刷新 TTL,如 7 天)。
|
||||
- 续期在壳本地完成,不依赖云端在线;超期未访问需重新扫码。
|
||||
- 无需 refresh\_token/云端续期(会话本来只在壳,不涉及云端会话生命周期)。
|
||||
|
||||
**会话续期 ≠ 权限续期(两个维度,不要混)**:
|
||||
|
||||
```text
|
||||
会话续期:本地滑动 TTL,不查云端(体验优先,见 §2.1.6)
|
||||
权限判定:每次登录/执行时调云端实时判(安全优先,见 §2.2)
|
||||
权限缓存:TTL 7 天,超期降级拒绝敏感插件(离线妥协,见 §2.5)
|
||||
```
|
||||
|
||||
- 会话可以在壳本地无限续期;**但权限是否有效必须由云端判定**。壳离线太久或权限被吊销,会话仍在、权限应失效。
|
||||
- 一句话:**会话可以本地续,权限必须云端判。**
|
||||
|
||||
### 2.2 壳持身份 → 云端查权限与插件目录(两层会话,各司其职)
|
||||
|
||||
**先分清两个不同层级的会话,不要混用一个 cookie**:
|
||||
|
||||
| 会话 | 归属 | 谁签发 / 客户端 | 存了什么 | 谁解 / 校验 | 用途 |
|
||||
|------|------|----------------|---------|------------|------|
|
||||
| 壳本机 `SESSION_COOKIE` | 壳 ↔ 壳前端 | 壳后端 | 壳前端会话 | 壳后端 | 壳内页面鉴权,**不拿去调云端** |
|
||||
| 云端会话 token | 壳后端 ↔ 云端 | 云端(`/auth/exchange` 签发) | 工号 + device | 云端 | 壳调 `/api/plugins`、审计上报 |
|
||||
|
||||
**`/auth/exchange` 除了返回工号,还要签发一个云端会话 token**(不能复用壳本机 SESSION_COOKIE——那是给壳前端用的一层会话)。
|
||||
|
||||
```
|
||||
壳调云端 /api/plugins 带「云端会话 token」(由 /auth/exchange 签发)
|
||||
→ 云端从 token 解出工号 → 按工号白名单返回插件清单(含 fields schema)
|
||||
→ 壳前端通用表单渲染器(现有 PluginPage) 按 fields 渲染本机参数录入
|
||||
```
|
||||
|
||||
- **鉴权机制定为方案 A:云端会话 token**(非明文传 `X-Employee-Id`)。云端从 token 解出工号判权限,工号不可伪造,天然防越权。token 由 `/auth/exchange` 签发并绑定工号与发放给该壳,杜绝"拿 token 跨机冒充"。
|
||||
- 云端会话 token 由 `/auth/exchange` 签发、壳后端持久化;效期与现有会话习惯对齐,超期需重新扫码(不推翻既有会话体系)。
|
||||
- 参数只在壳本机录入、不上云端(除非随结果上报)。
|
||||
|
||||
### 2.3 版本下载 → 验签 → 解压落盘(新增)
|
||||
|
||||
```
|
||||
壳 → GET 云端 /api/manifest → 比对本地已解压版本(本地版本标记)
|
||||
→ 有更新 → GET 云端 /api/pkg/{id}/{version} 下载 zip
|
||||
→ 用内置公开钥校验 顺序签名(Ed25519) → 通过才解压
|
||||
→ 解压到 %LOCALAPPDATA%\37duAutomation\plugins → 写本地版本标记
|
||||
```
|
||||
|
||||
- **签名而非仅 hash**:防云端被入或中间人替换后执行恶意插件。云端用私钥签包,壳内置公钥验签。控件 `controlplane` 现有 `cryptography` Ed25519 依赖(app.py 已引入 Ed25519)。
|
||||
|
||||
### 2.4 执行(沿用、几乎零改动)
|
||||
|
||||
- 复用 `plugin_runner.py`(JSON 参数 stdin 进 / 日志结果 stdout 出)、`scheduler.py`(设备单活)、`winjob.py`(Job 整树托管)、`hub.py`(WS 广播)。
|
||||
- 结果:本机展示 + 上报云端审计。
|
||||
- **审计上报带本机 cookie**(同 `/api/plugins`):云端从 cookie 取工号写审计记录,与权限鉴权同一身份源,防伪造。
|
||||
|
||||
### 2.5 离线与补报(复用现有 + 加 TTL/吊销)
|
||||
|
||||
- 在线:执行前拉权限/目录/版本;命中更新即下载验签解压。
|
||||
- 离线:直接用本机已落盘插件照跑;权限用**缓存清单**兜底。
|
||||
- **权限缓存加 TTL(如 7 天)**:超期未联网则拒绝执行敏感插件;敏感插件可强制在线校验。防止"员工离职、云端已回收权限,但壳离线继续用缓存插件"。
|
||||
- **"敏感插件"定义(写入** **`manifest.json`,新增字段)**:插件作者在 `plugin.json`/`manifest.json` 里显式声明 `"sensitive": true`。敏感插件=涉及文件读写、网络访问、系统命令等副作用/越权面的插件;非敏感=纯计算/纯查询。敏感插件在权限缓存超 TTL 时**拒绝离线执行**;非敏感插件可放行。
|
||||
- 结果/审计离线本地缓存,联网后 `flush_offline_reports` 补报(复用 `licensing.py` 机制)。
|
||||
|
||||
***
|
||||
|
||||
## 3. 复用清单(几乎不动)
|
||||
|
||||
| 资产 | 路径 | 说明 |
|
||||
| :------------------ | :-------------------------------------------------------------------- | :---------------------- |
|
||||
| 云端后台/授权/仓库/审计/OAuth | `controlplane/` | 账号、上传、白名单、audit、钉钉回调全保留 |
|
||||
| 壳前端页面 | `webhost/frontend/src/components/{LoginPage,PluginPage,LogPanel}.vue` | 登录、通用表单、日志界面直接用 |
|
||||
| 壳执行基建 | `plugin_runner.py / scheduler.py / winjob.py / hub.py` | 子进程协议、单活、Job 托管、WS 广播 |
|
||||
| 离线能力 | `licensing.py` | 离线票据缓存 + 延迟补报 |
|
||||
| 权限隔离 + 签名库 | `/api/plugins?account=` + cryptography Ed25519 | 现成 |
|
||||
|
||||
Vue 部署位置(明确):**页面前端跟随壳(本地),云端不放使用界面。** UI 迭代需更新壳(收影响小、通常插件才迭代)。评估点已对齐。
|
||||
|
||||
***
|
||||
|
||||
## 4. 新增 / 改造清单
|
||||
|
||||
| # | 项 | 归属 | 说明 |
|
||||
| :- | :------------------------------------------------------ | :- | :----------------------------------------------------------------- |
|
||||
| A | 云端 `/auth/exchange {code}`(唯一登录接口) | 云端 | 壳 POST code → code+AppSecret 换身份 → 只验证不建号 → 返回工号+云端会话 token(§2.1.4/§2.2) |
|
||||
| B | 壳登录页改打开钉钉授权 + `/auth/done` 直接接 code | 壳 | 改 `LoginPage.vue` + 新增 `/auth/done` 路由 + `main.py`:生成/校验 state、POST `/auth/exchange{code}`、建本机会话 + 存云端 token |
|
||||
| C | 壳下载解压插件落盘 | 壳 | 新增,复用 `licensing.py` 目录约定 |
|
||||
| D | 云端 `/api/plugins` 返回 fields | 云端 | 确保 schema 完整 |
|
||||
| E | 壳离线队列补报 | 壳 | 复用 `licensing.py` |
|
||||
| F | `fields` 支持 file 类型 | 壳 | `PluginPage.vue` 加控件(阶段一可后置) |
|
||||
| G | accounts 表加 `dingtalk_uid` | 云端 | unionid 绑定,避免散号;账号仍以工号为唯一键
|
||||
|
||||
***
|
||||
|
||||
## 5. 迁移步骤(每步可独立验证)
|
||||
|
||||
1. **前置验证**:钉钉后台登记回调域名 `http://localhost:8799` 并验证扫码后浏览器能带 code+state 跳回本机;`/auth/exchange{code}` 能换到工号。
|
||||
2. **登录链路改壳本机直接接 code**(`/auth/done` 收 code + state 校验 + POST `/auth/exchange`,不建号):壳建本机会话、存云端 token。验证:壳上扫码→建会话;AppSecret 只出现在云端;未开通工号提示联系管理员。
|
||||
3. **壳→云端双因子查权限/目录**,前端渲染本地表单。验证:员工只见授权内插件;越权工号被拒。
|
||||
4. **版本下载→验签→解压落盘**。验证:篡改包被拒,新版本运行的是验签通过的包。
|
||||
5. **离线与补报 + 权限缓存 TTL/吊销**。验证:断网跑存量、结果不丢;超 TTL 敏感插件被拒。
|
||||
6. **插件 exe 化(可选阶段二)**,按需打包 exe 由云端分发。
|
||||
|
||||
***
|
||||
|
||||
## 6. 插件形态(阶段化)
|
||||
|
||||
- **壳 venv 形态(已定:预装,方案 A)**:壳安装包**预装真实 venv**(DrissionPage/pyautogui/pywin32/FastAPI 全套打进安装包),**不选 PyInstaller 冻结**。
|
||||
- 理由:最大化**复用现有** **`webhost`** **的 venv 形态**与「插件在壳内 load 源码、动态 import 复用壳依赖」的现状;冻结 exe 下动态 import 受限、插件热更不便。
|
||||
- 代价(写清):安装包较大(几百 MB);**壳升级 = 下载新 venv/新壳版本**,升级带宽成本高于冻结方案。此为可接受取舍——阶段一频繁发壳低、插件频率高,预装最省事。
|
||||
- 兜底:若后续对升级带宽敏感,可在壳升级时做"版本间 venv diff 增量",不推翻预装形态。
|
||||
- **阶段一(本次核心)**:插件维持源码模块在壳内 load,依赖**复用壳 venv**(DrissionPage/pyautogui/pywin32 等已预装),云端只下发 `main.py + manifest.json`;不动骨架。
|
||||
- **阶段一的实质约束(写清,避免插件开发者预期落差)**:壳的 venv **随壳安装包/壳版本分发、版本锁定**。因此插件能用的依赖 = 该版本壳 venv 里已装的库;**插件开发者不能自主加依赖**,加新依赖必须等壳发新版。
|
||||
- 约定:插件 `requirements.txt` 只声明壳 venv 已包含的库;出现新依赖即触发阶段二(见下),而不是让壳临时 pip install。
|
||||
- **阶段二触发条件(何时必须升级,写清)**:**当"插件新增了壳 venv 中没有的依赖"时**,无法本地 pip install(本地不装),壳 venv 又要发新版才能补依赖——此时必须进阶段二:云端 vendor 打包(`pip install --target vendor`)+ 独立/嵌入 Python 运行时 + 插件自包含分发。
|
||||
- 若插件依赖长期固定且都在壳 venv:阶段一可一直用,不必进二。
|
||||
- 若某插件依赖开始演进:进阶段二,按需打包 exe 由云端分发。
|
||||
- **阶段二(exe/自包含)**:build 成 exe 或 vendor 包由云端分发,壳以子进程拉起;schema 仍放 plugin.json(云端 manifest 提供)。exe 化是打包问题,不改变架构判断。
|
||||
|
||||
***
|
||||
|
||||
## 7. 风险分级(按威胁模型分三档)
|
||||
|
||||
按"使用者不懂这些,别过度设防"的取向,风险按三档收敛:**只做防意外的必做项;防主动攻击的降级为可后置(阶段一先简);超出威胁模型的不做。**
|
||||
|
||||
### 7.1 必须做(防意外——低成本、防误操作/误配导致的破坏)
|
||||
|
||||
- **AppSecret 只在云端**:绝不下发到壳/客户端(安全红线),见 §8。
|
||||
- **登录不建号**:员工登录链路 `/auth/exchange` 只验证不建号,建号只在管理员入口,防"随意扫码自建账号"的越权面,见 §2.1.3b。
|
||||
- **state 防 CSRF(唯一回跳校验)**:壳本地校验 DingTalk 带回的 `state` 与发起时一致,不一致/缺失/已消费 → 拒绝,防"攻击者伪造回调把自己的 code 塞进壳会话"。见 §2.1.2。(原"回调白名单"概念随 localhost 固定回跳消失,等价防护由 state 承担。)
|
||||
- **权限缓存 TTL**:离线权限缓存设 TTL,超期拒绝敏感插件,防"员工离职/回收权限后仍离线可跑",见 §2.5。
|
||||
|
||||
> 备注:**钉钉回调登记(§0)**与 **userid→工号映射(§2.1.3)** 是"先于动工的前置约束 + 数据完整性约定",不是风险分级项,单独见 §0 与 §2.1.3。
|
||||
|
||||
### 7.2 可以后置(防主动攻击——阶段一先简,有需要再上)
|
||||
|
||||
- **插件签名**:最终为 Ed25519 签名(防云端被入/中间人替换),壳内置公钥验签。**阶段一可先 hash 即可**;注意 hash 防不了中间人(改包同时改 hash),端到端安全以签名为准,签名阶段二落地。
|
||||
- **防重放签名**:请求加时间戳+签名的重放防护,阶段一可不做(一次性 code + 短时效已覆盖登录主链路)。
|
||||
- **OS 级凭据存储**:云端会话 token 的落盘加密走 OS 凭据库(Trusted Platform / DPAPI),阶段一可先存明文配置文件。
|
||||
|
||||
> 已无 device_token:新链路云端只有 `/auth/exchange`(无 `start`/回调入口可被随机脚本打),故不再需要设备在册校验。
|
||||
|
||||
### 7.3 不做(威胁模型外)
|
||||
|
||||
- **社会工程攻击防护**(诱导扫码、钓鱼授权页等)。
|
||||
- **多因子认证**(钉钉自己就是身份源,MFA 在钉钉侧)。
|
||||
- **设备指纹绑定 / 硬件绑定唯一性**(装过壳的机器即视为可信)。
|
||||
|
||||
### 7.4 其它约束 / 兼容
|
||||
|
||||
- **userid→工号映射**:账号以工号为唯一键,accounts 加 `dingtalk_uid(unionid)` 防散号;登录链路不建号;拿不到工号时回退 userId 并要求后台补绑。见 §2.1.3。
|
||||
- **旧接口兼容**:`/api/admin/dingtalk/*` 改动不影响管理员后台(云端直连)。
|
||||
|
||||
***
|
||||
|
||||
## 8. 明确不做(防范围蔓延)
|
||||
|
||||
- ❌ 不把 AppSecret 下发到任何壳/客户端(安全红线)
|
||||
- ❌ 不做跨机调度 / 任务派发中心
|
||||
- ❌ 不做参数透传(参数只在壳本机,不上云端)
|
||||
- ❌ 不做云端持员工会话 / 把员工钉钉 token 长期驻留云端
|
||||
- ❌ 不做第二套"使用界面"(日常只访问壳,管理员只访问云端后台)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"5b5b138d2d5344ce87bde69ac17a2cb2": ["37036361", 1789294401], "2d53d67eb6e04d5eb564af487c7c437c": ["37036361", 1789294411], "d84bae0c4bd543a79924ea033adfb19a": ["37036361", 1789294893], "0a904b0be8e04ecab1aa3bb9ae15c005": ["37036361", 1789294591], "1879d5b380914d30925433a44f2a6d26": ["37036361", 1789294957], "be2581e6fa394f55986b9b556b3d2d0d": ["37036361", 1789295036]}
|
||||
+151
-15
@@ -14,6 +14,7 @@ import logging
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import secrets
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
@@ -25,7 +26,7 @@ from pathlib import Path
|
||||
from fastapi import FastAPI, HTTPException, Request, Response, WebSocket
|
||||
from pydantic import BaseModel
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from urllib.parse import urlencode
|
||||
|
||||
@@ -75,24 +76,59 @@ DINGTALK_APP_KEY = os.getenv("DINGTALK_APP_KEY", "") or os.getenv("DINGTALK_APPK
|
||||
# 统一账户体系为真源:登录态由后端 cookie 会话维护(账号在统一后端 accounts 表)。
|
||||
# cookie 会话:token -> (account, 活跃时间戳);登录后 set-cookie,进程内保持,供代理转发账号。
|
||||
SESSION_COOKIE = "cp_session"
|
||||
_SESS_TTL = 24 * 3600 # 会话空闲有效期 24h(惰性过期,防长期运行无限累积)
|
||||
# 会话空闲有效期:7 天滑动续期(每次有效请求刷新 TTL;天天用永不重登,超期需重登)
|
||||
_SESS_TTL = 7 * 24 * 3600
|
||||
_SESS: dict[str, tuple] = {}
|
||||
_SESS_LOCK = threading.Lock()
|
||||
# 本机会话落盘文件:重启后端不丢会话(兑现"双击壳直接进插件页、不必每次重登")
|
||||
_SESS_FILE = Path(__file__).resolve().parents[1] / "_cp_sessions.json"
|
||||
|
||||
|
||||
def _sess_persist():
|
||||
"""把本机会话快照落盘为首存(token → [account, 最近活跃ts]),进程重启后仍有效。"""
|
||||
try:
|
||||
with _SESS_LOCK:
|
||||
_payload = {t: [a, int(_ts)] for t, (a, _ts) in _SESS.items()}
|
||||
_SESS_FILE.write_text(json.dumps(_payload, ensure_ascii=False), encoding="utf-8")
|
||||
except OSError as _exc: # noqa: BLE001
|
||||
_LOGGER.warning("本机会话持久化失败: %s", _exc)
|
||||
|
||||
|
||||
def _sess_load():
|
||||
"""启动时从磁盘恢复本机会话(惰性丢弃已过期条)。"""
|
||||
if not _SESS_FILE.is_file():
|
||||
return
|
||||
try:
|
||||
_raw = json.loads(_SESS_FILE.read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError):
|
||||
return
|
||||
_now = time.time()
|
||||
with _SESS_LOCK:
|
||||
for _t, _it in (_raw or {}).items():
|
||||
try:
|
||||
_a, _ts = _it[0], float(_it[1])
|
||||
except (KeyError, IndexError, TypeError, ValueError):
|
||||
continue
|
||||
if _now - _ts <= _SESS_TTL:
|
||||
_SESS[_t] = (_a, _ts)
|
||||
|
||||
|
||||
def _sess_account(request) -> str:
|
||||
"""从请求 cookie 会话解析当前登录账号;未登录/过期返回空串(过期顺手清理)。"""
|
||||
"""从请求 cookie 会话解析当前登录账号;未登录/过期返回空串(过期顺手清理并落盘)。"""
|
||||
token = request.cookies.get(SESSION_COOKIE, "")
|
||||
account = ""
|
||||
with _SESS_LOCK:
|
||||
item = _SESS.get(token)
|
||||
if not item:
|
||||
return ""
|
||||
account, ts = item
|
||||
if time.time() - ts > _SESS_TTL:
|
||||
_SESS.pop(token, None)
|
||||
return ""
|
||||
_SESS[token] = (account, time.time()) # 滑动续期
|
||||
return account
|
||||
if item:
|
||||
_account, _ts = item
|
||||
if time.time() - _ts <= _SESS_TTL:
|
||||
_SESS[token] = (_account, time.time()) # 滑动续期
|
||||
account = _account
|
||||
else:
|
||||
_SESS.pop(token, None)
|
||||
if account:
|
||||
_sess_persist() # 滑动续期也落盘,重启后仍有效
|
||||
return account
|
||||
|
||||
|
||||
def _require_login(request: Request) -> str:
|
||||
@@ -103,6 +139,9 @@ def _require_login(request: Request) -> str:
|
||||
return account
|
||||
|
||||
|
||||
_sess_load() # 启动即恢复本机会话(重启后端不丢会话)
|
||||
|
||||
|
||||
# 平台登录态:标签/展示名来自 auth,在线状态实时校验(非内存假状态)
|
||||
PLATFORMS: dict = {p["id"]: {"id": p["id"], "label": p["label"]}
|
||||
for p in platform_auth.platforms()}
|
||||
@@ -240,14 +279,22 @@ app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], all
|
||||
|
||||
@app.get("/api/admin/me")
|
||||
def admin_me(request: Request) -> dict:
|
||||
"""当前登录账号是否为管理员(会话 cookie)。统一后端不可达时视为非管理员。"""
|
||||
"""当前登录账号是否管理员(会话 cookie)。
|
||||
|
||||
账号一律以**壳本机会话**为准(登录即有效);is_admin/部门 尽量从云端补齐,
|
||||
云端未授信 X-Admin-User(未配 CONTROLPLANE_TOKEN)或不可达时,仅降级 is_admin=False,
|
||||
不影响员工正常进入插件页(前端以 account 非空判登录)。
|
||||
"""
|
||||
account = _sess_account(request)
|
||||
if not account:
|
||||
return {"account": "", "is_admin": False}
|
||||
return {"account": "", "is_admin": False, "dept": "", "nickname": ""}
|
||||
try:
|
||||
return _cp_call("GET", "/api/admin/me", headers=_cp_headers(request))
|
||||
r = _cp_call("GET", "/api/admin/me", headers=_cp_headers(request))
|
||||
if r.get("account") == account:
|
||||
return r
|
||||
except HTTPException:
|
||||
return {"account": account, "is_admin": False}
|
||||
pass
|
||||
return {"account": account, "is_admin": False, "dept": "", "nickname": ""}
|
||||
|
||||
|
||||
class _LoginIn(BaseModel):
|
||||
@@ -271,6 +318,7 @@ def admin_login(b: _LoginIn, response: Response) -> dict:
|
||||
token = uuid.uuid4().hex
|
||||
with _SESS_LOCK:
|
||||
_SESS[token] = (b.account.strip(), time.time())
|
||||
_sess_persist()
|
||||
response.set_cookie(SESSION_COOKIE, token, httponly=True, samesite="lax")
|
||||
# 登录成功即联网同步该账号的离线授权票据 + 管控清单 + 中心机公钥(供离线运行)
|
||||
if CONTROLPLANE_URL:
|
||||
@@ -308,6 +356,7 @@ def _dingtalk_establish(account: str, nickname: str, dingtalk_uid: str, response
|
||||
token = uuid.uuid4().hex
|
||||
with _SESS_LOCK:
|
||||
_SESS[token] = (acct, time.time())
|
||||
_sess_persist()
|
||||
response.set_cookie(SESSION_COOKIE, token, httponly=True, samesite="lax")
|
||||
if CONTROLPLANE_URL:
|
||||
try:
|
||||
@@ -355,6 +404,92 @@ def admin_dingtalk_inline_qr(request: Request) -> dict:
|
||||
headers=({"X-API-Token": CONTROLPLANE_TOKEN} if CONTROLPLANE_TOKEN else {}))
|
||||
|
||||
|
||||
# ==================== v3 钉钉直连接登录:/api/auth/dingtalk + /auth/done(§2.1,待 §0 验证后实测) ====================
|
||||
# 浏览器跳转模型:壳生成 state → 打开钉钉授权URL(redirect_uri=http://localhost:8799/auth/done)
|
||||
# → 用户本机浏览器带回 code+state → 壳校验 state → POST 云端 /auth/exchange{code} 换工号+云端token → 建本机会话。
|
||||
# 云端只参与换 token,AppSecret 不出云端;会话存本机、重启不掉(见上方 _SESS 持久化)。
|
||||
_LOGIN_STATE_TTL = 5 * 60 # state 有效期(秒)
|
||||
_LOGIN_STATES: dict[str, float] = {} # state -> expiry(待回跳校验)
|
||||
_LOGIN_LOCK = threading.Lock()
|
||||
# account -> 最近云端会话 token(7 天,供壳后续调 /api/plugins 用 Bearer,见 §2.2)
|
||||
_ACCT_CLOUD_TOKEN: dict[str, str] = {}
|
||||
|
||||
|
||||
def _login_state_new() -> str:
|
||||
with _LOGIN_LOCK:
|
||||
_now = time.time()
|
||||
for s in [s for s, e in _LOGIN_STATES.items() if e < _now]:
|
||||
_LOGIN_STATES.pop(s, None)
|
||||
state = secrets.token_urlsafe(24)
|
||||
_LOGIN_STATES[state] = _now + _LOGIN_STATE_TTL
|
||||
return state
|
||||
|
||||
|
||||
def _login_state_take(state: str) -> bool:
|
||||
with _LOGIN_LOCK:
|
||||
exp = _LOGIN_STATES.pop(state, None)
|
||||
return bool(exp and exp >= time.time())
|
||||
|
||||
|
||||
def _auth_done_page(text: str) -> HTMLResponse:
|
||||
return HTMLResponse(f"""<!doctype html><html><head><meta charset="utf-8"><title>登录</title></head>
|
||||
<body style="font-family:sans-serif;text-align:center;padding:60px">
|
||||
<p>{text}</p><p><a href="/">返回</a></p></body></html>""")
|
||||
|
||||
|
||||
@app.get("/api/auth/dingtalk")
|
||||
def auth_dingtalk_url() -> dict:
|
||||
"""生成并返回钉钉扫码授权 URL(redirect_uri=本机 /auth/done)。前端「钉钉登录」当前窗口跳转该 URL。"""
|
||||
if not DINGTALK_APP_KEY:
|
||||
raise HTTPException(503, "未配置钉钉开放平台应用(DINGTALK_APP_KEY)")
|
||||
if not CONTROLPLANE_URL:
|
||||
raise HTTPException(503, "未配置中心机地址(CONTROLPLANE_URL)")
|
||||
state = _login_state_new()
|
||||
redirect_uri = f"http://localhost:{PORT}/auth/done"
|
||||
login_url = "https://login.dingtalk.com/oauth2/challenge.htm?" + urlencode({
|
||||
"redirect_uri": redirect_uri,
|
||||
"response_type": "code",
|
||||
"client_id": DINGTALK_APP_KEY,
|
||||
"scope": "openid",
|
||||
"prompt": "consent",
|
||||
"state": state})
|
||||
return {"url": login_url, "state": state}
|
||||
|
||||
|
||||
@app.get("/auth/done")
|
||||
def auth_done(code: str = "", state: str = "", error: str = "") -> Response:
|
||||
"""钉钉回跳落点(浏览器):收 code+state → 校验 state → 云端 /auth/exchange 换工号 → 建本机会话。
|
||||
|
||||
成功后写会话 cookie 并 302 回主页;任何失败给 HTML 提示,不建立会话。
|
||||
"""
|
||||
if error:
|
||||
return _auth_done_page("钉钉登录被取消或失败,请返回重试。")
|
||||
if not (code and state) or not _login_state_take(state):
|
||||
return _auth_done_page("登录状态无效或已过期,请返回重新扫码。")
|
||||
try:
|
||||
info = _cp_call("POST", "/auth/exchange", json={"code": code})
|
||||
except HTTPException as e:
|
||||
return _auth_done_page(f"登录失败:{e.detail}")
|
||||
account = (info.get("account") or "").strip()
|
||||
if not account or not info.get("exists"):
|
||||
return _auth_done_page("账号未开通或未解析到有效工号,请联系管理员。")
|
||||
# 建本机会话(写内存+落盘+set-cookie),并存云端 token 供后续调云端 API(§2.2)。
|
||||
_token = uuid.uuid4().hex
|
||||
with _SESS_LOCK:
|
||||
_SESS[_token] = (account, time.time())
|
||||
_sess_persist()
|
||||
if info.get("token"):
|
||||
_ACCT_CLOUD_TOKEN[account] = info["token"]
|
||||
resp = RedirectResponse("/")
|
||||
resp.set_cookie(SESSION_COOKIE, _token, httponly=True, samesite="lax")
|
||||
if CONTROLPLANE_URL:
|
||||
try:
|
||||
_sync_licensing(account)
|
||||
except Exception as _exc: # noqa: BLE001 同步失败不影响登录
|
||||
_LOGGER.warning("登录后同步离线授权票据失败:%s", _exc)
|
||||
return resp
|
||||
|
||||
|
||||
# ==================== 钉钉真实扫码:扫码URL + 静默回调页 ====================
|
||||
# 扫码 URL 指向中心机 /api/admin/dingtalk/scan(back 回跳到本机 /cb);
|
||||
# 扫码成功 → 中心机 /cb 302 回本机 /cb?account=&nickname= → 本页静默调 dingtalk/login 建会话
|
||||
@@ -407,6 +542,7 @@ def admin_logout(request: Request, response: Response) -> dict:
|
||||
token = request.cookies.get(SESSION_COOKIE, "")
|
||||
with _SESS_LOCK:
|
||||
_SESS.pop(token, None)
|
||||
_sess_persist()
|
||||
response.delete_cookie(SESSION_COOKIE)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@@ -174,19 +174,23 @@ function showToast(msg, type = 'info') {
|
||||
}
|
||||
|
||||
async function checkSession() {
|
||||
// 已在本地标记登录:与后端会话 cookie 是否一致(后端重启会失效,此时回登录页)
|
||||
if (!store.current) return
|
||||
// 登录态一律以**后端会话 cookie** 为准(钉钉扫码/账号登录/后端重启后均从 admin/me 判定),
|
||||
// 不再以 localStorage 的 cp_account 早退——否则全新扫码流程(未写过 cp_account)回跳后无法进入插件页。
|
||||
try {
|
||||
const me = await adminMe()
|
||||
if (!me.account) { store.current = ''; store.isAdmin = false; store.dept = ''; store.nickname = '' }
|
||||
else {
|
||||
store.isAdmin = !!me.is_admin
|
||||
store.dept = me.dept || ''
|
||||
store.nickname = me.nickname || ''
|
||||
// 会话有效:补拉插件清单(未登录时 meta 不返回插件)
|
||||
await refreshMeta()
|
||||
if (!me.account) {
|
||||
store.current = ''; store.isAdmin = false; store.dept = ''; store.nickname = ''
|
||||
try { localStorage.removeItem('cp_account') } catch (_) {}
|
||||
return
|
||||
}
|
||||
} catch (_) { /* 后端 down:暂保持本地态 */ }
|
||||
store.current = me.account
|
||||
store.isAdmin = !!me.is_admin
|
||||
store.dept = me.dept || ''
|
||||
store.nickname = me.nickname || ''
|
||||
try { localStorage.setItem('cp_account', me.account) } catch (_) {}
|
||||
// 会话有效:补拉插件清单(未登录时 meta 不返回插件)
|
||||
await refreshMeta()
|
||||
} catch (_) { /* 后端 down:无法校验,保持现状(可能为登录页或本地态) */ }
|
||||
}
|
||||
|
||||
async function refreshMeta() {
|
||||
|
||||
@@ -56,6 +56,10 @@ export async function adminDingtalkLogin(account, nickname, dingtalk_uid = '') {
|
||||
export async function adminDingtalkQr() {
|
||||
return j('/api/admin/dingtalk/qr')
|
||||
}
|
||||
// v3 钉钉直连接登录:生成钉钉授权 URL(redirect_uri=本机 /auth/done),前端当前窗口跳转到该 URL
|
||||
export async function authDingtalk() {
|
||||
return j('/api/auth/dingtalk')
|
||||
}
|
||||
// 内嵌二维码(DDLogin):拿 goto 参数 + 用 loginTmpCode 登录
|
||||
export async function adminDingtalkInlineQr() {
|
||||
return j('/api/admin/dingtalk/inline_qr')
|
||||
|
||||
@@ -1,57 +1,78 @@
|
||||
<template>
|
||||
<div class="login">
|
||||
<i class="blob b1"></i>
|
||||
<i class="blob b2"></i>
|
||||
<i class="blob b3"></i>
|
||||
|
||||
<div class="card">
|
||||
<div class="brand">
|
||||
<span class="logo">37</span>
|
||||
<div class="brand-meta">
|
||||
<strong>{{ appName || '37du 业务场景工具集' }}</strong>
|
||||
<span>统一账户登录</span>
|
||||
<div class="stage">
|
||||
<!-- 左:品牌叙事面板 -->
|
||||
<aside class="panel">
|
||||
<div class="panel-top">
|
||||
<span class="mark">37</span>
|
||||
<span class="word">{{ appName || '业务场景工具集' }}</span>
|
||||
<span class="mono panel-code">{{ code }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-form label-position="top" @submit.prevent="doLogin">
|
||||
<el-form-item label="账号">
|
||||
<el-input
|
||||
v-model="account"
|
||||
placeholder="账号"
|
||||
autocomplete="username"
|
||||
size="large"
|
||||
:prefix-icon="User"
|
||||
clearable
|
||||
@keyup.enter="doLogin"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码">
|
||||
<el-input
|
||||
v-model="password"
|
||||
type="password"
|
||||
placeholder="密码"
|
||||
autocomplete="current-password"
|
||||
size="large"
|
||||
:prefix-icon="Lock"
|
||||
show-password
|
||||
@keyup.enter="doLogin"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-button type="primary" size="large" class="primary" :loading="busy" @click="doLogin">
|
||||
{{ busy ? '校验中…' : '登 录' }}
|
||||
</el-button>
|
||||
</el-form>
|
||||
<div class="panel-mid">
|
||||
<h1 class="headline">一处登录,<br />驱动所有业务场景。</h1>
|
||||
<p class="slogan">考勤 · 审批 · 数据导出 · 定时任务<br />装好即用,扫码即入。</p>
|
||||
|
||||
<div class="divider"><span>或使用钉钉登录</span></div>
|
||||
<el-button size="large" class="dingtalk" :loading="dingBusy" :icon="ChatDotRound" @click="openDing">钉钉扫码登录</el-button>
|
||||
<!-- 内嵌二维码:本页内渲染钉钉二维码,扫码即登录(不弹浏览器) -->
|
||||
<div v-if="inlineOpen" class="inline-qr">
|
||||
<div ref="qrBoxEl" class="qr-box"><div id="ding_qr_container"></div></div>
|
||||
<p class="ding-tip">用钉钉 App 扫码,自动登录 / 自动建号(新账号首次登录请改密)</p>
|
||||
<div class="qr-actions">
|
||||
<el-link type="primary" :underline="false" @click="openDingWindow">改用浏览器窗口授权</el-link>
|
||||
<div class="nodes">
|
||||
<div v-for="(n, i) in nodes" :key="n.label" class="node" :class="{ act: n.act }">
|
||||
<span class="n-idx mono">0{{ i + 1 }}</span>
|
||||
<span class="n-txt">{{ n.label }}</span>
|
||||
<i class="n-dot"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel-foot mono">{{ foot }}</div>
|
||||
</aside>
|
||||
|
||||
<!-- 右:认证面板 -->
|
||||
<section class="auth">
|
||||
<div class="auth-head">
|
||||
<span class="mono auth-index">AUTH / 01</span>
|
||||
<h2 class="auth-title">欢迎回来</h2>
|
||||
<p class="auth-sub">使用统一账号或钉钉扫码登录</p>
|
||||
</div>
|
||||
|
||||
<el-form label-position="top" @submit.prevent="doLogin">
|
||||
<el-form-item label="账号">
|
||||
<el-input
|
||||
v-model="account"
|
||||
placeholder="账号"
|
||||
autocomplete="username"
|
||||
size="large"
|
||||
:prefix-icon="User"
|
||||
clearable
|
||||
@keyup.enter="doLogin"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码">
|
||||
<el-input
|
||||
v-model="password"
|
||||
type="password"
|
||||
placeholder="密码"
|
||||
autocomplete="current-password"
|
||||
size="large"
|
||||
:prefix-icon="Lock"
|
||||
show-password
|
||||
@keyup.enter="doLogin"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-button type="primary" size="large" class="primary" :loading="busy" @click="doLogin">
|
||||
{{ busy ? '校验中…' : '登 录' }}
|
||||
</el-button>
|
||||
</el-form>
|
||||
|
||||
<div class="divider"><span>或使用钉钉登录</span></div>
|
||||
<el-button size="large" class="dingtalk" :loading="dingBusy" :icon="ChatDotRound" @click="openDing">钉钉扫码登录</el-button>
|
||||
<!-- 内嵌二维码:本页内渲染钉钉二维码,扫码即登录(不弹浏览器) -->
|
||||
<div v-if="inlineOpen" class="inline-qr">
|
||||
<div ref="qrBoxEl" class="qr-box"><div id="ding_qr_container"></div></div>
|
||||
<p class="ding-tip">用钉钉 App 扫码,自动登录 / 自动建号(新账号首次登录请改密)</p>
|
||||
<div class="qr-actions">
|
||||
<el-link type="primary" :underline="false" @click="openDingWindow">改用浏览器窗口授权</el-link>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- 真实钉钉扫码(配置了开放平台应用时 window.open 扫码页;否则回落到工号录入) -->
|
||||
@@ -77,7 +98,7 @@
|
||||
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { User, Lock, ChatDotRound } from '@element-plus/icons-vue'
|
||||
import { adminLogin, adminDingtalkLogin, adminDingtalkQr, adminPassword, adminDingtalkInlineQr, adminDingtalkInlineLogin } from '../api'
|
||||
import { adminLogin, adminDingtalkLogin, adminDingtalkQr, adminPassword, adminDingtalkInlineQr, adminDingtalkInlineLogin, authDingtalk } from '../api'
|
||||
|
||||
const props = defineProps({ appName: { type: String, default: '' } })
|
||||
const emit = defineEmits(['ok'])
|
||||
@@ -96,6 +117,16 @@ const qrBoxEl = ref(null)
|
||||
const dingGoto = ref('')
|
||||
let ddMsgHandler = null
|
||||
|
||||
/* ---------- 蓝本展示数据(纯装饰,无逻辑) ---------- */
|
||||
const nodes = [
|
||||
{ label: '统一身份与权限', act: true },
|
||||
{ label: '插件仓库与更新', act: true },
|
||||
{ label: '执行调度与日志' },
|
||||
{ label: '离线兜底运行' },
|
||||
]
|
||||
const code = 'v0.31.0'
|
||||
const foot = '37DU AUTOMATION · SERVICE SHELL · 2026'
|
||||
|
||||
onMounted(async () => {
|
||||
try { const r = await adminDingtalkQr(); dingUrl.value = r.url || '' } catch (_) {}
|
||||
})
|
||||
@@ -116,18 +147,22 @@ async function doLogin() {
|
||||
}
|
||||
|
||||
async function openDing() {
|
||||
// 优先内嵌二维码:本页内渲染钉钉二维码,扫码即登录;失败则回落浏览器窗口授权 / 工号录入。
|
||||
if (dingBusy.value) return
|
||||
dingBusy.value = true
|
||||
// v3 钉钉直连接登录:壳后端生成授权 URL(redirect_uri=本机 /auth/done),当前窗口跳转钉钉。
|
||||
try {
|
||||
const r = await adminDingtalkInlineQr()
|
||||
if (r && r.goto) {
|
||||
dingGoto.value = r.goto
|
||||
inlineOpen.value = true
|
||||
await nextTick()
|
||||
loadDdLogin()
|
||||
const r = await authDingtalk()
|
||||
if (r && r.url) {
|
||||
window.location.href = r.url // 当前窗口跳转;扫码后浏览器跳回 /auth/done → 云端换身份 → 回主页
|
||||
return
|
||||
}
|
||||
} catch (_) { /* 中心机未配置钉钉应用或无中心机时走回退 */ }
|
||||
openDingWindow()
|
||||
} catch (e) {
|
||||
ElMessage.error('钉钉登录不可用:' + (e.message || e))
|
||||
}
|
||||
dingBusy.value = false
|
||||
// 兜底:未配置钉钉应用时回落到工号录入
|
||||
if (!dingAccount.value) dingAccount.value = account.value.trim()
|
||||
dingOpen.value = true
|
||||
}
|
||||
|
||||
function openDingWindow() {
|
||||
@@ -239,117 +274,216 @@ async function promptChangePwd(acc, r) {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* ================= 精密蓝本 · 分屏编辑式登录 =================
|
||||
暖纸底 + 墨色 + 赭红强调,发丝线 / 索引编号 / 制图节点营造"精密、可靠"。 */
|
||||
.login {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
height: 100%;
|
||||
padding: 24px;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: radial-gradient(1100px 520px at 50% -12%, rgba(59, 108, 255, .07), transparent 62%);
|
||||
}
|
||||
|
||||
/* ---------- 背景光斑 ---------- */
|
||||
.blob {
|
||||
position: absolute;
|
||||
border-radius: 50%;
|
||||
filter: blur(90px);
|
||||
opacity: .38;
|
||||
pointer-events: none;
|
||||
will-change: transform;
|
||||
animation: float 18s ease-in-out infinite;
|
||||
}
|
||||
.b1 { width: 460px; height: 460px; background: #a8c1ff; top: -150px; right: -110px; }
|
||||
.b2 { width: 400px; height: 400px; background: #9fe3c8; bottom: -140px; left: -90px; animation-delay: -6s; }
|
||||
.b3 { width: 280px; height: 280px; background: #ffd6a8; bottom: 18%; right: 10%; opacity: .22; animation-delay: -12s; }
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
|
||||
50% { transform: translate3d(0, -22px, 0) scale(1.06); }
|
||||
}
|
||||
|
||||
/* ---------- 卡片 ---------- */
|
||||
.card {
|
||||
width: 380px;
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
overflow: auto;
|
||||
padding: 42px 32px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
padding: 32px 32px 26px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 20px;
|
||||
background: var(--surface);
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: #eeece4;
|
||||
background-image:
|
||||
radial-gradient(1200px 700px at 82% -8%, rgba(208, 74, 36, .07), transparent 55%),
|
||||
radial-gradient(1000px 700px at 6% 108%, rgba(32, 34, 38, .06), transparent 55%);
|
||||
font-family: var(--font-body);
|
||||
color: #17181a;
|
||||
}
|
||||
/* 全屏细网格 */
|
||||
.login::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
background-image:
|
||||
linear-gradient(rgba(23, 24, 26, .045) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(23, 24, 26, .045) 1px, transparent 1px);
|
||||
background-size: 52px 52px;
|
||||
-webkit-mask-image: radial-gradient(circle at 50% 42%, #000, transparent 74%);
|
||||
mask-image: radial-gradient(circle at 50% 42%, #000, transparent 74%);
|
||||
}
|
||||
|
||||
.mono { font-family: var(--font-mono); letter-spacing: .04em; }
|
||||
|
||||
/* ---------- 舞台 ---------- */
|
||||
.stage {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
width: min(1080px, 100%);
|
||||
display: grid;
|
||||
grid-template-columns: 1.08fr 1fr;
|
||||
min-height: 600px;
|
||||
border-radius: 24px;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgba(23, 24, 26, .09);
|
||||
box-shadow:
|
||||
0 24px 60px -26px rgba(24, 39, 75, .34),
|
||||
0 2px 10px -3px rgba(24, 39, 75, .08);
|
||||
animation: rise .5s cubic-bezier(.22, 1, .36, 1) both;
|
||||
0 50px 120px -48px rgba(23, 24, 26, .5),
|
||||
0 6px 24px -8px rgba(23, 24, 26, .14);
|
||||
animation: rise .6s cubic-bezier(.22, 1, .36, 1) both;
|
||||
}
|
||||
|
||||
@keyframes rise {
|
||||
from { opacity: 0; transform: translateY(14px) scale(.985); }
|
||||
from { opacity: 0; transform: translateY(18px) scale(.985); }
|
||||
to { opacity: 1; transform: none; }
|
||||
}
|
||||
|
||||
/* ---------- 品牌区 ---------- */
|
||||
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 2px; }
|
||||
|
||||
.logo {
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
flex: none;
|
||||
border-radius: 12px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: var(--primary-grad);
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
font-weight: 800;
|
||||
letter-spacing: .02em;
|
||||
box-shadow: 0 6px 16px -5px rgba(59, 108, 255, .65);
|
||||
/* ---------- 左:品牌叙事面板 ---------- */
|
||||
.panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
padding: 42px 46px 36px;
|
||||
color: #eceadf;
|
||||
background:
|
||||
radial-gradient(560px 420px at 110% -10%, rgba(208, 74, 36, .28), transparent 60%),
|
||||
radial-gradient(460px 380px at -12% 112%, rgba(90, 98, 110, .35), transparent 62%),
|
||||
#1a1c1f;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.brand-meta { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
|
||||
.brand-meta strong {
|
||||
font-size: 15px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
.panel::after { /* 左侧制图导轨 */
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; bottom: 0; left: 22px;
|
||||
width: 1px;
|
||||
background: linear-gradient(rgba(236, 234, 223, .16), rgba(236, 234, 223, .02));
|
||||
}
|
||||
.brand-meta span { font-size: 11.5px; color: var(--text-faint); letter-spacing: .02em; }
|
||||
.panel-top { display: flex; align-items: center; gap: 12px; }
|
||||
.mark {
|
||||
width: 40px; height: 40px; flex: none;
|
||||
display: grid; place-items: center;
|
||||
border-radius: 10px;
|
||||
background: #d04a24;
|
||||
color: #fdfbf4;
|
||||
font-weight: 800; font-size: 15px; letter-spacing: .01em;
|
||||
box-shadow: 0 8px 22px -6px rgba(208, 74, 36, .6);
|
||||
}
|
||||
.word { font-size: 14px; font-weight: 600; letter-spacing: .02em; }
|
||||
.panel-code { margin-left: auto; font-size: 11px; opacity: .5; }
|
||||
|
||||
.panel-mid { padding: 8px 12px 0 0; }
|
||||
.headline {
|
||||
margin: 0 0 18px;
|
||||
font-size: 33px;
|
||||
line-height: 1.24;
|
||||
font-weight: 700;
|
||||
letter-spacing: .005em;
|
||||
}
|
||||
.headline::after {
|
||||
content: '';
|
||||
display: block;
|
||||
width: 34px; height: 3px; margin-top: 22px;
|
||||
background: #d04a24;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.slogan { margin: 22px 0 34px; font-size: 13.5px; line-height: 1.95; opacity: .62; }
|
||||
|
||||
.nodes { display: flex; flex-direction: column; gap: 20px; }
|
||||
.node { display: flex; align-items: center; gap: 14px; }
|
||||
.n-idx { width: 30px; font-size: 12px; opacity: .45; }
|
||||
.n-txt { font-size: 14.5px; letter-spacing: .01em; color: rgba(236, 234, 223, .72); }
|
||||
.node.act .n-txt { color: #f3f1e6; font-weight: 600; }
|
||||
.n-dot {
|
||||
width: 7px; height: 7px; border-radius: 50%;
|
||||
margin-left: auto;
|
||||
background: #2a2d31;
|
||||
border: 1px solid rgba(236, 234, 223, .22);
|
||||
}
|
||||
.node.act .n-dot {
|
||||
background: #d04a24;
|
||||
box-shadow: 0 0 0 4px rgba(208, 74, 36, .22);
|
||||
border-color: transparent;
|
||||
}
|
||||
.panel-foot { font-size: 10.5px; opacity: .38; letter-spacing: .12em; }
|
||||
|
||||
/* ---------- 右:认证面板 ---------- */
|
||||
.auth {
|
||||
background: #f6f4ec;
|
||||
padding: 46px 50px 40px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
.auth-head { margin-bottom: 26px; }
|
||||
.auth-index { font-size: 11px; color: #d04a24; letter-spacing: .16em; }
|
||||
.auth-title { margin: 10px 0 6px; font-size: 24px; font-weight: 700; letter-spacing: .01em; }
|
||||
.auth-sub { margin: 0; font-size: 13px; color: #6c6e74; }
|
||||
|
||||
/* ---------- 表单 ---------- */
|
||||
.auth :deep(.el-form-item) { margin-bottom: 20px; }
|
||||
.auth :deep(.el-form-item__label) {
|
||||
font-size: 12.5px; color: #4a4b50; font-weight: 600;
|
||||
padding-bottom: 7px;
|
||||
}
|
||||
.auth :deep(.el-input__wrapper) {
|
||||
border-radius: 8px;
|
||||
background: #fbfaf5;
|
||||
box-shadow: 0 0 0 1px #ded9ca inset;
|
||||
padding: 2px 12px;
|
||||
transition: box-shadow .2s, background-color .2s;
|
||||
}
|
||||
.auth :deep(.el-input__wrapper:hover) { box-shadow: 0 0 0 1px #cdc7b4 inset; }
|
||||
.auth :deep(.el-input__wrapper.is-focus) {
|
||||
background: #fff;
|
||||
box-shadow: 0 0 0 1.5px #d04a24 inset, 0 8px 22px -12px rgba(208, 74, 36, .5);
|
||||
}
|
||||
.auth :deep(.el-input__inner) { color: #17181a; height: 44px; }
|
||||
|
||||
/* ---------- 主按钮 ---------- */
|
||||
.primary { width: 100%; margin-top: 2px; letter-spacing: .06em; font-weight: 600; }
|
||||
.primary {
|
||||
width: 100%; height: 46px; margin-top: 2px;
|
||||
border: none; border-radius: 8px;
|
||||
background: #17181a;
|
||||
color: #f6f4ec;
|
||||
font-weight: 600; letter-spacing: .14em;
|
||||
box-shadow: 0 10px 26px -12px rgba(23, 24, 26, .7);
|
||||
transition: transform .12s, background-color .15s, box-shadow .12s;
|
||||
}
|
||||
.primary:hover { background: #26282c; transform: translateY(-1px); box-shadow: 0 14px 30px -12px rgba(23, 24, 26, .7); }
|
||||
.primary:active { transform: none; }
|
||||
.primary:disabled { opacity: .55; }
|
||||
|
||||
/* ---------- 钉钉登录区 ---------- */
|
||||
/* ---------- 钉钉 ---------- */
|
||||
.divider {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
color: var(--text-faint); font-size: 11px; letter-spacing: .02em;
|
||||
margin: 6px 0 2px;
|
||||
display: flex; align-items: center; gap: 12px;
|
||||
color: #9a968a; font-size: 11px; letter-spacing: .06em;
|
||||
margin: 26px 0 14px;
|
||||
}
|
||||
.divider::before, .divider::after {
|
||||
content: ''; height: 1px; flex: 1; background: var(--border);
|
||||
.divider::before, .divider::after { content: ''; height: 1px; flex: 1; background: #ded9ca; }
|
||||
.dingtalk {
|
||||
width: 100%; height: 46px; border-radius: 8px;
|
||||
border: none; color: #fff;
|
||||
background: linear-gradient(120deg, #1491f0, #0a7cdf);
|
||||
font-weight: 600; letter-spacing: .04em;
|
||||
box-shadow: 0 10px 26px -12px rgba(10, 124, 223, .6);
|
||||
transition: transform .12s, filter .12s;
|
||||
}
|
||||
.dingtalk { width: 100%; color: #0aa9f4; border-color: rgba(10,169,244,.35); letter-spacing: .04em; }
|
||||
.dingtalk:hover, .dingtalk:focus { border-color: #0aa9f4; color: #0aa9f4; background: rgba(10,169,244,.06); }
|
||||
.ding-tip { margin: 0 0 14px; font-size: 12px; line-height: 1.7; color: var(--text-faint); }
|
||||
.inline-qr { margin-top: 14px; text-align: center; }
|
||||
.qr-box { width: 240px; height: 240px; margin: 0 auto 6px; border: 1px solid rgba(0,0,0,.06); border-radius: 10px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; }
|
||||
.dingtalk:hover { color: #fff; filter: brightness(1.04); transform: translateY(-1px); }
|
||||
.dingtalk:active { transform: none; }
|
||||
|
||||
/* ---------- 内嵌二维码兜底 ---------- */
|
||||
.inline-qr { margin-top: 18px; text-align: center; }
|
||||
.qr-box { width: 240px; height: 240px; margin: 0 auto 8px; border: 1px solid rgba(23,24,26,.08); border-radius: 10px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; }
|
||||
.qr-box :deep(#ding_qr_container) { margin: 0 auto; }
|
||||
.qr-actions { margin-top: 4px; }
|
||||
.qr-actions .el-link { font-size: 12px; }
|
||||
.ding-tip { margin: 0 0 14px; font-size: 12px; line-height: 1.7; color: #6c6e74; }
|
||||
|
||||
/* ---------- 自适应 & 降级 ---------- */
|
||||
@media (max-width: 420px) {
|
||||
.login { padding: 16px; }
|
||||
.card { padding: 26px 22px 22px; border-radius: 16px; }
|
||||
.blob { filter: blur(70px); opacity: .3; }
|
||||
/* ---------- 自适应 ---------- */
|
||||
@media (max-width: 860px) {
|
||||
.stage { grid-template-columns: 1fr; min-height: 0; }
|
||||
.panel { padding: 30px 34px; min-height: 300px; }
|
||||
.auth { padding: 34px 30px; }
|
||||
.panel-mid { padding-top: 4px; }
|
||||
}
|
||||
@media (max-height: 640px) {
|
||||
.login { padding: 22px 18px; }
|
||||
.panel { justify-content: flex-start; gap: 26px; }
|
||||
.nodes { gap: 14px; }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.blob, .card { animation: none; }
|
||||
.stage { animation: none; }
|
||||
* { transition-duration: .01ms !important; }
|
||||
}
|
||||
</style>
|
||||
@@ -7,23 +7,32 @@
|
||||
:with-header="true"
|
||||
@close="emit('close')"
|
||||
>
|
||||
<!-- 个人信息卡片 -->
|
||||
<el-card class="info-card" shadow="never">
|
||||
<template #header>
|
||||
<div class="info-head">
|
||||
<el-avatar :size="46" :src="store.avatarUrl" @error="onAvatarError" class="avatar">
|
||||
<span>{{ store.current.slice(0, 1).toUpperCase() }}</span>
|
||||
</el-avatar>
|
||||
<div class="info-meta">
|
||||
<div class="name-line">
|
||||
<strong>{{ store.current }}</strong>
|
||||
<el-tag v-if="store.isAdmin" size="small" type="primary" effect="light" round>管理员</el-tag>
|
||||
</div>
|
||||
<span class="dept">{{ store.dept || '未设置部门' }}</span>
|
||||
<!-- 个人信息 -->
|
||||
<section class="pcard">
|
||||
<div class="cover"><span class="cover-id mono">ID · {{ store.current }}</span></div>
|
||||
<div class="pcard-main">
|
||||
<el-avatar :size="60" :src="store.avatarUrl" @error="onAvatarError" class="avatar">
|
||||
<span>{{ store.current.slice(0, 1).toUpperCase() }}</span>
|
||||
</el-avatar>
|
||||
<div class="pcard-id">
|
||||
<div class="name-line">
|
||||
<strong>{{ store.current }}</strong>
|
||||
<em v-if="store.isAdmin" class="admin">管理员</em>
|
||||
</div>
|
||||
<span class="dept">{{ store.dept || '未设置部门' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</el-card>
|
||||
</div>
|
||||
<div class="pcard-rows">
|
||||
<div class="crow">
|
||||
<span>已授权插件</span>
|
||||
<span class="mono">{{ store.plugins.length }}</span>
|
||||
</div>
|
||||
<div class="crow">
|
||||
<span>平台在线</span>
|
||||
<span class="mono">{{ store.platforms.filter(p => p.online).length }}/{{ store.platforms.length }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 平台登录态 -->
|
||||
<el-collapse v-model="activeNames">
|
||||
@@ -34,14 +43,14 @@
|
||||
<span>平台登录态</span>
|
||||
</div>
|
||||
</template>
|
||||
<div v-for="p in store.platforms" :key="p.id" class="prow">
|
||||
<i class="dot" :class="{ on: p.online }"></i>
|
||||
<div v-for="(p, i) in store.platforms" :key="p.id" class="prow">
|
||||
<span class="ridx mono">P0{{ i + 1 }}</span>
|
||||
<span class="dot" :class="{ on: p.online }"></span>
|
||||
<span class="pname">{{ p.label }}</span>
|
||||
<span class="pstat">{{ p.online ? '已登录' : '未登录' }}</span>
|
||||
<el-button size="small" :disabled="busy === p.id" @click="relogin(p.id)">
|
||||
{{ busy === p.id ? '处理中…' : '重新登录' }}
|
||||
<el-button size="small" :disabled="busy === p.id || p.online" @click="relogin(p.id)">
|
||||
{{ busy === p.id ? '处理中…' : p.online ? '正常' : '重新登录' }}
|
||||
</el-button>
|
||||
<el-button size="small" :disabled="busy === p.id || !p.online" @click="logout(p.id)">登出</el-button>
|
||||
<el-button v-if="p.online" size="small" plain type="danger" :disabled="busy === p.id" @click="logout(p.id)">登出</el-button>
|
||||
</div>
|
||||
</el-collapse-item>
|
||||
|
||||
@@ -54,10 +63,12 @@
|
||||
</div>
|
||||
</template>
|
||||
<el-empty v-if="!store.plugins.length" description="当前账号暂无可用插件" />
|
||||
<div v-else class="plist">
|
||||
<div v-for="p in store.plugins" :key="p.id" class="prow flat">
|
||||
<span class="pname">{{ p.name }}</span>
|
||||
<span class="ver">v{{ p.version }}</span>
|
||||
<div v-else class="ilist">
|
||||
<div v-for="(p, i) in store.plugins" :key="p.id" class="irow">
|
||||
<span class="ridx mono">{{ String(i + 1).padStart(2, '0') }}</span>
|
||||
<span class="iname">{{ p.name }}</span>
|
||||
<span class="mono iver">v{{ p.version }}</span>
|
||||
<span class="i-dot"></span>
|
||||
</div>
|
||||
</div>
|
||||
</el-collapse-item>
|
||||
@@ -189,28 +200,114 @@ async function changePwd() {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.info-card { margin-bottom: 16px; }
|
||||
.info-head { display: flex; align-items: center; gap: 12px; }
|
||||
.avatar { flex-shrink: 0; }
|
||||
.info-meta { flex: 1; min-width: 0; }
|
||||
.name-line { display: flex; align-items: center; gap: 8px; }
|
||||
.name-line strong { font-size: 15px; }
|
||||
.dept { font-size: 11.5px; color: var(--text-faint); }
|
||||
.mono { font-family: var(--font-mono); letter-spacing: .04em; }
|
||||
|
||||
.panel-title { display: flex; align-items: center; gap: 8px; }
|
||||
|
||||
.prow {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
padding: 8px 0;
|
||||
/* ================= 个人信息卡 ================= */
|
||||
.pcard {
|
||||
margin-bottom: 18px;
|
||||
background: #ffffff;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 10px 28px -18px rgba(23, 24, 26, .35);
|
||||
}
|
||||
.prow.flat { padding: 6px 0; }
|
||||
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c6ccdc; flex-shrink: 0; }
|
||||
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 176, 122, 0.18); }
|
||||
.pname { flex: 1; color: var(--text-sub); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.pstat { font-size: 11px; color: var(--text-faint); }
|
||||
.ver { font-size: 11px; color: var(--text-faint); }
|
||||
.plist { display: flex; flex-direction: column; }
|
||||
.empty { color: var(--text-faint); font-size: 12px; margin: 4px 0; }
|
||||
.cover {
|
||||
height: 66px;
|
||||
background:
|
||||
radial-gradient(360px 200px at 90% -30%, rgba(208, 74, 36, .5), transparent 60%),
|
||||
radial-gradient(300px 180px at -10% 120%, rgba(120, 128, 140, .4), transparent 60%),
|
||||
#1a1c1f;
|
||||
position: relative;
|
||||
}
|
||||
.cover-id {
|
||||
position: absolute;
|
||||
right: 14px; bottom: 12px;
|
||||
font-size: 11px;
|
||||
color: rgba(236, 234, 223, .55);
|
||||
letter-spacing: .1em;
|
||||
}
|
||||
.pcard-main {
|
||||
display: flex; align-items: center; gap: 14px;
|
||||
padding: 0 18px 16px;
|
||||
margin-top: -30px;
|
||||
position: relative;
|
||||
}
|
||||
.avatar {
|
||||
border: 3px solid #fff;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 6px 16px -6px rgba(23, 24, 26, .45);
|
||||
background: #17181a;
|
||||
color: #f6f4ec;
|
||||
font-weight: 700;
|
||||
flex: none;
|
||||
}
|
||||
.pcard-id { min-width: 0; }
|
||||
.name-line { display: flex; align-items: center; gap: 8px; }
|
||||
.name-line strong { font-size: 16px; letter-spacing: .01em; color: #17181a; }
|
||||
.admin {
|
||||
font-style: normal; font-size: 10.5px; font-weight: 600;
|
||||
color: #d04a24;
|
||||
border: 1px solid rgba(208, 74, 36, .35);
|
||||
background: rgba(208, 74, 36, .07);
|
||||
border-radius: 4px;
|
||||
padding: 1px 6px;
|
||||
letter-spacing: .04em;
|
||||
}
|
||||
.dept { font-size: 12px; color: var(--text-faint); }
|
||||
|
||||
.pwd-card { margin-top: 16px; }
|
||||
.pcard-rows { border-top: 1px solid var(--border); }
|
||||
.crow {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 11px 18px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
font-size: 13px;
|
||||
}
|
||||
.crow:last-child { border-bottom: none; }
|
||||
.crow span:first-child { color: var(--text-sub); }
|
||||
.crow .mono { color: #17181a; font-size: 13px; font-weight: 600; }
|
||||
|
||||
/* ================= 折叠面板 ================= */
|
||||
.panel-title { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-sub); }
|
||||
.panel-title :deep(.el-icon) { color: #d04a24; }
|
||||
|
||||
/* ---------- 平台登录态:编号 + 发丝线 ---------- */
|
||||
.prow {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
padding: 11px 0;
|
||||
border-bottom: 1px dashed var(--border);
|
||||
}
|
||||
.prow:last-child { border-bottom: none; }
|
||||
.ridx { flex: none; width: 26px; font-size: 11px; color: var(--text-faint); }
|
||||
.dot {
|
||||
flex: none; width: 7px; height: 7px; border-radius: 50%;
|
||||
background: #c6ccdc;
|
||||
}
|
||||
.dot.on { background: #22b07a; box-shadow: 0 0 0 3px rgba(34, 176, 122, .16); }
|
||||
.pname { flex: 1; color: var(--text-sub); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.prow :deep(.el-button--primary) { border-color: transparent; }
|
||||
.prow :deep(.el-button--danger.is-plain) { border-color: rgba(214, 69, 69, .35); color: #d64545; }
|
||||
|
||||
/* ---------- 我的插件:台账式列表 ---------- */
|
||||
.ilist { display: flex; flex-direction: column; }
|
||||
.irow {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
padding: 11px 0;
|
||||
border-bottom: 1px dashed var(--border);
|
||||
}
|
||||
.irow:last-child { border-bottom: none; }
|
||||
.iname { flex: 1; color: var(--text); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.iver { font-size: 11px; color: var(--text-faint); }
|
||||
.i-dot { flex: none; width: 5px; height: 5px; border-radius: 50%; background: #d04a24; }
|
||||
|
||||
/* ---------- 修改密码 ---------- */
|
||||
.pwd-card { margin-top: 16px; border-radius: 14px; border-color: var(--border); }
|
||||
.pwd-card :deep(.el-card__header) {
|
||||
font-size: 13px; font-weight: 600;
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding: 12px 16px;
|
||||
}
|
||||
.pwd-card :deep(.el-card__body) { padding: 16px; }
|
||||
.pwd-card :deep(.el-form-item__label) { color: var(--text-sub); font-weight: 500; }
|
||||
.pwd-card :deep(.el-button--primary) { width: 100%; border-color: transparent; background: #17181a; }
|
||||
.pwd-card :deep(.el-button--primary:hover) { background: #26282c; }
|
||||
</style>
|
||||
@@ -28,6 +28,8 @@
|
||||
--radius: 14px;
|
||||
--radius-sm: 9px;
|
||||
--mono: "JetBrains Mono", "Consolas", "Courier New", monospace;
|
||||
--font-mono: "JetBrains Mono", "Consolas", "Courier New", monospace;
|
||||
--font-body: "Inter", "Microsoft YaHei UI", "PingFang SC", -apple-system, sans-serif;
|
||||
|
||||
/* element-plus 主题与品牌蓝统一 */
|
||||
--el-color-primary: #3b6cff;
|
||||
|
||||
Reference in New Issue
Block a user