国内赛
Showing
2 changed files
with
81 additions
and
33 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 |
| ... | @@ -165,11 +165,11 @@ export function handleTree(data, id, parentId, children) { | ... | @@ -165,11 +165,11 @@ export function handleTree(data, id, parentId, children) { |
| 165 | parentId: parentId || 'parentId', | 165 | parentId: parentId || 'parentId', |
| 166 | childrenList: children || 'children' | 166 | childrenList: children || 'children' |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | var childrenListMap = {} | 169 | var childrenListMap = {} |
| 170 | var nodeIds = {} | 170 | var nodeIds = {} |
| 171 | var tree = [] | 171 | var tree = [] |
| 172 | 172 | ||
| 173 | for (const d of data) { | 173 | for (const d of data) { |
| 174 | const parentId = d[config.parentId] | 174 | const parentId = d[config.parentId] |
| 175 | if (childrenListMap[parentId] == null) { | 175 | if (childrenListMap[parentId] == null) { |
| ... | @@ -178,18 +178,18 @@ export function handleTree(data, id, parentId, children) { | ... | @@ -178,18 +178,18 @@ export function handleTree(data, id, parentId, children) { |
| 178 | nodeIds[d[config.id]] = d | 178 | nodeIds[d[config.id]] = d |
| 179 | childrenListMap[parentId].push(d) | 179 | childrenListMap[parentId].push(d) |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | for (const d of data) { | 182 | for (const d of data) { |
| 183 | const parentId = d[config.parentId] | 183 | const parentId = d[config.parentId] |
| 184 | if (nodeIds[parentId] == null) { | 184 | if (nodeIds[parentId] == null) { |
| 185 | tree.push(d) | 185 | tree.push(d) |
| 186 | } | 186 | } |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | for (const t of tree) { | 189 | for (const t of tree) { |
| 190 | adaptToChildrenList(t) | 190 | adaptToChildrenList(t) |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | function adaptToChildrenList(o) { | 193 | function adaptToChildrenList(o) { |
| 194 | if (childrenListMap[o[config.id]] !== null) { | 194 | if (childrenListMap[o[config.id]] !== null) { |
| 195 | o[config.childrenList] = childrenListMap[o[config.id]] | 195 | o[config.childrenList] = childrenListMap[o[config.id]] |
| ... | @@ -200,7 +200,7 @@ export function handleTree(data, id, parentId, children) { | ... | @@ -200,7 +200,7 @@ export function handleTree(data, id, parentId, children) { |
| 200 | } | 200 | } |
| 201 | } | 201 | } |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | return tree | 204 | return tree |
| 205 | } | 205 | } |
| 206 | 206 | ||
| ... | @@ -236,7 +236,7 @@ export function getNormalPath(p) { | ... | @@ -236,7 +236,7 @@ export function getNormalPath(p) { |
| 236 | if (p.length === 0 || !p || p == 'undefined') { | 236 | if (p.length === 0 || !p || p == 'undefined') { |
| 237 | return p | 237 | return p |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | const res = p.replace('//', '/') | 240 | const res = p.replace('//', '/') |
| 241 | if (res[res.length - 1] === '/') { | 241 | if (res[res.length - 1] === '/') { |
| 242 | return res.slice(0, res.length - 1) | 242 | return res.slice(0, res.length - 1) |
| ... | @@ -260,7 +260,7 @@ export function digitUppercase(price) { | ... | @@ -260,7 +260,7 @@ export function digitUppercase(price) { |
| 260 | if (price === null || price === undefined) { | 260 | if (price === null || price === undefined) { |
| 261 | return | 261 | return |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | const fraction = ['角', '分'] | 264 | const fraction = ['角', '分'] |
| 265 | const digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'] | 265 | const digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'] |
| 266 | const unit = [ | 266 | const unit = [ |
| ... | @@ -282,7 +282,7 @@ export function digitUppercase(price) { | ... | @@ -282,7 +282,7 @@ export function digitUppercase(price) { |
| 282 | } | 282 | } |
| 283 | s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s | 283 | s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | return s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整') | 286 | return s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整') |
| 287 | } | 287 | } |
| 288 | 288 | ||
| ... | @@ -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) | 313 | form.value.sex = '0' |
| 312 | tmpStr = '19' + tmpStr | ||
| 313 | tmpStr = tmpStr.substring(0, 4) + '-' + tmpStr.substring(4, 6) + '-' + tmpStr.substring(6) | ||
| 314 | } else { | 314 | } else { |
| 315 | tmpStr = form.value.idcCode.substring(6, 14) | 315 | form.value.sex = '1' |
| 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' | ||
| 325 | } else { | ||
| 326 | form.value.sex = '1' | ||
| 327 | } | ||
| 328 | } | 316 | } |
| 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