fix(IdentityField): 确保身份证号验证前转换为字符串类型
避免当传入非字符串类型值时导致indexOf方法调用失败
Showing
1 changed file
with
9 additions
and
5 deletions
| ... | @@ -137,7 +137,9 @@ watch( | ... | @@ -137,7 +137,9 @@ watch( |
| 137 | (v) => { | 137 | (v) => { |
| 138 | if (v) { | 138 | if (v) { |
| 139 | props.item.value = v; | 139 | props.item.value = v; |
| 140 | - if (v.indexOf('*') !== -1) { // 默认值是加密模式 | 140 | + // 确保v是字符串类型后再调用indexOf方法 |
| 141 | + const vStr = String(v); | ||
| 142 | + if (vStr.indexOf('*') !== -1) { // 默认值是加密模式 | ||
| 141 | props.item.component_props.readonly = true; | 143 | props.item.component_props.readonly = true; |
| 142 | data_type.value = 'encrypt_mode'; | 144 | data_type.value = 'encrypt_mode'; |
| 143 | } | 145 | } |
| ... | @@ -191,13 +193,15 @@ var checkCode = function (val) { | ... | @@ -191,13 +193,15 @@ var checkCode = function (val) { |
| 191 | 193 | ||
| 192 | const idCard = { | 194 | const idCard = { |
| 193 | verify: function (val) { | 195 | verify: function (val) { |
| 194 | - if (val.indexOf('*') !== -1 && data_type.value === 'encrypt_mode') { // 默认值是加密模式,跳过校验 | 196 | + // 确保val是字符串类型 |
| 197 | + const valStr = String(val || ''); | ||
| 198 | + if (valStr.indexOf('*') !== -1 && data_type.value === 'encrypt_mode') { // 默认值是加密模式,跳过校验 | ||
| 195 | return true; | 199 | return true; |
| 196 | } | 200 | } |
| 197 | - if (checkCode(val)) { | 201 | + if (checkCode(valStr)) { |
| 198 | - var date = val.substring(6,14); | 202 | + var date = valStr.substring(6,14); |
| 199 | if (checkDate(date)) { | 203 | if (checkDate(date)) { |
| 200 | - if (checkProv(val.substring(0,2))) { | 204 | + if (checkProv(valStr.substring(0,2))) { |
| 201 | return true; | 205 | return true; |
| 202 | } | 206 | } |
| 203 | } | 207 | } | ... | ... |
-
Please register or login to post a comment