feat: 前端的细节修改
This commit is contained in:
+45
-13
@@ -11,7 +11,6 @@
|
||||
const bodyEl = document.getElementById('aiCopyBody');
|
||||
const statusEl = document.getElementById('aiCopyStatus');
|
||||
const modelSelectEl = document.getElementById('aiModelSelect');
|
||||
const contextProductNameEl = document.getElementById('aiContextProductName');
|
||||
const contextModelCodeEl = document.getElementById('aiContextModelCode');
|
||||
const titlesContainerEl = document.getElementById('aiTitlesContainer');
|
||||
const tagsContainerEl = document.getElementById('aiTagsContainer');
|
||||
@@ -38,30 +37,64 @@
|
||||
}
|
||||
|
||||
function syncContextHints() {
|
||||
if (contextProductNameEl) {
|
||||
const name = (productNameInput && productNameInput.value || '').trim();
|
||||
contextProductNameEl.textContent = name || '--';
|
||||
}
|
||||
// 注:生成文案不再带入「商品名」,故此处只同步型号提示
|
||||
if (contextModelCodeEl) {
|
||||
const model = (modelCodeInput && modelCodeInput.value || '').trim();
|
||||
contextModelCodeEl.textContent = model || '--';
|
||||
}
|
||||
}
|
||||
|
||||
async function copyText(text) {
|
||||
async function copyText(text, btn) {
|
||||
const value = (text || '').trim();
|
||||
if (!value) {
|
||||
setStatus('没有可复制的内容', true);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(value);
|
||||
} else {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = value;
|
||||
ta.style.position = 'fixed';
|
||||
ta.style.left = '-9999px';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
setStatus('已复制');
|
||||
showCopyFeedback(btn);
|
||||
} catch (err) {
|
||||
setStatus('复制失败,请手动选择文本', true);
|
||||
}
|
||||
}
|
||||
|
||||
function showCopyFeedback(btn) {
|
||||
if (!btn || btn.dataset.copyFeedbackActive) return;
|
||||
|
||||
if (btn.classList.contains('ai-tag-chip')) {
|
||||
btn.classList.add('is-copied');
|
||||
setTimeout(function () {
|
||||
btn.classList.remove('is-copied');
|
||||
}, 1200);
|
||||
return;
|
||||
}
|
||||
|
||||
const originalText = btn.textContent;
|
||||
btn.dataset.copyFeedbackActive = '1';
|
||||
btn.disabled = true;
|
||||
btn.textContent = '已复制';
|
||||
btn.classList.add('is-copied');
|
||||
|
||||
setTimeout(function () {
|
||||
btn.textContent = originalText;
|
||||
btn.disabled = false;
|
||||
btn.classList.remove('is-copied');
|
||||
delete btn.dataset.copyFeedbackActive;
|
||||
}, 1200);
|
||||
}
|
||||
|
||||
function toStringList(value) {
|
||||
return Array.isArray(value)
|
||||
? value.map(function (item) { return String(item).trim(); })
|
||||
@@ -98,9 +131,9 @@
|
||||
|
||||
const copyBtn = document.createElement('button');
|
||||
copyBtn.type = 'button';
|
||||
copyBtn.className = 'px-3 py-1.5 text-sm rounded-lg bg-primary/20 hover:bg-primary/30 text-primary transition-colors duration-200';
|
||||
copyBtn.className = 'ai-copy-trigger px-3 py-1.5 text-sm rounded-lg bg-primary/20 hover:bg-primary/30 text-primary transition-colors duration-200';
|
||||
copyBtn.textContent = '复制俄文';
|
||||
copyBtn.addEventListener('click', function () { copyText(ru); });
|
||||
copyBtn.addEventListener('click', function () { copyText(ru, copyBtn); });
|
||||
|
||||
const fillBtn = document.createElement('button');
|
||||
fillBtn.type = 'button';
|
||||
@@ -253,7 +286,6 @@
|
||||
|
||||
const payload = {
|
||||
source_text: sourceText,
|
||||
product_name: (productNameInput && productNameInput.value || '').trim(),
|
||||
model_code: (modelCodeInput && modelCodeInput.value || '').trim(),
|
||||
model: (modelSelectEl && modelSelectEl.value || '').trim(),
|
||||
};
|
||||
@@ -307,7 +339,7 @@
|
||||
btn.addEventListener('click', function () {
|
||||
const sourceId = btn.getAttribute('data-copy-source');
|
||||
const el = sourceId ? document.getElementById(sourceId) : null;
|
||||
copyText(el ? el.textContent : '');
|
||||
copyText(el ? el.textContent : '', btn);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -315,13 +347,13 @@
|
||||
tagsContainerEl.addEventListener('click', function (event) {
|
||||
const chip = event.target.closest('.ai-tag-chip');
|
||||
if (!chip || !tagsContainerEl.contains(chip)) return;
|
||||
copyText(chip.getAttribute('data-tag-ru') || '');
|
||||
copyText(chip.getAttribute('data-tag-ru') || '', chip);
|
||||
});
|
||||
}
|
||||
|
||||
if (copyAllTagsBtn) {
|
||||
copyAllTagsBtn.addEventListener('click', function () {
|
||||
copyText(lastTagsRu.join(', '));
|
||||
copyText(lastTagsRu.join(', '), copyAllTagsBtn);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user