国内赛
Showing
2 changed files
with
70 additions
and
22 deletions
| ... | @@ -114,10 +114,10 @@ export function selectDictLabels(datas, value, separator) { | ... | @@ -114,10 +114,10 @@ export function selectDictLabels(datas, value, separator) { |
| 114 | 114 | ||
| 115 | // 字符串格式化(%s ) | 115 | // 字符串格式化(%s ) |
| 116 | export function sprintf(str) { | 116 | export function sprintf(str) { |
| 117 | var args = arguments; | 117 | var args = arguments |
| 118 | var flag = true; | 118 | var flag = true |
| 119 | var i = 1 | 119 | var i = 1 |
| 120 | str = str.replace(/%s/g, function () { | 120 | str = str.replace(/%s/g, function() { |
| 121 | var arg = args[i++] | 121 | var arg = args[i++] |
| 122 | if (typeof arg === 'undefined') { | 122 | if (typeof arg === 'undefined') { |
| 123 | flag = false | 123 | flag = false |
| ... | @@ -323,3 +323,42 @@ export function triggerLanguage(fn, cn, en) { | ... | @@ -323,3 +323,42 @@ export function triggerLanguage(fn, cn, en) { |
| 323 | return cn | 323 | return cn |
| 324 | } | 324 | } |
| 325 | } | 325 | } |
| 326 | |||
| 327 | |||
| 328 | export function parseIDCardInfo(idNumber) { | ||
| 329 | // 基础校验 | ||
| 330 | if (typeof idNumber !== 'string' || (idNumber.length !== 15 && idNumber.length !== 18)) { | ||
| 331 | return { error: '身份证号码格式错误(需15位或18位数字)' } | ||
| 332 | } | ||
| 333 | |||
| 334 | // 移除可能的空格(兼容用户输入带空格的情况) | ||
| 335 | const cleanId = idNumber.replace(/\s+/g, '') | ||
| 336 | |||
| 337 | // 解析出生日期 | ||
| 338 | let birthDate | ||
| 339 | if (cleanId.length === 18) { | ||
| 340 | // 18位:第7-14位为YYYYMMDD | ||
| 341 | const datePart = cleanId.slice(6, 14) | ||
| 342 | if (!/^\d{8}$/.test(datePart)) return { error: '身份证号码出生日期部分无效' } | ||
| 343 | birthDate = datePart.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3') | ||
| 344 | } else { | ||
| 345 | // 15位:第7-12位为YYMMDD(补全年份为19xx) | ||
| 346 | const datePart = cleanId.slice(6, 12) | ||
| 347 | if (!/^\d{6}$/.test(datePart)) return { error: '身份证号码出生日期部分无效' } | ||
| 348 | const year = `19${datePart.slice(0, 2)}` // 15位身份证年份默认19xx | ||
| 349 | const month = datePart.slice(2, 4).padStart(2, '0') | ||
| 350 | const day = datePart.slice(4, 6).padStart(2, '0') | ||
| 351 | birthDate = `${year}-${month}-${day}` | ||
| 352 | } | ||
| 353 | |||
| 354 | // 解析性别(最后一位前的奇偶判断) | ||
| 355 | const genderDigit = cleanId.slice(-2, -1) // 18位取倒数第2位,15位取倒数第2位(总长度15时slice(14,15)) | ||
| 356 | const genderCode = parseInt(genderDigit, 10) | ||
| 357 | if (isNaN(genderCode)) return { error: '身份证号码性别位无效' } | ||
| 358 | |||
| 359 | return { | ||
| 360 | gender: genderCode % 2 === 1 ? '男' : '女', | ||
| 361 | birthDate: birthDate, | ||
| 362 | rawId: cleanId // 可选:返回清理后的原始号码 | ||
| 363 | } | ||
| 364 | } | ... | ... |
| ... | @@ -38,14 +38,14 @@ | ... | @@ -38,14 +38,14 @@ |
| 38 | </el-form-item> | 38 | </el-form-item> |
| 39 | 39 | ||
| 40 | <el-form-item :label="language==0?'性别':'Gender'" prop="sex"> | 40 | <el-form-item :label="language==0?'性别':'Gender'" prop="sex"> |
| 41 | <el-radio-group v-model="form.sex" :disabled="editgay&&form.labelArr.indexOf('0')>-1"> | 41 | <el-radio-group v-model="form.sex" :disabled="editgay&&form.labelArr.indexOf('0')>-1||form.idcType==0"> |
| 42 | <el-radio value="0">{{ language == 0 ? '女' : 'female' }}</el-radio> | 42 | <el-radio value="0">{{ language == 0 ? '女' : 'female' }}</el-radio> |
| 43 | <el-radio value="1">{{ language == 0 ? '男' : 'male' }}</el-radio> | 43 | <el-radio value="1">{{ language == 0 ? '男' : 'male' }}</el-radio> |
| 44 | </el-radio-group> | 44 | </el-radio-group> |
| 45 | </el-form-item> | 45 | </el-form-item> |
| 46 | <el-form-item :label="language==0?'出生日期':'Date of Birth'" prop="birth" required> | 46 | <el-form-item :label="language==0?'出生日期':'Date of Birth'" prop="birth" required> |
| 47 | <el-date-picker | 47 | <el-date-picker |
| 48 | v-model="form.birth" :disabled="editgay&&form.labelArr.indexOf('0')>-1" | 48 | v-model="form.birth" :disabled="editgay&&form.labelArr.indexOf('0')>-1||form.idcType==0" |
| 49 | :disabled-date="disabledBirth" | 49 | :disabled-date="disabledBirth" |
| 50 | format="YYYY-MM-DD" style="width: 100%;" type="date" | 50 | format="YYYY-MM-DD" style="width: 100%;" type="date" |
| 51 | value-format="YYYY-MM-DD" | 51 | value-format="YYYY-MM-DD" |
| ... | @@ -104,6 +104,7 @@ | ... | @@ -104,6 +104,7 @@ |
| 104 | <script setup> | 104 | <script setup> |
| 105 | import { reactive, ref, toRefs, watch } from 'vue' | 105 | import { reactive, ref, toRefs, watch } from 'vue' |
| 106 | import { getCurrentInstance, nextTick, onMounted } from '@vue/runtime-core' | 106 | import { getCurrentInstance, nextTick, onMounted } from '@vue/runtime-core' |
| 107 | import { parseIDCardInfo } from '@/utils/ruoyi' | ||
| 107 | import * as match from '@/apiPc/match' | 108 | import * as match from '@/apiPc/match' |
| 108 | import { dayjs, ElMessage } from 'element-plus' | 109 | import { dayjs, ElMessage } from 'element-plus' |
| 109 | import _ from 'lodash' | 110 | import _ from 'lodash' |
| ... | @@ -125,6 +126,7 @@ const certificates = ref([ | ... | @@ -125,6 +126,7 @@ const certificates = ref([ |
| 125 | } | 126 | } |
| 126 | ]) | 127 | ]) |
| 127 | const { proxy } = getCurrentInstance() | 128 | const { proxy } = getCurrentInstance() |
| 129 | const disabledIdcType = ref(false) | ||
| 128 | const emit = defineEmits(['submitForm']) | 130 | const emit = defineEmits(['submitForm']) |
| 129 | const data = reactive({ | 131 | const data = reactive({ |
| 130 | form: { | 132 | form: { |
| ... | @@ -302,30 +304,37 @@ function checkCode() { | ... | @@ -302,30 +304,37 @@ function checkCode() { |
| 302 | 304 | ||
| 303 | function giveBirthDay() { | 305 | function giveBirthDay() { |
| 304 | // 判断身份证正确性/赋值生日 | 306 | // 判断身份证正确性/赋值生日 |
| 305 | if (form.value.idcType == 0) { | 307 | if (form.value.idcCode && form.value.idcType == 0) { |
| 306 | if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(form.value.idcCode))) { | 308 | if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(form.value.idcCode))) { |
| 307 | ElMessage.warning('请输入正确的身份证号码') | 309 | ElMessage.warning('请输入正确的身份证号码') |
| 308 | } else { | 310 | } else { |
| 309 | let tmpStr = '' | 311 | const res = parseIDCardInfo(form.value.idcCode) |
| 310 | if (form.value.idcCode.length == 15) { | 312 | if (res.gender == '女') { |
| 311 | tmpStr = form.value.idcCode.substring(6, 12) | ||
| 312 | tmpStr = '19' + tmpStr | ||
| 313 | tmpStr = tmpStr.substring(0, 4) + '-' + tmpStr.substring(4, 6) + '-' + tmpStr.substring(6) | ||
| 314 | } else { | ||
| 315 | tmpStr = form.value.idcCode.substring(6, 14) | ||
| 316 | tmpStr = tmpStr.substring(0, 4) + '-' + tmpStr.substring(4, 6) + '-' + tmpStr.substring(6) | ||
| 317 | } | ||
| 318 | form.value.birth = tmpStr | ||
| 319 | |||
| 320 | const res = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/ | ||
| 321 | if (form.value.idcCode && res.test(form.value.idcCode)) { | ||
| 322 | const genderCode = form.value.idcCode.charAt(16) | ||
| 323 | if (parseInt(genderCode) % 2 == 0) { | ||
| 324 | form.value.sex = '0' | 313 | form.value.sex = '0' |
| 325 | } else { | 314 | } else { |
| 326 | form.value.sex = '1' | 315 | form.value.sex = '1' |
| 327 | } | 316 | } |
| 328 | } | 317 | if (res.birthDate) form.value.birth = res.birthDate |
| 318 | // let tmpStr = '' | ||
| 319 | // if (form.value.idcCode.length == 15) { | ||
| 320 | // tmpStr = form.value.idcCode.substring(6, 12) | ||
| 321 | // tmpStr = '19' + tmpStr | ||
| 322 | // tmpStr = tmpStr.substring(0, 4) + '-' + tmpStr.substring(4, 6) + '-' + tmpStr.substring(6) | ||
| 323 | // } else { | ||
| 324 | // tmpStr = form.value.idcCode.substring(6, 14) | ||
| 325 | // tmpStr = tmpStr.substring(0, 4) + '-' + tmpStr.substring(4, 6) + '-' + tmpStr.substring(6) | ||
| 326 | // } | ||
| 327 | // form.value.birth = tmpStr | ||
| 328 | // | ||
| 329 | // const res = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/ | ||
| 330 | // if (form.value.idcCode && res.test(form.value.idcCode)) { | ||
| 331 | // const genderCode = form.value.idcCode.charAt(16) | ||
| 332 | // if (parseInt(genderCode) % 2 == 0) { | ||
| 333 | // form.value.sex = '0' | ||
| 334 | // } else { | ||
| 335 | // form.value.sex = '1' | ||
| 336 | // } | ||
| 337 | // } | ||
| 329 | } | 338 | } |
| 330 | } | 339 | } |
| 331 | } | 340 | } | ... | ... |
-
Please register or sign in to post a comment