ui: simplify helper copy and center page loading feedback
This commit is contained in:
+45
-27
@@ -18,7 +18,7 @@ class LoginPage {
|
||||
this.autoReloginMessage = el('p', {role: 'status'});
|
||||
this.autoReloginCountdown = el('p', {'data-auto-relogin-countdown': '', role: 'timer', 'aria-live': 'off', hidden: true});
|
||||
this.autoReloginCredentials = el('p', {'data-auto-relogin-credentials': '', role: 'status', hidden: true,
|
||||
text: '缺少服务端记住的账号和密码。请勾选“记住账号和密码”并完成登录,才能自动重登原区服角色。'});
|
||||
text: '未保存账号或密码,自动重登不可用。'});
|
||||
this.autoReloginStatus = el('div', {class: 'page-summary', 'data-auto-relogin-status': ''}, this.autoReloginMessage, this.autoReloginCountdown, this.autoReloginCredentials);
|
||||
this.account = el('input', {type: 'text', name: 'game-account', autocomplete: 'username', 'aria-label': '游戏账号'});
|
||||
this.password = el('input', {type: 'password', name: 'game-password', autocomplete: 'current-password', 'aria-label': '游戏密码'});
|
||||
@@ -48,11 +48,9 @@ class LoginPage {
|
||||
this.restore = el('button', {type: 'button', text: '恢复选中会话(无需重新输密码)', disabled: true, onClick: () => page.perform('restore_session', {session_id: this.saved.value}).catch(page.error)});
|
||||
this.root.append(form,
|
||||
field('第二步:区服 / 角色', el('div', {class: 'server-row'}, this.servers, this.enter)),
|
||||
el('p', {class: 'info-note', text: '账号验证 → 获取官方区服 → 选择区服 → 进入区服 → 读取角色。在线时默认自动刷新状态并自动执行已勾选功能;顶部“停止”仅暂停执行,重新登录和服务重启后仍保持暂停,直到再次“开启”。'}),
|
||||
el('div', {class: 'session-block policy-form'}, field('已保存账号 / 区服 / 角色', this.saved), el('div', {class: 'login-actions'}, this.restore)),
|
||||
el('div', {class: 'page-toolbar'}, el('button', {type: 'button', text: '退出登录', onClick: () => page.perform('logout').catch(page.error)}),
|
||||
el('button', {type: 'button', text: '退出并清除登录记录…', onClick: () => page.options.command('forget-login', page.account)})),
|
||||
el('p', {class: 'info-note', text: '记住的账号密码和登录会话由服务端加密保存。浏览器不会保存游戏凭据。账号登录并保存原区服、原角色后会持续保持登录:掉线、退出登录或服务重启,均按设定时长自动重登并恢复监控;默认等待 30 分钟,可修改为 10 分钟等时长。关闭页面不影响自动重登。只有“退出并清除登录记录”或删除账号才取消自动重登;手动停止的执行仍保持暂停。'}));
|
||||
el('button', {type: 'button', text: '退出并清除登录记录…', onClick: () => page.options.command('forget-login', page.account)})));
|
||||
host.append(this.autoReloginStatus, this.root);
|
||||
}
|
||||
|
||||
@@ -72,8 +70,9 @@ class LoginPage {
|
||||
|
||||
updateStatus() {
|
||||
const status = this.page.account.summary?.auto_relogin_status;
|
||||
const message = status?.message || '已保存的账号会持续自动重登,等待服务端状态;可设置重登等待时长。';
|
||||
const message = status?.message || '';
|
||||
if (this.autoReloginMessage.textContent !== message) this.autoReloginMessage.textContent = message;
|
||||
this.autoReloginMessage.hidden = !message;
|
||||
this.autoReloginCredentials.hidden = this.hasSavedPassword !== false;
|
||||
const attemptAt = typeof status?.next_attempt_at === 'string' ? Date.parse(status.next_attempt_at) : NaN;
|
||||
this.autoReloginCountdown.hidden = !Number.isFinite(attemptAt);
|
||||
@@ -82,6 +81,7 @@ class LoginPage {
|
||||
const countdown = remaining ? `${remaining} 秒后自动重新登录(${chinaTime(status.next_attempt_at, {date: true})},北京时间)` : '等待服务端执行自动重登';
|
||||
if (this.autoReloginCountdown.textContent !== countdown) this.autoReloginCountdown.textContent = countdown;
|
||||
}
|
||||
this.autoReloginStatus.hidden = !message && this.autoReloginCountdown.hidden && this.autoReloginCredentials.hidden;
|
||||
}
|
||||
|
||||
updateOptions(select, options, placeholder) {
|
||||
@@ -105,11 +105,12 @@ export class PageView {
|
||||
this.query = initialQuery(key);
|
||||
this.filters = new Map();
|
||||
this.data = null;
|
||||
this.root = el('section', {class: 'page-panel', role: 'tabpanel', 'aria-label': PAGES.find(page => page[0] === key)[1], 'data-page': key, hidden: true});
|
||||
this.root = el('section', {class: 'page-panel', role: 'tabpanel', 'aria-label': PAGES.find(page => page[0] === key)[1], 'aria-busy': 'false', 'data-page': key, hidden: true});
|
||||
this.header = el('div', {class: 'page-header'});
|
||||
this.title = el('h2', {text: PAGES.find(page => page[0] === key)[1]});
|
||||
this.loading = el('span', {class: 'page-loading', role: 'status', text: '正在读取…', 'data-loading': 'true'});
|
||||
this.header.append(this.title, this.loading);
|
||||
this.loading = el('div', {class: 'page-loading loading-state', role: 'status', 'aria-label': `正在加载${this.title.textContent}`, 'data-loading': 'false', hidden: true},
|
||||
el('span', {class: 'loading-spinner', 'aria-hidden': 'true'}));
|
||||
this.header.append(this.title);
|
||||
this.errorBox = el('div', {class: 'page-error', role: 'alert', hidden: true});
|
||||
this.error = error => { this.showError(error.message || String(error)); notice(error.message || String(error), true); };
|
||||
this.subtabs = el('div', {class: 'subtabs', role: 'tablist', 'aria-label': '子页面', hidden: true});
|
||||
@@ -119,18 +120,32 @@ export class PageView {
|
||||
this.formHost = el('div', {class: 'policy-form'});
|
||||
this.actionsHost = el('div', {class: 'page-toolbar'});
|
||||
this.content = el('div', {class: 'page-content'});
|
||||
this.notes = el('div', {class: 'info-note'});
|
||||
this.context = {get: (path, fallback) => getPath(account.config, path, fallback), set: (path, value, field, row) => options.edit(account, path, value, field, row),
|
||||
dirty: path => account.edits.has(pathKey(path)), onError: this.error, onSelection: () => this.syncActions(),
|
||||
onContext: (event, selected, row) => this.openContext(event, selected, row), onDetail: row => this.showDetail(row)};
|
||||
this.form = new PolicyForm(this.formHost, this.context);
|
||||
this.root.append(this.header, this.errorBox, this.subtabs, this.filterHost, this.summary, this.runtimeStatus, this.formHost, this.actionsHost, this.content, this.notes);
|
||||
this.surface = el('div', {class: 'page-surface'}, this.errorBox, this.subtabs, this.filterHost, this.summary, this.runtimeStatus, this.formHost, this.actionsHost, this.content);
|
||||
this.body = el('div', {class: 'page-body'}, this.surface, this.loading);
|
||||
this.root.append(this.header, this.body);
|
||||
if (key === 'login') this.login = new LoginPage(this.content, this);
|
||||
tabKeys(this.subtabs, '.subtab');
|
||||
}
|
||||
|
||||
perform(operation, payload = {}) { return this.options.perform(this.account, operation, payload, {page: this}); }
|
||||
showError(message) { this.errorBox.replaceChildren(el('span', {text: message}), el('button', {text: '重新读取', type: 'button', onClick: () => this.options.load(this, true)})); this.errorBox.hidden = false; }
|
||||
setLoading(loading) {
|
||||
const busy = Boolean(loading && !this.root.hidden && this.root.isConnected);
|
||||
if (this.loading.dataset.loading === String(busy)) return;
|
||||
clearTimeout(this.loadingTimer);
|
||||
this.root.setAttribute('aria-busy', String(busy));
|
||||
this.loading.dataset.loading = String(busy);
|
||||
this.loading.hidden = true;
|
||||
// Skip the visual flash for fast reads; expose busy status immediately.
|
||||
if (busy) this.loadingTimer = setTimeout(() => {
|
||||
if (!this.root.hidden && this.root.isConnected) this.loading.hidden = false;
|
||||
else this.setLoading(false);
|
||||
}, 150);
|
||||
}
|
||||
showError(message) { this.setLoading(false); this.errorBox.replaceChildren(el('span', {text: message}), el('button', {text: '重新读取', type: 'button', onClick: () => this.options.load(this, true)})); this.errorBox.hidden = false; }
|
||||
clearError() { this.errorBox.hidden = true; }
|
||||
|
||||
setQuery(key, value) {
|
||||
@@ -219,15 +234,14 @@ export class PageView {
|
||||
$$('button[data-selection]', this.actionsHost).forEach(button => { button.disabled = !selected; });
|
||||
}
|
||||
|
||||
render(data, loading = false) {
|
||||
if (!data) { this.loading.textContent = '正在读取…'; this.loading.dataset.loading = 'true'; return; }
|
||||
render(data) {
|
||||
if (!data) return;
|
||||
this.data = data;
|
||||
this.loading.dataset.loading = String(loading);
|
||||
this.loading.textContent = loading ? '后台更新中…' : '已载入';
|
||||
this.updateSubtabs(data);
|
||||
this.updateFilters(data.filters || []);
|
||||
this.summary.textContent = typeof data.summary === 'string' ? data.summary : textValue(data.summary || '');
|
||||
this.updateRuntimeStatus(data.details || {});
|
||||
this.summary.hidden = !data.summary;
|
||||
this.updateRuntimeStatus(data.details || {}, data.battle_mode);
|
||||
let fields = data.form || this.options.schema(this.key);
|
||||
if (this.key === 'login') fields = fields.filter(field => !(field.path?.[0] === 'auto_relogin' && field.path[1] === 'enabled'));
|
||||
fields=fields.map(field=>field.path?.[0]==='policy'&&field.path[1]==='buy_ten'?{...field,disabled:!this.account.config?.policy?.allow_single_draw}:field);
|
||||
@@ -238,11 +252,6 @@ export class PageView {
|
||||
if (this.login) { this.login.update(data); return; }
|
||||
this.content.hidden = policyTab;
|
||||
if (policyTab) return;
|
||||
const notes = data.notes || data.details?.note || data.details?.notes || data.details?.help || data.hint || '';
|
||||
const noteText=Array.isArray(notes)?notes.join('\n'):typeof notes==='string'?notes:textValue(notes);
|
||||
this.notes.textContent=[noteText,...(data.battle_mode?[data.battle_mode.label,data.battle_mode.damage_rule]:[])].filter(Boolean).join('\n');
|
||||
this.notes.style.whiteSpace = 'pre-wrap';
|
||||
this.notes.hidden = !this.notes.textContent;
|
||||
const groups = data.groups || [];
|
||||
const grouped = this.key === 'maps' || this.key === 'ranch' && (this.query.grouped === true || this.query.grouped === 'true');
|
||||
const mode = this.key === 'statistics' ? 'statistics' : grouped ? 'grouped' : 'table';
|
||||
@@ -250,7 +259,7 @@ export class PageView {
|
||||
if (this.content.contains(document.activeElement)) return;
|
||||
this.content.replaceChildren();
|
||||
this.contentMode = mode;
|
||||
this.table = mode === 'grouped' ? new GroupedTables(this.content, this.context, {collapsed: this.key === 'maps'}) : mode === 'table' ? new DataTable(this.content, this.context, {emptyMessage: this.key === 'plans' ? '当前没有执行计划。请配置策略并刷新 / 预览,查看下一步或等待原因。' : '当前筛选下没有条目。可调整筛选,或登录后刷新状态。'}) : null;
|
||||
this.table = mode === 'grouped' ? new GroupedTables(this.content, this.context, {collapsed: this.key === 'maps'}) : mode === 'table' ? new DataTable(this.content, this.context, {emptyMessage: this.key === 'plans' ? '当前没有执行计划。' : '当前筛选下没有条目。'}) : null;
|
||||
if (mode === 'statistics') this.buildStatistics();
|
||||
}
|
||||
if (mode === 'statistics') this.renderStatistics(data);
|
||||
@@ -260,7 +269,7 @@ export class PageView {
|
||||
} else this.table.update(data.columns || [], data.rows || []);
|
||||
}
|
||||
|
||||
updateRuntimeStatus(details) {
|
||||
updateRuntimeStatus(details, battleMode) {
|
||||
const lines=[];
|
||||
if(this.key==='hatching'){
|
||||
if(this.activeSubtab==='喂养策略' && Array.isArray(details.feed_status))lines.push(['feed_status','当前喂养状态:'+textValue(details.feed_status[1])]);
|
||||
@@ -270,7 +279,16 @@ export class PageView {
|
||||
const ready=details.next_ready_at;
|
||||
lines.push(['next_ready_at',ready===null?'下次赠礼:当前没有符合条件的目标或物品,等待状态更新':'下次可赠礼:'+chinaTime(ready,{date:true})+'(北京时间)']);
|
||||
}
|
||||
this.runtimeStatus.replaceChildren(...lines.map(([key,text])=>el('p',{'data-view-status':key,text})));
|
||||
// Planner notes are current execution/wait reasons, unlike DTO help text.
|
||||
const notes = Array.isArray(details.notes) ? [...new Set(details.notes.filter(note => typeof note === 'string' && note.trim()))] : [];
|
||||
if(notes.length)lines.push(['planner_notes',notes.join('\n')]);
|
||||
if(details.statistics_error)lines.push(['statistics_error',textValue(details.statistics_error)]);
|
||||
if(battleMode?.label)lines.push(['battle_mode',battleMode.label]);
|
||||
const signature=JSON.stringify(lines);
|
||||
if(signature!==this.runtimeSignature){
|
||||
this.runtimeStatus.replaceChildren(...lines.map(([key,text])=>el('p',{'data-view-status':key,text})));
|
||||
this.runtimeSignature=signature;
|
||||
}
|
||||
this.runtimeStatus.hidden=!lines.length;
|
||||
}
|
||||
|
||||
@@ -279,7 +297,7 @@ export class PageView {
|
||||
if (!data) return;
|
||||
const labels = {name:'名称',species:'种类',id:'魔物ID',level:'等级 / 当前上限',quality:'资质 攻/防/血/敏',reference_stats:'参考攻击 / 防御 / 生命 / 敏捷',growth:'成长数值',likes:'喜欢的物品',feel:'好感 / 上限',feed_exp:'喂养经验',scope:'管理范围'};
|
||||
const title=this.key==='ranch'?'魔物详情':this.key==='mainline'?'任务详情':this.key==='battles'?'战斗详情':'详情';
|
||||
dialog(title, el('div', {class:'detail-sections'}, detailsList(data, labels), this.key==='ranch'?el('p', {class:'info-note',text:'参考属性不含装备、羁绊或全局加成。'}):null), {info:true});
|
||||
dialog(title, el('div', {class:'detail-sections'}, detailsList(data, labels)), {info:true});
|
||||
}
|
||||
|
||||
openContext(event, selected, row) {
|
||||
@@ -296,7 +314,7 @@ export class PageView {
|
||||
this.statisticsPicker = el('div', {class:'statistics-picker',role:'listbox','aria-label':'关卡 / 难度'});
|
||||
this.chart = el('div',{class:'chart-scroll','aria-label':'掉落统计图'});
|
||||
this.statisticsTableHost = el('div',{class:'statistics-table-host'});
|
||||
this.statisticsTable = new DataTable(this.statisticsTableHost,this.context,{selection:false,emptyMessage:'所选关卡尚无已确认样本;完成扫荡后将显示实际统计。'});
|
||||
this.statisticsTable = new DataTable(this.statisticsTableHost,this.context,{selection:false,emptyMessage:'所选关卡尚无已确认样本。'});
|
||||
this.statisticsSummary = el('p',{class:'page-summary'});
|
||||
this.content.append(el('div',{class:'statistics-layout'},this.statisticsPicker,el('div',{class:'statistics-main'},this.statisticsSummary,this.chart,this.statisticsTableHost)));
|
||||
}
|
||||
@@ -358,7 +376,7 @@ export class PageView {
|
||||
if (this.chartSignature === signature) return;
|
||||
this.chartSignature = signature;
|
||||
this.chart.replaceChildren();
|
||||
if (!bars.length) { this.chart.append(empty(emptyReason || '暂无已确认的统计样本。图表将随实际扫荡记录生成。')); return; }
|
||||
if (!bars.length) { this.chart.append(empty(emptyReason || '暂无已确认的统计样本。')); return; }
|
||||
const ns='http://www.w3.org/2000/svg', width=760, height=Math.max(120,bars.length*29+50), labelWidth=175;
|
||||
const svg=document.createElementNS(ns,'svg');
|
||||
svg.setAttribute('viewBox',`0 0 ${width} ${height}`);svg.setAttribute('class','drop-chart');svg.setAttribute('role','img');svg.setAttribute('aria-label',metric==='per_stamina'?'每点体力掉落数量':'实测掉落率');
|
||||
|
||||
Reference in New Issue
Block a user