feat(admin,partner,shop,mini,domain): 联系电话脱敏支持座机 + 套餐表单多行输入
- maskPhone/maskContactPhone 支持座机(含区号/分机)脱敏展示,domain 补充单测 - 套餐「使用时间/其他说明」由单行 input 改为多行 textarea(admin/h5-partner/h5-shop) - 后台「套餐审核」标签文字恒为白色(不受 Badge 角标影响) - 新增 deploy/sync-prod-db-to-local.sh:线上库经 SSH 隧道同步至本地(含 @ 密码/base64 解析、--lock-tables=0 兼容受限账号) Co-Authored-By: WorkBuddy <workbuddy@tencent.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
isLandlinePhone,
|
||||
isMobilePhone,
|
||||
isStoreContactPhone,
|
||||
maskContactPhone,
|
||||
normalizeContactPhone,
|
||||
toDialablePhone,
|
||||
} from './phone';
|
||||
@@ -36,4 +37,13 @@ describe('store contact phone', () => {
|
||||
expect(toDialablePhone('0379-8888888')).toBe('03798888888');
|
||||
expect(toDialablePhone('010 1234 5678')).toBe('01012345678');
|
||||
});
|
||||
|
||||
it('masks mobile and landline for display', () => {
|
||||
expect(maskContactPhone('13800138000')).toBe('138****8000');
|
||||
expect(maskContactPhone('0379-8888888')).toBe('0379-****888');
|
||||
expect(maskContactPhone('010-12345678')).toBe('010-****5678');
|
||||
expect(maskContactPhone('03798888888')).toBe('0379****888');
|
||||
expect(maskContactPhone('0379-8888888-12')).toBe('0379-****888-12');
|
||||
expect(maskContactPhone('')).toBe('—');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,3 +33,39 @@ export function isStoreContactPhone(raw: string): boolean {
|
||||
export function toDialablePhone(raw: string): string {
|
||||
return String(raw ?? '').replace(/[\s-]/g, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 对外联系电话脱敏展示。
|
||||
* - 手机:138****8000
|
||||
* - 座机:保留区号,本地号中间打码,如 0379-****888 / 010-****5678
|
||||
* - 带分机时保留分机后缀
|
||||
*/
|
||||
export function maskContactPhone(phone?: string | null): string {
|
||||
const raw = String(phone ?? '').trim();
|
||||
if (!raw) return '—';
|
||||
const normalized = normalizeContactPhone(raw);
|
||||
if (isMobilePhone(normalized)) {
|
||||
const digits = normalized.replace(/\D/g, '');
|
||||
return `${digits.slice(0, 3)}****${digits.slice(-4)}`;
|
||||
}
|
||||
if (isLandlinePhone(normalized)) {
|
||||
const extMatch = normalized.match(/-(\d{1,6})$/);
|
||||
const hasExt = !!extMatch && normalized.indexOf('-') !== normalized.lastIndexOf('-');
|
||||
const ext = hasExt ? extMatch![1] : '';
|
||||
const main = hasExt ? normalized.slice(0, -(ext.length + 1)) : normalized;
|
||||
const digits = main.replace(/\D/g, '');
|
||||
const areaLen = digits.startsWith('01') || digits.startsWith('02') ? 3 : 4;
|
||||
const area = digits.slice(0, areaLen);
|
||||
const local = digits.slice(areaLen);
|
||||
const keepTail = Math.min(4, Math.max(2, local.length - 4));
|
||||
const maskedLocal =
|
||||
local.length <= 4 ? '*'.repeat(local.length) : `${'*'.repeat(local.length - keepTail)}${local.slice(-keepTail)}`;
|
||||
const joiner = main.includes('-') ? '-' : '';
|
||||
return ext ? `${area}${joiner}${maskedLocal}-${ext}` : `${area}${joiner}${maskedLocal}`;
|
||||
}
|
||||
const digits = normalized.replace(/\D/g, '');
|
||||
if (digits.length >= 11) return `${digits.slice(0, 3)}****${digits.slice(-4)}`;
|
||||
if (digits.length >= 7) return `${digits.slice(0, 3)}****${digits.slice(-2)}`;
|
||||
if (digits.length > 0) return `${digits.slice(0, 1)}****`;
|
||||
return '****';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user