@
15m44k 修两个新 bug: 删图后不让提交(可选附件误当必填) + 每次提交重复图(未去重)
Bug A: 15m44i 把"0 张图"当必填拦截, 用户删完所有图后 files.length===0 被拦→"未选择图片"
红字+不让提交。但图片是"可选附件"非必填, 删完也能提交(走 JSON 无图路径)。
修: 删 4080 行 0 张拦截, 改 errEl.textContent=""(不报错), 0 张正常走 JSON 路径提交。
Bug B: 用户选同一张图多次(或 input.files 含重复), ticketState.files 里多个相同 File 对象,
提交时 forEach append 多次相同文件→后端收到 N 张相同→EasyImages"今日 N 张重复"
(工单 #8/#9 都 1123 重复, 后台今日 2 张一模一样)。
修: ① 暂存阶段 uploadTicketImage 推入前按 name+size+lastModified 去重(重复忽略);
② 提交阶段 submitTicket 的 files 也去重(双保险, 防已暂存数组里残留重复)。
★教训: "可选附件"绝不能用 files.length===0 拦截提交(那是必填语义); 多文件 append 前必须
按 File 指纹(name+size+lastModified)去重, 否则同一张图传多次=后台 N 张重复。
This commit is contained in:
+17
-4
@@ -3984,6 +3984,11 @@ if ($currentVersion !== $BUILD_VERSION) {
|
|||||||
if (!okExts.includes(ext)) { setImgMsg(msg, '仅支持 ' + ticketImgCfg.allowed_exts.join(' / ') + ':' + file.name, true); continue; }
|
if (!okExts.includes(ext)) { setImgMsg(msg, '仅支持 ' + ticketImgCfg.allowed_exts.join(' / ') + ':' + file.name, true); continue; }
|
||||||
if (file.type && !file.type.startsWith('image/')) { setImgMsg(msg, '这不是图片文件:' + file.name, true); continue; }
|
if (file.type && !file.type.startsWith('image/')) { setImgMsg(msg, '这不是图片文件:' + file.name, true); continue; }
|
||||||
if (file.size > maxBytes) { setImgMsg(msg, '超过 ' + ticketImgCfg.max_size_mb + 'MB:' + file.name, true); continue; }
|
if (file.size > maxBytes) { setImgMsg(msg, '超过 ' + ticketImgCfg.max_size_mb + 'MB:' + file.name, true); continue; }
|
||||||
|
// 15m44k: 暂存阶段去重(按 name+size+lastModified), 防同一张图被选多次导致提交重复
|
||||||
|
const k = file.name + '|' + file.size + '|' + file.lastModified;
|
||||||
|
if ((ticketState.files || []).some(f => (f.name + '|' + f.size + '|' + f.lastModified) === k)) {
|
||||||
|
setImgMsg(msg, '重复图片已忽略:' + file.name, false); continue;
|
||||||
|
}
|
||||||
ticketState.files = ticketState.files || [];
|
ticketState.files = ticketState.files || [];
|
||||||
ticketState.files.push(file);
|
ticketState.files.push(file);
|
||||||
insertTicketPh('[图片' + ticketState.files.length + ']');
|
insertTicketPh('[图片' + ticketState.files.length + ']');
|
||||||
@@ -4075,11 +4080,11 @@ if ($currentVersion !== $BUILD_VERSION) {
|
|||||||
const errEl = document.getElementById('ticketError');
|
const errEl = document.getElementById('ticketError');
|
||||||
if (!title) { errEl.textContent = '请输入标题'; return; }
|
if (!title) { errEl.textContent = '请输入标题'; return; }
|
||||||
if (!desc) { errEl.textContent = '请输入描述'; return; }
|
if (!desc) { errEl.textContent = '请输入描述'; return; }
|
||||||
// 15m44i: 提交前校验暂存图, 0 张时提示"未选择图片" (不再"没反应")
|
// 15m44k: 图片是"可选附件"不是必填——0 张也能提交工单(走 JSON 无图路径)。
|
||||||
|
// 旧 15m44i 误把 0 张当必填拦截, 删完所有图就提交不了。改为: 0 张不拦, 仅清空 errEl。
|
||||||
const files = ticketState.files || [];
|
const files = ticketState.files || [];
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
errEl.textContent = '未选择图片(可选:点上方"📷 选择图片"暂存 1-3 张, 提交时一并上传图床)';
|
errEl.textContent = ''; // 无图不报错, 正常走 JSON 路径提交
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -4091,11 +4096,19 @@ if ($currentVersion !== $BUILD_VERSION) {
|
|||||||
let res;
|
let res;
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
// FormData: 字段 + 多文件(images[] 同名字段, 服务端 uploadTicketFiles 兼容解析)
|
// FormData: 字段 + 多文件(images[] 同名字段, 服务端 uploadTicketFiles 兼容解析)
|
||||||
|
// 15m44k: 按 name+size+lastModified 去重, 防同一张图被 append 多次(易生"今日 N 张重复")
|
||||||
|
const seen = new Set();
|
||||||
|
const uniq = files.filter(f => {
|
||||||
|
const k = f.name + '|' + f.size + '|' + f.lastModified;
|
||||||
|
if (seen.has(k)) return false;
|
||||||
|
seen.add(k);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('type', type);
|
fd.append('type', type);
|
||||||
fd.append('title', title);
|
fd.append('title', title);
|
||||||
fd.append('description', desc);
|
fd.append('description', desc);
|
||||||
files.forEach((f, i) => fd.append('images[]', f, f.name));
|
uniq.forEach((f, i) => fd.append('images[]', f, f.name));
|
||||||
res = await fetch(url, { method: 'POST', body: fd });
|
res = await fetch(url, { method: 'POST', body: fd });
|
||||||
} else {
|
} else {
|
||||||
res = await fetch(url, {
|
res = await fetch(url, {
|
||||||
|
|||||||
Reference in New Issue
Block a user