Browse Source

身份证隐藏

zhuli 1 week ago
parent
commit
d5dd23b8c8
2 changed files with 20 additions and 1 deletions
  1. 17 0
      src/utils/index.ts
  2. 3 1
      src/views/financialManagement/realName.vue

+ 17 - 0
src/utils/index.ts

@@ -343,3 +343,20 @@ export function findItemNested(enumData: any, callValue: any, value: string, chi
 
 // 导出权限判断相关函数
 export { usePermission } from "./permission";
+
+/**
+ * @description 身份证号脱敏处理,只显示前4位和后4位,中间用*代替
+ * @param {String} idCard 身份证号
+ * @returns {String} 脱敏后的身份证号
+ * */
+export function maskIdCard(idCard: string): string {
+  if (!idCard) return "";
+
+  // 如果身份证号长度小于等于8位,则只显示第一位和最后一位
+  if (idCard.length <= 8) {
+    return idCard.replace(/(.).*(.)$/, "$1****$2");
+  }
+
+  // 正常情况下显示前4位和后4位
+  return idCard.replace(/(\d{4})\d+(\d{4})/, "$1**********$2");
+}

+ 3 - 1
src/views/financialManagement/realName.vue

@@ -41,7 +41,7 @@
           <el-row class="auth-row">
             <el-col :span="2"> 身份证号 </el-col>
             <el-col :span="12">
-              {{ userInfo.idCard }}
+              {{ maskIdCard(userInfo.idCard) }}
             </el-col>
           </el-row>
           <el-row class="auth-row">
@@ -300,6 +300,8 @@ import homeIcon from "../../assets/images/home-icon.png";
 import zfbIcon from "../../assets/financial/zfb-icon.png";
 import { lo } from "element-plus/es/locale";
 import { getPhoneCode, getCheckSmsCode } from "@/api/modules/newLoginApi";
+import { maskIdCard } from "@/utils/index";
+
 // 初始化用户信息,统一处理支付宝账号字段名(兼容 aliPayAccount 和 alipayAccount)
 const initUserInfo = () => {
   const cachedUserInfo = localGet("geeker-user")?.userInfo || {};