release: prepare Web 2.0.1 automatic strategies and private updates

This commit is contained in:
AttilaNet
2026-11-11 12:52:08 +08:00
parent 5b1ef25048
commit 533280e007
30 changed files with 1177 additions and 107 deletions
+12 -11
View File
@@ -9,9 +9,10 @@ const current = () => state.accounts.get(state.active);
const currentPage = () => { const account=current(); return account?.pages.get(account.page); };
const terminal = new Set(['succeeded','failed','cancelled']);
const jobLabels = {queued:'排队中',running:'执行中',succeeded:'已完成',failed:'失败',cancelled:'已取消'};
const operationLabels = {login:'登录',enter_server:'进入区服',restore_session:'恢复会话',refresh:'刷新 / 预览',start:'开启策略',stop:'停止策略',set_config:'保存配置',import_config:'导入策略',import_yields:'导入收益',claim_daily:'领取每日奖励',quote_expansion:'读取扩建费用',expand:'扩建',sell:'派遣',feed:'喂养',lock:'锁定',unlock:'解锁'};
const operationLabels = {login:'获取区服',enter_server:'进入区服',restore_session:'恢复会话',refresh:'刷新 / 预览',start:'开启策略',stop:'停止策略',set_config:'保存配置',import_config:'导入策略',import_yields:'导入收益',claim_daily:'领取每日奖励',quote_expansion:'读取扩建费用',expand:'扩建',sell:'派遣',feed:'喂养',lock:'锁定',unlock:'解锁'};
const connectionLabels = {online:'已登录',retrying:'正在重试',expired:'登录已过期',offline:'游戏离线'};
const gameRefreshOperations = new Set(['start','refresh','refresh_maps','refresh_tasks']);
const loginOperations = new Set(['enter_server','restore_session']);
function connectionState(summary) {
if(summary?.demo)return 'online';
@@ -121,7 +122,7 @@ function renderSummary() {
$('#refresh').disabled=!connected;$('#refresh').title=connected?'读取游戏状态并预览策略':details;
const task=account?[...account.jobs.values()].at(-1)?.job:null;
$('#job-status').textContent=task?`${operationLabels[task.operation] || task.operation} · ${jobLabels[task.status]}`:summary?.busy?'后台任务执行中':'';
const message=[details || summary?.error || (demo?'当前为离线演示,不连接游戏服务器。':connected?'角色状态自动刷新;配置功能后开启策略。':'请在登录页输入账号密码,或恢复已保存会话。'),...transportMessages(account)].filter(Boolean).join(';');
const message=[details || summary?.error || (demo?'当前为离线演示,不连接游戏服务器。':connected?summary.running?'角色状态自动刷新,正在自动执行已配置且已勾选的功能;可在顶部“停止”。':'角色状态自动刷新;策略已停止,可在顶部“开启”继续执行已勾选功能。':'请在登录页输入账号密码,或恢复已保存会话。'),...transportMessages(account)].filter(Boolean).join(';');
$('#data-summary').textContent=message;$('#data-summary').title=message;
account?.pages.forEach(renderPageConnection);renderStatus();
syncSaveStatus(account);
@@ -247,7 +248,7 @@ async function perform(account,operation,payload={},options={}) {
if(operation!=='stop')await flushConfig(account);
if(gameRefreshOperations.has(operation) && !gameAvailable(account))throw connectionError(account);
const job=await api.action(account.id,operation,payload);
setStatus(`${operationLabels[operation] || '操作'}:${gameRefreshOperations.has(operation)&&job.status==='succeeded'?'等待确认游戏状态':jobLabels[job.status] || '已提交'}`);
setStatus(`${operationLabels[operation] || '操作'}:${(gameRefreshOperations.has(operation)||loginOperations.has(operation))&&job.status==='succeeded'?'等待确认游戏状态':jobLabels[job.status] || '已提交'}`);
const result=await trackJob(account,job);
if(!state.accounts.has(account.id))return result;
if(result?.config){account.config=clone(result.config);account.revision=result.revision;}
@@ -255,12 +256,12 @@ async function perform(account,operation,payload={},options={}) {
try{account.summary=await api.status(account.id);account.transportErrors.delete('status');}
catch(failure){transportError(account,'status','Web 账号状态',failure);failure.connection=true;throw failure;}
renderAccountTabs();renderSummary();
if((gameRefreshOperations.has(operation)||['enter_server','restore_session'].includes(operation)) && !gameAvailable(account)){setStatus('工作台状态已更新');throw connectionError(account);}
if((gameRefreshOperations.has(operation)||loginOperations.has(operation)) && !gameAvailable(account)){setStatus('工作台状态已更新');throw connectionError(account);}
const page=options.page || account.pages.get(account.page);if(page)await loadPage(page,true);
if(operation==='login'&&result)account.pages.get('login')?.login?.update(result);
if(operation==='enter_server'||operation==='restore_session')notice('已读取角色。策略保持关闭,请配置功能后开启。');
else if(result?.message)notice(result.message);
setStatus(result?.message || `${operationLabels[operation] || '操作'}已完成`);
const message=loginOperations.has(operation)?account.summary.running?'已读取角色,已自动开启策略,执行已配置且已勾选的功能;可在顶部“停止”。':'已读取角色。策略已停止,可在顶部“开启”继续执行已勾选功能。':result?.message;
if(message)notice(message);
setStatus(message || `${operationLabels[operation] || '操作'}已完成`);
return result;
}
@@ -373,7 +374,7 @@ async function exportYields(account=current()) {
async function command(name,account=current()) {
try {
if(name==='add-account'||name==='add-demo')return await addAccount(name==='add-demo');
if(name==='about')return dialog('关于牧场助手',el('div',{},el('p',{text:`牧羊人之心牧场助手 Web ${state.meta?.version || '2.0.0'}`}),el('p',{text:`游戏数据版本 ${state.meta?.gameVersion || '1.9.68'}`}),el('p',{class:'info-note',text:'与桌面助手共用核心策略。配置在服务端自动保存;运行开关在重启和恢复会话后保持关闭。'})),{info:true});
if(name==='about')return dialog('关于牧场助手',el('div',{},el('p',{text:`牧羊人之心牧场助手 Web ${state.meta?.version || '2.0.1'}`}),el('p',{text:`游戏数据版本 ${state.meta?.gameVersion || '1.9.68'}`}),el('p',{class:'info-note',text:'与桌面助手共用核心策略。配置在服务端自动保存;每次成功登录后自动执行已勾选功能,可在顶部“停止”。服务重启后须先成功登录才执行。'})),{info:true});
if(name==='updates')return await showUpdates();
if(name==='admin-logout'){hideWorkbench();try{await api.logout();}finally{requireAuth();}return;}
if(!account)throw new Error('请先新增或选择账号。');
@@ -403,8 +404,8 @@ async function command(name,account=current()) {
if(name==='import-config'){
const file=await filePicker('.json');if(!file)return;if(file.size>1024*1024)throw new Error('策略文件过大。');
let config;try{config=JSON.parse(await file.text());}catch{throw new Error('策略文件不是有效的 JSON。');}
if(!await confirm('导入当前账号策略','将替换当前账号策略,策略运行保持关闭。',{confirm:'导入策略'}))return;
await flushConfig(account);const result=await trackJob(account,await api.importConfig(account.id,config));await refreshConfig(account);notice('策略已导入,运行保持关闭。');await loadPage(getPage(account,account.page),true);return result;
if(!await confirm('导入当前账号策略','将替换当前账号策略并停止执行;下次成功登录会自动执行已勾选功能。',{confirm:'导入策略'}))return;
await flushConfig(account);const result=await trackJob(account,await api.importConfig(account.id,config));await refreshConfig(account);notice('策略已导入,执行已停止;下次成功登录会自动执行已勾选功能。');await loadPage(getPage(account,account.page),true);return result;
}
if(name==='import-yields')return await importYields(account);
if(name==='export-yields')return await exportYields(account);
@@ -576,7 +577,7 @@ async function bootstrap() {
$('#app').hidden=false;
const [meta,schema]=await Promise.all([api.meta(),api.schema()]);state.meta=meta;state.schema=schema;
if(state.redirecting)return;
$('#app-version').textContent=meta.version || '2.0.0';$('#game-version').textContent=meta.gameVersion || '1.9.68';$('#access-mode').textContent=auth.access_mode==='local'||auth.access_mode==='loopback'?'本机工作台':auth.required?'管理工作台':'本机工作台';
$('#app-version').textContent=meta.version || '2.0.1';$('#game-version').textContent=meta.gameVersion || '1.9.68';$('#access-mode').textContent=auth.access_mode==='local'||auth.access_mode==='loopback'?'本机工作台':auth.required?'管理工作台':'本机工作台';
await syncAccounts();if(state.redirecting)return;state.ready=true;setStatus('工作台已连接');
}catch(failure){if(failure.status===401||$('#app').hidden){requireAuth();return;}if(state.redirecting)return;setStatus(failure.message);$('#page-host').replaceChildren(el('div',{class:'initial-state'},el('p',{text:failure.message}),el('button',{text:'重新连接',onClick:bootstrap})));}
}