Blame view

store-pc/src/utils/mobile-mask.js 835 Bytes
4528226f   “wangming”   feat: 管理端暗黑焕肤与阿里云...
1
2
  /**
   * 手机号脱敏工具(受系统配置 privacyMobileMask 控制)
e1dcb3a0   “wangming”   1
3
   * 默认明文;开关开启时中间四位打码,如 181****7871
4528226f   “wangming”   feat: 管理端暗黑焕肤与阿里云...
4
5
6
7
8
9
   */
  
  export function maskMobileValue(mobile) {
    if (mobile == null || mobile === '') return ''
    const m = String(mobile).trim()
    if (!m) return ''
e1dcb3a0   “wangming”   1
10
    if (m.indexOf('*') !== -1) return m
4528226f   “wangming”   feat: 管理端暗黑焕肤与阿里云...
11
12
13
14
15
16
17
18
19
    if (m.length < 7) return '****'
    return `${m.slice(0, 3)}****${m.slice(-4)}`
  }
  
  export function formatMobileDisplay(mobile, enabled) {
    const raw = mobile == null ? '' : String(mobile).trim()
    if (!raw) return ''
    return Number(enabled) === 1 ? maskMobileValue(raw) : raw
  }
e1dcb3a0   “wangming”   1
20
21
22
23
24
25
26
27
28
29
30
  
  export function displayMobile(mobile, enabled, emptyText = '') {
    const v = formatMobileDisplay(mobile, enabled)
    return v || emptyText
  }
  
  export default {
    maskMobileValue,
    formatMobileDisplay,
    displayMobile
  }