wangrong
2026-08-30 4c949c0dc9bcae785c281c9d8125295f09810b15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 替换所有 标准模板格式 为 $panelName$
export function pdfTemplateReplaceAll(content, source, target) {
  const pattern = '\\$' + source + '\\$'
  content = content.replace(new RegExp(pattern, 'gm'), target)
  return content
}
 
export function randomRange(min, max) {
  let returnStr = ''
  const range = max ? Math.round(Math.random() * (max - min)) + min : min
  const charStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
 
  for (let i = 0; i < range; i++) {
    const index = Math.round(Math.random() * (charStr.length - 1))
    returnStr += charStr.substring(index, index + 1)
  }
  return returnStr
}
 
export function equalsAny(target, ...sources) {
  for (let i = 0; i < sources.length; i++) {
    if (target === sources[i]) {
      return true
    }
  }
  return false
}
 
export function includesAny(target, ...sources) {
  if (!target || !sources) {
    return false
  }
  for (let i = 0; i < sources.length; i++) {
    if (target.includes(sources[i])) {
      return true
    }
  }
  return false
}
 
// 替换字符串中的国际化内容, 格式为$t('xxx')
export function replaceInlineI18n(rawString) {
  const res = []
  const reg = /\$t\('([\w.]+)'\)/gm
  let tmp
  if (!rawString) {
    return res
  }
  while ((tmp = reg.exec(rawString)) !== null) {
    res.push(tmp)
  }
  res.forEach(tmp => {
    rawString = rawString.replaceAll(tmp[0], tmp[1])
  })
  return rawString
}