Newer
Older
securityFront / src / utils / dataAnalysis.js
TAN YUE on 9 Dec 2020 694 bytes 20201209 初始提交 车辆管理
// 数据处理功能
// 从身份证号提取生日
export function getBirthdayByIdNO(IdNO) {
  let birthday = ''
  if (IdNO.length === 18) {
    birthday = IdNO.substr(6, 8)
    return birthday.replace(/(.{4})(.{2})/, '$1-$2-')
  } else if (IdNO.length === 15) {
    birthday = '19' + IdNO.substr(6, 6)
    return birthday.replace(/(.{4})(.{2})/, '$1-$2-')
  } else {
    return ''
  }
}
// 从身份证号提取性别,1表示男,2表示女
export function getSexByIdNO(IdNO) {
  if (IdNO.length === 18) {
    // 奇数为男
    return IdNO.charAt(16) % 2 === 1 ? '1' : '2'
  } else if (IdNO.length === 15) {
    return IdNO.charAt(14) % 2 === 1 ? '1' : '2'
  } else {
    return ''
  }
}