feat(web): 桌面端前端 Web 独立部署适配——浏览器降级桥+登录态引导+页面动态修正

- 新增 web-fallback.ts:无 pywebview 时以浏览器能力降级(文件选择/上传/模板下载/配置),
  其余桌面能力(enqueue_json/vc_*/folder 选择等)保持 undefined 交由页面既有请在本地客户端中打开提示
- 新增 ensure-auth.ts:无 uid 时经 /newApi/check_login 恢复登录态,无 token/失效跳登录页;
  21 个入口 main.ts 挂载前先引导(桌面端已注入 uid 时零开销)
- pywebview.ts:getPywebviewApi() 在纯浏览器环境返回降级桥;新增 isDesktopRuntime 标志
  (首页更新面板/退出链接据此区分桌面与 Web);hasPywebview 语义修正为真实桥判定
- 登录页跳转、首页登出链接、品牌检测页 hasBridge 判定(select_brand_folder 存在性)适配 Web
This commit is contained in:
2026-09-07 16:35:19 +08:00
parent c5982dd900
commit 30b8c910e8
28 changed files with 424 additions and 32 deletions
+26 -2
View File
@@ -1,3 +1,7 @@
import { ref } from 'vue';
import { webFallbackApi } from './web-fallback';
export interface UploadedJavaFile {
fileKey: string;
originalFilename: string;
@@ -110,6 +114,14 @@ export interface PywebviewApi {
path?: string;
error?: string;
}>;
/** 工具台首页「立即下载」:本地查找教程压缩包并弹窗复制(对齐主程序 _on_dl_click) */
save_workbench_zip?: () => Promise<{
success: boolean;
path?: string;
size_mb?: number;
not_found?: boolean;
error?: string;
}>;
launch_yaoayanui?: () => Promise<{
success: boolean;
path?: string;
@@ -185,8 +197,14 @@ declare global {
let cachedPywebviewApi: PywebviewApi | undefined;
let pywebviewReadyBound = false;
/** 当前是否运行在桌面客户端(pywebview)运行时;Web 独立部署下恒为 false */
export const isDesktopRuntime = ref(false);
function syncPywebviewApi() {
cachedPywebviewApi = window.pywebview?.api;
if (cachedPywebviewApi) {
isDesktopRuntime.value = true;
}
return cachedPywebviewApi;
}
@@ -206,9 +224,15 @@ function bindPywebviewReady() {
bindPywebviewReady();
export function getPywebviewApi() {
return syncPywebviewApi() || cachedPywebviewApi;
const real = syncPywebviewApi() || cachedPywebviewApi;
if (real) return real;
// 纯浏览器环境(Web 独立部署 / dev 预览):返回浏览器降级桥,
// 未在降级桥中实现的方法为 undefined,页面代码走既有的"请在本地客户端中打开"分支
if (typeof window !== 'undefined') return webFallbackApi;
return undefined;
}
/** 是否运行在真实 pywebview 桌面桥环境(Web 降级桥不算桌面运行时) */
export function hasPywebview() {
return Boolean(getPywebviewApi());
return Boolean(syncPywebviewApi() || cachedPywebviewApi);
}