场景:不知道长度的情况下把一串秘钥中间用*替换

 

过滤器
filters:{
      hideInfo(val) {
        let str = [null,undefined,""];
        if (!str.includes(val) && val.length > 9) {
          let valLen = val.length;
          const  numt = 1;
          const  num = 2;
          let  numf = 2;
          if (valLen > 26) {
            numf=numf*2;
          }
          if (valLen % 2 == 0) {
            return val.substring(0,valLen/num-numf)+"******"+val.substring((valLen/num)+numf);
          }else {
            valLen += numt;
            return val.substring(0,(valLen/num)-numf-numt)+"******"+val.substring((valLen/num)+numf-numt);
          }
        }else {
          return val;
        }
      }
    },

 

Logo

前往低代码交流专区

更多推荐