laiqi пре 1 година
родитељ
комит
a945948465
1 измењених фајлова са 12 додато и 1 уклоњено
  1. 12 1
      src/pages/index/index.vue

+ 12 - 1
src/pages/index/index.vue

@@ -71,7 +71,7 @@
             :key="index"
             class="flex items-center gap-2 py-1"
           >
-            <text class="text-sm">{{ record.name }}</text>
+            <text class="text-sm">{{ desensitizeName(record.name) }}</text>
             <text class="text-xs text-green-500">申请</text>
             <text class="text-xs text-gray-400 ml-auto">
               {{ formatTimeText(record.time) }}已申请优惠劵
@@ -148,6 +148,17 @@ const applyRecords = ref([
   { name: '赵六', time: new Date(Date.now() - 2 * 60 * 60 * 1000) },
 ])
 
+// 脱敏name字段 如果姓名2个字,最后一个字替换为*;如果大于3个字,保留第一个和最后一个字,中间全部替换为*;
+function desensitizeName(name: string) {
+  if (name.length === 2) {
+    return name.substring(0, 1) + '*'
+  } else if (name.length >= 3) {
+    const stars = '*'.repeat(name.length - 2)
+    return name.charAt(0) + stars + name.charAt(name.length - 1)
+  }
+  return name
+}
+
 // 处理拨打电话
 function handleCall(phone: string) {
   uni.makePhoneCall({