diff --git a/src/Masa.Stack.Components/Extensions/TextFormattingExtensions.cs b/src/Masa.Stack.Components/Extensions/TextFormattingExtensions.cs new file mode 100644 index 00000000..ee497df6 --- /dev/null +++ b/src/Masa.Stack.Components/Extensions/TextFormattingExtensions.cs @@ -0,0 +1,46 @@ +namespace Masa.Stack.Components.Extensions; + +public static class TextFormattingExtensions +{ + public static string MaskPhoneNumber(this string phoneNumber) + { + if (phoneNumber.Length == 11) + { + return phoneNumber.Substring(0, 3) + "****" + phoneNumber.Substring(7); + } + return phoneNumber; + } + + public static string MaskIdCard(this string idCard) + { + if (idCard.Length == 18) + { + return idCard.Substring(0, 6) + "********" + idCard.Substring(14); + } + return idCard; + } + + public static string MaskAccount(this string account) + { + if (account.Length > 2) + { + return account.Substring(0, 1) + new string('*', account.Length - 2) + account.Substring(account.Length - 1); + } + else if (account.Length == 2) + { + return account.Substring(0, 1) + "*"; + } + return account; + } + + public static string MaskSensitiveInfo(this string input, string type) + { + return type switch + { + "phone" => input.MaskPhoneNumber(), + "idCard" => input.MaskIdCard(), + "account" => input.MaskAccount(), + _ => input + }; + } +} diff --git a/src/Masa.Stack.Components/Shared/IntegrationComponents/Users/SUserAutoComplete.razor b/src/Masa.Stack.Components/Shared/IntegrationComponents/Users/SUserAutoComplete.razor index 62495297..ba2368e5 100644 --- a/src/Masa.Stack.Components/Shared/IntegrationComponents/Users/SUserAutoComplete.razor +++ b/src/Masa.Stack.Components/Shared/IntegrationComponents/Users/SUserAutoComplete.razor @@ -27,6 +27,6 @@ Clearable=Clearable PrependInnerIcon="mdi-magnify"> - @RenderFragments.UserSelectItem(data.Item.Avatar, data.Item.DisplayName, data.Item.PhoneNumber, data.Item.Account, data.Item.Email) + @RenderFragments.UserSelectItem(data.Item.Avatar, data.Item.DisplayName, data.Item.PhoneNumber?.MaskPhoneNumber(), data.Item.Account.MaskAccount(), data.Item.Email) \ No newline at end of file diff --git a/tests/MasaWebApp/Shared/MainLayout.razor b/tests/MasaWebApp/Shared/MainLayout.razor index 2c3aebfb..f0ba6434 100644 --- a/tests/MasaWebApp/Shared/MainLayout.razor +++ b/tests/MasaWebApp/Shared/MainLayout.razor @@ -1,7 +1,7 @@ @using Masa.Stack.Components.Models @inherits LayoutComponentBase - @Body