fix(ui): silence successful user copy actions

go
codex 3 weeks ago
parent ef57a5ac37
commit b658a01a95

@ -2935,7 +2935,7 @@ function bindInstanceSettings(vmId) {
byId('vm-detail-generated-password-copy')?.addEventListener('click', async () => {
const value = byId('vm-detail-generated-password')?.textContent || '';
if (!value) return;
try { await copyText(value); toast('新密码已复制,请妥善保存。', 'success'); }
try { await copyText(value); }
catch (error) { toast(error.message, 'error'); }
});
byId('vm-detail-generated-password-close')?.addEventListener('click', clearGeneratedPassword);
@ -2994,7 +2994,7 @@ export async function initialize() {
if (!byId('vm-settings-section-rescue')?.hidden) await loadRescue(vmId, true).catch(() => null);
});
byId('vm-detail-ip-copy')?.addEventListener('click', async () => {
try { await copyText(vmIp(selectedVm())); toast('公网 IP 已复制。'); }
try { await copyText(vmIp(selectedVm())); }
catch (error) { toast(error.message, 'error'); }
});
byId('vm-detail-password-reveal')?.addEventListener('click', () => credential());

@ -721,7 +721,6 @@ function bindEvents() {
const button = event.target.closest?.('[data-copy-value]');
if (!button) return;
void copyText(button.dataset.copyValue || '')
.then(() => toast(`${button.dataset.copyLabel || '内容'}已复制。`, 'success'))
.catch(error => toast(error?.message || '复制失败。', 'error'));
});
window.addEventListener('pagehide', () => {

@ -744,7 +744,6 @@ function renderOnlinePayment(container, payment) {
box.append(actionButton('复制收款地址', async () => {
try {
await copyText(qrValue);
toast('USDT 收款地址已复制。', 'success');
} catch (error) {
toast(error.message, 'error');
}
@ -764,7 +763,6 @@ function renderOnlinePayment(container, payment) {
box.append(actionButton('复制支付信息', async () => {
try {
await copyText(qrValue);
toast('支付信息已复制。', 'success');
} catch (error) {
toast(error.message, 'error');
}

@ -537,7 +537,7 @@ async function credential(copy = false) {
const vm = selectedVm(); if (!vm?.can_view_credential || !vm.password_available) return;
if (!copy && state.credentialVisible) return clearCredential();
const id = vm.api_id;
try { const result = await api(`${vmPath(vm)}/credential`, { method: 'POST' }); if (selectedVm()?.api_id !== id || state.view !== 'detail') return; if (!result?.password) throw new Error('没有可查看的初始密码。'); if (copy) { await copyText(result.password); toast('初始密码已复制。', 'success'); } else { state.credentialPassword = result.password; state.credentialVisible = true; text('vm-detail-root-password', result.password); byId('vm-detail-password-reveal').setAttribute('aria-pressed', 'true'); clearTimeout(state.credentialTimer); state.credentialTimer = setTimeout(clearCredential, 30000); } } catch (error) { toast(error.message, 'error'); }
try { const result = await api(`${vmPath(vm)}/credential`, { method: 'POST' }); if (selectedVm()?.api_id !== id || state.view !== 'detail') return; if (!result?.password) throw new Error('没有可查看的初始密码。'); if (copy) { await copyText(result.password); } else { state.credentialPassword = result.password; state.credentialVisible = true; text('vm-detail-root-password', result.password); byId('vm-detail-password-reveal').setAttribute('aria-pressed', 'true'); clearTimeout(state.credentialTimer); state.credentialTimer = setTimeout(clearCredential, 30000); } } catch (error) { toast(error.message, 'error'); }
}
async function loadKeys() {
state.sshKeys = items(await api('/api/v1/ssh-keys'));
@ -1179,7 +1179,7 @@ async function openReinstall(vm, bootstrap = null) {
copyName.disabled = !currentName;
copyName.onclick = async () => {
if (!currentName) return;
try { await copyText(currentName); toast('虚拟机名称已复制。', 'success'); }
try { await copyText(currentName); }
catch (error) { toast(error.message, 'error'); }
};
}
@ -1191,7 +1191,7 @@ async function openReinstall(vm, bootstrap = null) {
if (passwordCardCopy) {
passwordCardCopy.onclick = async () => {
if (!state.reinstallPassword) return;
try { await copyText(state.reinstallPassword); toast('重装密码已复制,请妥善保存。', 'success'); }
try { await copyText(state.reinstallPassword); }
catch (error) { toast(error.message, 'error'); }
};
}
@ -1400,7 +1400,6 @@ function makeCopyIconButton(value, label) {
button.addEventListener("click", async () => {
try {
await copyText(value);
toast(`${label}已复制。`, "success");
} catch (error) {
toast(error.message, "error");
}

@ -317,8 +317,7 @@
if (!button) return;
event.preventDefault();
copyText(button.getAttribute("data-copy")).then(function (ok) {
alertModal(ok ? "已复制到剪贴板" : "复制失败,请手动复制", ok ? "success" : "error");
if (!ok) alertModal("复制失败,请手动复制", "error");
}).catch(function () {
alertModal("复制失败,请手动复制", "error");
});

@ -1,2 +1,2 @@
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
{assign var=venix_asset_version value='2026110125' scope='global'}
{assign var=venix_asset_version value='2026110126' scope='global'}

@ -329,7 +329,7 @@ $assert(str_contains($invoicePresentation,
&& !str_contains($invoicePresentation, 'match (strtolower($status))'),
'User invoice statuses must translate catalog tones, not rebuild semantics.');
$assert(str_contains($layoutAssets,
"venix_asset_version value='2026110125'")
"venix_asset_version value='2026110126'")
&& str_contains($template,
'/cloud/admin-billing.js?v={$venix_asset_version}'),
'Administrator billing asset changes must advance the shared cache key.');

@ -15,7 +15,7 @@ $assert = static function (bool $condition, string $message): void {
};
$assert(is_string($assets)
&& str_contains($assets, "venix_asset_version value='2026110125'")
&& str_contains($assets, "venix_asset_version value='2026110126'")
&& is_string($cloudShell)
&& str_contains($cloudShell, '/cloud/app.js?v={$venix_asset_version}'),
'The cloud application entry must use the shared Venix asset version.');

@ -0,0 +1,35 @@
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
const root = new URL('../', import.meta.url);
const sources = new Map(await Promise.all([
'public/cloud/runtime.js',
'public/cloud/instances.js',
'public/cloud/detail.js',
'public/cloud/invoice-detail-runtime.js',
'public/theme/venix/js/user-home.js',
].map(async path => [path, await readFile(new URL(path, root), 'utf8')])));
for (const [path, source] of sources) {
assert.doesNotMatch(source, /已复制|复制成功|已复制到剪贴板/,
`${path} still displays a success message after copying.`);
}
const runtime = sources.get('public/cloud/runtime.js');
const instances = sources.get('public/cloud/instances.js');
const detail = sources.get('public/cloud/detail.js');
const invoice = sources.get('public/cloud/invoice-detail-runtime.js');
const account = sources.get('public/theme/venix/js/user-home.js');
assert.match(runtime, /浏览器无法复制,请手动选择文本/,
'Shared VM copy failures no longer explain how to recover.');
assert.match(instances, /复制失败|浏览器无法复制/,
'Instance-list copy failures no longer notify the user.');
assert.match(detail, /copyText\([^)]+\)[\s\S]{0,120}catch \(error\) \{ toast\(error\.message, 'error'\); \}/,
'Instance-detail copy failures are no longer surfaced.');
assert.match(invoice, /浏览器无法复制,请手动选择文本/,
'Invoice copy failures no longer explain how to recover.');
assert.match(account, /复制失败,请手动复制/,
'Account-page copy failures are no longer surfaced.');
console.log('User copy actions stay silent on success and visible on failure.');
Loading…
Cancel
Save