- 启动链路 P1-P7 修复:预算对齐、完成事件推送、端口占用提示、前端阶段文案接管 - 静态缓存按 IS_FROZEN 区分开发/打包态,bootPhaseOwned 竞态修复 - 一键执行与参数配置统一收口到插件界面,定时任务引用 config_id - 环境包迁移到 %LOCALAPPDATA%\37duAutomation\python-env,重装零解压 - shell-updater:缓存包 sha256 校验、静默升级后自动拉起新版、自动清理旧安装包 - after-pack 钩子生成 shell.version 修复打包态版本识别 - 插件 xq0031/xq0045 迁移至 plugins/XQ0001-0100/ 号段分桶中文目录
188 lines
5.9 KiB
JavaScript
188 lines
5.9 KiB
JavaScript
// 与 FastAPI 后端交互 + WebSocket 实时流
|
||
const WS_BASE = (location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host
|
||
|
||
async function j(url, opts) {
|
||
const res = await fetch(url, opts)
|
||
if (!res.ok) {
|
||
let msg = `HTTP ${res.status}`
|
||
try { msg = (await res.json()).detail || msg } catch (e) {}
|
||
throw new Error(msg)
|
||
}
|
||
return res.json()
|
||
}
|
||
|
||
export async function fetchMeta() {
|
||
return j('/api/meta')
|
||
}
|
||
|
||
// 启动状态(启动页展示当前步骤,无需登录)
|
||
export async function getBootStatus() {
|
||
return j('/api/boot/status')
|
||
}
|
||
|
||
export async function syncPlugins() {
|
||
return j('/api/plugins/sync', { method: 'POST' })
|
||
}
|
||
|
||
// ===== 插件回滚(升级前自动备份上一版,坏包可回退) =====
|
||
export async function listRollbacks() {
|
||
return j('/api/plugins/rollback')
|
||
}
|
||
export async function rollbackPlugin(id) {
|
||
return j(`/api/plugins/rollback/${encodeURIComponent(id)}`, { method: 'POST' })
|
||
}
|
||
|
||
// ===== 场景配置方案(多配置,SQLite 存储) =====
|
||
export async function listPluginConfigs(pluginId) {
|
||
return j(`/api/plugin-configs?plugin_id=${encodeURIComponent(pluginId)}`)
|
||
}
|
||
export async function savePluginConfig(pluginId, name, fields) {
|
||
return j('/api/plugin-configs', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ plugin_id: pluginId, name, fields }),
|
||
})
|
||
}
|
||
export async function deletePluginConfig(pluginId, cfgId) {
|
||
return j(`/api/plugin-configs/${encodeURIComponent(pluginId)}/${encodeURIComponent(cfgId)}`, { method: 'DELETE' })
|
||
}
|
||
|
||
export async function getShellStatus() {
|
||
return j('/api/shell/update-status')
|
||
}
|
||
|
||
export async function checkShellUpdate() {
|
||
return j('/api/shell/check', { method: 'POST' })
|
||
}
|
||
|
||
export async function downloadShellUpdate() {
|
||
return j('/api/shell/download', { method: 'POST' })
|
||
}
|
||
|
||
export async function applyShellUpdate() {
|
||
return j('/api/shell/apply', { method: 'POST' })
|
||
}
|
||
|
||
// ===== 浏览器(Chrome)安装 =====
|
||
export async function getChromeStatus() {
|
||
return j('/api/chrome/status')
|
||
}
|
||
export async function checkChrome() {
|
||
return j('/api/chrome/check', { method: 'POST' })
|
||
}
|
||
export async function downloadChrome() {
|
||
return j('/api/chrome/download', { method: 'POST' })
|
||
}
|
||
export async function installChrome() {
|
||
return j('/api/chrome/install', { method: 'POST' })
|
||
}
|
||
|
||
// ===== 环境包(便携 Python 运行时) =====
|
||
export async function getEnvStatus() {
|
||
return j('/api/env/status')
|
||
}
|
||
export async function syncEnv() {
|
||
return j('/api/env/sync', { method: 'POST' })
|
||
}
|
||
export async function rollbackEnv() {
|
||
return j('/api/env/rollback', { method: 'POST' })
|
||
}
|
||
|
||
export async function loginPlatform(id) {
|
||
return j(`/api/platforms/${id}/login`, { method: 'POST' })
|
||
}
|
||
|
||
export async function logoutPlatform(id) {
|
||
return j(`/api/platforms/${id}/logout`, { method: 'POST' })
|
||
}
|
||
|
||
// 当前账号的平台状态(个人中心):在线态 + 是否已配置个人账号密码 + 已存用户名
|
||
export async function getPlatformStatus() {
|
||
return j('/api/platforms/status')
|
||
}
|
||
|
||
// 保存当前账号的 HR/OA 账号密码(本机加密);pass 留空表示保留原密码
|
||
export async function savePlatformCreds(payload) {
|
||
return j('/api/platforms/creds', {
|
||
method: 'PUT',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(payload),
|
||
})
|
||
}
|
||
|
||
export async function startRun(pluginId, fields) {
|
||
return j('/api/runs', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ plugin_id: pluginId, fields }),
|
||
})
|
||
}
|
||
|
||
export async function getRun(runId) {
|
||
return j(`/api/runs/${runId}`)
|
||
}
|
||
|
||
// 运行历史列表(当前账号,新的在前):执行台「历史运行」数据源
|
||
export async function fetchRuns(limit = 30) {
|
||
return j(`/api/runs?limit=${limit}`)
|
||
}
|
||
|
||
// ===== 定时任务(壳子内置定时,配置自动备份中心机) =====
|
||
export async function listSchedules() {
|
||
return j('/api/schedules')
|
||
}
|
||
export async function createSchedule(body) {
|
||
return j('/api/schedules', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(body),
|
||
})
|
||
}
|
||
export async function updateSchedule(sid, body) {
|
||
return j(`/api/schedules/${sid}`, {
|
||
method: 'PUT',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(body),
|
||
})
|
||
}
|
||
export async function deleteSchedule(sid) {
|
||
return j(`/api/schedules/${sid}`, { method: 'DELETE' })
|
||
}
|
||
export async function toggleSchedule(sid, enabled) {
|
||
return j(`/api/schedules/${sid}/toggle`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ enabled }),
|
||
})
|
||
}
|
||
|
||
export function connectWS(onEvent) {
|
||
const ws = new WebSocket(WS_BASE + '/ws')
|
||
ws.onmessage = (e) => {
|
||
try { onEvent(JSON.parse(e.data)) } catch (_) {}
|
||
}
|
||
return ws
|
||
}
|
||
|
||
// ===== 统一账户登录/会话(底座仅保留认证与个人密码,管理走中心机控制面) =====
|
||
export async function adminMe() {
|
||
return j('/api/admin/me')
|
||
}
|
||
export async function adminLogin(account, password) {
|
||
return j('/api/admin/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ account, password }) })
|
||
}
|
||
// v3 钉钉直连接登录:生成钉钉授权 URL(redirect_uri=本机 /auth/done),前端当前窗口跳转到该 URL
|
||
export async function authDingtalk() {
|
||
return j('/api/auth/dingtalk')
|
||
}
|
||
export async function adminLogout() {
|
||
return j('/api/admin/logout', { method: 'POST' })
|
||
}
|
||
export async function adminPassword(body) {
|
||
return j('/api/admin/password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) })
|
||
}
|
||
export async function adminAvatarUpload(file) {
|
||
const fd = new FormData()
|
||
fd.append('file', file)
|
||
return j('/api/avatar', { method: 'POST', body: fd })
|
||
} |