refactor(download): open generated links directly without the popup

The success modal added a second click between the download button and
the file: request -> "下载链接已生成" popup -> 立即下载. Drop it and open
the generated relay link right away, keeping the previous new-tab
behaviour; a missing link still surfaces the error view.

- Replace renderSuccess with startDownload (anchor + target=_blank)
- Remove the popup-only CSS: alert, code-row, copy button, chips, meta
  and the download action skin; error, cashier and scan-pay views keep
  their styles
This commit is contained in:
2026-09-24 18:56:36 +08:00
parent d49fd9f6a4
commit bc97c4ddc3
2 changed files with 16 additions and 168 deletions
+16 -73
View File
@@ -4,7 +4,7 @@
* 功能:
* - 监听 [data-action="aksrt-download"] 按钮点击
* - 调 POST /aksrt/v1/download/request
* - 弹窗显示下载链接(含提取码)
* - 成功后直接打开生成的下载链接;失败/购买等场景仍走弹窗
*
* 弹窗视觉走主题 design token(见 assets/css/frontend/cms-download.css),
* 付费收银台沿用参考实现的 colorful header 结构。
@@ -251,78 +251,21 @@
}
}
// ===== 成功渲染 =====
function renderSuccess(payload, returnFocusEl) {
payload = payload || {};
const code = String(payload.extract_code || '').trim();
const has = !!payload.has_extract || code !== '';
const safeCode = escapeHtml(code);
const safeCodeAttr = escapeAttr(code);
const expiresIn = typeof payload.expires_in === 'number' && payload.expires_in > 0
? Math.max(1, Math.round(payload.expires_in / 60))
: 10;
const hintMsg = '点击下方按钮开始下载,链接 ' + expiresIn + ' 分钟内有效。';
let body = '';
if (code !== '') {
body +=
'<div class="aksrt-dl-modal__code-card">' +
' <div class="aksrt-dl-modal__code-caption">网盘提取码</div>' +
' <div class="aksrt-dl-modal__code-row">' +
' <code class="aksrt-dl-modal__code">' + safeCode + '</code>' +
' <button type="button" class="aksrt-dl-modal__copy" data-copy="' + safeCodeAttr + '"><span class="aksrt-dl-modal__copy-text">复制</span></button>' +
' </div>' +
'</div>' +
'<p class="aksrt-dl-modal__msg">' + escapeHtml(hintMsg) + '</p>';
} else if (has) {
body += '<p class="aksrt-dl-modal__alert aksrt-dl-modal__alert--warn">下载源标记了提取码,但接口未返回具体内容,请检查资源下载源的 extract_code 字段。</p>';
} else {
body += '<p class="aksrt-dl-modal__msg">' + escapeHtml(hintMsg) + '</p>';
// ===== 成功:直接打开生成的下载链接,不再弹窗 =====
function startDownload(payload, returnFocusEl) {
const url = payload && payload.dl_url ? String(payload.dl_url) : '';
if (!url) {
renderError('下载链接生成失败,请稍后重试', {}, returnFocusEl);
return;
}
const chips = [];
const sourceLabel = String(payload.source_label || '').trim();
if (sourceLabel !== '') {
chips.push('<span class="aksrt-dl-modal__chip"><i class="fa fas fa-box" aria-hidden="true"></i>' + escapeHtml(sourceLabel) + '</span>');
}
if (chips.length) {
body += '<div class="aksrt-dl-modal__meta">' + chips.join('') + '</div>';
}
open(
dlView('success', {
subtitle: '下载链接已生成,请及时将文件保存到本地。',
body: body,
actions: [{
kind: 'link',
url: payload.dl_url || '#',
label: '立即下载',
icon: 'fa-download',
cls: 'aksrt-dl-modal__download',
attrs: 'target="_blank" rel="noopener noreferrer"',
}],
}),
returnFocusEl
);
// 复制按钮
document.querySelectorAll('[data-copy]').forEach(function (btn) {
btn.addEventListener('click', function () {
const text = btn.getAttribute('data-copy') || '';
const label = btn.querySelector('.aksrt-dl-modal__copy-text') || btn;
if (navigator.clipboard) {
navigator.clipboard.writeText(text).then(function () {
label.textContent = '已复制';
btn.classList.add('is-done');
setTimeout(function () {
label.textContent = '复制';
btn.classList.remove('is-done');
}, 2000);
});
}
});
});
// 与旧版弹窗内「立即下载」一致:新标签页打开本站中转链接。
const link = document.createElement('a');
link.href = url;
link.target = '_blank';
link.rel = 'noopener noreferrer';
document.body.appendChild(link);
link.click();
link.remove();
}
// ===== 主流程 =====
@@ -403,7 +346,7 @@
renderError(r.json.message || '请稍后重试', r.json.data || {}, button, r.json.code);
return;
}
renderSuccess(r.json, button);
startDownload(r.json, button);
})
.catch(function () {
button.disabled = false;