|
@@ -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}`
|
|
|
|
|
+}
|