a35a0e9f9d
位次来自 /batch/list 附带的 task_data.queue(桌面客户端对桥返回字段有白名单, 只有 task_data 被原样透传,故位次嵌在那里;服务端见 maixiang_run_task 同批改动)。 前方为 0 时显示「马上轮到」。离开排队状态即清空位次,避免卡片残留旧值。 上一个提交(6ce55337)曾记「仍需客户端发版透传 queue_position」——现改走 task_data 通道,无需发客户端即可显示。
277 lines
8.5 KiB
TypeScript
277 lines
8.5 KiB
TypeScript
import { webFallbackApi } from './web-fallback';
|
||
import { isDesktopRuntime } from '@/shared/runtime-env';
|
||
|
||
export interface UploadedJavaFile {
|
||
fileKey: string;
|
||
originalFilename: string;
|
||
localPath: string;
|
||
size: number;
|
||
relativePath?: string;
|
||
}
|
||
|
||
export type ProxyMode = 1 | 2;
|
||
|
||
/** ASIN 变体采集任务项(/batch/list 返回元素,后端数值状态 0排队/1执行/2成功/3失败) */
|
||
export interface VariantTaskListItem {
|
||
task_id: string;
|
||
status?: number | string;
|
||
task_type?: string;
|
||
/** 最近更新时间(后台有则返回) */
|
||
update_time?: string;
|
||
/** 任务创建时间(后台有则返回) */
|
||
create_time?: string;
|
||
/** 任务完成时间(后台有则返回) */
|
||
finish_time?: string;
|
||
res_type?: number | string;
|
||
res_mes?: string;
|
||
file_url?: string[] | string;
|
||
task_data?: {
|
||
file_url?: string;
|
||
execute_country?: string[];
|
||
proxy_url?: string;
|
||
proxy_mode?: number | string;
|
||
/**
|
||
* 排队位次:仅排队中(status=0)的任务由 /batch/list 附带,
|
||
* 供页面显示「前面还有 N 个任务」。
|
||
*
|
||
* 之所以嵌在 task_data 里而不是顶层:桌面客户端对桥返回的字段有白名单,
|
||
* 顶层新字段到不了页面,而 task_data 是客户端唯一原样透传的开放对象。
|
||
*/
|
||
queue?: {
|
||
/** 位次(1-based);不在待处理队列里为 null */
|
||
position?: number | null;
|
||
/** 前面还有几个任务(= position - 1) */
|
||
ahead?: number | null;
|
||
/** 待处理队列总长 */
|
||
len?: number | null;
|
||
};
|
||
[key: string]: unknown;
|
||
};
|
||
}
|
||
|
||
/** ASIN 变体采集单任务查询 data 段 */
|
||
export interface VariantTaskQueryData {
|
||
message?: string;
|
||
msg?: string;
|
||
res_mes?: string;
|
||
res_type?: number | string;
|
||
file_url?: string[] | string;
|
||
task_data?: VariantTaskListItem['task_data'];
|
||
[key: string]: unknown;
|
||
}
|
||
|
||
export interface DesktopConfig {
|
||
proxy_url?: string;
|
||
proxy_mode?: number | string;
|
||
aliprice_usename?: string;
|
||
aliprice_pwd?: string;
|
||
[key: string]: unknown;
|
||
}
|
||
|
||
export interface DesktopConfigUpdate {
|
||
proxy_url?: string;
|
||
proxy_mode?: ProxyMode;
|
||
current_uid?: string;
|
||
proxy_users?: Record<string, { proxy_url?: string; proxy_mode?: number }>;
|
||
aliprice_usename?: string;
|
||
aliprice_pwd?: string;
|
||
}
|
||
|
||
export interface PywebviewApi {
|
||
/**
|
||
* 把页面登录态令牌交给桌面端 Python 侧(审查 A1/A3):
|
||
* Python 调用自家 Java 接口时会带上 Authorization: Bearer <token>,服务端可按人鉴权。
|
||
* 网页形态(降级桥)无此方法,页面静默跳过。
|
||
*/
|
||
set_user_token?: (token: string) => Promise<unknown>;
|
||
close?: () => Promise<void>;
|
||
minimize?: () => Promise<void>;
|
||
maximize?: () => Promise<void>;
|
||
toggle_maximize?: () => Promise<void>;
|
||
select_files?: (options?: {
|
||
filters?: Array<{
|
||
name?: string;
|
||
extensions?: string;
|
||
}>;
|
||
multiple?: boolean;
|
||
}) => Promise<{
|
||
paths?: string[];
|
||
} | null>;
|
||
save_image?: (
|
||
urlOrData: string,
|
||
filename?: string,
|
||
) => Promise<{ success: boolean; path?: string; error?: string }>;
|
||
save_image_to_folder?: (
|
||
urlOrData: string,
|
||
dirPath: string,
|
||
filename?: string,
|
||
) => Promise<{ success: boolean; path?: string; error?: string }>;
|
||
select_folder?: () => Promise<string | null>;
|
||
select_brand_xlsx_files?: () => Promise<string[]>;
|
||
select_brand_folder?: () => Promise<string | null>;
|
||
/** 本机展开文件夹下的 xlsx 文件(供品牌检测"选择文件夹");新版桌面客户端提供 */
|
||
expand_brand_folder?: (
|
||
folder: string,
|
||
) => Promise<{ success: boolean; items?: Array<{ absolutePath: string; relativePath: string }>; error?: string }>;
|
||
upload_file_to_java?: (
|
||
filePath: string,
|
||
relativePath?: string,
|
||
uploadOss?: boolean,
|
||
) => Promise<{
|
||
success: boolean;
|
||
message?: string;
|
||
data?: UploadedJavaFile;
|
||
error?: string;
|
||
}>;
|
||
save_file_from_url?: (
|
||
url: string,
|
||
filename: string,
|
||
) => Promise<{ success: boolean; path?: string; error?: string }>;
|
||
save_file_from_url_new?: (
|
||
url: string,
|
||
filename: string,
|
||
) => Promise<{ success: boolean; path?: string; error?: string }>;
|
||
save_file_from_url_with_progress?: (
|
||
url: string,
|
||
filename: string,
|
||
downloadId: string,
|
||
) => Promise<{ success: boolean; path?: string; error?: string }>;
|
||
save_template_xlsx?: () => Promise<{
|
||
success: boolean;
|
||
path?: string;
|
||
error?: string;
|
||
}>;
|
||
save_template_zip?: () => Promise<{
|
||
success: boolean;
|
||
path?: string;
|
||
error?: string;
|
||
}>;
|
||
/** 工具台首页「立即下载」:本地查找教程压缩包并弹窗复制(对齐主程序 _on_dl_click) */
|
||
save_workbench_zip?: () => Promise<{
|
||
success: boolean;
|
||
path?: string;
|
||
size_mb?: number;
|
||
not_found?: boolean;
|
||
error?: string;
|
||
}>;
|
||
/** 用系统默认浏览器打开链接(桌面端下载教程包等走外部浏览器,可看到下载进度) */
|
||
open_external_url?: (url: string) => Promise<{ success: boolean; error?: string }>;
|
||
/** 版本更新(桌面专属):下载更新包并启动 update.exe 后退出主程序(原 Flask /api/update/do 桥化) */
|
||
do_update_app?: (fileUrl: string) => Promise<{ success: boolean; error?: string }>;
|
||
/** 桌面客户端本地版本号(与 /api/version/latest 比较检测更新;新版客户端提供) */
|
||
get_app_version?: () => Promise<{ success: boolean; version?: string; error?: string }>;
|
||
launch_yaoayanui?: () => Promise<{
|
||
success: boolean;
|
||
path?: string;
|
||
error?: string;
|
||
alreadyRunning?: boolean;
|
||
}>;
|
||
enqueue_json?: (
|
||
data: unknown,
|
||
) => Promise<{ success: boolean; queue_size?: number; error?: string }>;
|
||
// —— ASIN 变体采集(VariantCollectionAPI,vc_* 前缀)——
|
||
vc_select_input_files?: () => Promise<string[]>;
|
||
vc_start_collect?: (params: {
|
||
mode: 'asin' | 'file';
|
||
files?: string[];
|
||
asins?: string[];
|
||
countries: string[];
|
||
uid: string;
|
||
}) => Promise<{
|
||
success: boolean;
|
||
tasks?: Array<{ task_id: string; source?: string; execute_country?: string[] }>;
|
||
error?: string;
|
||
}>;
|
||
vc_query_task?: (
|
||
taskId: string,
|
||
) => Promise<{
|
||
success: boolean;
|
||
status?: number | string;
|
||
data?: VariantTaskQueryData;
|
||
error?: string;
|
||
}>;
|
||
vc_list_tasks?: (query: {
|
||
uid: string;
|
||
page: number;
|
||
page_size: number;
|
||
}) => Promise<{
|
||
success: boolean;
|
||
page?: number;
|
||
total_page?: number;
|
||
total?: number;
|
||
tasks?: VariantTaskListItem[];
|
||
error?: string;
|
||
}>;
|
||
vc_export_task?: (
|
||
taskId: string,
|
||
) => Promise<{ success: boolean; file_id?: string; error?: string }>;
|
||
vc_query_export?: (
|
||
fileId: string,
|
||
) => Promise<{
|
||
success: boolean;
|
||
status?: number | string;
|
||
file_url?: string;
|
||
file_name?: string;
|
||
error?: string;
|
||
}>;
|
||
vc_download_files_as_zip?: (params: {
|
||
urls: string[];
|
||
zip_name: string;
|
||
download_id: string;
|
||
}) => Promise<{ success: boolean; path?: string; error?: string }>;
|
||
read_config?: () => Promise<DesktopConfig>;
|
||
save_config?: (data: DesktopConfigUpdate) => Promise<DesktopConfig>;
|
||
get_device_id?: () => Promise<{ success: boolean; device_id?: string; error?: string }>;
|
||
}
|
||
|
||
declare global {
|
||
interface Window {
|
||
pywebview?: {
|
||
api?: PywebviewApi;
|
||
};
|
||
}
|
||
}
|
||
|
||
let cachedPywebviewApi: PywebviewApi | undefined;
|
||
let pywebviewReadyBound = false;
|
||
|
||
/** 当前是否运行在桌面客户端(pywebview)运行时;Web 独立部署下恒为 false(见 runtime-env.ts 注释) */
|
||
export { isDesktopRuntime };
|
||
|
||
function syncPywebviewApi() {
|
||
cachedPywebviewApi = window.pywebview?.api;
|
||
if (cachedPywebviewApi) {
|
||
isDesktopRuntime.value = true;
|
||
}
|
||
return cachedPywebviewApi;
|
||
}
|
||
|
||
function bindPywebviewReady() {
|
||
if (
|
||
pywebviewReadyBound ||
|
||
typeof window === "undefined" ||
|
||
!window.addEventListener
|
||
)
|
||
return;
|
||
pywebviewReadyBound = true;
|
||
window.addEventListener("pywebviewready", () => {
|
||
syncPywebviewApi();
|
||
});
|
||
}
|
||
|
||
bindPywebviewReady();
|
||
|
||
export function getPywebviewApi() {
|
||
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(syncPywebviewApi() || cachedPywebviewApi);
|
||
}
|