vue页面隐藏个人信息用*代替,两种方法(详细)

1.当是表单时候:即
<el-col :span="8">
  <el-form-item label="身份证号码" prop="pIdentityId">
    <el-input v-model="form.pIdentityId" placeholder="" clearable :style="{width: '100%'}">
    </el-input>
  </el-form-item>
</el-col>

使用下面这种方式:定义一个类负责进行信息替换

 1 //将姓名进行隐藏处理
 2 nameFormat (item) {
 3   console.log(item)
 4   if (!item) return '';
 5   let str = item;
 6   if(str.length == 2){
 7     str = str.toString().replace(/^([^\x00-\xff])([^\x00-\xff]{0,})([^\x00-\xff])/g , '$1*')
 8   }else if(str.length == 3){
 9     str = str.toString().replace(/^([^\x00-\xff])([^\x00-\xff]{0,})([^\x00-\xff])/g , '$1*$3')
10   }else if(str.length == 4){
11     str = str.toString().replace(/^([^\x00-\xff])([^\x00-\xff]{0,2})([^\x00-\xff])/g , '$1**$3')
12   }else if(str.length > 4){
13     str = str.toString().replace(/^([^\x00-\xff])([^\x00-\xff]{0,3})([^\x00-\xff])/g , '$1***$3')
14   }else{}
15   // str = str.toString().replace(/^([^\x00-\xff])([^\x00-\xff]{1,3})([^\x00-\xff])/g , '$1**$3')
16   return str;
17 },
18 
19 //将身份证号进行隐藏处理
20 formatIDcard (value) {
21   if (!value) return '';
22   let str = value;
23   str = str.toString().replace(/^(.{6})(?:\w+)(.{4})$/ , '$1********$2')
24   return str;
25 },
26 
27 //将电话号进行处理
28 formatPhone (value) {
29   if (!value) return '';
30   let str = value;
31   str = str.toString().replace(/^(\d{3})(\d{4})(\d{4})/g , '$1****$3')
32   return str;
33 },
需要注意的是 需要在接收值的时候进行转化即接收值的时候进行处理
 1 handleUpdate(row) {
 2   this.reset();
 3   if (row != '') {
 4     var r = row;
 5     this.selectedOptions = [];
 6     if(r.pProvince != null) {
 7       this.selectedOptions.push(TextToCode[r.pProvince].code);
 8       if (r.pProvince != null) {
 9         this.selectedOptions.push(TextToCode[r.pProvince][r.pCity].code);
10         if(r.pArea != null) {
11           this.selectedOptions.push(
12             TextToCode[r.pProvince][r.pCity][r.pArea].code)
13         }
14       }
15     }
16    //获取转换的姓名
17   var pName = this.nameFormat(row.pName);
18     r.pName = pName;
19 
20     //获取转换的身份证号
21    var pIdentityId = this.formatIDcard(row.pIdentityId) ;
22    r.pIdentityId = pIdentityId;
23 
24     //获取转换的联系电话
25     var pPhone = this.formatPhone(row.pPhone);
26     r.pPhone = pPhone;
第二种方式: 当是 div时候直接转化就行
<div class="grid-content bg-purple" style="font-weight: bolder; font-size: 20px">
  姓名:{{patientInfo.pName?patientInfo.pName.replace(/^([^\x00-\xff])([^\x00-\xff]{0,})([^\x00-\xff])/g , '$1*'):""}}
</div>

 

 
posted @ 2021-02-08 21:10  贩卖人烟  阅读(2144)  评论(0编辑  收藏  举报