fix(products): 创建商品 · 修复卖点收集(读 .bl-text + 兜底未回车)· 增加必填提示 · 跳转延时 400→1200ms
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 5s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 5s
This commit is contained in:
parent
e3afa6659b
commit
2a3ae88dc5
@ -1677,20 +1677,30 @@ blInput.addEventListener('keydown', e => {
|
||||
|
||||
// 创建商品 (真正插入 grid)
|
||||
saveBtn.addEventListener('click', () => {
|
||||
// 防呆:每一步明确反馈,清晰看出在哪一步出问题
|
||||
const name = document.getElementById('pf-name').value.trim();
|
||||
const cat = document.getElementById('pf-cat').value;
|
||||
if (!name) {
|
||||
Shell.toast('请填写商品名称');
|
||||
Shell.toast('请填写商品名称', '必填项');
|
||||
document.getElementById('pf-name').focus();
|
||||
return;
|
||||
}
|
||||
if (pfFiles.length === 0) {
|
||||
Shell.toast('请上传商品主图', '至少 1 张');
|
||||
Shell.toast('请上传商品主图', '至少 1 张 · 必填');
|
||||
return;
|
||||
}
|
||||
// 计数器收集卖点 bullets
|
||||
const bullets = [...document.querySelectorAll('#pf-bullets .bl-item input')]
|
||||
.map(i => i.value.trim()).filter(Boolean);
|
||||
// 收集核心卖点:存在 .bl-item .bl-text 里(已确认的)+ .bl-add input(用户打了字但未回车)
|
||||
const confirmedBullets = [...document.querySelectorAll('#pf-bullets .bl-item .bl-text')]
|
||||
.map(el => el.textContent.trim()).filter(Boolean);
|
||||
const pendingInput = document.querySelector('#pf-bullets .bl-add .bl-input');
|
||||
const pendingText = (pendingInput?.value || '').trim();
|
||||
if (pendingText) confirmedBullets.push(pendingText); // 包容用户没按回车的情况
|
||||
if (confirmedBullets.length === 0) {
|
||||
Shell.toast('请填写核心卖点', '至少 1 条 · 回车确认');
|
||||
pendingInput?.focus();
|
||||
return;
|
||||
}
|
||||
const bullets = confirmedBullets;
|
||||
// 创建 card 并插入 grid 最前
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const card = document.createElement('div');
|
||||
@ -1767,7 +1777,7 @@ saveBtn.addEventListener('click', () => {
|
||||
const sidebar = document.querySelector('aside.sidebar a[href="products.html"] .pill-mini');
|
||||
if (sidebar) sidebar.textContent = remaining;
|
||||
|
||||
Shell.toast('商品已创建', `+ ${name} · 跳转至详情页`);
|
||||
Shell.toast('商品已创建 · 即将跳转详情', `+ ${name} · ${bullets.length} 条卖点`);
|
||||
closeNewProductDrawer();
|
||||
// 重置表单(为下次新建准备)
|
||||
document.getElementById('pf-name').value = '';
|
||||
@ -1777,10 +1787,12 @@ saveBtn.addEventListener('click', () => {
|
||||
if (pfGrid) pfGrid.innerHTML = '';
|
||||
const blList = document.getElementById('pf-bullets');
|
||||
if (blList) blList.querySelectorAll('.bl-item').forEach(li => li.remove());
|
||||
// 商品库新建商品后跳转到该商品的详情页(其他页保持原行为)
|
||||
const pendingI = document.querySelector('#pf-bullets .bl-add .bl-input');
|
||||
if (pendingI) pendingI.value = '';
|
||||
// 1200ms 后跳转(让 toast 看清),商品库新建商品后跳转到该商品的详情页
|
||||
setTimeout(() => {
|
||||
location.href = 'product-detail.html?t=' + Date.now() + '&product=' + encodeURIComponent(name);
|
||||
}, 400);
|
||||
}, 1200);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user