merge(dev): 联系电话脱敏支持座机 + 套餐表单多行输入
CI / verify (push) Has been cancelled

This commit is contained in:
2026-08-16 08:52:19 +08:00
9 changed files with 294 additions and 26 deletions
@@ -283,7 +283,8 @@ const AdminStorePackagesSection = forwardRef<AdminStorePackagesHandle, { storeId
</Form.Item>
<Form.Item label="使用时间" style={{ marginBottom: 12 }}>
<Input
<Input.TextArea
rows={2}
placeholder="节假日除外"
value={item.usableTime || ''}
onChange={(e) => updateAt(index, { usableTime: e.target.value })}
@@ -303,7 +304,8 @@ const AdminStorePackagesSection = forwardRef<AdminStorePackagesHandle, { storeId
</Form.Item>
<Form.Item label="其他说明" style={{ marginBottom: 0 }}>
<Input
<Input.TextArea
rows={2}
placeholder="不可叠加"
value={item.otherNotes || ''}
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
+1 -1
View File
@@ -259,7 +259,7 @@ function attachPackageAuditBadge(items: MenuProps['items'], pendingCount: number
...item,
label: (
<Badge count={pendingCount} size="small" offset={[8, 0]}>
<span style={{ color: '#ffffffa6' }}></span>
</Badge>
),
} as MenuItem;
+21 -2
View File
@@ -140,10 +140,29 @@ export function fmtTime(v?: string | null) {
return v ? new Date(v).toLocaleString('zh-CN') : '—';
}
/** 手机号脱敏展示:138****5678;空值返回 — */
/** 联系电话脱敏:手机 138****5678;座机 0379-****888;空值返回 — */
export function maskPhone(phone?: string | null): string {
const raw = String(phone ?? '').trim();
const raw = String(phone ?? '').trim().replace(/\s+/g, '');
if (!raw) return '—';
if (/^1[3-9]\d{9}$/.test(raw)) {
const digits = raw.replace(/\D/g, '');
return `${digits.slice(0, 3)}****${digits.slice(-4)}`;
}
if (/^0\d{2,3}-?\d{7,8}(-\d{1,6})?$/.test(raw)) {
const extMatch = raw.match(/-(\d{1,6})$/);
const hasExt = !!extMatch && raw.indexOf('-') !== raw.lastIndexOf('-');
const ext = hasExt ? extMatch![1] : '';
const main = hasExt ? raw.slice(0, -(ext.length + 1)) : raw;
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 = raw.replace(/\D/g, '');
if (digits.length >= 11) {
return `${digits.slice(0, 3)}****${digits.slice(-4)}`;
@@ -119,15 +119,13 @@ export default function StorePackagesForm({ items, onChange, disabled, embedded
<div className="partner-field">
<label>使</label>
<div className="partner-field-input">
<span className="material-symbols-outlined">schedule</span>
<input
placeholder="节假日除外"
value={item.usableTime || ''}
disabled={disabled}
onChange={(e) => updateAt(index, { usableTime: e.target.value })}
/>
</div>
<textarea
rows={2}
placeholder="节假日除外"
value={item.usableTime || ''}
disabled={disabled}
onChange={(e) => updateAt(index, { usableTime: e.target.value })}
/>
</div>
<div className="partner-field">
@@ -154,15 +152,13 @@ export default function StorePackagesForm({ items, onChange, disabled, embedded
<div className="partner-field">
<label></label>
<div className="partner-field-input">
<span className="material-symbols-outlined">info</span>
<input
placeholder="不可叠加"
value={item.otherNotes || ''}
disabled={disabled}
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
/>
</div>
<textarea
rows={2}
placeholder="不可叠加"
value={item.otherNotes || ''}
disabled={disabled}
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
/>
</div>
</>
) : null}
@@ -148,8 +148,9 @@ export default function ShopPackagesForm({ items, onChange, disabled }: Props) {
<label className="shop-packages-field">
<span className="shop-packages-label">使</span>
<input
<textarea
className="shop-packages-input"
rows={2}
placeholder="节假日除外"
value={item.usableTime || ''}
disabled={disabled}
@@ -213,8 +214,9 @@ export default function ShopPackagesForm({ items, onChange, disabled }: Props) {
<label className="shop-packages-field">
<span className="shop-packages-label"></span>
<input
<textarea
className="shop-packages-input"
rows={2}
placeholder="不可叠加"
value={item.otherNotes || ''}
disabled={disabled}
+33 -1
View File
@@ -1,4 +1,5 @@
const MOBILE_PHONE_RE = /^1[3-9]\d{9}$/;
const LANDLINE_PHONE_RE = /^0\d{2,3}-?\d{7,8}(-\d{1,6})?$/;
export function normalizePhoneInput(value: string): string {
return value.replace(/\D/g, '').slice(0, 11);
@@ -18,8 +19,39 @@ export function validateMobilePhone(phone: string): { ok: boolean; message?: str
return { ok: true };
}
function normalizeContactPhone(raw: string): string {
return String(raw ?? '')
.trim()
.replace(/\s+/g, '');
}
/**
* 脱敏展示:手机 138****8000;座机保留区号,如 0379-****888。
* 门店详情电话展示用(拨号仍走 toDialablePhone 明文)。
*/
export function maskPhone(phone: string) {
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
const normalized = normalizeContactPhone(phone);
if (!normalized) return '';
if (MOBILE_PHONE_RE.test(normalized)) {
const digits = normalized.replace(/\D/g, '');
return `${digits.slice(0, 3)}****${digits.slice(-4)}`;
}
if (LANDLINE_PHONE_RE.test(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}`;
}
return normalized.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}
export function toDialablePhone(raw: string): string {
+171
View File
@@ -0,0 +1,171 @@
#!/usr/bin/env bash
# sync-prod-db-to-local.sh — 将线上(production)数据库同步到本地 Docker MySQL
#
# 原理:
# 1. 通过 SSH 隧道穿透到阿里云 RDS。生产 DB 主机通常只允许应用服务器访问,
# 本地开发机一般不在白名单,因此借道生产服务器 dukang-server 建立隧道。
# 2. 在本地 dukang-v1-mysql 容器内用 mysqldump 连接隧道端口,导出线上库。
# 3. 通过管道直接导入本地库(默认 dukang_haoke,即应用本地库名)。
#
# 前置条件:
# - deploy.env 中 DEPLOY_HOST / DEPLOY_USER / DEPLOY_PORT 已配置且可无密码 SSH
# - 本地 docker compose 已启动(dukang-v1-mysql 容器监听 6016
# - 远端 /opt/dukang/server/dukang-api/.env.production 含 DATABASE_URL
# - 本地已安装 dockerWindows 用 Docker Desktop,容器内自带 mysql 客户端)
#
# 用法:
# bash deploy/sync-prod-db-to-local.sh # 交互确认 + 先备份本地
# bash deploy/sync-prod-db-to-local.sh --yes # 跳过确认(仍先备份本地)
# bash deploy/sync-prod-db-to-local.sh --no-backup --yes
# bash deploy/sync-prod-db-to-local.sh --dry-run # 仅打印计划,不落库、不开隧道
# bash deploy/sync-prod-db-to-local.sh --help
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
# ---------------- 默认参数 ----------------
LOCAL_CONTAINER="dukang-v1-mysql"
LOCAL_DB="dukang_haoke"
LOCAL_ROOT_PASSWORD="root"
TUNNEL_PORT=6018
REMOTE_ENV_FILE="/opt/dukang/server/dukang-api/.env.production"
HOST_ALIAS="host.docker.internal" # 容器内访问宿主机(Docker Desktop 默认支持)
DO_BACKUP=1
ASSUME_YES=0
DRY_RUN=0
# ---------------- 解析参数 ----------------
for arg in "$@"; do
case "$arg" in
--yes|-y) ASSUME_YES=1 ;;
--no-backup) DO_BACKUP=0 ;;
--dry-run) DRY_RUN=1 ;;
--help|-h) sed -n '3,30p' "$0"; exit 0 ;;
--tunnel-port=*) TUNNEL_PORT="${arg#*=}" ;;
--local-db=*) LOCAL_DB="${arg#*=}" ;;
--container=*) LOCAL_CONTAINER="${arg#*=}" ;;
--host-alias=*) HOST_ALIAS="${arg#*=}" ;;
*) echo "未知参数: $arg" >&2; exit 2 ;;
esac
done
# ---------------- 加载 deploy.env ----------------
if [[ -f deploy.env ]]; then
# shellcheck disable=SC1091
source deploy.env
fi
DEPLOY_HOST="${DEPLOY_HOST:?请在 deploy.env 配置 DEPLOY_HOST}"
DEPLOY_USER="${DEPLOY_USER:-root}"
DEPLOY_PORT="${DEPLOY_PORT:-22}"
SSH=(ssh -o StrictHostKeyChecking=accept-new -p "$DEPLOY_PORT")
if [[ -n "${DEPLOY_SSH_KEY:-}" ]]; then SSH+=(-i "$DEPLOY_SSH_KEY"); fi
TARGET="$DEPLOY_USER@$DEPLOY_HOST"
# ---------------- 读取并解析远端 DATABASE_URL ----------------
echo "==> 读取线上数据库配置 ($TARGET:$REMOTE_ENV_FILE)"
# 用服务端 new URL 解析(密码可能含 @ / : 等特殊字符),base64 回传避免 shell 转义问题
PARSED="$("${SSH[@]}" "$TARGET" bash -s <<'NODEEOF'
cat > /tmp/_parse_db.js <<'JSEOF'
const fs=require("fs");
const l=fs.readFileSync("/opt/dukang/server/dukang-api/.env.production","utf8").match(/^DATABASE_URL=(.*)$/m)[1].trim();
let u=l;
if((u[0]==='"'&&u[u.length-1]==='"')||(u[0]==="'"&&u[u.length-1]==="'"))u=u.slice(1,-1);
const U=new URL(u);
const b=s=>Buffer.from(s).toString("base64");
const path=U.pathname.replace(/^\//,"").split("?")[0];
process.stdout.write([b(decodeURIComponent(U.username)),b(U.hostname),U.port||"3306",b(path),b(decodeURIComponent(U.password))].join("|")+"\n");
JSEOF
node /tmp/_parse_db.js; rm -f /tmp/_parse_db.js
NODEEOF
)"
if [[ -z "$PARSED" ]]; then
echo "无法读取远端 DATABASE_URL,中止。" >&2; exit 1
fi
IFS='|' read -r _U _H _P _DB _PASS <<< "$PARSED"
REMOTE_USER="$(echo "$_U" | base64 -d)"
REMOTE_HOST="$(echo "$_H" | base64 -d)"
REMOTE_PORT="$_P"
REMOTE_DB="$(echo "$_DB" | base64 -d)"
REMOTE_PASS="$(echo "$_PASS" | base64 -d)"
echo " 线上库: $REMOTE_USER@$REMOTE_HOST:$REMOTE_PORT/$REMOTE_DB"
# ---------------- 检查本地容器 ----------------
if ! docker ps --format '{{.Names}}' | grep -qx "$LOCAL_CONTAINER"; then
echo "本地容器 $LOCAL_CONTAINER 未运行。请先执行: cd deploy && docker compose up -d" >&2
exit 1
fi
# ---------------- 打印计划 ----------------
echo
echo "同步计划:"
echo " 源(线上): $REMOTE_USER@$REMOTE_HOST:$REMOTE_PORT/$REMOTE_DB"
echo " 目标(本地): root@$LOCAL_CONTAINER:$LOCAL_DB (对外端口 6016)"
echo " 隧道: $TARGET -L $TUNNEL_PORT:$REMOTE_HOST:$REMOTE_PORT"
echo " 本地备份: $([[ $DO_BACKUP -eq 1 ]] && echo|| echo)"
if [[ $DRY_RUN -eq 1 ]]; then
echo "(dry-run) 已结束,未做任何修改。"
exit 0
fi
# ---------------- 确认 ----------------
if [[ $ASSUME_YES -ne 1 ]]; then
read -r -p "确认将【线上 $REMOTE_DB】覆盖同步到【本地 $LOCAL_DB】? [y/N] " ans
[[ "$ans" == "y" || "$ans" == "Y" ]] || { echo "已取消。"; exit 0; }
fi
# ---------------- 备份本地 ----------------
if [[ $DO_BACKUP -eq 1 ]]; then
mkdir -p backups
BK="backups/local-${LOCAL_DB}-$(date +%Y%m%d-%H%M%S).sql"
echo "==> 备份本地库到 $BK"
docker exec "$LOCAL_CONTAINER" mysqldump -uroot -p"$LOCAL_ROOT_PASSWORD" --single-transaction "$LOCAL_DB" > "$BK"
echo " 备份完成 ($(wc -c < "$BK") bytes)"
fi
# ---------------- 确保本地目标库存在 ----------------
docker exec "$LOCAL_CONTAINER" mysql -uroot -p"$LOCAL_ROOT_PASSWORD" \
-e "CREATE DATABASE IF NOT EXISTS \`$LOCAL_DB\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
# ---------------- 建立 SSH 隧道 ----------------
CTL="/tmp/sync-prod-db-$$.sock"
echo "==> 建立 SSH 隧道 $TARGET -L $TUNNEL_PORT:$REMOTE_HOST:$REMOTE_PORT"
"${SSH[@]}" -M -S "$CTL" -f -N -L "$TUNNEL_PORT:$REMOTE_HOST:$REMOTE_PORT" "$TARGET"
# 等待隧道就绪
ready=0
for i in 1 2 3 4 5 6 7 8 9 10; do
if docker exec -e "MYSQL_PWD=$REMOTE_PASS" "$LOCAL_CONTAINER" \
mysqladmin -h "$HOST_ALIAS" -P "$TUNNEL_PORT" -u "$REMOTE_USER" ping >/dev/null 2>&1; then
ready=1; break
fi
sleep 1
done
if [[ $ready -ne 1 ]]; then
echo "隧道未就绪,中止。" >&2
"${SSH[@]}" -S "$CTL" -O exit "$TARGET" 2>/dev/null || true
exit 1
fi
# ---------------- 同步(线上 -> 本地,管道直导) ----------------
echo "==> 开始同步(管道直导,不落临时文件)"
echo " 提示:同步前建议本地 Prisma 已追平线上 schemapnpm db:push 或迁移),否则可能因表结构差异报错。"
set +e
docker exec -i -e "MYSQL_PWD=$REMOTE_PASS" "$LOCAL_CONTAINER" \
mysqldump -h "$HOST_ALIAS" -P "$TUNNEL_PORT" -u "$REMOTE_USER" \
--lock-tables=0 --add-drop-table --skip-triggers --no-create-db \
--skip-routines --skip-events --column-statistics=0 --no-tablespaces --set-gtid-purged=OFF \
"$REMOTE_DB" \
| docker exec -i "$LOCAL_CONTAINER" mysql -uroot -p"$LOCAL_ROOT_PASSWORD" "$LOCAL_DB"
RC=${PIPESTATUS[0]}
set -e
# ---------------- 关闭隧道 ----------------
"${SSH[@]}" -S "$CTL" -O exit "$TARGET" 2>/dev/null || true
if [[ $RC -ne 0 ]]; then
echo "同步失败 (mysqldump 退出码 $RC)。本地库可能处于不一致状态。" >&2
[[ $DO_BACKUP -eq 1 ]] && echo "请用备份恢复: $BK" >&2
exit 1
fi
echo "==> 同步完成 ✅ 本地 $LOCAL_DB 现已是线上 $REMOTE_DB 的副本。"
+10
View File
@@ -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('—');
});
});
+36
View File
@@ -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 '****';
}