From f05e353d1e601ffd7a25630705fbcb808f42d65b Mon Sep 17 00:00:00 2001 From: wuzilong <704541015@qq.com> Date: Mon, 14 Sep 2026 11:32:17 +0800 Subject: [PATCH] feat(miniprogram): add apply attachment display name helper Co-authored-by: Cursor --- miniprogram/utils/bxAttachmentDisplayName.js | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 miniprogram/utils/bxAttachmentDisplayName.js diff --git a/miniprogram/utils/bxAttachmentDisplayName.js b/miniprogram/utils/bxAttachmentDisplayName.js new file mode 100644 index 000000000..a43b4356a --- /dev/null +++ b/miniprogram/utils/bxAttachmentDisplayName.js @@ -0,0 +1,28 @@ +const ILLEGAL = /[/\\:*?"<>|\u0000-\u001f]/g + +export function sanitizeRemarkBaseName(remark) { + const cleaned = String(remark || '') + .trim() + .replace(ILLEGAL, '_') + .replace(/\s+/g, '_') + .replace(/_+/g, '_') + .replace(/^_|_$/g, '') + if (!cleaned) return '' + return cleaned.length > 40 ? cleaned.slice(0, 40) : cleaned +} + +function splitExt(fileName) { + const name = String(fileName || '') + const i = name.lastIndexOf('.') + if (i <= 0 || i === name.length - 1) return { base: name, ext: '' } + return { base: name.slice(0, i), ext: name.slice(i) } +} + +export function buildApplyAttachmentDisplayName({ remark, originalFileName, index1 }) { + const original = String(originalFileName || '').trim() || '申请附件' + const base = sanitizeRemarkBaseName(remark) + if (!base) return original + const { ext } = splitExt(original) + const n = Math.max(1, Math.floor(Number(index1) || 1)) + return `${base}_${n}${ext}` +}